/// <summary>
 ///     The size of the message on screen. This is using UILabel.relativeSize.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override Vector2 GetSize(ScoreMessage msg)
 {
     textMesh.text = msg.Text;
     return new Vector2(
         textMesh.GetComponent<Renderer>().bounds.size.x,
         textMesh.GetComponent<Renderer>().bounds.size.y);
 }
 /// <summary>
 ///     Calculates the size using the GUIStyle from the message.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override Vector2 GetSize(ScoreMessage msg)
 {
     GUIContent msgText = new GUIContent(msg.Text);
     Vector2 size = msg.style.CalcSize(msgText);
     float maxWidth = msg.MaxWidth;
     if (size.x > maxWidth) {
         msg.style.wordWrap = true;
         size.x = maxWidth;
         size.y = msg.style.CalcHeight(msgText, size.x);
     }
     return size;
 }
        public override void Initialize(ScoreMessage msg)
        {
            Vector2 sd = rt.sizeDelta;
            sd.x = msg.MaxWidth;
            rt.sizeDelta = sd;

            text.text = msg.Text;

            rt.anchorMin = rt.anchorMax = new Vector2(0, 1);

            // set the alignment correctly
            if (fixAlignment) {
                text.alignment = (TextAnchor)NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.TextAnchor);
            }

            // set the anchor and pivot correctly depending on ScreenAlign
            if (fixPivot) {
                Vector2 pivot = Vector2.zero; // min and max are the same, so is Pivot
                switch (NGAlignment.Horizontal(msg.InnerAnchor)) {
                    case NGAlignment.HorizontalAlign.Left:
                        pivot.x = 0;
                        break;
                    case NGAlignment.HorizontalAlign.Center:
                        pivot.x = 0.5F;
                        break;
                    case NGAlignment.HorizontalAlign.Right:
                        pivot.x = 1;
                        break;
                }
                switch (NGAlignment.Vertical(msg.InnerAnchor)) {
                    case NGAlignment.VerticalAlign.Bottom:
                        pivot.y = 0;
                        break;
                    case NGAlignment.VerticalAlign.Middle:
                        pivot.y = 0.5F;
                        break;
                    case NGAlignment.VerticalAlign.Top:
                        pivot.y = 1;
                        break;
                }
                rt.pivot = pivot;
            }

            DoLayout();
        }
 private void ApplyScoreFlashAnchorToTextMesh(ScoreMessage msg)
 {
     textMesh.anchor = (TextAnchor)NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.TextAnchor);
     textMesh.alignment = (TextAlignment)NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.TextAlignment);
 }
 private Rect GetPaddingWidthPosition(ScoreMessage msg, float width, bool isPadding)
 {
     Rect maxPos = GetMaxRectPosition(msg, width);
     Rect paddingWidthPos = new Rect(maxPos);
     paddingWidthPos.width = paddingWidthPos.height = 28;
     paddingWidthPos.y = isPadding ? paddingWidthPos.y - paddingWidthPos.height : paddingWidthPos.y + maxPos.height;
     if (!NGAlignment.IsRight(msg.InnerAnchor)) {
         paddingWidthPos.x += maxPos.width - paddingWidthPos.width;
     } // otherwise: location is already fine :-)
     return paddingWidthPos;
 }
        private void DrawWorldOffsetPositionHandle(ScoreMessage msg)
        {
            if (msg.FollowLocation != null) {
                Handles.color = Color.white;
                Handles.DrawLine(
                    msg.FollowLocation.CurrentOriginalPosition,
                    msg.FollowLocation.CurrentTranslatedPosition);
            }

            Vector3 offsetRelativeToPosition = msg.FollowLocation.CurrentOriginalPosition + designed.PositionWorld.Value;
            Vector3 newOffsetRelativeToPosition = Handles.PositionHandle(offsetRelativeToPosition, Quaternion.identity);
            if (newOffsetRelativeToPosition != offsetRelativeToPosition) {
                designed.PositionWorld = newOffsetRelativeToPosition - msg.FollowLocation.CurrentOriginalPosition;
                changed = true;
            }
        }
        private void DrawPositionHandles(ScoreMessage msg)
        {
            Vector2 msgPos = FlipY(msg.Position);

            Vector2 refPoint = msg.OriginalPosition;
            Vector2 scrOri = FlipY(refPoint);

            Vector3 pointA = ScreenToWorldPoint(msgPos);
            Vector3 pointB = ScreenToWorldPoint(scrOri);

            Vector3 pointX = ScreenToWorldPoint(new Vector2(scrOri.x, msgPos.y));
            Vector3 pointY = ScreenToWorldPoint(new Vector2(msgPos.x, scrOri.y));

            Handles.color = Color.blue;
            Handles.DrawLine(pointA, pointB);
            Handles.DrawLine(pointB, pointY);
            Handles.DrawLine(pointB, pointX);

            Handles.color = Color.red;
            Handles.DrawLine(pointA, pointX);

            Handles.color = Color.green;
            Handles.DrawLine(pointA, pointY);
        }
        private void DrawMaxWidthBox(bool isSceneView, ScoreMessage msg, float width, float alpha, Color color, bool isPadding)
        {
            Rect maxPos = GetMaxRectPosition(msg, width);

            color.a = IsDraggingPosition && isSceneView ? 0.1F : alpha;
            GUI.color = color;
            GUI.Box(maxPos, "");

            if (isSceneView) {
                NGDragButton button = isPadding ? DragButtonPadding : DragButtonWidth;
                button.maxPosition.x = EditorSceneViewGUI.GetScreenWidth(isSceneView);
                button.maxPosition.y = EditorSceneViewGUI.GetScreenHeight(isSceneView);

                color.a = IsDraggingPosition && isSceneView ? 0.1F : (designed.LockScreenAlign ? 0.8F : 0.5F);
                GUI.color = color;
                button.position = GetPaddingWidthPosition(msg, width, isPadding);
                Vector2 diff = button.DrawMe();
                float diffX = diff.x;
                if (diffX != 0) {
                    NGAlignment.HorizontalAlign align = NGAlignment.Horizontal(msg.InnerAnchor);
                    changed = true;

                    if (isPadding) {
                        if (align != NGAlignment.HorizontalAlign.Right) {
                            diffX *= -1F; // invert
                        }
                        designed.MinPaddingX += diffX;
                    } else {
                        if (align == NGAlignment.HorizontalAlign.Right) {
                            diffX *= -1F; // invert
                        }
                        if (align == NGAlignment.HorizontalAlign.Center) {
                            diffX *= 2F; // 1 pixel => left / right => 2 pixels
                        }
                        designed.MaxWidth += diffX;
                    }
                }

                if (isPadding && IsDraggingPadding || !isPadding && IsDraggingWidth) {
                    if (isPadding) {
                        DragButtonPadding.DrawToolTip(isSceneView,
                            "Padding: {0}", designed.MinPaddingX);
                    } else {
                        DragButtonWidth.DrawToolTip(isSceneView,
                            "Max Width: {0}", designed.MaxWidth);
                    }
                    // drawing handles has to be done outside of "Handles.BeginGUI()" and Handles.EndGUI() => OnSceneViewGUI()
                }

            }
        }
        private void DrawEditorGUIDesignPosition(ScoreMessage msg, float size)
        {
            DragButtonPosition.position.width = DragButtonPosition.position.height = size * 2;

            if (designed.LockInnerAnchor) {
                DragButtonPosition.position.x = msg.Position.x - size;
                DragButtonPosition.position.y = msg.Position.y - size;
            } else {
                DragButtonPosition.position.x = msg.Position.x + size * 2.5F;
                if (NGAlignment.IsRight(designed.ScreenAlign)) {
                    DragButtonPosition.position.x = msg.Position.x - size * 3.5F;
                }
                DragButtonPosition.position.y = msg.Position.y + size * 2.5F;
                if (NGAlignment.IsBottom(designed.ScreenAlign)) {
                    DragButtonPosition.position.y = msg.Position.y - size * 3.5F;
                }
            }

            GUI.color = Color.white;
            DragButtonPosition.maxPosition.x = EditorSceneViewGUI.GetScreenWidth(isSceneView);
            DragButtonPosition.maxPosition.y = EditorSceneViewGUI.GetScreenHeight(isSceneView);
            Vector2 dragDistance = DragButtonPosition.DrawMe();

            Vector2 designedPosition = designed.Position;
            if (NGAlignment.IsRight(designed.ScreenAlign)) {
                designedPosition.x -= dragDistance.x;
            } else {
                designedPosition.x += dragDistance.x;
            }
            if (NGAlignment.IsBottom(designed.ScreenAlign)) {
                designedPosition.y -= dragDistance.y;
            } else {
                designedPosition.y += dragDistance.y;
            }
            if (designed.Position != designedPosition) {
                designed.Position = designedPosition;
                changed = true;
            }

            if (IsDraggingPosition) {
                DragButtonPosition.DrawToolTip(isSceneView,
                    "({0:0}, {1:0})", designed.Position.x, designed.Position.y);

                // drawing handles has to be done outside of "Handles.BeginGUI()" and Handles.EndGUI() => OnSceneViewGUI()
            }
        }
        public override void Initialize(ScoreMessage msg) {
            // for ScoreFlash, the anchor always needs to be "top-left"!
            rt.anchorMin = rt.anchorMax = new Vector2(0, 1);

            // set the anchor and pivot correctly depending on ScreenAlign
            Vector2 pivot = Vector2.zero; // min and max are the same, so is Pivot
            switch (NGAlignment.Horizontal(msg.InnerAnchor)) {
                case NGAlignment.HorizontalAlign.Left:
                    pivot.x = 0;
                    break;
                case NGAlignment.HorizontalAlign.Center:
                    pivot.x = 0.5F;
                    break;
                case NGAlignment.HorizontalAlign.Right:
                    pivot.x = 1;
                    break;
            }
            switch (NGAlignment.Vertical(msg.InnerAnchor)) {
                case NGAlignment.VerticalAlign.Bottom:
                    pivot.y = 0;
                    break;
                case NGAlignment.VerticalAlign.Middle:
                    pivot.y = 0.5F;
                    break;
                case NGAlignment.VerticalAlign.Top:
                    pivot.y = 1;
                    break;
            }
            rt.pivot = pivot;
        }
 /// <summary>
 ///     Update the message. The implementation needs
 ///     to make sure that you update position, scale, color and outline
 ///     color as well as the text.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override void UpdateMessage(ScoreMessage msg)
 {
     this.msg = msg;
 }
        /// <summary>
        ///     Update the message. This only handles text and position because
        ///     that's all that is supported by GUIText (shame on you, GUIText!)
        /// </summary>
        /// <param name="msg">the current version of the message</param>
        public override void UpdateMessage(ScoreMessage msg)
        {
            myGuiText.enabled = msg.IsVisible;
            myGuiText.text = msg.Text;
            if (myMaterial != null) {
                myMaterial.color = msg.CurrentTextColor;
            }

            myGuiText.anchor = (TextAnchor)NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.TextAnchor);
            myGuiText.alignment = (TextAlignment)NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.TextAlignment);

            // we need to convert screen position from pixel based to
            // "0-1"-based:
            Vector3 position = new Vector3(
                msg.Position.x / EditorSceneViewGUI.GetScreenWidth(msg.IsSceneView),
                1F - (msg.Position.y / EditorSceneViewGUI.GetScreenHeight(msg.IsSceneView)));
            myGuiText.transform.position = position;
        }
 /// <summary>
 ///     The size of the message on screen. Depending on the underlying GUI system
 ///     you are using, there may be different ways of calculating the
 ///     size. This needs to be in screen coordinates.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override Vector2 GetSize(ScoreMessage msg)
 {
     myGuiText.text = msg.Text;
     Rect size = myGuiText.GetScreenRect();
     return new Vector2(size.width, size.height);
 }
        /// <summary>
        ///     Update the message.
        /// </summary>
        /// <param name="msg">the current version of the message</param>
        public override void UpdateMessage(ScoreMessage msg)
        {
            // are we visible (we may be behind the player when rendering ScoreFlashFollow3D stuff)
            text.enabled= msg.IsVisible;

            // if the text has changed, we might have to re-layout
            if (!msg.Text.Equals(text.text)) {
                DoLayout();
                Rect pos = msg.Position;
                pos.height = rt.sizeDelta.y;
                msg.Position = pos;
            }

            // push text and color to Unity UI
            text.text = msg.Text;
            text.color = msg.CurrentTextColor;

            // if we have background images registered, push color to those
            for (int i = 0; i < coloredGraphics.Count; i++) {
                coloredGraphics[i].color = AlphaMultiplyColor(coloredGraphicsOrigColor[i], msg.CurrentTextColor);
            }

            Vector2 position = new Vector2(msg.Position.x, msg.Position.y);
            if (canvas != null && canvasRT != null) {
                Vector2 screenSize = new Vector2(canvas.pixelRect.width, canvas.pixelRect.height);
                Vector2 viewPortSize = canvasRT.sizeDelta;
                position = new Vector2(
                    position.x * viewPortSize.x / screenSize.x,
                    position.y * viewPortSize.y / screenSize.y);
            }

            // convert our coordinate system into Unity UI's coordinate system
            //Vector2 pos = NGAlignment.GetAlignBasedOffset(msg.InnerAnchor, msg.Position);
            rt.anchoredPosition = new Vector2(position.x, -position.y);

            // ... ok, I guess there's are kind of obvious, aren't they?
            transform.localScale = msg.Scale * Vector3.one;
            transform.localRotation = Quaternion.Euler(0, 0, -msg.Rotation);
        }
