Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

この記事は 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

yuujii
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした