コード例 #1
0
    void OnDestroy()
    {
        //being paranoid again, make absolute sure you are removed from the grids before being destroyed
        //but this shouldn't really ever get called
        if (GridManagement.IsInGrid(gameObject))
        {
            GridManagement.ClearPosition(GridManagement.GetPositionOfObject(gameObject), solid);
        }


        GridMovementGeneral.StopCoroutines(gameObject); //and stop any movement coroutines that are on it
    }
コード例 #2
0
    /// <summary>
    /// set an object to a position in the grid. Returns an object that is in the way if overwrite is false. returns null when it all worked.
    /// </summary>
    /// <param name="objectToSet"> this is the object you are moving to the position</param>
    /// <param name="newPosition"> this is said position. will be rounded to ints</param>
    /// <param name="overWrite"> false by default, if true it will destroy any object in that spot</param>
    /// <param name="handleMovement"> true by default, this lets setObjectToPosition instantly snap the object to the position. if false, that implies you would have to do the physical movement yourself</param>
    /// <returns></returns>
    public static GameObject SetObjectToPosition(GameObject objectToSet, Vector3 newPosition, bool handleMovement = true, bool overWrite = false, bool solid = true)
    {
        ///start with a round
        newPosition = RoundVectorToInts(newPosition);


        if (solid)
        {
            GameObject ObjectInNextPosition = getObjectFromPosition(newPosition);
            if (ObjectInNextPosition != null && ObjectInNextPosition.GetComponent <GridObject>().solid)
            {
                //if theres something in the way and overwrite is true:
                if (overWrite)
                {
                    if (ObjectInNextPosition.name.Contains("Player") || ObjectInNextPosition.tag == "Wall")
                    {
                        return(ObjectInNextPosition);
                    }
                    //kill it
                    DeleteObject(ObjectInNextPosition);
                }
                else
                {
                    //dont kill it, return it
                    //print("there's something in the way!");
                    //delete this guy
                    //Destroy(objectToSet);
                    return(ObjectInNextPosition);
                }
            }

            //after that, only get rid of old object if you are actually going to move
            Vector3 previousPosition = GetPositionOfObject(objectToSet);
            if (previousPosition != nullVector)
            {
                //if the object was somewhere else in the grid originally, clear those positions on the grids
                ClearPosition(previousPosition, true);
            }
            //write floor to the space you were previously
            ClearPosition(previousPosition, false);
            Instantiate(instance.voidPrefab, previousPosition, Quaternion.identity);

            //and remove space from the position you are going to
            ClearPosition(newPosition, false);

            //actual movement
            FillPosition(objectToSet, newPosition);

            if (handleMovement)
            {
                //do the most basic physical movement
                GridMovementGeneral.MovementByType(objectToSet, newPosition, objectToSet.transform.rotation, GridMovementGeneral.MovementTypes.Instant);
            }



            return(null); //on a successful movement, return null I guess, peeps would probably wanna check if it worked
        }
        else
        {
            FillFloorPosition(objectToSet, newPosition);
            return(null);
        }
    }
コード例 #3
0
 public void Start()
 {
     instance = this;
 }
コード例 #4
0
 void Move(GameObject thing)
 {
     GridMovementGeneral.MovementByType(thing, thing.transform.position + dir, Quaternion.identity, GridMovementGeneral.MovementTypes.Smooth);
 }