using System.Collections.Generic; using Core.Utility; using Fort23.Core; using Fort23.UTool; using GameLogic.Combat.CombatTool; using UnityEngine; using Utility; namespace GameLogic.CombatScenesTool { public class CombatEquipFallManager : Singleton { public BetterList allEquipFall = new BetterList(); public class EquipFallObject : CObject { public GameObjectPool GameObjectPool; public Parabola3DPath Parabola3DPath; public float _currTime; public int stateIndex; private float _addTime; public void Init(Parabola3DPath Parabola3DPath) { this.Parabola3DPath = Parabola3DPath; _addTime = 1.0f / Parabola3DPath.totalFlightTime; } public override void Dispose() { } public override void ActiveObj() { } public override void DormancyObj() { GObjectPool.Instance.Recycle(GameObjectPool); GameObjectPool = null; CObjectPool.Instance.Recycle(Parabola3DPath); _currTime = 0; stateIndex = 0; } public void Update(float t) { if (stateIndex == 0) { _currTime += t*_addTime*2; Vector3 pos = Parabola3DPath.GetPositionAtTime(_currTime*Parabola3DPath.totalFlightTime); GameObjectPool.own.transform.position = pos; if (_currTime > 1) { stateIndex = 1; _currTime = 0; } } else if (stateIndex == 1) { _currTime += t; if (_currTime > 2) { stateIndex = 2; _currTime = 0; } } else if (stateIndex == 2) { _currTime += t; CombatHeroEntity[] heroEntities = CombatController.currActiveCombat.CombatHeroController.GetHero(false); if (heroEntities.Length > 0) { Transform heroT = heroEntities[0].combatHeroGameObject.transform; GameObjectPool.own.transform.position = Vector3.Lerp(GameObjectPool.own.transform.position, heroT.position, 0.2f); if (Vector3.SqrMagnitude(GameObjectPool.own.transform.position - heroT.position) < 0.3f) { CombatEquipFallManager.Instance.allEquipFall.Remove(this); CObjectPool.Instance.Recycle(this); } } } } } public CombatEquipFallManager() { StaticUpdater.Instance.AddRenderUpdateCallBack(Update); } public override void Dispose() { StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update); } public void Fall(List allEquip, Vector3 worldPos) { for (int i = 0; i < allEquip.Count; i++) { GObjectPool.Instance.FetchAsync("equip1", delegate(GameObjectPool pool) { EquipFallObject equipFallObject = CObjectPool.Instance.Fetch(); equipFallObject.GameObjectPool = pool; Parabola3DPath parabolaPath = CObjectPool.Instance.Fetch(); parabolaPath.addY = 3; Vector3 startPos = worldPos; float x = Random.Range(-2f, 2f); float z = Random.Range(-2f, 2f); // if (x < 0) // { // x = Mathf.Clamp(x, -1, -2.5f); // } // else // { // x = Mathf.Clamp(x, 1, 2.5f); // } // // if (z < 0) // { // z = Mathf.Clamp(z, -1, -2.5f); // } // else // { // z = Mathf.Clamp(z, 1, 2.5f); // } Vector3 endPos = startPos + new Vector3(x, 0, z); parabolaPath.SetPos(startPos, endPos); // equipFallObject.Parabola3DPath = parabolaPath; equipFallObject.Init(parabolaPath); allEquipFall.Add(equipFallObject); }); } } public void Update() { for (int i = 0; i < allEquipFall.Count; i++) { allEquipFall[i].Update(Time.deltaTime); } } } }