###前提・実現したいこと
現在オーディオ関係をまとめた自作クラスのPropertyDrawerを作成しそれをリストにして、インスペクターの拡張をしています。
インスペクタ上でボタンを押したとき、ループ再生や通常再生などが出来るようにする予定ですが、下の画像の様に、ボタンを押したとき、リスト全てのボタンが押された状態になってしまいます。
調べていたら、変数がリストになっていたのが原因だと分かりましたが、解決方法が分かりません。
インスペクター拡張が複雑になっていたので、シンプルなPropertyDrawerを作りました。
挙動としてはリストを使用しつつ、画像1の様にそれぞれボタンを押せるようにしたいです。
###該当のソースコード
テストコードはGitHubに公開しました。
こちらにプルリクエストしてもらっても大丈夫です。
よろしくお願い致します。
・自作した変数
[System.Serializable] public class Piyo { }
・上のクラスのPropertyDrawer
using UnityEngine; [System.Serializable] public class PiyoAttribute : PropertyAttribute { public bool isButtonOn = false; public PiyoAttribute() { } }
using UnityEngine; using UnityEditor; [CustomPropertyDrawer(typeof(PiyoAttribute))] public class PiyoDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { PiyoAttribute att = (PiyoAttribute)attribute; using (new EditorGUI.PropertyScope(position, label, property)) { var buttonLabelRect = new Rect(position) { width = position.width / 2.0f }; var buttonRect = new Rect(position) { x = position.width / 2.0f, width = position.width / 2.0f }; EditorGUI.LabelField(buttonLabelRect, "Test"); att.isButtonOn = GUI.Toggle(buttonRect, att.isButtonOn, att.isButtonOn ? "On" : "Off", GUI.skin.button); } } }
・インスペクター表示用
using System.Collections.Generic; using UnityEngine; public class Test : MonoBehaviour { [SerializeField, Piyo] private List<Piyo> piyo = new List<Piyo>(); }
###補足情報(言語/FW/ツール等のバージョンなど)
使用言語:C#
Unityのバージョン:Unity20171.1.p3
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/17 00:14