private void DrawElement(Rect rect, int index, bool isActive, bool isFocused) { EditorGUI.indentLevel++; SerializedProperty childProperty = list.serializedProperty.GetArrayElementAtIndex(index); SerializedProperty prefabPropety = childProperty.FindPropertyRelative("prefab"); SerializedProperty viewNamePropety = childProperty.FindPropertyRelative("viewName"); bool isSetPrefab = prefabPropety.objectReferenceValue == null && string.IsNullOrEmpty(viewNamePropety.stringValue); EditorGUI.PropertyField(rect, childProperty, true); if (isSetPrefab && prefabPropety.objectReferenceValue != null && string.IsNullOrEmpty(viewNamePropety.stringValue)) { GameObject prefabObject = prefabPropety.objectReferenceValue as GameObject; ViewModelBinding viewModelBinding = prefabObject.GetComponent <ViewModelBinding>(); if (viewModelBinding != null) { viewNamePropety.stringValue = viewModelBinding.modelId; viewNamePropety.serializedObject.ApplyModifiedProperties(); } } EditorGUI.indentLevel--; }
public static void DrawPropertyBindingName(Rect rect, SerializedProperty property, GUIContent label, System.Type propertyType) { SerializedProperty parentBinding = property.serializedObject.FindProperty("parentBinding"); ViewModelBinding viewModelBindig = parentBinding.objectReferenceValue as ViewModelBinding; SerializedProperty modelUniqueId = property.serializedObject.FindProperty("modelUniqueId"); string parentName = viewModelBindig != null ? viewModelBindig.modelId : null; bool checkedModel = ModelReflection.instance.CheckModelProperty(parentName, modelUniqueId.stringValue); if (!checkedModel) { Color oldColor = GUI.color; GUI.color = Color.red; EditorGUI.LabelField(rect, label, new GUIContent("Not Propertys"), EditorStyles.popup); GUI.color = oldColor; } else { rect = EditorGUI.PrefixLabel(rect, label); if (GUI.Button(rect, property.stringValue, EditorStyles.popup)) { GenericMenu menu = new GenericMenu(); ModelReflection.instance.ForeachProperty(parentName, modelUniqueId.stringValue, (propertyName, type) => { if (propertyType == null || propertyType.IsAssignableFrom(type)) { menu.AddItem(new GUIContent(propertyName), propertyName == property.stringValue, () => { property.stringValue = propertyName; property.serializedObject.ApplyModifiedProperties(); }); } else { menu.AddDisabledItem(new GUIContent(propertyName)); } }); menu.DropDown(rect); } } }
private void RefreshBindings() { ViewModelBinding.ResetBindings(true); tcImages.SelectedTab = tabGeneratedImage; }
public override void OnInspectorGUI() { ViewModelBinding behavior = target as ViewModelBinding; serializedObject.Update(); EditorGUI.BeginChangeCheck(); SerializedProperty parentBinding = serializedObject.FindProperty("parentBinding"); EditorGUILayout.PropertyField(parentBinding); if (parentBinding.objectReferenceValue != null) { ViewModelBinding parent = parentBinding.objectReferenceValue as ViewModelBinding; if (!behavior.transform.IsChildOf(parent.transform)) { EditorGUILayout.HelpBox("The object is not parent transform.", MessageType.Error); } } EditorGUILayout.BeginHorizontal(); SerializedProperty modelUniqueId = serializedObject.FindProperty("modelUniqueId"); EditorGUILayout.PrefixLabel("Model"); if (switchModelSelected) { if (parentBinding.objectReferenceValue == null) { EditorGUILayout.PropertyField(modelUniqueId, GUIContent.none, null); } else if (GUILayout.Button(modelUniqueId.stringValue, EditorStyles.popup)) { GenericMenu menu = new GenericMenu(); menu.AddDisabledItem(new GUIContent("None")); ViewModelBinding parent = parentBinding.objectReferenceValue as ViewModelBinding; int index = ModelReflection.instance.IndexOfModel(parent.modelId); if (index != -1) { ModelReflection.instance.ForeachProperty(index, (name, type) => { if (typeof(IModel).IsAssignableFrom(type)) { menu.AddItem(new GUIContent(name), name == modelUniqueId.stringValue, () => { modelUniqueId.stringValue = name; modelUniqueId.serializedObject.ApplyModifiedProperties(); }); } }); } menu.ShowAsContext(); } } else { if (GUILayout.Button(modelUniqueId.stringValue)) { ShowAddMemberMenu(modelUniqueId); } } switchModelSelected = EditorGUILayout.Toggle(switchModelSelected, EditorStyles.radioButton, GUILayout.Width(15f)); EditorGUILayout.EndHorizontal(); SerializedProperty propertiesBinding = serializedObject.FindProperty("propertiesBinding"); EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(modelUniqueId.stringValue)); GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); EditorGUI.indentLevel++; DrawPropertiesBinding(propertiesBinding); EditorGUI.indentLevel--; EditorGUI.EndDisabledGroup(); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }