private void HeaderUi(int level, bool hasError) { var color = MyTree.GetColor(level, Collapsed, () => new Color(0, 0, 0, 0)); BGEditorUtility.SwapGuiBackgroundColor(color, () => { BGEditorUtility.Horizontal(headerBoxStyle, () => { BGEditorUtility.Indent(1, () => { var content = new GUIContent(descriptor == null ? Cc.GetType().Name : descriptor.Name + " (" + BGEditorUtility.Trim(Cc.CcName, 10) + ")", descriptor == null ? null : descriptor.Description); var width = headerFoldoutStyle.CalcSize(content).x + 16; BGEditorUtility.SwapLabelWidth((int)width, () => { //foldout (we dont use layout version cause it does not support clickin on labels) Collapsed = EditorGUI.Foldout( GUILayoutUtility.GetRect(width, 16f), Collapsed, content, true, Cc.enabled ? headerFoldoutStyle : headerFoldoutStyleDisabled); }); }); GUILayout.FlexibleSpace(); // status(error or Ok) EditorGUI.LabelField(GUILayoutUtility.GetRect(70, 16, EditorStyles.label), hasError ? "Error" : "Ok.", hasError ? errorStyle : okStyle); //help url if (!String.IsNullOrEmpty(Cc.HelpURL)) { if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGHelp123, "Open help in the browser")) { Application.OpenURL(Cc.HelpURL); } EditorGUILayout.Separator(); } //change visibility if (BGEditorUtility.ButtonWithIcon(Cc.Hidden ? BGBinaryResources.BGHiddenOn123 : BGBinaryResources.BGHiddenOff123, "Hide/Show properties")) { Cc.Hidden = !Cc.Hidden; } EditorGUILayout.Separator(); //change name if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCcEditName123, "Change the name")) { BGCcChangeNameWindow.Open(Cc); } EditorGUILayout.Separator(); //add a child if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add a component, which is dependant on this component")) { BGCcAddWindow.Open(MyTree.Curve, type => { //cache some data var gameObject = Cc.Curve.gameObject; var oldComponents = gameObject.GetComponents <BGCc>(); var currentCcType = Cc.GetType(); //add var addedCc = AddComponent(MyTree.Curve, type); if (addedCc == null) { return; } //we need to process all the way up to the Cc and link Ccs to right (newly created) parents var parentClass = addedCc.GetParentClass(); var recursionLimit = 16; var cc = addedCc; while (parentClass != null && recursionLimit-- > 0) { if (currentCcType == parentClass) { //we reached the current Cc cc.SetParent(Cc); break; } //going up var possibleParents = gameObject.GetComponents(parentClass); var parent = possibleParents.Where(possibleParent => !oldComponents.Contains(possibleParent)).Cast <BGCc>().FirstOrDefault(); if (parent == null) { break; } cc.SetParent(parent); cc = parent; parentClass = cc.GetParentClass(); } }, Cc.GetType()); } EditorGUILayout.Separator(); //enable/disable if (BGEditorUtility.ButtonWithIcon(Cc.enabled ? BGBinaryResources.BGTickYes123 : BGBinaryResources.BGTickNo123, "Enable/disable a component")) { Enable(!Cc.enabled); } EditorGUILayout.Separator(); //delete if (!BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Remove this component")) { return; } //remove Delete(); EditorUtility.SetDirty(MyTree.Curve.gameObject); //not sure how to make proper exit throw new BGEditorUtility.ExitException(); }); }); }
private void HeaderUi(int level, bool hasError) { var color = MyTree.GetColor(level, Collapsed, () => new Color(0, 0, 0, 0)); BGEditorUtility.SwapGuiBackgroundColor(color, () => { BGEditorUtility.Horizontal(headerBoxStyle, () => { BGEditorUtility.Indent(1, () => { var content = new GUIContent(descriptor == null ? Cc.GetType().Name : descriptor.Name + " (" + BGEditorUtility.Trim(Cc.CcName, 10) + ")", descriptor == null ? null : descriptor.Description); var width = headerFoldoutStyle.CalcSize(content).x + 16; BGEditorUtility.SwapLabelWidth((int)width, () => { //foldout (we dont use layout version cause it does not support clickin on labels) Collapsed = EditorGUI.Foldout( GUILayoutUtility.GetRect(width, 16f), Collapsed, content, true, Cc.enabled ? headerFoldoutStyle : headerFoldoutStyleDisabled); }); }); GUILayout.FlexibleSpace(); // status(error or Ok) EditorGUI.LabelField(GUILayoutUtility.GetRect(70, 16, EditorStyles.label), hasError ? "Error" : "Ok.", hasError ? errorStyle : okStyle); //help url if (!String.IsNullOrEmpty(Cc.HelpURL)) { if (BGEditorUtility.ButtonWithIcon(helpTexture, "Open help in the browser")) { Application.OpenURL(Cc.HelpURL); } EditorGUILayout.Separator(); } //change name if (BGEditorUtility.ButtonWithIcon(changeNameTexture, "Change the name")) { BGCcChangeNameWindow.Open(Cc); } EditorGUILayout.Separator(); //add child if (BGEditorUtility.ButtonWithIcon(addTexture, "Add a component, which is dependant on this component")) { BGCcAddWindow.Open(MyTree.Curve, type => { var bgCc = AddComponent(MyTree.Curve, type); bgCc.SetParent(Cc); }, Cc.GetType()); } EditorGUILayout.Separator(); //enable/disable if (BGEditorUtility.ButtonWithIcon(Cc.enabled ? enabledTexture : disabledTexture, "Enable/disable a component")) { Enable(!Cc.enabled); } EditorGUILayout.Separator(); //delete if (!BGEditorUtility.ButtonWithIcon(deleteTexture, "Remove this component")) { return; } //remove Delete(); EditorUtility.SetDirty(MyTree.Curve.gameObject); //not sure how to make proper exit throw new ExitException(); }); }); }