Unity/Editor/inspector値更新
提供: 初心者エンジニアの簡易メモ
2022年2月7日 (月) 20:11時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「SampleScene.cs <pre> using UnityEngine; public class SampleScene : MonoBehaviour { [SerializeField] GameObject testView; [SerializeField] int num; // Start i...」)
SampleScene.cs
using UnityEngine; public class SampleScene : MonoBehaviour { [SerializeField] GameObject testView; [SerializeField] int num; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } }
SampleSceneInspectorEditor.cs
using UnityEngine; using UnityEditor; [CustomEditor(typeof(SampleScene))] public class SampleSceneInspectorEditor : Editor { public override void OnInspectorGUI() { serializedObject.Update(); var testView = serializedObject.FindProperty("testView"); var num = serializedObject.FindProperty("num"); num.intValue = 3; testView.objectReferenceValue = GameObject.Find("TestView"); EditorGUILayout.PropertyField(testView); EditorGUILayout.PropertyField(num); serializedObject.ApplyModifiedProperties(); } }