0
0

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 1 year has passed since last update.

[MR Dev Tips #3] アプリケーションの一時的なデータ、キャッシュを保存する方法

Last updated at Posted at 2023-07-27

はじめに

HoloLens 2 Dev Tips #3 ということで、今回は HoloLens 2 アプリケーション開発時に、一時的にローカルストレージにデータを保存しておきたいケースで使えるストレージパスの取得方法について紹介したいと思います。

開発環境

  • Unity 2020.3

内容

Unity が提供している Scripting API の Application.temporaryCachePath を利用すると、アプリを実行しているハードウェアプラットフォーム (ローカルストレージ) で、一次的なデータ保存が可能なディレクトリパスを返却してくれます。戻値の string は読み取り専用 (readonly) となっています。

public static string temporaryCachePath;
sample.cs
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        Debug.Log(Application.temporaryCachePath);
    }
}

この Application.temporaryCachePath は実行時にフォルダパス (文字列) を返却してくれるので、Unity Editor ( Windows PC ) と HoloLens 2 で、ファイルパスがどのように出力されるのかを見てみたいと思います。

Unity Editor (PC) で実行した場合

C:/Users/<UserName>/AppData/Local/Temp/<CompanyName>/<ProductName>

CompanyNameProductName は Project Settings > Player で設定している値となります。

HoloLens 2 で実行した場合

C:/Data/Users/<UserName>/AppData/Local/Packages/<PackageName>/TempState

以上、アプリケーションの一時的なデータ保存場所についてでした。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?