sssssss

using UnityEngine;
using System.Collections;

public class CarControlor : MonoBehaviour
{
    private bool second_jump_status = false;
    //    public GameObject car;
    public GameObject fwheel;
    public GameObject bwheel;
    //车身挂件显示
    public GameObject carLight;
    //    public GameObject shock;
    [HideInInspector]
    public Vector2 speed;
    [HideInInspector]
    public Vector2 jumpSpeedY;
    [HideInInspector]
    public CarWheelF tempIsFgrounded;
    [HideInInspector]
    public CarWheelB tempIsBgrounded;
    private bool isFgrounded;
    private    bool isBgrounded;
    //    private Vector3 tempVec3;
    private Vector2 tempJump;
    //    private Vector2 tempY0;
    public GameObject FlyWheelBLight;
    public GameObject FlyWheelFLight;
    public GameObject Fly_Car_Speed;
    public bool isFly = false;
    public GameObject superPosition;
    //    private Vector2 tempDownVelocity;
    public GameObject attractCorn;
    public SpriteRenderer driver;
    public SpriteRenderer carBody;
    public SpriteRenderer wheelf;
    public SpriteRenderer wheelb;
    //设置汽车初始化速度
    public float initCarVelocity;
    private float carFlySpeed;
    private float sameSceneAddSpeed;
    private float changeSceneAddSpeed;
    private int addSpeedDistance;
    private WheelJoint2D[] temp;
    private string[] tempSkin;
    private float changeFlySpeed;
    public GameObject fWheelShock;
    public GameObject bWheelShock;
    private bool isAddSameScenevelocity = false;
    public GameObject starw;
    //在飞行模式中,关闭吸收玉米特效
    //    private GameObject EatCornCollider;
    //    private StopEatCornCollider stopEatCornCollider;
    private bool isCliff = false;
    //如果在悬崖坠落之后,要等待一段时间之后才能开始前进
//    private BoxCollider2D box2dAttractCorn;
    public EdgeCollider2D chessColliderToPressMidMonster;
    public BoxCollider2D carHitMidMonster;
    public CircleCollider2D forntWheelHitSmallMonster;
    public CircleCollider2D backWheelHitSmallMonster;
    private float defaultGravityScale = 6.5f;
    private Transform myTransform;
    public Rigidbody2D myRigid2D;
    private char[] subLineSplit = new char[]{ '_' };
    private BoxCollider2D attractBoxCollider;
    public FlyCarSpeed flyCarSpeed;
    //6.5f
    void Awake ()
    {
        myTransform = this.transform;
        myRigid2D = this.rigidbody2D;
        Init ();
        SetCarInitCongfig ();
    }

    void Init ()
    {
        GetCommponent getComponent = GetComponent<GetCommponent> ();
        fwheel = getComponent.defaultGameObject [0];
        bwheel = getComponent.defaultGameObject [1];
        carLight = getComponent.defaultGameObject [2];
        FlyWheelBLight = getComponent.defaultGameObject [3];
        FlyWheelFLight = getComponent.defaultGameObject [4];
        Fly_Car_Speed = getComponent.defaultGameObject [5];
        superPosition = getComponent.defaultGameObject [6];
        attractCorn = getComponent.defaultGameObject [7];

        driver = getComponent.GetDefaultGB<SpriteRenderer> (8);
        carBody = getComponent.GetDefaultGB<SpriteRenderer> (9);
        wheelf = getComponent.GetDefaultGB<SpriteRenderer> (10);
        wheelb = getComponent.GetDefaultGB<SpriteRenderer> (11);


        fWheelShock = getComponent.defaultGameObject [12];
        bWheelShock = getComponent.defaultGameObject [13];
        starw = getComponent.defaultGameObject [14];


        chessColliderToPressMidMonster = getComponent.GetDefaultGB<EdgeCollider2D> (15);
        carHitMidMonster = getComponent.GetDefaultGB<BoxCollider2D> (16);
        forntWheelHitSmallMonster = getComponent.GetDefaultGB<CircleCollider2D> (17);
        backWheelHitSmallMonster = getComponent.GetDefaultGB<CircleCollider2D> (18);

    }

    public void SetCarInitCongfig ()
    {
//        targetSpeed = 25f;
        targetSpeed = ClientConstantConfigParseXML.GetValueById ("initCarSpeed");
//        carFlySpeed = 80f;
        carFlySpeed = ClientConstantConfigParseXML.GetValueById ("carFlySpeed");
//        sameSceneAddSpeed = 0.191f;
        sameSceneAddSpeed = ClientConstantConfigParseXML.GetValueById ("sameSceneAddSpeed");
//        changeSceneAddSpeed = 0.764f;
        changeSceneAddSpeed = ClientConstantConfigParseXML.GetValueById ("changeSceneAddSpeed");
//        addSpeedDistance = 114;
        addSpeedDistance = (int)ClientConstantConfigParseXML.GetValueById ("addSpeedDistance");
    }

    void  Start ()
    {
        starw.transform.localPosition = new Vector3 (1.473f, 0.48f, 0);
        InitCarProperty ();
    }

    /// <summary>
    /// 1、获得有用物体
    /// 2、判断是否有飞行道具
    /// 3、根据车子的属性,增加吸收玉米的范围
    /// </summary>
    void InitCarProperty ()
    {
        flyCarSpeed = Fly_Car_Speed.GetComponent<FlyCarSpeed> ();
        flyCarSpeed.ShowCarFlyAnim (false);
        GetUsefulGameobject ();
        HasFlyPropBuff ();
        AddAttractCornRange ();
    }

    void GetUsefulGameobject ()
    {
        attractBoxCollider = attractCorn.GetComponent<BoxCollider2D> ();
        temp = gameObject.GetComponents<WheelJoint2D> ();
        tempIsFgrounded = fwheel.GetComponent<CarWheelF> ();
        tempIsBgrounded = bwheel.GetComponent<CarWheelB> ();
//        box2dAttractCorn = attractCorn.GetComponent<BoxCollider2D> ();
    }

    void HasFlyPropBuff ()
    {
//        if (GameBuff.GetInstance ().Fly_status) {
//            GameBuff.GetInstance ().Fly_status = false;
////            挂件的飞行时间是单个计算还是和任务飞行属性相关联?
////            SetHasFlyBuffTime (11.4f);//11.4秒飞行700米
//            SetHasFlyBuffTime (50f);// 飞车测试速度
//        } else 
        if (GameBuff.GetInstance ().StartCarFly) {
            GameObject.FindGameObjectWithTag ("ClickBtnToFly").SetActive (false);
            GameBuff.GetInstance ().StartCarFly = false;
            SetHasFlyBuffTime (GameBuff.GetInstance ().ExtraCarFlyTimeBeforeStart);
        } else {
//            Fly_Car_Speed.SetActive (false);
            flyCarSpeed.ShowCarFlyAnim (false);
        }
    }

    void Update ()
    {
    
        UserInfos.GetInstance ().distance = myTransform.position.x;
        HasStopCarShockBuff ();
        WheelIsGround ();
        CarJumpState ();

    }
        

    /// <summary>
    /// 判断是否有减震挂件
    /// </summary>
    void HasStopCarShockBuff ()
    {
        if (GameBuff.GetInstance ().StopShockBuffNum != 0) {
            SetWheelShockEffect (true);
        } else {
            SetWheelShockEffect (false);
        }
    }

    void SetWheelShockEffect (bool isActive)
    {
        fWheelShock.SetActive (isActive);
        bWheelShock.SetActive (isActive);
    }

    void FixedUpdate ()
    {
        SetCarMaxSpeedAndRotate ();
        SetCarCenterOfMass ();
        //设置汽车向前的速度
        CarHorzontialSpeed ();
    }

    /// <summary>
    /// 车轮是否着地,设置轮子离开地面后,和车身的距离
    /// </summary>
    void WheelIsGround ()
    {
        isFgrounded = tempIsFgrounded.isWheelFGrounded;
        isBgrounded = tempIsBgrounded.isWheelBGrounded;

        if (isFgrounded && isBgrounded) {
            temp [0].anchor = new Vector2 (temp [0].anchor.x, -0.672f);
            temp [1].anchor = new Vector2 (temp [1].anchor.x, -0.672f);
            tempIsBgrounded.SetSuspensionDis (temp [0].anchor.y);
            tempIsFgrounded.SetSuspensionDis (temp [0].anchor.y);
        } else {
            temp [0].anchor = new Vector2 (temp [0].anchor.x, -0.718f);
            temp [1].anchor = new Vector2 (temp [1].anchor.x, -0.718f);
            tempIsBgrounded.SetSuspensionDis (temp [0].anchor.y);
            tempIsFgrounded.SetSuspensionDis (temp [0].anchor.y);
        }
    }

    public float targetSpeed;
    public float curSpeed;

    /// <summary>
    /// 汽车水平速度 
    /// </summary>
    void CarHorzontialSpeed ()
    {
        if (!isCliff) {
            if ((int)(UserInfos.GetInstance ().distance / 0.382) % addSpeedDistance == 0 && !isAddSameScenevelocity) {
                targetSpeed += sameSceneAddSpeed;    
                BossConfig.GetInstant ().normalSpeed += sameSceneAddSpeed;
                isAddSameScenevelocity = true;
            }
            if ((int)(UserInfos.GetInstance ().distance / 0.382) % addSpeedDistance != 0) {
                isAddSameScenevelocity = false;
            }
//            GLogger.Log ("*****************************************目标targetSpeed************************:" + targetSpeed);
            curSpeed = Mathf.MoveTowards (curSpeed, targetSpeed, 4 * Time.deltaTime);
            initCarVelocity = curSpeed;
            speed = myRigid2D.velocity;
            speed.x = initCarVelocity;

            if (speed.x >= CarConfig.GetInstance ().maxSpeed && !isFly) {
                speed.x = CarConfig.GetInstance ().maxSpeed;
            }

            myRigid2D.velocity = speed;
            //Boss和车子之间的距离 = 当前车速*2s
            BossConfig.GetInstant ().minRacingWithCar = myRigid2D.velocity.x * 2;
            CarConfig.GetInstance ().carCurrentVelocity = myRigid2D.velocity.x;
//            GLogger.Log ("*****************************************当前汽车水平速度:" + rigidbody2D.velocity.x);
        }
    }

    /// <summary>
    /// 汽车垂直速度
    /// </summary>
    void CarVerticalSpeed ()
    {
        tempJump = myRigid2D.velocity;
        tempJump.y = CarConfig.GetInstance ().jumpVelocity;
        myRigid2D.velocity = tempJump;
    }

    /// <summary>
    /// 汽车质量中心
    /// </summary>
    void SetCarCenterOfMass ()
    {
        float centerOfMassOfPoint = -0.13f;
        myRigid2D.centerOfMass = new Vector2 (centerOfMassOfPoint, centerOfMassOfPoint);    
    }

    /// <summary>
    /// 汽车二段跳
    /// </summary>
    void CarJumpState ()
    {
        //先判断是否是飞行模式,是,不可起跳,否则,可跳
        if (Input.GetKeyDown (KeyCode.W) || Input.GetMouseButtonDown (0)) {
            Ray ray = UICamera.mainCamera.ScreenPointToRay (Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast (ray, out hit)) {
                if (hit.transform.gameObject.tag == "Root") {
                    return; 
                }
                AudioMngr.GetInstance ().PlayEffect (AudioConfig.vehicle_jump);
                JumpHandler ();
            } else {
                GLogger.LogWarning ("==============================================汽车不能起跳!!!!!!!!!!");
            }
        }
    }

