using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Gameplay.Skill; using PhxhSDK; namespace Gameplay.Summon { using cfg.SummonCfg; using Framework; using Gameplay.Common; using Gameplay.Level; using LTGame; using UnityEngine; public class BaseSummon : GameUnit { public bool needRemove = false; public readonly DataSummon configData; public readonly SummonRuntimeData runtimeData; protected NStateMachine _fsm; protected List _skillIntParams; protected List _skillFloatParams; public readonly SkillHandle createSkill; public BaseSummon(DataSummon configData, uint id, int tId, SkillHandle skillHandle) : base(id, tId, EGameUnitType.Summon) { // TODO: 暂时不知道从哪里读 commonData.level = 1; createSkill = skillHandle; this.configData = configData; runtimeData = new SummonRuntimeData(); runtimeData.remainExistTime = configData.ExistTime; commonData.canControl = false; statusData.canBeAttack = configData.CanBeAttack; commonData.standLevel = configData.StandCrossLevel; commonData.crossLevel = configData.MoveCrossLevel; } private void _InitFsm() { _OnInitFsm(); } protected virtual void _OnInitFsm() { _fsm = new NStateMachine(); _fsm.Add(new SummonStateWaitRemove(this)); } public async void Create() { var modelPath = configData.ModelPath; var loadObj = await AssetManager.Instance.LoadAssetAsync(modelPath); if (loadObj == null) { return; } var instObj = Object.Instantiate(loadObj, Node.GameObject.transform); instObj.transform.localPosition = Vector3.zero; instObj.transform.localRotation = Quaternion.identity; instObj.transform.localScale = Vector3.one; Node.GameObject.SetLayerEx(Node.GameObject.layer); } public void Init(int createCellIndex, float yaw) { _InitNode(createCellIndex, yaw); _OnInited(); _InitFsm(); } private void _InitNode(int createCellIndex, float yaw) { var map = LevelManager.Instance.CurrentLevel.Map; var worldPos = map.TGSCellIndex2WorldPosition(createCellIndex); transData.pos = worldPos; transData.yaw = yaw; Node.GameObject.transform.SetPositionAndRotation(transData.pos, transData.rot); } protected virtual void _OnInited() { } public void LogicUpdate(float dt) { _UpdateExitTime(dt); _fsm.LogicUpdate(dt); _UpdateTrans(dt); } private void _UpdateExitTime(float dt) { runtimeData.remainExistTime -= dt; } private void _UpdateTrans(float dt) { if (IsDispose()) return; if (transData.isTransChanged) { Node.GameObject.transform.SetPositionAndRotation(transData.pos, transData.rot); } transData.Reset(); } } }