Esempio n. 1
0
    public void AddObject(WorldObject o, int x, int y, int l = 0, bool forceDestroy = false)
    {
        // Debug.Assert(map[l,x,y] == null);
        if (map[l, x, y] != null)
        {
            // Debug.Log("Tried to overwrite "+map[l,x,y].gameSpaceObject.mainSprite.sprite.name);
            if (forceDestroy)
            {
                DestroyObjectAt(x, y, l);
            }
            else
            {
                return;
            }
        }

        map[l, x, y] = o;
        o.x          = x;
        o.y          = y;

        Debug.Assert(map[l, x, y] == o);
        Debug.Assert(map[l, o.x, o.y] == o);

        GameSpaceObject gso = GameSpaceView.instance.CreateWorldSpaceObject(o, "PlayLayer", l);

        gso.GetComponent <SpriteRenderer>().sortingOrder = (l + 1) * 2;
    }
Esempio n. 2
0
    public GameSpaceObject CreateWorldSpaceObject(WorldObject obj, string layer = "PlayLayer", int worldLayer = 0)
    {
        GameSpaceObject gameSpaceObject = Instantiate(tilePrefab).GetComponent <GameSpaceObject>();

        //Setup sprite
        SpriteRenderer sr = gameSpaceObject.GetComponent <SpriteRenderer>();

        sr.sprite            = SpriteManager.instance.GetSpriteByName(obj.spriteName);
        gameSpaceObject.name = obj.spriteName;
        sr.color             = obj.color;

        sr.sortingLayerName = layer;
        sr.sortingOrder     = worldLayer + 1;

        obj.SetGameSpaceObject(gameSpaceObject);

        gameSpaceObject.transform.position = GetWorldSpaceLocation(obj.x, obj.y);

        allObjects.Add(gameSpaceObject);

        return(gameSpaceObject);
    }