ItemUtil.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using GadgetCore.API;
  2. using UnityEngine;
  3. namespace MoreLights
  4. {
  5. public static class ItemUtil
  6. {
  7. public static int CreatePlacableLightItem(string tileImgPath, string itemImgPath, string name, Color color)
  8. {
  9. Texture2D textureTile = GadgetCoreAPI.LoadTexture2D(tileImgPath);
  10. Texture2D textureItem = GadgetCoreAPI.LoadTexture2D(itemImgPath);
  11. GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("prop/" + 2401));
  12. gameObject.GetComponentInChildren<Light>().color = color;
  13. Renderer renderer = gameObject.GetComponentInChildren<Renderer>();
  14. renderer.material = new Material(Shader.Find("Transparent/Diffuse"))
  15. {
  16. mainTexture = textureTile
  17. };
  18. ItemInfo itemInfo = new ItemInfo(ItemType.GENERIC, name, "", textureItem);
  19. int itemID = ItemRegistry.Singleton.Register(itemInfo, name);
  20. if (itemID == -1)
  21. throw new System.Exception("Could not register Item " + name);
  22. TileInfo tileInfo = new TileInfo(TileType.NONSOLID, textureTile, gameObject, itemInfo);
  23. int tileID = TileRegistry.Singleton.Register(tileInfo, name);
  24. if (tileID == -1)
  25. throw new System.Exception("Could not register Tile " + name);
  26. return itemID;
  27. }
  28. }
  29. }