Esempio n. 15
0
        private Rect DrawAlignmentButton(ScoreMessage msg, Rect buttonPosition, NGAlignment.ScreenAlign align, string text, Texture icon)
        {
            Vector2 clampedPosition = new Vector2(Mathf.Clamp(designed.Position.x, -100F, 100F), Mathf.Clamp(designed.Position.y, -100F, 100F));
            if (!designed.SupportsScreenAlign) {
                align = NGAlignment.ScreenAlign.MiddleCenter;
            }
            if (msg != null) {
                clampedPosition = Vector2.zero;
            }
            Vector2 posForButton = (msg == null)
                ? NGAlignment.GetScreenBasedReferencePosition(align, clampedPosition, isSceneView)
                : msg.OriginalPosition;

            Vector2 offset = NGAlignment.GetAlignBasedOffset(align, buttonPosition);
            buttonPosition.x = Mathf.Clamp(posForButton.x + offset.x, 0F, EditorSceneViewGUI.GetScreenWidth(isSceneView) - buttonPosition.width);
            buttonPosition.y = Mathf.Clamp(posForButton.y + offset.y, 0F, EditorSceneViewGUI.GetScreenHeight(isSceneView) - buttonPosition.height);
            Color col = GUI.color;
            if (IsDraggingPosition) {
                col.a = 0.4F;
            }
            if (clampedPosition != designed.Position) {
                col.a = 0.2F;
            }
            if (msg != null) {
                col.a = 1F;
            }
            GUI.color = col;
            if (msg == null) {
                if (GUI.Button(buttonPosition, text)) {
                    designed.ScreenAlign = align;
                }
            } else { // otherwise: reset position
                if (GUI.Button(buttonPosition, icon)) {
                    designed.Position = Vector2.zero;
                    changed = true;
                }
            }
            return buttonPosition;
        }
