public static float CalculateHeight(IParentDrawer target) { float unfoldedness = target.Unfoldedness; if (unfoldedness > 0f) { var visibleMembers = target.VisibleMembers; int count = visibleMembers.Length; if (count > 0) { float membersHeight = 0f; for (int n = count - 1; n >= 0; n--) { membersHeight += visibleMembers[n].Height; } #if DEV_MODE && DEBUG_WHEN_UNFOLDED UnityEngine.Debug.Log("CalculateHeight(" + target + ") from " + count + " visible members: " + (target.HeaderHeight + membersHeight * unfoldedness + DrawGUI.RightPadding) + " with Unfolded=" + target.Unfolded + " , Unfoldedness=" + target.Unfoldedness + ", HeaderHeight=" + target.HeaderHeight); #elif DEV_MODE && DEBUG_WHEN_CHANGING if (unfoldedness < 1f) { UnityEngine.Debug.Log("CalculateHeight(" + target + ") from " + count + " visible members: " + (target.HeaderHeight + membersHeight * unfoldedness + DrawGUI.RightPadding) + " with Unfolded=" + target.Unfolded + " , Unfoldedness=" + target.Unfoldedness + ", HeaderHeight=" + target.HeaderHeight + ", DrawGUI.RightPadding=" + DrawGUI.RightPadding); } #endif return(target.HeaderHeight + membersHeight * unfoldedness + DrawGUI.RightPadding); } } #if DEV_MODE && DEBUG_WHEN_FOLDED UnityEngine.Debug.Log("CalculateHeight(" + target + ") returning HeaderHeight: " + target.HeaderHeight); #endif return(target.HeaderHeight); }
public void RestoreFoldedStateWhenDisposingDuringFiltering(IParentDrawer subject) { if (!hasFilter) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(!inspector.State.filter.HasFilter); #endif return; } if (foldedBeforeFiltering.Remove(subject) && subject.Unfolded) { var membs = subject.Members; for (int n = membs.Length - 1; n >= 0; n--) { var memb = membs[n] as IParentDrawer; if (memb != null) { RestoreFoldedStateWhenDisposingDuringFiltering(memb); } } subject.SetUnfolded(false, false); } }
/// <inheritdoc/> public override void OnParentAssigned(IParentDrawer newParent) { memberIndex = Array.IndexOf(newParent.Members, this); switch (memberIndex) { default: axisColor = DrawGUI.IsProSkin ? XAxisColorDark : XAxisColorLight; break; case 1: axisColor = DrawGUI.IsProSkin ? YAxisColorDark : YAxisColorLight; break; case 2: axisColor = DrawGUI.IsProSkin ? ZAxisColorDark : ZAxisColorLight; break; } var component = parent.Parent as IUnityObjectDrawer; if (component != null) { component.OnWidthsChanged += OnWidthChanged; } #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(memberIndex != -1, ToString() + ".OnParentAssigned: index in members " + StringUtils.ToString(newParent.Members) + " of parent " + newParent + " was -1"); Debug.Assert(newParent is ISnappable, ToString() + ".OnParentAssigned: parent " + newParent + " was not snappable"); Debug.Assert(newParent is TransformMemberBaseDrawer, ToString() + ".OnParentAssigned: parent " + newParent + " did not inherit from TransformMemberBaseDrawer"); #endif SnapIfSnappingEnabled(); }
/// <inheritdoc /> protected override void Setup(Component[] setTargets, IParentDrawer setParent, IInspector setInspector, Type setEditorType) { inspector = setInspector; hasExecuteMethodItems = base.HasExecuteMethodIcon && HasExecuteMethodMenuItems(); var firstTarget = setTargets[0]; if (!HeadlessMode && firstTarget != null && firstTarget.HasEnabledProperty()) { hasEnabledFlag = true; var monoBehaviour = firstTarget as MonoBehaviour; if (monoBehaviour != null) { //Unity doesn't show the enabled flag in the inspector unless //the Behaviour contains certain methods. However, it can be //useful to have it be there anyways for various reasons. createCustomEnabledFlag = !monoBehaviour.HasEnabledFlagInEditor(); #if DEV_MODE && DEBUG_CUSTOM_ENABLED_FLAG if (createCustomEnabledFlag) { Debug.Log(ToString() + " - Creating custom enabled flag for " + firstTarget.GetType()); } #endif } } base.Setup(setTargets, setParent, setInspector, setEditorType); #if DEV_MODE && DEBUG_ENABLED_FLAG Debug.Log(ToString() + " hasEnabledFlag: " + hasEnabledFlag); #endif }
/// <summary> /// Sets up the drawer so that it is ready to be used. /// LateSetup should be called right after this. /// </summary> /// <param name="setStyle"> GUIStyle inside which to draw members. </param> /// <param name="indentLevel"> How many levels of indentation to add when drawing members. </param> /// <param name="setDrawHeader"> Should the prefix label header be drawn for the dataset. </param> /// <param name="setValue"> The initial cached value of the drawers. </param> /// <param name="setValueType"> Type constraint for the value. </param> /// <param name="setMemberInfo"> LinkedMemberInfo for the field or property that these drawers represent. </param> /// <param name="setParent"> Drawer whose member these Drawer are. Can be null. </param> /// <param name="setLabel"> The label (name) of the field. Can be null. </param> /// <param name="setReadOnly"> True if Drawer should be read only. </param> private void Setup(GUIStyle setStyle, int indentLevel, bool setDrawHeader, object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly) { style = new GUIStyle(setStyle); style.fixedHeight = 0f; style.fixedWidth = 0f; style.stretchHeight = true; style.stretchWidth = true; appendIndentLevel = indentLevel; drawHeader = setDrawHeader; if (setValueType == null) { #if DEV_MODE Debug.LogWarning(GetType().Name + ".Setup called with null setValueType"); #endif setValueType = DrawerUtility.GetType(setMemberInfo, setValue); } // This is an important step, because parent is referenced by DebugMode parent = setParent; drawInSingleRow = DrawerUtility.CanDrawInSingleRow(setValueType, DebugMode); base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly); #if DEV_MODE && DEBUG_DRAW_IN_SINGLE_ROW if (drawInSingleRow) { Debug.Log(Msg(ToString(setLabel, setMemberInfo) + ".Setup with drawInSingleRow=", drawInSingleRow, ", type=", setValueType, ", DebugMode=", DebugMode)); } #endif }
/// <inheritdoc/> public override void OnParentAssigned(IParentDrawer newParent) { #if DEV_MODE && DEBUG_ON_PARENT_ASSIGNED Debug.Assert(Array.IndexOf(newParent.Members, this) != -1, ToString() + ".OnParentAssigned: index in members " + StringUtils.ToString(newParent.Members) + " of parent " + newParent + " was -1"); #endif #if UNITY_EDITOR if (EditorSettings.serializationMode != SerializationMode.ForceBinary) { var scene = gameObject.scene; if (!scene.IsValid()) { #if DEV_MODE Debug.Log("MissingScript OnParentAssigned: GameObject \"" + gameObject.name + "\" had no scene."); #endif } else { var path = scene.path; if (string.IsNullOrEmpty(path)) { #if DEV_MODE Debug.Log("MissingScript OnParentAssigned: Path of scene \"" + scene.name + "\" was empty."); #endif } else { var scenePath = FileUtility.LocalAssetsPathToFullPath(path); try { string sceneData = System.IO.File.ReadAllText(scenePath); int index = Array.IndexOf(newParent.Members, this); guid = TryGetGuidForMissingComponent(gameObject, index, sceneData); } catch (Exception e) { Debug.LogError("MissingScript.OnParentAssigned - File.ReadAllText " + e); guid = ""; } if (guid.Length > 0) { assetPath = guid.Length == 0 ? "" : AssetDatabase.GUIDToAssetPath(guid); monoScript = AssetDatabase.LoadAssetAtPath <MonoScript>(assetPath); } } } } #endif base.OnParentAssigned(newParent); if (memberBuildState != MemberBuildState.MembersBuilt && MembersAreVisible) { memberBuildState = MemberBuildState.BuildListGenerated; BuildMembers(); } }
private void Setup([NotNull] IInspector setInspector, IParentDrawer setParent, GUIContent setLabel) { nowEditingMembers = true; inspector = setInspector; hasFilter = setInspector.State.filter.HasFilter; base.Setup(setParent, setLabel); inspector.OnFilterChanging += OnFilterChanging; }
private void Setup(int setValue, int setMin, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly) { min = setMin; base.Setup(setValue < min ? min : setValue, typeof(int), setMemberInfo, setParent, setLabel, setReadOnly); if (string.IsNullOrEmpty(label.tooltip)) { label.tooltip = string.Concat("Value greater than or equal to ", StringUtils.ToString(min)); } }
/// <summary> /// Sets up the drawer so that it is ready to be used. /// LateSetup should be called right after this. /// </summary> /// <param name="setMemberInfo"> LinkedMemberInfo for the field or property that these drawers represent. </param> /// <param name="setParent"> Drawer whose member these Drawer are. Can be null. </param> /// <param name="setPrefixLabel"> The prefix label to precede the button. Can be null. </param> /// <param name="setButtonLabel"> Label to show on the button. </param> /// <param name="setGUIStyle"> GUIStyle to use when drawing the button. Can be null. </param> /// <param name="setReadOnly"> True if Drawer should be read only. </param> protected virtual void Setup(LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setPrefixLabel, GUIContent setButtonLabel, GUIStyle setGUIStyle, bool setReadOnly) { #if DEV_MODE && DEBUG_SETUP Debug.Log("MethodButton with setPrefixLabel=" + StringUtils.ToString(setPrefixLabel) + ", setButtonLabel=" + StringUtils.ToString(setButtonLabel)); #endif guiStyle = setGUIStyle; base.Setup(setMemberInfo, setParent, setPrefixLabel, setButtonLabel, setReadOnly); }
private void Setup(int value, int setMax, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly) { max = setMax; base.Setup(value > max ? max : value, typeof(int), setMemberInfo, setParent, setLabel, setReadOnly); if (string.IsNullOrEmpty(label.tooltip)) { label.tooltip = string.Concat("Value smaller than or equal to ", StringUtils.ToString(max)); } }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="value"> The starting cached value of the drawer. </param> /// <param name="memberInfo"> LinkedMemberInfo for the field, property or parameter that the drawer represents. Can be null. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="label"> The prefix label. </param> /// <param name="readOnly"> True if control should be read only. </param> /// <returns> The instance, ready to be used. </returns> public static FloatDrawer Create(float value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly) { FloatDrawer result; if(!DrawerPool.TryGet(out result)) { result = new FloatDrawer(); } result.Setup(value, typeof(float), memberInfo, parent, label, readOnly); result.LateSetup(); return result; }
private void Setup(int value, int min, int max, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool setReadOnly) { this.min = Mathf.Min(min, max); this.max = Mathf.Max(min, max); base.Setup(Mathf.Clamp(value, this.min, this.max), typeof(int), memberInfo, parent, label, setReadOnly); if (string.IsNullOrEmpty(label.tooltip)) { label.tooltip = string.Concat("Value between ", StringUtils.ToString(min), " and ", StringUtils.ToString(max)); } }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="label"> The prefix label. </param> /// <param name="setReadOnly"> True if control should be read only. </param> /// <returns> The instance, ready to be used. </returns> public static CategorizedComponentsDrawer Create(IParentDrawer parent, GUIContent label) { CategorizedComponentsDrawer result; if (!DrawerPool.TryGet(out result)) { result = new CategorizedComponentsDrawer(); } result.Setup(parent, label); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="text"> The header text. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <returns> The drawer instance, ready to be used. </returns> public static HeaderDrawer Create(string text, [CanBeNull] IParentDrawer parent) { HeaderDrawer result; if (!DrawerPool.TryGet(out result)) { result = new HeaderDrawer(); } result.Setup(text, parent); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="value"> The starting cached value of the drawer. </param> /// <param name="memberInfo"> LinkedMemberInfo for the field, property or parameter that the drawer represents. Can be null. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="label"> The prefix label. </param> /// <param name="readOnly"> True if control should be read only. </param> /// <returns> The instance, ready to be used. </returns> public static ScaleDrawer Create(Vector3 value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly) { ScaleDrawer result; if (!DrawerPool.TryGet(out result)) { result = new ScaleDrawer(); } result.Setup(value, typeof(Vector3), memberInfo, parent, label, readOnly); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="targets"> The targets that the drawer represent. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="inspector"> The inspector in which the IDrawer are contained. Can not be null. </param> /// <returns> The instance, ready to be used. </returns> public static RectTransformDrawer Create(Component[] targets, [CanBeNull] IParentDrawer parent, [NotNull] IInspector inspector) { RectTransformDrawer result; if (!DrawerPool.TryGet(out result)) { result = new RectTransformDrawer(); } result.Setup(targets, parent, inspector, Types.GetInternalEditorType("UnityEditor.RectTransformEditor")); result.LateSetup(); return(result); }
public static ClassDrawer Create([NotNull] Type setClassType, [CanBeNull] IParentDrawer parent, [NotNull] IInspector inspector) { ClassDrawer result; if (!DrawerPool.TryGet(out result)) { result = new ClassDrawer(); } result.Setup(setClassType, parent, GUIContentPool.Create(StringUtils.SplitPascalCaseToWords(StringUtils.ToStringSansNamespace(setClassType))), inspector); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="label"> Label with the text to shown in the box. </param> /// <param name="messageType"> Type of the message. </param> /// <param name="readOnly"> True if control should be read only. </param> /// <returns> The instance, ready to be used. </returns> public static BoxDrawer Create(IParentDrawer parent, GUIContent label, MessageType messageType, bool readOnly) { BoxDrawer result; if (!DrawerPool.TryGet(out result)) { result = new BoxDrawer(); } result.Setup(label.text, null, parent, label, messageType, readOnly); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="parent"> The parent drawers of the created drawers. Can be null. </param> /// <param name="inspector"> The inspector in which the IDrawer are contained. Can not be null. </param> /// <returns> The drawer instance, ready to be used. </returns> public static MissingScriptDrawer Create([NotNull] IParentDrawer parent, [NotNull] IInspector inspector) { MissingScriptDrawer result; if (!DrawerPool.TryGet(out result)) { result = new MissingScriptDrawer(); } result.Setup(ArrayPool <Component> .Create(1), parent, null, inspector); result.LateSetup(); return(result); }
public static GameObjectBoxDrawer Create(IParentDrawer parent, GUIContent label) { GameObjectBoxDrawer result; if (!DrawerPool.TryGet(out result)) { result = new GameObjectBoxDrawer(); } result.Setup(parent, label); result.LateSetup(); return(result); }
/// <inheritdoc/> protected override void Setup(Component[] setTargets, IParentDrawer setParent, GUIContent setLabel, IInspector setInspector) { if (arrow == null) { var demoGraphics = FileUtility.LoadAssetByName <DemoGraphics>("Demo Graphics"); arrow = demoGraphics.arrow; } PowerInspectorDocumentation.ShowUrlIfWindowOpen(DocumentationPageUrl); base.Setup(setTargets, setParent, setLabel, setInspector); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="targets"> The targets that the drawer represent. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="inspector"> The inspector in which the IDrawer are contained. Can not be null. </param> /// <param name="setLabel"> The label to be shown in the header of the asset. If left null, label will be generated from class name. </param> /// <returns> The instance, ready to be used. </returns> public static CustomAssetDrawer Create(Object[] targets, IParentDrawer parent, [NotNull] IInspector inspector, GUIContent setLabel = null) { CustomAssetDrawer result; if (!DrawerPool.TryGet(out result)) { result = new CustomAssetDrawer(); } result.Setup(targets, parent, setLabel, inspector); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="targets"> The targets that the drawer represent. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="inspector"> The inspector in which the IDrawer are contained. Can not be null. </param> /// <returns> The instance, ready to be used. </returns> public static TerrainDrawer Create(Component[] targets, [CanBeNull] IParentDrawer parent, [NotNull] IInspector inspector) { TerrainDrawer result; if (!DrawerPool.TryGet(out result)) { result = new TerrainDrawer(); } result.Setup(targets, parent, inspector, null); result.LateSetup(); return(result); }
public static new AudioClipDrawer Create(Object[] targets, [CanBeNull] IParentDrawer parent, [NotNull] IInspector inspector) { AudioClipDrawer result; if (!DrawerPool.TryGet(out result)) { result = new AudioClipDrawer(); } result.Setup(targets, null, null, parent, inspector); result.LateSetup(); return(result); }
public static new MaterialDrawer Create(Object[] targets, [CanBeNull] IParentDrawer parent, [NotNull] IInspector inspector) { MaterialDrawer result; if (!DrawerPool.TryGet(out result)) { result = new MaterialDrawer(); } result.Setup(targets, targets, typeof(MaterialEditor), parent, inspector); result.LateSetup(); return(result); }
/// <inheritdoc/> public override void Setup([NotNullOrEmpty] GameObject[] setTargets, [CanBeNull] IParentDrawer setParent, [NotNull] IInspector setInspector) { if (arrow == null) { var demoGraphics = FileUtility.LoadAssetByName <DemoGraphics>("Demo Graphics"); arrow = demoGraphics.arrow; } base.Setup(setTargets, setParent, setInspector); PowerInspectorDocumentation.ShowUrlIfWindowOpen(DocumentationPageUrl); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="value"> The starting cached value of the drawer. </param> /// <param name="memberInfo"> LinkedMemberInfo for the field, property or parameter that the drawer represents. Can be null. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="label"> The prefix label. </param> /// <param name="readOnly"> True if control should be read only. </param> /// <returns> The instance, ready to be used. </returns> public static ObjectDrawer Create(object value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool setReadOnly) { ObjectDrawer result; if (!DrawerPool.TryGet(out result)) { result = new ObjectDrawer(); } result.Setup(value, DrawerUtility.GetType(memberInfo, value), memberInfo, parent, label, setReadOnly); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="targets"> The targets that the drawers represent. </param> /// <param name="parent"> The parent drawers of the created drawers. Can be null. </param> /// <param name="inspector"> The inspector in which the IDrawer are contained. Can not be null. </param> /// <param name="editorType"> The type of for the custom editor. </param> /// <returns> The drawer instance, ready to be used. </returns> public static CustomEditorComponentDrawer Create(Component[] targets, IParentDrawer parent, [NotNull] IInspector inspector, Type editorType = null) { CustomEditorComponentDrawer result; if (!DrawerPool.TryGet(out result)) { result = new CustomEditorComponentDrawer(); } result.Setup(targets, parent, inspector, editorType); result.LateSetup(); return(result); }
public static new ShaderDrawer Create(Object[] targets, [CanBeNull] IParentDrawer parent, [NotNull] IInspector inspector) { ShaderDrawer result; if (!DrawerPool.TryGet(out result)) { result = new ShaderDrawer(); } result.Setup(targets, targets, Types.GetInternalEditorType("UnityEditor.ShaderImporterInspector"), parent, inspector); result.LateSetup(); return(result); }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="height"> The height in pixels to occupy in the inspector. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <returns> The drawer instance, ready to be used. </returns> public static SpaceDrawer Create(float height, [CanBeNull] IParentDrawer parent) { SpaceDrawer result; if (!DrawerPool.TryGet(out result)) { result = new SpaceDrawer(); } result.Setup(height, parent); result.LateSetup(); return(result); }