blob: dd33f8712d47c703369176dccf8bb33d14587b12 (
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
|
#if UNITY_EDITOR
using System;
using UnityEngine;
using XUtliPoolLib;
namespace XEditor
{
internal class XCutSceneCamera
{
private GameObject _cameraObject = null;
private GameObject _dummyObject = null;
private Transform _dummyCamera = null;
private Transform _cameraTransform = null;
private Animator _ator = null;
public AnimatorOverrideController _overrideController = new AnimatorOverrideController();
private UnityEngine.Camera _camera = null;
private bool _root_pos_inited = false;
private Vector3 _root_pos = Vector3.zero;
private Quaternion _idle_root_rotation = Quaternion.identity;
private Vector3 _dummyCamera_pos = Vector3.zero;
private CameraMotionSpace _effect_axis = CameraMotionSpace.World;
private XCameraMotionData _motion = new XCameraMotionData();
public XActor Target = null;
private string _trigger = null;
public UnityEngine.Camera UnityCamera
{
get { return _camera; }
}
public Transform CameraTrans
{
get { return _cameraTransform; }
}
public Animator CameraAnimator
{
get { return _ator; }
}
public Vector3 Position
{
get { return _cameraTransform.position; }
}
public Quaternion Rotaton
{
get { return _cameraTransform.rotation; }
}
public bool Initialize()
{
_cameraObject = GameObject.Find(@"Main Camera");
if (null != _cameraObject)
{
_camera = _cameraObject.GetComponent<UnityEngine.Camera>();
_cameraTransform = _cameraObject.transform;
XResourceLoaderMgr.SafeDestroy(ref _dummyObject);
_dummyObject = XResourceLoaderMgr.singleton.CreateFromPrefab("Prefabs/DummyCamera") as GameObject;
_dummyObject.name = "Dummy Camera";
_dummyCamera = _dummyObject.transform.GetChild(0);
_ator = _dummyObject.GetComponent<Animator>();
_overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController;
_ator.runtimeAnimatorController = _overrideController;
_root_pos_inited = false;
}
return true;
}
public void OverrideAnimClip(string motion, string clipname)
{
//get override clip
AnimationClip animClip = XResourceLoaderMgr.singleton.GetSharedResource<AnimationClip>(clipname, ".anim");
OverrideAnimClip(motion, animClip);
}
public void OverrideAnimClip(string motion, AnimationClip clip)
{
//override
if (clip != null && _overrideController[motion] != clip) _overrideController[motion] = clip;
}
public void PostUpdate(float fDeltaT)
{
if (!_root_pos_inited)
{
_root_pos = _dummyCamera.position;
_root_pos_inited = true;
_idle_root_rotation = _motion.Follow_Position ? Quaternion.Euler(0, 180, 0) : Quaternion.identity;
}
InnerUpdateEx();
TriggerEffect();
}
private void InnerPosition()
{
_dummyCamera_pos = _idle_root_rotation * (_dummyCamera.position - _dummyObject.transform.position) + _dummyObject.transform.position;
}
private void InnerUpdateEx()
{
InnerPosition();
Vector3 v_self_p = Target == null ? Vector3.zero : Target.Actor.transform.position;
Vector3 forward = Vector3.Cross(_dummyCamera.forward, _dummyCamera.up);
Quaternion q = Quaternion.LookRotation(forward, _dummyCamera.up);
Vector3 delta = (_dummyCamera_pos - _root_pos);
Vector3 target_pos = _root_pos + (_motion.Follow_Position ? v_self_p : Vector3.zero);
_cameraTransform.rotation = _idle_root_rotation * q;
switch (_effect_axis)
{
case CameraMotionSpace.World:
{
target_pos += delta;
} break;
}
_cameraTransform.position = target_pos;
}
public void Effect(XCameraMotionData motion)
{
//must be called from UPDATE pass
AnimationClip clip = XResourceLoaderMgr.singleton.GetSharedResource<AnimationClip>(motion.Motion, ".anim");
if (clip != null)
{
_trigger = "ToEffect";
if (_overrideController["CameraEffect"] != clip) _overrideController["CameraEffect"] = clip;
_motion.Follow_Position = motion.Follow_Position;
_motion.Coordinate = motion.Coordinate;
_motion.AutoSync_At_Begin = motion.AutoSync_At_Begin;
_motion.LookAt_Target = motion.LookAt_Target;
_motion.Motion = motion.Motion;
}
}
private void TriggerEffect()
{
if (_trigger != null && !_ator.IsInTransition(0))
{
_effect_axis = _motion.Coordinate;
_ator.SetTrigger(_trigger);
_root_pos_inited = false;
_trigger = null;
}
}
}
}
#endif
|