RecipePage.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace RecipeMenuCore.API
  4. {
  5. /// <summary>
  6. /// Defines a custom RecipePage. Make sure to call Register on it to enable your RecipePage and to add at least one RecipePageEntry using AddRecipePageEntry.
  7. /// </summary>
  8. public class RecipePage
  9. {
  10. /// <summary>
  11. /// The RecipePageType of this RecipePage
  12. /// </summary>
  13. public readonly RecipePageType Type;
  14. /// <summary>
  15. /// The Title displayed on top of this RecipePage.
  16. /// </summary>
  17. public readonly string Title;
  18. /// <summary>
  19. /// The Texture associated with this RecipePage. May be null.
  20. /// </summary>
  21. public Texture Tex { get; protected set; }
  22. /// <summary>
  23. /// The Material associated with this RecipePage. May be null.
  24. /// </summary>
  25. public Material Mat { get; protected set; }
  26. internal List<RecipePageEntry> Rows = new List<RecipePageEntry>();
  27. /// <summary>
  28. /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage.
  29. /// </summary>
  30. public RecipePage(RecipePageType Type, string Title, Texture Tex)
  31. {
  32. this.Type = Type;
  33. this.Title = Title;
  34. this.Tex = Tex;
  35. }
  36. /// <summary>
  37. /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage.
  38. /// </summary>
  39. public RecipePage(RecipePageType Type, string Title, Material Mat)
  40. {
  41. this.Type = Type;
  42. this.Title = Title;
  43. this.Mat = Mat;
  44. }
  45. /// <summary>
  46. /// Used to register the page and make it show.
  47. /// </summary>
  48. public virtual RecipePage Register()
  49. {
  50. PostRegister();
  51. switch (Type)
  52. {
  53. case RecipePageType.GearForge:
  54. Core.pageGearForgeInfoList.Add(this);
  55. break;
  56. case RecipePageType.AlchemyStation:
  57. Core.pageAlchemyStationInfoList.Add(this);
  58. break;
  59. case RecipePageType.UltimateForge:
  60. Core.pageUltimateForgeInfoList.Add(this);
  61. break;
  62. }
  63. return this;
  64. }
  65. protected void PostRegister()
  66. {
  67. if (Mat == null)
  68. {
  69. Mat = new Material(Shader.Find("Unlit/Transparent"))
  70. {
  71. mainTexture = Tex
  72. };
  73. }
  74. else
  75. {
  76. Tex = Mat.mainTexture;
  77. }
  78. }
  79. /// <summary>
  80. /// Used to register the RecipePage to make it show up.
  81. /// </summary>
  82. public RecipePageType GetEntryType()
  83. {
  84. return Type;
  85. }
  86. /// <summary>
  87. /// Adds a new RecipePageEntry to the RecipePage.
  88. /// </summary>
  89. public void AddRecipePageEntry(RecipePageEntry row)
  90. {
  91. Rows.Add(row);
  92. }
  93. /// <summary>
  94. /// Returns the list of avalible RecipePageEntry on this RecipePage.
  95. /// </summary>
  96. public RecipePageEntry[] GetRecipePageEntries()
  97. {
  98. return Rows.ToArray();
  99. }
  100. }
  101. /// <summary>
  102. /// This indicates what types of recipes are avalible.
  103. /// </summary>
  104. public enum RecipePageType
  105. {
  106. /// <summary>
  107. /// This recipe is for the Gear Forge.
  108. /// </summary>
  109. GearForge,
  110. /// <summary>
  111. /// This recipe is for the Alchemy Station.
  112. /// </summary>
  113. AlchemyStation,
  114. /// <summary>
  115. /// This recipe is for the Ultimate Forge.
  116. /// </summary>
  117. UltimateForge
  118. }
  119. }