Esempio n. 16
0
        private void DrawEditorGUIDesignInnerAnchor(ScoreMessage msg, float size)
        {
            Rect pos = msg.Position;
            pos.width = pos.height = size;
            if (!designed.LockInnerAnchor && !IsDraggingPosition) {
                pos.x = msg.Position.x + size * 0.5F; pos.y = msg.Position.y + size * 0.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.TopLeft)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.TopLeft;
                    changed = true;
                }
                pos.x = msg.Position.x - size * 0.5F; pos.y = msg.Position.y + size * 0.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.TopCenter)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.TopCenter;
                    changed = true;
                }
                pos.x = msg.Position.x - size * 1.5F; pos.y = msg.Position.y + size * 0.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.TopRight)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.TopRight;
                    changed = true;
                }
                pos.x = msg.Position.x + size * 0.5F; pos.y = msg.Position.y - size * 0.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.MiddleLeft)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.MiddleLeft;
                    changed = true;
                }
                pos.x = msg.Position.x - size * 0.5F; pos.y = msg.Position.y - size * 0.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.MiddleCenter)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.MiddleCenter;
                    changed = true;
                }
                pos.x = msg.Position.x - size * 1.5F; pos.y = msg.Position.y - size * 0.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.MiddleRight)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.MiddleRight;
                    changed = true;
                }
                pos.x = msg.Position.x + size * 0.5F; pos.y = msg.Position.y - size * 1.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.BottomLeft)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.BottomLeft;
                    changed = true;
                }
                pos.x = msg.Position.x - size * 0.5F; pos.y = msg.Position.y - size * 1.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.BottomCenter)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.BottomCenter;
                    changed = true;
                }
                pos.x = msg.Position.x - size * 1.5F; pos.y = msg.Position.y - size * 1.5F;
                if (EditorSceneViewGUI.Toggle(pos, designed.InnerAnchor != NGAlignment.ScreenAlign.BottomRight)) {
                    designed.InnerAnchor = NGAlignment.ScreenAlign.BottomRight;
                    changed = true;
                }
            } else {
                pos.x = msg.Position.x - size * 0.5F; pos.y = msg.Position.y - size * 0.5F;
                GUI.Box(pos, "");
            }

            pos.width = designed.DefaultScoreFlash.editorIconSet.lockOpen.width;
            pos.height = designed.DefaultScoreFlash.editorIconSet.lockOpen.height;

            pos.x = msg.Position.x + size * 1.5F; pos.y = msg.Position.y - size * 0.5F;
            if (pos.x + 2 * pos.width + 3 > Screen.width - 2) {
                pos.x = msg.Position.x - size * 2.5F - 2 * pos.width + 6;
            }

            // when we're going too far right for the tooltip, where should the tool tip start
            float xOnFlip = msg.Position.x - size * 2.5F;
            GUIContent lockClosed;
            GUIContent lockOpen;
            bool newLocked = false;
            if (designed.SupportsScreenAlign && designed.SupportsInnerAnchor) {
                lockClosed = new GUIContent(designed.DefaultScoreFlash.editorIconSet.lockClosed, "Define arbitrary inner anchors");
                lockOpen = new GUIContent(designed.DefaultScoreFlash.editorIconSet.lockOpen, "Lock Inner Anchors to Screen Align");
                newLocked = EditorSceneViewGUI.ToggleWithToolTip(pos, xOnFlip, designed.LockInnerAnchor, lockClosed, lockOpen);
                if (newLocked != designed.LockInnerAnchor) {
                    designed.LockInnerAnchor = newLocked;
                    changed = true;
                }
                pos.x += pos.width + 3;
            }

            if (designed.SupportsScreenAlign) {
                lockClosed = new GUIContent(designed.DefaultScoreFlash.editorIconSet.lockClosed, "Show Buttons for Screen Alignment");
                lockOpen = new GUIContent(designed.DefaultScoreFlash.editorIconSet.lockOpen, "Hide Buttons for Screen Alignment");
                newLocked = EditorSceneViewGUI.ToggleWithToolTip(pos, xOnFlip, designed.LockScreenAlign, lockClosed, lockOpen);
                if (newLocked != designed.LockScreenAlign) {
                    designed.LockScreenAlign = newLocked;
                    changed = true;
                }
            }
        }
 /// <summary>
 ///     The size of the message on screen. This is using RectTransform.sizeDelta.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override Vector2 GetSize(ScoreMessage msg) {
     return rt.sizeDelta;
 }
