12 namespace Valve.VR.InteractionSystem
18 public Bounds meshBounds {
get;
private set; }
21 private MeshRenderer areaMesh;
22 private int tintColorId = 0;
23 private Color visibleTintColor = Color.clear;
24 private Color highlightedTintColor = Color.clear;
25 private Color lockedTintColor = Color.clear;
26 private bool highlighted =
false;
31 areaMesh = GetComponent<MeshRenderer>();
33 tintColorId = Shader.PropertyToID(
"_TintColor" );
42 visibleTintColor = Teleport.instance.areaVisibleMaterial.GetColor( tintColorId );
43 highlightedTintColor = Teleport.instance.areaHighlightedMaterial.GetColor( tintColorId );
44 lockedTintColor = Teleport.instance.areaLockedMaterial.GetColor( tintColorId );
49 public override bool ShouldActivate( Vector3 playerPosition )
56 public override bool ShouldMovePlayer()
63 public override void Highlight(
bool highlight )
67 highlighted = highlight;
71 areaMesh.material = Teleport.instance.areaHighlightedMaterial;
75 areaMesh.material = Teleport.instance.areaVisibleMaterial;
82 public override void SetAlpha(
float tintAlpha,
float alphaPercent )
84 Color tintedColor = GetTintColor();
85 tintedColor.a *= alphaPercent;
86 areaMesh.material.SetColor( tintColorId, tintedColor );
91 public override void UpdateVisuals()
95 areaMesh.material = Teleport.instance.areaLockedMaterial;
99 areaMesh.material = Teleport.instance.areaVisibleMaterial;
105 public void UpdateVisualsInEditor()
107 areaMesh = GetComponent<MeshRenderer>();
111 areaMesh.sharedMaterial = Teleport.instance.areaLockedMaterial;
115 areaMesh.sharedMaterial = Teleport.instance.areaVisibleMaterial;
121 private bool CalculateBounds()
123 MeshFilter meshFilter = GetComponent<MeshFilter>();
124 if ( meshFilter == null )
129 Mesh mesh = meshFilter.sharedMesh;
135 meshBounds = mesh.bounds;
141 private Color GetTintColor()
145 return lockedTintColor;
151 return highlightedTintColor;
155 return visibleTintColor;
165 public class TeleportAreaEditor : Editor
170 if ( Selection.activeTransform != null )
173 if ( teleportArea != null )
175 teleportArea.UpdateVisualsInEditor();
182 public override void OnInspectorGUI()
184 DrawDefaultInspector();
186 if ( Selection.activeTransform != null )
188 TeleportArea teleportArea = Selection.activeTransform.GetComponent<TeleportArea>();
189 if ( GUI.changed && teleportArea != null )
191 teleportArea.UpdateVisualsInEditor();