示例#1
0
    public void ReplaceContained(CONTAINED newContained, int state)
    {
        Destroy(this.transform.Find(contained.ToString()).gameObject);
        contained = newContained;

        containedObject      = Instantiate(contained.GetPrefab(), transform.position, Quaternion.identity, this.transform) as GameObject;
        containedObject.name = newContained.ToString();
        behaviour            = containedObject.GetComponent <IBehaviour>();

        behaviour.Initialize(state);
        behaviour.SetSprite(tileset);

        this.name = contained.ContainsNone() ? type.ToString() : contained.ToString();
    }
示例#2
0
    public void SetUpTile(TYPE typeSetUp, CONTAINED containedSetup, int state, int room_tileset, int[] position)
    {
        foreach (Transform child in transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        typeObject      = Instantiate(Resources.Load("Prefabs/Type"), transform.position, Quaternion.identity, this.transform) as GameObject;
        typeObject.name = "Type";
        this.position   = position;

        Transform typeSprite = typeObject.transform;

        type      = typeSetUp;
        contained = containedSetup;
        canPass   = true;
        reserved  = false;

        tileset = room_tileset;

        switch (typeSetUp)
        {
        case TYPE.floor:
            fireObject      = Instantiate(Resources.Load("Prefabs/Fire"), transform.position, Quaternion.identity, this.transform) as GameObject;
            fireScript      = fireObject.GetComponent <Fire>();
            fireObject.name = "Fire";
            room_images     = getRoomImages(room_tileset, floor_images);
            typeSprite.GetComponent <SpriteRenderer>().sprite = room_images[Random.Range(0, room_images.Length - 1)];
            break;

        case TYPE.wall:
            typeSprite.GetComponent <SpriteRenderer>().sprite = wall_images[Random.Range(0, wall_images.Length - 1)];
            canPass = false;
            break;

        case TYPE.front_wall:
            room_images = getRoomImages(room_tileset, front_wall_images);
            typeSprite.GetComponent <SpriteRenderer>().sprite = room_images[Random.Range(0, room_images.Length - 1)];
            canPass = false;
            break;

        case TYPE.breakable_wall:
            //room_images = getRoomImages(room_tileset, breakable_wall_images);
            canPass = false;
            break;

        case TYPE.stair_up:
            Sprite orientation;

            if (position[1] == 1)
            {
                orientation = stair_up_bottom_image;
            }
            else if (position[1] >= GameManager.instance.GetComponent <LevelGenerator>().columns - 3)
            {
                orientation = stair_up_top_image;
            }
            else if (position[0] == (GameManager.instance.level - 1) * GameManager.instance.boardScript.rows + 1)
            {
                orientation = stair_up_left_image;
            }
            else
            {
                orientation = stair_up_right_image;
            }

            typeSprite.GetComponent <SpriteRenderer>().sprite = orientation;
            break;

        case TYPE.stair_down:
            Sprite orientationD;

            if (position[1] == 1)
            {
                orientationD = stair_down_bottom_image;
            }
            else if (position[1] >= GameManager.instance.GetComponent <LevelGenerator>().columns - 3)
            {
                orientationD = stair_down_top_image;
            }
            else if (position[0] == (GameManager.instance.level - 1) * GameManager.instance.boardScript.rows + 1)
            {
                orientationD = stair_down_left_image;
            }
            else
            {
                orientationD = stair_down_right_image;
            }

            typeSprite.GetComponent <SpriteRenderer>().sprite = orientationD;
            break;

        default:
            Debug.Log("Tile type " + typeSetUp + " entered default state (Floor)");
            type = typeSetUp;
            break;
        }

        CheckTileIntegrity();

        containedObject      = Instantiate(contained.GetPrefab(), transform.position, Quaternion.identity, this.transform) as GameObject;
        containedObject.name = containedSetup.ToString();
        behaviour            = containedObject.GetComponent <IBehaviour>();

        behaviour.Initialize(state);
        behaviour.SetSprite(room_tileset);

        this.name = contained.ContainsNone() ? type.ToString() : contained.ToString();
    }