add
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEditorHelper
|
||||
{
|
||||
[CustomPropertyDrawer(typeof (LayerAttribute))]
|
||||
public class LayerPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Integer)
|
||||
{
|
||||
Debug.LogWarning("LayerAttribute can only be applied on integer properties/fields");
|
||||
return;
|
||||
}
|
||||
|
||||
property.intValue = EditorGUI.LayerField(position, property.name, property.intValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db7cad7f95703f84ea5d8b4baea7a483
|
||||
timeCreated: 1434825477
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEditorHelper
|
||||
{
|
||||
[CustomPropertyDrawer(typeof (LimitAttribute))]
|
||||
public class LimitPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Integer)
|
||||
{
|
||||
Debug.LogWarning("LimitAttribute can only be applied on integer properties/fields");
|
||||
return;
|
||||
}
|
||||
|
||||
LimitAttribute limiter = attribute as LimitAttribute;
|
||||
property.intValue = limiter.Limit(EditorGUI.IntField(position, property.name, property.intValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c031d8492d933e49b0bc44865d327aa
|
||||
timeCreated: 1434825477
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System.Reflection;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEditorHelper
|
||||
{
|
||||
[CustomPropertyDrawer(typeof (SortingLayerAttribute))]
|
||||
public class SortingLayerDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Integer)
|
||||
{
|
||||
Debug.LogWarning("SortingLayerAttributes can only be applied on integer properties/fields");
|
||||
return;
|
||||
}
|
||||
EditorGUI.LabelField(position, label);
|
||||
|
||||
position.x += EditorGUIUtility.labelWidth;
|
||||
position.width -= EditorGUIUtility.labelWidth;
|
||||
|
||||
string[] sortingLayerNames = GetSortingLayerNames();
|
||||
int[] sortingLayerIDs = GetSortingLayerIDs();
|
||||
|
||||
int sortingLayerIndex = Mathf.Max(0, System.Array.IndexOf(sortingLayerIDs, property.intValue));
|
||||
sortingLayerIndex = EditorGUI.Popup(position, sortingLayerIndex, sortingLayerNames);
|
||||
property.intValue = sortingLayerIDs[sortingLayerIndex];
|
||||
}
|
||||
|
||||
private string[] GetSortingLayerNames()
|
||||
{
|
||||
System.Type internalEditorUtilityType = typeof (InternalEditorUtility);
|
||||
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
return (string[]) sortingLayersProperty.GetValue(null, new object[0]);
|
||||
}
|
||||
|
||||
private int[] GetSortingLayerIDs()
|
||||
{
|
||||
System.Type internalEditorUtilityType = typeof (InternalEditorUtility);
|
||||
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerUniqueIDs", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
return (int[]) sortingLayersProperty.GetValue(null, new object[0]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3e77ff7706ee9c4a85b478eb23510fd
|
||||
timeCreated: 1434825477
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEditorHelper
|
||||
{
|
||||
[CustomPropertyDrawer(typeof (TagAttribute))]
|
||||
public class TagPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
{
|
||||
Debug.LogWarning("TagAttribute can only be applied on string properties/fields");
|
||||
return;
|
||||
}
|
||||
|
||||
property.stringValue = EditorGUI.TagField(position, property.name, property.stringValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32950be6beb9f3b4ca5419e5d71ec0ed
|
||||
timeCreated: 1434825476
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user