| 1234567891011121314151617181920212223242526272829303132333435 |
- using GadgetCore.API;
- using UnityEngine;
- namespace MoreLights
- {
- public static class ItemUtil
- {
- public static int CreatePlacableLightItem(string tileImgPath, string itemImgPath, string name, Color color)
- {
- Texture2D textureTile = GadgetCoreAPI.LoadTexture2D(tileImgPath);
- Texture2D textureItem = GadgetCoreAPI.LoadTexture2D(itemImgPath);
- GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("prop/" + 2401));
- gameObject.GetComponentInChildren<Light>().color = color;
- Renderer renderer = gameObject.GetComponentInChildren<Renderer>();
- renderer.material = new Material(Shader.Find("Transparent/Diffuse"))
- {
- mainTexture = textureTile
- };
- ItemInfo itemInfo = new ItemInfo(ItemType.GENERIC, name, "", textureItem);
- int itemID = ItemRegistry.Singleton.Register(itemInfo, name);
- if (itemID == -1)
- throw new System.Exception("Could not register Item " + name);
- TileInfo tileInfo = new TileInfo(TileType.NONSOLID, textureTile, gameObject, itemInfo);
- int tileID = TileRegistry.Singleton.Register(tileInfo, name);
- if (tileID == -1)
- throw new System.Exception("Could not register Tile " + name);
- return itemID;
- }
- }
- }
|