13 namespace Valve.VR.InteractionSystem
18 public enum TeleportPointType
25 public TeleportPointType teleportType = TeleportPointType.MoveToLocation;
27 public string switchToScene;
28 public Color titleVisibleColor;
29 public Color titleHighlightedColor;
30 public Color titleLockedColor;
31 public bool playerSpawnPoint =
false;
34 private bool gotReleventComponents =
false;
35 private MeshRenderer markerMesh;
36 private MeshRenderer switchSceneIcon;
37 private MeshRenderer moveLocationIcon;
38 private MeshRenderer lockedIcon;
39 private MeshRenderer pointIcon;
40 private Transform lookAtJointTransform;
41 private new Animation animation;
42 private Text titleText;
44 private Vector3 lookAtPosition = Vector3.zero;
45 private int tintColorID = 0;
46 private Color tintColor = Color.clear;
47 private Color titleColor = Color.clear;
48 private float fullTitleAlpha = 0.0f;
51 private const string switchSceneAnimation =
"switch_scenes_idle";
52 private const string moveLocationAnimation =
"move_location_idle";
53 private const string lockedAnimation =
"locked_idle";
57 public override bool showReticle
69 GetRelevantComponents();
71 animation = GetComponent<Animation>();
73 tintColorID = Shader.PropertyToID(
"_TintColor" );
75 moveLocationIcon.gameObject.SetActive( false );
76 switchSceneIcon.gameObject.SetActive( false );
77 lockedIcon.gameObject.SetActive( false );
86 player = Player.instance;
93 if ( Application.isPlaying )
95 lookAtPosition.x = player.hmdTransform.position.x;
96 lookAtPosition.y = lookAtJointTransform.position.y;
97 lookAtPosition.z = player.hmdTransform.position.z;
99 lookAtJointTransform.LookAt( lookAtPosition );
105 public override bool ShouldActivate( Vector3 playerPosition )
107 return ( Vector3.Distance( transform.position, playerPosition ) > 1.0f );
112 public override bool ShouldMovePlayer()
119 public override void Highlight(
bool highlight )
125 SetMeshMaterials(
Teleport.instance.pointHighlightedMaterial, titleHighlightedColor );
129 SetMeshMaterials(
Teleport.instance.pointVisibleMaterial, titleVisibleColor );
135 pointIcon.gameObject.SetActive( true );
140 pointIcon.gameObject.SetActive( false );
147 public override void UpdateVisuals()
149 if ( !gotReleventComponents )
156 SetMeshMaterials(
Teleport.instance.pointLockedMaterial, titleLockedColor );
158 pointIcon = lockedIcon;
160 animation.clip = animation.GetClip( lockedAnimation );
164 SetMeshMaterials(
Teleport.instance.pointVisibleMaterial, titleVisibleColor );
166 switch ( teleportType )
168 case TeleportPointType.MoveToLocation:
170 pointIcon = moveLocationIcon;
172 animation.clip = animation.GetClip( moveLocationAnimation );
175 case TeleportPointType.SwitchToNewScene:
177 pointIcon = switchSceneIcon;
179 animation.clip = animation.GetClip( switchSceneAnimation );
185 titleText.text = title;
190 public override void SetAlpha(
float tintAlpha,
float alphaPercent )
192 tintColor = markerMesh.material.GetColor( tintColorID );
193 tintColor.a = tintAlpha;
195 markerMesh.material.SetColor( tintColorID, tintColor );
196 switchSceneIcon.material.SetColor( tintColorID, tintColor );
197 moveLocationIcon.material.SetColor( tintColorID, tintColor );
198 lockedIcon.material.SetColor( tintColorID, tintColor );
200 titleColor.a = fullTitleAlpha * alphaPercent;
201 titleText.color = titleColor;
206 public void SetMeshMaterials( Material material, Color textColor )
208 markerMesh.material = material;
209 switchSceneIcon.material = material;
210 moveLocationIcon.material = material;
211 lockedIcon.material = material;
213 titleColor = textColor;
214 fullTitleAlpha = textColor.a;
215 titleText.color = titleColor;
220 public void TeleportToScene()
222 if ( !
string.IsNullOrEmpty( switchToScene ) )
224 Debug.Log(
"TeleportPoint: Hook up your level loading logic to switch to new scene: " + switchToScene );
228 Debug.LogError(
"TeleportPoint: Invalid scene name to switch to: " + switchToScene );
234 public void GetRelevantComponents()
236 markerMesh = transform.Find(
"teleport_marker_mesh" ).GetComponent<MeshRenderer>();
237 switchSceneIcon = transform.Find(
"teleport_marker_lookat_joint/teleport_marker_icons/switch_scenes_icon" ).GetComponent<MeshRenderer>();
238 moveLocationIcon = transform.Find(
"teleport_marker_lookat_joint/teleport_marker_icons/move_location_icon" ).GetComponent<MeshRenderer>();
239 lockedIcon = transform.Find(
"teleport_marker_lookat_joint/teleport_marker_icons/locked_icon" ).GetComponent<MeshRenderer>();
240 lookAtJointTransform = transform.Find(
"teleport_marker_lookat_joint" );
242 titleText = transform.Find(
"teleport_marker_lookat_joint/teleport_marker_canvas/teleport_marker_canvas_text" ).GetComponent<Text>();
244 gotReleventComponents =
true;
249 public void ReleaseRelevantComponents()
252 switchSceneIcon = null;
253 moveLocationIcon = null;
255 lookAtJointTransform = null;
261 public void UpdateVisualsInEditor()
263 if ( Application.isPlaying )
268 GetRelevantComponents();
272 lockedIcon.gameObject.SetActive( true );
273 moveLocationIcon.gameObject.SetActive( false );
274 switchSceneIcon.gameObject.SetActive( false );
276 markerMesh.sharedMaterial = Teleport.instance.pointLockedMaterial;
277 lockedIcon.sharedMaterial = Teleport.instance.pointLockedMaterial;
279 titleText.color = titleLockedColor;
283 lockedIcon.gameObject.SetActive( false );
285 markerMesh.sharedMaterial = Teleport.instance.pointVisibleMaterial;
286 switchSceneIcon.sharedMaterial = Teleport.instance.pointVisibleMaterial;
287 moveLocationIcon.sharedMaterial = Teleport.instance.pointVisibleMaterial;
289 titleText.color = titleVisibleColor;
291 switch ( teleportType )
293 case TeleportPointType.MoveToLocation:
295 moveLocationIcon.gameObject.SetActive( true );
296 switchSceneIcon.gameObject.SetActive( false );
299 case TeleportPointType.SwitchToNewScene:
301 moveLocationIcon.gameObject.SetActive( false );
302 switchSceneIcon.gameObject.SetActive( true );
308 titleText.text = title;
310 ReleaseRelevantComponents();
318 public class TeleportPointEditor : Editor
323 if ( Selection.activeTransform )
326 teleportPoint.UpdateVisualsInEditor();
332 public override void OnInspectorGUI()
334 DrawDefaultInspector();
336 if ( Selection.activeTransform )
338 TeleportPoint teleportPoint = Selection.activeTransform.GetComponent<TeleportPoint>();
341 teleportPoint.UpdateVisualsInEditor();