Esempio n. 18
0
 private void DrawEditorGUIDesignScreenAlignment(ScoreMessage msg)
 {
     Rect buttonPosition = new Rect(0, 0, 120, 40);
     NGAlignment.ScreenAlign oldAlign = designed.ScreenAlign;
     if (designed.SupportsScreenAlign && !designed.LockScreenAlign) {
         foreach (NGAlignment.ScreenAlign align in System.Enum.GetValues(typeof(NGAlignment.ScreenAlign))) {
             if (align != designed.ScreenAlign) {
                 buttonPosition = DrawAlignmentButton(null, buttonPosition, align, align.ToString(), null);
             }
         }
     }
     if (designed.Position.sqrMagnitude > 43 * 43) {
         buttonPosition.width = buttonPosition.height = 28;
         DrawAlignmentButton(msg, buttonPosition, designed.ScreenAlign, null, designed.DefaultScoreFlash.editorIconSet.moveReset);
     }
     if (oldAlign != designed.ScreenAlign) {
         changed = true;
     }
 }
        /// <summary>
        ///     Update the message.
        /// </summary>
        /// <param name="msg">the current version of the message</param>
        public override void UpdateMessage(ScoreMessage msg) {
            // push only the alpha channel of the color
            background.color = AlphaMultiplyColor(origColorBackground, msg.CurrentTextColor);
            title.color = AlphaMultiplyColor(origColorName, msg.CurrentTextColor);
            description.color = AlphaMultiplyColor(origColorDescription, msg.CurrentTextColor);

            Vector2 position = new Vector2(msg.Position.x, msg.Position.y);
            if (canvas != null && canvasRT != null) {
                Vector2 screenSize = new Vector2(canvas.pixelRect.width, canvas.pixelRect.height);
                Vector2 viewPortSize = canvasRT.sizeDelta;
                position = new Vector2(
                    position.x * viewPortSize.x / screenSize.x,
                    position.y * viewPortSize.y / screenSize.y);
            }

            // convert our coordinate system into Unity UI's coordinate system
            //Vector2 pos = NGAlignment.GetAlignBasedOffset(msg.InnerAnchor, msg.Position);
            rt.anchoredPosition = new Vector2(position.x, -position.y);

            // ... ok, I guess there's are kind of obvious, aren't they?
            transform.localScale = msg.Scale * Vector3.one;
            transform.localRotation = Quaternion.Euler(0, 0, -msg.Rotation);
        }
