1515*
1616*/
1717
18- //#define SPLINE_INTERPOLATOR
19-
2018using UnityEngine ;
2119using IBM . Watson . DeveloperCloud . Logging ;
2220
@@ -28,39 +26,36 @@ namespace IBM.Watson.DeveloperCloud.Camera
2826 public class CameraTarget : MonoBehaviour
2927 {
3028
31- #region Private Members
29+ #region protected Members
3230
33- private WatsonCamera mp_WatsonCamera = null ;
34- private UnityEngine . Camera mp_CameraAttached = null ;
31+ protected WatsonCamera mp_WatsonCamera = null ;
32+ protected UnityEngine . Camera mp_CameraAttached = null ;
3533 [ SerializeField ]
36- private bool m_UseCustomPosition = false ;
34+ protected bool m_UseCustomPosition = false ;
3735 [ SerializeField ]
38- private Vector3 m_CustomPosition = Vector3 . zero ;
36+ protected Vector3 m_CustomPosition = Vector3 . zero ;
3937 [ SerializeField ]
40- private Vector3 m_OffsetPosition = Vector3 . zero ;
41- private Quaternion m_OffsetPositionRotation = Quaternion . identity ;
38+ protected Vector3 m_OffsetPosition = Vector3 . zero ;
39+ protected Quaternion m_OffsetPositionRotation = Quaternion . identity ;
4240 [ SerializeField ]
43- private bool m_UseCustomRotation = false ;
44- private Quaternion m_CustomRotation = Quaternion . identity ;
45- private bool m_UseTargetObjectToRotate = false ;
41+ protected bool m_UseCustomRotation = false ;
42+ protected Quaternion m_CustomRotation = Quaternion . identity ;
43+ protected bool m_UseTargetObjectToRotate = false ;
4644 [ SerializeField ]
47- private GameObject m_CustomTargetObjectToLookAt = null ;
45+ protected GameObject m_CustomTargetObjectToLookAt = null ;
4846 [ SerializeField ]
49- private GameObject m_CameraPathRootObject = null ;
47+ protected GameObject m_CameraPathRootObject = null ;
5048 [ SerializeField ]
51- private float m_RatioAtCameraPath = 0.0f ;
49+ protected float m_RatioAtCameraPath = 0.0f ;
5250 [ SerializeField ]
53- private Vector3 m_DistanceFromCamera = Vector3 . zero ;
54- #if SPLINE_INTERPOLATOR
55- [ SerializeField ]
56- private SplineInterpolator m_SplineInterpolator ;
57- #endif
58- private Transform [ ] m_PathTransforms ;
51+ protected Vector3 m_DistanceFromCamera = Vector3 . zero ;
52+
53+ protected Transform [ ] m_PathTransforms ;
5954
6055 [ SerializeField ]
61- private bool m_TextEnableCamera = false ;
56+ protected bool m_TextEnableCamera = false ;
6257 [ SerializeField ]
63- private bool m_TestToMakeItCurrent = false ;
58+ protected bool m_TestToMakeItCurrent = false ;
6459
6560 #endregion
6661
@@ -71,7 +66,7 @@ public class CameraTarget : MonoBehaviour
7166 /// custom position.
7267 /// </summary>
7368 /// <value><c>true</c> if use custom position; otherwise, <c>false</c>.</value>
74- public bool UseCustomPosition
69+ public virtual bool UseCustomPosition
7570 {
7671 get
7772 {
@@ -88,7 +83,7 @@ public bool UseCustomPosition
8883 /// custom rotation.
8984 /// </summary>
9085 /// <value><c>true</c> if use custom rotation; otherwise, <c>false</c>.</value>
91- public bool UseCustomRotation
86+ public virtual bool UseCustomRotation
9287 {
9388 get
9489 {
@@ -104,7 +99,7 @@ public bool UseCustomRotation
10499 /// Gets or sets the ratio at camera path. It is used if there is path root object assigned to the system
105100 /// </summary>
106101 /// <value>The ratio at camera path.</value>
107- public float RatioAtCameraPath
102+ public virtual float RatioAtCameraPath
108103 {
109104 get
110105 {
@@ -120,7 +115,7 @@ public float RatioAtCameraPath
120115 /// Gets or sets the camera path root object.
121116 /// </summary>
122117 /// <value>The camera path root object.</value>
123- public GameObject CameraPathRootObject
118+ public virtual GameObject CameraPathRootObject
124119 {
125120 get
126121 {
@@ -132,7 +127,7 @@ public GameObject CameraPathRootObject
132127 }
133128 }
134129
135- public Vector3 OffsetPosition
130+ public virtual Vector3 OffsetPosition
136131 {
137132 get
138133 {
@@ -144,7 +139,7 @@ public Vector3 OffsetPosition
144139 }
145140 }
146141
147- public Vector3 DistanceFromCamera
142+ public virtual Vector3 DistanceFromCamera
148143 {
149144 get
150145 {
@@ -156,7 +151,7 @@ public Vector3 DistanceFromCamera
156151 }
157152 }
158153
159- public Quaternion OffsetPositionRotation
154+ public virtual Quaternion OffsetPositionRotation
160155 {
161156 get
162157 {
@@ -172,47 +167,10 @@ public Quaternion OffsetPositionRotation
172167 /// Gets or sets the target position.
173168 /// </summary>
174169 /// <value>The target position.</value>
175- public Vector3 TargetPosition
170+ public virtual Vector3 TargetPosition
176171 {
177172 get
178173 {
179- #if SPLINE_INTERPOLATOR
180- if ( m_CameraPathRootObject != null )
181- {
182- if ( m_PathTransforms == null )
183- {
184- List < Transform > childrenTransforms = new List < Transform > ( m_CameraPathRootObject . GetComponentsInChildren < Transform > ( ) ) ;
185-
186- childrenTransforms . Remove ( m_CameraPathRootObject . transform ) ;
187- childrenTransforms . Sort ( delegate ( Transform t1 , Transform t2 )
188- {
189- return t1 . name . CompareTo ( t2 . name ) ;
190- } ) ;
191-
192- m_PathTransforms = childrenTransforms . ToArray ( ) ;
193-
194- if ( m_SplineInterpolator == null )
195- {
196- m_SplineInterpolator = this . gameObject . GetComponent < SplineInterpolator > ( ) ;
197- if ( m_SplineInterpolator == null )
198- m_SplineInterpolator = this . gameObject . AddComponent < SplineInterpolator > ( ) ;
199- }
200-
201- m_SplineInterpolator . SetupSplineInterpolator ( m_PathTransforms ) ;
202- }
203-
204- if ( m_OffsetPosition != Vector3 . zero )
205- {
206- return m_SplineInterpolator . GetHermiteAtTime ( m_RatioAtCameraPath ) + ( TargetRotation * m_OffsetPosition ) + DistanceFromCamera ;
207- }
208- else
209- {
210- return m_SplineInterpolator . GetHermiteAtTime ( m_RatioAtCameraPath ) + DistanceFromCamera ;
211- }
212-
213- }
214- else
215- #endif
216174 if ( m_UseCustomPosition )
217175 {
218176 return m_CustomPosition ;
@@ -237,7 +195,7 @@ public Vector3 TargetPosition
237195 /// Gets or sets the target rotation.
238196 /// </summary>
239197 /// <value>The target rotation.</value>
240- public Quaternion TargetRotation
198+ public virtual Quaternion TargetRotation
241199 {
242200 get
243201 {
@@ -285,7 +243,7 @@ public Quaternion TargetRotation
285243 /// Gets or sets the target object.
286244 /// </summary>
287245 /// <value>The target object.</value>
288- public GameObject TargetObject
246+ public virtual GameObject TargetObject
289247 {
290248 get
291249 {
@@ -310,7 +268,7 @@ public GameObject TargetObject
310268 /// Gets the camera attached.
311269 /// </summary>
312270 /// <value>The camera attached.</value>
313- public UnityEngine . Camera CameraAttached
271+ public virtual UnityEngine . Camera CameraAttached
314272 {
315273 get
316274 {
@@ -327,7 +285,7 @@ public UnityEngine.Camera CameraAttached
327285 /// Gets the watson camera attached.
328286 /// </summary>
329287 /// <value>The watson camera attached.</value>
330- public WatsonCamera WatsonCameraAttached
288+ public virtual WatsonCamera WatsonCameraAttached
331289 {
332290 get
333291 {
@@ -353,7 +311,7 @@ public WatsonCamera WatsonCameraAttached
353311 /// Sets the current target on camera.
354312 /// </summary>
355313 /// <param name="enable">If set to <c>true</c> enable.</param>
356- public void SetCurrentTargetOnCamera ( bool enable )
314+ public virtual void SetCurrentTargetOnCamera ( bool enable )
357315 {
358316 if ( WatsonCamera . Instance != null )
359317 {
@@ -367,7 +325,7 @@ public void SetCurrentTargetOnCamera(bool enable)
367325 /// <summary>
368326 /// Sets the target position default.
369327 /// </summary>
370- public void SetTargetPositionDefault ( )
328+ public virtual void SetTargetPositionDefault ( )
371329 {
372330 if ( WatsonCamera . Instance != null && WatsonCamera . Instance . DefaultCameraTarget != null )
373331 {
@@ -378,7 +336,7 @@ public void SetTargetPositionDefault()
378336 /// <summary>
379337 /// Sets the target rotation default.
380338 /// </summary>
381- public void SetTargetRotationDefault ( )
339+ public virtual void SetTargetRotationDefault ( )
382340 {
383341 if ( WatsonCamera . Instance != null && WatsonCamera . Instance . DefaultCameraTarget != null )
384342 {
@@ -407,53 +365,14 @@ void Update()
407365 /// Sets the target position with offset.
408366 /// </summary>
409367 /// <param name="offsetPosition"></param>
410- public void SetTargetPositionWithOffset ( Vector3 offsetPosition )
368+ public virtual void SetTargetPositionWithOffset ( Vector3 offsetPosition )
411369 {
412370 m_OffsetPosition = offsetPosition ;
413371 m_OffsetPositionRotation = this . transform . rotation ;
414372 }
415373
416374 #endregion
417375
418- #if SPLINE_INTERPOLATOR
419-
420- void OnDrawGizmos ( )
421- {
422- if ( m_CameraPathRootObject != null )
423- {
424- List < Transform > childrenTransforms = new List < Transform > ( m_CameraPathRootObject . GetComponentsInChildren < Transform > ( ) ) ;
425-
426- childrenTransforms . Remove ( m_CameraPathRootObject . transform ) ;
427- childrenTransforms . Sort ( delegate ( Transform t1 , Transform t2 )
428- {
429- return t1 . name . CompareTo ( t2 . name ) ;
430- } ) ;
431-
432- m_PathTransforms = childrenTransforms . ToArray ( ) ;
433-
434- if ( m_SplineInterpolator == null )
435- {
436- m_SplineInterpolator = this . gameObject . GetComponent < SplineInterpolator > ( ) ;
437- if ( m_SplineInterpolator == null )
438- m_SplineInterpolator = this . gameObject . AddComponent < SplineInterpolator > ( ) ;
439- }
440-
441- m_SplineInterpolator . SetupSplineInterpolator ( m_PathTransforms ) ;
442-
443- Vector3 prevPos = m_PathTransforms [ 0 ] . position ;
444- for ( int c = 1 ; c <= 100 ; c ++ )
445- {
446- float currTime = c * 1.0f / 100 ;
447- Vector3 currPos = m_SplineInterpolator . GetHermiteAtTime ( currTime ) ;
448- float mag = ( currPos - prevPos ) . magnitude * 2 ;
449- Gizmos . color = new Color ( mag , 0 , 0 , 1 ) ;
450- Gizmos . DrawLine ( prevPos , currPos ) ;
451- prevPos = currPos ;
452- }
453- }
454- }
455-
456- #endif
457376 }
458377
459378}
0 commit comments