-
-
Save anchan828/4307873 to your computer and use it in GitHub Desktop.
自分だけのPropertyDrawerを作ろう! ref: http://qiita.com/kyusyukeigo/items/8be4cdef97496a68a39d
This file contains 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 SampleScript : MonoBehaviour { | |
public float hp; | |
void Update() | |
{ | |
Debug.Log( hp ); | |
} | |
} |
This file contains 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; | |
public class Range2Attribute : PropertyAttribute | |
{ | |
public float min; | |
public float max; | |
public Range2Attribute (float min, float max) | |
{ | |
this.min = min; | |
this.max = max; | |
} | |
} |
This file contains 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; | |
public class Range2AttributeExample : MonoBehaviour | |
{ | |
[Range2( 0f, 100f )] | |
public float hp; | |
} |
This file contains 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; | |
[CustomPropertyDrawer( typeof ( Range2Attribute ) )] | |
public class Range2Drawer : PropertyDrawer | |
{ | |
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) | |
{ | |
Range2Attribute range2Attribute = (Range2Attribute)attribute; | |
if (property.propertyType == SerializedPropertyType.Float) { | |
EditorGUI.Slider (position, property, range2Attribute.min, range2Attribute.max, label); | |
} | |
} | |
} |
This file contains 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 SampleScript : MonoBehaviour { | |
[Range( 0f, 100f )] | |
public float hp; | |
} |
This file contains 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; | |
public class SampleAttribute : PropertyAttribute | |
{ | |
public bool init = false; | |
public SampleAttribute () | |
{ | |
} | |
} |
This file contains 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; | |
[CustomPropertyDrawer(typeof(SampleAttribute))] | |
public class SampleDrawer : PropertyDrawer | |
{ | |
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) | |
{ | |
if (sampleAttribute.init == false) { | |
sampleAttribute.init = true; | |
return; | |
} | |
... | |
} | |
public override float GetPropertyHeight (SerializedProperty property, GUIContent label) | |
{ | |
if (sampleAttribute.init == false) { | |
return 0; | |
} | |
return base.GetPropertyHeight (property, label); | |
} | |
} |
This file contains 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; | |
public class SampleScript : MonoBehaviour | |
{ | |
[Range2( 0f, 100f )] | |
public float hp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment