Esempio n. 1
0
        internal void Select(DisplayObject target)
        {
            var dlm = target as DisplayListMember;

            // do not analyze anything from this stage
            if (null != dlm && !DesignerOverlay.IsInspectable(dlm))
            {
                return;
            }

            var go = GuiLookup.GetGameObject((Component)target);

            if (null != go)
            {
                _selectionOverlay.Visible = true;
                var bounds = target.Transform.GlobalBounds;

                /**
                 * 1. Expand around component
                 * */
                bounds = bounds.Expand(PlayModeOverlaySelectionBorderStyle.BorderWidth);

                /**
                 * 2. Constrain with stage bounds
                 * */
                bounds.ConstrainWithin(Rectangle.FromSize(SystemManager.Instance.ScreenSize));

                _selectionOverlay.Redraw(bounds, Bounds, GuiLookup.PathToString(go.transform, " -> "));
                _selectionOverlay.ValidateNow();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fires on mouse-overed component change<br/>
        /// Since in editor overlay we are dealing with adapters, we need to examine if the mouse-overed component is related to any adapter<br/>
        /// We do that by looking for the adapter via GuiLookup, which finds the adapter in component parent<br/>
        /// We then examine if the current selection changed. If it did, we are calling the Select method
        /// </summary>
        private void MouseOverSlot(params object[] parameters)
        {
            Component comp = (Component)parameters[0];

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("DesignerOverlay->MouseOverSlot: " + comp);
            }
#endif
            if (null == comp)
            {
                return;
            }

            GameObject go = GuiLookup.GetGameObject(comp);

            if (null == go)
            {
                return;
            }

            ComponentAdapter adapter = (ComponentAdapter)go.GetComponent(typeof(ComponentAdapter));
            if (null == adapter)
            {
                return;
            }

            if (null == adapter.Component)
            {
                return;
            }

            _hoveredComponent = adapter.Component;

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("Hover: " + _hoveredComponent);
            }
#endif
            Hover(_hoveredComponent);
        }
Esempio n. 3
0
        internal void SpecialClickHandler(Event e)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log("DesignerOverlay->SpecialClickHandler: " + e.Target);
            }
#endif
            MouseEvent me = (MouseEvent)e;
            if (me.CurrentEvent.control || me.CurrentEvent.shift)
            {
                e.CancelAndStopPropagation(); // disable the actual button click in the capture phase. Sweet ^_^
            }

            GameObject go = GuiLookup.GetGameObject((Component)e.Target);

            if (null == go)
            {
                _hoveredComponent = null;
                ClickSignal.Emit(null, e);
                return;
            }

            ComponentAdapter adapter = (ComponentAdapter)go.GetComponent(typeof(ComponentAdapter));
            if (null == adapter)
            {
                _hoveredComponent = null;
                ClickSignal.Emit(null, e);
                return;
            }

            if (null == adapter.Component)
            {
                _hoveredComponent = null;
                ClickSignal.Emit(null, e);
                return;
            }

            _hoveredComponent = adapter.Component;

            ClickSignal.Emit(_hoveredComponent, e);
        }
        /// <summary>
        /// Fires when in-game GUI element clicked
        /// </summary>
        /// <param name="parameters"></param>
        internal static void ClickSlot(object[] parameters)
        {
            if (!EditorSettings.InspectorEnabled)
            {
                return;
            }

            /**
             * 1. No component with adapter selected -> remove the hierarchy selection
             * */
            if (parameters.Length == 0)
            {
                // ReSharper disable ConditionIsAlwaysTrueOrFalse
                if (DipSwitches.DeselectHierarchyOnNonAdaptedComponentSelection)
                // ReSharper restore ConditionIsAlwaysTrueOrFalse
#pragma warning disable 162
                {
                    Selection.activeTransform = null;
                }
#pragma warning restore 162
                return;
            }

            Component comp = parameters[0] as Component;

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Component clicked in the game view: {0}", comp));
            }
#endif

            DraggableList.StopDrag(); // solves the bug of still dragging when view changed

            /**
             * 2. The adapted component selected
             * */
            if (null != comp)
            {
                /**
                 * 2.a) Get game object having adapter for this component attached<br/>
                 * If no adapter found, it means that this component is not bound to an adapter<br/>
                 * For instance Alert (created from code), or component created by an adapter working in factory mode
                 * */
                GameObject gameObject = GuiLookup.GetGameObject(comp);

                /**
                 * 2.b) Check if game object found
                 * If not, nullify the selection and return
                 * */
                if (null == gameObject)
                {
                    Selection.activeTransform = null;
                    return;
                }

                /**
                 * 2.c) If game object found, ping it (highlight it) and select it
                 * Selecting it will in turn execute all the mechanisms for processing the selection change
                 * */
                //EditorGUIUtility.PingObject(gameObject); // ping
                Selection.activeTransform = gameObject.transform; // select

                if (parameters.Length > 1)
                {
                    MouseEvent me = (MouseEvent)parameters[1];
                    ProcessMouseEvent(me);
                }
            }
        }