コード例 #1
0
ファイル: CollisionMap.cs プロジェクト: zkactivity/Diablerie
        public static Cell GetCell(Vector3 pos)
        {
            var tilePos = Iso.Snap(pos);
            int index   = instance.MapToIndex(tilePos);

            return(instance.map[index]);
        }
コード例 #2
0
ファイル: CollisionMap.cs プロジェクト: zkactivity/Diablerie
        public static int OverlapBox(Vector2 center, Vector2 size, GameObject[] result)
        {
            int count = 0;

            if (result.Length == 0)
            {
                return(0);
            }
            int rows    = Mathf.RoundToInt(size.y);
            int columns = Mathf.RoundToInt(size.x);
            int index   = instance.MapToIndex(Iso.Snap(center - size / 2));

            for (int row = 0; row < rows; ++row)
            {
                for (int column = 0; column < columns; ++column)
                {
                    var gameObject = instance.map[index + column].gameObject;
                    if (gameObject != null)
                    {
                        result[count] = gameObject;
                        count        += 1;
                        if (count >= result.Length)
                        {
                            return(count);
                        }
                    }
                }
                index += instance.width;
            }
            return(count);
        }
コード例 #3
0
ファイル: IsoInput.cs プロジェクト: zkactivity/Diablerie
        void Update()
        {
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            mousePosition = Iso.MapToIso(mousePos);
            mouseTile     = Iso.Snap(mousePosition);
        }
コード例 #4
0
ファイル: Pathing.cs プロジェクト: zkactivity/Diablerie
        public static List <Step> BuildPath(Vector2 from_, Vector2 target_, float minRange = 0.1f, int size = 2, GameObject self = null, int depth = 100)
        {
            UnityEngine.Profiling.Profiler.BeginSample("BuildPath");
            Vector2i from = Iso.Snap(from_);

            target = Iso.Snap(target_);
            path.Clear();
            if (from == target)
            {
                UnityEngine.Profiling.Profiler.EndSample();
                return(path);
            }
            openNodes.Clear();
            Node.Recycle(closeNodes);

            Pathing.size = size;
            Pathing.self = self;
            Node startNode = Node.Get();

            startNode.parent         = null;
            startNode.pos            = from;
            startNode.gScore         = 0;
            startNode.hScore         = Vector2i.manhattanDistance(from, target);
            startNode.score          = int.MaxValue;
            startNode.directionIndex = -1;
            openNodes.Add(startNode);
            closeNodes.Add(startNode);
            int  iterCount = 0;
            Node bestNode  = startNode;

            while (openNodes.Count > 0)
            {
                Node node = openNodes.Take();

                if (node.hScore < bestNode.hScore)
                {
                    bestNode = node;
                }
                if (node.hScore <= minRange)
                {
                    TraverseBack(node);
                    break;
                }
                StepTo(node);
                iterCount += 1;
                if (iterCount > depth)
                {
                    TraverseBack(bestNode);
                    break;
                }
            }
            //foreach (Node node in closeNodes)
            //{
            //    Iso.DebugDrawTile(node.pos, Color.magenta, 0.3f);
            //}
            //foreach (Node node in openNodes)
            //{
            //    Iso.DebugDrawTile(node.pos, Color.green, 0.3f);
            //}
            UnityEngine.Profiling.Profiler.EndSample();
            return(path);
        }
コード例 #5
0
ファイル: CollisionMap.cs プロジェクト: zkactivity/Diablerie
 public static void SetBlocked(Vector3 pos, CollisionLayers value)
 {
     SetBlocked(Iso.Snap(pos), value);
 }
コード例 #6
0
ファイル: CollisionMap.cs プロジェクト: zkactivity/Diablerie
 public static bool Passable(Vector3 pos, CollisionLayers mask, int size = 1, GameObject ignore = null)
 {
     return(Passable(Iso.Snap(pos), mask, size, ignore));
 }
コード例 #7
0
ファイル: CollisionMap.cs プロジェクト: zkactivity/Diablerie
 private int MapToIndex(Vector3 pos)
 {
     return(MapToIndex(Iso.Snap(pos)));
 }
コード例 #8
0
ファイル: CollisionMap.cs プロジェクト: zkactivity/Diablerie
 public static void SetPassable(Vector3 pos, int sizeX, int sizeY, bool passable, GameObject gameObject)
 {
     SetPassable(Iso.Snap(pos), sizeX, sizeY, passable, gameObject);
 }