Exemplo n.º 1
0
        private void OnGUI()
        {
            if (myNode != null && textWhere != null)
            {
                var screenWhere = PlanetariumCamera.Camera.WorldToScreenPoint(
                    ScaledSpace.LocalToScaledSpace(textWhere));

                if (screenWhere.z > 0 &&
                    screenWhere.x >= 0 && screenWhere.x <= Screen.width &&
                    screenWhere.y >= 0 && screenWhere.y <= Screen.height)
                {
                    // In front of camera, so draw

                    var camDist = cameraDist(textWhere);
                    if (0 < camDist && camDist < ringScale)
                    {
                        var offset = 0.6f * ringScale / camDist + 10;

                        labelStyle.normal.textColor = myNode.color;
                        if (GUI.Button(
                                new Rect(screenWhere.x - 50, Screen.height - screenWhere.y + offset, 100, 30),
                                myNode.GetCaption(vessel),
                                labelStyle
                                ))
                        {
                            EditMe?.Invoke(myNode);
                        }
                    }
                }
                else
                {
                    Vector2 edgePos = (screenWhere.z < 0 ? -1f : 1f) * screenRadius * (
                        new Vector2(screenWhere.x - Screen.width / 2, Screen.height / 2 - screenWhere.y).normalized
                        );
                    GUI.Label(
                        new Rect(
                            Mathf.Clamp(Screen.width / 2 + edgePos.x, 50, Screen.width - 100),
                            Mathf.Clamp(Screen.height / 2 + edgePos.y, 50, Screen.height - 50),
                            100, 30
                            ),
                        myNode.GetCaption(vessel),
                        labelStyle
                        );
                }
            }
        }
Exemplo n.º 2
0
        private void OnGUI()
        {
            if (myNode != null && textWhere != null)
            {
                var camDist = cameraDist(textWhere);
                if (0 < camDist && camDist < ringScale)
                {
                    var screenWhere = PlanetariumCamera.Camera.WorldToScreenPoint(
                        ScaledSpace.LocalToScaledSpace(textWhere))
                                      + (0.6f * ringScale / camDist + 10) * Vector3.down;

                    if (screenWhere.z > 0 && viewport.Contains(screenWhere))
                    {
                        // In front of camera, so draw button
                        labelStyle.normal.textColor = myNode.color;
                        if (GUI.Button(
                                new Rect(
                                    screenWhere.x - halfTextWidth,
                                    Screen.height - screenWhere.y,
                                    textWidth, 30),
                                myNode.GetCaption(vessel),
                                labelStyle
                                ))
                        {
                            EditMe?.Invoke(myNode);
                        }
                    }
                    else
                    {
                        // Off edge of screen or behind camera, draw marker at edge of screen
                        labelStyle.normal.textColor = new Color(
                            myNode.color.r, myNode.color.g, myNode.color.b, 0.6f);
                        var edgePos = edgePosition((screenWhere.z < 0 ? -1f : 1f)
                                                   * ((Vector2)screenWhere - screenCenterOffset));
                        GUI.Label(
                            new Rect(edgePos.x - halfTextWidth, edgePos.y, textWidth, 30),
                            myNode.GetCaption(vessel),
                            labelStyle
                            );
                    }
                }
            }
        }