ItemUtil.cs 983 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. using GadgetCore.API;
  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. itemInfo.Register(name);
  20. new TileInfo(TileType.NONSOLID, textureTile, gameObject, itemInfo).Register(name);
  21. return itemInfo.GetID();
  22. }
  23. }
  24. }