Пример #1
0
    // Register a new sprite, which is saved into the (internal) sprite list
    public void AddSprite(Sprite NewSprite)
    {
        // Do we have a list of sprites for this texture yet?
        ArrayList Sprites = null;
        if(!SpriteList.TryGetValue(NewSprite.GetTextureName(), out Sprites))
        {
            // 1. Generate a new game object and sprite list array
            GameObject GameObj = new GameObject();
            Models.Add(NewSprite.GetTextureName(), GameObj);

            Sprites = new ArrayList();
            SpriteList.Add(NewSprite.GetTextureName(), Sprites);

            // 2. Generate mesh (model)
            GameObj.AddComponent("MeshFilter");													// Mesh (required)
            MeshRenderer meshRenderer = GameObj.AddComponent("MeshRenderer") as MeshRenderer;	// Material

            // 3. Pair with texture
            meshRenderer.renderer.material = LoadSpriteTexture(NewSprite.GetTextureName());
        }

        // Save this sprite into our sorted list (sorted based on depth)
        // Note to self: what's the internal data structure? Any speed guarantee over a custom BTree?
        Sprites.Add(NewSprite);
    }
Пример #2
0
    // Remove a sprite from the renderables list
    public void RemoveSprite(Sprite OldSprite)
    {
        // Which list is this sprite in? If found, remove
        ArrayList Sprites = null;
        if(SpriteList.TryGetValue(OldSprite.GetTextureName(), out Sprites))
        {
            // Remove the data
            Sprites.Remove(OldSprite);

            // If this sprite batch has other sprites, flag those as needing update to
            // update the entire geometry
            if(Sprites.Count > 0)
            {
                foreach(Sprite SpriteObj in Sprites)
                    SpriteObj.Changed();
            }
            // Else, just remove the sprite list and model completely
            else
            {
                // Remove sprites list
                SpriteList.Remove(OldSprite.GetTextureName());

                // Remove model
                GameObject SpriteModel = null;
                if(Models.TryGetValue(OldSprite.GetTextureName(), out SpriteModel))
                {
                    Destroy(SpriteModel);
                    Models.Remove(OldSprite.GetTextureName());
                }
            }
        }
    }