unity3d无限跑酷完整源码
- /// <summary>
-
/// Pattern system.
-
/// This script use for manage pattern
-
///
-
///
-
/// DO NOT EDIT THIS SCRIPT !!
-
///
-
/// </summary>
-
-
using UnityEngine;
-
using System.Collections;
-
using System.Collections.Generic;
-
-
[System.Serializable]
-
public class PatternSystem : MonoBehaviour {
-
//Building
-
public enum StateBuilding{
-
Build_1, Build_2, Build_3, Build_4, Null
-
}
-
[System.Serializable]
-
public class SetBuilding{
-
-
public int[] stateBuilding_Left = new int[8];
-
public int[] stateBuilding_Right = new int[8];
-
}
-
-
[System.Serializable]
-
public class SetBuildingAmount{
-
public int[] stateBuilding_Left = new int[4];
-
public int[] stateBuilding_Right = new int[4];
-
}
-
-
//Item
-
[System.Serializable]
-
public class SetItem{
-
public Vector2[] itemType_Left = new Vector2[31];
-
public Vector2[] itemType_SubLeft = new Vector2[31];
-
public Vector2[] itemType_Middle = new Vector2[31];
-
public Vector2[] itemType_SubRight = new Vector2[31];
-
public Vector2[] itemType_Right = new Vector2[31];
-
}
-
[System.Serializable]
-
public class FloorItemSlot{
-
public bool[] floor_Slot_Left, floor_Slot_SubLeft, floor_Slot_Middle, floor_Slot_SubRight,floor_Slot_Right;
-
}
-
-
//Floor
-
[System.Serializable]
-
public class Floor{
-
public bool[] floor_Slot_Left, floor_Slot_Right;
-
}
-
-
[System.Serializable]
-
public class QueueFloor{
-
public Floor floorClass;
-
public FloorItemSlot floorItemSlotClass;
-
public GameObject floorObj;
-
public List<Building> getBuilding = new List<Building>();
-
public List<Item> getItem = new List<Item>();
-
}
-
-
[System.Serializable]
-
public class LevelItem{
-
[HideInInspector]
-
public string level = "Pattern";
-
public List<SetItem> patternItem = new List<SetItem>();
-
}
-
-
[System.Serializable]
-
public class Item_Type{
-
public List<Item> itemList = new List<Item>();
-
}
-
-
[System.Serializable]
-
public class SetFloatItemType{
-
public List<int> item = new List<int>();
-
}
-
-
[HideInInspector] public List<Vector3> defaultPosBuilding_Left = new List<Vector3>();
-
-
[HideInInspector] public List<Vector3> defaultPosBuilding_Right = new List<Vector3>();
-
-
[HideInInspector] public List<Vector3> defaultPosItem_Left = new List<Vector3>();
-
-
[HideInInspector] public List<Vector3> defaultPosItem_SubLeft = new List<Vector3>();
-
-
[HideInInspector] public List<Vector3> defaultPosItem_Middle = new List<Vector3>();
-
-
[HideInInspector] public List<Vector3> defaultPosItem_SubRight = new List<Vector3>();
-
-
[HideInInspector] public List<Vector3> defaultPosItem_Right = new List<Vector3>();
-
-
//Prefab
-
public List<GameObject> building_Pref = new List<GameObject>();
-
public List<GameObject> item_Pref = new List<GameObject>();
-
public GameObject spawnObj_Pref;
-
public GameObject floor_Pref;
-
-
-
[HideInInspector] public List<SetBuilding> patternBuilding = new List<SetBuilding>();
-
[HideInInspector] public List<SetItem> patternItem = new List<SetItem>();
-
-
private int[] amountBuildingSpawn;
-
private int[] amountItemSpawn;
-
private int amountFloorSpawn = 4;
-
private float nextPosFloor = 32;
-
public bool loadingComplete;
-
public float loadingPercent;
-
-
public static PatternSystem instance;
-
-
//GameObject
-
private List<GameObject> building_Obj = new List<GameObject>();
-
private List<GameObject> item_Obj = new List<GameObject>();
-
private List<GameObject> floor_Obj = new List<GameObject>();
-
-
//Building
-
private List<Building> building_Script = new List<Building>();
-
private int[] maxAmountBuilding;
-
-
//Type Item
-
private List<Item_Type> item_Type_Script = new List<Item_Type>();
-
private List<int> amount_Item_Pattern_Left = new List<int>();
-
private List<int> amount_Item_Pattern_SubLeft = new List<int>();
-
private List<int> amount_Item_Pattern_Middle = new List<int>();
-
private List<int> amount_Item_Pattern_SubRight = new List<int>();
-
private List<int> amount_Item_Pattern_Right = new List<int>();
-
-
-
private List<Floor> floor_Slot = new List<Floor>();
-
private List<FloorItemSlot> floor_item_Slot = new List<FloorItemSlot>();
-
private List<QueueFloor> queneFloor = new List<QueueFloor>();
-
-
private GameObject spawnObj_Obj;
-
private ColliderSpawnCheck colSpawnCheck;
-
-
//variable value in game
-
private int randomPattern;
-
private int randomItem;
-
private Vector3 posFloorLast;
-
-
//Defalut
-
private Vector3 posStart = new Vector3(-100,-100,-100);
-
private Vector3 angleLeft = new Vector3(0,180,0);
-
private Vector3 angleRight = new Vector3(0,0,0);
-
-
public PatternSystem(){
-
SettingVariableFirst ();
-
}
-
-
void SettingVariableFirst(){
-
if (defaultPosBuilding_Left.Count <= 0) {
-
Vector3 pos = new Vector3(-3,0,12);
-
for(int i = 0; i < 8; i++){
-
defaultPosBuilding_Left.Add(new Vector3(pos.x,pos.y,pos.z-(i*4)));
-
}
-
}
-
-
if(defaultPosBuilding_Right.Count <= 0){
-
Vector3 pos = new Vector3(3,0,16);
-
for(int i = 0; i < 8; i++){
-
defaultPosBuilding_Right.Add(new Vector3(pos.x,pos.y,pos.z-(i*4)));
-
}
-
}
-
-
if(defaultPosItem_Left.Count <= 0){
-
Vector3 pos = new Vector3(-1.8f,0,15);
-
for(int i = 0; i < 31; i++){
-
defaultPosItem_Left.Add(new Vector3(pos.x,pos.y,pos.z-i));
-
}
-
}
-
-
if(defaultPosItem_SubLeft.Count <= 0){
-
Vector3 pos = new Vector3(-0.9f,0,15);
-
for(int i = 0; i < 31; i++){
-
defaultPosItem_SubLeft.Add(new Vector3(pos.x, pos.y, pos.z-i));
-
}
-
}
-
-
if(defaultPosItem_Middle.Count <= 0){
-
Vector3 pos = new Vector3(0,0,15);
-
for(int i = 0; i < 31; i++){
-
defaultPosItem_Middle.Add(new Vector3(pos.x, pos.y, pos.z-i));
-
}
-
}
-
-
if(defaultPosItem_SubRight.Count <= 0){
-
Vector3 pos = new Vector3(0.9f,0,15);
-
for(int i = 0; i < 31; i++){
-
defaultPosItem_SubRight.Add(new Vector3(pos.x, pos.y, pos.z-i));
-
}
-
}
-
-
if(defaultPosItem_Right.Count <= 0){
-
Vector3 pos = new Vector3(1.8f,0,15);
-
for(int i = 0; i < 31; i++){
-
defaultPosItem_Right.Add(new Vector3(pos.x, pos.y, pos.z-i));
-
}
-
}
-
-
if (patternBuilding.Count <= 0) {
-
patternBuilding.Add(new SetBuilding());
-
}
-
-
if(patternItem.Count <= 0){
-
patternItem.Add(new SetItem());
-
}
-
}
-
-
void Start(){
-
instance = this;
-
StartCoroutine(CalAmountItem());
-
}
-
-
private List<SetFloatItemType> _itemType = new List<SetFloatItemType>();
-
private SetFloatItemType itemTypeMax;
-
IEnumerator CalAmountItem(){
-
//25%
-
ConvertPatternToItemTpyeSet();
-
itemTypeMax = new SetFloatItemType();
-
int i = 0;
-
while(i < item_Pref.Count){
-
itemTypeMax.item.Add(0);
-
i++;
-
}
-
i = 0;
-
loadingPercent = 1;
-
while(i < _itemType.Count){
-
int j = 0;
-
while(j < _itemType[i].item.Count){
-
if(_itemType[i].item[j] > itemTypeMax.item[j]){
-
itemTypeMax.item[j] = _itemType[i].item[j];
-
}
-
j++;
-
}
-
i++;
-
}
-
i = 0;
-
loadingPercent = 3;
-
amountItemSpawn = new int[itemTypeMax.item.Count];
-
while(i < amountItemSpawn.Length){
-
amountItemSpawn[i] = itemTypeMax.item[i] * amountFloorSpawn;
-
amountItemSpawn[i]++;
-
i++;
-
}
-
yield return 0;
-
loadingPercent = 5;
-
StartCoroutine(CalAmountBuilding());
-
}
-
-
private void ConvertPatternToItemTpyeSet(){
-
int i = 0;
-
while(i < patternItem.Count){
-
_itemType.Add(new SetFloatItemType());
-
int j = 0;
-
while(j < item_Pref.Count){
-
_itemType[i].item.Add(0);
-
j++;
-
}
-
i++;
-
}
-
i = 0;
-
while(i < patternItem.Count){
-
int j = 0;
-
//Left
-
while(j < patternItem[i].itemType_Left.Length){
-
int k = 0;
-
while(k < item_Pref.Count){
-
if(patternItem[i].itemType_Left[j].x == k+1){
-
_itemType[i].item[k] += 1;
-
}
-
-
k++;
-
}
-
j++;
-
}
-
j = 0;
-
//Middle
-
while(j < patternItem[i].itemType_Middle.Length){
-
int k = 0;
-
while(k < item_Pref.Count){
-
if(patternItem[i].itemType_Middle[j].x == k+1){
-
_itemType[i].item[k] += 1;
-
}
-
-
k++;
-
}
-
j++;
-
}