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?

デバッグを快適に!Configファイル設計[Unity]

Posted at

はじめに

staticでbool値を参照してデバッグと本番で時短の切り替えできたら便利ですよね?
ただいちいちファイルに戻って値を直すのは面倒...
ということでエディタから編集できるようにします。

実装

こちらが設定ファイル。編集してお好きなbool値を設定しましょう。
僕は
・アニメーションを飛ばす
・デバッグ関連のを表示させる
・無敵モードにする
・ゲーム速度上昇
・エラー時自動スクショ
に機能を限定しました。ゲーム制作にわかなので色々大事なことが抜けてるかもしれません...!コメント欄にてご指摘してくだされば幸いです。

GameConfig.cs
/*
 * Copyright (c) DeepNapEngine
 * https://github.com/TrueRyoB
 */
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

namespace PoseQ.Config
{
    /// <summary>
    /// For a global reference in shifting to the debug mode!
    /// </summary>
    public class GameConfig : MonoBehaviour
    {
        public static bool SkipLongAnimations = false;
        public static bool ShowDebugInfo = false;
        public static bool GodModeEnabled = false;
        public static float PlayerSpeedMultiplier = 1.0f;
        public static bool AutoScreenshotOnError = false;
    }
}

そしてこちらがEditor拡張用のファイル。

GameConfigEditor.cs
/*
 * Copyright (c) DeepNapEngine
 * https://github.com/TrueRyoB
 */
using UnityEngine;
using UnityEditor;
using PoseQ.Config;

namespace PoseQ.Extensions.Editor
{
    /// <summary>
    /// To change the values of static variables on an inspector
    /// </summary>
    public class GameConfigEditor : EditorWindow
    {
        [MenuItem("Tools/Game Config Editor")]
        public static void ShowWindow()
        {
            GetWindow<GameConfigEditor>("Game Config");
        }

        private void OnGUI()
        {
            GUILayout.Label("Debug Settings", EditorStyles.boldLabel);

            GameConfig.SkipLongAnimations =
                EditorGUILayout.Toggle("Skip Long Animations", GameConfig.SkipLongAnimations);
            GameConfig.ShowDebugInfo = 
                EditorGUILayout.Toggle("Show Debug Info", GameConfig.ShowDebugInfo);
            GameConfig.GodModeEnabled =
                EditorGUILayout.Toggle("God Mode Enabled", GameConfig.GodModeEnabled);
            GameConfig.AutoScreenshotOnError =
                EditorGUILayout.Toggle("Auto Screenshot On Error", GameConfig.AutoScreenshotOnError);
            GameConfig.PlayerSpeedMultiplier =
                EditorGUILayout.FloatField("Player Speed Multiplier", GameConfig.PlayerSpeedMultiplier);

            if (GUILayout.Button("Reset to Defaults"))
            {
                GameConfig.SkipLongAnimations = false;
                GameConfig.ShowDebugInfo = false;
                GameConfig.GodModeEnabled = false;
                GameConfig.AutoScreenshotOnError = false;
                GameConfig.PlayerSpeedMultiplier = 1.0f;
            }
        }
    }
}

結果

もし何もエラーが起きなければ、上のバー(?)にてこれが出てきます。
ここから数値をいい感じに弄れるといった具合です。
Screenshot 2025-04-26 at 11.37.17.png

まとめ

自動スクショとかの実装はちょっと後回しにしてますが、リマインドしてくだされば記事更新しに戻るので遠慮なくご連絡ください。
お疲れ様でした!

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?