Esempio n. 20
0
        private void DrawPaddingWidthHandles(ScoreMessage msg, bool isPadding)
        {
            bool isRight = NGAlignment.IsRight(msg.InnerAnchor);

            float width = isPadding ? msg.MaxWidthViaPadding : msg.MaxWidthViaWidth;

            Rect dragHandle = GetPaddingWidthPosition(msg, width, isPadding);
            dragHandle.y += dragHandle.height * 0.5F;
            if (!isRight && isPadding || isRight && !isPadding) {
                dragHandle.x += dragHandle.width;
            }
            Vector2 msgPos = FlipY(dragHandle);

            Vector2 scrOri = Vector2.zero;
            if (isPadding) {
                if (!isRight) {
                    scrOri = new Vector2(EditorSceneViewGUI.GetScreenWidth(isSceneView), msgPos.y);
                } else {
                    scrOri = new Vector2(0, msgPos.y);
                }
            } else {
                if (!isRight) {
                    scrOri = new Vector2(msgPos.x - width + dragHandle.width, msgPos.y);
                } else {
                    scrOri = new Vector2(msgPos.x + width - dragHandle.width, msgPos.y);
                }
            }
            Vector3 pointA = ScreenToWorldPoint(msgPos);
            Vector3 pointB = ScreenToWorldPoint(scrOri);

            Handles.color = isPadding ? Color.green : Color.cyan;
            Handles.DrawLine(pointA, pointB);
        }
