Last active
December 27, 2015 03:09
-
-
Save Suzeep/7257058 to your computer and use it in GitHub Desktop.
カスタムインスペクタに配列を表示するサンプルコード。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Sample : MonoBehaviour | |
{ | |
// member | |
public int m_Count; | |
public int[] m_CountArray = new int[ 4 ]; | |
public float m_DeltaTime; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
[CustomEditor( typeof(Sample) )] | |
public class SampleInspector : Editor | |
{ | |
// OnInspectorGUI | |
public override void OnInspectorGUI() | |
{ | |
// update | |
this.serializedObject.Update(); | |
var sample = this.target as Sample; | |
{ | |
// count | |
sample.m_Count = EditorGUILayout.IntField( "Count", sample.m_Count ); | |
// array count | |
drawArrayProperty( "m_CountArray" ); | |
// delta time | |
sample.m_DeltaTime = EditorGUILayout.FloatField( "DeltaTime", sample.m_DeltaTime ); | |
} | |
} | |
// draw array property | |
private void drawArrayProperty( string prop_name ) | |
{ | |
EditorGUIUtility.LookLikeInspector(); | |
SerializedProperty prop = this.serializedObject.FindProperty( prop_name ); | |
EditorGUI.BeginChangeCheck(); | |
EditorGUILayout.PropertyField( prop, true ); | |
if( EditorGUI.EndChangeCheck() ){ | |
this.serializedObject.ApplyModifiedProperties(); | |
} | |
EditorGUIUtility.LookLikeControls(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment