Example #1
0
        public static UITextureAtlas CreateTextureAtlas(
            string textureFile,
            string atlasName,
            Material baseMaterial,
            int spriteWidth,
            int spriteHeight,
            string[] spriteNames)
        {
            Logger.Debug("Processing, textureFile: " + textureFile + ", atlasName: " + atlasName + ", width: " + (object)spriteWidth + ", height: " + (object)spriteHeight + ", baseMaterial" + (object)baseMaterial);
            int            width    = spriteWidth * spriteNames.Length;
            int            height   = spriteHeight;
            Texture2D      texture  = UIUtils.createTexture(textureFile, width, height);
            UITextureAtlas instance = (UITextureAtlas)ScriptableObject.CreateInstance <UITextureAtlas>();
            Material       material = (Material)Object.Instantiate <Material>((M0)baseMaterial);

            material.set_mainTexture((Texture)texture);
            instance.set_material(material);
            ((Object)instance).set_name(atlasName);
            for (int index = 0; index < spriteNames.Length; ++index)
            {
                float num = 1f / (float)spriteNames.Length;
                UITextureAtlas.SpriteInfo spriteInfo1 = new UITextureAtlas.SpriteInfo();
                spriteInfo1.set_name(spriteNames[index]);
                spriteInfo1.set_texture(texture);
                spriteInfo1.set_region(new Rect((float)index * num, 0.0f, num, 1f));
                UITextureAtlas.SpriteInfo spriteInfo2 = spriteInfo1;
                instance.AddSprite(spriteInfo2);
            }
            return(instance);
        }