예제 #1
0
        private void OnDrawGizmos()
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (gameObject == UnityEditor.Selection.activeGameObject)
            {
                Gizmos.color = Color.cyan;
                Transform relativeTo = null;
                switch (PivotDirectionOrient)
                {
                case ToolTipConnector.OrientTypeEnum.OrientToCamera:
                    relativeTo = Camera.main.transform;    //Veil.Instance.HeadTransform;
                    break;

                case ToolTipConnector.OrientTypeEnum.OrientToObject:
                    relativeTo = (Anchor != null) ? Anchor.transform : transform;
                    break;
                }
                if (PivotMode == ToolTipConnector.PivotModeEnum.Automatic)
                {
                    Vector3 targetPosition  = (Anchor != null) ? Anchor.transform.position : transform.position;
                    Vector3 toolTipPosition = targetPosition + ToolTipConnector.GetDirectionFromPivotDirection(
                        PivotDirection,
                        ManualPivotDirection,
                        relativeTo) * PivotDistance;
                    Gizmos.DrawLine(targetPosition, toolTipPosition);
                    Gizmos.DrawWireCube(toolTipPosition, Vector3.one * 0.05f);
                }
                else
                {
                    Vector3 targetPosition  = (Anchor != null) ? Anchor.transform.position : transform.position;
                    Vector3 toolTipPosition = transform.TransformPoint(ManualPivotLocalPosition);
                    Gizmos.DrawLine(targetPosition, toolTipPosition);
                    Gizmos.DrawWireCube(toolTipPosition, Vector3.one * 0.05f);
                }
            }
        }
        public void OnSceneGUI()
        {
            if (Application.isPlaying)
            {
                return;
            }

            ToolTip          tt  = (ToolTip)target;
            ToolTipConnector ttc = tt.GetComponent <ToolTipConnector>();

            if (ttc == null)
            {
                ttc = tt.gameObject.AddComponent <ToolTipConnector>();
            }

            if (tt.Anchor == null || tt.ContentParentTransform == null)
            {
                return;
            }

            if (Event.current.type == EventType.MouseDown)
            {
                mouseDown = true;
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                mouseDown     = false;
                recordingUndo = false;
            }

            float edgeSize = tt.LocalContentSize.x * tt.ContentParentTransform.lossyScale.x * 0.6f;

            // If the tooltip connector will permit handle / anchor movement, do those here
            bool doPivot  = false;
            bool doAnchor = false;

            switch (ttc.PivotMode)
            {
            case ToolTipConnector.PivotModeEnum.Automatic:
                switch (ttc.FollowType)
                {
                case ToolTipConnector.FollowTypeEnum.AnchorOnly:
                    doPivot = true;
                    break;

                default:
                    break;
                }
                break;

            case ToolTipConnector.PivotModeEnum.Manual:
                doPivot = true;
                break;
            }

            if (doPivot)
            {
                // Draw a tool for moving the pivot
                Vector3 pivotPosition    = tt.PivotPosition;
                Vector3 newPivotPosition = pivotPosition;
                pivotPosition += (tt.ContentParentTransform.right * edgeSize);
                Handles.color  = Color.white;
                Handles.Label(pivotPosition, "Move pivot");
                Handles.DrawDottedLine(pivotPosition, tt.PivotPosition, 2f);
                newPivotPosition = Handles.PositionHandle(pivotPosition, tt.ContentParentTransform.rotation);
                newPivotPosition = tt.PivotPosition + (newPivotPosition - pivotPosition);
                // Draw a line from the anchor handle to the actual anchor so we know what's up
                //Handles.color = Color.white;
                //Handles.DrawDottedLine(pivotPosition, tt.AnchorPosition, 2f);
                if (newPivotPosition != tt.PivotPosition)
                {
                    if (mouseDown && !recordingUndo)
                    {
                        recordingUndo = true;
                        Undo.RegisterCompleteObjectUndo(target, "Pivot");
                    }
                    tt.PivotPosition = newPivotPosition;
                    EditorUtility.SetDirty(target);
                }
                Handles.color = Color.Lerp(Color.yellow, Color.clear, 0.5f);
                Handles.DrawSphere(0, tt.PivotPosition, Quaternion.identity, tt.transform.lossyScale.x * 0.025f);
            }

            switch (ttc.FollowType)
            {
            case ToolTipConnector.FollowTypeEnum.AnchorOnly:
                break;

            default:
                doAnchor = true;
                break;
            }

            if (doAnchor)
            {
                Vector3 anchorPosition    = tt.AnchorPosition;
                Vector3 newAnchorPosition = anchorPosition;
                anchorPosition += (tt.Pivot.transform.right * edgeSize);
                Handles.color   = Color.white;
                Handles.Label(anchorPosition, "Move anchor");
                Handles.DrawDottedLine(anchorPosition, tt.AnchorPosition, 2f);
                newAnchorPosition = Handles.PositionHandle(anchorPosition, tt.Pivot.transform.rotation);
                newAnchorPosition = tt.Anchor.transform.position + (newAnchorPosition - anchorPosition);

                if (newAnchorPosition != tt.Anchor.transform.position)
                {
                    if (mouseDown && !recordingUndo)
                    {
                        recordingUndo = true;
                        Undo.RegisterCompleteObjectUndo(target, "Anchor");
                    }
                    tt.Anchor.transform.position = newAnchorPosition;
                    EditorUtility.SetDirty(target);
                }
                Handles.color = Color.Lerp(Color.yellow, Color.clear, 0.5f);
                Handles.DrawSphere(0, tt.AnchorPosition, Quaternion.identity, tt.transform.lossyScale.x * 0.025f);
            }
        }
