summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/TimelineEventProxy_Handlers.cs
blob: 0bb8df5c7ef71873b975943d4f63665723eb1d86 (plain)
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// Timeline Event Handlers
public partial class TimelineEventProxy
{

	void EventEffect(AnimationEventBase animEvent)
	{
		EventEffect effect = animEvent as EventEffect;
		if (effect == null)
			return;
		string path = effect.effectPath;
		if (path == null || path == "")
			return;
		GameObject prefab = ResourceManager.Instance.LoadAsset<GameObject>(path);
		if (prefab != null)
		{
			GameObject root = new GameObject();

			GameObject go = GameObject.Instantiate(prefab);
			go.transform.SetParent(root.transform);
			FxClear onClear = root.AddComponent<FxClear>();
			onClear.gameObject.name = prefab.name + "(Clone)";

			PlayEffectInfo info = new PlayEffectInfo();
			info.path = path;
			info.playEffectType = EffectPlayTypes.Oneshot;
			info.posOffset = effect.position;
			info.rot = effect.rotation;
			info.scale = effect.scale;
			info.bAttached = effect.attached;
			if (effect.attached)
			{
				if (effect.parentNode == global::EventEffect.EParentNode.Unit)
				{
					info.rootTr = m_Root;
				}
                else if(effect.parentNode == global::EventEffect.EParentNode.World)
                {
                    info.rootTr = null;
                }
				else if (effect.parentNode == global::EventEffect.EParentNode.Bone)
				{
					if (m_UnitModel != null)
					{
						info.rootTr = m_UnitModel.Find(effect.bonePath);
					}
				}
				else if(effect.parentNode == global::EventEffect.EParentNode.PresetBone)
				{
					if(m_UnitModel != null)
					{
						UnitDetail detail = m_UnitModel.GetComponent<UnitDetail>();
						if(detail)
						{
							info.rootTr = detail.GetBone(effect.bone);
						}
					}
				}
                else if(effect.parentNode == global::EventEffect.EParentNode.ReferencePoint)
                {
                }
			}

			onClear.Initialize(info);
#if UNITY_EDITOR
			if (isInEditMode && registerParticleSystem != null)
			{
				registerParticleSystem(onClear);
			}
			onClear.gameObject.transform.SetParent(Root_Particles.transform);
#endif
		}
	}

	void EventCamera_Shake(AnimationEventBase animEvent)
	{

	}

	void EventProjectile(AnimationEventBase animEvent)
	{
		EventProjectile e = animEvent as EventProjectile;
		if (e == null)
			return;
		string projectilePath = e.projectilePath;
		if (projectilePath == null || projectilePath == "")
			return;
		GameObject prefab = ResourceManager.Instance.LoadAsset<GameObject>(projectilePath);
		if (prefab == null)
		{
			LogHelper.LogError("缺少对应的projectile, " + projectilePath);
			return;
		}
		if (prefab.GetComponent<Projectile>() == null)
		{
			LogHelper.LogError("没有projectile脚本");
			return;
		}
		GameObject obj = GameObject.Instantiate(prefab);
		Projectile projectile = obj.GetComponent<Projectile>();
		ProjectileInfo info = new ProjectileInfo();
		info.name = e.name;
		info.tag = e.tag;
		info.moveType = e.moveType;
		info.owner = owner;
		info.position = m_Root.transform.position + e.posOffset;
		info.rotation = e.rotation;
		info.scale = e.scale;
		if (owner)
		{
			info.velocity = owner.transform.rotation * e.velocity;
		}
		else
		{
			info.velocity = e.velocity;
		}
		info.acceleration = e.acceleration;
		info.lifetime = e.lifeTime;
		info.sparkPath = e.sparkPath;
		projectile.Initialize(info);

#if UNITY_EDITOR
		if (isInEditMode && registerProjectile != null)
		{
			registerProjectile(projectile);
		}
		obj.transform.SetParent(Root_Projectiles.transform);
#endif
	}

	void EventMesh_AfterImage(AnimationEventBase animEvent)
	{
#if UNITY_EDITOR
		if (isInEditMode)
			return;
#endif
		EventMesh_AfterImage afterImage = animEvent as EventMesh_AfterImage;
		if (afterImage == null)
			return;
		string avatarPath = owner.unitDetail.afterImageAvatarPath;
		GameObject go = ResourceManager.Instance.LoadAsset<GameObject>(avatarPath);
		if (go)
		{
			GameObject instance = GameObject.Instantiate(go);
			AfterImageAvatar avatar = instance.GetOrAddComponent<AfterImageAvatar>();
			if (!avatar)
			{
				GameObject.DestroyImmediate(instance);
				return;
			}
			avatar.Initialize(owner);
		}
	}

	void EventUnit_SetPosition(AnimationEventBase animEvent)
	{
		// 在unitState回调里处理
	}

    void EventMesh_VisibilityInMainCamera(AnimationEventBase animEvent)
    {
        EventMesh_VisibilityInMainCamera visible = animEvent as EventMesh_VisibilityInMainCamera;
        if (visible == null)
            return;
        if (owner == null || owner.unitRender == null)
            return;
        owner.unitRender.SetVisibilityInMainCamera(visible.isVisible);
    }

	#region Unit Image Effects
	void EventMesh_ImageEffect_MotionBlur(AnimationEventBase animEvent)
    {
        EventMesh_ImageEffect_MotionBlur motionBlur = animEvent as EventMesh_ImageEffect_MotionBlur;
        if (motionBlur == null)
            return ;
		if (owner == null || !(owner is PCController))
			return;
		float angle = motionBlur.angle;
		angle = owner.isTowardRight ? angle : 180 - angle;
	//	((PCController)owner).unitImageEffect.ShowMotionBlur(motionBlur.lifeTime, angle, motionBlur.distance);
		((PCController)owner).unitImageEffect.ShowGlitch(motionBlur.lifeTime);
    }

	#endregion

}