7
3

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 21

HoloLensアプリでOneDriveからファイルを開く #アセットアドカレ

Posted at

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

今日はUnityで作るHoloLensアプリから、OneDriveに保存しているファイルを開いてRuntimeで扱う方法を紹介します。

Windows Store Native 1.19 (Dec 19, 2016)

image

以下がOneDrive呼び出し箇所で、new[] { ".png", ".jpg" }の箇所でファイルを絞れる。選択後に result.ReadBytes()やresult.ReadText()でファイルのデータが取れるので、それをTextureに突っ込んだりして使います。

ExampleSceneManagerController.cs
    public void ShowFileOpenPicker()
    {
        WSANativeFilePicker.PickSingleFile("Select", WSAPickerViewMode.Thumbnail, WSAPickerLocationId.PicturesLibrary, new[] { ".png", ".jpg" }, (result) =>
        {
            if (result != null)
            {
#pragma warning disable 0219
                byte[] fileBytes = result.ReadBytes();
                string fileString = result.ReadText();
#pragma warning restore 0219
            }
        });
    }

参考 Air-TapでOneDrive開く

image

AirTapAction.cs
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.VR.WSA.Input;
using HoloToolkit.Unity;

[RequireComponent(typeof(GazeManager))]
public class AirTapAction : MonoBehaviour
{
	GestureRecognizer recognizer;
	
	public UnityEvent myEvent;
	
	void Start()
	{
		recognizer = new GestureRecognizer();
		recognizer.SetRecognizableGestures(GestureSettings.Tap);
		recognizer.TappedEvent += Recognizer_TappedEvent;
		recognizer.StartCapturingGestures();
	}
	
	void OnDestroy()
	{
		recognizer.StopCapturingGestures();
		recognizer.TappedEvent -= Recognizer_TappedEvent;
	}
	
	private void Recognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay)
	{
		OnTap();
	}
	
	void LateUpdate()
	{
#if UNITY_EDITOR
		if (Input.GetMouseButtonDown(0))
		{
			OnTap();
		}
#endif
	}
	private void OnTap()
	{
		if (myEvent != null)
			myEvent.Invoke();
	}
}

ちなみに

OneDriveがHoloLensにインストールされていないとインストールするように案内が出ます。よくできてる。
image

7
3
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
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?