//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Thursday, October 26, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System; namespace vnxbqy.UI { public class DungeonItemCollectFlyObject : MonoBehaviour { [SerializeField] BezierMove m_BezierMove; Action endCallBack = null; public void Begin(Vector3 _from, Vector3 _to, Action _callBack) { var startPoint = _from.SetZ(0); var endPoint = _to; endCallBack = _callBack; var nl = Vector3.Normalize(endPoint - startPoint); var normal = new Vector3(-nl.y, nl.x, 0); var distance = Vector3.Distance(startPoint, endPoint); var pivot = startPoint + normal * UnityEngine.Random.Range(-distance, distance)*0.7f + nl * distance * 0.4f; m_BezierMove.Begin(startPoint, pivot, endPoint, OnReach); this.SetActive(true); this.transform.localPosition = startPoint; } public void Begin(Vector3 _from, Vector3 _to, float modulus, Action _callBack) { var startPoint = _from.SetZ(0); var endPoint = _to; endCallBack = _callBack; var nl = Vector3.Normalize(endPoint - startPoint); var normal = new Vector3(-nl.y, nl.x, 0); var distance = Vector3.Distance(startPoint, endPoint); var pivot = startPoint + normal * UnityEngine.Random.Range(-distance, distance) * modulus + nl * distance * 0.4f; m_BezierMove.Begin(startPoint, pivot, endPoint, OnReach); this.SetActive(true); this.transform.localPosition = startPoint; } private void OnReach() { if (endCallBack != null) { endCallBack(); endCallBack = null; } DungeonItemCollectFlyObjectPool.Recycle(this.gameObject); } } public class DungeonItemCollectFlyObjectPool { static GameObjectPoolManager.GameObjectPool pool = null; public static DungeonItemCollectFlyObject Require() { if (pool == null) { var prefab = UILoader.LoadPrefab("DungeonItemCollectFlyObject"); if (prefab != null) { pool = GameObjectPoolManager.Instance.RequestPool(prefab); } } if (pool != null) { var instance = pool.Request(); return instance.GetComponent(); } else { return null; } } public static void Recycle(GameObject _gameObject) { if (pool != null) { pool.Release(_gameObject); _gameObject.transform.SetParent(null); _gameObject.SetActive(false); } } public static void Clear() { if (pool != null) { pool.Clear(); pool = null; } } } }