Last active
May 7, 2017 06:48
-
-
Save jweimann/3606571755c5ed8f43b07138e6cb7a7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class PrimitiveCreator : MonoBehaviour | |
{ | |
private SteamVR_TrackedController _controller; | |
private PrimitiveType _currentPrimitiveType = PrimitiveType.Sphere; | |
private void OnEnable() | |
{ | |
_controller = GetComponent<SteamVR_TrackedController>(); | |
_controller.TriggerClicked += HandleTriggerClicked; | |
_controller.PadClicked += HandlePadClicked; | |
} | |
private void OnDisable() | |
{ | |
_controller.TriggerClicked -= HandleTriggerClicked; | |
_controller.PadClicked -= HandlePadClicked; | |
} | |
#region Primitive Spawning | |
private void HandleTriggerClicked(object sender, ClickedEventArgs e) | |
{ | |
SpawnCurrentPrimitiveAtController(); | |
} | |
private void SpawnCurrentPrimitiveAtController() | |
{ | |
var spawnedPrimitive = GameObject.CreatePrimitive(_currentPrimitiveType); | |
spawnedPrimitive.transform.position = transform.position; | |
spawnedPrimitive.transform.rotation = transform.rotation; | |
spawnedPrimitive.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); | |
if (_currentPrimitiveType == PrimitiveType.Plane) | |
spawnedPrimitive.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f); | |
} | |
#endregion | |
#region Primitive Selection | |
private void HandlePadClicked(object sender, ClickedEventArgs e) | |
{ | |
if (e.padY < 0) | |
SelectPreviousPrimitive(); | |
else | |
SelectNextPrimitive(); | |
} | |
private void SelectNextPrimitive() | |
{ | |
_currentPrimitiveType++; | |
if (_currentPrimitiveType > PrimitiveType.Quad) | |
_currentPrimitiveType = PrimitiveType.Sphere; | |
} | |
private void SelectPreviousPrimitive() | |
{ | |
_currentPrimitiveType--; | |
if (_currentPrimitiveType < PrimitiveType.Sphere) | |
_currentPrimitiveType = PrimitiveType.Quad; | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like this gist should be updated to work with Unity 5.6: