Пример #1
0
        /// <summary>
        /// Adds a sprite (from a resource) to a collection
        /// </summary>
        /// <returns>The spriteID of the defintion in the collection</returns>
        public static int AddSpriteToCollection(string resourcePath, tk2dSpriteCollectionData collection)
        {
            string extension = !resourcePath.EndsWith(".png") ? ".png" : "";

            resourcePath += extension;
            var texture = ResourceExtractor.GetTextureFromResource(resourcePath); //Get Texture

            var definition = ConstructDefinition(texture);                        //Generate definition

            definition.name = texture.name;                                       //naming the definition is actually extremely important

            return(AddSpriteToCollection(definition, collection));
        }
Пример #2
0
        /// <summary>
        /// Returns an object with a tk2dSprite component with the
        /// texture of a file in the sprites folder
        /// </summary>
        public static GameObject SpriteFromFile(string spriteName, GameObject obj = null, bool copyFromExisting = true)
        {
            string filename = spriteName.Replace(".png", "");

            var texture = ResourceExtractor.GetTextureFromFile(filename);

            if (texture == null)
            {
                return(null);
            }

            return(SpriteFromTexture(texture, spriteName, obj, copyFromExisting));
        }
Пример #3
0
        /// <summary>
        /// Returns an object with a tk2dSprite component with the
        /// texture of an embedded resource
        /// </summary>
        public static GameObject SpriteFromResource(string spriteName, GameObject obj = null, bool copyFromExisting = true)
        {
            string extension    = !spriteName.EndsWith(".png") ? ".png" : "";
            string resourcePath = spriteName + extension;

            var texture = ResourceExtractor.GetTextureFromResource(resourcePath);

            if (texture == null)
            {
                return(null);
            }

            return(SpriteFromTexture(texture, resourcePath, obj, copyFromExisting));
        }
Пример #4
0
 /// <summary>
 /// Sets the base assembly of the ResourceExtractor, so
 /// resources can be accessed
 /// </summary>
 public static void Init()
 {
     try
     {
         MethodBase method        = new StackFrame(1, false).GetMethod();
         var        declaringType = method.DeclaringType;
         ResourceExtractor.SetAssembly(declaringType);
     }
     catch (Exception e)
     {
         ETGModConsole.Log(e.Message);
         ETGModConsole.Log(e.StackTrace);
     }
 }