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
|
#if UNITY_EDITOR
using UnityEngine;
using XEditor;
using XUtliPoolLib;
using UnityEditor;
namespace XEditor
{
internal class XActor
{
private GameObject _actor = null;
private Transform _shadow = null;
private Transform _bip = null;
private Animator _ator = null;
private static Terrain _terrain = null;
private AudioSource _audio_motion = null;
private AudioSource _audio_action = null;
private AudioSource _audio_skill = null;
static XActor()
{
_terrain = Terrain.activeTerrain;
/*if (_terrain == null)
{
SceneTable.RowData sceneConf = XSceneMgr.singleton.GetSceneData(_scene_id);
if (sceneConf.BlockFilePath.Length > 0)
{
_grid = new XGrid();
if (!_grid.LoadFile(@"Assets\Resources\" + sceneConf.BlockFilePath))
{
Debug.Log(@"Load Grid file: Assets\Resources\" + sceneConf.BlockFilePath + " failed!");
_grid = null;
}
}
}*/
}
public GameObject Actor { get { return _actor; } }
public Transform Bip { get { return _bip; } }
public XActor(float x, float y, float z, string clip)
{
_actor = AssetDatabase.LoadAssetAtPath("Assets/Editor/EditorResources/Prefabs/ZJ_zhanshi.prefab", typeof(GameObject)) as GameObject;
_actor = UnityEngine.Object.Instantiate(_actor) as GameObject;
DisablePhysic();
_actor.transform.position = new Vector3(x, y, z);
_ator = _actor.GetComponent<Animator>();
AnimatorOverrideController overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController;
_ator.runtimeAnimatorController = overrideController;
overrideController["Idle"] = XResourceLoaderMgr.singleton.GetSharedResource<AnimationClip>(clip, ".anim");
_shadow = _actor.transform.Find("Shadow");
if (_shadow != null) _shadow.GetComponent<Renderer>().enabled = true;
_ator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
}
public XActor(string prefab, float x, float y, float z, string clip)
{
_actor = XResourceLoaderMgr.singleton.CreateFromPrefab(prefab, new Vector3(x, y, z), Quaternion.identity) as GameObject;
_ator = _actor.GetComponent<Animator>();
DisablePhysic();
if (_ator != null)
{
AnimatorOverrideController overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController;
_ator.runtimeAnimatorController = overrideController;
overrideController["Idle"] = XResourceLoaderMgr.singleton.GetSharedResource<AnimationClip>(clip, ".anim");
_shadow = _actor.transform.Find("Shadow");
if (_shadow != null) _shadow.GetComponent<Renderer>().enabled = true;
_ator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
}
}
public XActor(uint id, float x, float y, float z, string clip)
{
_actor = UnityEngine.Object.Instantiate(XStatisticsLibrary.GetDummy(id), new Vector3(x, y, z), Quaternion.identity) as GameObject;
_ator = _actor.GetComponent<Animator>();
DisablePhysic();
AnimatorOverrideController overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController;
_ator.runtimeAnimatorController = overrideController;
overrideController["Idle"] = XResourceLoaderMgr.singleton.GetSharedResource<AnimationClip>(clip, ".anim");
_shadow = _actor.transform.Find("Shadow");
if (_shadow != null) _shadow.GetComponent<Renderer>().enabled = true;
_ator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
}
private void DisablePhysic()
{
if (_actor != null)
{
CharacterController cc = _actor.GetComponent<CharacterController>();
if (cc != null) cc.enabled = false;
}
}
public void Update(float fDelta)
{
StickShadow();
}
public AudioSource GetAudioSourceByChannel(AudioChannel channel)
{
switch (channel)
{
case AudioChannel.Action:
{
if (_audio_action == null)
_audio_action = _actor.AddComponent<AudioSource>();
return _audio_action;
}
case AudioChannel.Motion:
{
if (_audio_motion == null)
_audio_motion = _actor.AddComponent<AudioSource>();
return _audio_motion;
}
case AudioChannel.Skill:
{
if (_audio_skill == null)
_audio_skill = _actor.AddComponent<AudioSource>();
return _audio_skill;
}
}
return _audio_action;
}
protected void StickShadow()
{
if (_bip == null) return;
Vector3 shadow_pos;
shadow_pos.x = _bip.position.x;
shadow_pos.z = _bip.position.z;
shadow_pos.y = XActor.TerrainY(_bip.transform.position) + 0.02f;
_shadow.position = shadow_pos;
}
public static float TerrainY(Vector3 pos)
{
if (_terrain != null)
{
return _terrain.SampleHeight(pos);
}
return 0;
}
}
}
#endif
|