Пример #1
0
        private static void DrawSidebar(Rect position)
        {
            GUI.color = CurrentRowColor;

            float sideBarWidth = CalculateSideBarWidth();

            position.x     = position.width - sideBarWidth;
            position.width = sideBarWidth;

            GUI.DrawTexture(position, EditorGUIUtility.whiteTexture);
            GUI.color = Color.white;

            position.y    -= 1;
            position.width = kDividerWidth;

            GrendelGUI.ShadedGUILine(position, Color.gray, Color.white, Vector2.one);
        }
Пример #2
0
        public static void DrawPopup(GrendelLayerPreviewPopupState state)
        {
            if (state == null)
            {
                return;
            }

            Event currentEvent = Event.current;
            Rect  iconPosition = state.IconPosition;
            int   layer        = state.Object.gameObject.layer;

            float windowWidth = 128f;

            Rect layerRect;
            Rect checkmarkRect;
            Rect lastRect;
            Rect longLayerRect;

            int returnLayer = layer;

            //GenericMenu layerMenu = new GenericMenu();
            //GUIContent tempContent = new GUIContent(string.Empty);

            //for (int i = 0; i < sLayerNames.Length; i++)
            //{
            //    tempContent.text = sLayerNames[i];
            //    bool isOn = layer == i;
            //    layerMenu.AddItem(tempContent, isOn, SetLayer, i);
            //}


            //layerMenu.ShowAsContext();

            GUILayout.BeginVertical();

            for (int i = 0; i < sLayerNames.Length; i++)
            {
                GUILayout.BeginHorizontal(GUILayout.Height(kLayerEntryHeight));

                GUILayout.Label(layer == LayerMask.NameToLayer(sLayerNames[i]) ? kCheckMarkText : " ", GUILayout.Width(kLayerCheckMarkWidth), GUILayout.Height(kLayerEntryHeight));

                lastRect = checkmarkRect = GUILayoutUtility.GetLastRect();

                GrendelGUI.ShadedGUILine(new Rect(lastRect.x + kLayerCheckMarkWidth, lastRect.y - 4, 1, EditorGUIUtility.singleLineHeight + 1), Color.white, Color.gray, Vector2.one);

                layerRect           = GUILayoutUtility.GetRect(windowWidth - kLayerCheckMarkWidth, kLayerEntryHeight);
                longLayerRect       = new Rect(layerRect);
                longLayerRect.width = windowWidth;
                longLayerRect.x    -= kLayerCheckMarkWidth;

                GUI.color = GrendelLayerColours.GetLayerColor(LayerMask.NameToLayer(sLayerNames[i]));

                GUI.DrawTexture(layerRect, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);
                GUI.Label(layerRect, sLayerNames[i]);

                if (longLayerRect.Contains(currentEvent.mousePosition))
                {
                    GUI.color = Color.cyan;
                    GUI.Box(layerRect, string.Empty, sSelectionRectStyle);

                    if (LayerMask.NameToLayer(sLayerNames[i]) != layer)
                    {
                        GUI.color = Color.gray;
                        GUI.Label(checkmarkRect, kCheckMarkText, EditorStyles.whiteLabel);
                    }

                    if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
                    {
                        returnLayer = LayerMask.NameToLayer(sLayerNames[i]);
                        currentEvent.Use();
                        state.IsExpanded = false;
                        sPopupWindow.Close();
                    }
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();

            GUI.color = Color.white;

            if (returnLayer != state.Object.TrueLayer)
            {
                state.Object.gameObject.layer = returnLayer; //TODO: Undo functionality
                EditorUtility.SetDirty(state.Object);
            }
        }