16
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity AssetsAdvent Calendar 2016

Day 24

HoloLensで俺のこの手が光ってうなる

Last updated at Posted at 2016-12-24

この記事は Unity Assets Advent Calendar 2016 24日目の記事になります。

今日は俺のこの手を光って唸らせる。

Ultimate VFX 2.6.2 (Dec 20, 2016)

image

HoloLensで自分の手の位置を認識する

  • HandPositionスクリプトを空のManagarゲームオブジェクトにアタッチ。
  • シーンにCubeを配置。Scaleは0.01にしてInspectorでHandObjectに設定しておく。
HandPosition.cs
using UnityEngine;
using System.Collections;
using UnityEngine.VR.WSA.Input;

public class HandPosition : MonoBehaviour {

	private Vector3 initPos;
	public GameObject HandObject;
	
	void Start() {
		InteractionManager.SourceUpdated += InteractionManager_SourceUpdated;
	}
	
	void InteractionManager_SourceUpdated(InteractionSourceState state) {
		Vector3 handPosition;
		if (state.source.kind == InteractionSourceKind.Hand && state.properties.location.TryGetPosition(out handPosition)) {
			HandObject.transform.position = initPos + handPosition;
		}
	}
	
}

HoloLensのハンドジェスチャーで手を光らせる

Ultimate VFXに含まれるよさげなエフェクトのプレハブをCubeの子に入れて完成。

HandPosition.csはAir-Tapを認識するようにし、HandObjectに指定したゲームオブジェクトの表示非表示をON/OFFするようにする。

HandPosition.cs(改)
using UnityEngine;
using System.Collections;
using UnityEngine.VR.WSA.Input;

public class HandPosition : MonoBehaviour {

	private Vector3 initPos;
	public GameObject HandObject;
	
	void Start() {
		InteractionManager.SourceUpdated += InteractionManager_SourceUpdated;
		InteractionManager.SourceLost += InteractionManager_SourceLost;
		InteractionManager.SourcePressed += InteractionManager_SourcePressed;
		InteractionManager.SourceReleased += InteractionManager_SourceReleased;
	}
	
	void InteractionManager_SourceUpdated(InteractionSourceState state) {
		Vector3 handPosition;
		if (state.source.kind == InteractionSourceKind.Hand && state.properties.location.TryGetPosition(out handPosition)) {
			HandObject.transform.position = initPos + handPosition;
		}
	}
	
	void InteractionManager_SourceLost(InteractionSourceState state) {
		ShiningFinger(false);
	}
	
	void InteractionManager_SourcePressed(InteractionSourceState state) {
		ShiningFinger(true);
	}
	
	void InteractionManager_SourceReleased(InteractionSourceState state) {
		ShiningFinger(false);
	}
	
	void ShiningFinger(bool isActive) {
		HandObject.SetActive(isActive);
	}
	
}
16
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?