    public void JumpHandler ()
    {
        if ((isFgrounded || isBgrounded)) {
            second_jump_status = false;
        }
        if (isFly || CarConfig.GetInstance ().isStopJump || CarConfig.GetInstance ().isLifeStopJump) {
            return;
        }
        if ((isFgrounded || isBgrounded) && !second_jump_status) {
            myRigid2D.gravityScale = 0;
            fwheel.rigidbody2D.velocity = new Vector2 (fwheel.rigidbody2D.velocity.x, 0);
            bwheel.rigidbody2D.velocity = new Vector2 (bwheel.rigidbody2D.velocity.x, 0);
            myRigid2D.velocity = new Vector2 (myRigid2D.velocity.x, 0);

            myRigid2D.velocity = new Vector2 (myRigid2D.velocity.x, CarConfig.GetInstance ().jumpVelocity);
            tempIsFgrounded.isWheelFGrounded = false;
            tempIsBgrounded.isWheelBGrounded = false;
            second_jump_status = true;
            SetCarJumpTimes ();
            myRigid2D.gravityScale = defaultGravityScale;
            if (myRigid2D.velocity.x < initCarVelocity) {
                myRigid2D.velocity = new Vector2 (initCarVelocity, myRigid2D.velocity.y);
            }
        } else if (second_jump_status && !(isFgrounded || isBgrounded)) {

            myRigid2D.gravityScale = 0;
            fwheel.rigidbody2D.velocity = new Vector2 (fwheel.rigidbody2D.velocity.x, 0);
            bwheel.rigidbody2D.velocity = new Vector2 (bwheel.rigidbody2D.velocity.x, 0);
            myRigid2D.velocity = new Vector2 (myRigid2D.velocity.x, 0);

            myRigid2D.velocity = new Vector2 (myRigid2D.velocity.x, CarConfig.GetInstance ().jumpVelocity);
            second_jump_status = false;
            SetCarJumpTimes ();
            myRigid2D.gravityScale = defaultGravityScale;

        }
    }

    void SetCarJumpTimes ()
    {
        CarConfig.GetInstance ().jumpTimes++;
    }

    int rotationSpeed = 8;

    /// <summary>
    /// 设置汽车最大速度,判断旋转角度
    /// </summary>
    void SetCarMaxSpeedAndRotate ()
    {
        //固定车身的旋转方向
        if ((myTransform.rotation.eulerAngles.z <= 350) && (myTransform.rotation.eulerAngles.z >= 180)) {

            if (initCarVelocity == 0) {
                SetMyRigid2DZero ();    
                SetTransformRotation ();
            } else {    
                SetMyRigid2DToBalance (1);
                SetTransformRotation ();
            }
        }
        //固定车身的旋转方向¡
        if ((myTransform.rotation.eulerAngles.z >= 10) && (myTransform.rotation.eulerAngles.z <= 180)) {
            if (initCarVelocity == 0) {
                SetMyRigid2DZero ();
                SetTransformRotation ();
            } else {
                SetMyRigid2DToBalance (-1);
                SetTransformRotation ();
            }
        }
    }

    void SetMyRigid2DZero ()
    {
        myRigid2D.angularDrag = 0f;
        myRigid2D.angularVelocity = 0f;
        myRigid2D.AddTorque (0f);
    }

    void SetMyRigid2DToBalance (int i)
    {
        myRigid2D.angularDrag = 1000f * i;
        myRigid2D.angularVelocity = 0f;
        myRigid2D.AddTorque (61000f * i);
    }

    void SetTransformRotation ()
    {
        myTransform.rotation = Quaternion.Lerp (myTransform.rotation, Quaternion.identity, Time.deltaTime * rotationSpeed);
    }

    public void SetCarFlyingCanNotHitMidMonster ()
    {
        carHitMidMonster.enabled = false;
        chessColliderToPressMidMonster.enabled = false;
    }

    /// <summary>
    /// 车子行进中,飞行模式,汽车不能起跳
    /// </summary>
    public void FlyModel (float flyTime)
    {
        if (isFly) {
            return;
        }

        if (GameBuff.GetInstance ().IsCarReadyFly) {
            GameBuff.GetInstance ().IsCarFlyAfterDead = true;
        }

        AudioMngr.GetInstance ().PlayEffect (AudioConfig.vehicle_dash);
        myTransform.rotation = Quaternion.identity;
        SetCarFlyingStatus (false);
        SetStarwFalseWhenFlying (false);
        CarConfig.GetInstance ().flyTimes++;
//        Fly_Car_Speed.SetActive (true);
        flyCarSpeed.ShowCarFlyAnim (true);
        myRigid2D.isKinematic = true;
        float y = 3f;
        SetFlyWheel ();

        //初始速度
//        changeFlySpeed = curSpeed;
        changeFlySpeed = targetSpeed;
        targetSpeed = carFlySpeed;
        curSpeed = carFlySpeed;

        CarConfig.GetInstance ().isFlying = true;
        isFly = true;
        //在飞行模式中销毁堵住物体
        GameObject.FindGameObjectWithTag ("StopEatCornCollider").GetComponent<StopEatCornCollider> ().IsFlyModel (isFly);

        StartCoroutine (RaiseUp (y));
        StartCoroutine (Wait (flyTime));
//        Debug.Log ("=========================================总飞行时间:" + CarConfig.GetInstance ().FlyTime ());
    }

    public void SetHasFlyBuffTime (float flyTime)
    {
        if (isFly) {
            return;
        }
        AudioMngr.GetInstance ().PlayEffect (AudioConfig.vehicle_dash);
        myTransform.rotation = Quaternion.identity;

        SetCarFlyingStatus (false);
        SetStarwFalseWhenFlying (false);
//        Fly_Car_Speed.SetActive (true);
        flyCarSpeed.ShowCarFlyAnim (true);
        myRigid2D.isKinematic = true;
        SetFlyWheel ();
        CarConfig.GetInstance ().flyTimes++;
//        if (targetSpeed == 0) {
//            changeFlySpeed = 4f + CarConfig.GetInstance ().throughMidScenetimes;
//        } else {
        changeFlySpeed = targetSpeed;
//        }
        float y = 3f;

        isFly = true;
        CarConfig.GetInstance ().isFlying = true;
        targetSpeed = carFlySpeed;
        curSpeed = carFlySpeed;

        StartCoroutine (RaiseUp (y));
        StartCoroutine (Wait (flyTime));
    }

    IEnumerator RaiseUp (float y)
    {
        float aa = 20;
        if (myTransform.position.y > y) {
            //如果汽车的位置大于3时,将汽车的位置设置为3
            myTransform.position = new Vector3 (myTransform.position.x, y, myTransform.position.z);
        }
        while (myTransform.position.y <= y) {
            yield return new WaitForSeconds (0.01f);
            myTransform.position += Vector3.up * (y / aa);
        }
    }

    IEnumerator Wait (float waitTime)
    {
        yield return new WaitForSeconds (waitTime);
        FlyDone ();
    }

    void FlyDone ()
    {
        myTransform.rotation = Quaternion.identity;

        SetCarFlyingStatus (true);

        SetFlyDoneWheel ();

        myRigid2D.isKinematic = false;

        targetSpeed = changeFlySpeed;
        curSpeed = changeFlySpeed;
                
//        Fly_Car_Speed.SetActive (false);
        flyCarSpeed.ShowCarFlyAnim (false);
        SetStarwFalseWhenFlying (false);
        isFly = false;
        CarConfig.GetInstance ().isFlying = false;
        CarConfig.GetInstance ().isAccFull = false;

        if (GameBuff.GetInstance ().IsCarReadyFly) {
            GameBuff.GetInstance ().IsCarReadyFly = false;
            GameBuff.GetInstance ().IsCarFlyAfterDead = false;
        }
//        GLogger.LogWarning ("+++========================================current target speed0000000000000000000000000000: " + targetSpeed);

    }

    /// <summary>
    /// 汽车在飞行状态,需要关闭自身的某些功能,不能碰撞怪物,路面等
    /// </summary>
    void SetCarFlyingStatus (bool isActive)
    {
//        attractBoxCollider.enabled = isActive;
        attractCorn.SetActive (isActive);
        carHitMidMonster.enabled = isActive;
        forntWheelHitSmallMonster.enabled = isActive;
        backWheelHitSmallMonster.enabled = isActive;
        chessColliderToPressMidMonster.enabled = isActive;
        CarConfig.GetInstance ().isAccFly = isActive;
    }

    void SetStarwFalseWhenFlying (bool isFalse)
    {
        if (starw.activeInHierarchy == true) {
            starw.SetActive (isFalse);
        }
    }

    void SetFlyWheel ()
    {
        SetTwoWheelsStatus (true, -0.735f);
    }

    void SetFlyDoneWheel ()
    {
        SetTwoWheelsStatus (false, -0.672f);
    }

    void SetTwoWheelsStatus (bool isUseMotor, float dis)
    {
        temp [0].useMotor = isUseMotor;
        temp [0].anchor = new Vector2 (temp [0].anchor.x, dis);
        temp [1].useMotor = isUseMotor;
        temp [1].anchor = new Vector2 (temp [1].anchor.x, dis);
        tempIsBgrounded.SetSuspensionDis (temp [0].anchor.y);
        tempIsFgrounded.SetSuspensionDis (temp [0].anchor.y);
    }

    /// <summary>
    /// 根据不同等级,增加BoxCollider2D的范围,吸收玉米
    /// </summary>
    void AddAttractCornRange ()
    {
        switch (CarConfig.GetInstance ().attractCornLevel) {
        case 1:
            SetAttractCornSize (new Vector2 (3f, CarConfig.GetInstance ().attractCornLevel));
            break;
        case 2:
            SetAttractCornSize (new Vector2 (3f, CarConfig.GetInstance ().attractCornLevel));
            break;
        case 3:
            SetAttractCornSize (new Vector2 (3f, CarConfig.GetInstance ().attractCornLevel));
            break;
        case 4:
            SetAttractCornSize (new Vector2 (3f, CarConfig.GetInstance ().attractCornLevel));
            break;
        case 5:
            SetAttractCornSize (new Vector2 (3f, CarConfig.GetInstance ().attractCornLevel));
            break;
        }
    }

    void SetAttractCornSize (Vector2 vectorSize)
    {
//        box2dAttractCorn.size = vectorSize;
        attractBoxCollider.size  = vectorSize;
    }

    public void SetCarSkin ()
    {
        SetDriverSprite (CarConfig.GetInstance ().driverIcon);
        SetCarSprite (CarConfig.GetInstance ().carIcon);
        SetWheelSprite (CarConfig.GetInstance ().wheelIcon);
    }

    void SetDriverSprite (string skin)
    {
        tempSkin = skin.Split (subLineSplit);
//        Sprite temp = ResManager.LoadSprite ("GameProp/Driver/" + tempSkin [0]); //Resources.Load<Sprite> ("GameProp/Driver/" + tempSkin [0]);
//        Sprite temp = Resources.Load<Sprite> (tempSkin [0]);
        Sprite temp = ResManager.LoadSprite (tempSkin [0]);

        SetDriversAnimation (tempSkin [0]);
        driver.GetComponent<SpriteRenderer> ().sprite = temp;
    }

    void SetDriversAnimation (string str)
    {
        switch (str) {
        case "Driver1":
            SetDriverAnimIndex (1);
            break;
        case "Driver2":
            SetDriverAnimIndex (2);
            break;
        case "Driver3":
            SetDriverAnimIndex (3);
            break;
        case "Driver4":
            SetDriverAnimIndex (4);
            break;
        case "Driver5":
            SetDriverAnimIndex (5);
            break;
        case "Driver6":
            SetDriverAnimIndex (6);
            break;
        }
    }

    void SetDriverAnimIndex (int index)
    {
        TempValue.GetInstance ().driverAnimIndex = index;
    }

