コード例 #1
0
    private void BuildCurve(int __roadSize, Directions __from, Directions __to)
    {
        Quaternion __newRotation = Quaternion.identity;

        switch (__from)
        {
        case Directions.Up:
        {
            currentSpot.y++;

            __newRotation = __to == Directions.Right ?
                            Quaternion.Euler(new Vector3(0, 180, 0)) :
                            Quaternion.Euler(new Vector3(0, -90, 0));

            break;
        }

        case Directions.Down:
        {
            currentSpot.y--;

            if (__to == Directions.Right)
            {
                __newRotation = Quaternion.Euler(new Vector3(0, 90, 0));
            }

            break;
        }

        case Directions.Left:
        {
            currentSpot.x--;

            __newRotation = __to == Directions.Down ?
                            Quaternion.Euler(new Vector3(0, 180, 0)) :
                            Quaternion.Euler(new Vector3(0, 90, 0));

            break;
        }

        case Directions.Right:
        {
            currentSpot.x++;

            if (__to == Directions.Down)
            {
                __newRotation = Quaternion.Euler(new Vector3(0, 270, 0));
            }
            break;
        }
        }

        if (!Map[currentSpot.x, currentSpot.y].Value)
        {
            GameObject a = InstantiateBlock(_prefabs, Blocks.Curve);
            a.transform.rotation = __newRotation;

            Tiles.Add(a);
            Ints.Add((int)Blocks.Curve);
        }
        else
        {
            int index = 0;
            if (Tiles.Contains(Map[currentSpot.x, currentSpot.y].Value))
            {
                for (int i = 0; i < Tiles.Count; i++)
                {
                    if (Tiles[i] == Map[currentSpot.x, currentSpot.y].Value)
                    {
                        index = i;
                    }
                }
            }

            Ints.RemoveAt(index);
            Tiles.RemoveAt(index);

            Destroy(Map[currentSpot.x, currentSpot.y].Value);
            GameObject a = InstantiateBlock(_prefabs, Blocks.Intersection);

            Tiles.Insert(index, a);
            Ints.Insert(index, (int)Blocks.Intersection);
        }


        buildCurve = false;
    }