示例#1
0
    private void Awake()
    {
        this.myRigidbody = this.GetComponent <Rigidbody>();
        this.cellable    = this.GetComponent <SnakeCharacter>().cellable;

        this.targetMask = 1 << LayerMask.NameToLayer("Ground");

        // Data
        this.data.snakeRigidbody      = this.myRigidbody;
        this.data.snakeMovementEvents = new SnakeMovementEvents();
        this.data.snakeController     = this;
    }
示例#2
0
    public List <Step> GetAnotherPathFor(Cellable e)
    {
        List <Step>       steps;
        PlanetPathfinding pathfinder;

        if (!pathfinders.ContainsKey(e.currentSurface))
        {
            Debug.LogError($"ERROR : Could not find the pathfinder associated with the surface of {e} !");
            return(null);
        }

        pathfinder = pathfinders[e.currentSurface];
        steps      = pathfinder.GetAnotherPath(e);

        return(steps);
    }
示例#3
0
    /* ---------------------------------------------------------------------------------------------*/
    /* ---------------------------------------------------------------------------------------------*/
    /* ---------------------------------------------------------------------------------------------*/
    /* ------------------------------------- PUBLIC FUNCTIONS --------------------------------------*/
    /* ---------------------------------------------------------------------------------------------*/
    /* ---------------------------------------------------------------------------------------------*/
    /* ---------------------------------------------------------------------------------------------*/
    public List <Step> GetPathTo(Cellable e, Vector3 dest, Vector3 normal, AstarMoveMode mode = AstarMoveMode.Diagonal)
    {
        List <Step>       steps;
        PlanetPathfinding pathfinder;

        if (!pathfinders.ContainsKey(e.currentSurface))
        {
            Debug.LogError($"ERROR : Could not find the pathfinder associated with the surface of {e} !");
            return(null);
        }

        pathfinder = pathfinders[e.currentSurface];
        steps      = pathfinder.GetPath(e, dest, normal, mode);

        return(steps);
    }
示例#4
0
        public List <Step> GetPath(Cellable e, Vector3 target, Vector3 targetNormal, AstarMoveMode mode = AstarMoveMode.Diagonal)
        {
            Path path;

            int[]          from, to;
            List <Vector2> indexes;
            Grill          fromgrill, togrill;
            List <Step>    steps;


            if (!paths.ContainsKey(e))
            {
                path = new Path();
                this.paths.Add(e, path);
                indexes = new List <Vector2>();
            }
            else
            {
                path    = this.paths[e];
                indexes = path.indexes;
            }


            fromgrill = e.currentCell.grill;
            togrill   = this.surface.GetGrillOf(target, targetNormal);

            from = fromgrill.GetIndexInGrill(e.currentCell.position);
            to   = togrill.GetIndexInGrill(target);

            // store data
            path.Store(indexes, togrill, to, mode);

            if (fromgrill == togrill)
            {
                steps = this.FindPath(indexes, fromgrill, from, to, mode);
            }
            else
            {
                Debug.LogWarning("WARNING : Pathfinding among several faces is not yet implemented and may never be...");
                steps = null;
                // steps = this.FindPathAmongGrill(indexes, fromgrill, togrill, from, to, mode);
            }

            path.steps = steps;

            return(steps);
        }
示例#5
0
        public List <Step> GetAnotherPath(Cellable e)
        {
            Path          path;
            AstarMoveMode mode;

            int[]          from, to;
            List <Vector2> indexes;
            Grill          fromgrill, togrill;
            List <Step>    steps;

            if (!paths.ContainsKey(e))
            {
                Debug.LogError($"ERROR : This planet element {e} never asked for a path to begin with !");
                return(null);
            }

            // get stored data
            path    = this.paths[e];
            indexes = path.indexes;
            togrill = path.togrill;
            to      = path.to;
            mode    = path.mode;
            steps   = path.steps;

            fromgrill = e.currentCell.grill;
            from      = fromgrill.GetIndexInGrill(e.currentCell.position);

            // update grid
            this.UpdateGridOf(fromgrill);

            if (fromgrill == togrill)
            {
                this.FindPath(indexes, fromgrill, from, to, mode, steps);
            }
            else
            {
                Debug.LogWarning("WARNING : Pathfinding among several faces is not yet implemented and may never be...");
                steps = null;
                // steps = this.FindPathAmongGrill(indexes, fromgrill, togrill, from, to, mode);
            }

            return(steps);
        }