    void SetCarSprite (string skin)
    {
        tempSkin = skin.Split (subLineSplit);

//        Sprite temp = ResManager.LoadSprite ("GameProp/Car/" + tempSkin [0]);
        //Resources.Load<Sprite> ("GameProp/Driver/" + tempSkin [0]);
        Sprite temp = ResManager.LoadSprite (tempSkin [0]);
//        Sprite temp = Resources.Load<Sprite> ("GameProp/Car/" + tempSkin [0]);
        carBody.GetComponent<SpriteRenderer> ().sprite = temp;
        Vector2 vec = new Vector2 ();
        vec = GetDriverIconPosition (temp.name);
        SetDriverPosition (vec);
    }

    void SetWheelSprite (string skin)
    {
        tempSkin = skin.Split (subLineSplit);
//        Sprite temp = ResManager.LoadSprite ("GameProp/Wheel/" + tempSkin [0]);
        Sprite temp = ResManager.LoadSprite (tempSkin [0]);
//        Sprite temp = Resources.Load<Sprite> ("GameProp/Wheel/" + tempSkin [0]);
        wheelf.sprite = temp;
        wheelb.sprite = temp;
    }

    void SetDriverPosition (Vector2 vec)
    {
        driver.transform.localPosition = new Vector3 (vec.x, vec.y, 0);
        //获得角色头像,在PK面板显示
        switch (driver.sprite.name) {
        case "Driver1":
            UserInfos.GetInstance ().playerTouXiangName = string.Format ("{0}{1}", driver.sprite.name, "_icon");
            break;
        case "Driver2":
            UserInfos.GetInstance ().playerTouXiangName = string.Format ("{0}{1}", driver.sprite.name, "_icon");
            break;
        case "Driver3":
            UserInfos.GetInstance ().playerTouXiangName = string.Format ("{0}{1}", driver.sprite.name, "_icon");
            break;
        case "Driver4":
            UserInfos.GetInstance ().playerTouXiangName = string.Format ("{0}{1}", driver.sprite.name, "_icon");
            break;
        case "Driver5":
            UserInfos.GetInstance ().playerTouXiangName = string.Format ("{0}{1}", driver.sprite.name, "_icon");
            break;
        case "Driver6":
            UserInfos.GetInstance ().playerTouXiangName = string.Format ("{0}{1}", driver.sprite.name, "_icon");
            break;
        }
    }

    /// <summary>
    /// 当加载中间场景的时候,重新设置汽车在下一个场景中的数据
    /// </summary>
    public void StopCarFlyInMidscene ()
    {
        //在过渡场景时,如果是飞行模式,则将其设置为false
        if (isFly) {
            StopAllCoroutines ();
            StopCoroutine ("RaiseUp");
            StopCoroutine ("Wait");
            FlyDone ();
        }
        //在过渡场景时,如果有堵住物,将其删除
        GameObject.FindGameObjectWithTag ("StopEatCornCollider").GetComponent<StopEatCornCollider> ().SetActiveInMidscene ();
    }

    public void ResetCarVelocityInNextScene ()
    {
        //切换场景之后,重置汽车的各项速度值
        SetCarInitCongfig ();
        //每通过一个过渡场景时,要为汽车增加一个过渡场景值,设置全局变量用于记录通过过渡场景的次数,然后增加汽车的数值
        targetSpeed += changeSceneAddSpeed * CarConfig.GetInstance ().throughMidScenetimes;
        CarConfig.GetInstance ().changeSceneAddVelocity = targetSpeed;
        BossConfig.GetInstant ().normalSpeed = targetSpeed;
    }

    /// <summary>
    /// 在中间过渡场景,选择下一个场景的Boss
    /// </summary>
    public void ChangeBossAccordingToNextLevel (bool isTrack)
    {
        if (isTrack == false) {
            switch (TempValue.GetInstance ().curLandType) {
            case (int)Land_type.Dusk_land:
                DestroySunBoss ();
                break;
            case (int)Land_type.Night_land:
                DestroyNightFrost ();
                break;
            case (int)Land_type.Ground_land:
                DestoryGroundPig ();
                break;
            case (int)Land_type.Rain_land:
                DestroyRainClouds ();
                break;
            }
        } else if (isTrack == true) {
            switch (TempValue.GetInstance ().curLandType) {
            case (int)Land_type.Dusk_land:
                LoadSunBoss ();
                break;
            case (int)Land_type.Night_land:
                LoadNightFrostBoss ();
                break;
            case (int)Land_type.Ground_land:
                LoadGroundPigBoss ();
                break;
            case (int)Land_type.Rain_land:
                LoadRainCloudsBoss ();
                break;
            }
        }
    }

    void DestroySunBoss ()
    {
        GameObject sunBoss = GameObject.FindGameObjectWithTag ("SunBoss");
        SunBoss sun = sunBoss.GetComponent<SunBoss> ();
        BossConfig.GetInstant ().changePosition = sun.transform.position.x;
        sun.DestroySelf ();
    }

    void DestroyNightFrost ()
    {
        GameObject nightBoss = GameObject.FindGameObjectWithTag ("NightFrost");    
        NightFrost frost = nightBoss.GetComponent<NightFrost> ();
        BossConfig.GetInstant ().changePosition = frost.transform.position.x;
        frost.DestroySelf ();
    }

    void DestoryGroundPig ()
    {
        GameObject groundBoss = GameObject.FindGameObjectWithTag ("GroundPig");    
        GroundPig pig = groundBoss.GetComponent<GroundPig> ();
        BossConfig.GetInstant ().changePosition = pig.transform.position.x;
        pig.DestroySelf ();
    }

    void DestroyRainClouds ()
    {
        GameObject rainBoss = GameObject.FindGameObjectWithTag ("RainClouds");    
        RainClouds rain = rainBoss.GetComponent<RainClouds> ();
        BossConfig.GetInstant ().changePosition = rain.transform.position.x;
        rain.DestroySelf ();
    }

    void LoadSunBoss ()
    {
        SetCarLight ((int)Land_type.Dusk_land);
//                GameObject sunBoss = Instantiate (ResManager.LoadObject (AllPrefabsInfo.SunBoss)) as GameObject;
        GameObject tempSunBoss = GameObject.FindGameObjectWithTag ("SunBoss");
        SunBoss sun;
        if (tempSunBoss) {
            sun = tempSunBoss.GetComponent<SunBoss> ();
            sun.enabled = true;
        } else {
            GameObject sunBoss = GameObject.Instantiate (ResourcesUpdate.GetInstance ().bundle.Load (AllPrefabsInfo.SunBoss, typeof(GameObject))) as GameObject;
            sun = sunBoss.GetComponent<SunBoss> ();
        }
        sun.transform.position = new Vector3 (BossConfig.GetInstant ().changePosition, sun.transform.position.y, sun.transform.position.z);
        sun.SetBossTrackCarStatus (true);
    }

    void LoadNightFrostBoss ()
    {
        SetCarLight ((int)Land_type.Night_land);
//                GameObject nightBoss = Instantiate (ResManager.LoadObject (AllPrefabsInfo.NightFrost)) as GameObject;
        GameObject tempNightFrost = GameObject.FindGameObjectWithTag ("NightFrost");
        NightFrost frost;
        if (tempNightFrost) {
            frost = tempNightFrost.GetComponent<NightFrost> ();
            frost.enabled = true;
        } else {
            GameObject nightBoss = GameObject.Instantiate (ResourcesUpdate.GetInstance ().bundle.Load (AllPrefabsInfo.NightFrost, typeof(GameObject))) as GameObject;
            frost = nightBoss.GetComponent<NightFrost> ();
        }
        frost.transform.position = new Vector3 (BossConfig.GetInstant ().changePosition, frost.transform.position.y, frost.transform.position.z);
        frost.SetBossTrackCarStatus (true);
    }

    void LoadGroundPigBoss ()
    {
        SetCarLight ((int)Land_type.Ground_land);
//                GameObject groundBoss = Instantiate (ResManager.LoadObject (AllPrefabsInfo.GroundPig)) as GameObject;
        GameObject tempGroundPig = GameObject.FindGameObjectWithTag ("GroundPig");
        GroundPig pigg;
        if (tempGroundPig) {
            pigg = tempGroundPig.GetComponent<GroundPig> ();
            pigg.enabled = true;
        } else {
            GameObject groundBoss = GameObject.Instantiate (ResourcesUpdate.GetInstance ().bundle.Load (AllPrefabsInfo.GroundPig, typeof(GameObject))) as GameObject;
            pigg = groundBoss.GetComponent<GroundPig> ();
        }
        pigg.isFire = true;
        pigg.gameObject.transform.position = new Vector3 (BossConfig.GetInstant ().changePosition, pigg.transform.position.y, pigg.transform.position.z);
        pigg.SetBossTrackCarStatus (true);
    }

    void LoadRainCloudsBoss ()
    {
        SetCarLight ((int)Land_type.Rain_land);
//                GameObject rainBoss = Instantiate (ResManager.LoadObject (AllPrefabsInfo.RainClouds)) as GameObject;
        GameObject tempRainBoss = GameObject.FindGameObjectWithTag ("RainClouds");
        RainClouds rain;
        if (tempRainBoss) {
            rain = tempRainBoss.GetComponent<RainClouds> ();
            rain.enabled = true;
        } else {
            GameObject rainBoss = GameObject.Instantiate (ResourcesUpdate.GetInstance ().bundle.Load (AllPrefabsInfo.RainClouds, typeof(GameObject))) as GameObject;
            rain = rainBoss.GetComponent<RainClouds> ();
        }
        rain.isLighting = true;
        rain.transform.position = new Vector3 (BossConfig.GetInstant ().changePosition, rain.transform.position.y, rain.transform.position.z);
        rain.SetBossTrackCarStatus (true);
    }
    //1、判断挂在车头灯挂件 只在夜晚场景显示
    public void SetCarLight (int temp)
    {
        if ((temp == (int)Land_type.Night_land) && GameBuff.GetInstance ().CarLight_status) {
            carLight.SetActive (true);
        } else {
            carLight.SetActive (false);
        }
    }

    void DontHitMidMonster (bool flag)
    {
        carBody.gameObject.GetComponent<BoxCollider2D> ().enabled = flag;
    }

    public void HitMiddleMonsterCarStopTime (float stopSpeed, bool isfixedAngle)
    {
        if (isfixedAngle == true) {
            curSpeed = stopSpeed;
            targetSpeed = stopSpeed;
            myRigid2D.fixedAngle = isfixedAngle;
        } else if (isfixedAngle == false) {
            if (stopSpeed == 0) {
                stopSpeed = 4f + CarConfig.GetInstance ().throughMidScenetimes;
            }
            curSpeed = stopSpeed;
            targetSpeed = stopSpeed;
            myRigid2D.fixedAngle = isfixedAngle;
        }

    }

    public Vector2 GetDriverIconPosition (string driverIcon)
    {
        Vector2 vec = new Vector2 ();
        switch (driverIcon) {
        case "Car1":
            vec = new Vector2 (-0.1696444f, 0.1921324f);
            break;
        case "Car2":
            vec = new Vector2 (-0.2980517f, 0.5773843f);
            break;
        case "Car3":
            vec = new Vector2 (-0.03133809f, 0.3106723f);
            break;
        case "Car4":
            vec = new Vector2 (-0.4201125f, 0.41f);
            break;
        case "Car5":
            vec = new Vector2 (-0.57f, 0.37f);
            break;
        case "Car6":
            vec = new Vector2 (-0.9651286f, 0.2909725f);
            break;
        case "Car7":
            vec = new Vector2 (-0.5008478f, 0.4391445f);
            break;
        case "Car8":
            vec = new Vector2 (-0.07608307f, 0.53f);
            break;
        case "Car9":
            vec = new Vector2 (-0.6490132f, 0.5280491f);
            break;
        case "Car10":
            vec = new Vector2 (-0.3427967f, 0.3897544f);
            break;
        case "Car11":
            vec = new Vector2 (-0.4218289f, 0.3897544f);
            break;
        }
        return vec;
    }

