WienerWiener
  • はじめに
  • 競合比較
  • 価格・入手
  • FAQ
  • 向いているケース
  • ライセンス
  • Unity Asset版とStandalone版の違い
  • 簡易難読化・改ざん検知
  • 整合性検知・デバッグ
  • ローカライズ
  • バージョン管理
  • Google Sheets入力
  • Excel
  • YAML
  • 設定ファイル
  • データフォーマット
  • マスターデータコンバート
  • ValueOnlyフォーマット
  • スタートアップ
  • サンプル
  • Converter
  • YAML Editor
  • Setting Editor
  • 日本語
  • English
  • はじめに
  • 競合比較
  • 価格・入手
  • FAQ
  • 向いているケース
  • ライセンス
  • Unity Asset版とStandalone版の違い
  • 簡易難読化・改ざん検知
  • 整合性検知・デバッグ
  • ローカライズ
  • バージョン管理
  • Google Sheets入力
  • Excel
  • YAML
  • 設定ファイル
  • データフォーマット
  • マスターデータコンバート
  • ValueOnlyフォーマット
  • スタートアップ
  • サンプル
  • Converter
  • YAML Editor
  • Setting Editor
  • 日本語
  • English
  • サンプル

    • サンプル
    • 220万セルサンプルデータをコンバートする
    • アイテムマスターを作成する
    • ホットリロードを体験する
    • ユニットマスターを作成する
    • 報酬マスターを作成する
    • 装備マスターを作成する
    • ローカライズを体験する
    • 既存のYAMLにキーを追加する

ホットリロードを体験する

サンプル開始前の準備

  • Unityスタートアップが完了している
  • アイテムマスターを作成するが完了している

概要

このサンプルでは、Unityを再生したままアイテムマスターをコンバートし直し、Rキーでbasic.bytesを再読み込みして変更を確認します。

手順は次の通りです。

  1. ホットリロード用のC#コードを作成
  2. Unityの再生ボタンを押してログを確認
  3. Excelを開いてアイテムデータを書き換える
  4. Unity実行中にコンバート
  5. Rキーを押して書き換えを確認

Resources更新をUnityに認識させる

このサンプルではAssets/Resources/basic.bytesを読み込みます。Unity実行中にコンバートしたbasic.bytesをUnity側でも更新済みとして扱うため、Unityの自動更新を有効にしておきます。

Edit > Preferences > Asset Pipelineを開き、Auto Refreshを有効にしてください。

注意

Auto Refreshが無効の場合、Unity実行中にAssets/Resources/basic.bytesが更新されても、Resources.Loadで古いアセットが読み込まれることがあります。 その場合は、後述のStreamingAssetsを使うEditor限定サンプルを使用してください。

C#コードを作成

アイテムマスターサンプルのSample.csを次のように変更します。起動時に一度ログを出力し、Rキーを押すたびにbasic.bytesを読み直して再出力します。

Sample.cs

using UnityEngine;
using Wiener;
using WienerLib;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif

public class Sample : MonoBehaviour
{
    private WienerManager _wm;

    void Start()
    {
        ReloadAndOutput();
    }

    void Update()
    {
        if (IsReloadKeyPressed())
        {
            ReloadAndOutput();
        }
    }

    bool IsReloadKeyPressed()
    {
#if ENABLE_INPUT_SYSTEM
        return Keyboard.current != null && Keyboard.current.rKey.wasPressedThisFrame;
#else
        return Input.GetKeyDown(KeyCode.R);
#endif
    }

    void ReloadAndOutput()
    {
        var textAsset = Resources.Load<TextAsset>("basic");
        if (textAsset == null)
        {
            Debug.LogError("basic.bytes was not found in Resources.");
            return;
        }

        try
        {
            _wm = new WienerManager();
            var result = _wm.LoadBasicPack(textAsset.bytes);
            if (result != Result.Success)
            {
                Debug.LogError($"Failed to load basic pack: {result}");
                return;
            }

            Debug.Log("---- Reload master data");
            OutputItem();
        }
        finally
        {
            Resources.UnloadAsset(textAsset);
        }
    }

