Пример #1
0
    /* Setup component on start */
    private void Start()
    {
        if (!gameObject.GetComponent <BoxCollider2D>())
        {
            gameObject.AddComponent <BoxCollider2D>();
        }
        if (!gameObject.GetComponent <Image>())
        {
            gameObject.AddComponent <Image>();
        }

        gameObject.GetComponent <Image>().sprite = TileProperties.GetSpriteSet(objectType).editorUI;

        gameObject.layer = 8; //Must match TouchManager
    }
Пример #2
0
    public void Initialise(TileTypes _type, Tile _tile, bool doSpawnAnim = true, bool refreshAllSprites = false)
    {
        gridTile = _tile;
        tileType = _type;

        childObject = gameObject.transform.GetChild(0).gameObject;
        ourSprite   = childObject.GetComponent <SpriteRenderer>();
        ourCollider = childObject.GetComponent <BoxCollider2D>();

        if (!doSpawnAnim)
        {
            GetComponent <Animator>().speed = 9999;
        }

        hasInitialised = true;
        spriteSet      = TileProperties.GetSpriteSet(tileType);

        //Try and occupy the tile we were given, this shouldn't really ever fail
        if (!gridTile.SetOccupied(this))
        {
            Debug.LogWarning("Failed to init tile! May be an issue with SetOccupied in grid.");
            Destroy(this.gameObject);
            return;
        }

        //Set tags for flocking AI
        if (!TileProperties.IsPathable(_type))
        {
            gameObject.layer = 30;                                    //"Obstacle"
        }
        else
        {
            gameObject.layer = 0;  //"Default"
        }
        //Enable collision for walls
        ourCollider.enabled = (TileProperties.GetVariant(_type) == TileVariant.WALL);

        //For neatness in the editor, parent to the grid
        this.gameObject.transform.parent = LevelManager.Instance.Grid.gameObject.transform;

        //Refresh sprites
        if (refreshAllSprites)
        {
            for (int i = 0; i < LevelManager.Instance.Grid.AllTiles.Count; i++)
            {
                if (LevelManager.Instance.Grid.AllTiles[i].IsOccupied && LevelManager.Instance.Grid.AllTiles[i].Occupier.Type == tileType)
                {
                    LevelManager.Instance.Grid.AllTiles[i].Occupier.RefreshSprite();
                }
            }
        }
        else
        {
            RefreshSprite();
        }

        if (LevelManager.Instance.IsInEditor)
        {
            //If in editor, spawn an invalid marker for UI use
            invalidMarker = Instantiate(LevelEditor.Instance.InvalidTileMarker, this.gameObject.transform.position, Quaternion.identity) as GameObject;
            invalidMarker.transform.parent = this.gameObject.transform;
            invalidMarker.SetActive(false);
        }
        else
        {
            //If out of editor, remove touchable from our child - it's not needed
            gameObject.transform.GetChild(0).gameObject.layer = gameObject.layer;
        }
    }