    /// <summary>
    /// 汽车在等待复活时候的配置
    /// </summary>
    public void NewCarJustRelifeConfig ()
    {
        SetCarSkin ();
        SetCarLight (TempValue.GetInstance ().curLandType);
        superPosition.SetActive (true);
        DontHitMidMonster (false);
        if (!CarConfig.GetInstance ().isAccFull) {
            CarConfig.GetInstance ().isAccFly = false;
        }
        isCliff = true;
        myRigid2D.fixedAngle = true;
        CarConfig.GetInstance ().isStopJump = false;
        CarConfig.GetInstance ().isLifeStopJump = false;
        forntWheelHitSmallMonster.enabled = false;
        backWheelHitSmallMonster.enabled = false;
    }

    /// <summary>
    /// 复活后等待几秒后的配置
    /// </summary>
    public void NewCarAfterWaitForSecondsConfig ()
    {
        myRigid2D.fixedAngle = false; 
        if (!CarConfig.GetInstance ().isAccFull) {
            CarConfig.GetInstance ().isAccFly = true;
        }
        CarConfig.GetInstance ().isLifeStopJump = false;
        DontHitMidMonster (true);
        forntWheelHitSmallMonster.enabled = true;
        backWheelHitSmallMonster.enabled = true;
        //停留规定秒数后,汽车开始运动
        isCliff = false;
        superPosition.SetActive (false);
    }

}





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{ 1,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 ()
    {

        SumWeight = 0;
        WeightList = new List<int> ();
        TimesList = new List<int> ();

        tempNewLandEntity = NewLandParseXML.GetLand (NewLandParseXML.index);
        GLogger.LogError ("====================================================================NewLandParseXML.index: " + 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);
        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;
    private bool isChangeScene = false;
    int midSceneDistance = 3000;
    int currentLeftLand = 0;
    int currentElementLeftLand = 0;

    void Update ()
    {
    
        curDistance = UserInfos.GetInstance ().distance;

        bool result = false;
        if (result) {

        } else {


            //加载路面
            if (curDistance >= (lastLandPositionX - 20) && !isLoadNextLand) {
                if (carIsDead) {
                    startLandIndex += 10;
                    LoadLand (startLandIndex);
                    carIsDead = false;
                } else {

                    if (startLandIndex <= LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count) {
//                        GLogger.LogError ("===================================================== 路面总长 " + LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count);
                        currentLeftLand = LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count - endLandIndex;
//                        GLogger.LogError ("======================================================================剩余路面 " + (currentLeftLand));
                        if (currentLeftLand >= 12) {
                            startLandIndex += 12;
                        } else {
                            startLandIndex += currentLeftLand;
                        }
                        LoadLand (startLandIndex);
                    }
                }
                isLoadNextLand = true;
                CheckIsRandomNextLand ();
            } else if ((curDistance < (lastLandPositionX - 20)) && isLoadNextLand == true) {
                isLoadNextLand = false;
            }
                
            //加载路面元素
            if (curDistance > (lastElementPositionX - 10) && !isLoadNextElement) {
                if (carIsDead) {
                    startElementIndex += 10;
                    LoadLandElements (startElementIndex);
                    carIsDead = false;
                } else {

                    if (startElementIndex <= LandConfigParseXML.GetLandElement (GetLevelSplitName ()).Count) {

                        GLogger.LogError ("===================================================== 路面元素总长 " + LandConfigParseXML.GetLandElement (GetLevelSplitName ()).Count);
                        currentElementLeftLand = LandConfigParseXML.GetLandElement (GetLevelSplitName ()).Count - endElementIndex;
                        GLogger.LogError ("======================================================================剩余路面元素 " + (currentElementLeftLand));
                        if (currentElementLeftLand > 10) {
                            startElementIndex += 10;
                        } else {
                            startElementIndex += currentElementLeftLand;
                        }
                        LoadLandElements (startElementIndex);
                    }
                }
                isLoadNextElement = true;
                if (IsLastElement ()) {
                    finalElementPosition = lastElementPositionX;
                    startElementIndex = 0;
                    endElementIndex = 0;
                    startElementCount = 0;
                    GLogger.LogError ("FUCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCK");
                }
            } else if (curDistance < (lastElementPositionX - 10) && isLoadNextElement == true) {
                isLoadNextElement = false;
            }
                
        }

//        if (isChangeBg) {
//            ChangeBgTexture ();
//        }

    }

    void CheckIsRandomNextLand ()
    {
        if (IsLastLand ()) {
            float temp = lastLandPositionX / 0.382f;
//            GLogger.LogError ("********************************************************lastLandPositionX  temp: " + temp);
            if (temp > 500 && temp <= 3000) {
                NewLandParseXML.index = 1;
            } else if (temp > 3000 && temp <= 6000) {
                NewLandParseXML.index = 2;
            } else if (temp > 6000 && temp <= 9000) {
                NewLandParseXML.index = 3;
            } else if (temp > 9000 && temp <= 12000) {
                NewLandParseXML.index = 4;
            }


            //2、判断是否需要加载中间场景
            if (temp > midSceneDistance) {
                //添加中间场景
                NewMidScene ();
            } else {

                tempLandPosition = lastLandPositionX;
                
                startLandCount = 0;
                startLandIndex = 0;
                endLandIndex = 0;
                InitCurParm ();
                isLoadNextLand = false;
                GLogger.LogError ("mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm " + GetLevelSplitName ());
            }
        }
    }

    bool IsLastLand ()
    {

        if (LandConfigParseXML.GetLandList (GetLevelSplitName ()).Count == endLandIndex) {
            return true;
        } else {
            return false;
        }

    }

    bool IsLastElement ()
    {

        if (LandConfigParseXML.GetLandElement (GetLevelSplitName ()).Count == endElementIndex) {
            return true;
        } else {
            return false;
        }

    }

    bool NewMidScene ()
    {

        addedMidSceneNum++;
        isChangeBg = true;

        ResetCarInMidScene ();

        int midIndex = 7;
        int midElementIndex = Random.Range (1, 6);
//        GLogger.LogError ("=======================================================================MISSCENEMISSCENEMISSCENEMISSCENEMISSCENEMISSCENEMISSCENE");
        GameObject ob = null;
        string midName = midIndex + "_" + midElementIndex;
        for (int i = 0; i < LandConfigParseXML.GetLandList (midName).Count; i++) {
            RandomLand land = new RandomLand ();
            land = LandConfigParseXML.GetLandList (midName) [i];

            switch (land.type) {
            case (int)ObjectType.Land:
                x = (land.x - XOffset) / rate - 0 + lastLandPositionX;
                y = -land.y / rate + 1.07f;
                string resourceName = land.resource;
                ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem (resourceName));
                ob.transform.localPosition = new Vector3 (x, y, 5);
                break;
            }

        }

        GameObject elementOb = null;
        for (int i = 0; i < LandConfigParseXML.GetLandElement (midName).Count; i++) {
            RandomlandElement landElement = new RandomlandElement ();
            landElement = LandConfigParseXML.GetLandElement (midName) [i];

            switch (landElement.type) {
            case (int)ObjectType.Corn:
                x = (landElement.x - XOffset) / rate - 8 + lastLandPositionX;
                y = -landElement.y / rate + YOffset;
                elementOb = Instantiate (ResManager.Load ("Prefab/Monster/Corn/CommomCorn/" + landElement.resource)) as GameObject;
                elementOb.transform.parent = road_Parent.transform;
                elementOb.transform.localPosition = new Vector3 (x, y + 3.4f, 5);
                break;

            case (int)ObjectType.GravityCorn:
                x = (landElement.x - XOffset) / rate - 8 + lastLandPositionX;
                y = -landElement.y / rate + YOffset;
                elementOb = Instantiate (ResManager.Load ("Prefab/Monster/Corn/GravityCorn/" + landElement.resource)) as GameObject;
                elementOb.transform.parent = road_Parent.transform;
                elementOb.transform.localPosition = new Vector3 (x, y + 3.4f, 5);
                break;

            case (int)ObjectType.Randomevent:
                x = (landElement.x - XOffset) / rate - 8 + lastLandPositionX;
                y = -landElement.y / rate + YOffset;

                elementOb = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
                string str = RandomEventInGame.GetInstance ().GetRandomValue ();
                elementOb.GetComponent<AwardPropInGame> ().SetPropAttribute (str);
                elementOb.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
                break;

            case (int)ObjectType.Event:
                x = (landElement.x - XOffset) / rate - 8 + lastLandPositionX;
                y = -landElement.y / rate + YOffset;
                elementOb = NGUITools.AddToChild (propInGame, ItemPool.GetInstance ().GetItem ("ExtraProp"));
                elementOb.GetComponent<AwardPropInGame> ().SetPropAttribute (landElement.resource);
                elementOb.transform.localPosition = new Vector3 (x, y + ExtraPropYOffset, 10);
                break;

            }
        }


        SetRandomBgIndex ();

        if (midSceneDistance >= 12000) {
            midSceneDistance += 2000;
        } else {
            midSceneDistance += 3000;
        }

        lastLandPositionX = ob.transform.localPosition.x;

        tempLandPosition = lastLandPositionX;
        startLandCount = 0;
        startLandIndex = 0;
        endLandIndex = 0;
        InitCurParm ();
        isLoadNextLand = false;

        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 = 1;

    int SetRandomBgIndex ()
    {
        int tempId = 0;
        if ((curDistance / 0.382f) > 12000) {
            int tempIndex = Random.Range (0, sceneRandomList.Count);
            tempId = (int)sceneRandomList [tempIndex];
            sceneRandomList.RemoveAt (tempIndex);
        } else {
            tempId = (int)sceneRandomList [sceneIndex];
            sceneIndex++;
            if (sceneIndex >= 4) {
                sceneIndex = 0;
            }
        }

        if (sceneRandomList.Count <= 0) {
            sceneRandomList.Add (1);
            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;
    float tempLandPosition = 0;

    void LoadLand (int landCount)
    {

        GameObject ob = null;
//        GLogger.LogError ("*******************************************landCount> " + landCount);
//        GLogger.LogError ("===================================================startLandCount> " + startLandCount);
        RandomLand land = new RandomLand ();
        for (int i = startLandCount; i < landCount; 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 + tempLandPosition;

                y = -land.y / rate + YOffset;
                string resourceName = land.resource;

                switch (TempValue.GetInstance ().curLandType) {
                case (int)Land_type.Dusk_land:

                    ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem (resourceName));

                    break;
                case (int)Land_type.Ground_land:

                    switch (resourceName) {
                    case "Dusk_land_End_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_End_1"));
                        break;
                    case "Dusk_land_End_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_End_2"));
                        break;
                    case "Dusk_land_Mid_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Mid_1"));
                        break;
                    case "Dusk_land_Mid_1_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Mid_1_2"));
                        break;
                    case "Dusk_land_Mid_1_3":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Mid_1_3"));
                        break;
                    case "Dusk_land_Mid_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Mid_2"));
                        break;
                    case "Dusk_land_Mid_2_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Mid_2_2"));
                        break;
                    case "Dusk_land_Mid_2_3":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Mid_2_3"));
                        break;
                    case "Dusk_land_Start_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Start_1"));
                        break;
                    case "Dusk_land_Start_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Ground_land_Start_2"));
                        break;
                    case "Cliff":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Cliff"));
                        break;
                    case "MinCliff":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("MinCliff"));
                        break;
                    }


                    break;
                case (int)Land_type.Night_land:

                    switch (resourceName) {
                    case "Dusk_land_End_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_End_1"));
                        break;
                    case "Dusk_land_End_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_End_2"));
                        break;
                    case "Dusk_land_Mid_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Mid_1"));
                        break;
                    case "Dusk_land_Mid_1_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Mid_1_2"));
                        break;
                    case "Dusk_land_Mid_1_3":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Mid_1_3"));
                        break;
                    case "Dusk_land_Mid_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Mid_2"));
                        break;
                    case "Dusk_land_Mid_2_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Mid_2_2"));
                        break;
                    case "Dusk_land_Mid_2_3":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Mid_2_3"));
                        break;
                    case "Dusk_land_Start_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Start_1"));
                        break;
                    case "Dusk_land_Start_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Night_land_Start_2"));
                        break;
                    case "Cliff":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Cliff"));
                        break;
                    case "MinCliff":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("MinCliff"));
                        break;
                    }

                    break;
                case (int)Land_type.Rain_land:

                    switch (resourceName) {
                    case "Dusk_land_End_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_End_1"));
                        break;
                    case "Dusk_land_End_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_End_2"));
                        break;
                    case "Dusk_land_Mid_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Mid_1"));
                        break;
                    case "Dusk_land_Mid_1_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Mid_1_2"));
                        break;
                    case "Dusk_land_Mid_1_3":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Mid_1_3"));
                        break;
                    case "Dusk_land_Mid_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Mid_2"));
                        break;
                    case "Dusk_land_Mid_2_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Mid_2_2"));
                        break;
                    case "Dusk_land_Mid_2_3":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Mid_2_3"));
                        break;
                    case "Dusk_land_Start_1":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Start_1"));
                        break;
                    case "Dusk_land_Start_2":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Rain_land_Start_2"));
                        break;
                    case "Cliff":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("Cliff"));
                        break;
                    case "MinCliff":
                        ob = NGUITools.AddToChild (road_Parent, ItemPool.GetInstance ().GetItem ("MinCliff"));
                        break;
                    }

                    break;
                }



                if (resourceName == "MinCliff" || resourceName == "Cliff") {
                    ob.GetComponent<SpriteRenderer> ().enabled = false;
                }
                ob.transform.localPosition = new Vector3 (x, y, 5);

                endLandIndex = i + 1;
                break;
            }
        }
        startLandCount = landCount;
    
