public static void DrawHideButton(GrendelObjectData obj, Rect iconPosition) { if (sHideButtonStyle == null) { SetupStyles(); } bool hidden = obj.IsHidden; Color previousGUIColor = GUI.color; if (!obj.gameObject.activeInHierarchy) { sSubHiddenColor.a = kSubHiddenAlpha; GUI.color = sSubHiddenColor; } hidden = GUI.Toggle(iconPosition, hidden, hidden ? sInvisibleContent : sVisibleContent, sHideButtonStyle); if (hidden != obj.IsHidden) { obj.SetHidden(hidden, true); EditorUtility.SetDirty(obj); SceneView.RepaintAll(); } if (!obj.gameObject.activeInHierarchy) { GUI.color = previousGUIColor; } }
internal static GrendelObjectData EnsureObjectHasGrendelData(GameObject gameObject) { GrendelObjectData objectData = gameObject.GetComponent <GrendelObjectData>(); if (objectData == null) { objectData = (GrendelObjectData)gameObject.AddComponent <GrendelObjectData>(); //objectData.hideFlags = HideFlags.HideInInspector; //TODO: Remove for release, exposed for debugging EditorUtility.SetDirty(gameObject); } return(objectData); }
internal static void DrawLockButton(GrendelObjectData obj, Rect iconPosition) { if (obj == null) { return; } if (sLockButtonStyle == null) { sLockButtonStyle = sLockButtonStyleName; sLockedLabelStyle = new GUIStyle(GUI.skin.label); sLockedLabelStyle.fontStyle = FontStyle.Bold; } bool locked = obj.IsLocked; if (!locked && Event.current.type == EventType.Repaint) { GUI.enabled = false; sLockButtonStyle.Draw(iconPosition, false, false, false, false); GUI.enabled = true; } locked = GUI.Toggle(iconPosition, locked, string.Empty, locked ? sLockButtonStyle : GUIStyle.none); sLockButtonStyle.normal.textColor = Color.gray; if (locked != obj.IsLocked) { obj.SetLock(locked, true); EditorUtility.SetDirty(obj); SceneView.RepaintAll(); if (locked && Selection.Contains(obj)) { List <GameObject> selectedObjects = new List <GameObject>(Selection.gameObjects); selectedObjects.Remove(obj.gameObject); Selection.objects = selectedObjects.ToArray(); } } GUI.color = Color.white; }
internal static void SetObjectLock(GrendelObjectData objectData, bool isLocked, bool setRecursively) { bool previousStatus = objectData.IsLocked; if (isLocked) { if (!previousStatus) { objectData.gameObject.hideFlags |= (HideFlags.NotEditable); if (setRecursively && objectData.gameObject.transform.childCount > 0) { Transform[] children = objectData.gameObject.GetComponentsInChildren <Transform>(); foreach (Transform child in children) { child.gameObject.hideFlags |= (HideFlags.NotEditable); EnsureEntryExists(child.gameObject.GetInstanceID()).SetLock(true); } } } } else if (previousStatus) { objectData.gameObject.hideFlags &= ~(HideFlags.NotEditable); EnsureEntryExists(objectData.gameObject.GetInstanceID()).SetLock(false); if (setRecursively && objectData.gameObject.transform.childCount > 0) { Transform[] children = objectData.gameObject.GetComponentsInChildren <Transform>(); foreach (Transform child in children) { child.gameObject.hideFlags &= ~(HideFlags.NotEditable); EnsureEntryExists(child.gameObject.GetInstanceID()).SetLock(false); } } } SceneView.RepaintAll(); EditorApplication.RepaintHierarchyWindow(); HandleUtility.Repaint(); }
internal static void DrawLayerPreview(GrendelObjectData obj, Rect iconPosition) { if (sLabelStyle == null) { sLabelStyle = new GUIStyle(EditorStyles.miniLabel); sLabelStyle.fontSize = 9; sLabelStyle.alignment = TextAnchor.MiddleLeft; sButtonStyle = new GUIStyle(GrendelStyles.DropDownStyle); sButtonStyle.fontSize = 9; sButtonStyle.alignment = TextAnchor.MiddleRight; sButtonStyle.margin = sLabelStyle.margin; sButtonStyle.padding = sLabelStyle.padding; sButtonStyle.fixedHeight = iconPosition.height - 1f; sSelectionRectStyle = new GUIStyle("selectionRect"); } int layerPreviewControlID = GUIUtility.GetControlID(FocusType.Passive, iconPosition); GrendelLayerPreviewPopupState previewState = (GrendelLayerPreviewPopupState)GUIUtility.GetStateObject(typeof(GrendelLayerPreviewPopupState), layerPreviewControlID); previewState.IconPosition = iconPosition; previewState.Object = obj; if (CurrentPopupState != null && CurrentPopupState.GetHashCode() == previewState.GetHashCode()) { previewState.IsExpanded = CurrentPopupState.IsExpanded; } string layerName = LayerMask.LayerToName(obj.TrueLayer); string shortName = layerName; if (shortName.Length > 3) { shortName = shortName.Remove(3); } GUIContent labelContent = new GUIContent(shortName, kLayerTooltipPretext + layerName); Color previousColor = GUI.color; GUI.color = Color.Lerp(GrendelLayerColours.GetLayerColor(obj.TrueLayer), GrendelEditorGUIUtility.CurrentSkinViewColor, 0.35f); previewState.IsExpanded = GUI.Toggle(iconPosition, previewState.IsExpanded, kButtonText, sButtonStyle); GUI.Label(iconPosition, labelContent, sLabelStyle); GUI.color = previousColor; if (previewState.IsExpanded) { if (CurrentPopupState == null) { CurrentPopupState = previewState; sLayerNames = UnityEditorInternal.InternalEditorUtility.layers; CreatePopup(iconPosition); } else if (CurrentPopupState.GetHashCode() != previewState.GetHashCode()) { CurrentPopupState.IsExpanded = false; CurrentPopupState = previewState; if (sPopupWindow != null) { sPopupWindow.Close(); } sLayerNames = UnityEditorInternal.InternalEditorUtility.layers; CreatePopup(iconPosition); } else if (CurrentPopupState.GetHashCode() == previewState.GetHashCode()) { if (!CurrentPopupState.IsExpanded || sPopupWindow == null) { CurrentPopupState.IsExpanded = true; if (sPopupWindow != null) { sPopupWindow.Close(); } sLayerNames = UnityEditorInternal.InternalEditorUtility.layers; CreatePopup(iconPosition); } } } else if (!previewState.IsExpanded) { if (CurrentPopupState == null) { } else if (CurrentPopupState.GetHashCode() == previewState.GetHashCode() && CurrentPopupState.IsExpanded) { CurrentPopupState.IsExpanded = false; CurrentPopupState = null; if (sPopupWindow != null) { sPopupWindow.Close(); } } } }
public static void OnDrawGizmos(GrendelObjectData grendelObject, GizmoType gizmoType) { }
private static void OnHierarchyWindowItemOnGUI(int instanceID, Rect position) { sCurrentIndentAmount = (int)((position.x / kIndentWidth) - 1); GameObject gameObject = (GameObject)EditorUtility.InstanceIDToObject(instanceID); if (gameObject == null) { return; } sCurrentObjectData = GrendelHierarchy.EnsureObjectHasGrendelData(gameObject); if (sCurrentObjectData == null) { return; } sCurrentItemPosition = new Rect(position); sCurrentTransform = gameObject.transform; sCurrentParents = new List <Transform>(gameObject.GetComponentsInParent <Transform>(true)); if (sCurrentParents.Count > 0 && sCurrentParents.Contains(gameObject.transform)) { sCurrentParents.Remove(gameObject.transform); } sCurrentChildCount = gameObject.transform.childCount; sCurrentParentCount = sCurrentParents.Count; if (sPreviousItemPosition.y > position.y) { //we're back at the top of the hierarchy sTotalCurrentObjectCount = sCurrentObjectIndex; sCurrentObjectIndex = 0; RefreshLayerVisibility(); } GrendelFolderComponent folderComponent = gameObject.GetComponent <GrendelFolderComponent>(); if (folderComponent != null && !IsGameObjectBeingRenamed(gameObject)) { GrendelFolder.DrawFolder(position, folderComponent, CurrentRowColor); } ColorNextRow(position); //if (gameObject.transform.parent != null) //{ // GUI.Label(position, "------------------" + EditorWindow.GetWindowWithRect<EditorWindow>(sCurrentItemPosition).ToString()); //} if (GrendelPreferencesHierarchy.sTreeViewEnabled.BoolValue) { GrendelHierarchyTreeView.DrawTreeBranch(gameObject, position, sCurrentIndentAmount, sPreviousIndentAmount); } Rect previewPosition = new Rect(position); previewPosition.x -= kIconWidth; previewPosition.width = kIconWidth; GrendelHierarchyObjectPreview.DrawPreview(gameObject, previewPosition, position, folderComponent == null); Rect sideBarPosition = new Rect(position); sideBarPosition.width += (sCurrentIndentAmount + 1) * kIndentWidth; DrawSidebar(sideBarPosition); Rect iconPosition = new Rect(position); iconPosition.width = kIconWidth; iconPosition.x = (position.width - kIconWidth) + kIconRightMargin; iconPosition.x += (kIndentWidth * sCurrentIndentAmount); GrendelLockButton.DrawLockButton(sCurrentObjectData, iconPosition); iconPosition.x -= (kIconWidth + kIconBufferWidth); GrendelHideButton.DrawHideButton(sCurrentObjectData, iconPosition); Rect layerPreviewPosition = new Rect(iconPosition); if (GrendelPreferencesHierarchy.sLayerPreviewEnabled.BoolValue) { layerPreviewPosition.x -= (kIconWidth * 2) + (kIconBufferWidth * 2); layerPreviewPosition.width = kIconWidth * 2; GrendelHierarchyLayerPreview.DrawLayerPreview(sCurrentObjectData, layerPreviewPosition); } if (GrendelPreferencesHierarchy.sComponentPreviewEnabled.BoolValue) { iconPosition = new Rect(layerPreviewPosition); iconPosition.x -= (kIconWidth) + (kIconBufferWidth); iconPosition.width = kIconWidth; GrendelHierarchyObjectPreview.DrawTypeIcon(iconPosition, gameObject, folderComponent); } sPreviousIndentAmount = sCurrentIndentAmount; sPreviousItemPosition = new Rect(position); sCurrentObjectIndex++; }