using System; using Spine.Unity; using Unity.VisualScripting; using UnityEngine; namespace DDD.Restaurant { public class RestaurantEnvironment : MonoBehaviour { private RestaurantPropLocation restaurantPropLocation; private Collider _collider; private Transform _rootObject; private Transform _visualLook; private Renderer _renderer; public void Initialize(RestaurantPropLocation location) { EnvironmentDataEntry environmentDataEntry = DataManager.Instance.GetDataSo().GetDataById(location.Id); _collider = GetComponent(); _rootObject = transform.Find(CommonConstants.RootObject); _visualLook = _rootObject.Find(CommonConstants.VisualLook); if (environmentDataEntry == null) { Debug.Assert(false, "environmentDataEntry is null"); } if (environmentDataEntry.RendererType == RendererType.Sprite) { var spriteRenderer = _visualLook.AddComponent(); _renderer = spriteRenderer; spriteRenderer.sprite = DataManager.Instance.GetSprite(environmentDataEntry.SpriteKey); spriteRenderer.sortingOrder = 5; //Material material = await AssetManager.LoadAssetAsync(DataConstants.BasePropSpriteMaterial); //spriteRenderer.material = new Material(material); } else if (environmentDataEntry.RendererType == RendererType.Spine) { var skeletonAnimation = _visualLook.AddComponent(); //var skeletonDataAsset = await AssetManager.LoadAssetAsync(environmentDataEntry.SkeletonDataName); //skeletonAnimation.skeletonDataAsset = skeletonDataAsset; var spineController = transform.AddComponent(); spineController.SetSkin(environmentDataEntry.SkinName); spineController.PlayAnimation(environmentDataEntry.DefaultAnimationName, true); _renderer = _visualLook.GetComponent(); } _collider.isTrigger = environmentDataEntry.IsTrigger == 1; transform.position = new Vector3(location.Position.x, 0f, location.Position.y); transform.localScale = Vector3.one * environmentDataEntry.Size; // Interaction initialize if (environmentDataEntry.InteractionType != InteractionType.None) { var interactionComponent = transform.AddComponent(); interactionComponent.InitializeInteraction(environmentDataEntry.InteractionType); } } } }