//        GLogger.LogError ("============================ob.transform.position.x= " + ob.transform.localPosition.x + "==== " + endLandIndex);
        lastLandPositionX = ob.transform.localPosition.x;




    }

    int endElementIndex = 0;
    int startElementCount = 0;
    float finalElementPosition = 0;

    void LoadLandElements (int landElementCount)
    {

        GLogger.LogError (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>landElementCount> " + landElementCount);
        GLogger.LogError (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>startElementCountstartElementCount > " + startElementCount);
        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 + finalElementPosition;
//                x = (landElement.x - XOffset) / rate - xOffsetPosition + lastLandPositionX;
                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 + finalElementPosition;
                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 + finalElementPosition;
                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 + finalElementPosition;
                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 + finalElementPosition;
                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 + 1;
        }
        startElementCount = landElementCount;
        lastElementPositionX = ob.transform.localPosition.x;
    }
}




using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

public class RoadRandom : MonoBehaviour
{
    private float StartLandLength;
    private float MidLandLength;
    private float EndLandLength;
    public List<GameObject> CornList = new List<GameObject> ();
    //    private GameObject obj;
    private Transform obj;
    private int CurDistance;
    private int RandomDistance = 20;
//30
    //随机一段路的路长度
    private int RemainDistance = 15;
//20
    //触发生成随机路段点
    private int SumWeight;
    private List<int> WeightList;
    private List<int> TimesList;
    private int MinCliffIndex = 3;
    private float alreadyDis = 0;
    //记录每一次随机的路段的长度,随机完之后清零,下一次继续记录
    private float offsetX = 0.04f;
//二级路面的偏移量,由于路面的大小不一致,需要手动添加一个偏移量
    private float XOffset = 0.04f;
//一级路面的偏移量,由于路面的大小不一致,需要手动添加一个偏移量
    //从加载一直到结束的计数
    private int roadType;
    //随机的路段类型 1,2,3,4,5,6
    private int randomNum;
    bool isCliff = false;
    // Cliff 悬崖
    private int StartRandomRoad = 3000;
    //开始第一次要随机的路段点,在100米处开始随机路面  加上中间过渡路面 136
    private int LastRoadType = 0;
    //2级路面
    private float Land2Height = 3.05f;
    //2.1
    //开始随机路段的前的游戏距离,以3000为标准
    private float RandomRoadLength = 1146;
    //3006.5f //1146表示换算成游戏引擎里面的距离,来判断是否加载路面
    //随机路段总长度
    private bool isRandom = false;
    //路段的Y轴偏移量
    private float YOffset = -2.1f;
    private float MonsterYOffset = 0f;
    private List<MonsterEntity> RandomMonsterList;
    private List<List<int>> monsterWeightList;
    private List<int> MonsterSumList;
    private float LandHalfHeight = 0f;
    //    private GameObject end_2;
    //中间过渡场景路面高度
    private float MidSceneHeight = 4.72f;
    private ArrayList sceneRandomList;
    //已经添加的中间场景的数量
    private int addedMidSceneNum = 0;
    //是否改变背景
    private bool isChangeBg = false;
    //添加中间场景的距离倍数
    //    private float addMidSceneDisTimes = 3000;
    private float addMidSceneDisTimes = 1146;
    //此倍数是引擎里面的距离
    private float startFirstRandomRoadPoint = 1134.54f;
    //父级路面
    public GameObject parentRoad;
    public GameObject monstersParent;
    float scale;
    private BtcAcc btnAcc;
    private StopBoss btnStopBoss;
    //路的z轴
    private int roadDepth = 50;
    // 1134.54f = 2970*0.382f
    private string[] propName = new string[] {
        "doubleCorn",
        "carFly200",
        "carFly500",
        "carFly700",
        "corn200",
        "corn350",
        "corn650",
        "diamond",
        "stopBoss"
    };

    public GameObject propInGame;


    void Awake ()
    {
        Init ();
    }

    void Init ()
    {
        GetCommponent getComponent = GetComponent<GetCommponent> ();
        parentRoad = getComponent.defaultGameObject [0];
        monstersParent = getComponent.defaultGameObject [1];
        propInGame = getComponent.defaultGameObject [2];
        for (int i = 0; i < 3; i++) {
//            CornList.Add (ResManager.Load("Prefab/Monster/CornsHeap/CornHeap_" + (i+1)));
            CornList.Add (ResourcesUpdate.GetInstance ().bundle.Load (string.Format ("{0}{1}", "CornHeap_", (i + 1)), typeof(GameObject))as GameObject);
        }

    }

    void Start ()
    {
//        float x = 0;
//        float y = 0;
//
//        for(int i=0;i<RandomLandParseXML.landList.Count;i++){
//            x = (RandomLandParseXML.GetLand(i).x - 0)/100f ;
//            y = (RandomLandParseXML.GetLand(i).y - 0)/100f;
//
//            GameObject ob = Instantiate (ResManager.Load ("Prefab/Land/1/" + RandomLandParseXML.GetLand(i).resource)) as GameObject;
//            ob.transform.parent = Camera.main.transform;
//            ob.transform.localPosition = new Vector3 (x,y,5);
//
//        }


        sceneRandomList = new ArrayList{ 2, 3, 4 };//随机场景的序号
        //        RandomMonsterList = MonsterParseXML.monsterDict [LandParseXML.landList [LandParseXML.index].Id];
        //        RandomMonsterList = MonsterParseXML.GetMonsterListById(LandParseXML.landList [LandParseXML.index].Id);
        RandomMonsterList = MonsterParseXML.GetMonsterListById (LandParseXML.GetLand (LandParseXML.index).Id);
//        bgimageload = gameObject.GetComponent<LoadBgImage> ();
        TempValue.GetInstance ().curLandType = (int)Land_type.Dusk_land;
        LandParseXML.index = 0;
        InitLandLength ();
        //玩家行驶距离
        InitCurParm ();
        InitCurMonster ();

        btnAcc = GameObject.FindGameObjectWithTag ("BtnAcc").GetComponent<BtcAcc> ();
        btnStopBoss = GameObject.FindGameObjectWithTag ("StopBoss").GetComponent<StopBoss> ();
        //第一次加载怪物
//        Monsters_Temp = Monsters_Dusk;
    }

    void InitCurParm ()
    {
        WeightList = new List<int> ();
        TimesList = new List<int> ();
        //LandParseXML.GetLand(LandParseXML.index).Id
        //        LandEntity temp = LandParseXML.landList [LandParseXML.index];
        LandEntity temp = LandParseXML.GetLand (LandParseXML.index);

        TimesList.Add (temp.times1);
        TimesList.Add (temp.times2);
        TimesList.Add (temp.times3);
        TimesList.Add (temp.times4);
        TimesList.Add (temp.times5);
        TimesList.Add (temp.times6);

        WeightList.Add (SumWeight += temp.weight1);
        WeightList.Add (SumWeight += temp.weight2);
        WeightList.Add (SumWeight += temp.weight3);
        WeightList.Add (SumWeight += temp.weight4);
        WeightList.Add (SumWeight += temp.weight5);
        WeightList.Add (SumWeight += temp.weight6);

    }

    void InitCurMonster ()
    {
        monsterWeightList = new List<List<int>> ();
        List<int> singleWeightList;
        MonsterSumList = new List<int> ();
        MonsterEntity temp;
        int flag;
        int count = RandomMonsterList.Count;
        for (int i = 0; i < count; i++) {
            flag = 0;
            singleWeightList = new List<int> ();
            temp = RandomMonsterList [i];
            singleWeightList.Add (flag += temp.SunFlower);
            singleWeightList.Add (flag += temp.Stone);
            singleWeightList.Add (flag += temp.ShutUp);
            singleWeightList.Add (flag += temp.CornHeap);
            singleWeightList.Add (flag += temp.Empty);
            MonsterSumList.Add (flag);
            monsterWeightList.Add (singleWeightList);
        }
    }









    void Update ()
    {
        //*2.6178f 显示玩家距离的系数(玩家距离并非游戏引擎距离)
//        CurDistance = (int)(UserInfos.GetInstance ().distance * 2.6178f);//现在是从0开始,记录车子跑的距离
        CurDistance = UserInfos.GetInstance ().finialDistance;//现在是从0开始,记录车子跑的当前距离
        if (RandomRoadLength > startFirstRandomRoadPoint) {//100是相当于3000米时,判断开始加载随机路面
            //如果随机的路长和当前车子跑的距离小于14米(引擎距离)时,随机下一段路,随机下一段路的路长为30米(引擎距离)




            if (RandomRoadLength - CurDistance * 0.382f < RemainDistance) {
                RandomSingleLand ();
            }
        } else if (CurDistance > StartRandomRoad - RemainDistance) {//StartRandomRoad -  RandomDis 等到汽车行驶到一个点,然后触发随机路面
            RandomSingleLand ();
        }





            
        if (isChangeBg) {
            ChangeBgTexture ();
        }
    }
        
    void RandomSingleLand ()
    {
        if (isRandom) {
            return;
        }
        isRandom = true;
        //添加过渡场景
        bool result = NewMidScene (RandomRoadLength);

        //设置路的类型
//        if (result) {
//            SetCurSceneLand (TempValue.GetInstance ().curLandType);
//        }
        //LandParseXML.GetLand(LandParseXML.index).Id
        //        LandEntity le = LandParseXML.landList [LandParseXML.index];
        LandEntity le = LandParseXML.GetLand (LandParseXML.index);
        //开始随机
        int count = WeightList.Count;
        int times = 0;
        int i = 0;
        //现在默认随机 RandomDistance = 30米
        while (alreadyDis <= RandomDistance) { //玩家的距离减去开始的3000米之后,行驶的距离和已经创建路的2/3处对比,判断是否创建下一级路面 
            randomNum = (int)(Random.value * SumWeight);//随机一个权重值
            for (i = 0; i < count; i++) {
                if (WeightList [i] > randomNum) {//和配置表中的权重对比
                    if (isCliff) {
                        roadType = (int)(Random.value * MinCliffIndex) + 1;
                        isCliff = false;
                    } else {
                        roadType = i + 1;//
                        isCliff = (roadType >= MinCliffIndex);//判断是否为悬崖
                    }
                    //创建路段
                    times = TimesList [roadType - 1];
                    if (result) {//在添加过渡场景之后,默认把下一个场景的初始路面设置为1级路面
                        result = false;
                        roadType = 1;
                    }
                    createRoad (roadType, times);
                    LastRoadType = roadType > 3 ? 0 : roadType;
                    break;
                }
            }
        }
        RandomRoadLength += alreadyDis;
        alreadyDis = 0;

        if ((CurDistance + RandomDistance) > le.MINDIS) {
            LandParseXML.index++;
            RandomMonsterList = MonsterParseXML.GetMonsterListById (LandParseXML.GetLand (LandParseXML.index).Id);
            InitCurParm ();
        }
        isRandom = false;
    }

