@@ -33,13 +33,23 @@ public class CameraTarget : MonoBehaviour
3333 private static UnityEngine . Camera mp_CameraAttached = null ;
3434 [ SerializeField ]
3535 private bool m_UseCustomPosition = false ;
36+ [ SerializeField ]
3637 private Vector3 m_CustomPosition = Vector3 . zero ;
3738 [ SerializeField ]
39+ private Vector3 m_OffsetPosition = Vector3 . zero ;
40+ private Quaternion m_OffsetPositionRotation = Quaternion . identity ;
41+ [ SerializeField ]
3842 private bool m_UseCustomRotation = false ;
3943 private Quaternion m_CustomRotation = Quaternion . identity ;
4044 private bool m_UseTargetObjectToRotate = false ;
45+ [ SerializeField ]
4146 private GameObject m_CustomTargetObjectToLookAt = null ;
4247
48+ [ SerializeField ]
49+ private bool m_TextEnableCamera = false ;
50+ [ SerializeField ]
51+ private bool m_TestToMakeItCurrent = false ;
52+
4353 #endregion
4454
4555 #region Public Members
@@ -57,9 +67,13 @@ public Vector3 TargetPosition
5767 {
5868 return m_CustomPosition ;
5969 }
70+ else if ( m_OffsetPosition != Vector3 . zero )
71+ {
72+ return transform . position + ( Quaternion . Euler ( transform . rotation . eulerAngles - m_OffsetPositionRotation . eulerAngles ) * m_OffsetPosition ) ;
73+ }
6074 else
6175 {
62- return transform . position ;
76+ return transform . position ;
6377 }
6478 }
6579 set
@@ -77,11 +91,7 @@ public Quaternion TargetRotation
7791 {
7892 get
7993 {
80- if ( m_UseCustomRotation )
81- {
82- return m_CustomRotation ;
83- }
84- else if ( m_UseTargetObjectToRotate )
94+ if ( m_UseTargetObjectToRotate )
8595 {
8696 if ( TargetObject != null )
8797 {
@@ -102,6 +112,10 @@ public Quaternion TargetRotation
102112 return Quaternion . identity ;
103113 }
104114 }
115+ else if ( m_UseCustomRotation )
116+ {
117+ return m_CustomRotation ;
118+ }
105119 else
106120 {
107121 return transform . rotation ;
@@ -114,20 +128,28 @@ public Quaternion TargetRotation
114128 }
115129 }
116130
117- protected GameObject TargetObject
131+ public GameObject TargetObject
118132 {
119133 get
120134 {
121135 return m_CustomTargetObjectToLookAt ;
122136 }
123137 set
124138 {
125- m_UseTargetObjectToRotate = true ;
126- m_CustomTargetObjectToLookAt = value ;
139+ if ( value != null )
140+ {
141+ m_UseTargetObjectToRotate = true ;
142+ m_CustomTargetObjectToLookAt = value ;
143+ }
144+ else
145+ {
146+ m_UseTargetObjectToRotate = false ;
147+ m_CustomTargetObjectToLookAt = null ;
148+ }
127149 }
128150 }
129151
130- protected UnityEngine . Camera CameraAttached
152+ public UnityEngine . Camera CameraAttached
131153 {
132154 get
133155 {
@@ -140,7 +162,7 @@ protected UnityEngine.Camera CameraAttached
140162 }
141163 }
142164
143- protected WatsonCamera WatsonCameraAttached
165+ public WatsonCamera WatsonCameraAttached
144166 {
145167 get
146168 {
@@ -156,7 +178,7 @@ protected WatsonCamera WatsonCameraAttached
156178
157179 #region Set Target on Camera
158180
159- protected void SetCurrentTargetOnCamera ( bool enable )
181+ public void SetCurrentTargetOnCamera ( bool enable )
160182 {
161183 if ( WatsonCamera . Instance != null )
162184 {
@@ -167,15 +189,15 @@ protected void SetCurrentTargetOnCamera(bool enable)
167189 }
168190 }
169191
170- protected void SetTargetPositionDefault ( )
192+ public void SetTargetPositionDefault ( )
171193 {
172194 if ( WatsonCamera . Instance != null && WatsonCamera . Instance . DefaultCameraTarget != null )
173195 {
174196 TargetPosition = WatsonCamera . Instance . DefaultCameraTarget . TargetPosition ;
175197 }
176198 }
177199
178- protected void SetTargetRotationDefault ( )
200+ public void SetTargetRotationDefault ( )
179201 {
180202 if ( WatsonCamera . Instance != null && WatsonCamera . Instance . DefaultCameraTarget != null )
181203 {
@@ -184,6 +206,29 @@ protected void SetTargetRotationDefault()
184206 }
185207
186208 #endregion
209+
210+ #region Update
211+
212+ void Update ( )
213+ {
214+ if ( m_TestToMakeItCurrent )
215+ {
216+ m_TestToMakeItCurrent = false ;
217+ SetCurrentTargetOnCamera ( m_TextEnableCamera ) ;
218+ }
219+ }
220+
221+ #endregion
222+
223+ #region public Functions
224+
225+ public void SetTargetPositionWithOffset ( Vector3 offsetPosition )
226+ {
227+ m_OffsetPosition = offsetPosition ;
228+ m_OffsetPositionRotation = this . transform . rotation ;
229+ }
230+
231+ #endregion
187232 }
188233
189234}
0 commit comments