레스토랑 ready flow에서 createEnvironment 로직 추가
This commit is contained in:
parent
2804b9a240
commit
7ddbf3be68
@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DDD
|
namespace DDD
|
||||||
@ -7,6 +7,10 @@ namespace DDD
|
|||||||
public class DataManager : Singleton<DataManager>, IManager
|
public class DataManager : Singleton<DataManager>, IManager
|
||||||
{
|
{
|
||||||
public ItemDataSo ItemDataSo { get; private set; }
|
public ItemDataSo ItemDataSo { get; private set; }
|
||||||
|
public FoodDataSo FoodDataSo { get; private set; }
|
||||||
|
public EnvironmentDataSo EnvironmentDataSo { get; private set; }
|
||||||
|
|
||||||
|
public bool IsInitialized { get; private set; }
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
@ -18,22 +22,28 @@ public async void PostInit()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ItemDataSo = await AssetManager.LoadAsset<ItemDataSo>(DataConstants.ItemDataSo);
|
ItemDataSo = await AssetManager.LoadAsset<ItemDataSo>(DataConstants.ItemDataSo);
|
||||||
|
FoodDataSo = await AssetManager.LoadAsset<FoodDataSo>(DataConstants.FoodDataSo);
|
||||||
|
EnvironmentDataSo = await AssetManager.LoadAsset<EnvironmentDataSo>(DataConstants.EnvironmentDataSo);
|
||||||
|
|
||||||
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogError($"So bind failed\n{e.Message}");
|
Debug.LogError($"So bind failed\n{e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task WaitUntilInitialized()
|
||||||
|
{
|
||||||
|
while (!IsInitialized)
|
||||||
|
{
|
||||||
|
await Task.Yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO : So가 늘어나는 경우 관리 방법 변경 필요성이 있음
|
// TODO : So가 늘어나는 경우 관리 방법 변경 필요성이 있음
|
||||||
// GetItemType(id)
|
// GetItemType(id)
|
||||||
// GetItemImage
|
// GetItemImage
|
||||||
// GetItemName
|
// GetItemName
|
||||||
|
|
||||||
public ItemType GetItemType(string key)
|
|
||||||
{
|
|
||||||
ItemData itemData = ItemDataSo.ItemDataList.FirstOrDefault(item => item.Id == key);
|
|
||||||
return itemData?.ItemType ?? ItemType.None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DDD
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(fileName = "CreateEnvironment", menuName = "GameFlow/CreateEnvironment")]
|
||||||
|
public class CreateEnvironment : GameFlowReadyHandler
|
||||||
|
{
|
||||||
|
public override async Task OnReadyNewFlow(GameFlowState newFlowState)
|
||||||
|
{
|
||||||
|
var baseRestaurantEnvironmentPrefab = await AssetManager.LoadAsset<GameObject>(CommonConstants.BaseRestaurantEnvironment);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
|
||||||
|
restaurantEnvironment.Initialize("Item_Environment_002");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
|
||||||
|
restaurantEnvironment.Initialize("Item_Environment_002");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
|
||||||
|
restaurantEnvironment.Initialize("Item_Environment_003");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
|
||||||
|
restaurantEnvironment.Initialize("Item_Environment_004");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
using Spine.Unity;
|
||||||
|
using Unity.VisualScripting;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DDD
|
||||||
|
{
|
||||||
|
public class RestaurantEnvironment : MonoBehaviour
|
||||||
|
{
|
||||||
|
private RestaurantEnvironmentData _restaurantEnvironmentData;
|
||||||
|
|
||||||
|
private Collider _collider;
|
||||||
|
private Transform _visualLook;
|
||||||
|
private Renderer _renderer;
|
||||||
|
|
||||||
|
public async void Initialize(string id)
|
||||||
|
{
|
||||||
|
await DataManager.Instance.WaitUntilInitialized();
|
||||||
|
|
||||||
|
EnvironmentData environmentData = DataManager.Instance.EnvironmentDataSo.GetDataById(id);
|
||||||
|
|
||||||
|
_collider = GetComponent<Collider>();
|
||||||
|
_visualLook = transform.Find(CommonConstants.VisualLook);
|
||||||
|
|
||||||
|
if (environmentData == null)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "environmentData is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (environmentData.RendererType == RendererType.Sprite)
|
||||||
|
{
|
||||||
|
var spriteRenderer = _visualLook.AddComponent<SpriteRenderer>();
|
||||||
|
_renderer = spriteRenderer;
|
||||||
|
spriteRenderer.sprite = environmentData.Sprite;
|
||||||
|
spriteRenderer.sortingOrder = 5;
|
||||||
|
Material material = await AssetManager.LoadAsset<Material>(DataConstants.BasePropSpriteMaterial);
|
||||||
|
spriteRenderer.material = new Material(material);
|
||||||
|
}
|
||||||
|
else if (environmentData.RendererType == RendererType.Spine)
|
||||||
|
{
|
||||||
|
var skeletonAnimation = _visualLook.AddComponent<SkeletonAnimation>();
|
||||||
|
var skeletonDataAsset = await AssetManager.LoadAsset<SkeletonDataAsset>(environmentData.SkeletonDataName);
|
||||||
|
skeletonAnimation.skeletonDataAsset = skeletonDataAsset;
|
||||||
|
var spineController = transform.AddComponent<SpineController>();
|
||||||
|
spineController.SetSkin(environmentData.SkinName);
|
||||||
|
spineController.PlayAnimation(environmentData.DefaultAnimationName, true);
|
||||||
|
_renderer = _visualLook.GetComponent<MeshRenderer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
_collider.isTrigger = environmentData.IsTrigger == 1;
|
||||||
|
|
||||||
|
Vector2 randomPos = new Vector2(
|
||||||
|
Random.Range(-10f, 10f),
|
||||||
|
Random.Range(10f, 20f)
|
||||||
|
);
|
||||||
|
|
||||||
|
transform.position = new Vector3(randomPos.x, 0f, randomPos.y);
|
||||||
|
transform.localScale = Vector3.one * environmentData.Size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0ca3054addaa7fb4a86dfb3ad8241452
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DDD
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class RestaurantEnvironmentData
|
||||||
|
{
|
||||||
|
public string Id;
|
||||||
|
public Vector2 Position;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0d90911f4c827e3439a9a28d25e9bf93
|
@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DDD
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(fileName = "RestaurantEnvironmentDataSo", menuName = "RestaurantEnvironment/RestaurantEnvironmentDataSo")]
|
||||||
|
public class RestaurantEnvironmentDataSo : SerializedScriptableObject
|
||||||
|
{
|
||||||
|
public Dictionary<string, List<RestaurantEnvironmentData>> RestaurantEnvironmentDatas = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6d9bb690776b59d40a1cc2e7036d78bd
|
@ -4,12 +4,18 @@ public static class CommonConstants
|
|||||||
{
|
{
|
||||||
public const string VisualLook = "VisualLook";
|
public const string VisualLook = "VisualLook";
|
||||||
public const string RestaurantPlayer = "RestaurantPlayer";
|
public const string RestaurantPlayer = "RestaurantPlayer";
|
||||||
|
public const string BaseRestaurantEnvironment = "BaseRestaurantEnvironment";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DataConstants
|
public static class DataConstants
|
||||||
{
|
{
|
||||||
public const string ItemDataSo = "ItemDataSo";
|
public const string ItemDataSo = "ItemDataSo";
|
||||||
|
public const string FoodDataSo = "FoodDataSo";
|
||||||
|
public const string EnvironmentDataSo = "EnvironmentDataSo";
|
||||||
|
public const string SpriteDataSo = "SpriteDataSo";
|
||||||
public const string RestaurantPlayerDataSo = "RestaurantPlayerDataSo";
|
public const string RestaurantPlayerDataSo = "RestaurantPlayerDataSo";
|
||||||
|
|
||||||
|
public const string BasePropSpriteMaterial = "BasePropSpriteMaterial";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RestaurantPlayerAnimation
|
public static class RestaurantPlayerAnimation
|
||||||
|
Loading…
Reference in New Issue
Block a user