예제 #1
0
	// Function to display properties in inspector, invokes setter for observable properties
	public void ExposeProperty(WMG_PropertyField field, string tooltip = "")
	{
		var emptyOptions = new GUILayoutOption[0];
		if (field.Type == SerializedPropertyType.Integer)
		{
			var oldValue = (int)field.GetValue();
			var newValue = EditorGUILayout.IntField(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
		else if (field.Type == SerializedPropertyType.Float)
		{
			var oldValue = (float)field.GetValue();
			var newValue = EditorGUILayout.FloatField(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
		else if (field.Type == SerializedPropertyType.Boolean)
		{
			var oldValue = (bool)field.GetValue();
			var newValue = EditorGUILayout.Toggle(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
		else if (field.Type == SerializedPropertyType.String)
		{
			var oldValue = (string)field.GetValue();
			var newValue = EditorGUILayout.TextField(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
		else if (field.Type == SerializedPropertyType.Vector2)
		{
			var oldValue = (Vector2)field.GetValue();
			var newValue = EditorGUILayout.Vector2Field(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
		else if (field.Type == SerializedPropertyType.Vector3)
		{
			var oldValue = (Vector3)field.GetValue();
			var newValue = EditorGUILayout.Vector3Field(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
		else if (field.Type == SerializedPropertyType.Enum)
		{
			var oldValue = (Enum)field.GetValue();
			var newValue = EditorGUILayout.EnumPopup(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
		else if (field.Type == SerializedPropertyType.Color)
		{
			var oldValue = (Color)field.GetValue();
			var newValue = EditorGUILayout.ColorField(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
		}
	}
예제 #2
0
	public void ExposeEnumMaskProperty(WMG_PropertyField field) {
		var emptyOptions = new GUILayoutOption[0];
		var oldValue = (Enum)field.GetValue();
		var newValue = EditorGUILayout.EnumMaskField(field.Name, oldValue, emptyOptions);
		if (oldValue != newValue)
			field.SetValue(newValue);
	}
예제 #3
0
//	public void ArrayGUIoc2<T>(WMG_List<T> observableCollection, string label, string name, SerializedObject serObj = serializedObject , EditorListOption options = EditorListOption.Default) {
//		bool showListLabel = (options & EditorListOption.ListLabel) != 0;
//		bool showListSize = (options & EditorListOption.ListSize) != 0;
//		SerializedProperty list = serObj.FindProperty(name);
//		
//		if (showListLabel) {
//			EditorGUILayout.PropertyField(list, new GUIContent(label));
//			EditorGUI.indentLevel += 1;
//		}
//		if (!showListLabel || list.isExpanded) {
//			int prevSize = list.arraySize;
//			if (showListSize) {
//				EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
//			}
//			// The size changed notify observableCollection of this change
//			if (prevSize != list.arraySize) {
//				if (Application.isPlaying) {
//					list.serializedObject.ApplyModifiedProperties ();
//					observableCollection.SizeChangedViaEditor();
//				}
//			}
//			
//			for (int i = 0; i < list.arraySize; i++) {
//				SerializedProperty prop = list.GetArrayElementAtIndex(i);
//				if (prop.propertyType == SerializedPropertyType.String) {
//					string prev = prop.stringValue;
//					EditorGUILayout.PropertyField(prop);
//					if (prev != prop.stringValue) {
//						list.serializedObject.ApplyModifiedProperties ();
//						observableCollection.ValueChangedViaEditor(i);
//					}
//				}
//				else if (prop.propertyType == SerializedPropertyType.Float) {
//					float prev = prop.floatValue;
//					EditorGUILayout.PropertyField(prop);
//					if (prev != prop.floatValue) {
//						list.serializedObject.ApplyModifiedProperties ();
//						observableCollection.ValueChangedViaEditor(i);
//					}
//				}
//				else if (prop.propertyType == SerializedPropertyType.Color) {
//					Color prev = prop.colorValue;
//					EditorGUILayout.PropertyField(prop);
//					if (prev != prop.colorValue) {
//						list.serializedObject.ApplyModifiedProperties ();
//						observableCollection.ValueChangedViaEditor(i);
//					}
//				}
//				else if (prop.propertyType == SerializedPropertyType.Vector2) {
//					Vector2 prev = prop.vector2Value;
//					EditorGUILayout.PropertyField(prop);
//					if (prev != prop.vector2Value) {
//						list.serializedObject.ApplyModifiedProperties ();
//						observableCollection.ValueChangedViaEditor(i);
//					}
//				}
//				else if (prop.propertyType == SerializedPropertyType.ObjectReference) {
//					UnityEngine.Object prev = prop.objectReferenceValue;
//					EditorGUILayout.PropertyField(prop);
//					if (prev != prop.objectReferenceValue) {
//						list.serializedObject.ApplyModifiedProperties ();
//						observableCollection.ValueChangedViaEditor(i);
//					}
//				}
//			}
//		}
//		if (showListLabel) {
//			EditorGUI.indentLevel -= 1;
//		}
//	}

	public bool ExposeAndReturnBool(WMG_PropertyField field, string tooltip = "") {
		var emptyOptions = new GUILayoutOption[0];
		if (field.Type == SerializedPropertyType.Boolean)
		{
			bool oldValue = (bool)field.GetValue();
			bool newValue = EditorGUILayout.Toggle(new GUIContent(field.Name, tooltip), oldValue, emptyOptions);
			if (oldValue != newValue)
				field.SetValue(newValue);
			return newValue;
		}
		return false;
	}
예제 #4
0
    public void ExposeEnumMaskProperty(WMG_PropertyField field)
    {
        var emptyOptions = new GUILayoutOption[0];
        var oldValue     = (Enum)field.GetValue();

                #if !UNITY_2017_3_OR_NEWER
        var newValue = EditorGUILayout.EnumMaskField(field.Name, oldValue, emptyOptions);
                #else
        var newValue = EditorGUILayout.EnumFlagsField(field.Name, oldValue, emptyOptions);
                #endif
        if (oldValue != newValue)
        {
            field.SetValue(newValue);
        }
    }