    bool NewMidScene (float length)
    {
        int temp = (int)(length / addMidSceneDisTimes);
        if (temp <= addedMidSceneNum) {
            return false;
        }
        //切换场景前添加悬崖
        if (LastRoadType <= (int)LANDTYPE.THIRD) {
            createRoad ((int)LANDTYPE.FOURTH, 1);
            RandomRoadLength += alreadyDis;
            alreadyDis = 0;
            LastRoadType = (int)LANDTYPE.FOURTH;
        }
//        float tempPos = length/2.6178f;
        float tempPos = length;
        //36.5中间场景的长度的一半
        GameObject ob1 = NGUITools.AddToChild (parentRoad, ItemPool.GetInstance ().GetItem ("MidScene"));
        ob1.transform.localPosition = new Vector3 (tempPos + 36.5f, MidSceneHeight, 7f);
        float scale = ItemPool.GetInstance ().GetScale ("MidScene");
        ob1.transform.localScale = new Vector3 (scale, scale, 1);

        addedMidSceneNum++;
        ResetCarInMidScene ();
        //72.5f 中间场景的总长度
        RandomRoadLength += 72.5f;
        isChangeBg = true;
        SetRandomBgIndex ();
        createRoad ((int)LANDTYPE.FOURTH, 1);
        RandomRoadLength += alreadyDis;
        alreadyDis = 0;
        LastRoadType = (int)LANDTYPE.FOURTH;
        return true;
    }

    /// <summary>
    /// 0、暂停前一个场景的Boss
    /// 1、判断跑过中间场景的次数
    /// 2、在中间场景重新设置汽车配置
    /// 3、在中间场景,不再积蓄飞行模式
    /// </summary>
    void ResetCarInMidScene ()
    {
        TempValue.GetInstance ().isPlayBackgroundAnim = false;
        //暂停前一个场景的Boss
        GameObject.FindGameObjectWithTag ("Player").GetComponent<CarControlor> ().ChangeBossAccordingToNextLevel (false);
        CarConfig.GetInstance ().throughMidScenetimes++;//统计路过中间场景的次数
//        GameObject.FindGameObjectWithTag ("Player").GetComponent<CarControlor> ().ResetCarVelocityInMidScene ();//以前是用碰撞检测来实现,现在改为加载中间场景时设置
//        btnAcc.enabled = false;
//        btnStopBoss.stopBossIsEnable = false;
//        btnStopBoss.HideStopBossBtn ();//暂时保留,在过渡场景判断
    }

    /// <summary>
    /// 改变游戏背景Texture Update
    /// </summary>
    void ChangeBgTexture ()
    {
        int temp = (int)((UserInfos.GetInstance ().distance) / (addMidSceneDisTimes + 18));
        if (addedMidSceneNum <= 0 || temp <= addedMidSceneNum - 1) {
            return;
        }
//        ChangeRandomBg ();
        isChangeBg = false;
    }

    void createRoad (int roadType, int times)
    {
        //StartLand + MidLand + EndLand 根据游戏距离,切换场景类型、背景类型、路面类型
        //创建路面 
        switch (roadType) {
        case (int)LANDTYPE.FIRST:
            AddRoadLevel1 (times);
            break;
        case (int)LANDTYPE.SECOND:
            //加载2级路面
            AddRoadLevel2 (times);
            break;
        case (int)LANDTYPE.THIRD:
            //加载3级路面
            AddRoadLevel3 (times);
            break;
        case (int)LANDTYPE.FOURTH:
        case (int)LANDTYPE.FIFTH:
        case (int)LANDTYPE.SIXTH:
            //加载6级路面
            AddRoadLevel456 (times);
            break;
        }
    }

    /// <summary>
    /// 添加一级路面
    /// </summary>EndYOffset
    /// <param name="times">Times.</param>
    void AddRoadLevel1 (int times)
    {
        switch (LastRoadType) {
        case 1:
            break;
        case 2:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, Land2Height + YOffset, roadDepth);
            alreadyDis += EndLandLength;

            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_1")).transform;  
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + XOffset, YOffset, roadDepth);
            alreadyDis += StartLandLength;

            break;
        case 3:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, Land2Height + YOffset, roadDepth);
            break;
        default :
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + XOffset, YOffset, roadDepth);
            alreadyDis += StartLandLength;

            break;
        }

        RandomMonster (times, MonsterYOffset);
        //添加路面RandomMonsterList = MonsterParseXML.monsterDict [LandParseXML.landList[LandParseXML.index ].Id];
        for (int i = 0; i < times; i++) {
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Mid_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, YOffset, roadDepth);
            obj.localRotation = Quaternion.identity;
            alreadyDis += MidLandLength;

        }
    }

    /// <summary>
    /// 添加二级路面
    /// </summary>
    /// <param name="roadType">Road type.</param>
    /// <param name="times">Times.</param>
    void AddRoadLevel2 (int times)
    {
        switch (LastRoadType) {
        case 1:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, YOffset, roadDepth);
            alreadyDis += EndLandLength;

            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offsetX, Land2Height + YOffset, roadDepth);

            alreadyDis += StartLandLength;

            break;
        case 2:
            break;
        case 3:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, YOffset, roadDepth);

            break;
        default :
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offsetX, Land2Height + YOffset, roadDepth);
            alreadyDis += StartLandLength;

            break;
        }

        RandomMonster2 (times, Land2Height + MonsterYOffset);
        for (int i = 0; i < times; i++) {
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Mid_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, Land2Height + YOffset, roadDepth);
            alreadyDis += MidLandLength;
        }
    }

    /// <summary>
    /// 添加三级路面
    /// </summary>
    /// <param name="roadType">Road type.</param>
    /// <param name="times">Times.</param>
    void AddRoadLevel3 (int times)
    {
        switch (LastRoadType) {
        case 1:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis - StartLandLength + offsetX, Land2Height + YOffset, roadDepth);
            break;
        case 2:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis - StartLandLength + XOffset, YOffset, roadDepth);

            break;
        case 3:
            break;
        default :
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offsetX, Land2Height + YOffset, roadDepth);
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Start_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + XOffset, YOffset, roadDepth);
            alreadyDis += StartLandLength;
            break;
        }

        RandomMonster (times, MonsterYOffset);
        RandomMonster2 (times, Land2Height + MonsterYOffset);
        for (int i = 0; i < times; i++) {
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Mid_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, YOffset, roadDepth);
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Mid_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, Land2Height + YOffset, roadDepth);
            alreadyDis += MidLandLength;
        }
    }

    /// <summary>
    /// 4\5\6添加悬崖
    /// </summary>
    /// <param name="roadType">Road type.</param>
    /// <param name="times">Times.</param>
    void AddRoadLevel456 (int times)
    {
        switch (LastRoadType) {
        case 1:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, YOffset, roadDepth);
            alreadyDis += EndLandLength;

            break;
        case 2:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, Land2Height + YOffset, roadDepth);
            alreadyDis += EndLandLength;

            break;
        case 3:
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_2")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, Land2Height + YOffset, roadDepth);
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "End_1")).transform;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, YOffset, roadDepth);
            alreadyDis += EndLandLength;
            break;
        default :
            break;
        }

        for (int i = 0; i < times; i++) {
            obj = NGUITools.AddToChild (parentRoad, SetCurSceneLand (TempValue.GetInstance ().curLandType, "Mid_1")).transform;
            obj.GetComponent<SpriteRenderer> ().enabled = false;
            obj.GetComponent<PolygonCollider2D> ().enabled = false;
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis, YOffset, roadDepth);
            alreadyDis += MidLandLength;

        }
    }

    /// <summary>
    /// 随机怪物
    /// </summary>
    /// <param name="times">Times.</param>
    /// <param name="Yoffset">Yoffset.</param>
    void RandomMonster (int times, float Yoffset)
    {
        List<float> refpoint = RandomMonsterList [times].RefreshPoint;
        float OnceLandLength = times * MidLandLength;
        if (refpoint.Count < 1) {
            return;
        }
        int SumMonsterWeight = MonsterSumList [times - 1];
        List<int> list = monsterWeightList [times - 1];
        int tempRefpointCount = refpoint.Count;
        int tempListCount = list.Count;
        for (int i = 0; i < tempRefpointCount; i++) {
            int Num = (int)(Random.value * SumMonsterWeight);//随机一个权重值
            for (int j = 0; j < tempListCount; j++) {
                if (list [j] > Num) {//和配置表中的权重对比
                    createMonster (OnceLandLength * refpoint [i], j, Yoffset + LandHalfHeight);
                    break;
                }
            }
        }
    }
    //创建怪物
    void createMonster (float offset, int type, float Yoffset)
    {
        switch (type) {
        case 0: //Sunflower
            switch (TempValue.GetInstance ().curLandType) {
            case 0:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("SunflowerRun")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.4f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("SunflowerRun");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 1:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Ground_Pumpkin")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.4f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Ground_Pumpkin");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 2:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Night_Cactus")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.4f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Night_Cactus");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 3:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Rain_Wind_Sway")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.4f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Rain_Wind_Sway");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            }
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 0.4f, 5), Quaternion.identity);
            break;
        case 1: //Stone
            switch (TempValue.GetInstance ().curLandType) {
            case 0:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Stone1")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Stone1");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 1:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Ground_Bone")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Ground_Bone");
                obj.localScale = new Vector3 (scale, scale, 1);
                obj.localRotation = Quaternion.identity;
                break;
            case 2:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Night_Grass")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Night_Grass");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 3:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Rain_Puddles_Wave")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Rain_Puddles_Wave");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            }
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, 5), Quaternion.identity);
            break;
        case 2: //Mouse
            switch (TempValue.GetInstance ().curLandType) {
            case 0:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("MouseRun")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("MouseRun");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 1:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Ground_Apple")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Ground_Apple");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 2:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Night_Duck")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Night_Duck");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 3:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Rain_Frog_Jump")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Rain_Frog_Jump");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            }
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, 5), Quaternion.identity);
            break;
        case 3: //CornHeap
            //设置玉米堆方法,返回一个玉米GameObject
//            Stopwatch st = new Stopwatch();
//            st.Start();
            GameObject objCornHeap = (GameObject)Instantiate (GetRandomCornHeapType (), new Vector3 (RandomRoadLength + alreadyDis + offset, 0.5f, roadDepth), Quaternion.identity);
//            st.Stop();
//            GLogger.LogWarning("=============================================================生成玉米堆时间" + st.ElapsedMilliseconds.ToString() );
            break;
        case 4: //Empty
//            obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Empty")).transform;
            GameObject prop = (GameObject)Instantiate (ResManager.Load ("Prefab/ExtraProp/ExtraProp"));
            obj = prop.transform;