Esempio n. 21
0
 /// <summary>
 ///     The size of the message on screen. Depending on the underlying GUI system
 ///     you are using, there may be different ways of calculating the
 ///     size. This needs to be in screen coordinates.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public abstract Vector2 GetSize(ScoreMessage msg);
Esempio n. 22
0
        private bool DrawWidthLock(ScoreMessage msg, bool oldIsMax, Rect lockPos, Rect localPos)
        {
            lockPos.width = designed.DefaultScoreFlash.editorIconSet.lockOpen.width;
            lockPos.height = designed.DefaultScoreFlash.editorIconSet.lockOpen.height;
            // trying to find a position for the lock that makes sense ... and can be used all the time ;-)
            if (!NGAlignment.IsRight(msg.InnerAnchor)) {
                lockPos.x += localPos.width + 3;
            } else {
                lockPos.x -= lockPos.width + 3;
            }
            lockPos.y = localPos.y + localPos.height + 3F;
            float xOnFlip = lockPos.x - lockPos.width;

            GUIContent lockClosed = new GUIContent(designed.DefaultScoreFlash.editorIconSet.lockClosed, "Set Max Width to Current");
            GUIContent lockOpen = new GUIContent(designed.DefaultScoreFlash.editorIconSet.lockOpen, "Set Max Width to Max");
            return EditorSceneViewGUI.ToggleWithToolTip(lockPos, xOnFlip, oldIsMax, lockClosed, lockOpen);
        }
Esempio n. 23
0
 /// <summary>
 ///     Can be used to initialize the message renderer.
 /// </summary>
 /// <param name="msg">the initial of the message</param>
 public virtual void Initialize(ScoreMessage msg)
 {
 }
Esempio n. 24
0
 private Rect GetMaxRectPosition(ScoreMessage msg, float width)
 {
     Rect maxPos = new Rect(msg.Position);
     maxPos.width = width;
     Vector2 alignBasedOffsetMax = NGAlignment.GetAlignBasedOffset(msg.InnerAnchor, maxPos);
     maxPos.x += alignBasedOffsetMax.x;
     maxPos.y += alignBasedOffsetMax.y;
     return maxPos;
 }
