public Presentation Resolve(PresentationResolverParameter parameter) { Type type = parameter.DataType;// parameter.Instance == null ? parameter.DataType : parameter.Instance.GetType(); Presentation presentation; if (parameter.PresentationSite.SiteType == PresentationSiteType.Property && parameter.PresentationSite.PropertyInfo.GetCustomAttribute <InspectorAttribute>() != null) { Type presentationType = TypeHelper.GetAllTypes(AllTypeCategory.Editor) .First( type1 => string.Format("{0}.{1}", type1.Namespace, type1.Name) == parameter.PresentationSite.PropertyInfo.GetCustomAttribute <InspectorAttribute>() .Presentation); presentation = (Presentation)Activator.CreateInstance(presentationType); } else if (parameter.PresentationSite.SiteType == PresentationSiteType.Property && parameter.PresentationSite.PropertyInfo.GetCustomAttribute <PropertyInstanceResolveAttribute>() != null) { return(new PropertyResolvablePresentation()); } else if (type == typeof(string)) { presentation = new StringPresentation(); } else if (_numericTypes.ContainsKey(type)) { presentation = new NumberPresentation(); } else if (type == typeof(bool)) { presentation = new BoolPresentation(); } else if (type.IsEnum) { presentation = new EnumPresentation(); } else if (type.IsArray) { presentation = new ArrayPresentation(); } else if (typeof(UnityEngine.Object).IsAssignableFrom(type)) { presentation = new UnityObjectPresentation(); } else if (typeof(AnimationCurve) == type) { presentation = new CurvePresentation(); } else { InspectorAttribute inspectorAttribute = type.GetCustomAttribute <InspectorAttribute>(); if (inspectorAttribute == null) { if (type.IsAbstract || type.IsInterface) { presentation = new AbstractConcretePresentation(); } else { presentation = new ConcretePresentation(); } } else { Type presentationType = TypeHelper.GetAllTypes(AllTypeCategory.Editor).First(type1 => string.Format("{0}.{1}", type1.Namespace, type1.Name) == type.GetCustomAttribute <InspectorAttribute>().Presentation); presentation = (Presentation)Activator.CreateInstance(presentationType); } } return(presentation); }
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 }); }