Example #1
0
        void JointsSceneGUI()
        {
            SplineEditor.ShowEditor = false;

            for (int i = 0; i < rope.Links.Length; i++)
            {
                if (!rope.Links[i].IsActive)
                {
                    continue;
                }

                Vector3 pos      = rope.Links[i].transform.position;
                float   handleSz = HandleUtility.GetHandleSize(pos) * handleSize;

                if (selectedLink == i)
                {
                    EditorX.Circlelever(pos, Color.yellow, handleSz * 0.7f);
                }
                else
                {
                    bool isCustom = (rope.Links[i].overrideColliderSettings ||
                                     rope.Links[i].overrideJointSettings ||
                                     rope.Links[i].overrideOffsetSettings ||
                                     rope.Links[i].overridePrefab ||
                                     rope.Links[i].overrideRigidbodySettings);

                    if (EditorX.Circlelever(pos, isCustom ? new Color(0.7f, 0.3f, 0.3f) : Color.white, handleSz * (isCustom ? 0.7f : 0.5f)))
                    {
                        selectedLink = i;
                        this.Repaint();
                    }
                }
            }
        }
        private void OnSceneGUI()
        {
            var linkmap = (KuroiLinkMap)target;
            var navmesh = linkmap.NavMesh;

            if (navmesh == null)
            {
                return;
            }

            var navigationNodes = linkmap.nodes;

            if (navigationNodes == null || navigationNodes.Length != navmesh.Area)
            {
                return;
            }

            var grid      = navmesh.grid;
            var mousePos  = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition).origin;
            var mouseCell = grid.WorldToCell(mousePos);

            if (drawHeat)
            {
                var nodes = navmesh.Nodes;
                if (nodes == null || nodes.Length != navmesh.Area)
                {
                    return;
                }

                var highest = WithMostConnectionIndex;

                var min = navmesh.Min;
                var max = navmesh.Max;

                for (var x = min.x; x <= max.x; x++)
                {
                    for (var y = min.y; y <= max.y; y++)
                    {
                        var index = navmesh.IndexOfUnsafe(x, y);
                        var other = navmesh.Nodes[index];

                        if (other.IsSolid())
                        {
                            continue;
                        }

                        var node = navigationNodes[index];
                        var c    = node.directLinks.Length + node.gravitationalLinks.Length;
                        if (c == 0)
                        {
                            continue;
                        }

                        var color = Color.black;
                        color.r = ((float)c / highest);
                        color.a = 1;
                        UnityX.DrawCell(x, y, navmesh.grid, color, Color.clear);
                    }
                }
            }

            /*Handles.DrawSolidRectangleWithOutline(
             *  new Rect(
             *      (Vector2) mousePos - linkmap.hitBoxSize / 2, linkmap.hitBoxSize),
             *  Color.red,
             *  Color.clear
             * );*/
            for (var x = -linkRadius; x <= linkRadius; x++)
            {
                for (var y = -linkRadius; y <= linkRadius; y++)
                {
                    var gridPos = new Vector3Int(x, y, 0) + mouseCell;


                    var index = navmesh.IndexOfUnsafe(gridPos.x, gridPos.y);
                    if (index > navmesh.Nodes.Length)
                    {
                        continue;
                    }

                    var origin = grid.GetCellCenterWorld(gridPos);
                    var node   = navigationNodes[index];

                    if (drawDirect)
                    {
                        foreach (var link in node.directLinks)
                        {
                            var nI         = (Vector3Int)navmesh.PositionOf(link.Destination);
                            var pos        = grid.GetCellCenterWorld(nI);
                            var neightboor = navmesh.Nodes[link.Destination];
                            var dir        = pos - origin;
                            var n          = dir.normalized;
                            var color      = new Color((n.x + 1) / 2, (n.y + 1) / 2, 1);
                            EditorX.ForHandles(origin, dir, color);
                        }
                    }

                    if (drawGravitational)
                    {
                        foreach (var link in node.gravitationalLinks)
                        {
                            var   nI   = (Vector3Int)navmesh.PositionOf(link.Destination);
                            var   pos  = grid.GetCellCenterWorld(nI);
                            float size = 4;
                            var   p    = link.Path;


                            for (int i = 0; i < p.Length - 1; i++)
                            {
                                var current = p[i];
                                var next    = p[i + 1];
                                var dir     = next - current;
                                dir.Normalize();
                                var color = new Color((dir.x + 1) / 2, (dir.y + 1) / 2, 0);
                                var prog  = (float)i / p.Length;
                                color.b       = prog;
                                color.a       = 0.5F + (prog / 2);
                                Handles.color = color;
                                Handles.DrawLine(current, next);
                            }
                        }
                    }
                }
            }

            var radius = new Vector2Int(linkRadius, linkRadius);

            Handles.color = Color.red;
            EditorX.DrawBoundaries(
                (Vector2Int)mouseCell - radius,
                (Vector2Int)mouseCell + radius, grid
                );
        }
