ItemUtil.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using UnityEngine;
  2. using GadgetCore.API;
  3. namespace First
  4. {
  5. public static class ItemUtil
  6. {
  7. public static int CreatePlacableItem(string tileImgPath, string itemImgPath, int tileId, string itemName, string tileName, string name)
  8. {
  9. Texture2D texture2D = GadgetCoreAPI.LoadTexture2D(tileImgPath, false);
  10. Texture2D texture2D2 = GadgetCoreAPI.LoadTexture2D(itemImgPath, false);
  11. GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("prop/" + tileId));
  12. //gameObject.transform.localScale = new Vector3(0.3333f, 0.3333f);
  13. gameObject.layer = 11;
  14. BoxCollider collider = gameObject.AddComponent<BoxCollider>();
  15. //collider.transform.localScale = new Vector3(3, 3);
  16. ItemInfo itemInfo = new ItemInfo(0, name, "", texture2D2, 500, default(EquipStats), null, null, null, null);
  17. itemInfo.Register(name, -1, false);
  18. new TileInfo(TileType.SOLID, texture2D, gameObject, itemInfo).Register(name, -1, false);
  19. return itemInfo.GetID();
  20. }
  21. public static int CreatePlacableLightItem(string tileImgPath, string itemImgPath, string name, Color color)
  22. {
  23. Texture2D texture2D = GadgetCoreAPI.LoadTexture2D(tileImgPath, false);
  24. Texture2D texture2D2 = GadgetCoreAPI.LoadTexture2D(itemImgPath, false);
  25. GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("prop/" + 2401));
  26. try
  27. {
  28. gameObject.GetComponentInChildren<Light>().color = color;
  29. }
  30. catch { }
  31. ItemInfo itemInfo = new ItemInfo(0, name, "", texture2D2, 500, default(EquipStats), null, null, null, null);
  32. itemInfo.Register(name, -1, false);
  33. new TileInfo(TileType.NONSOLID, texture2D, gameObject, itemInfo).Register(name, -1, false);
  34. return itemInfo.GetID();
  35. }
  36. public static int CreateDefaultItem(string itemImgPath, string name, int value = 20)
  37. {
  38. Texture2D texture2D2 = GadgetCoreAPI.LoadTexture2D(itemImgPath, false);
  39. ItemInfo itemInfo = new ItemInfo(ItemType.GENERIC, name, "", texture2D2, value, default(EquipStats), null, null, null, null);
  40. itemInfo.Register(name, -1, false);
  41. return itemInfo.GetID();
  42. }
  43. }
  44. }