//            string str = propName [Random.Range (0, propName.Length-1)];
            string name = RandomEventInGame.GetInstance ().GetRandomValue ();
            GLogger.LogWarning ("888888888888888888888888888888888888888888888888888888888888888 " + name);
            obj.GetComponent<AwardPropInGame> ().SetPropAttribute (name);
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2.2f, roadDepth);
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 0.3f, 5), Quaternion.identity);
            break;
        }
    }

    void RandomMonster2 (int times, float Yoffset)
    {
        List<float> refpoint = RandomMonsterList [times].RefreshPoint;
        float OnceLandLength = times * MidLandLength;
        if (refpoint.Count < 1) {
            return;
        }
        int SumMonsterWeight = MonsterSumList [times - 1];
        List<int> list = monsterWeightList [times - 1];
        int tempRefpointCount = refpoint.Count;
        int tempListCount = list.Count;
        for (int i = 0; i < tempRefpointCount; i++) {
            int Num = (int)(Random.value * SumMonsterWeight);//随机一个权重值
            for (int j = 0; j < tempListCount; j++) {
                if (list [j] > Num) {//和配置表中的权重对比
                    createMonster2 (OnceLandLength * refpoint [i], j, Yoffset + LandHalfHeight);
                    break;
                }
            }
        }
    }
    //创建怪物
    void createMonster2 (float offset, int type, float Yoffset)
    {
        switch (type) {
        case 0: //Sunflower
            switch (TempValue.GetInstance ().curLandType) {
            case 0:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("SunflowerRun")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("SunflowerRun");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 1:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Ground_Pumpkin")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Ground_Pumpkin");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 2:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Night_Cactus")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Night_Cactus");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 3:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Rain_Wind_Sway")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Rain_Wind_Sway");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            }
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, 5), Quaternion.identity);//0.84 0.9899795
            break;
        case 1: //Stone
            switch (TempValue.GetInstance ().curLandType) {
            case 0:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Stone1")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Stone1");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 1:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Ground_Bone")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Ground_Bone");
                obj.localScale = new Vector3 (scale, scale, 1);
                obj.localRotation = Quaternion.identity;
                break;
            case 2:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Night_Grass")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Night_Grass");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 3:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Rain_Puddles_Wave")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2.5f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Rain_Puddles_Wave");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            }
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 2.5f, 5), Quaternion.identity);//1.2
            break;
        case 2: //Mouse
            switch (TempValue.GetInstance ().curLandType) {
            case 0:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("MouseRun")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("MouseRun");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 1:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Ground_Apple")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Ground_Apple");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 2:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Night_Duck")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Night_Duck");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            case 3:
                obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Rain_Frog_Jump")).transform;
                obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, roadDepth);
                scale = ItemPool.GetInstance ().GetScale ("Rain_Frog_Jump");
                obj.localScale = new Vector3 (scale, scale, 1);
                break;
            }
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 2f, 5), Quaternion.identity);//0.669744f
            break;
        case 3: //CornHeap
            //设置玉米堆方法,返回一个玉米GameObject
//            Stopwatch st = new Stopwatch();
//            st.Start();
//            GameObject objCornHeap = (GameObject)Instantiate (GetRandomCornHeapType (), new Vector3 (RandomRoadLength + alreadyDis + offset, 2.2f, roadDepth), Quaternion.identity);
            GameObject objCornHeap = GetRandomCornHeapType ();
            objCornHeap.transform.position = new Vector3 (RandomRoadLength + alreadyDis + offset, 2.2f, roadDepth);
            objCornHeap.transform.rotation = Quaternion.identity;


//            st.Stop();
//            GLogger.LogWarning("=============================================================生成玉米堆时间" + st.ElapsedMilliseconds.ToString() );
            break;
        case 4: //Empty
//            obj = NGUITools.AddToChild (monstersParent, ItemPool.GetInstance ().GetItem ("Empty")).transform;
            GameObject prop = (GameObject)Instantiate (ResManager.Load ("Prefab/ExtraProp/ExtraProp"));
            obj = prop.transform;
//            string str = propName [Random.Range (0, propName.Length-1)];
            string name = RandomEventInGame.GetInstance ().GetRandomValue ();
            GLogger.LogWarning ("99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 " + name);
            obj.GetComponent<AwardPropInGame> ().SetPropAttribute (name);
            obj.localPosition = new Vector3 (RandomRoadLength + alreadyDis + offset, 2.5f, roadDepth);
//            obj = (GameObject)Instantiate (Monsters_Temp [type], new Vector3 (RandomRoadLength + alreadyDis + offset, 2.5f, 5), Quaternion.identity);
            break;
        }
    }

    GameObject GetRandomCornHeapType ()
    {
        GameObject corn;
        if (TempValue.GetInstance ().curLandType == (int)Land_type.Night_land) {
            corn = Instantiate (CornList [Random.Range (0, 3)]) as GameObject;
        } else {
            corn = Instantiate (CornList [Random.Range (0, 2)]) as GameObject;
        }
        return corn;
    }

    private string startLandName = null;
    private string LandFullName = null;

    GameObject SetCurSceneLand (int landType, string endLandName)
    {
        switch (landType) {
        case (int)Land_type.Dusk_land:
            startLandName = "Dusk_land_";
            break;
        case (int)Land_type.Ground_land:
            startLandName = "Ground_land_";
            break;
        case (int)Land_type.Night_land:
            startLandName = "Night_land_";
            break;
        case (int)Land_type.Rain_land:
            startLandName = "Rain_land_";
            break;
        }
        LandFullName = string.Format ("{0}{1}", startLandName, endLandName);
        return ItemPool.GetInstance ().GetItem (LandFullName);
    }

    void InitLandLength ()
    {
//        StartLandLength = start_1.GetComponent<Land> ().GetComponent<SpriteRenderer> ().bounds.size.x;
        StartLandLength = 0.25f;
//        MidLandLength = mid_1.GetComponent<Land> ().GetComponent<SpriteRenderer> ().bounds.size.x;
        MidLandLength = 2.27f;
//        EndLandLength = end_1.GetComponent<Land> ().GetComponent<SpriteRenderer> ().bounds.size.x;
        EndLandLength = 0.25f;
    }

    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;
            }
        }

//        int tempId = 3;
        if (sceneRandomList.Count <= 0) {
            sceneRandomList.Add (2);
            sceneRandomList.Add (3);
            sceneRandomList.Add (4);
        }

//        switch (tempId) {
//        case 1:
//            Monsters_Temp = Monsters_Dusk;
//            break;
//        case 2:
//            Monsters_Temp = Monsters_Night;
//            break;
//        case 3:
//            Monsters_Temp = Monsters_Ground;
//            break;
//        case 4:
//            Monsters_Temp = Monsters_Rain;
//            break;
//        }

        TempValue.GetInstance ().curLandType = tempId - 1;
        return tempId;
    }
}



using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Monsterconfig
{
    public string symbol;
    public string name;
    public string path;
    public float scale;
    public int num;
}

public class RoadMngr : MonoBehaviour
{
    public static bool isDebug = false;
//    private GameObject road_start_1, road_mid_1, road_end_1;
//    private GameObject road_start_2, road_mid_2, road_end_2;
    public GameObject road_Parent;
    public GameObject monster_Parent;
    private Vector3 road_1_startpos = new Vector3 (5, -2.1f, 10);
    private Vector3 road_2_startpos = new Vector3 (5, 0.95f, 10);
    public float length;
//    private List<Monsterconfig> monsterlist;

    public delegate void HandleFinishRoad ();

    public HandleFinishRoad finishInitCarHandler;
//    private float newLandTimes = 10;
    private string[] roads;
    private string[] secondRoads;
    private string[] items;
    private string[] secondItems;
//    private string[] newRoad = new string[10];
//    private string[] newItem = new string[10];
    private float width_start = 0.16f;
    private float width_part = 2.27f;
    private Vector3 pos;
    private Vector3 secondPos;
    private Vector3 lastpos;
    private Vector3 secondLastpos;
    private int lastIndex = 0;
    private bool isLoadDone = false;
    private string[] lines;
    private string FirstRoad;
    private string FirstMonster;
    private string SecondRoad;
    private string SecondMonster;
    private bool isLoadNextRoad = false;

    private char[] subSplit = new char[]{ ';' };
    private char[] subSplitAnotherLine = new char[]{ '\r' };

    void Awake(){
        Init();
    }

    void Init(){
        GetCommponent getComponent = GetComponent<GetCommponent> ();
        road_Parent = getComponent.defaultGameObject[0];
        monster_Parent = getComponent.defaultGameObject[1];
    }


    void Start ()
    {
        LoadRoadData ();
    }

    public void LoadRoadData ()
    {
        string path = GameUtils.GetAssetPath () + "/Road/RoadTable.csv";
        StartCoroutine (DownloadText.GetInstance ().DownLoad (path, GetStringRoad, false));
    }

    void GetStringRoad (string www, string str, bool flag)
    {
        lines = www.Split (subSplitAnotherLine);
        FirstRoad = lines [4];
        FirstMonster = lines [3];
        SecondRoad = lines [2];
        SecondMonster = lines [1];
//        CreatRoad (lines [4], lines [3], 1);//一级路面,怪物
//        CreatRoad (lines [2], lines [1], 2);//二级路面,怪物
        CreatRoad (FirstRoad, FirstMonster);//一级路面,怪物
        CreatSecondRoad (SecondRoad, SecondMonster);//二级路面,怪物
        isLoadDone = true;
    }

    void CreatRoad (string road, string item)
    {
        roads = road.Split (subSplit);//获得每一个路段的名字 535
        items = item.Split (subSplit);
    }

    void CreatSecondRoad (string road, string item)
    {
        secondRoads = road.Split (subSplit);
        secondItems = item.Split (subSplit);
    }

    void Update ()
    {
        if (isLoadDone) {
            if (TempValue.GetInstance ().curLandType == (int)Land_type.Dusk_land) {
                if (((int)UserInfos.GetInstance ().distance >= (int)(lastpos.x - 20)) && !isLoadNextRoad) {

                    int start = lastIndex;
                    int end = lastIndex + 18 < roads.Length ? lastIndex + 18 : roads.Length;
                    if (end > roads.Length) {
                        end = roads.Length;
                    }
                    lastIndex = lastIndex + 18;
                    CreateLoadedRoad (start, end, 1);
//                  CreateLoadedRoad (start, end, 2);
                    CreateSecondLoadedRoad (start, end, 2);
                    isLoadNextRoad = true;
                } else if (((int)UserInfos.GetInstance ().distance < (int)(lastpos.x - 20)) && isLoadNextRoad == true) {//有时候,没有执行这一步骤,所以没有加载到路面
                    isLoadNextRoad = false;
                }
            }
        }
    }

    void CreateLoadedRoad (int start, int end, int types)
    {
        pos = road_1_startpos;
        lastpos = road_1_startpos;
        switch (types) {
        case 1:
            width_start = 0.16f;
            pos = road_1_startpos;
            lastpos = road_1_startpos;
            break;
        case 2:
            width_start = 0.15f;
            pos = road_2_startpos;
            lastpos = road_2_startpos;
            break;
        }
        CreatSingleRoad (start, end, types);
    }

    void CreatSingleRoad (int start, int end, int types)
    {

        for (int i = start; i <= end; i++) {
            Transform temp = null, coin;
            GameObject tempRoad = ItemPool.GetInstance ().GetItem (roads [i]);
            if (tempRoad != null && roads [i].Length > 0) {
                temp = NGUITools.AddToChild (road_Parent, tempRoad).transform;
            } else if (roads [i].Length > 0) {
                temp = null;
//                Debug.LogWarning ("==========>>>>>>>>>" + roads [i]);    
            }
            //添加路面
            switch (roads [i]) {
            case  "Dusk_land_Start_1":
                pos = Vector3.right * width_start;
                break;
            case  "Dusk_land_Mid_1":
                pos = Vector3.right * width_part;
                break;
            case "Dusk_land_End_1":    
                pos = Vector3.right * width_part;
                break;
            case  "Dusk_land_Start_2":
                pos = Vector3.right * width_start;
                break;
            case  "Dusk_land_Mid_2":
                pos = Vector3.right * width_part;
                break;
            case "Dusk_land_End_2":    
                pos = Vector3.right * width_part;
                break;
            default:
                pos = Vector3.right * width_part / 4;
                lastpos += pos;
                continue;    
            }
            //添加玉米和道具
            if (items [i].Length > 0) {
                GameObject mm = ItemPool.GetInstance ().GetItem (items [i]);
//                coin = NGUITools.AddToChild (road_Parent, mm).transform;
                coin = NGUITools.AddToChild (monster_Parent, mm).transform;
                coin.localPosition = lastpos + Vector3.up;
                coin.localScale = Vector3.one * ItemPool.GetInstance ().GetScale (items [i]);
            }
            if (types == 1) {
                length = lastpos.x;
            }
            if (temp != null) {
                temp.localPosition = lastpos;
                lastpos = temp.localPosition + pos;
                road_1_startpos = lastpos;
//                road_2_startpos = lastpos;
            } else {
            }
        }
    }

