using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
public enum ObjectType
{
Land,
Obstacle,
Corn,
GravityCorn,
Randomevent,
Event,
}
//RoadMngr
public class TestNewRoad : MonoBehaviour
{
public GameObject road_Parent;
public GameObject monster_Parent;
public GameObject propInGame;
void Awake ()
{
Init ();
}
void Init ()
{
GetCommponent getComponent = GetComponent<GetCommponent> ();
road_Parent = getComponent.defaultGameObject [0];
monster_Parent = getComponent.defaultGameObject [1];
propInGame = getComponent.defaultGameObject [2];
}
void Start ()
{
InitCurParm ();
sceneRandomList = new ArrayList{ 2, 3, 4 };//随机场景的序号
}
private int SumWeight;
private List<int> WeightList;
private List<int> TimesList;
int randomNum;
NewLandEntity tempNewLandEntity;
private int levelIndex = 0;
private int elementIndex = 0;
void InitCurParm ()
{
WeightList = new List<int> ();
TimesList = new List<int> ();
tempNewLandEntity = NewLandParseXML.GetLand (NewLandParseXML.index);
TimesList.Add (tempNewLandEntity.times0);
TimesList.Add (tempNewLandEntity.times1);
TimesList.Add (tempNewLandEntity.times2);
TimesList.Add (tempNewLandEntity.times3);
TimesList.Add (tempNewLandEntity.times4);
TimesList.Add (tempNewLandEntity.times5);
TimesList.Add (tempNewLandEntity.times6);
WeightList.Add (SumWeight += tempNewLandEntity.weight0);
WeightList.Add (SumWeight += tempNewLandEntity.weight1);
WeightList.Add (SumWeight += tempNewLandEntity.weight2);
WeightList.Add (SumWeight += tempNewLandEntity.weight3);
WeightList.Add (SumWeight += tempNewLandEntity.weight4);
WeightList.Add (SumWeight += tempNewLandEntity.weight5);
WeightList.Add (SumWeight += tempNewLandEntity.weight6);
randomNum = (int)(Random.value * SumWeight);
GLogger.LogError ("**********************************===SumWeight= " + SumWeight + "=== " + randomNum);
for (int i = 0; i < WeightList.Count; i++) {
if (WeightList [i] > randomNum) {
GLogger.LogError ("**********************************===i= " + i);
switch (NewLandParseXML.index) {
case 0:
levelIndex = i;
elementIndex = Random.Range (1,6);
break;
case 1:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 2:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 3:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 4:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 5:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 6:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 7:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 8:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 9:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 10:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 11:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
}
break;
}
}
}
//由于中间场景规定的Lv7_0 是中间场景,所以以后要添加7等级的关卡难度要注意!!!
string GetLevelSplitName(){
GLogger.LogError ("=======================================随即路面: " + levelIndex + "_" + elementIndex);
return levelIndex + "_" + elementIndex;
}
private float rate = 100f;
private float YOffset = 2.4f;
private float XOffset = 0;
private float xOffsetPosition = 2;
private float x = 0;
private float y = 0;
private float ExtraPropYOffset = 0.31f;
private float CornYOffset = 0.35f;
float scale = 0;
private bool isLoadNextLand = false;
private bool isLoadNextElement = false;
int startLandIndex = 0;
int startElementIndex = 0;
bool carIsDead = false;
float lastLandPositionX = 0f;
float lastElementPositionX = 0f;
float curDistance = 0;
private float addMidSceneDisTimes = 1146;
//已经添加的中间场景的数量
private int addedMidSceneNum = 0;
private bool isChangeBg = false;
private ArrayList sceneRandomList;
private int finalLandIndex = 0;
private int startLandCount = 0;
void Update ()
{
curDistance = UserInfos.GetInstance ().distance;
// bool result = NewMidScene (curDistance);
bool result = false;
if (result) {
} else {
//加载路面
if (curDistance > (lastLandPositionX - 10) && !isLoadNextLand) {
// if (!isLoadNextLand) {
if (carIsDead) {
startLandIndex += 10;
LoadLand (startLandIndex);
carIsDead = false;
} else {
if (startLandIndex <= LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count) {
int currentLeftLand = LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count - endLandIndex;
if (currentLeftLand > 0) {
startLandIndex += 10;
} else {
startLandIndex += currentLeftLand;
}
LoadLand (startLandIndex);
// if (IsLastLand ()) {
// if(lastLandPositionX){
// //添加中间场景
// }
// }
}
// LoadLand (LandConfigParseXML.GetLandList(GetLevelSplitName()).Count);
}
isLoadNextLand = true;
}
else if(curDistance < (lastLandPositionX - 10) && isLoadNextLand == true){
isLoadNextLand = false;
InitCurParm ();
}
//加载路面元素
if (curDistance > (lastElementPositionX - 10) && !isLoadNextElement) {
// if (!isLoadNextLand) {
if (carIsDead) {
startElementIndex += 10;
LoadLandElements (startElementIndex);
carIsDead = false;
} else {
if (startElementIndex <= LandConfigParseXML.GetLandElement(GetLevelSplitName()).Count) {
int currentLeftLand = LandConfigParseXML.GetLandElement(GetLevelSplitName()).Count - endElementIndex;
if (currentLeftLand > 0) {
startElementIndex += 5;
} else {
startElementIndex += currentLeftLand;
}
}
LoadLandElements (startElementIndex);
// LoadLandElements (LandConfigParseXML.GetLandElement(GetLevelSplitName()).Count);
}
isLoadNextElement = true;
}
else if(curDistance < (lastElementPositionX - 10) && isLoadNextElement == true){
isLoadNextElement = false;
}
}
if (isChangeBg) {
ChangeBgTexture ();
}
}
bool IsLastLand(){
if (RandomLandParseXML.landList.Count == endLandIndex) {
return true;
} else {
return false;
}
}
// bool NewMidScene (float length)
bool NewMidScene ()
{
int midIndex = 7;
int midElementIndex = Random.Range (1,6);
GameObject ob = null;
// int temp = (int)(length / addMidSceneDisTimes);
// if (temp <= addedMidSceneNum) {
// return false;
// }
//add midScene
for (int i = 0; i < transition0_1ParseXML.landList.Count; i++) {
RandomLand land = new RandomLand ();
land = transition0_1ParseXML.GetLand (i);
switch (land.type) {
case (int)ObjectType.Land:
x = (land.x - XOffset) / rate - 0;
y = -land.y / rate + 1.43f;
string resourceName = land.resource;
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem (resourceName));
// ob.transform.localScale = new Vector3 (1f,1f,1f);
ob.transform.localPosition = new Vector3 (x, y, 5);
break;
}
}
for (int i = 0; i < transition0_1ParseXML.landElement.Count; i++) {
RandomlandElement landElement = new RandomlandElement ();
landElement = transition0_1ParseXML.GetLandElements (i);
switch (landElement.type) {
case (int)ObjectType.Corn:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/CommomCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + 3.4f, 5);
break;
case (int)ObjectType.GravityCorn:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/GravityCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + 3.4f, 5);
break;
case (int)ObjectType.Randomevent:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
string str = RandomEventInGame.GetInstance ().GetRandomValue ();
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (str);
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
case (int)ObjectType.Event:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (landElement.resource);
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
}
}
addedMidSceneNum++;
isChangeBg = true;
SetRandomBgIndex ();
ResetCarInMidScene ();
return true;
}
/// <summary>
/// 改变游戏背景Texture Update
/// </summary>
void ChangeBgTexture ()
{
int temp = (int)((UserInfos.GetInstance ().distance) / (addMidSceneDisTimes + 18));
if (addedMidSceneNum <= 0 || temp <= addedMidSceneNum - 1) {
return;
}
isChangeBg = false;
}
int sceneIndex = 0;
int SetRandomBgIndex ()
{
int tempId = 0;
if (curDistance > 12000) {
int tempIndex = Random.Range (0, sceneRandomList.Count);
tempId = (int)sceneRandomList [tempIndex];
sceneRandomList.RemoveAt (tempIndex);
} else {
tempId = (int)sceneRandomList [sceneIndex];
sceneRandomList.RemoveAt (sceneIndex);
sceneIndex++;
if (sceneIndex > 3) {
sceneIndex = 0;
}
}
if (sceneRandomList.Count <= 0) {
sceneRandomList.Add (2);
sceneRandomList.Add (3);
sceneRandomList.Add (4);
}
TempValue.GetInstance ().curLandType = tempId - 1;
return tempId;
}
/// <summary>
/// 0、暂停前一个场景的Boss
/// 1、判断跑过中间场景的次数
/// 2、在中间场景重新设置汽车配置
/// 3、在中间场景,不再积蓄飞行模式
/// </summary>
void ResetCarInMidScene ()
{
TempValue.GetInstance ().isPlayBackgroundAnim = false;
//暂停前一个场景的Boss
GameObject.FindGameObjectWithTag ("Player").GetComponent<CarControlor> ().ChangeBossAccordingToNextLevel (false);
CarConfig.GetInstance ().throughMidScenetimes++;//统计路过中间场景的次数
}
int endLandIndex = 0;
void LoadLand (int landCount)
{
GameObject ob = null;
RandomLand land = new RandomLand ();
for (int i = startLandCount; i < landCount; i++) {
GLogger.LogError ("========================================iiiiiiiiiii " + i);
land = LandConfigParseXML.GetLandList(GetLevelSplitName())[i];
switch (land.type) {
case (int)ObjectType.Land:
// x = (land.x - XOffset) / rate - xOffsetPosition + lastLandPositionX;
x = (land.x - XOffset) / rate - xOffsetPosition + 0;
y = -land.y / rate + YOffset;
string resourceName = land.resource;
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem (resourceName));
if (resourceName == "MinCliff" || resourceName == "Cliff") {
ob.GetComponent<SpriteRenderer> ().enabled = false;
}
ob.transform.localPosition = new Vector3 (x, y, 5);
endLandIndex = i;
break;
}
}
startLandCount = landCount;
GLogger.LogError ("============================ob.transform.position.x= " + ob.transform.localPosition.x + "==== " + startLandCount);
lastLandPositionX = ob.transform.localPosition.x;
}
int endElementIndex = 0;
int startElementCount = 0;
void LoadLandElements (int landElementCount)
{
GLogger.LogError (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>landElementCount> " + landElementCount);
GameObject ob = null;
for (int i = startElementCount; i < landElementCount; i++) {
RandomlandElement landElement = new RandomlandElement ();
landElement = LandConfigParseXML.GetLandElement(GetLevelSplitName()) [i];
switch (landElement.type) {
case (int)ObjectType.Obstacle:
// x = (landElement.x - XOffset) / rate - xOffsetPosition + lastElementPositionX;
x = (landElement.x - XOffset) / rate - xOffsetPosition + 0;
y = -landElement.y / rate + YOffset;
switch (landElement.resource) {
case "mouse":
switch (TempValue.GetInstance ().curLandType) {
case (int)Land_type.Dusk_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("MouseRun"));
scale = ItemPool.GetInstance ().GetScale ("MouseRun");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Ground_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_Apple"));
scale = ItemPool.GetInstance ().GetScale ("Ground_Apple");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Night_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_Duck"));
scale = ItemPool.GetInstance ().GetScale ("Night_Duck");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Rain_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_Frog_Jump"));
scale = ItemPool.GetInstance ().GetScale ("Rain_Frog_Jump");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
}
break;
case "stone":
switch (TempValue.GetInstance ().curLandType) {
case (int)Land_type.Dusk_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Stone1"));
scale = ItemPool.GetInstance ().GetScale ("Stone1");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Ground_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_Bone"));
scale = ItemPool.GetInstance ().GetScale ("Ground_Bone");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Night_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_Grass"));
scale = ItemPool.GetInstance ().GetScale ("Night_Grass");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Rain_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_Puddles_Wave"));
scale = ItemPool.GetInstance ().GetScale ("Rain_Puddles_Wave");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
}
break;
case "sunflower":
switch (TempValue.GetInstance ().curLandType) {
case (int)Land_type.Dusk_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("SunflowerRun"));
scale = ItemPool.GetInstance ().GetScale ("SunflowerRun");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Ground_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_Pumpkin"));
scale = ItemPool.GetInstance ().GetScale ("Ground_Pumpkin");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Night_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_Cactus"));
scale = ItemPool.GetInstance ().GetScale ("Night_Cactus");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Rain_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_Wind_Sway"));
scale = ItemPool.GetInstance ().GetScale ("Rain_Wind_Sway");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
}
break;
}
ob.transform.localPosition = new Vector3 (x, y, 5);
break;
case (int)ObjectType.Corn:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/CommomCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + CornYOffset, 5);
break;
case (int)ObjectType.GravityCorn:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/GravityCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + CornYOffset, 5);
break;
case (int)ObjectType.Randomevent:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
// ob = Instantiate (ResManager.Load ("Prefab/ExtraProp/ExtraProp")) as GameObject;
string str = RandomEventInGame.GetInstance ().GetRandomValue ();
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (str);
// ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
case (int)ObjectType.Event:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
// ob = Instantiate (ResManager.Load ("Prefab/ExtraProp/ExtraProp")) as GameObject;
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (landElement.resource);
// ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
}
endElementIndex = i;
}
startElementCount = landElementCount;
lastElementPositionX = ob.transform.localPosition.x;
}
}
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
public enum ObjectType
{
Land,
Obstacle,
Corn,
GravityCorn,
Randomevent,
Event,
}
//RoadMngr
public class TestNewRoad : MonoBehaviour
{
public GameObject road_Parent;
public GameObject monster_Parent;
public GameObject propInGame;
void Awake ()
{
Init ();
}
void Init ()
{
GetCommponent getComponent = GetComponent<GetCommponent> ();
road_Parent = getComponent.defaultGameObject [0];
monster_Parent = getComponent.defaultGameObject [1];
propInGame = getComponent.defaultGameObject [2];
}
void Start ()
{
InitCurParm ();
sceneRandomList = new ArrayList{ 2, 3, 4 };//随机场景的序号
}
private int SumWeight;
private List<int> WeightList;
private List<int> TimesList;
int randomNum;
NewLandEntity tempNewLandEntity;
private int levelIndex = 0;
private int elementIndex = 0;
void InitCurParm ()
{
WeightList = new List<int> ();
TimesList = new List<int> ();
tempNewLandEntity = NewLandParseXML.GetLand (NewLandParseXML.index);
TimesList.Add (tempNewLandEntity.times0);
TimesList.Add (tempNewLandEntity.times1);
TimesList.Add (tempNewLandEntity.times2);
TimesList.Add (tempNewLandEntity.times3);
TimesList.Add (tempNewLandEntity.times4);
TimesList.Add (tempNewLandEntity.times5);
TimesList.Add (tempNewLandEntity.times6);
WeightList.Add (SumWeight += tempNewLandEntity.weight0);
WeightList.Add (SumWeight += tempNewLandEntity.weight1);
WeightList.Add (SumWeight += tempNewLandEntity.weight2);
WeightList.Add (SumWeight += tempNewLandEntity.weight3);
WeightList.Add (SumWeight += tempNewLandEntity.weight4);
WeightList.Add (SumWeight += tempNewLandEntity.weight5);
WeightList.Add (SumWeight += tempNewLandEntity.weight6);
randomNum = (int)(Random.value * SumWeight);
GLogger.LogError ("**********************************===SumWeight= " + SumWeight + "=== " + randomNum);
for (int i = 0; i < WeightList.Count; i++) {
if (WeightList [i] > randomNum) {
GLogger.LogError ("**********************************===i= " + i);
switch (NewLandParseXML.index) {
case 0:
levelIndex = i;
elementIndex = Random.Range (1,6);
break;
case 1:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 2:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 3:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 4:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 5:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 6:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 7:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 8:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 9:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 10:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
case 11:
levelIndex = i;
elementIndex = Random.Range (1,11);
break;
}
break;
}
}
}
//由于中间场景规定的Lv7_0 是中间场景,所以以后要添加7等级的关卡难度要注意!!!
string GetLevelSplitName(){
GLogger.LogError ("=======================================随即路面: " + levelIndex + "_" + elementIndex);
return levelIndex + "_" + elementIndex;
}
private float rate = 100f;
private float YOffset = 2.4f;
private float XOffset = 0;
private float xOffsetPosition = 2;
private float x = 0;
private float y = 0;
private float ExtraPropYOffset = 0.31f;
private float CornYOffset = 0.35f;
float scale = 0;
private bool isLoadNextLand = false;
private bool isLoadNextElement = false;
int startLandIndex = 0;
int startElementIndex = 0;
bool carIsDead = false;
float lastLandPositionX = 0f;
float lastElementPositionX = 0f;
float curDistance = 0;
private float addMidSceneDisTimes = 1146;
//已经添加的中间场景的数量
private int addedMidSceneNum = 0;
private bool isChangeBg = false;
private ArrayList sceneRandomList;
private int finalLandIndex = 0;
private int startLandCount = 0;
void Update ()
{
curDistance = UserInfos.GetInstance ().distance;
// bool result = NewMidScene (curDistance);
bool result = false;
if (result) {
} else {
//加载路面
if (curDistance > (lastLandPositionX - 10) && !isLoadNextLand) {
// if (!isLoadNextLand) {
if (carIsDead) {
startLandIndex += 10;
LoadLand (startLandIndex);
carIsDead = false;
} else {
if (startLandIndex <= LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count) {
int currentLeftLand = LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count - endLandIndex;
if (currentLeftLand > 0) {
startLandIndex += 10;
} else {
startLandIndex += currentLeftLand;
}
LoadLand (startLandIndex);
// if (IsLastLand ()) {
// if(lastLandPositionX){
// //添加中间场景
// }
// }
}
// LoadLand (LandConfigParseXML.GetLandList(GetLevelSplitName()).Count);
}
isLoadNextLand = true;
}
else if(curDistance < (lastLandPositionX - 10) && isLoadNextLand == true){
isLoadNextLand = false;
InitCurParm ();
}
//加载路面元素
if (curDistance > (lastElementPositionX - 10) && !isLoadNextElement) {
// if (!isLoadNextLand) {
if (carIsDead) {
startElementIndex += 10;
LoadLandElements (startElementIndex);
carIsDead = false;
} else {
if (startElementIndex <= LandConfigParseXML.GetLandElement(GetLevelSplitName()).Count) {
int currentLeftLand = LandConfigParseXML.GetLandElement(GetLevelSplitName()).Count - endElementIndex;
if (currentLeftLand > 0) {
startElementIndex += 5;
} else {
startElementIndex += currentLeftLand;
}
}
LoadLandElements (startElementIndex);
// LoadLandElements (LandConfigParseXML.GetLandElement(GetLevelSplitName()).Count);
}
isLoadNextElement = true;
}
else if(curDistance < (lastElementPositionX - 10) && isLoadNextElement == true){
isLoadNextElement = false;
}
}
if (isChangeBg) {
ChangeBgTexture ();
}
}
bool IsLastLand(){
if (RandomLandParseXML.landList.Count == endLandIndex) {
return true;
} else {
return false;
}
}
// bool NewMidScene (float length)
bool NewMidScene ()
{
int midIndex = 7;
int midElementIndex = Random.Range (1,6);
GameObject ob = null;
// int temp = (int)(length / addMidSceneDisTimes);
// if (temp <= addedMidSceneNum) {
// return false;
// }
//add midScene
for (int i = 0; i < transition0_1ParseXML.landList.Count; i++) {
RandomLand land = new RandomLand ();
land = transition0_1ParseXML.GetLand (i);
switch (land.type) {
case (int)ObjectType.Land:
x = (land.x - XOffset) / rate - 0;
y = -land.y / rate + 1.43f;
string resourceName = land.resource;
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem (resourceName));
// ob.transform.localScale = new Vector3 (1f,1f,1f);
ob.transform.localPosition = new Vector3 (x, y, 5);
break;
}
}
for (int i = 0; i < transition0_1ParseXML.landElement.Count; i++) {
RandomlandElement landElement = new RandomlandElement ();
landElement = transition0_1ParseXML.GetLandElements (i);
switch (landElement.type) {
case (int)ObjectType.Corn:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/CommomCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + 3.4f, 5);
break;
case (int)ObjectType.GravityCorn:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/GravityCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + 3.4f, 5);
break;
case (int)ObjectType.Randomevent:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
string str = RandomEventInGame.GetInstance ().GetRandomValue ();
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (str);
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
case (int)ObjectType.Event:
x = (landElement.x - XOffset) / rate - 0;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (landElement.resource);
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
}
}
addedMidSceneNum++;
isChangeBg = true;
SetRandomBgIndex ();
ResetCarInMidScene ();
return true;
}
/// <summary>
/// 改变游戏背景Texture Update
/// </summary>
void ChangeBgTexture ()
{
int temp = (int)((UserInfos.GetInstance ().distance) / (addMidSceneDisTimes + 18));
if (addedMidSceneNum <= 0 || temp <= addedMidSceneNum - 1) {
return;
}
isChangeBg = false;
}
int sceneIndex = 0;
int SetRandomBgIndex ()
{
int tempId = 0;
if (curDistance > 12000) {
int tempIndex = Random.Range (0, sceneRandomList.Count);
tempId = (int)sceneRandomList [tempIndex];
sceneRandomList.RemoveAt (tempIndex);
} else {
tempId = (int)sceneRandomList [sceneIndex];
sceneRandomList.RemoveAt (sceneIndex);
sceneIndex++;
if (sceneIndex > 3) {
sceneIndex = 0;
}
}
if (sceneRandomList.Count <= 0) {
sceneRandomList.Add (2);
sceneRandomList.Add (3);
sceneRandomList.Add (4);
}
TempValue.GetInstance ().curLandType = tempId - 1;
return tempId;
}
/// <summary>
/// 0、暂停前一个场景的Boss
/// 1、判断跑过中间场景的次数
/// 2、在中间场景重新设置汽车配置
/// 3、在中间场景,不再积蓄飞行模式
/// </summary>
void ResetCarInMidScene ()
{
TempValue.GetInstance ().isPlayBackgroundAnim = false;
//暂停前一个场景的Boss
GameObject.FindGameObjectWithTag ("Player").GetComponent<CarControlor> ().ChangeBossAccordingToNextLevel (false);
CarConfig.GetInstance ().throughMidScenetimes++;//统计路过中间场景的次数
}
int endLandIndex = 0;
void LoadLand (int landCount)
{
GameObject ob = null;
RandomLand land = new RandomLand ();
for (int i = startLandCount; i < landCount; i++) {
GLogger.LogError ("========================================iiiiiiiiiii " + i);
land = LandConfigParseXML.GetLandList(GetLevelSplitName())[i];
switch (land.type) {
case (int)ObjectType.Land:
// x = (land.x - XOffset) / rate - xOffsetPosition + lastLandPositionX;
x = (land.x - XOffset) / rate - xOffsetPosition + 0;
y = -land.y / rate + YOffset;
string resourceName = land.resource;
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem (resourceName));
if (resourceName == "MinCliff" || resourceName == "Cliff") {
ob.GetComponent<SpriteRenderer> ().enabled = false;
}
ob.transform.localPosition = new Vector3 (x, y, 5);
endLandIndex = i;
break;
}
}
startLandCount = landCount;
GLogger.LogError ("============================ob.transform.position.x= " + ob.transform.localPosition.x + "==== " + startLandCount);
lastLandPositionX = ob.transform.localPosition.x;
}
int endElementIndex = 0;
int startElementCount = 0;
void LoadLandElements (int landElementCount)
{
GLogger.LogError (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>landElementCount> " + landElementCount);
GameObject ob = null;
for (int i = startElementCount; i < landElementCount; i++) {
RandomlandElement landElement = new RandomlandElement ();
landElement = LandConfigParseXML.GetLandElement(GetLevelSplitName()) [i];
switch (landElement.type) {
case (int)ObjectType.Obstacle:
// x = (landElement.x - XOffset) / rate - xOffsetPosition + lastElementPositionX;
x = (landElement.x - XOffset) / rate - xOffsetPosition + 0;
y = -landElement.y / rate + YOffset;
switch (landElement.resource) {
case "mouse":
switch (TempValue.GetInstance ().curLandType) {
case (int)Land_type.Dusk_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("MouseRun"));
scale = ItemPool.GetInstance ().GetScale ("MouseRun");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Ground_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_Apple"));
scale = ItemPool.GetInstance ().GetScale ("Ground_Apple");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Night_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_Duck"));
scale = ItemPool.GetInstance ().GetScale ("Night_Duck");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Rain_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_Frog_Jump"));
scale = ItemPool.GetInstance ().GetScale ("Rain_Frog_Jump");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
}
break;
case "stone":
switch (TempValue.GetInstance ().curLandType) {
case (int)Land_type.Dusk_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Stone1"));
scale = ItemPool.GetInstance ().GetScale ("Stone1");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Ground_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_Bone"));
scale = ItemPool.GetInstance ().GetScale ("Ground_Bone");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Night_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_Grass"));
scale = ItemPool.GetInstance ().GetScale ("Night_Grass");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Rain_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_Puddles_Wave"));
scale = ItemPool.GetInstance ().GetScale ("Rain_Puddles_Wave");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
}
break;
case "sunflower":
switch (TempValue.GetInstance ().curLandType) {
case (int)Land_type.Dusk_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("SunflowerRun"));
scale = ItemPool.GetInstance ().GetScale ("SunflowerRun");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Ground_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_Pumpkin"));
scale = ItemPool.GetInstance ().GetScale ("Ground_Pumpkin");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Night_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_Cactus"));
scale = ItemPool.GetInstance ().GetScale ("Night_Cactus");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
case (int)Land_type.Rain_land:
ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_Wind_Sway"));
scale = ItemPool.GetInstance ().GetScale ("Rain_Wind_Sway");
ob.transform.localScale = new Vector3 (scale, scale, 1);
break;
}
break;
}
ob.transform.localPosition = new Vector3 (x, y, 5);
break;
case (int)ObjectType.Corn:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/CommomCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + CornYOffset, 5);
break;
case (int)ObjectType.GravityCorn:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = Instantiate (ResManager.Load ("Prefab/Monster/Corn/GravityCorn/" + landElement.resource)) as GameObject;
ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + CornYOffset, 5);
break;
case (int)ObjectType.Randomevent:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
// ob = Instantiate (ResManager.Load ("Prefab/ExtraProp/ExtraProp")) as GameObject;
string str = RandomEventInGame.GetInstance ().GetRandomValue ();
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (str);
// ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
case (int)ObjectType.Event:
x = (landElement.x - XOffset) / rate - xOffsetPosition;
y = -landElement.y / rate + YOffset;
ob = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
// ob = Instantiate (ResManager.Load ("Prefab/ExtraProp/ExtraProp")) as GameObject;
ob.GetComponent<AwardPropInGame> ().SetPropAttribute (landElement.resource);
// ob.transform.parent = road_Parent.transform;
ob.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
break;
}
endElementIndex = i;
}
startElementCount = landElementCount;
lastElementPositionX = ob.transform.localPosition.x;
}
}