1 using UnityEngine;
2 using System.Collections;
3
4 public class BattleHurtNum : MonoBehaviour
5 {
6
7 public Vector3 mVec;
8
9 protected TweenAlpha mTa;
10 protected TweenPosition mTp;
11 protected TweenScale mTs;
12
13 // Use this for initialization
14 void Start ()
15 {
16
17 mTa = gameObject.GetComponent<TweenAlpha>();
18 mTp = gameObject.GetComponent<TweenPosition>();
19 mTs = gameObject.GetComponent<TweenScale>();
20 // GetNumObject(1234);
21 }
22
23 // Update is called once per frame
24 void Update ()
25 {
26
27 }
28
29 public virtual void Show(GameObject obj, Vector3 vec) { }
30 public virtual void Move() { }
31 public virtual void Scale() { }
32 public virtual void Alpha() { }
33 }
34
35 /// <summary>
36 /// 暴击
37 /// </summary>
38 public class CritNum : BattleHurtNum
39 {
40
41
42 public override void Show(GameObject obj, Vector3 vec)
43 {
44 mTa = obj.GetComponent<TweenAlpha>();
45 mTp = obj.GetComponent<TweenPosition>();
46 mTs = obj.GetComponent<TweenScale>();
47 Move(vec);
48 Scale();
49 Alpha();
50 }
51
52 public void Move(Vector3 vec)
53 {
54 mTp.from = mVec;
55 mTp.to = new Vector3(0, vec.y + 200, 0);
56 mTp.delay = 0;
57 mTp.duration = 0.4f;
58 mTp.onFinished = OnMoveFinished;
59 mTp.Play(true);
60 mTp.Reset();
61 }
62 private void OnMoveFinished(UITweener twwen)
63 {
64 GameObject.Destroy(twwen.gameObject);
65 }
66 public override void Scale()
67 {
68 mTs.from = new Vector3(0,0.2f,0);
69 mTs.to = new Vector3(1,1,0);
70 mTs.delay = 0;
71 mTs.duration = 0.1f;
72 mTs.Play(true);
73 mTs.Reset();
74 }
75
76 public override void Alpha()
77 {
78 mTa.from = 1;
79 mTa.to = 0;
80 mTa.delay = 0.25f;
81 mTa.duration = 0.15f;
82 mTa.Play(true);
83 mTa.Reset();
84
85 }
86 }
87
88 /// <summary>
89 /// 回复
90 /// </summary>
91 public class ReplyNum : BattleHurtNum
92 {
93 public override void Show(GameObject obj, Vector3 vec)
94 {
95 mTa = obj.GetComponent<TweenAlpha>();
96 mTp = obj.GetComponent<TweenPosition>();
97 mTs = obj.GetComponent<TweenScale>();
98 Move(vec);
99 Alpha();
100 }
101
102 public void Move(Vector3 vec)
103 {
104 mTp.from = mVec;
105 mTp.to = new Vector3(0, vec.y + 200, 0);
106 mTp.delay = 0;
107 mTp.duration = 0.4f;
108 mTp.onFinished = OnMoveFinished;
109 mTp.Play(true);
110 mTp.Reset();
111 }
112 private void OnMoveFinished(UITweener twwen)
113 {
114 GameObject.Destroy(twwen.gameObject);
115 }
116
117 public override void Alpha()
118 {
119 mTa.from = 1;
120 mTa.to = 0;
121 mTa.delay = 0.35f;
122 mTa.duration = 0.05f;
123 mTa.Play(true);
124 mTa.Reset();
125
126 }
127 }
128
129 /// <summary>
130 /// 受击
131 /// </summary>
132 public class HitNum : BattleHurtNum
133 {
134 private GameObject mObj;
135 private int mRandom = 0;
136
137 public override void Show(GameObject obj, Vector3 vec)
138 {
139 mObj = obj;
140 mTa = obj.GetComponent<TweenAlpha>();
141 mTp = obj.GetComponent<TweenPosition>();
142 mTs = obj.GetComponent<TweenScale>();
143 System.Random r = new System.Random();
144 mRandom = r.Next(-100, 100);
145 vec.x += mRandom;
146 Move(vec);
147
148 }
149
150 public void Move(Vector3 vec)
151 {
152 mTp.from = mVec;
153 mTp.to = new Vector3(vec.x, vec.y + 200, 0);
154 mTp.delay = 0;
155 mTp.duration = 1;
156 mTp.onFinished = OnMoveFinished;
157 mTp.Play(true);
158 mTp.Reset();
159 }
160 private void OnMoveFinished(UITweener move)
161 {
162 mTp.from = mObj.transform.localPosition;
163 mTp.to = new Vector3(mRandom*2, 0, 0);
164 mTp.delay = 0;
165 mTp.duration = 1;
166 mTp.onFinished = OnEndAin;
167 mTp.Play(true);
168 mTp.Reset();
169 Alpha();
170 }
171
172 private void OnEndAin(UITweener twwen)
173 {
174 GameObject.Destroy(twwen.gameObject);
175 }
176 public override void Alpha()
177 {
178 mTa.from = 1;
179 mTa.to = 0;
180 mTa.delay = 0;
181 mTa.duration = 1;
182 mTa.Play(true);
183 mTa.Reset();
184 }
185 }
1 using UnityEngine;
2 using System.Collections;
3
4 public class TestNum : MonoBehaviour {
5
6 public UISprite mNum;
7 protected string mName = "sj_0";
8 protected GameObject mObj = null;
9
10 public GameObject mCirt;
11 public GameObject mHit;
12 public GameObject mReply;
13 // Use this for initialization
14 void Start ()
15 {
16 mNum.gameObject.SetActive(false);
17 UIEventListener.Get(mCirt).onClick = OnClickCirt;
18 UIEventListener.Get(mHit).onClick = OnClickHit;
19 UIEventListener.Get(mReply).onClick = OnClickReply;
20 }
21
22 // Update is called once per frame
23 void Update ()
24 {
25
26 }
27
28 void OnClickCirt(GameObject obj)
29 {
30 ShowNum(1);
31 }
32
33 void OnClickHit(GameObject obj)
34 {
35 ShowNum(2);
36 }
37
38 void OnClickReply(GameObject obj)
39 {
40 ShowNum(3);
41 }
42
43 public GameObject GetNumObject(int num)
44 {
45 GameObject obj = new GameObject();
46 obj.transform.parent = gameObject.transform;
47 obj.transform.localScale = new Vector3(1,1,1);
48 obj.layer = gameObject.layer;
49 obj.AddComponent<UIPanel>();
50 obj.AddComponent<TweenAlpha>();
51 obj.AddComponent<TweenPosition>();
52 obj.AddComponent<TweenScale>();
53
54 string str = num.ToString();
55 for (int i = 0; i < str.Length; ++i)
56 {
57 GameObject numObj = GameObject.Instantiate(mNum.gameObject) as GameObject;
58 numObj.SetActive(true);
59 numObj.GetComponent<UISprite>().spriteName = mName + str[i];
60 numObj.transform.parent = obj.transform;
61 numObj.transform.localPosition = new Vector3(i * 40, 0, 0);
62 numObj.transform.localScale = new Vector3(39, 54, 0);
63 numObj.transform.localEulerAngles = new Vector3(0, 0, 0);
64 }
65 mObj = gameObject;
66 return obj;
67 }
68
69 void ShowNum(int index)
70 {
71 switch(index)
72 {
73 case 1:
74 CritNum crit = new CritNum();
75 crit.mVec = new Vector3(0,0,0);
76 crit.Show(GetNumObject(1000),new Vector3(0,0,0));
77 break;
78 case 2:
79 ReplyNum reply = new ReplyNum();
80 reply.mVec = new Vector3(0,0,0);
81 reply.Show(GetNumObject(1000), new Vector3(0, 0, 0));
82 break;
83 case 3:
84 HitNum hit = new HitNum();
85 hit.mVec = new Vector3(0,0,0);
86 hit.Show(GetNumObject(1000), new Vector3(0, 0, 0));
87 break;
88 }
89
90 }
91 }
![]()