public override void OnInspectorGUI() { if (_avaliableModels == null || _avaliableModels.Count == 0) { EditorGUILayout.HelpBox("no model!", MessageType.Warning); return; } var temp = EditorKit.DrawTypeSelector("Model Type", _modelTypeProperty.stringValue, _avaliableModelTypes); if (temp != null) { _modelTypeProperty.stringValue = temp.Value.TypeString; DrawSerializeFields(temp.Value.Type); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { var specifyEnumTypeProp = serializedObject.FindProperty("_specifyEnumType"); EditorGUILayout.PropertyField(specifyEnumTypeProp); Type enumType = null; if (specifyEnumTypeProp.boolValue) { var enumTypeStringProperty = serializedObject.FindProperty("_enumTypeString"); var allEnumTypes = TypeUtil.GetAllTypes(t => t.IsEnum && t.GetCustomAttributes(typeof(MvpModelAttribute), true).Length != 0) .Select(t => new EditorKit.SerializedType(t)) .OrderBy(t => t.TypeString) .ToList(); if (allEnumTypes.Count == 0) { EditorGUILayout.HelpBox("No enum implement MvpModelAttribute", MessageType.Info); } else { var type = EditorKit.DrawTypeSelector("Select Enum Type", enumTypeStringProperty.stringValue, allEnumTypes); if (type != null) { enumTypeStringProperty.stringValue = type.Value.TypeString; enumType = type.Value.Type; } } } var graphic = ((Component)target).GetComponent <Graphic>(); var settingsListProperty = serializedObject.FindProperty("_settings"); if (EditorGUILayout.PropertyField(settingsListProperty, false)) { EditorGUI.indentLevel++; var size = EditorGUILayout.DelayedIntField("Size", settingsListProperty.arraySize); while (settingsListProperty.arraySize > size) { settingsListProperty.DeleteArrayElementAtIndex(size); } for (var i = 0; i < size; i++) { if (i >= settingsListProperty.arraySize) { settingsListProperty.InsertArrayElementAtIndex(i); } var elementProp = settingsListProperty.GetArrayElementAtIndex(i); var valueProp = elementProp.FindPropertyRelative("Value"); var colorProp = elementProp.FindPropertyRelative("ToSetColor"); EditorGUILayout.BeginHorizontal(); if (enumType == null) { valueProp.intValue = EditorGUILayout.IntField("Element " + i, valueProp.intValue); } else { var enumNames = Enum.GetNames(enumType); var enumValues = (int[])Enum.GetValues(enumType); var index = enumValues.ToList().FindIndex(t => t == valueProp.intValue); index = EditorGUILayout.Popup("Element " + i, index, enumNames); valueProp.intValue = enumValues[index]; } var oldColor = colorProp.colorValue; colorProp.colorValue = EditorGUILayout.ColorField(colorProp.colorValue); if (colorProp.colorValue != oldColor && graphic != null) { graphic.color = colorProp.colorValue; } if (graphic != null && GUILayout.Button("Set")) { graphic.color = colorProp.colorValue; graphic.enabled = !graphic.enabled; graphic.enabled = !graphic.enabled; } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } serializedObject.ApplyModifiedProperties(); }
//int _selectedPageIndex; public override void OnInspectorGUI() { //_selectedPageIndex = GUILayout.Toolbar(_selectedPageIndex, new string[] { "Settings", "Events" }, EditorStyles.miniButton); //EditorGUILayout.Space(); //Rect rect = EditorGUILayout.GetControlRect(false, 1f); //EditorGUI.DrawRect(rect, EditorStyles.label.normal.textColor * 0.5f); //EditorGUILayout.Space(); //if (_selectedPageIndex == 1) //{ // EditorGUILayout.PropertyField(serializedObject.FindProperty("_beforeReceiveEvent")); // EditorGUILayout.PropertyField(serializedObject.FindProperty("_afterReceiveEvent")); //} //else { var typeProperty = serializedObject.FindProperty("_dataType"); EditorGUILayout.PropertyField(typeProperty); Type binderInterfaceType = null; var arrayElementType = (ArrayElementTypeEnum)typeProperty.enumValueIndex; switch (arrayElementType) { case ArrayElementTypeEnum.Bool: binderInterfaceType = typeof(IMvpBoolBinder); break; case ArrayElementTypeEnum.String: binderInterfaceType = typeof(IMvpStringBinder); break; case ArrayElementTypeEnum.Float: binderInterfaceType = typeof(IMvpFloatBinder); break; case ArrayElementTypeEnum.Object: binderInterfaceType = typeof(IMvpObjectBinder); break; case ArrayElementTypeEnum.Custom: { var customElementTypeStringProp = serializedObject.FindProperty("_customElementTypeString"); if (_allBinderValueTypes.Count == 0) { EditorGUILayout.HelpBox("No custom type binder implemented.", MessageType.Warning); } else { var returnType = EditorKit.DrawTypeSelector("Custom Element Type", customElementTypeStringProp.stringValue, _allBinderValueTypes); if (returnType != null) { customElementTypeStringProp.stringValue = returnType.Value.TypeString; binderInterfaceType = typeof(IMvpCustomTypeBinder <>).MakeGenericType(returnType.Value.Type); } } } break; } if (binderInterfaceType != null) { var mainBinderProperty = serializedObject.FindProperty("_mainBinder"); var extendBindersProperty = serializedObject.FindProperty("_extendBinders"); //EditorGUILayout.BeginHorizontal(); //EditorGUILayout.PrefixLabel("Array Element Template"); mainBinderProperty.objectReferenceValue = EditorKit.DrawBinderField("Main Binder", mainBinderProperty.objectReferenceValue, binderInterfaceType); if (EditorGUILayout.PropertyField(extendBindersProperty, false)) { EditorGUI.indentLevel++; var size = EditorGUILayout.DelayedIntField("Size", extendBindersProperty.arraySize); while (extendBindersProperty.arraySize > size) { extendBindersProperty.DeleteArrayElementAtIndex(size); } for (var i = 0; i < size; i++) { if (i >= extendBindersProperty.arraySize) { extendBindersProperty.InsertArrayElementAtIndex(i); } var elementProp = extendBindersProperty.GetArrayElementAtIndex(i); elementProp.objectReferenceValue = EditorKit.DrawBinderField("Element " + i, elementProp.objectReferenceValue, binderInterfaceType); } EditorGUI.indentLevel--; } //EditorGUILayout.PropertyField(extendBindersProperty, true); //for(var i = 0; i < extendBindersProperty.arraySize; i++) //{ // var exbp = extendBindersProperty.GetArrayElementAtIndex(i); //} //EditorGUILayout.EndHorizontal(); } } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { var specifyEnumTypeProp = serializedObject.FindProperty("_specifyEnumType"); EditorGUILayout.PropertyField(specifyEnumTypeProp); Type enumType = null; if (specifyEnumTypeProp.boolValue) { var enumTypeStringProperty = serializedObject.FindProperty("_enumTypeString"); var allEnumTypes = TypeUtil.GetAllTypes(t => t.IsEnum && t.GetCustomAttributes(typeof(MvpModelAttribute), true).Length != 0) .Select(t => new EditorKit.SerializedType(t)) .OrderBy(t => t.TypeString) .ToList(); if (allEnumTypes.Count == 0) { EditorGUILayout.HelpBox("No enum implement MvpModelAttribute", MessageType.Info); } else { var type = EditorKit.DrawTypeSelector("Select Enum Type", enumTypeStringProperty.stringValue, allEnumTypes); if (type != null) { enumTypeStringProperty.stringValue = type.Value.TypeString; enumType = type.Value.Type; } } } var settingsListProperty = serializedObject.FindProperty("_eventSettings"); if (EditorGUILayout.PropertyField(settingsListProperty, false)) { EditorGUI.indentLevel++; var size = EditorGUILayout.DelayedIntField("Size", settingsListProperty.arraySize); while (settingsListProperty.arraySize > size) { settingsListProperty.DeleteArrayElementAtIndex(size); } for (var i = 0; i < size; i++) { if (i >= settingsListProperty.arraySize) { settingsListProperty.InsertArrayElementAtIndex(i); } var elementProp = settingsListProperty.GetArrayElementAtIndex(i); var valueProp = elementProp.FindPropertyRelative("Value"); var eventPorp = elementProp.FindPropertyRelative("Event"); if (enumType == null) { valueProp.intValue = EditorGUILayout.IntField("Element " + i, valueProp.intValue); } else { var enumNames = Enum.GetNames(enumType); var enumValues = (int[])Enum.GetValues(enumType); var index = enumValues.ToList().FindIndex(t => t == valueProp.intValue); index = EditorGUILayout.Popup("Element " + i, index, enumNames); valueProp.intValue = enumValues[index]; } EditorGUI.indentLevel++; var rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 5); rect.x += 15; EditorGUI.PropertyField(rect, eventPorp); EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { _selectedPageIndex = GUILayout.Toolbar(_selectedPageIndex, new string[] { "Settings", "Events" }, EditorStyles.miniButton); EditorGUILayout.Space(); Rect rect = EditorGUILayout.GetControlRect(false, 1f); EditorGUI.DrawRect(rect, EditorStyles.label.normal.textColor * 0.5f); EditorGUILayout.Space(); if (_selectedPageIndex == 1) { EditorGUILayout.PropertyField(serializedObject.FindProperty("_beforeReceiveEvent")); EditorGUILayout.PropertyField(serializedObject.FindProperty("_afterReceiveEvent")); } else { var typeProperty = serializedObject.FindProperty("_elementType"); EditorGUILayout.PropertyField(typeProperty); var templateProperty = serializedObject.FindProperty("_elementBinder"); Type templateInterfaceType = null; var arrayElementType = (ArrayElementTypeEnum)typeProperty.enumValueIndex; switch (arrayElementType) { case ArrayElementTypeEnum.Bool: templateInterfaceType = typeof(IMvpBoolBinder); break; case ArrayElementTypeEnum.String: templateInterfaceType = typeof(IMvpStringBinder); break; case ArrayElementTypeEnum.Float: templateInterfaceType = typeof(IMvpFloatBinder); break; case ArrayElementTypeEnum.Object: templateInterfaceType = typeof(IMvpObjectBinder); break; case ArrayElementTypeEnum.Custom: { var customElementTypeStringProp = serializedObject.FindProperty("_customElementTypeString"); if (_allBinderValueTypes.Count == 0) { EditorGUILayout.HelpBox("No custom type binder implemented.", MessageType.Warning); } else { var returnType = EditorKit.DrawTypeSelector("Custom Element Type", customElementTypeStringProp.stringValue, _allBinderValueTypes); if (returnType != null) { customElementTypeStringProp.stringValue = returnType.Value.TypeString; templateInterfaceType = typeof(IMvpCustomTypeBinder <>).MakeGenericType(returnType.Value.Type); } } } break; } if (templateInterfaceType != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Element Binder"); templateProperty.objectReferenceValue = EditorKit.DrawBinderField("", templateProperty.objectReferenceValue, templateInterfaceType); EditorGUILayout.EndHorizontal(); } } serializedObject.ApplyModifiedProperties(); }