「Unity/Editor/inspector値更新」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「SampleScene.cs <pre> using UnityEngine; public class SampleScene : MonoBehaviour { [SerializeField] GameObject testView; [SerializeField] int num; // Start i...」) |
|||
行5: | 行5: | ||
public class SampleScene : MonoBehaviour | public class SampleScene : MonoBehaviour | ||
{ | { | ||
− | [SerializeField] GameObject | + | [SerializeField] GameObject testObject; |
[SerializeField] int num; | [SerializeField] int num; | ||
// Start is called before the first frame update | // Start is called before the first frame update | ||
行33: | 行33: | ||
serializedObject.Update(); | serializedObject.Update(); | ||
− | var | + | var testObject = serializedObject.FindProperty("testObject"); |
var num = serializedObject.FindProperty("num"); | var num = serializedObject.FindProperty("num"); | ||
num.intValue = 3; | num.intValue = 3; | ||
− | + | testObject.objectReferenceValue = GameObject.Find("TestObject"); | |
− | EditorGUILayout.PropertyField( | + | EditorGUILayout.PropertyField(testObject); |
EditorGUILayout.PropertyField(num); | EditorGUILayout.PropertyField(num); | ||
2022年2月7日 (月) 20:12時点における版
SampleScene.cs
using UnityEngine; public class SampleScene : MonoBehaviour { [SerializeField] GameObject testObject; [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 testObject = serializedObject.FindProperty("testObject"); var num = serializedObject.FindProperty("num"); num.intValue = 3; testObject.objectReferenceValue = GameObject.Find("TestObject"); EditorGUILayout.PropertyField(testObject); EditorGUILayout.PropertyField(num); serializedObject.ApplyModifiedProperties(); } }