unity3d无限跑酷完整源码

  1. /// <summary>
  2. /// Pattern system.
  3. /// This script use for manage pattern
  4. ///
  5. ///
  6. /// DO NOT EDIT THIS SCRIPT !!
  7. ///
  8. /// </summary>
  9. using UnityEngine;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. [System.Serializable]
  13. public class PatternSystem : MonoBehaviour {
  14. //Building
  15. public enum StateBuilding{
  16. Build_1, Build_2, Build_3, Build_4, Null
  17. }
  18. [System.Serializable]
  19. public class SetBuilding{
  20. public int[] stateBuilding_Left = new int[8];
  21. public int[] stateBuilding_Right = new int[8];
  22. }
  23. [System.Serializable]
  24. public class SetBuildingAmount{
  25. public int[] stateBuilding_Left = new int[4];
  26. public int[] stateBuilding_Right = new int[4];
  27. }
  28. //Item
  29. [System.Serializable]
  30. public class SetItem{
  31. public Vector2[] itemType_Left = new Vector2[31];
  32. public Vector2[] itemType_SubLeft = new Vector2[31];
  33. public Vector2[] itemType_Middle = new Vector2[31];
  34. public Vector2[] itemType_SubRight = new Vector2[31];
  35. public Vector2[] itemType_Right = new Vector2[31];
  36. }
  37. [System.Serializable]
  38. public class FloorItemSlot{
  39. public bool[] floor_Slot_Left, floor_Slot_SubLeft, floor_Slot_Middle, floor_Slot_SubRight,floor_Slot_Right;
  40. }
  41. //Floor
  42. [System.Serializable]
  43. public class Floor{
  44. public bool[] floor_Slot_Left, floor_Slot_Right;
  45. }
  46. [System.Serializable]
  47. public class QueueFloor{
  48. public Floor floorClass;
  49. public FloorItemSlot floorItemSlotClass;
  50. public GameObject floorObj;
  51. public List<Building> getBuilding = new List<Building>();
  52. public List<Item> getItem = new List<Item>();
  53. }
  54. [System.Serializable]
  55. public class LevelItem{
  56. [HideInInspector]
  57. public string level = "Pattern";
  58. public List<SetItem> patternItem = new List<SetItem>();
  59. }
  60. [System.Serializable]
  61. public class Item_Type{
  62. public List<Item> itemList = new List<Item>();
  63. }
  64. [System.Serializable]
  65. public class SetFloatItemType{
  66. public List<int> item = new List<int>();
  67. }
  68. [HideInInspector] public List<Vector3> defaultPosBuilding_Left = new List<Vector3>();
  69. [HideInInspector] public List<Vector3> defaultPosBuilding_Right = new List<Vector3>();
  70. [HideInInspector] public List<Vector3> defaultPosItem_Left = new List<Vector3>();
  71. [HideInInspector] public List<Vector3> defaultPosItem_SubLeft = new List<Vector3>();
  72. [HideInInspector] public List<Vector3> defaultPosItem_Middle = new List<Vector3>();
  73. [HideInInspector] public List<Vector3> defaultPosItem_SubRight = new List<Vector3>();
  74. [HideInInspector] public List<Vector3> defaultPosItem_Right = new List<Vector3>();
  75. //Prefab
  76. public List<GameObject> building_Pref = new List<GameObject>();
  77. public List<GameObject> item_Pref = new List<GameObject>();
  78. public GameObject spawnObj_Pref;
  79. public GameObject floor_Pref;
  80. [HideInInspector] public List<SetBuilding> patternBuilding = new List<SetBuilding>();
  81. [HideInInspector] public List<SetItem> patternItem = new List<SetItem>();
  82. private int[] amountBuildingSpawn;
  83. private int[] amountItemSpawn;
  84. private int amountFloorSpawn = 4;
  85. private float nextPosFloor = 32;
  86. public bool loadingComplete;
  87. public float loadingPercent;
  88. public static PatternSystem instance;
  89. //GameObject
  90. private List<GameObject> building_Obj = new List<GameObject>();
  91. private List<GameObject> item_Obj = new List<GameObject>();
  92. private List<GameObject> floor_Obj = new List<GameObject>();
  93. //Building
  94. private List<Building> building_Script = new List<Building>();
  95. private int[] maxAmountBuilding;
  96. //Type Item
  97. private List<Item_Type> item_Type_Script = new List<Item_Type>();
  98. private List<int> amount_Item_Pattern_Left = new List<int>();
  99. private List<int> amount_Item_Pattern_SubLeft = new List<int>();
  100. private List<int> amount_Item_Pattern_Middle = new List<int>();
  101. private List<int> amount_Item_Pattern_SubRight = new List<int>();
  102. private List<int> amount_Item_Pattern_Right = new List<int>();
  103. private List<Floor> floor_Slot = new List<Floor>();
  104. private List<FloorItemSlot> floor_item_Slot = new List<FloorItemSlot>();
  105. private List<QueueFloor> queneFloor = new List<QueueFloor>();
  106. private GameObject spawnObj_Obj;
  107. private ColliderSpawnCheck colSpawnCheck;
  108. //variable value in game
  109. private int randomPattern;
  110. private int randomItem;
  111. private Vector3 posFloorLast;
  112. //Defalut
  113. private Vector3 posStart = new Vector3(-100,-100,-100);
  114. private Vector3 angleLeft = new Vector3(0,180,0);
  115. private Vector3 angleRight = new Vector3(0,0,0);
  116. public PatternSystem(){
  117. SettingVariableFirst ();
  118. }
  119. void SettingVariableFirst(){
  120. if (defaultPosBuilding_Left.Count <= 0) {
  121. Vector3 pos = new Vector3(-3,0,12);
  122. for(int i = 0; i < 8; i++){
  123. defaultPosBuilding_Left.Add(new Vector3(pos.x,pos.y,pos.z-(i*4)));
  124. }
  125. }
  126. if(defaultPosBuilding_Right.Count <= 0){
  127. Vector3 pos = new Vector3(3,0,16);
  128. for(int i = 0; i < 8; i++){
  129. defaultPosBuilding_Right.Add(new Vector3(pos.x,pos.y,pos.z-(i*4)));
  130. }
  131. }
  132. if(defaultPosItem_Left.Count <= 0){
  133. Vector3 pos = new Vector3(-1.8f,0,15);
  134. for(int i = 0; i < 31; i++){
  135. defaultPosItem_Left.Add(new Vector3(pos.x,pos.y,pos.z-i));
  136. }
  137. }
  138. if(defaultPosItem_SubLeft.Count <= 0){
  139. Vector3 pos = new Vector3(-0.9f,0,15);
  140. for(int i = 0; i < 31; i++){
  141. defaultPosItem_SubLeft.Add(new Vector3(pos.x, pos.y, pos.z-i));
  142. }
  143. }
  144. if(defaultPosItem_Middle.Count <= 0){
  145. Vector3 pos = new Vector3(0,0,15);
  146. for(int i = 0; i < 31; i++){
  147. defaultPosItem_Middle.Add(new Vector3(pos.x, pos.y, pos.z-i));
  148. }
  149. }
  150. if(defaultPosItem_SubRight.Count <= 0){
  151. Vector3 pos = new Vector3(0.9f,0,15);
  152. for(int i = 0; i < 31; i++){
  153. defaultPosItem_SubRight.Add(new Vector3(pos.x, pos.y, pos.z-i));
  154. }
  155. }
  156. if(defaultPosItem_Right.Count <= 0){
  157. Vector3 pos = new Vector3(1.8f,0,15);
  158. for(int i = 0; i < 31; i++){
  159. defaultPosItem_Right.Add(new Vector3(pos.x, pos.y, pos.z-i));
  160. }
  161. }
  162. if (patternBuilding.Count <= 0) {
  163. patternBuilding.Add(new SetBuilding());
  164. }
  165. if(patternItem.Count <= 0){
  166. patternItem.Add(new SetItem());
  167. }
  168. }
  169. void Start(){
  170. instance = this;
  171. StartCoroutine(CalAmountItem());
  172. }
  173. private List<SetFloatItemType> _itemType = new List<SetFloatItemType>();
  174. private SetFloatItemType itemTypeMax;
  175. IEnumerator CalAmountItem(){
  176. //25%
  177. ConvertPatternToItemTpyeSet();
  178. itemTypeMax = new SetFloatItemType();
  179. int i = 0;
  180. while(i < item_Pref.Count){
  181. itemTypeMax.item.Add(0);
  182. i++;
  183. }
  184. i = 0;
  185. loadingPercent = 1;
  186. while(i < _itemType.Count){
  187. int j = 0;
  188. while(j < _itemType[i].item.Count){
  189. if(_itemType[i].item[j] > itemTypeMax.item[j]){
  190. itemTypeMax.item[j] = _itemType[i].item[j];
  191. }
  192. j++;
  193. }
  194. i++;
  195. }
  196. i = 0;
  197. loadingPercent = 3;
  198. amountItemSpawn = new int[itemTypeMax.item.Count];
  199. while(i < amountItemSpawn.Length){
  200. amountItemSpawn[i] = itemTypeMax.item[i] * amountFloorSpawn;
  201. amountItemSpawn[i]++;
  202. i++;
  203. }
  204. yield return 0;
  205. loadingPercent = 5;
  206. StartCoroutine(CalAmountBuilding());
  207. }
  208. private void ConvertPatternToItemTpyeSet(){
  209. int i = 0;
  210. while(i < patternItem.Count){
  211. _itemType.Add(new SetFloatItemType());
  212. int j = 0;
  213. while(j < item_Pref.Count){
  214. _itemType[i].item.Add(0);
  215. j++;
  216. }
  217. i++;
  218. }
  219. i = 0;
  220. while(i < patternItem.Count){
  221. int j = 0;
  222. //Left
  223. while(j < patternItem[i].itemType_Left.Length){
  224. int k = 0;
  225. while(k < item_Pref.Count){
  226. if(patternItem[i].itemType_Left[j].x == k+1){
  227. _itemType[i].item[k] += 1;
  228. }
  229. k++;
  230. }
  231. j++;
  232. }
  233. j = 0;
  234. //Middle
  235. while(j < patternItem[i].itemType_Middle.Length){
  236. int k = 0;
  237. while(k < item_Pref.Count){
  238. if(patternItem[i].itemType_Middle[j].x == k+1){
  239. _itemType[i].item[k] += 1;
  240. }
  241. k++;
  242. }
  243. j++;
  244. }