少年修仙传客户端代码仓库
hch
2025-03-19 6770e1eb64c4282def45adb824b14b2a407fdd30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//--------------------------------------------------------
//    [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<DungeonItemCollectFlyObject>();
            }
            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;
            }
        }
 
    }
 
 
}