    void CreateSecondLoadedRoad (int start, int end, int types)
    {
//        secondPos = road_2_startpos;
//        secondLastpos = road_2_startpos;
        switch (types) {
        case 1:
            width_start = 0.16f;
            pos = road_1_startpos;
            lastpos = road_1_startpos;
            break;
        case 2:
            width_start = 0.15f;
            secondPos = road_2_startpos;
            secondLastpos = road_2_startpos;
            break;
        }
        CreatSecondSingleRoad (start, end, types);
    }

    void CreatSecondSingleRoad (int start, int end, int types)
    {

        for (int i = start; i < end; i++) {
            Transform temp = null, coin;
            GameObject tempRoad = ItemPool.GetInstance ().GetItem (secondRoads [i]);
            if (tempRoad != null && secondRoads [i].Length > 0) {
                temp = NGUITools.AddToChild (road_Parent, tempRoad).transform;
            } else if (secondRoads [i].Length > 0) {
                temp = null;
//                Debug.LogWarning ("==========>>>>>>>>>" + secondRoads [i]);    
            }
            //添加路面
            switch (secondRoads [i]) {
            case  "Dusk_land_Start_2":
                secondPos = Vector3.right * width_start;
                break;
            case  "Dusk_land_Mid_2":
                secondPos = Vector3.right * width_part;
                break;
            case "Dusk_land_End_2":    
                secondPos = Vector3.right * width_part;
                break;    
            default:
                secondPos = Vector3.right * width_part / 4;
                secondLastpos += secondPos;
                continue;    
            }
            //添加玉米和道具
            if (secondItems [i].Length > 0) {
                GameObject mm = ItemPool.GetInstance ().GetItem (secondItems [i]);
//            coin = NGUITools.AddToChild (road_Parent, mm).transform;
                coin = NGUITools.AddToChild (monster_Parent, mm).transform;
                coin.localPosition = secondLastpos + Vector3.up;
                coin.localScale = Vector3.one * ItemPool.GetInstance ().GetScale (secondItems [i]);
            }
//            if (types == 1) {
//                length = secondLastpos.x;
//            }
            if (temp != null) {
                temp.localPosition = secondLastpos;
                secondLastpos = temp.localPosition + secondPos;
                road_2_startpos = secondLastpos;
            } else {
            }
        }
    }
}
using UnityEngine;

using System.Collections;
using System.Collections.Generic;

public class Monsterconfig
{
    public string symbol;
    public string name;
    public string path;
    public float scale;
    public int num;
}

public class RoadMngr : MonoBehaviour
{
    public static bool isDebug = false;
//    private GameObject road_start_1, road_mid_1, road_end_1;
//    private GameObject road_start_2, road_mid_2, road_end_2;
    public GameObject road_Parent;
    public GameObject monster_Parent;
    private Vector3 road_1_startpos = new Vector3 (5, -2.1f, 10);
    private Vector3 road_2_startpos = new Vector3 (5, 0.95f, 10);
    public float length;
//    private List<Monsterconfig> monsterlist;

    public delegate void HandleFinishRoad ();

    public HandleFinishRoad finishInitCarHandler;
//    private float newLandTimes = 10;
    private string[] roads;
    private string[] secondRoads;
    private string[] items;
    private string[] secondItems;
//    private string[] newRoad = new string[10];
//    private string[] newItem = new string[10];
    private float width_start = 0.16f;
    private float width_part = 2.27f;
    private Vector3 pos;
    private Vector3 secondPos;
    private Vector3 lastpos;
    private Vector3 secondLastpos;
    private int lastIndex = 0;
    private bool isLoadDone = false;
    private string[] lines;
    private string FirstRoad;
    private string FirstMonster;
    private string SecondRoad;
    private string SecondMonster;
    private bool isLoadNextRoad = false;

    private char[] subSplit = new char[]{ ';' };
    private char[] subSplitAnotherLine = new char[]{ '\r' };

    void Awake(){
        Init();
    }

    void Init(){
        GetCommponent getComponent = GetComponent<GetCommponent> ();
        road_Parent = getComponent.defaultGameObject[0];
        monster_Parent = getComponent.defaultGameObject[1];
    }


    void Start ()
    {
        LoadRoadData ();
    }

    public void LoadRoadData ()
    {
        string path = GameUtils.GetAssetPath () + "/Road/RoadTable.csv";
        StartCoroutine (DownloadText.GetInstance ().DownLoad (path, GetStringRoad, false));
    }

    void GetStringRoad (string www, string str, bool flag)
    {
        lines = www.Split (subSplitAnotherLine);
        FirstRoad = lines [4];
        FirstMonster = lines [3];
        SecondRoad = lines [2];
        SecondMonster = lines [1];
//        CreatRoad (lines [4], lines [3], 1);//一级路面,怪物
//        CreatRoad (lines [2], lines [1], 2);//二级路面,怪物
        CreatRoad (FirstRoad, FirstMonster);//一级路面,怪物
        CreatSecondRoad (SecondRoad, SecondMonster);//二级路面,怪物
        isLoadDone = true;
    }

    void CreatRoad (string road, string item)
    {
        roads = road.Split (subSplit);//获得每一个路段的名字 535
        items = item.Split (subSplit);
    }

    void CreatSecondRoad (string road, string item)
    {
        secondRoads = road.Split (subSplit);
        secondItems = item.Split (subSplit);
    }

    void Update ()
    {
        if (isLoadDone) {
            if (TempValue.GetInstance ().curLandType == (int)Land_type.Dusk_land) {
                if (((int)UserInfos.GetInstance ().distance >= (int)(lastpos.x - 20)) && !isLoadNextRoad) {

                    int start = lastIndex;
                    int end = lastIndex + 18 < roads.Length ? lastIndex + 18 : roads.Length;
                    if (end > roads.Length) {
                        end = roads.Length;
                    }
                    lastIndex = lastIndex + 18;
                    CreateLoadedRoad (start, end, 1);
//                  CreateLoadedRoad (start, end, 2);
                    CreateSecondLoadedRoad (start, end, 2);
                    isLoadNextRoad = true;
                } else if (((int)UserInfos.GetInstance ().distance < (int)(lastpos.x - 20)) && isLoadNextRoad == true) {//有时候,没有执行这一步骤,所以没有加载到路面
                    isLoadNextRoad = false;
                }
            }
        }
    }

    void CreateLoadedRoad (int start, int end, int types)
    {
        pos = road_1_startpos;
        lastpos = road_1_startpos;
        switch (types) {
        case 1:
            width_start = 0.16f;
            pos = road_1_startpos;
            lastpos = road_1_startpos;
            break;
        case 2:
            width_start = 0.15f;
            pos = road_2_startpos;
            lastpos = road_2_startpos;
            break;
        }
        CreatSingleRoad (start, end, types);
    }

    void CreatSingleRoad (int start, int end, int types)
    {

        for (int i = start; i <= end; i++) {
            Transform temp = null, coin;
            GameObject tempRoad = ItemPool.GetInstance ().GetItem (roads [i]);
            if (tempRoad != null && roads [i].Length > 0) {
                temp = NGUITools.AddToChild (road_Parent, tempRoad).transform;
            } else if (roads [i].Length > 0) {
                temp = null;
//                Debug.LogWarning ("==========>>>>>>>>>" + roads [i]);    
            }
            //添加路面
            switch (roads [i]) {
            case  "Dusk_land_Start_1":
                pos = Vector3.right * width_start;
                break;
            case  "Dusk_land_Mid_1":
                pos = Vector3.right * width_part;
                break;
            case "Dusk_land_End_1":    
                pos = Vector3.right * width_part;
                break;
            case  "Dusk_land_Start_2":
                pos = Vector3.right * width_start;
                break;
            case  "Dusk_land_Mid_2":
                pos = Vector3.right * width_part;
                break;
            case "Dusk_land_End_2":    
                pos = Vector3.right * width_part;
                break;
            default:
                pos = Vector3.right * width_part / 4;
                lastpos += pos;
                continue;    
            }
            //添加玉米和道具
            if (items [i].Length > 0) {
                GameObject mm = ItemPool.GetInstance ().GetItem (items [i]);
//                coin = NGUITools.AddToChild (road_Parent, mm).transform;
                coin = NGUITools.AddToChild (monster_Parent, mm).transform;
                coin.localPosition = lastpos + Vector3.up;
                coin.localScale = Vector3.one * ItemPool.GetInstance ().GetScale (items [i]);
            }
            if (types == 1) {
                length = lastpos.x;
            }
            if (temp != null) {
                temp.localPosition = lastpos;
                lastpos = temp.localPosition + pos;
                road_1_startpos = lastpos;
//                road_2_startpos = lastpos;
            } else {
            }
        }
    }

    void CreateSecondLoadedRoad (int start, int end, int types)
    {
//        secondPos = road_2_startpos;
//        secondLastpos = road_2_startpos;
        switch (types) {
        case 1:
            width_start = 0.16f;
            pos = road_1_startpos;
            lastpos = road_1_startpos;
            break;
        case 2:
            width_start = 0.15f;
            secondPos = road_2_startpos;
            secondLastpos = road_2_startpos;
            break;
        }
        CreatSecondSingleRoad (start, end, types);
    }

    void CreatSecondSingleRoad (int start, int end, int types)
    {

        for (int i = start; i < end; i++) {
            Transform temp = null, coin;
            GameObject tempRoad = ItemPool.GetInstance ().GetItem (secondRoads [i]);
            if (tempRoad != null && secondRoads [i].Length > 0) {
                temp = NGUITools.AddToChild (road_Parent, tempRoad).transform;
            } else if (secondRoads [i].Length > 0) {
                temp = null;
//                Debug.LogWarning ("==========>>>>>>>>>" + secondRoads [i]);    
            }
            //添加路面
            switch (secondRoads [i]) {
            case  "Dusk_land_Start_2":
                secondPos = Vector3.right * width_start;
                break;
            case  "Dusk_land_Mid_2":
                secondPos = Vector3.right * width_part;
                break;
            case "Dusk_land_End_2":    
                secondPos = Vector3.right * width_part;
                break;    
            default:
                secondPos = Vector3.right * width_part / 4;
                secondLastpos += secondPos;
                continue;    
            }
            //添加玉米和道具
            if (secondItems [i].Length > 0) {
                GameObject mm = ItemPool.GetInstance ().GetItem (secondItems [i]);
//            coin = NGUITools.AddToChild (road_Parent, mm).transform;
                coin = NGUITools.AddToChild (monster_Parent, mm).transform;
                coin.localPosition = secondLastpos + Vector3.up;
                coin.localScale = Vector3.one * ItemPool.GetInstance ().GetScale (secondItems [i]);
            }
//            if (types == 1) {
//                length = secondLastpos.x;
//            }
            if (temp != null) {
                temp.localPosition = secondLastpos;
                secondLastpos = temp.localPosition + secondPos;
                road_2_startpos = secondLastpos;
            } else {
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值