forked from u3dkbe/kbengine_unity3d_warring
-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathSceneEntityObject.cs
More file actions
393 lines (342 loc) · 20.1 KB
/
SceneEntityObject.cs
File metadata and controls
393 lines (342 loc) · 20.1 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
using UnityEngine;
using KBEngine;
using System.Collections;
using System;
using System.Xml;
using System.Collections.Generic;
public class SceneEntityObject : SceneObject
{
public SByte state = 0;
public GameEntityCtrl gameEntity = null;
public Vector3 destPosition = Vector3.zero;
public Vector3 destDirection = Vector3.zero;
UnityEngine.GameObject hud_infosObj = null;
public Hud_Infos hudinfos = null;
public KBEngine.Entity kbentity = null;
public bool isPlayer = false;
public SceneEntityObject()
{
}
~SceneEntityObject() // destructor
{
gameEntity.seo = null;
gameEntity = null;
//if (hudinfos != null)
if (!(System.Object.ReferenceEquals(hudinfos, null)))
{
hudinfos.seo = null;
}
}
public void setName(string name)
{
//if(hud_infosObj != null)
if (!(System.Object.ReferenceEquals(hud_infosObj, null)))
{
hudinfos.setName(name);
}
}
public void updateHPBar(Int32 hp, Int32 hpmax)
{
//if (hud_infosObj != null)
if (!(System.Object.ReferenceEquals(hud_infosObj, null)))
{
hudinfos.updateHPBar(hp, hpmax);
}
}
public void create()
{
// 设置默认的模型
gameObject = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(loader.inst.defaultEntityAsset, position, Quaternion.Euler(eulerAngles));
gameObject.name = name;
gameObject.transform.localScale = scale;
//if(loader.inst.entityHudInfosAsset != null)
if (!(System.Object.ReferenceEquals(loader.inst.entityHudInfosAsset, null)))
{
hud_infosObj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(loader.inst.entityHudInfosAsset);
hud_infosObj.name = "hud_infos";
hudinfos = hud_infosObj.GetComponent<Hud_Infos>();
hudinfos.seo = this;
attachHeadInfo();
}
else
{
Common.WARNING_MSG("SceneEntityObject::Start: not found entityHudInfosAsset!");
}
}
public void createPlayer()
{
gameObject = UnityEngine.GameObject.Find("PlayerChar/entity");
isPlayer = true;
}
public override void Instantiate()
{
asset.Instantiate(this, name, position, eulerAngles, scale);
}
void attachHeadInfo()
{
if(hud_infosObj == null)
return;
hud_infosObj.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
hud_infosObj.transform.parent = gameObject.transform.FindChild("head_info");
if(hud_infosObj.transform.parent == null)
{
hud_infosObj.transform.parent = gameObject.transform;
hudinfos.offsetY = 3f;
}
hud_infosObj.transform.position = new Vector3(hud_infosObj.transform.parent.position.x,
hud_infosObj.transform.parent.position.y + hudinfos.offsetY, hud_infosObj.transform.parent.position.z);
}
public override void onAssetAsyncLoadObjectCB(string name, UnityEngine.Object obj, Asset asset)
{
this.name = asset.source;
//if (hud_infosObj != null)
if(!System.Object.ReferenceEquals(hud_infosObj,null))
{
hud_infosObj.transform.parent = null;
}
//if(gameObject != null)
if (!System.Object.ReferenceEquals(gameObject, null))
{
UnityEngine.GameObject.Destroy(gameObject);
gameObject = null;
}
base.onAssetAsyncLoadObjectCB(name, obj, asset);
gameEntity = gameObject.GetComponent<GameEntityCtrl>();
gameEntity.seo = this;
gameEntity.isPlayer = isPlayer;
if(isPlayer == false)
{
attachHeadInfo();
destPosition = position;
destDirection = eulerAngles;
Common.calcPositionY(destPosition, out destPosition.y, false);
gameEntity.gameObject.transform.position = destPosition;
}
else
{
if(gameObject.GetComponent<RPG_Animation>() == null)
gameObject.AddComponent<RPG_Animation>();
gameObject.name = "entity";
BoxCollider boxCollider = gameObject.GetComponent<BoxCollider>();
//if(boxCollider != null)
if (!System.Object.ReferenceEquals(boxCollider, null))
{
UnityEngine.Object.Destroy(boxCollider);
}
//if (gameObject.GetComponent<MeshCollider>() != null)
if (!System.Object.ReferenceEquals(gameObject.GetComponent<MeshCollider>(), null))
{
gameObject.AddComponent<MeshCollider>();
}
UnityEngine.GameObject PlayerChar = UnityEngine.GameObject.Find("PlayerChar");
//if(PlayerChar != null)
if (!System.Object.ReferenceEquals(PlayerChar, null))
{
gameObject.transform.parent = PlayerChar.transform;
}
}
}
public void update_position(Vector3 destPos)
{
destPosition = destPos;
}
public void set_moveSpeed(float v)
{
speed = v;
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.set_moveSpeed(v);
}
}
public void addHP(Int32 v)
{
//if(hud_infosObj != null)
if (!System.Object.ReferenceEquals(hud_infosObj, null))
{
if(v > 0)
hudinfos.addHP(v);
else
hudinfos.addDamage(v);
}
}
public void addMP(Int32 v)
{
//if(hud_infosObj != null)
if (!System.Object.ReferenceEquals(hud_infosObj, null))
{
hudinfos.addHP(v);
}
}
public void set_state(SByte v)
{
state = v;
//if(hudinfos != null)
if (!System.Object.ReferenceEquals(hudinfos, null))
{
hudinfos.set_state(v);
}
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
switch(state)
{
case 0:
gameEntity.playIdleAnimation();
break;
case 1:
gameEntity.playDeadAnimation();
break;
case 2:
gameEntity.playIdleAnimation();
break;
case 3:
gameEntity.playIdleAnimation();
break;
default:
gameEntity.playIdleAnimation();
break;
};
}
}
public void attack(Int32 skillID, Int32 damageType, SceneEntityObject receiver)
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playAttackAnimation();
}
if(receiver == null || receiver.gameEntity == null)
return;
//if(particles.inst != null)
if (!System.Object.ReferenceEquals(particles.inst, null))
{
Vector3 v = position;
UnityEngine.GameObject pobj = null;
switch(skillID)
{
case 7000101:
pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[37], gameEntity.gameObject.transform.FindChild("attackPoint").transform.position, rotation);
SM_moveToEntity sm = pobj.GetComponent<SM_moveToEntity>();
sm.moveSpeed = 10.0f;
sm.target = receiver.gameEntity.gameObject;
break;
default:
break;
};
if(pobj)
pobj.transform.localScale = new Vector3(2.5f, 2.5f, 2.5f);
}
}
public void recvDamage(Int32 skillID, Int32 damageType, Int32 damage)
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playDamageAnimation();
}
//if (hud_infosObj != null)
if (!System.Object.ReferenceEquals(hud_infosObj, null))
{
hudinfos.addDamage(damage);
}
//if(particles.inst != null)
if (!System.Object.ReferenceEquals(particles.inst, null))
{
Vector3 v = position;
UnityEngine.GameObject pobj = null;
v.y += 1f;
switch(skillID)
{
case 1:
break;
case 1000101:
pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[47], v, rotation);
break;
case 2000101:
v.y += 1.5f;
pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[21], v, rotation);
break;
case 3000101:
pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[32], v, rotation);
break;
case 4000101:
pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[45], v, rotation);
break;
case 5000101:
v.y -= 1f;
pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[14], v, rotation);
break;
case 6000101:
v.y += 0.5f;
pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[9], v, rotation);
pobj.transform.parent = gameObject.transform;
break;
case 7000101:
//pobj = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(particles.inst.allpartis[37], v, rotation);
//pobj.transform.parent = gameObject.transform;
break;
default:
break;
};
if(pobj)
pobj.transform.localScale = new Vector3(2.5f, 2.5f, 2.5f);
}
}
public void playAnimation(string ani)
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playAnimation(ani);
}
}
public void stopPlayAnimation(string ani)
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.stopPlayAnimation(ani);
}
}
public void playJumpAnimation()
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playJumpAnimation();
}
}
public void playIdleAnimation()
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playIdleAnimation();
}
}
public void playWalkAnimation()
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playWalkAnimation();
}
}
public void playRunAnimation()
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playRunAnimation();
}
}
public void playAttackAnimation()
{
//if(gameEntity != null)
if (!System.Object.ReferenceEquals(gameEntity, null))
{
gameEntity.playAttackAnimation();
}
}
}