public override void OnInspectorGUI() { Initialize(); PresentationParamater paramater = new PresentationParamater(_target, _presentationData, string.Empty, _targetType, new PresentationSite { BaseSite = null, BasePresentation = null, Base = null, PropertyInfo = null, SiteType = PresentationSiteType.None }, this); PresentationResult presentationResult = _presentation.OnInspectorGui(paramater); bool isChanged = false; if (presentationResult.Change.IsAnyPresentationChanged()) { ((FortScriptableObject)target).SavePresentationData(presentationResult.PresentationData); _presentationData = presentationResult.PresentationData; isChanged = true; } if (presentationResult.Change.IsAnyDataChanged()) { ((FortScriptableObject)target).Save(_target); isChanged = true; InternalTargetChanged(_target); } if (isChanged) { EditorUtility.SetDirty(target); } if (_repaintOnFinish) { _repaintOnFinish = false; Repaint(); } }
public override PresentationResult OnInspectorGui(PresentationParamater parameter) { GUIStyle guiStyle = new GUIStyle(); Change change = new Change(); object presentationData = parameter.PresentationData; if (presentationData != null && !((presentationData) is ArrayPresentationData)) { presentationData = null; } ArrayPresentationData arrayPresentationData; if (presentationData != null) { arrayPresentationData = (ArrayPresentationData)presentationData; _isFoldout = arrayPresentationData.IsFoldout; } else { arrayPresentationData = new ArrayPresentationData(); } arrayPresentationData.IsFoldout = EditorGUILayout.Foldout(_isFoldout, parameter.Title); change.IsPresentationChanged |= arrayPresentationData.IsFoldout != _isFoldout; _isFoldout = arrayPresentationData.IsFoldout; EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); object data = parameter.Instance; if (data == null) { data = Array.CreateInstance(parameter.DataType.GetElementType(), 0); change.IsDataChanged = true; } Array arrayData = (Array)data; Initialize(arrayData, parameter); if (_isFoldout) { EditorGUILayout.BeginVertical(guiStyle); GUI.SetNextControlName(_sizeControlName); _elementSize = EditorGUILayout.IntField("Size", _elementSize); //Debug.Log(_elementSize); Event e = Event.current; if (e.keyCode == KeyCode.Return || GUI.GetNameOfFocusedControl() != _sizeControlName) { if (arrayData.Length != _elementSize) { Array newArray = Array.CreateInstance(parameter.DataType.GetElementType(), _elementSize); Presentation[] arrayElementPresentations = _arrayElementPresentations; _arrayElementPresentations = new Presentation[_elementSize]; for (int i = 0; i < newArray.Length; i++) { if (i >= arrayData.Length) { newArray.SetValue(CreateNewElement(parameter, i), i); } else { newArray.SetValue(arrayData.GetValue(i), i); } } arrayData = newArray; for (int i = 0; i < _arrayElementPresentations.Length; i++) { if (i >= arrayElementPresentations.Length) { _arrayElementPresentations[i] = parameter.FortInspector.GetResolver().Resolve(new PresentationResolverParameter(parameter.DataType.GetElementType(), arrayData.GetValue(i), new PresentationSite { Base = parameter.Instance, BasePresentation = this, BaseSite = parameter.PresentationSite, SiteType = PresentationSiteType.ArrayElement })); } else { _arrayElementPresentations[i] = arrayElementPresentations[i]; } } change.IsDataChanged = true; } } EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); object[] elementPresentationData = new object[_arrayElementPresentations.Length]; change.ChildrenChange = new Change[arrayData.Length]; for (int i = 0; i < arrayData.Length; i++) { PresentationParamater guiParameter = new PresentationParamater(arrayData.GetValue(i), arrayPresentationData.ElementPresentationData.Length > i ? arrayPresentationData.ElementPresentationData[i] : null, string.Format("Element {0}", i), parameter.DataType.GetElementType(), new PresentationSite { Base = arrayData, BasePresentation = this, BaseSite = parameter.PresentationSite, SiteType = PresentationSiteType.ArrayElement }, parameter.FortInspector); PresentationResult presentationResult = _arrayElementPresentations[i].OnInspectorGui(guiParameter); arrayData.SetValue(presentationResult.Result, i); change.ChildrenChange[i] = presentationResult.Change; elementPresentationData[i] = presentationResult.PresentationData; } arrayPresentationData.ElementPresentationData = elementPresentationData; EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); return(new PresentationResult { Result = arrayData, Change = change, PresentationData = arrayPresentationData }); }
public override PresentationResult OnInspectorGui(PresentationParamater parameter) { GUIStyle guiStyle = new GUIStyle(); //EditorGUILayout.BeginVertical(); if (parameter.PresentationSite != null && parameter.PresentationSite.Base != null && parameter.DataType == parameter.PresentationSite.Base.GetType() && parameter.Instance == null) { return(OnCircularRefrence(parameter)); } bool isRoot = string.IsNullOrEmpty(parameter.Title); if (parameter.Instance != null && _objectType == null) { _objectType = parameter.Instance.GetType(); } else { _objectType = parameter.DataType; } Initialize(); //bool isChanged = false; Change change = new Change(); object presentationData = parameter.PresentationData; ConcretePresentationData concretePresentationData; if (presentationData != null && !((presentationData) is ConcretePresentationData)) { presentationData = null; } if (presentationData != null) { concretePresentationData = (ConcretePresentationData)presentationData; _isFoldout = concretePresentationData.IsFoldout; } else { presentationData = concretePresentationData = new ConcretePresentationData { IsFoldout = _isFoldout }; } if (!isRoot) { /* if (_isFoldout) * { * GUILayout.Space(-10f); * }*/ concretePresentationData.IsFoldout = EditorGUILayout.Foldout(_isFoldout, parameter.Title); change.IsPresentationChanged |= _isFoldout != concretePresentationData.IsFoldout; _isFoldout = concretePresentationData.IsFoldout; /* EditorGUILayout.BeginHorizontal(); * GUILayoutUtility.GetRect(3f, 6f);*/ } object data = parameter.Instance; if (data == null) { data = Activator.CreateInstance(_objectType); change.IsDataChanged = true; } if (isRoot || _isFoldout) { change.ChildrenChange = new Change[_presentationFieldInfos.Length]; int i = 0; foreach (PresentationField presentationField in _presentationFieldInfos) { EditorGUILayout.BeginHorizontal(guiStyle); if (!isRoot) { GUILayout.Space(FortInspector.ItemSpacing); } else { GUILayout.Space(0f); } EditorGUILayout.BeginVertical(guiStyle); if (!concretePresentationData.InnerPresentationData.ContainsKey(presentationField.PropertyInfo.Name)) { concretePresentationData.InnerPresentationData[presentationField.PropertyInfo.Name] = null; } object objectData = presentationField.PropertyInfo.GetValue(data, new object[0]); PresentationSite presentationSite = new PresentationSite { BasePresentation = this, Base = parameter.Instance, BaseSite = parameter.PresentationSite, PropertyInfo = presentationField.PropertyInfo, SiteType = PresentationSiteType.Property }; if (presentationField.Presentation == null) { PresentationResolverParameter resolverParameter = new PresentationResolverParameter(presentationField.PropertyInfo.PropertyType, objectData, presentationSite); presentationField.Presentation = parameter.FortInspector.GetResolver().Resolve(resolverParameter); } //PresentationParamater PresentationTitleAttribute presentationTitleAttribute = presentationField.PropertyInfo.GetCustomAttribute <PresentationTitleAttribute>(); string title = presentationTitleAttribute == null ? CamelCaseSplit.SplitCamelCase(presentationField.PropertyInfo.Name) : presentationTitleAttribute.Title; PresentationResult presentationResult = presentationField.Presentation.OnInspectorGui( new PresentationParamater(presentationField.PropertyInfo.GetValue(data, new object[0]), concretePresentationData.InnerPresentationData[presentationField.PropertyInfo.Name], title, presentationField.PropertyInfo.PropertyType, presentationSite, parameter.FortInspector)); presentationField.PropertyInfo.SetValue(data, presentationResult.Result, new object[0]); change.ChildrenChange[i] = presentationResult.Change; concretePresentationData.InnerPresentationData[presentationField.PropertyInfo.Name] = presentationResult.PresentationData; i++; EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } } if (!isRoot) { //EditorGUILayout.EndHorizontal(); } //EditorGUILayout.EndVertical(); return(new PresentationResult { Result = data, Change = change, PresentationData = presentationData }); }
public override PresentationResult OnInspectorGui(PresentationParamater parameter) { GUIStyle guiStyle = new GUIStyle(); if (_propertyInstanceResolver == null) { _propertyInstanceResolver = (IPropertyInstanceResolver) Activator.CreateInstance( parameter.PresentationSite.PropertyInfo.GetCustomAttribute <PropertyInstanceResolveAttribute> ().PropertyInstanceResolver); } Change change = new Change(); object presentationData = parameter.PresentationData; if (presentationData != null && !((presentationData) is PropertyResolvablePresentationData)) { presentationData = null; } PropertyResolvablePresentationData propertyResolvablePresentationData; if (presentationData != null) { propertyResolvablePresentationData = (PropertyResolvablePresentationData)presentationData; } else { propertyResolvablePresentationData = new PropertyResolvablePresentationData(); } bool oldFoldout = propertyResolvablePresentationData.IsFoldout; propertyResolvablePresentationData.IsFoldout = EditorGUILayout.Foldout(propertyResolvablePresentationData.IsFoldout, parameter.Title); change.IsPresentationChanged |= propertyResolvablePresentationData.IsFoldout != oldFoldout; object result = parameter.Instance; if (propertyResolvablePresentationData.IsFoldout) { InstanceResolverResult instanceResolverResult = _propertyInstanceResolver.ResolvePossibleData(parameter.PresentationSite.Base, parameter.Instance, parameter.PresentationSite.PropertyInfo); if (parameter.DataType.IsArray) { EditorGUILayout.BeginVertical(guiStyle); List <int> removedIndex = new List <int>(); object[] innerPresentationData = propertyResolvablePresentationData.PresentationDatas; if (innerPresentationData == null || innerPresentationData.Length == 0) { innerPresentationData = new object[instanceResolverResult.PresentableInstanceTokens.Length]; } object[] finalInnerPresentationData = new object[instanceResolverResult.PresentableInstanceTokens.Length]; for (int i = 0; i < instanceResolverResult.PresentableInstanceTokens.Length; i++) { finalInnerPresentationData[i] = i < innerPresentationData.Length ? innerPresentationData[i] : null; } object[] results = new object[instanceResolverResult.PresentableInstanceTokens.Length]; change.ChildrenChange = new Change[instanceResolverResult.PresentableInstanceTokens.Length]; for (int i = 0; i < instanceResolverResult.PresentableInstanceTokens.Length; i++) { EditorGUILayout.BeginVertical(guiStyle); EditorGUILayout.BeginHorizontal(guiStyle); EditorGUILayout.LabelField(instanceResolverResult.PresentableInstanceTokens[i].DisplayName); if (GUILayout.Button("-")) { removedIndex.Add(i); change.IsDataChanged = true; } EditorGUILayout.EndHorizontal(); if (instanceResolverResult.IsEditable) { PresentationSite presentationSite = new PresentationSite { BaseSite = parameter.PresentationSite, BasePresentation = this, Base = parameter.Instance, SiteType = PresentationSiteType.None }; Type elementType = instanceResolverResult.UseValueTypeForEdit ? instanceResolverResult.PresentableInstanceTokens[i].Value.GetType() : parameter.DataType.GetElementType(); Presentation presentation = parameter.FortInspector.GetResolver() .Resolve(new PresentationResolverParameter(elementType, instanceResolverResult.PresentableInstanceTokens[i].Value, presentationSite)); EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); PresentationResult presentationResult = presentation.OnInspectorGui( new PresentationParamater( instanceResolverResult.PresentableInstanceTokens[i].Value, finalInnerPresentationData[i], string.Format("Element {0}", i), elementType, presentationSite, parameter.FortInspector)); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); results[i] = presentationResult.Result; finalInnerPresentationData[i] = presentationResult.PresentationData; change.ChildrenChange[i] = presentationResult.Change; } EditorGUILayout.EndVertical(); } propertyResolvablePresentationData.PresentationDatas = finalInnerPresentationData; object addObject = null; if (instanceResolverResult.PossibleInstanceTokens.Length > 0) { int selectedIndex = EditorGUILayout.Popup("New Element", 0, new[] { "None" }.Concat( instanceResolverResult.PossibleInstanceTokens.Select(token => token.DisplayName)) .ToArray()); if (selectedIndex != 0) { addObject = instanceResolverResult.PossibleInstanceTokens[selectedIndex - 1].Value; change.IsDataChanged = true; } } int firstArraySize = parameter.Instance is Array ? ((Array)parameter.Instance).Length : 0; int arraySize = firstArraySize - removedIndex.Count + (addObject != null ? 1 : 0); result = parameter.Instance; if (result == null || arraySize != firstArraySize) { result = Array.CreateInstance(parameter.DataType.GetElementType(), arraySize); } Array array = (Array)result; int resultIndex = 0; for (int i = 0; i < instanceResolverResult.PresentableInstanceTokens.Length; i++) { if (removedIndex.Contains(i)) { continue; } array.SetValue(instanceResolverResult.PresentableInstanceTokens[i].Value, resultIndex); resultIndex++; } if (addObject != null) { array.SetValue(addObject, array.Length - 1); } EditorGUILayout.EndVertical(); } else { int selectedIndex = parameter.Instance == null || instanceResolverResult.PresentableInstanceTokens.Length == 0 ? 0 : instanceResolverResult.PossibleInstanceTokens.ToList().IndexOf(instanceResolverResult.PresentableInstanceTokens.Single()) + 1; EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); selectedIndex = EditorGUILayout.Popup("", selectedIndex, new[] { "None" }.Concat( instanceResolverResult.PossibleInstanceTokens.Select(token => token.DisplayName)) .ToArray()); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (selectedIndex == 0) { result = null; } else { result = instanceResolverResult.PossibleInstanceTokens[selectedIndex - 1].Value; } if (result != parameter.Instance) { change.IsDataChanged = true; } } } return(new PresentationResult { Result = result, Change = change, PresentationData = propertyResolvablePresentationData }); }
public override PresentationResult OnInspectorGui(PresentationParamater parameter) { GUIStyle guiStyle = new GUIStyle(); AbstractConcretePresentationData presentationData = parameter.PresentationData as AbstractConcretePresentationData ?? new AbstractConcretePresentationData(); Change change = new Change(); bool isFoldout = presentationData.IsFoldout; presentationData.IsFoldout = EditorGUILayout.Foldout(presentationData.IsFoldout, parameter.Title); change.IsPresentationChanged = isFoldout != presentationData.IsFoldout; object data = parameter.Instance; if (presentationData.IsFoldout) { Type[] possibleTypes; AbstractTypeChildResolverAttribute abstractTypeChildResolverAttribute = parameter.DataType.GetCustomAttribute <AbstractTypeChildResolverAttribute>(); if (abstractTypeChildResolverAttribute != null) { IAbstractTypeChildResolver abstractTypeChildResolver = (IAbstractTypeChildResolver) Activator.CreateInstance(abstractTypeChildResolverAttribute.ChildResolverType); possibleTypes = abstractTypeChildResolver.ResolveChildrenType(parameter.DataType, ResolvePresentationSiteProperties(parameter.PresentationSite)); } else { possibleTypes = TypeHelper.GetAllTypes(AllTypeCategory.Game) .Where(type => parameter.DataType.IsAssignableFrom(type) && !type.IsAbstract) .ToArray(); } int selectedIndex = 0; if (parameter.Instance != null) { selectedIndex = possibleTypes.ToList().IndexOf(parameter.Instance.GetType()) + 1; } EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); selectedIndex = EditorGUILayout.Popup("Class Type", selectedIndex, new[] { "None" }.Concat(possibleTypes.Select(type => { PresentationTitleAttribute presentationTitleAttribute = type.GetCustomAttribute <PresentationTitleAttribute>(); return(presentationTitleAttribute == null ? CamelCaseSplit.SplitCamelCase(type.Name) : presentationTitleAttribute.Title); })).ToArray()); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); object oldData = data; bool changed = false; if (selectedIndex > 0) { if (data == null || data.GetType() != possibleTypes[selectedIndex - 1]) { data = Activator.CreateInstance(possibleTypes[selectedIndex - 1]); changed = true; } } else { data = null; } if (data != oldData) { change.IsDataChanged = true; } //object presentationData = parameter.PresentationData; if (data != null) { PresentationSite presentationSite = new PresentationSite { BaseSite = parameter.PresentationSite, BasePresentation = this, Base = parameter.Instance, SiteType = PresentationSiteType.None }; if (_presentation == null || changed) { _presentation = parameter.FortInspector.GetResolver() .Resolve(new PresentationResolverParameter(possibleTypes[selectedIndex - 1], data, presentationSite)); } EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); PresentationResult presentationResult = _presentation.OnInspectorGui(new PresentationParamater(data, presentationData.InnerPresentationData, string.Empty, possibleTypes[selectedIndex - 1], presentationSite, parameter.FortInspector)); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); presentationData.InnerPresentationData = presentationResult.PresentationData; data = presentationResult.Result; change.ChildrenChange = new[] { presentationResult.Change }; } } return(new PresentationResult { Change = change, PresentationData = presentationData, Result = data }); }