「Unity/Editor/inspector値更新」の版間の差分
提供: 初心者エンジニアの簡易メモ
| 行26: | 行26: | ||
</pre> | </pre> | ||
| − | + | SampleSceneUpdateEditor.cs | |
<pre> | <pre> | ||
using UnityEngine; | using UnityEngine; | ||
| 行32: | 行32: | ||
[CustomEditor(typeof(SampleScene))] | [CustomEditor(typeof(SampleScene))] | ||
| − | public class | + | public class SampleSceneUpdateEditor : Editor |
{ | { | ||
public override void OnInspectorGUI() | public override void OnInspectorGUI() | ||
2022年2月8日 (火) 11:36時点における版
Inspector更新サンプル
以下メンバを更新するサンプル
- testObjectに、TestObjectをいれる。
- numに、3をいれる。
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()
{
}
}
SampleSceneUpdateEditor.cs
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(SampleScene))]
public class SampleSceneUpdateEditor : 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();
}
}
