예제 #1
0
        private void DrawRuleMatrix(RuleTile tile, Rect rect, RuleTile.Rule rule)
        {
            var index = 0;
            var w     = rect.width / 3;
            var h     = rect.height / 3;
            var color = new Color(0, 0, 0, 0.2f);

            for (var y = 0; y <= 3; y++)
            {
                var top = rect.yMin + y * h;
                HandleHelper.DrawLine(new Vector2(rect.xMin, top), new Vector2(rect.xMax, top), color);
            }

            for (var x = 0; x <= 3; x++)
            {
                var left = rect.xMin + x * w;
                HandleHelper.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax), color);
            }

            for (var y = 0; y <= 2; y++)
            {
                for (var x = 0; x <= 2; x++)
                {
                    var r = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1);

                    if (x != 1 || y != 1)
                    {
                        var currentRule = rule.Neighbors[index];

                        DrawRule(tile, r, new Vector2Int(x, y), currentRule);

                        index++;
                    }
                    else
                    {
                        if (!rule.UseReference)
                        {
                            if (rule.Tile.FlipHorizontal)
                            {
                                GUI.DrawTexture(r, RuleTileEditor.Textures[10]);
                            }

                            if (rule.Tile.FlipVertical)
                            {
                                GUI.DrawTexture(r, RuleTileEditor.Textures[11]);
                            }

                            if (rule.Tile.Rotation != 0)
                            {
                                GUI.DrawTexture(r, RuleTileEditor.Textures[5]);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        private void DrawBounds()
        {
            var bounds       = _building.Bounds;
            var roofPosition = new Vector2(bounds.center.x, bounds.yMax - _building.RoofHeight);
            var size         = HandleUtility.GetHandleSize(bounds.center) * 0.1f;

            HandleHelper.DrawLine(new Vector2(bounds.xMin, roofPosition.y), new Vector2(bounds.xMax, roofPosition.y), Color.cyan);

            var selectedBounds       = HandleHelper.BoundsHandle(bounds, new Vector2(0.5f, 0.5f), Color.blue, Color.clear, Color.white, Color.white);
            var selectedRoofPosition = HandleHelper.MoveHandle(roofPosition, new Vector2(size * 2.5f, size), Vector2.one, Color.cyan, Color.cyan);

            UpdateMainTransforms(selectedBounds, _building.SortPoint, bounds.yMax - selectedRoofPosition.y, true);
        }
예제 #3
0
        private void DrawRuleMatrix(RuleTile tile, Rect rect, RuleTile.Rule rule)
        {
            var index = 0;
            var w     = rect.width / 3;
            var h     = rect.height / 3;
            var color = new Color(0, 0, 0, 0.2f);

            for (var y = 0; y <= 3; y++)
            {
                var top = rect.yMin + y * h;
                HandleHelper.DrawLine(new Vector2(rect.xMin, top), new Vector2(rect.xMax, top), color);
            }

            for (var x = 0; x <= 3; x++)
            {
                var left = rect.xMin + x * w;
                HandleHelper.DrawLine(new Vector2(left, rect.yMin), new Vector2(left, rect.yMax), color);
            }

            for (var y = 0; y <= 2; y++)
            {
                for (var x = 0; x <= 2; x++)
                {
                    var r = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1);

                    if (x != 1 || y != 1)
                    {
                        var currentRule = rule.Neighbors[index];

                        DrawRule(tile, r, new Vector2Int(x, y), currentRule);

                        if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
                        {
                            if (Event.current.button == 0)
                            {
                                rule.Neighbors[index] = (RuleTile.NeighborType)Mathf.Repeat((int)currentRule + 1, (int)RuleTile.NeighborType.Count);

                                GUI.changed = true;
                                Event.current.Use();
                            }
                        }

                        index++;
                    }
                    else
                    {
                        if (!rule.UseReference)
                        {
                            if (rule.Tile.FlipHorizontal)
                            {
                                GUI.DrawTexture(r, Textures[10]);
                            }

                            if (rule.Tile.FlipVertical)
                            {
                                GUI.DrawTexture(r, Textures[11]);
                            }

                            if (rule.Tile.Rotation != 0)
                            {
                                GUI.DrawTexture(r, Textures[5]);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        private void OnSceneGUI()
        {
            if (_pathController.Path.Nodes.Length > 0)
            {
                var lineColor         = Color.cyan;
                var fillColor         = new Color(0.0f, 1.0f, 1.0f, 0.2f);
                var mover             = _pathController.GetComponent <Mover>();
                var pathfinding       = ComponentHelper.GetComponentInScene <Pathfinding>(_pathController.gameObject.scene.buildIndex, false);
                var transformPosition = _pathController.Path.UseAbsolutePositioning ? Vector2.zero : (Vector2)_pathController.transform.position;

                if (_pathController.Path.Nodes.Length > 2 && _pathController.Path.Type == Path.PathType.Loop)
                {
                    var first = _pathController.Path.Nodes[0];
                    var last  = _pathController.Path.Nodes[_pathController.Path.Nodes.Length - 1];

                    var firstPosition = GetPosition(first.Position, _pathController.transform.position, Mover.PositionOffset);
                    var lastPosition  = GetPosition(last.Position, transformPosition, Mover.PositionOffset);

                    if (_pathController.Path.UsePathfinding && pathfinding)
                    {
                        var pathFrom = GetPathPosition(first.Position, _pathController.transform.position);
                        var pathTo   = GetPathPosition(last.Position, transformPosition);
                        var path     = pathfinding.GetPath(mover.MovementLayer, pathFrom, pathTo, false);

                        if (path.Count > 1)
                        {
                            for (var n = 1; n < path.Count; n++)
                            {
                                var node     = path[n];
                                var position = node + Mover.PositionOffset;

                                HandleHelper.DrawLine(position, firstPosition, lineColor);

                                firstPosition = position;
                            }
                        }
                    }
                    else
                    {
                        HandleHelper.DrawLine(lastPosition, firstPosition, lineColor);
                    }
                }

                for (var i = 1; i < _pathController.Path.Nodes.Length; i++)
                {
                    var previous = _pathController.Path.Nodes[i - 1];
                    var current  = _pathController.Path.Nodes[i];

                    var previousPosition = GetPosition(previous.Position, i == 1 ? (Vector2)_pathController.transform.position : transformPosition, Mover.PositionOffset);
                    var currentPosition  = GetPosition(current.Position, transformPosition, Mover.PositionOffset);

                    if (_pathController.Path.UsePathfinding && pathfinding)
                    {
                        var pathFrom = GetPathPosition(previous.Position, i == 1 ? (Vector2)_pathController.transform.position : transformPosition);
                        var pathTo   = GetPathPosition(current.Position, transformPosition);
                        var path     = pathfinding.GetPath(mover.MovementLayer, pathFrom, pathTo, false);

                        if (path.Count > 1)
                        {
                            for (var n = 1; n < path.Count; n++)
                            {
                                var node     = path[n];
                                var position = node + Mover.PositionOffset;

                                HandleHelper.DrawLine(position, previousPosition, lineColor);

                                previousPosition = position;
                            }
                        }
                    }
                    else
                    {
                        HandleHelper.DrawLine(currentPosition, previousPosition, Color.cyan);
                    }
                }

                for (var i = 0; i < _pathController.Path.Nodes.Length; i++)
                {
                    var node             = _pathController.Path.Nodes[i];
                    var position         = GetPosition(node.Position, i == 0 ? (Vector2)_pathController.transform.position : transformPosition, Mover.PositionOffset);
                    var selectedPosition = HandleHelper.MoveHandle(position, Vector2.one, lineColor, fillColor, 0.25f);

                    if (i != 0 && position != selectedPosition)
                    {
                        selectedPosition -= transformPosition;

                        using (new UndoScope(_pathController, true))
                            _pathController.Path.Nodes[i].Position = Vector2Int.FloorToInt(selectedPosition);
                    }

                    if (node.Delay > 0 && node.Direction != MovementDirection.None)
                    {
                        HandleHelper.DrawArrow(selectedPosition, Direction.GetVector(node.Direction), 0.25f, Color.white);
                    }

                    HandleHelper.DrawText(new Vector2(selectedPosition.x, selectedPosition.y + 0.05f), i.ToString(), TextAnchor.MiddleCenter, Color.white);
                }
            }
        }