예제 #3
0
        private IEnumerator UpdateTooltip(float focusEnterTimeOnStart, float tappedTimeOnStart)
        {
            if (toolTip == null)
            {
                GameObject toolTipGo = GameObject.Instantiate(ToolTipPrefab) as GameObject;
                toolTip = toolTipGo.GetComponent <ToolTip>();
                toolTip.transform.position = transform.position;
                toolTip.transform.parent   = transform;
                toolTip.gameObject.SetActive(false);
            }

            switch (AppearBehavior)
            {
            case AppearBehaviorEnum.AppearOnFocusEnter:
                // Wait for the appear delay
                yield return(new WaitForSeconds(AppearDelay));

                // If we don't have focus any more, get out of here
                if (!hasFocus)
                {
                    yield break;
                }
                break;
            }

            toolTip.gameObject.SetActive(true);
            toolTip.ToolTipText = ToolTipText;
            ToolTipConnector connector = toolTip.GetComponent <ToolTipConnector>();

            connector.Target                   = (Anchor != null) ? Anchor.gameObject : gameObject;
            connector.PivotDirection           = PivotDirection;
            connector.PivotDirectionOrient     = PivotDirectionOrient;
            connector.ManualPivotLocalPosition = ManualPivotLocalPosition;
            connector.ManualPivotDirection     = ManualPivotDirection;
            connector.FollowType               = FollowType;
            connector.PivotMode                = PivotMode;
            if (PivotMode == ToolTipConnector.PivotModeEnum.Manual)
            {
                toolTip.PivotPosition = transform.TransformPoint(ManualPivotLocalPosition);
            }

            while (toolTip.gameObject.activeSelf)
            {
                //check whether we're suppose to disappear
                switch (VanishBehavior)
                {
                case VanishBehaviorEnum.VanishOnFocusExit:
                default:
                    if (!hasFocus)
                    {
                        if (Time.time - focusExitTime > VanishDelay)
                        {
                            toolTip.gameObject.SetActive(false);
                        }
                    }
                    break;

                case VanishBehaviorEnum.VanishOnTap:
                    if (tappedTime != tappedTimeOnStart)
                    {
                        toolTip.gameObject.SetActive(false);
                    }
                    break;
                }
                yield return(null);
            }
            yield break;
        }