LoginSignup
3
0

More than 3 years have passed since last update.

Unity:Addressable でコンテンツをダウンロード

Last updated at Posted at 2021-01-24

Addresablesでコンテンツをサーバからダウンロードする方法

環境

OS macOS 10.15.7
Unity 2019.4.2f1
Addressable 1.16.15


PackageManagerからAdressablesをインストール

スクリーンショット 2021-01-21 13.52.57.png

WindowメニューからAsset Management->Addressables->Groupsを選択
スクリーンショット 2021-01-21 13.54.11.png

Create Addressables Settingsをクリック
スクリーンショット 2021-01-21 13.54.26.png

オブジェクトを配置する。オブジェクトは一度ProjectにドラッグしPrefabにする。この例では「Object」と名前をつけた。
PrefabにしたオブジェクトはHierarchyから削除する。
PrefabはAddressableにチェックを入れる。
スクリーンショット 2021-01-21 13.59.33.png

カラのGameObjectを生成し、その中に下記のスクリプトを記述する。ここではファイル名を「LoadScript」とした。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.AddressableAssets; 
using UnityEngine.ResourceManagement.AsyncOperations;

public class LoadScript : MonoBehaviour

{
    public AssetReference reference;

    // Start is called before the first frame update
    void Start()
    {
        reference.InstantiateAsync();
    }

}

上記のスクリプトのInspecterには下図のようなUIが表示されるので、リモートからロードするPrefabを選択する。
スクリーンショット 2021-01-21 14.04.39.png
上記のUIがInspectorに表示されない場合は、Project WindowでRefleshする。
スクリーンショット 2021-01-21 14.04.21.png

AdressableAssetSettingのInspectorでCatalogの設定をおこなう。
Assets>AddresableAssetsDataの中にあるAdressableAssetSettingをクリックしてInspectorを表示する。
スクリーンショット 2021-01-21 14.27.20.png

「Build Remote Catalog」にチェックを入れる。
「Build Remote Caralog」はRemoteBuildPathを選択。
「LoadPath」はRemoteLodePathを選択。
ここではlocalhostのStandaloneOSXフォルダを参照するようになっている。
スクリーンショット 2021-01-21 14.27.08.png

LoadPathのURLを変更する際にはWindow>Addressable Management>Addresbles>Profilesを開きRemoteLoadPathのURLを変更する。
スクリーンショット 2021-01-22 22.20.10.png
スクリーンショット 2021-01-22 22.16.29.png

リモートサーバにアップするファイルのビルドを行う。
Play Mode ScriptのUse Existing Buildを選択
スクリーンショット 2021-01-21 14.07.52.png
Build>New Build> Default Build Scriptを選択肢ビルドする。
スクリーンショット 2021-01-22 22.24.38.png

プロジェクトのフォルダ内にSarverDataフォルダが出来ているはず。
その中にBuildTarget名のフォルダをアプリが参照するディレクトリにコピーする。
スクリーンショット 2021-01-22 22.28.26.png
macOSの場合httpServerが/Library/WebServer/Documentsを参照するので下記の様になる
スクリーンショット 2021-01-22 22.35.34.png

最後にアプリをBuild and Runを実行する。

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