private void DrawViewModel() { using (var hor = new EditorGUILayout.HorizontalScope()) { var model = EditorGUILayout.ObjectField(new GUIContent("IViewModel"), connecton.viewModel, typeof(ScriptableObject), false); if (model != connecton.viewModel && model is Binding.IViewModel) { connecton.viewModel = model as ScriptableObject; } if (model == null) { connecton.viewModel = null; } if (GUILayout.Button("new", EditorStyles.miniButtonRight, GUILayout.Width(60))) { MvvmUtil.CreateNewViewModel((viewModel) => { connecton.viewModel = viewModel; }); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (defultviewModel == null) { defultviewModel = ScriptableObject.CreateInstance <ViewModel>(); } if (!(property.objectReferenceValue is Binding.IViewModel)) { property.objectReferenceValue = null; } if (property.propertyType == SerializedPropertyType.ObjectReference) { var rect = new Rect(position.x + position.width - 60, position.y, 60, position.height); if (GUI.Button(rect, "new", EditorStyles.miniButtonRight)) { var target = property.serializedObject.targetObject; var path = property.propertyPath; MvvmUtil.CreateNewViewModel((viewModel) => { var serializeObj = new SerializedObject(target); var prop = serializeObj.FindProperty(path); prop.objectReferenceValue = viewModel; serializeObj.ApplyModifiedProperties(); }); } rect = new Rect(position.x, position.y, position.width - 60, position.height); if (property.objectReferenceValue == null) { var viewModel = EditorGUI.ObjectField(rect, content, defultviewModel, typeof(ScriptableObject), false) as ScriptableObject; if (viewModel != defultviewModel && viewModel is IViewModel) { property.objectReferenceValue = viewModel; } if (viewModel == null) { property.objectReferenceValue = null; } } else { EditorGUI.PropertyField(rect, property, content); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var hide = (attribute as DefultViewModelAttribute).hide; if (hide && property.objectReferenceValue == null) { return; } if (!(property.objectReferenceValue is Binding.IViewModel)) { property.objectReferenceValue = null; } if (property.propertyType == SerializedPropertyType.ObjectReference) { var rect = new Rect(position.x + position.width - 60, position.y, 60, position.height); if (GUI.Button(rect, "new", EditorStyles.miniButtonRight)) { var target = property.serializedObject.targetObject; var path = property.propertyPath; MvvmUtil.CreateAssets(typeof(ViewModelContainer), (viewModel) => { var serializeObj = new SerializedObject(target); var prop = serializeObj.FindProperty(path); prop.objectReferenceValue = viewModel; serializeObj.ApplyModifiedProperties(); }); } rect = new Rect(position.x, position.y, position.width - 60, position.height); if (property.objectReferenceValue != null) { EditorGUI.PropertyField(rect, property, content); } } }