Exemple #1
0
        private void Draw(int pInstanceID, Rect pDrawingRect)
        {
            // called per-line in the hierarchy window

            GameObject gameObject = EditorUtility.InstanceIDToObject(pInstanceID) as GameObject;

            if (gameObject == null)
            {
                return;
            }

            bool currentLock = (gameObject.hideFlags & HideFlags.NotEditable) != 0;

            bool doPreview = _setting_showHoverPreview &&
                             (!_setting_showHoverPreviewShift || (Event.current.modifiers & EventModifiers.Shift) != 0) &&
                             (!_setting_showHoverPreviewCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) &&
                             (!_setting_showHoverPreviewAlt || (Event.current.modifiers & EventModifiers.Alt) != 0);

            bool doTooltip = _setting_showHoverTooltip &&
                             (!_setting_showHoverTooltipShift || (Event.current.modifiers & EventModifiers.Shift) != 0) &&
                             (!_setting_showHoverTooltipCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) &&
                             (!_setting_showHoverTooltipAlt || (Event.current.modifiers & EventModifiers.Alt) != 0);

            bool doComponents = _setting_showComponents &&
                                (!_setting_showComponentsShift || (Event.current.modifiers & EventModifiers.Shift) != 0) &&
                                (!_setting_showComponentsCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) &&
                                (!_setting_showComponentsAlt || (Event.current.modifiers & EventModifiers.Alt) != 0);

            bool doLockIcon = _setting_showLock &&
                              (!_setting_showLockShift || (Event.current.modifiers & EventModifiers.Shift) != 0) &&
                              (!_setting_showLockCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) &&
                              (!_setting_showLockAlt || (Event.current.modifiers & EventModifiers.Alt) != 0);

            doLockIcon |= _setting_showLock && _setting_showLockLocked && currentLock;


            string tooltip = "";

            Color originalColor = GUI.color;

            if (doLockIcon)
            {
                Rect r = pDrawingRect;
                r.x     = r.x + r.width - 14;
                r.width = 12;

                GUI.color = currentLock ? new Color(1, 1, 1, 1) : new Color(1, 1, 1, 0.4f);

                bool newLock = GUI.Toggle(r, currentLock, "", (GUIStyle)"IN LockButton");
                if (newLock != currentLock)
                {
                    if (newLock)
                    {
                        gameObject.hideFlags |= HideFlags.NotEditable;
                    }
                    else
                    {
                        gameObject.hideFlags -= HideFlags.NotEditable;
                    }
                }

                pDrawingRect.width -= 14;
            }

            float width = EditorStyles.label.CalcSize(new GUIContent(gameObject.name)).x;

            if (((1 << gameObject.layer) & Tools.visibleLayers) == 0)
            {
                Rect labelRect = pDrawingRect;
                labelRect.width = width;
                labelRect.x    -= 2;
                labelRect.y    -= 4;
                GUI.Label(labelRect, "".PadRight(gameObject.name.Length, '_'));
            }

            if (doTooltip)
            {
                tooltip = GetTooltip(gameObject);
                if (tooltip.Length > 0)
                {
                    GUI.Label(pDrawingRect, new GUIContent(" ", tooltip));
                }
            }

            if (doComponents)
            {
                Rect iconRect = pDrawingRect;
                iconRect.x = pDrawingRect.x + pDrawingRect.width - 16;
                iconRect.y--;
                iconRect.width  = 16;
                iconRect.height = 16;

                _mousePosition = new Vector2(Event.current.mousePosition.x + Common.HierarchyWindow.position.x, Event.current.mousePosition.y + Common.HierarchyWindow.position.y);

                bool mouseIn = pDrawingRect.Contains(Event.current.mousePosition);

                if (doPreview && mouseIn)
                {
                    _hoverObject = gameObject;
                }

                Object dragging = DragAndDrop.objectReferences.Length == 1 ? DragAndDrop.objectReferences[0] : null;

                if (DragAndDrop.objectReferences.Length == 1 && _setting_showHoverDropWindow && mouseIn)
                {
                    if (_draggingHeldOver == null)
                    {
                        _draggingHeldStart = System.DateTime.Now;
                    }

                    if (_draggingHeldOver != gameObject)
                    {
                        _draggingShownQuickInspector = false;
                    }

                    _draggingHeldOver = gameObject;
                }

                bool suitableDrop = false;
                bool drawnEtc     = false;

                foreach (Component c in gameObject.GetComponents <Component>())
                {
                    if (c is Transform)
                    {
                        continue;
                    }

                    if (c != null && !suitableDrop && dragging != null)
                    {
                        Type type = c.GetType();
                        foreach (FieldInfo f in TeneDropTarget.FieldsFor(type))
                        {
                            if (TeneDropTarget.IsCompatibleField(f, dragging))
                            {
                                suitableDrop = true;
                                break;
                            }
                        }
                    }

                    if (c == null)
                    {
                        Rect rectX = new Rect(iconRect.x + 4, iconRect.y + 1, 14, iconRect.height);
                        GUI.color = new Color(1.0f, 0.35f, 0.35f, 1.0f);
                        GUI.Label(rectX, new GUIContent("X", "Missing Script"), Common.ColorLabel(new Color(1.0f, 0.35f, 0.35f, 1.0f)));
                        iconRect.x -= 9;

                        if (rectX.Contains(Event.current.mousePosition))
                        {
                            _hoverObject = null;
                        }

                        continue;
                    }

                    GUI.color = c.GetEnabled() ? Color.white : new Color(0.5f, 0.5f, 0.5f, 0.5f);

                    if (iconRect.x < pDrawingRect.x + width)
                    {
                        if (!drawnEtc)
                        {
                            GUI.Label(iconRect, " ..");
                            drawnEtc = true;
                        }
                        continue;
                    }

                    if (doTooltip)
                    {
                        tooltip = GetTooltip(c);
                    }

                    Texture iconTexture = null;

                    if (c is MonoBehaviour)
                    {
                        MonoScript ms = MonoScript.FromMonoBehaviour(c as MonoBehaviour);
                        iconTexture = AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(ms));
                    }

                    if (iconTexture == null)
                    {
                        iconTexture = Common.GetMiniThumbnail(c);
                    }

                    if (iconTexture != null)
                    {
                        if (doPreview)
                        {
                            if (iconRect.Contains(Event.current.mousePosition))
                            {
                                _hoverObject = c;
                            }
                        }

                        GUI.DrawTexture(iconRect, iconTexture, ScaleMode.ScaleToFit);
                        if (GUI.Button(iconRect, new GUIContent("", tooltip), EditorStyles.label))
                        {
                            c.SetEnabled(!c.GetEnabled());
                            Common.HierarchyWindow.Repaint();
                            return;
                        }
                        iconRect.x -= iconRect.width;
                    }
                }

                if (suitableDrop)
                {
                    Rect labelRect = pDrawingRect;

                    labelRect.width = width;
                    labelRect.x    -= 2;
                    labelRect.y    += 1;

                    GUI.color = Color.white;
                    GUI.DrawTexture(new Rect(labelRect.x, labelRect.y, labelRect.width, 1), EditorGUIUtility.whiteTexture);
                    GUI.DrawTexture(new Rect(labelRect.x, labelRect.y, 1, labelRect.height), EditorGUIUtility.whiteTexture);
                    GUI.DrawTexture(new Rect(labelRect.x, labelRect.yMax, labelRect.width, 1), EditorGUIUtility.whiteTexture);
                    GUI.DrawTexture(new Rect(labelRect.xMax, labelRect.y, 1, labelRect.height), EditorGUIUtility.whiteTexture);

                    if (mouseIn)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                    }
                }
            }

            GUI.color = originalColor;
        }