Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?

More than 3 years have passed since last update.

@yuujii

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

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

3
Help us understand the problem. What is going on with this article?
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
3
Help us understand the problem. What is going on with this article?