コード例 #1
0
ファイル: Game.cs プロジェクト: Hengle/Framework-2
        public static Point3 LocalGridRotated(Point3 pos, float angle)
        {
            var calcPosV3 = Quaternion.AngleAxis(angle, Vector3.up) * pos.toVector3();

            return(new Point3(
                       (int)Math.Round(calcPosV3.x),
                       (int)Math.Round(calcPosV3.y),
                       (int)Math.Round(calcPosV3.z)));
        }
コード例 #2
0
        private void UpdateRegularPathfinding()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                ToggleDoors();
            }
            var cell = new Point3(_moveTarget.position);

            cell.y = 0;
            if (cell != _lastPositionP3)
            {
                _lastPositionP3 = cell;
                World.Get <PathfindingSystem>().Grid.ClearLocks();
                for (int i = 0; i < _entities.Count; i++)
                {
                    _entities[i].Post(new SetMoveTarget(null, _lastPositionP3.toVector3(), null));
                }
            }
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: Hengle/Framework-2
        public static Point3 LocalGridRotated(Point3 pos, Transform tr)
        {
            var calcPosV3 = Quaternion.AngleAxis(tr.rotation.eulerAngles.y, Vector3.up) * pos.toVector3();

            return(new Point3(
                       (int)Math.Round(calcPosV3.x),
                       (int)Math.Round(calcPosV3.y),
                       (int)Math.Round(calcPosV3.z)));
        }
コード例 #4
0
        void OnDrawGizmos()
        {
            Gizmos.DrawSphere((transform.position + _target), 0.5f);
            if (_pathfinderTest != null)
            {
                for (int i = 0; i < _pathfinderTest.Count; i++)
                {
                    var node = _pathfinderTest[i];
                    UnityEditor.Handles.color = node.Color;
                    Gizmos.color = node.Color;
                    Gizmos.DrawWireCube(node.Position, Vector3.one * 0.9f);
                    UnityEditor.Handles.Label(node.Position, node.TotalCost.ToString("F1"));  //string.Format("{0:F1}/{1:F1}", node.StarCost, node.EndCost));
                }
            }
            if (_spiralPoints != null)
            {
                var center = new Point3(transform.position);
                for (int i = 0; i < _spiralPoints.Length; i++)
                {
                    var pos = center + _spiralPoints[i];
                    UnityEditor.Handles.Label(pos.toVector3(), i.ToString());
                    Gizmos.DrawWireCube(pos.toVector3(), Vector3.one);
                }
            }
            var simpleGrid = World.Get <PathfindingSystem>().Grid;

            if (simpleGrid == null || simpleGrid.CellsCount == 0)
            {
                return;
            }
            RunActionOnCells(
                c => {
                var p3   = new Point3(c.WorldPositionV3);
                var size = Game.MapCellSize / 2;
                for (int x = -size; x <= size; x++)
                {
                    for (int z = -size; z <= size; z++)
                    {
                        var pos = new Point3(p3.x + x, p3.y, p3.z + z);
                        Color color;
                        if (!simpleGrid.IsWalkable(pos, false))
                        {
                            color = Color.red;
                        }
                        else
                        {
                            color = Color.Lerp(Color.green, Color.yellow, Mathf.InverseLerp(_defaultCost, _occupiedCost, simpleGrid.GetTraversalCost(pos)));
                        }
                        //else if (simpleGrid.Targets.ContainsKey(pos)) {
                        //    color = Color.blue;
                        //}
                        Gizmos.color = color;
                        Gizmos.DrawWireCube(pos.toVector3(), Vector3.one * 0.9f);
                        //UnityEditor.Handles.Label(pos.toVector3(), string.Format("{0}{2}{1}", pos, simpleGrid.GetTraversalCost(pos).ToString("F1"), System.Environment.NewLine));
                    }
                }
            });
            //for (int i = 0; i < _cells.Count; i++) {
            //    var cell = _cells[i];
            //    var pos = cell.Position;
            //    var walkable = cell.Walkable;
            //    Gizmos.color = walkable ? Color.green : Color.red;
            //    Gizmos.DrawWireCube(pos.toVector3() + (Vector3.one * _drawOffset), Vector3.one);
            //    //UnityEditor.Handles.Label(pos.toVector3() + (Vector3.one * _drawOffset), string.Format("O:{0}{3}P:{1}{3}W:{2}", cell.Origin, cell.Position, cell.CheckDir, System.Environment.NewLine));
            //}
        }