Example #3
0
    internal static void IconsGUI()
    {
        var useIcon = h2Settings.enableIcons;

        GuiX.xDrawTitleBar("ICONS SETTINGS", ref useIcon, -9f, -40f);
        h2Settings.enableIcons = useIcon;
        EditorGUI.BeginDisabledGroup(!useIcon);

        var idx = Hierarchy2.currentIconMode;
        var rr  = GUILayoutUtility.GetLastRect();

        if (iconModesDrawer == null)
        {
            iconModesDrawer = new h2StringBool {
                source = new StringBuilder(h2Settings.iconModes), total = h2Settings.nIcons
            };
        }

        if (modeTitles == null)
        {
            var list = new List <string> {
                "D"
            };
            for (var i = 1; i < h2Settings.nModes; i++)
            {
                list.Add("" + i);
            }
            modeTitles = list.ToArray();
        }

        idx = GUI.Toolbar(rr.r(470f).l(470f - (10f + 20f * h2Settings.nModes)), idx, modeTitles);
        iconModesDrawer.offset = idx * (h2Settings.nIcons + 1);

        if (idx != Hierarchy2.currentIconMode)
        {
            Hierarchy2.currentIconMode = idx;
            EditorX.xDelayCall(WindowX.Hierarchy.Repaint);
        }

        const int nCols = 3;

        using (GuiX.hzLayout) {
            for (var i = 0; i < iconTitles.Length; i++)
            {
                if (i % nCols == 0)
                {
                    GUILayout.BeginVertical();
                }
                iconModesDrawer.Draw(i, (j, v) => GuiX.GLToggle(v, iconTitles[j], 130f));
                if (i % nCols == nCols - 1 || i == iconTitles.Length - 1)
                {
                    GUILayout.EndVertical();
                }
            }
        }


        if (iconModesDrawer.changed)
        {
            //Debug.Log(h2Settings.iconModes + " ---> " + iconModesDrawer.source);
            h2Settings.iconModes = iconModesDrawer.source.ToString();
            //Debug.Log("after ---> " + h2Settings.iconModes);
        }

        EditorGUI.EndDisabledGroup();
    }
Example #4
0
        void OnSceneGUI()
        {
            if (!SplineEditor.ShowEditor || (Application.isPlaying && !ShowEditorInPlayMode))
            {
                return;
            }

            #region Keypress Events
            // Get Events
            float btnSize;
            int   pointsToDraw = spline.IsLooped ? spline.Points.Length - 1 : spline.Points.Length;
            //bool cntrlDwn = false;

            if (!Event.current.control)
            {
                btnSize = HandleUtility.GetHandleSize(transform.position) * handleSize;
                if (EditorX.CircleButton(transform.position, Color.red, btnSize))
                {
                    selectedControl = -1;
                    Tools.hidden    = false;
                }

                if (Tools.hidden && selectedControl == -1)
                {
                    Tools.hidden = false;
                }
            }
            else
            {
                Tools.hidden = true;
            }

            // Draw Spline
            for (int i = 0; i < pointsToDraw; i++)
            {
                Vector3 cpPos = transform.TransformPoint(spline.GetPoint(i));
                btnSize = HandleUtility.GetHandleSize(cpPos) * handleSize;

                bool isPivot = (i % 3) == 0;
                if (selectedControl == i)
                {
                    EditorX.DrawDot(cpPos, Color.yellow, isPivot ? btnSize : btnSize * 0.75f);

                    EditorGUI.BeginChangeCheck();

                    Vector3 newPos = transform.InverseTransformPoint(Handles.DoPositionHandle(cpPos, Quaternion.identity));

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(spline, "Moved Control Point");
                        spline.SetPoint(i, newPos);
                    }
                }
                else
                {
                    if (i == 0 && !Event.current.control)
                    {
                        continue;
                    }

                    if (EditorX.CircleButton(cpPos, isPivot ? Color.blue : Color.cyan, isPivot ? btnSize : btnSize * 0.75f))
                    {
                        selectedControl = i;
                        Tools.hidden    = true;

                        Repaint();
                    }
                }
            }

            for (int i = 0; i < spline.ControlCount; i++)
            {
                Vector3 p0 = transform.TransformPoint(spline.GetPoint((i * 3) + 0));
                Vector3 p1 = transform.TransformPoint(spline.GetPoint((i * 3) + 1));
                Vector3 p2 = transform.TransformPoint(spline.GetPoint((i * 3) + 2));
                Vector3 p3 = transform.TransformPoint(spline.GetPoint((i * 3) + 3));

                Handles.color = Color.green;
                Handles.DrawDottedLine(p0, p3, 5f);

                Handles.color = Color.black;
                Handles.DrawAAPolyLine(null, 2f, p0, p1);
                Handles.DrawAAPolyLine(null, 2f, p2, p3);

                Vector3 center   = (p0 + p3) * 0.5f;
                float   handleSz = HandleUtility.GetHandleSize(center) * handleSize;

                if (EditorX.CircleButton(center, Color.green, handleSz * 0.7f))
                {
                    Undo.RecordObject(spline, "Added Spline Point");
                    spline.AddCurve(i);
                    Repaint();
                }
            }

            DrawSpline();

            Event e = Event.current;
            switch (e.type)
            {
            case EventType.KeyDown:
            {
                switch (e.keyCode)
                {
                case KeyCode.Backspace:
                {
                    // Delete Selected Control
                    Undo.RecordObject(spline, "Deleted Spline Point");

                    spline.RemoveCurve(selectedControl / 3);
                    selectedControl = -1;

                    EditorUtility.SetDirty(spline);
                    e.Use();
                }
                break;

                default:
                    break;
                }
            }
            break;
            }
            #endregion
        }