コード例 #1
0
    Vector2 GetValidDest(Vector2 Destination)
    {
        Vector2 PosInUnit = ZDGameRule.WorldToUnit(transform.position);
        Vector2 DesInUnit = ZDGameRule.WorldToUnit(ZDGameRule.QuadrifyDirection(Destination, transform.position));

        for (int i = 0; i < 2; ++i)
        {
            if (!PosInUnit[i].Equals(DesInUnit[i]))
            {
                int     Delta  = (PosInUnit[i] < DesInUnit[i] ? 1 : -1);
                Vector2 CurPos = PosInUnit;

                while (true)
                {
                    //Move To Currently Checking Position.
                    CurPos[i] += Delta;
                    if (!ZDMap.IsUnitInMap(CurPos) || ZDMap.HitAtUnit(CurPos, EObjectType.Obstacle) != null)
                    {
                        //Return To Last Position.
                        CurPos[i] -= Delta;
                        return(ZDGameRule.UnitToWorld(CurPos));
                    }
                    if (CurPos[i].Equals(DesInUnit[i]))
                    {
                        break;
                    }
                }
                return(ZDGameRule.UnitToWorld(DesInUnit));
            }
        }
        return(transform.position);
    }
コード例 #2
0
        static public void RevisePosition(ZDObject Caller)
        {
            Vector3 UnitLoc = ZDGameRule.WorldToUnit(Caller.transform.position);

            if (Mathf.Abs(UnitLoc.x) > ZDGameRule.MAP_WIDTH_UNIT / 2)
            {
                UnitLoc.x = (UnitLoc.x > 0 ? 1 : -1) * ZDGameRule.MAP_WIDTH_UNIT / 2;
            }
            if (Mathf.Abs(UnitLoc.y) > ZDGameRule.MAP_HEIGHT_UNIT / 2)
            {
                UnitLoc.y = (UnitLoc.y > 0 ? 1 : -1) * ZDGameRule.MAP_HEIGHT_UNIT / 2;
            }
            Caller.transform.position = ZDGameRule.UnitToWorld(UnitLoc);
        }