forked from Shardstone/trail-into-darkness
added more utilty packges
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace InspectorToolkit {
|
||||
public class InfoAttribute : PropertyAttribute {
|
||||
public enum MessageType {
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public readonly UnityEditor.MessageType messageType;
|
||||
public readonly string message;
|
||||
#endif
|
||||
|
||||
public InfoAttribute(string message, MessageType messageType = MessageType.Info) {
|
||||
#if UNITY_EDITOR
|
||||
this.message = message;
|
||||
switch(messageType) {
|
||||
case MessageType.Error:
|
||||
this.messageType = UnityEditor.MessageType.Error;
|
||||
break;
|
||||
case MessageType.Warning:
|
||||
this.messageType = UnityEditor.MessageType.Warning;
|
||||
break;
|
||||
case MessageType.Info:
|
||||
default:
|
||||
this.messageType = UnityEditor.MessageType.Info;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace InspectorToolkit.Internal {
|
||||
using UnityEditor;
|
||||
|
||||
[CustomPropertyDrawer(typeof(InfoAttribute))]
|
||||
public class InfoAttributeDrawer : PropertyDrawer {
|
||||
private const float MESSAGEBOX_HEIGHT = 40f;
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
||||
return base.GetPropertyHeight(property, label) + MESSAGEBOX_HEIGHT;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
||||
var message = ((InfoAttribute)attribute).message;
|
||||
var messageType = ((InfoAttribute)attribute).messageType;
|
||||
|
||||
var boxPosition = new Rect(position.x, position.y, position.width, MESSAGEBOX_HEIGHT);
|
||||
EditorGUI.HelpBox(boxPosition, message, messageType);
|
||||
|
||||
var fieldPosition = new Rect(position.x, position.y + MESSAGEBOX_HEIGHT, position.width, 18f);
|
||||
EditorGUI.PropertyField(fieldPosition, property, label);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user