    void OutputItem()
    {
        foreach (var item in _wm.Item.Values)
        {
            Debug.Log($"Id: {item.Id}, Name: {item.Name}, Value: {item.Value}");
        }
    }
}

Unity再生中に確認

Unityの再生ボタンを押す

Unityの再生ボタンを押して、Consoleにアイテムマスターのログが出力されることを確認します。

Image from alias

Excelを書き換える

Unityを再生したまま、Assets/Wiener/Data/excel/Item/Item.xlsxをExcelで開きます。

例として、Potion (S)のvalueを100から150に変更して保存します。

Image from alias

↓

Image from alias

Unity実行中にコンバート

Unityを再生したまま、Tools > Wiener > Open Converterを開きます。

Image from alias

Run Develop Binary Onlyを押下してコンバートを実行し、Assets/Resources/basic.bytesを更新します。

Image from alias

Rキーでリロード

Gameビューにフォーカスを合わせてRキーを押します。

Consoleに再度アイテムマスターが出力され、Excelで変更した値に変わっていることを確認してください。

Image from alias

StreamingAssetsを使うサンプル

Resourcesの自動更新を使いたくない場合は、StreamingAssetsからbasic.bytesを読み込む方法もあります。

StreamingAssetsは本番環境でも使用できます。ただし、AndroidではUnityWebRequestでアクセスする必要があるなど、実行環境によって読み込み方法が異なります。Resources.Loadはどの環境でも同じ呼び出し方で読み込めるため、Wienerの基本サンプルではResourcesを推奨しています。

ここでは、Unity Editorで確認するための直接読み込みコードを紹介します。

この方法ではConverterのbytes output directory (basic.bytes)をAssets/StreamingAssetsに変更してからコンバートします。

Assets
+-- Resources
+-- StreamingAssets
|   +-- basic.bytes
+-- Scenes
+-- Scripts

Sample.cs

using System.IO;
using UnityEngine;
using Wiener;
using WienerLib;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif

public class Sample : MonoBehaviour
{
    private WienerManager _wm;

    void Start()
    {
        ReloadAndOutput();
    }

    void Update()
    {
        if (IsReloadKeyPressed())
        {
            ReloadAndOutput();
        }
    }

    bool IsReloadKeyPressed()
    {
#if ENABLE_INPUT_SYSTEM
        return Keyboard.current != null && Keyboard.current.rKey.wasPressedThisFrame;
#else
        return Input.GetKeyDown(KeyCode.R);
#endif
    }

    void ReloadAndOutput()
    {
#if UNITY_EDITOR
        var path = Path.Combine(Application.streamingAssetsPath, "basic.bytes");
        if (!File.Exists(path))
        {
            Debug.LogError($"basic.bytes was not found: {path}");
            return;
        }

        var bytes = File.ReadAllBytes(path);
        _wm = new WienerManager();
        var result = _wm.LoadBasicPack(bytes);
        if (result != Result.Success)
        {
            Debug.LogError($"Failed to load basic pack: {result}");
            return;
        }

        Debug.Log("---- Reload master data");
        OutputItem();
#else
        Debug.LogError("This sample reads StreamingAssets directly only in Unity Editor. Use a platform-specific loading method for runtime builds.");
#endif
    }

    void OutputItem()
    {
        foreach (var item in _wm.Item.Values)
        {
            Debug.Log($"Id: {item.Id}, Name: {item.Name}, Value: {item.Value}");
        }
    }
}

ヒント

Unity EditorではStreamingAssets内のファイルを直接読み込めるため、UnityのResourcesアセット更新タイミングに依存せずに確認できます。

最終更新:: 2026/06/16 19:09
Contributors: artisan-sawasaka
Prev
アイテムマスターを作成する
Next
ユニットマスターを作成する