Add airport tutorial assets and long background
This commit is contained in:
+137
-17
@@ -2,6 +2,23 @@ using UnityEngine;
|
||||
|
||||
// 발판으로서 필요한 동작을 담은 스크립트
|
||||
public class Platform : MonoBehaviour {
|
||||
public enum PlatformPattern {
|
||||
Random,
|
||||
Empty,
|
||||
LowLeft,
|
||||
LowMid,
|
||||
LowRight,
|
||||
Slide
|
||||
}
|
||||
|
||||
public enum MileagePattern {
|
||||
Random,
|
||||
None,
|
||||
SafeLine,
|
||||
JumpArc,
|
||||
SlideLine
|
||||
}
|
||||
|
||||
public GameObject[] obstacles; // 장애물 오브젝트들
|
||||
public int emptyPatternWeight = 2; // 장애물이 없는 패턴이 선택될 가중치
|
||||
public Sprite mileageSprite; // 이 발판에서 사용할 마일리지 토큰 스프라이트
|
||||
@@ -11,7 +28,21 @@ public class Platform : MonoBehaviour {
|
||||
|
||||
private bool stepped = false; // 플레이어 캐릭터가 밟았었는가
|
||||
private MileagePickup[] mileagePickups; // 런타임에 생성하는 마일리지 토큰 풀
|
||||
private PlatformPattern reservedPattern = PlatformPattern.Random; // 다음 활성화 때 사용할 수동 패턴
|
||||
private MileagePattern reservedMileagePattern = MileagePattern.Random; // 다음 활성화 때 사용할 마일리지 패턴
|
||||
private const int MileagePoolSize = 5;
|
||||
private const float MileageTokenScale = 0.55f;
|
||||
private const float MileageColliderRadius = 0.4f;
|
||||
|
||||
public void ConfigureForTutorial(PlatformPattern pattern, MileagePattern mileagePattern) {
|
||||
reservedPattern = pattern;
|
||||
reservedMileagePattern = mileagePattern;
|
||||
}
|
||||
|
||||
public void ConfigureForRandom() {
|
||||
reservedPattern = PlatformPattern.Random;
|
||||
reservedMileagePattern = MileagePattern.Random;
|
||||
}
|
||||
|
||||
// 컴포넌트가 활성화될때 마다 매번 실행되는 메서드
|
||||
private void OnEnable() {
|
||||
@@ -27,6 +58,12 @@ public class Platform : MonoBehaviour {
|
||||
|
||||
HideMileagePickups();
|
||||
|
||||
if(reservedPattern != PlatformPattern.Random)
|
||||
{
|
||||
ApplyTutorialPattern();
|
||||
return;
|
||||
}
|
||||
|
||||
if(obstacles.Length == 0)
|
||||
{
|
||||
TryPlaceMileagePattern(null);
|
||||
@@ -67,7 +104,7 @@ public class Platform : MonoBehaviour {
|
||||
{
|
||||
GameObject pickupObject = new GameObject("Mileage Pickup " + (i + 1));
|
||||
pickupObject.transform.SetParent(transform);
|
||||
pickupObject.transform.localScale = Vector3.one;
|
||||
pickupObject.transform.localScale = GetParentScaleCompensatedVector(MileageTokenScale);
|
||||
|
||||
SpriteRenderer spriteRenderer = pickupObject.AddComponent<SpriteRenderer>();
|
||||
spriteRenderer.sprite = mileageSprite;
|
||||
@@ -76,7 +113,7 @@ public class Platform : MonoBehaviour {
|
||||
|
||||
CircleCollider2D pickupCollider = pickupObject.AddComponent<CircleCollider2D>();
|
||||
pickupCollider.isTrigger = true;
|
||||
pickupCollider.radius = 0.35f;
|
||||
pickupCollider.radius = MileageColliderRadius;
|
||||
|
||||
mileagePickups[i] = pickupObject.AddComponent<MileagePickup>();
|
||||
mileagePickups[i].Setup(mileageSprite, smallMileageValue);
|
||||
@@ -118,17 +155,84 @@ public class Platform : MonoBehaviour {
|
||||
}
|
||||
else
|
||||
{
|
||||
PlaceJumpMileageArc(activeObstacle.transform.localPosition.x);
|
||||
PlaceJumpMileageArc(GetWorldRelativeX(activeObstacle.transform));
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyTutorialPattern() {
|
||||
GameObject activeObstacle = null;
|
||||
|
||||
switch(reservedPattern)
|
||||
{
|
||||
case PlatformPattern.LowLeft:
|
||||
activeObstacle = FindObstacle("Obstacle Left");
|
||||
break;
|
||||
case PlatformPattern.LowMid:
|
||||
activeObstacle = FindObstacle("Obstacle Mid");
|
||||
break;
|
||||
case PlatformPattern.LowRight:
|
||||
activeObstacle = FindObstacle("Obstacle Right");
|
||||
break;
|
||||
case PlatformPattern.Slide:
|
||||
activeObstacle = FindObstacle("Slide Obstacle Pattern");
|
||||
break;
|
||||
}
|
||||
|
||||
if(activeObstacle != null)
|
||||
{
|
||||
activeObstacle.SetActive(true);
|
||||
}
|
||||
|
||||
PlaceReservedMileagePattern(activeObstacle);
|
||||
}
|
||||
|
||||
private GameObject FindObstacle(string obstacleName) {
|
||||
for(int i = 0; i < obstacles.Length; i++)
|
||||
{
|
||||
if(obstacles[i] != null && obstacles[i].name == obstacleName)
|
||||
{
|
||||
return obstacles[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void PlaceReservedMileagePattern(GameObject activeObstacle) {
|
||||
if(mileageSprite == null || mileagePickups == null || reservedMileagePattern == MileagePattern.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(reservedMileagePattern == MileagePattern.SafeLine)
|
||||
{
|
||||
PlaceSafeMileageLine();
|
||||
return;
|
||||
}
|
||||
|
||||
if(reservedMileagePattern == MileagePattern.JumpArc)
|
||||
{
|
||||
float obstacleX = activeObstacle != null ? GetWorldRelativeX(activeObstacle.transform) : 0f;
|
||||
PlaceJumpMileageArc(obstacleX);
|
||||
return;
|
||||
}
|
||||
|
||||
if(reservedMileagePattern == MileagePattern.SlideLine)
|
||||
{
|
||||
PlaceSlideMileageLine();
|
||||
return;
|
||||
}
|
||||
|
||||
TryPlaceMileagePattern(activeObstacle);
|
||||
}
|
||||
|
||||
private void PlaceSafeMileageLine() {
|
||||
Vector2[] positions = {
|
||||
new Vector2(-2f, 2.25f),
|
||||
new Vector2(-1f, 2.25f),
|
||||
new Vector2(0f, 2.25f),
|
||||
new Vector2(1f, 2.25f),
|
||||
new Vector2(2f, 2.25f)
|
||||
new Vector2(-2f, 1.35f),
|
||||
new Vector2(-1f, 1.35f),
|
||||
new Vector2(0f, 1.35f),
|
||||
new Vector2(1f, 1.35f),
|
||||
new Vector2(2f, 1.35f)
|
||||
};
|
||||
|
||||
PlaceMileageTokens(positions, smallMileageValue);
|
||||
@@ -136,10 +240,10 @@ public class Platform : MonoBehaviour {
|
||||
|
||||
private void PlaceJumpMileageArc(float obstacleX) {
|
||||
Vector2[] positions = {
|
||||
new Vector2(obstacleX - 1.2f, 2.7f),
|
||||
new Vector2(obstacleX, 3.45f),
|
||||
new Vector2(obstacleX + 1.2f, 2.7f),
|
||||
new Vector2(obstacleX + 1.9f, 2.25f)
|
||||
new Vector2(obstacleX - 1.2f, 1.65f),
|
||||
new Vector2(obstacleX, 2.25f),
|
||||
new Vector2(obstacleX + 1.2f, 1.65f),
|
||||
new Vector2(obstacleX + 1.9f, 1.35f)
|
||||
};
|
||||
|
||||
PlaceMileageTokens(positions, smallMileageValue);
|
||||
@@ -148,10 +252,10 @@ public class Platform : MonoBehaviour {
|
||||
|
||||
private void PlaceSlideMileageLine() {
|
||||
Vector2[] positions = {
|
||||
new Vector2(-1.5f, 1.45f),
|
||||
new Vector2(-0.5f, 1.45f),
|
||||
new Vector2(0.5f, 1.45f),
|
||||
new Vector2(1.5f, 1.45f)
|
||||
new Vector2(-1.5f, 1.05f),
|
||||
new Vector2(-0.5f, 1.05f),
|
||||
new Vector2(0.5f, 1.05f),
|
||||
new Vector2(1.5f, 1.05f)
|
||||
};
|
||||
|
||||
PlaceMileageTokens(positions, smallMileageValue);
|
||||
@@ -164,11 +268,27 @@ public class Platform : MonoBehaviour {
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
mileagePickups[i].Setup(mileageSprite, value);
|
||||
mileagePickups[i].transform.localPosition = positions[i];
|
||||
mileagePickups[i].transform.localPosition = GetParentScaleCompensatedPosition(positions[i]);
|
||||
mileagePickups[i].ResetPickup();
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetParentScaleCompensatedVector(float scale) {
|
||||
float parentScaleX = Mathf.Approximately(transform.localScale.x, 0f) ? 1f : transform.localScale.x;
|
||||
float parentScaleY = Mathf.Approximately(transform.localScale.y, 0f) ? 1f : transform.localScale.y;
|
||||
return new Vector3(scale / parentScaleX, scale / parentScaleY, 1f);
|
||||
}
|
||||
|
||||
private Vector3 GetParentScaleCompensatedPosition(Vector2 position) {
|
||||
float parentScaleX = Mathf.Approximately(transform.localScale.x, 0f) ? 1f : transform.localScale.x;
|
||||
float parentScaleY = Mathf.Approximately(transform.localScale.y, 0f) ? 1f : transform.localScale.y;
|
||||
return new Vector3(position.x / parentScaleX, position.y / parentScaleY, 0f);
|
||||
}
|
||||
|
||||
private float GetWorldRelativeX(Transform child) {
|
||||
return child.localPosition.x * transform.localScale.x;
|
||||
}
|
||||
|
||||
private void SetPickupValue(int index, int value) {
|
||||
if(index < 0 || index >= mileagePickups.Length || !mileagePickups[index].gameObject.activeSelf)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user