Beispiel #1
0
        private void HandleNormal(Bounds portalBounds, GridPortalComponent p)
        {
            var grid = GridManager.instance.GetGridComponent(_portalRectStart);

            if (grid == null)
            {
                grid = GridManager.instance.GetGridComponent(_portalRectEnd);
                if (grid == null)
                {
                    return;
                }
            }

            portalBounds = EditorUtilitiesInternal.SnapToGrid(grid, portalBounds, _gridConnectMode);

            if (p.relativeToTransform)
            {
                portalBounds.center = p.transform.InverseTransformPoint(portalBounds.center);
            }

            if (_shiftDown)
            {
                p.portalTwo = portalBounds;
            }
            else
            {
                p.portalOne = portalBounds;
            }
        }
Beispiel #2
0
        private void HandleFieldDefinition()
        {
            if (!_inDrawMode)
            {
                return;
            }

            var p          = this.target as SimpleCostField;
            int id         = GUIUtility.GetControlID(_idHash, FocusType.Passive);
            var groundRect = new Plane(Vector3.up, new Vector3(0f, 0f, 0f));

            var evt = Event.current;

            if (evt.type == EventType.MouseDown && evt.button == 0)
            {
                GUIUtility.hotControl = id;

                evt.Use();

                if (!EditorUtilitiesInternal.MouseToWorldPoint(groundRect, out _boundsRectStart))
                {
                    GUIUtility.hotControl = 0;
                }

                _boundsRectEnd = _boundsRectStart;
                return;
            }
            else if (evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Escape)
            {
                GUIUtility.hotControl = id;
                evt.Use();
                return;
            }
            else if (evt.type == EventType.KeyUp && evt.keyCode == KeyCode.Escape)
            {
                GUIUtility.hotControl = 0;
                evt.Use();
                _inDrawMode = false;
                this.Repaint();

                return;
            }
            else if (GUIUtility.hotControl != id)
            {
                return;
            }

            if (evt.type == EventType.MouseDrag)
            {
                evt.Use();

                if (!EditorUtilitiesInternal.MouseToWorldPoint(groundRect, out _boundsRectEnd))
                {
                    _boundsRectEnd = _boundsRectStart;
                }
            }
            else if (evt.type == EventType.MouseUp)
            {
                GUIUtility.hotControl = 0;
                evt.Use();

                _boundsRectStart.y = _boundsRectEnd.y = Mathf.Max(_boundsRectStart.y, _boundsRectEnd.y);

                var grid = GridManager.instance.GetGridComponent(_boundsRectStart);
                if (grid == null)
                {
                    grid = GridManager.instance.GetGridComponent(_boundsRectEnd);
                    if (grid == null)
                    {
                        return;
                    }
                }

                var startToEnd  = (_boundsRectEnd - _boundsRectStart);
                var fieldBounds = new Bounds(
                    _boundsRectStart + (startToEnd * 0.5f),
                    new Vector3(Mathf.Abs(startToEnd.x), Mathf.Abs(startToEnd.y) + 0.1f, Mathf.Abs(startToEnd.z)));

                fieldBounds = EditorUtilitiesInternal.SnapToGrid(grid, fieldBounds, false);

                if (p.relativeToTransform)
                {
                    fieldBounds.center = p.transform.InverseTransformPoint(fieldBounds.center);
                }

                p.bounds = fieldBounds;

                EditorUtility.SetDirty(p);
            }
            else if (evt.type == EventType.Repaint)
            {
                Handles.color = p.gizmoColor;
                var c1 = new Vector3(_boundsRectStart.x, _boundsRectStart.y, _boundsRectEnd.z);
                var c2 = new Vector3(_boundsRectEnd.x, _boundsRectEnd.y, _boundsRectStart.z);
                Handles.DrawDottedLine(_boundsRectStart, c1, 10f);
                Handles.DrawDottedLine(c1, _boundsRectEnd, 10f);
                Handles.DrawDottedLine(_boundsRectEnd, c2, 10f);
                Handles.DrawDottedLine(c2, _boundsRectStart, 10f);
            }
        }