Esempio n. 25
0
 /// <summary>
 ///     Update the message. The implementation needs
 ///     to make sure that you update position, scale, rotation color and outline
 ///     color as well as the text ... and whether the message is currently visible!
 /// </summary>
 /// <remarks>
 ///     See also:
 ///     <list type="bullet">
 ///         <item><description><see cref="ScoreMessage.IsVisible"/></description></item>
 ///         <item><description><see cref="ScoreMessage.Text"/></description></item>
 ///         <item><description><see cref="ScoreMessage.position"/></description></item>
 ///         <item><description><see cref="ScoreMessage.rotation"/></description></item>
 ///         <item><description><see cref="ScoreMessage.scale"/></description></item>
 ///         <item><description><see cref="ScoreMessage.CurrentTextColor"/></description></item>
 ///         <item><description><see cref="ScoreMessage.OutlineColor"/></description></item>
 ///     </list>
 /// </remarks>
 /// <param name="msg">the current version of the message</param>
 public abstract void UpdateMessage(ScoreMessage msg);
        /// <summary>
        ///     Update the message.
        /// </summary>
        /// <param name="msg">the current version of the message</param>
        public override void UpdateMessage(ScoreMessage msg)
        {
            transform.position = msg.FollowLocation.CurrentTranslatedPosition;
            transform.LookAt(msg.Follow3D.referenceCamera.transform.position, msg.Follow3D.referenceCamera.transform.up);

            // are we visible (we may be behind the player when rendering ScoreFlashFollow3D stuff)
            textMesh.GetComponent<Renderer>().enabled = msg.IsVisible;

            //textMeshPro.lineLength = msg.MaxWidth;

            // push text and color to NGUI
            textMesh.text = msg.Text;
            textMesh.color = msg.CurrentTextColor;

            Vector2 pos = new Vector2(msg.Position.x + msg.Position.width * 0.5F, msg.Position.y + msg.Position.height * 0.5F);
            pos -= msg.OriginalPosition;

            // convert our coordinate system into World coordinate system
            Vector3 position = new Vector3(
                pos.x * positionScale,
                -pos.y * positionScale,
                0); // any value > 0 will do ;-)
            textTransform.localPosition = position;

            // ... ok, I guess there's are kind of obvious, aren't they?
            textMesh.transform.localScale = msg.Scale * Vector3.one;
            textTransform.localRotation = Quaternion.Euler(0, 180, -msg.Rotation);
        }
        /// <summary>
        ///     Update the message.
        /// </summary>
        /// <param name="msg">the current version of the message</param>
        public override void UpdateMessage(ScoreMessage msg)
        {
            // are we visible (we may be behind the player when rendering ScoreFlashFollow3D stuff)
            textMesh.GetComponent<Renderer>().enabled = msg.IsVisible;

            // msg.MaxWidth; // not supported by text mesh

            // push text and color to NGUI
            textMesh.text = msg.Text;
            textMesh.color = msg.CurrentTextColor;

            // convert our coordinate system into World coordinate system
            Vector3 position = new Vector3(
                msg.Position.x - 0.5F * Screen.width,
                0.5F * Screen.height - msg.Position.y,
                10F); // any value > 0 will do ;-)
            transform.localPosition = position;

            // ... ok, I guess there's are kind of obvious, aren't they?
            textMesh.transform.localScale = msg.Scale * Vector3.one;
            transform.localRotation = Quaternion.Euler(0, 0, -msg.Rotation);
        }
        public override void Initialize(ScoreMessage msg)
        {
            textMesh.text = msg.Text;
            // msg.MaxWidth; // not supported by text mesh

            // We can't use this, yet, because NGAlignment doesn't support Text Mesh Pro, yet
            // I might clean this up in a future version; on the other hand, it's a nice example for adding
            // a custom renderer for a GUI framework that's not supported "out-of-the-box" ;-)
            //NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.NGUI_Pivot);

            ApplyScoreFlashAnchorToTextMesh(msg);
        }
 /// <summary>
 ///     The size of the message on screen. This is using 
 ///     text.preferredWith and text.preferredHeight.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override Vector2 GetSize(ScoreMessage msg)
 {
     if (csf != null) {
         text.text = msg.Text;
         DoLayout();
         return new Vector2(text.preferredWidth, rt.sizeDelta.y);
     } else {
         return rt.sizeDelta;
     }
 }