Skip to content

Instantly share code, notes, and snippets.

@SatoshiRobatoFujimoto
Last active August 29, 2018 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SatoshiRobatoFujimoto/fb69facf8bbd242629b0e1cf986332ec to your computer and use it in GitHub Desktop.
Save SatoshiRobatoFujimoto/fb69facf8bbd242629b0e1cf986332ec to your computer and use it in GitHub Desktop.
ガチラボ vol.8
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule;
public class DrawingManager : MonoBehaviour, ISourceStateHandler, IInputHandler
{
IInputSource currentInputSource;
private uint id;
private bool isDrag = false;
private GameObject obj;
public GameObject cube;
// Use this for initialization
void Start()
{
InputManager.Instance.PushFallbackInputHandler(gameObject);
}
// Update is called once per frame
void Update()
{
if (isDrag)
{
Vector3 pos;
currentInputSource.TryGetGripPosition(id, out pos);
obj.transform.position = pos;
}
}
public void OnInputDown(InputEventData eventData)
{
currentInputSource = eventData.InputSource;
id = eventData.SourceId;
Vector3 pos;
currentInputSource.TryGetGripPosition(id, out pos);
cube.transform.position = pos;
obj = GameObject.Instantiate(cube);
isDrag = true;
Debug.Log("Down");
}
public void OnInputUp(InputEventData eventData)
{
obj.transform.localScale = Vector3.zero;
isDrag = false;
Debug.Log("Up");
}
public void OnSourceDetected(SourceStateEventData eventData)
{
Debug.Log("Detected");
}
public void OnSourceLost(SourceStateEventData eventData)
{
isDrag = false;
Debug.Log("Lost");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment