예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.DockWidgets.DummyDockWidgetScript"/> class.
        /// </summary>
        /// <param name="baseScript">Base script.</param>
        public static DummyDockWidgetScript Create(DockWidgetScript baseScript)
        {
            DebugEx.VerboseFormat("DummyDockWidgetScript.Create(baseScript = {0})", baseScript);

            DestroyInstance();

            //***************************************************************************
            // Dummy GameObject
            //***************************************************************************
            #region Dummy GameObject
            GameObject dummy = new GameObject("Dummy");
            Utils.InitUIObject(dummy, Global.dockingAreaScript.transform);

            //===========================================================================
            // DummyDockWidgetScript Component
            //===========================================================================
            #region DummyDockWidgetScript Component
            sInstance = dummy.AddComponent <DummyDockWidgetScript>();

            sInstance.image           = baseScript.image;
            sInstance.tokenId         = baseScript.tokenId;
            sInstance.backgroundColor = Assets.Common.DockWidgets.Colors.dummyBackground;
            #endregion
            #endregion

            return(sInstance);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.DockWidgets.DummyDockWidgetScript"/> class.
        /// </summary>
        /// <param name="baseScript">Base script.</param>
        public static DummyDockWidgetScript Create(DockWidgetScript baseScript)
        {
            DebugEx.VerboseFormat("DummyDockWidgetScript.Create(baseScript = {0})", baseScript);

            DestroyInstance();

            //***************************************************************************
            // Dummy GameObject
            //***************************************************************************
            #region Dummy GameObject
            GameObject dummy = new GameObject("Dummy");
            Utils.InitUIObject(dummy, Global.dockingAreaScript.transform);

            //===========================================================================
            // DummyDockWidgetScript Component
            //===========================================================================
            #region DummyDockWidgetScript Component
            sInstance = dummy.AddComponent<DummyDockWidgetScript>();

            sInstance.image           = baseScript.image;
            sInstance.tokenId         = baseScript.tokenId;
            sInstance.backgroundColor = Assets.Common.DockWidgets.Colors.dummyBackground;
            #endregion
            #endregion

            return sInstance;
        }
예제 #3
0
        /// <summary>
        /// Handler for destroy event.
        /// </summary>
        void OnDestroy()
        {
            DebugEx.Verbose("DummyDockWidgetScript.OnDestroy()");

            if (sInstance == this)
            {
                sInstance = null;
            }
        }
예제 #4
0
        /// <summary>
        /// Destroies the instance.
        /// </summary>
        public static void DestroyInstance()
        {
            DebugEx.VeryVerbose("DummyDockWidgetScript.DestroyInstance()");

            if (sInstance != null)
            {
                sInstance.Destroy();
                sInstance = null;
            }
        }
예제 #5
0
        /// <summary>
        /// Handler for drag event.
        /// </summary>
        /// <param name="eventData">Pointer data.</param>
        public void OnDrag(PointerEventData eventData)
        {
            DebugEx.VeryVerboseFormat("DockingTabButton.OnDrag(eventData = {0})", eventData);

            DragInfoHolder.minimum       = float.MaxValue;
            DragInfoHolder.dockingArea   = null;
            DragInfoHolder.mouseLocation = DragInfoHolder.MouseLocation.Outside;

            RaycastResult     raycastResult  = eventData.pointerCurrentRaycast;
            DockingAreaScript hitDockingArea = null;

            if (raycastResult.gameObject != null)
            {
                hitDockingArea = Utils.FindInParents <DockingAreaScript>(raycastResult.gameObject);
            }

            if (hitDockingArea != null && hitDockingArea.HasDragInfo())
            {
                hitDockingArea.PreprocessDockWidgetDrag(eventData);
            }
            else
            {
                for (int i = mDockingAreas.Count - 1; i >= 0; --i)
                {
                    mDockingAreas[i].PreprocessDockWidgetDrag(eventData);
                }
            }

            if (DragInfoHolder.dockingArea != null)
            {
                DragInfoHolder.dockingArea.ProcessDockWidgetDrag(eventData);
            }

            if (DragInfoHolder.dockingArea != null)
            {
                DragData.HideImage();
            }
            else
            {
                DummyDockWidgetScript.DestroyInstance();

                DragData.ShowImage();
                DragData.Drag();
            }
        }
        /// <summary>
        /// Handler for destroy event.
        /// </summary>
        void OnDestroy()
        {
            DebugEx.Verbose("DummyDockWidgetScript.OnDestroy()");

            if (sInstance == this)
            {
                sInstance = null;
            }
        }
        /// <summary>
        /// Destroies the instance.
        /// </summary>
        public static void DestroyInstance()
        {
            DebugEx.VeryVerbose("DummyDockWidgetScript.DestroyInstance()");

            if (sInstance != null)
            {
                sInstance.Destroy();
                sInstance = null;
            }
        }
예제 #8
0
        /// <summary>
        /// Handler for end drag event.
        /// </summary>
        /// <param name="eventData">Pointer data.</param>
        public void OnEndDrag(PointerEventData eventData)
        {
            DebugEx.VerboseFormat("DockingTabButton.OnEndDrag(eventData = {0})", eventData);

            foreach (DockingAreaScript dockingArea in mDockingAreas)
            {
                dockingArea.ClearDragInfo();
            }

            mDockingAreas = null;

            if (DummyDockWidgetScript.instance != null)
            {
                int index = DummyDockWidgetScript.instance.parent.children.IndexOf(DummyDockWidgetScript.instance);

                if (index >= 0)
                {
                    DummyDockWidgetScript.instance.parent.InsertDockWidget(DragInfoHolder.dockWidget, index);
                    DummyDockWidgetScript.instance.parent.selectedIndex = index;
                }
                else
                {
                    DebugEx.Fatal("Unexpected behaviour in DockingTabButton.OnEndDrag()");
                }

                DummyDockWidgetScript.DestroyInstance();
            }
            else
            if (DragInfoHolder.dockingArea == null)
            {
                WindowScript parentWindow = Utils.FindInParents <WindowScript>(gameObject);

                if (parentWindow != null)
                {
                    //***************************************************************************
                    // DockingWindow GameObject
                    //***************************************************************************
                    #region DockingWindow GameObject
                    GameObject dockingWindow = new GameObject("DockingWindow");
                    Utils.InitUIObject(dockingWindow, parentWindow.transform.parent);

                    //===========================================================================
                    // DockingWindowScript Component
                    //===========================================================================
                    #region DockingWindowScript Component
                    DockingWindowScript dockingWindowScript = dockingWindow.AddComponent <DockingWindowScript>();

                    dockingWindowScript.dockWidget = DragInfoHolder.dockWidget;

                    dockingWindowScript.x      = DragData.x - 8f;
                    dockingWindowScript.y      = DragData.y - 15f;      // - 8f      - 7f
                    dockingWindowScript.width  = DragData.width + 16f;  // + 8f + 8f
                    dockingWindowScript.height = DragData.height + 23f; // + 8f + 8f + 7f

                    dockingWindowScript.Show();
                    #endregion
                    #endregion
                }
                else
                {
                    DebugEx.Fatal("Unexpected behaviour in DockingTabButton.OnEndDrag()");
                }
            }

            DragInfoHolder.dockWidget    = null;
            DragInfoHolder.minimum       = float.MaxValue;
            DragInfoHolder.dockingArea   = null;
            DragInfoHolder.mouseLocation = DragInfoHolder.MouseLocation.Outside;

            DragData.EndDrag();
        }
        /// <summary>
        /// Handler for dock widget drag event.
        /// </summary>
        /// <param name="eventData">Pointer data.</param>
        /// <param name="dragCorners">Cached drag corners.</param>
        public void ProcessDockWidgetDrag(PointerEventData eventData, Vector3[] dragCorners)
        {
            DebugEx.VerboseFormat("DockingGroupScript.ProcessDockWidgetDrag(eventData = {0}, dragCorners = {1})", eventData, dragCorners);

            float x = Mouse.scaledX - dragCorners[0].x;

            DragInfoHolder.dockingArea = mParent;

            #region Insert dummy dock widget if absent
            if (
                DummyDockWidgetScript.instance == null
                ||
                DummyDockWidgetScript.instance.parent != this
                )
            {
                DummyDockWidgetScript.Create(DragInfoHolder.dockWidget).
                InsertToDockingGroup(this, 0);
            }
            #endregion

            int dummyIndex = -1;

            #region Find dummy dock widget position
            float contentWidth = 0f;

            int index = 0;

            for (int i = 0; i < mChildren.Count; ++i)
            {
                if (mChildren[i] == DummyDockWidgetScript.instance)
                {
                    dummyIndex = i;
                }
                else
                {
                    RectTransform tabTransform = mTabsTransform.GetChild(i) as RectTransform;

                    float tabWidth = tabTransform.sizeDelta.x;

                    if (
                        x >= contentWidth
                        &&
                        x <= contentWidth + tabWidth
                        )
                    {
                        if (x <= contentWidth + tabWidth / 2)
                        {
                            index = i;
                        }
                        else
                        {
                            index = i + 1;
                        }
                    }

                    contentWidth += tabWidth;
                }
            }

            if (x >= contentWidth)
            {
                index = mChildren.Count;
            }

            if (dummyIndex < index)
            {
                --index;
            }

            dummyIndex = index;
            #endregion

            InsertDockWidget(DummyDockWidgetScript.instance, dummyIndex);

            int dockWidgetIndex = -1;

            #region Place tabs where it should be
            contentWidth = 0f;

            for (int i = 0; i < mChildren.Count; ++i)
            {
                if (mChildren[i] == DragInfoHolder.dockWidget)
                {
                    dockWidgetIndex = i;
                }
                else
                {
                    RectTransform tabTransform = mTabsTransform.GetChild(i) as RectTransform;

                    float tabWidth = tabTransform.sizeDelta.x;

                    if (i == dummyIndex)
                    {
                        Utils.AlignRectTransformStretchLeft(tabTransform, tabWidth, x - tabWidth * 0.3f, 0f, -1f);
                    }
                    else
                    {
                        Utils.AlignRectTransformStretchLeft(tabTransform, tabWidth, contentWidth, 0f, -1f);
                    }

                    contentWidth += tabWidth;
                }
            }
            #endregion

            if (dockWidgetIndex >= 0)
            {
                RectTransform tabTransform      = mTabsTransform.GetChild(dockWidgetIndex) as RectTransform;
                RectTransform dummyTabTransform = mTabsTransform.GetChild(dummyIndex)      as RectTransform;

                tabTransform.offsetMin = dummyTabTransform.offsetMin;
                tabTransform.offsetMax = dummyTabTransform.offsetMax;
            }
        }