TH1/Unity/Assets/Scripts/HotfixView/Client/Demo/Unit/AfterUnitCreate_CreateUnitView.cs
2025-07-17 18:26:28 +08:00

24 lines
1014 B
C#

using UnityEngine;
namespace ET.Client
{
[Event(SceneType.Current)]
public class AfterUnitCreate_CreateUnitView: AEvent<Scene, AfterUnitCreate>
{
protected override async ETTask Run(Scene scene, AfterUnitCreate args)
{
Unit unit = args.Unit;
// Unit View层
string assetsName = $"Assets/Bundles/Unit/Unit.prefab";
GameObject bundleGameObject = await scene.GetComponent<ResourcesLoaderComponent>().LoadAssetAsync<GameObject>(assetsName);
GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
GlobalComponent globalComponent = scene.Root().GetComponent<GlobalComponent>();
GameObject go = UnityEngine.Object.Instantiate(prefab, globalComponent.Unit, true);
go.transform.position = unit.Position;
unit.AddComponent<GameObjectComponent>().GameObject = go;
unit.AddComponent<AnimatorComponent>();
await ETTask.CompletedTask;
}
}
}