123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- 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<CombatEquipFallManager>
- {
- public BetterList<EquipFallObject> allEquipFall = new BetterList<EquipFallObject>();
- 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<string> allEquip, Vector3 worldPos)
- {
- for (int i = 0; i < allEquip.Count; i++)
- {
- GObjectPool.Instance.FetchAsync<GameObjectPool>("equip1", delegate(GameObjectPool pool)
- {
- EquipFallObject equipFallObject = CObjectPool.Instance.Fetch<EquipFallObject>();
- equipFallObject.GameObjectPool = pool;
- Parabola3DPath parabolaPath = CObjectPool.Instance.Fetch<Parabola3DPath>();
- 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);
- }
- }
- }
- }
|