Exemple #1
0
    public bool TryMoveTo(IntVector3 to)
    {
        bool toReturn = false;

        IntVector3 from = intTransform.position;

        if (OccupantManager.S.OccupantAt(to) != null)
        {
            toReturn = false;
        }
        else
        {
            OccupantManager.S.occupants.Remove(from);
            OccupantManager.S.occupants[to] = this.gameObject;
            intTransform.position           = to;
            toReturn = true;

            foreach (IOnMove onMove in this.GetComponentsInChildren <IOnMove>())
            {
                onMove.OnMove(from, to);
            }
        }


        if (rotate)
        {
            IntVector3 groundedFrom = new IntVector3(from.x, 0, from.z);
            IntVector3 groundedTo   = new IntVector3(to.x, 0, to.z);
            IntVector3 diff         = groundedTo - groundedFrom;

            if (diff.x != 0 || diff.z != 0)
            {
                Quaternion   fromRot      = this.transform.rotation;
                Quaternion   toRot        = IntVector3.RotationFromDir(diff);
                SmoothRotate smoothRotate = this.GetComponentInChildren <SmoothRotate>();
                if (smoothRotate)
                {
                    smoothRotate.OnRotate(fromRot, toRot);
                }
                this.transform.rotation = toRot;
            }
        }
        return(toReturn);
    }