Пример #1
0
    // Use this for initialization
    void Awake()
    {
        SSCreatNpcData npcDataCom = gameObject.GetComponent <SSCreatNpcData>();

        if (NpcObj == null && npcDataCom == null)
        {
            if (!XkGameCtrl.GetInstance().IsCartoonShootTest)
            {
                Debug.LogWarning("Unity:" + "NpcObj was null");
                GameObject obj = null;
                obj.name = "null";
            }
            return;
        }

        if (NpcObj != null)
        {
            XKNpcMoveCtrl npcScript = NpcObj.GetComponent <XKNpcMoveCtrl>();
            if (npcScript != null)
            {
                if (IsFireMove && IsAimPlayer)
                {
                    Debug.LogWarning("Unity:" + "SpawnPoint.IsFireMove and SpawnPoint.IsAimPlayer is true!");
                    GameObject obj = null;
                    obj.name = "null";
                }
            }
        }

        if (NpcPath != null)
        {
            if (NpcPath.childCount < 1)
            {
                Debug.LogWarning("Unity:" + "NpcPath.childCount was wrong! childCount = " + NpcPath.childCount);
                GameObject obj = null;
                obj.name = "null";
            }

            if (NpcPath.GetComponent <NpcPathCtrl>() == null)
            {
                Debug.LogWarning("Unity:" + "NpcPath was wrong! cannot find NpcPathCtrl script");
                GameObject obj = null;
                obj.name = "null";
            }
        }

        if (NpcSpawnLoop.Length > 0)
        {
            for (int i = 0; i < NpcSpawnLoop.Length; i++)
            {
                if (NpcSpawnLoop[i] == null)
                {
                    Debug.LogWarning("Unity:" + "NpcSpawnLoop was wrong! index " + (i + 1));
                    GameObject obj = null;
                    obj.name = "null";
                    break;
                }
            }
        }

        if (ChildSpawnPoint.Length > 0)
        {
            for (int i = 0; i < ChildSpawnPoint.Length; i++)
            {
                if (ChildSpawnPoint[i] == null)
                {
                    Debug.LogWarning("Unity:" + "ChildSpawnPoint was wrong! index " + (i + 1));
                    GameObject obj = null;
                    obj.name = "null";
                    break;
                }
            }
        }

        if (ChildSpawnPoint.Length > 0 && NpcFangZhen == null)
        {
            Debug.LogWarning("Unity:" + "NpcFangZhen is null! fangZhenLength " + ChildSpawnPoint.Length);
            GameObject obj = null;
            obj.name = "null";
        }
        //Invoke("CheckIsRemoveTrigger", 1f);

        MeshRenderer mesh = gameObject.GetComponent <MeshRenderer>();

        if (mesh != null)
        {
            Destroy(mesh);
        }

        MeshFilter meshFt = gameObject.GetComponent <MeshFilter>();

        if (meshFt != null)
        {
            Destroy(meshFt);
        }
    }
Пример #2
0
 public void SaveFeiJiNpcSpawnInfo(XKNpcMoveCtrl npcScript)
 {
     NpcLoopObj = npcScript.gameObject;
     npcScript.TestSpawnPoint = gameObject;
 }
Пример #3
0
 public void SetNpcMoveScript(XKNpcMoveCtrl scriptVal)
 {
     NpcScript = scriptVal;
     ResetNpcHealthInfo();
 }
Пример #4
0
    void Awake()
    {
        //if (pcvr.TKMoveSt == TKMoveState.U_FangXiangPan) {
        //	for (int i = 0; i < TimeFireAmmo.Length; i++) {
        //		TimeFireAmmo[i] *= XkGameCtrl.GetInstance().NpcAmmoTime;
        //	}
        //}

        if (NpcAniController.Length > 0)
        {
            for (int i = 0; i < NpcAniController.Length; i++)
            {
                if (NpcAniController[i] == null)
                {
                    Debug.LogWarning("Unity:" + "NpcAniController was wrong!");
                    GameObject obj = null;
                    obj.name = "null";
                    break;
                }
            }

            int randVal = Random.Range(0, (1 + NpcAniController.Length));
            if (randVal < NpcAniController.Length && ZaiTiNpcAni != null)
            {
                ZaiTiNpcAni.runtimeAnimatorController = NpcAniController[randVal];
            }
            //ZaiTiNpcAni.runtimeAnimatorController = NpcAniController[0]; //test
        }

        if (IsTeShuFireNpc)
        {
            if (TimeFireAmmo.Length != AmmoPrefabTeShu.Length || TimeFireAmmo.Length != AmmoSpawnTranTeShu.Length)
            {
                Debug.LogWarning("Unity:" + "IsTeShuFireNpc was true, but TimeFireAmmo or AmmoPrefabTeShu or AmmoSpawnTranTeShu length was wrong!");
                GameObject obj = null;
                obj.name = "null";
            }

            for (int i = 0; i < TimeFireAmmo.Length; i++)
            {
                if (TimeFireAmmo[i] < 0.005f)
                {
                    TimeFireAmmo[i] = 0.005f;
                }
            }
//			AmmoLZObjTeShu = new GameObject[AmmoLZPrefabTeShu.Length];
            InitNpcAmmoList();
        }

        if (ZaiTiNpcBuWaWa != null)
        {
            ZaiTiNpcBuWaWa.gameObject.SetActive(false);
            //取消布娃娃.
            ZaiTiNpcBuWaWa = null;
        }
        NpcObj = gameObject;
        //NpcTran = transform;

//		if (DeathExplodePoint == null) {
//			DeathExplodePoint = NpcTran;
//		}
//		XKNpcHealthCtrl healthScript = GetComponent<XKNpcHealthCtrl>();
//		healthScript.SetNpcJiFen(NpcJiFen);

        NpcScript = GetComponentInParent <XKNpcMoveCtrl>();
//		if (NpcScript != null) {
//			if (NpcScript.IsAniMove) {
//				Rigidbody rig = GetComponent<Rigidbody>();
//				if (rig == null) {
//					gameObject.AddComponent<Rigidbody>();
//				}
//				Invoke("DelaySetRigidbodyInfo", 0.2f);
//			}
//		}
        TimeTeShuFire = new float[TimeFireAmmo.Length];

        for (int i = 0; i < AmmoSpawnTranTeShu.Length; i++)
        {
            if (AmmoSpawnTranTeShu[i] != null)
            {
                AmmoSpawnTranTeShu[i].gameObject.SetActive(false);
            }
        }
    }
    // Use this for initialization
    void Awake()
    {
//		if (HuoCheNpcTran != null) {
//			HuoCheNpcTran.gameObject.SetActive(false);
//		}

        if (NpcObj == null)
        {
            if (!XkGameCtrl.GetInstance().IsCartoonShootTest)
            {
                Debug.LogWarning("NpcObj was null");
                GameObject obj = null;
                obj.name = "null";
            }
            return;
        }
//		else {
//			NetworkView netView = NpcObj.GetComponent<NetworkView>();
//			if (netView == null) {
//				Debug.LogWarning("npc cannot find NetworkView");
//				GameObject obj = null;
//				obj.name = "null";
//				return;
//			}
//		}

        XKNpcMoveCtrl npcScript = NpcObj.GetComponent <XKNpcMoveCtrl>();

        if (npcScript != null)
        {
            if (IsFireMove && IsAimPlayer)
            {
                Debug.LogWarning("SpawnPoint.IsFireMove and SpawnPoint.IsAimPlayer is true!");
                GameObject obj = null;
                obj.name = "null";
            }

//			if (npcScript.IsAniMove) {
//				SetFeiJiSpawnPointInfo();
//			}

//			if (npcScript.NpcState == NpcType.FlyNpc) {
//				if (NpcPath != null && NpcPath.childCount < 2) {
//					Debug.LogWarning("NpcPath.childCount was wrong!");
//					GameObject obj = null;
//					obj.name = "null";
//				}
//			}
        }

        if (NpcPath != null)
        {
            if (NpcPath.childCount < 1)
            {
                Debug.LogWarning("NpcPath.childCount was wrong! childCount = " + NpcPath.childCount);
                GameObject obj = null;
                obj.name = "null";
            }

            if (NpcPath.GetComponent <NpcPathCtrl>() == null)
            {
                Debug.LogWarning("NpcPath was wrong! cannot find NpcPathCtrl script");
                GameObject obj = null;
                obj.name = "null";
            }
        }

//		if (FirePointGroup.Length > 0) {
//			for (int i = 0; i < FirePointGroup.Length; i++) {
//				if (FirePointGroup[i] == null) {
//					Debug.LogWarning("FirePointGroup was wrong! index "+(i+1));
//					GameObject obj = null;
//					obj.name = "null";
//					break;
//				}
//			}
//
//			if (SpeedFangZhenFireRun <= 0f) {
//				Debug.LogWarning("SpeedFangZhenFireRun was wrong! SpeedFangZhenFireRun "+SpeedFangZhenFireRun);
//				GameObject obj = null;
//				obj.name = "null";
//			}
//		}

        if (NpcSpawnLoop.Length > 0)
        {
            for (int i = 0; i < NpcSpawnLoop.Length; i++)
            {
                if (NpcSpawnLoop[i] == null)
                {
                    Debug.LogWarning("NpcSpawnLoop was wrong! index " + (i + 1));
                    GameObject obj = null;
                    obj.name = "null";
                    break;
                }
            }
        }

        if (ChildSpawnPoint.Length > 0)
        {
            for (int i = 0; i < ChildSpawnPoint.Length; i++)
            {
                if (ChildSpawnPoint[i] == null)
                {
                    Debug.LogWarning("ChildSpawnPoint was wrong! index " + (i + 1));
                    GameObject obj = null;
                    obj.name = "null";
                    break;
                }
            }
        }

        if (ChildSpawnPoint.Length > 0 && NpcFangZhen == null)
        {
            Debug.LogWarning("NpcFangZhen is null! fangZhenLength " + ChildSpawnPoint.Length);
            GameObject obj = null;
            obj.name = "null";
        }
        //Invoke("CheckIsRemoveTrigger", 1f);
    }
    void StartSpawnNpc()
    {
        if (!enabled || !gameObject.activeSelf)
        {
            return;
        }

        if (ScreenDanHeiCtrl.IsStartGame)
        {
//			if ((XkGameCtrl.GameModeVal == GameMode.DanJiFeiJi && PointType == SpawnPointType.DiMian)
//			    || (XkGameCtrl.GameModeVal == GameMode.DanJiTanKe && PointType == SpawnPointType.KongZhong)) {
//				return;
//			}

//			if (IsDoublePlayer && (!XkGameCtrl.IsActivePlayerOne || !XkGameCtrl.IsActivePlayerTwo)) {
//				return;
//			}

            switch (PlayerNumSt)
            {
            case NpcSpawnType.PlayerNum_2:
                if (XkGameCtrl.PlayerActiveNum < 2)
                {
                    return;
                }
                break;

            case NpcSpawnType.PlayerNum_3:
                if (XkGameCtrl.PlayerActiveNum < 3)
                {
                    return;
                }
                break;

            case NpcSpawnType.PlayerNum_4:
                if (XkGameCtrl.PlayerActiveNum < 4)
                {
                    return;
                }
                break;
            }
        }

        GameObject   obj      = null;
        XKHuoCheCtrl hcScript = NpcObj.GetComponent <XKHuoCheCtrl>();

        if (hcScript != null)
        {
            obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation);
            if (obj == null)
            {
                //Debug.Log("StartSpawnNpc -> Cannot spawn HuoCheNpc!");
                return;
            }

            obj.transform.parent = XkGameCtrl.NpcObjArray;
            HuoCheScript         = obj.GetComponent <XKHuoCheCtrl>();
            HuoCheScript.SetHuoCheInfo(this);
            //HuoCheScript.StartMoveHuoChe(NpcPath);
            NpcLoopObj = obj;
            return;
        }

        DaPaoScript = NpcObj.GetComponent <XKDaPaoCtrl>();
        if (DaPaoScript != null)
        {
//			Debug.Log("Spawn Cannon... ");
            obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation);
            if (obj == null)
            {
                //Debug.Log("StartSpawnNpc -> Cannot spawn DaPaoNpc!");
                return;
            }

            if (!IsHuoCheNpc)
            {
                obj.transform.parent = XkGameCtrl.NpcObjArray;
            }
            else
            {
                obj.transform.parent = transform.parent;
            }

            //XkGameCtrl.GetInstance().AddNpcTranToList(obj.transform);
            DaPaoScript = obj.GetComponent <XKDaPaoCtrl>();
            DaPaoScript.SetSpawnPointScript(this);
            NpcLoopObj = obj;
            return;
        }

        if (IsRemoveSpawnPointNpc)
        {
            return;
        }

        //Debug.Log("SpawnPointAllNpc...NpcObj is "+NpcObj.name+", SpawnNpcCount "+SpawnNpcCount);
        if (ChildSpawnPoint.Length > 0)
        {
            //spawn fangZhenNpc
            GameObject fangZhenObj = SpawnPointNpc(NpcFangZhen, transform.position, transform.rotation);
            if (fangZhenObj == null)
            {
                //Debug.LogError("StartSpawnNpc -> Cannot spawn FangZhenNpc! NpcFangZhen "+NpcFangZhen.name);
                //fangZhenObj.name = "null";
                return;
            }
            NpcFangZhenScript = fangZhenObj.GetComponent <XKNpcFangZhenCtrl>();
            //NpcFangZhenScript.ActiveFangZhenNpc();

            XKNpcMoveCtrl npcScript    = null;
            Transform     fangZhenTran = fangZhenObj.transform;
            fangZhenTran.parent = XkGameCtrl.NpcObjArray;
            obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation);
            if (obj == null)
            {
                //Debug.Log("StartSpawnNpc -> Cannot spawn FangZhenChildNpc --- 1");
                return;
            }

            npcScript = obj.GetComponent <XKNpcMoveCtrl>();
            if (npcScript != null)
            {
                npcScript.ActiveIsFangZhenNpc();
                npcScript.SetNpcSpawnScriptInfo(this);
            }
            obj.transform.parent = fangZhenTran;

            for (int i = 0; i < ChildSpawnPoint.Length; i++)
            {
                obj = SpawnPointNpc(NpcObj, ChildSpawnPoint[i].position, ChildSpawnPoint[i].rotation);
                if (obj == null)
                {
                    //Debug.LogWarning("StartSpawnNpc -> Cannot spawn FangZhenChildNpc --- index "+i);
                    break;
                }

                npcScript = obj.GetComponent <XKNpcMoveCtrl>();
                if (npcScript != null)
                {
                    npcScript.ActiveIsFangZhenNpc();
                    npcScript.SetNpcSpawnScriptInfo(this);
                }
                obj.transform.parent = fangZhenTran;
            }

            NpcFangZhenScript.SetSpawnNpcInfo(this);
            NpcLoopObj = fangZhenObj;
            return;
        }

//		if (NpcLoopObj != null && SpawnMaxNpc > 1) {
//			if (IsRemoveSpawnPointNpc) {
//				return;
//			}
//
//			XKNpcMoveCtrl npcScript = NpcLoopObj.GetComponent<XKNpcMoveCtrl>();
//			if (npcScript != null && !npcScript.GetIsDeathNPC()) {
//				Invoke("StartSpawnNpc", LoopSpawnTime);
//				return;
//			}
//		}

        if (SpawnNpcCount > 0)
        {
            int maxVal  = NpcSpawnLoop.Length;
            int randVal = Random.Range(0, (maxVal + 1));
            if (randVal == 0)
            {
                obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation);
            }
            else
            {
                randVal = randVal > maxVal ? maxVal : randVal;
                obj     = SpawnPointNpc(NpcSpawnLoop[randVal - 1], transform.position, transform.rotation);
            }
        }
        else
        {
            obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation);
        }

        if (obj == null)
        {
            //Debug.Log("StartSpawnNpc -> Cannot spawn PuTongNpc!");
            return;
        }

        if (!IsHuoCheNpc)
        {
            obj.transform.parent = XkGameCtrl.NpcObjArray;
        }
        else
        {
            obj.transform.parent = transform.parent;
        }

        NpcScript[SpawnNpcCount] = obj.GetComponent <XKNpcMoveCtrl>();
        if (NpcScript[SpawnNpcCount] != null)
        {
            NpcScript[SpawnNpcCount].SetSpawnNpcInfo(this);
        }
        NpcLoopObj = obj;

        SpawnNpcCount++;
        if (SpawnNpcCount >= SpawnMaxNpc || SpawnMaxNpc <= 1)
        {
            return;
        }
        Invoke("StartSpawnNpc", LoopSpawnTime);
    }
    public void SetNpcMoveScript(XKNpcMoveCtrl script)
    {
        IsSpawnObj = true;
        NpcScript  = script;
        if (NpcScript != null && NpcJiFen == NpcJiFenEnum.Boss)
        {
            NpcScript.SetIsBossNpc(true);
        }
        NpcNameInfo = script.name;
        ResetNpcHealthInfo();

        if (m_CaiPiaoNpcUI != null)
        {
            if (NpcScript != null)
            {
                if (NpcScript.IsCaiPiaoZhanChe == true)
                {
                    if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null && IsGetTotalHealthData == false)
                    {
                        IsGetTotalHealthData = true;
                        //获取获取JPBoss和战车Npc的血值数据.
                        if (NpcScript.IsJPBossNpc == true)
                        {
                            //JPBoss战车.
                            XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.GetTotalHealthData(SSCaiPiaoDataManage.GameCaiPiaoData.DaiJinQuanState.JPBossDaiJinQuan);
                        }
                        else
                        {
                            //战车01或02.
                            XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.GetTotalHealthData(NpcScript.m_DaiJinQuanState);
                        }
                        //保存代金券npc的血条脚本.
                        XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.SaveDaiJinQuanHealth(this);
                    }

                    SetRecordMaxPuTongAmmo();
                    if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true)
                    {
                        //没有玩家激活游戏,使用游戏记录的血值数据.
                        MaxPuTongAmmo = MaxPuTongAmmoCache;
                    }
                    else
                    {
                        //有玩家正在进行游戏,使用游戏配置的血值数据.
                        if (NpcScript.GetIsBossNpc() == true)
                        {
                            if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null)
                            {
                                //跟新JPBoss的血值数据.
                                MaxPuTongAmmo = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.m_CurrentTotalHealthDt.JPBossHealth.MaxPuTongAmmo;
                                //SSDebug.Log("*********************************************************3333333333333333333333333333333");
                            }
                        }
                        else
                        {
                            if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null)
                            {
                                //跟新战车Npc的血值数据.
                                MaxPuTongAmmo = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.m_CurrentTotalHealthDt.ZhanCheHealth.MaxPuTongAmmo;
                            }
                        }
                    }

                    if (NpcScript.GetIsBossNpc() == true)
                    {
                        m_CaiPiaoNpcUI.ShowNumUI(SSCaiPiaoDataManage.GameCaiPiaoData.DeCaiState.JPBoss, this);
                    }
                    else
                    {
                        m_CaiPiaoNpcUI.ShowNumUI(SSCaiPiaoDataManage.GameCaiPiaoData.DeCaiState.ZhanChe, this);
                    }

                    //创建代金券npc的血条信息.
                    float perVal = 0.5f;
                    if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null)
                    {
                        perVal = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.m_CurrentTotalHealthDt.UIHealthPer;
                    }
                    SSUIRoot.GetInstance().m_GameUIManage.CreatDaiJinQuanNpcXueTiaoUI(perVal);
                }
                NpcScript.m_CaiPiaoNpcUI = m_CaiPiaoNpcUI;
            }
        }
        TimeLastVal = Time.time;
    }
Пример #8
0
    void OnTriggerExit(Collider other)
    {
        XKNpcMoveCtrl npcMoveCom = other.gameObject.GetComponent <XKNpcMoveCtrl>();

        if (npcMoveCom != null && npcMoveCom.IsCaiPiaoZhanChe)
        {
            //Debug.Log("Unity: OnTriggerExit******************name === " + npcMoveCom.name);
            bool isExit = false;
            switch (m_TriggerState)
            {
            case TriggerState.JPBoss:
            {
                if (npcMoveCom.IsEnterCameraBox == true && npcMoveCom.GetIsBossNpc() == true)
                {
                    isExit = true;
                }

                if (npcMoveCom.IsCaiPiaoZhanChe == false)
                {
                    //普通npc走出JPBoss的镜头范围盒子.
                    if (XkPlayerCtrl.GetInstanceFeiJi() != null)
                    {
                        if (XkPlayerCtrl.GetInstanceFeiJi().m_SpawnNpcManage != null)
                        {
                            XkPlayerCtrl.GetInstanceFeiJi().m_SpawnNpcManage.RemovePuTongNpcToBuJiDt(npcMoveCom.gameObject);
                        }
                    }
                }
                break;
            }

            case TriggerState.ZhanCheBoss:
            {
                if (npcMoveCom.IsEnterCameraBox == true && npcMoveCom.GetIsBossNpc() == false)
                {
                    isExit = true;
                }
                break;
            }
            }

            if (isExit == false)
            {
                return;
            }

            if (npcMoveCom.GetIsBossNpc() == true)
            {
                //Boss走出镜头范围.
                if (XkGameCtrl.GetInstance() != null && XkGameCtrl.GetInstance().m_AiPathGroup != null &&
                    XkGameCtrl.GetInstance().m_AiPathGroup.m_CameraMoveType != AiPathGroupCtrl.MoveState.YuLe)
                {
                    XkGameCtrl.GetInstance().m_AiPathGroup.SetCameraMoveType(AiPathGroupCtrl.MoveState.Default);
                }
                npcMoveCom.TriggerRemovePointNpc(0);
                //boss删除后切换背景音效.
                AudioBeiJingCtrl.StopGameBeiJingAudio();
                //镜头继续移动.
                XkGameCtrl.GetInstance().SetGameCameraIsMoveing(true, NpcJiFenEnum.Boss);
            }
            else
            {
                //彩票战车npc走出镜头范围.
                npcMoveCom.TriggerRemovePointNpc(0);
                //镜头继续移动.
                XkGameCtrl.GetInstance().SetGameCameraIsMoveing(true, NpcJiFenEnum.CheLiang);
                //SSDebug.LogWarning("SSTriggerCamerBox::OnTriggerExit -> time ==================== " + Time.time);
            }
        }
    }
    public GameObject FindNpcObjFromNpcList(XKSpawnNpcPoint spawnCom, GameObject npcPrefab)
    {
        if (npcPrefab == null)
        {
            return(null);
        }

        GameObject        npcObj            = null;
        int               max               = NpcList.Count;
        XKNpcMoveCtrl     npcMoveScript     = null;
        XKDaPaoCtrl       npcDaPaoScript    = null;
        XKHuoCheCtrl      npcHuoCheScript   = null;
        XKNpcFangZhenCtrl npcFangZhenScript = null;

        if (max > 0 && NpcScriptSt != NpcScriptState.XKHuoChe)
        {
            for (int i = 0; i < max; i++)
            {
                if (NpcList[i] != null)
                {
                    switch (NpcScriptSt)
                    {
                    case NpcScriptState.XKNpcMove:
                        npcMoveScript = NpcList[i].GetComponent <XKNpcMoveCtrl>();
                        if (npcMoveScript != null &&
                            npcMoveScript.GetIsDeathNPC())
                        {
                            GameObject realNpcObj = npcMoveScript.RealNpcTran.gameObject;
                            if (!realNpcObj.activeSelf)
                            {
                                npcObj = NpcList[i];
                            }
                        }
                        break;

                    case NpcScriptState.XKDaPao:
                        npcDaPaoScript = NpcList[i].GetComponent <XKDaPaoCtrl>();
                        if (npcDaPaoScript != null &&
                            npcDaPaoScript.GetIsDeathNpc())
                        {
                            npcDaPaoScript.SetSpawnPointScript(spawnCom);
                            npcDaPaoScript.ResetNpcDaPaoInfo();
                            npcObj = NpcList[i];
                        }
                        break;

                    case NpcScriptState.XKHuoChe:
                        break;

                    case NpcScriptState.XKFangZhen:
                        npcFangZhenScript = NpcList[i].GetComponent <XKNpcFangZhenCtrl>();
                        if (npcFangZhenScript != null &&
                            npcFangZhenScript.GetIsHiddenNpcObj() &&
                            !npcFangZhenScript.GetIsActiveFangZhen())
                        {
                            npcObj = NpcList[i];
                            npcFangZhenScript.ActiveFangZhenNpc();
                        }
                        break;
                    }
                }

                if (npcObj != null)
                {
                    break;
                }
            }
        }

        if (npcObj == null)
        {
            if (NpcScriptSt == NpcScriptState.Null)
            {
                npcMoveScript = npcPrefab.GetComponent <XKNpcMoveCtrl>();
                if (npcMoveScript != null)
                {
                    NpcScriptSt = NpcScriptState.XKNpcMove;
                }

                if (NpcScriptSt == NpcScriptState.Null)
                {
                    npcDaPaoScript = npcPrefab.GetComponent <XKDaPaoCtrl>();
                    if (npcDaPaoScript != null)
                    {
                        NpcScriptSt = NpcScriptState.XKDaPao;
                    }
                }

                if (NpcScriptSt == NpcScriptState.Null)
                {
                    npcHuoCheScript = npcPrefab.GetComponent <XKHuoCheCtrl>();
                    if (npcHuoCheScript != null)
                    {
                        NpcScriptSt = NpcScriptState.XKHuoChe;
                    }
                }

                if (NpcScriptSt == NpcScriptState.Null)
                {
                    npcFangZhenScript = npcPrefab.GetComponent <XKNpcFangZhenCtrl>();
                    if (npcFangZhenScript != null)
                    {
                        NpcScriptSt = NpcScriptState.XKFangZhen;
                    }
                }
            }

            switch (NpcScriptSt)
            {
            case NpcScriptState.XKNpcMove:
                npcObj = SpawnNpcByNpcPrefab(npcPrefab);
                break;

            case NpcScriptState.XKDaPao:
                npcObj = SpawnNpcByNpcPrefab(npcPrefab);
                break;

            case NpcScriptState.XKHuoChe:
                npcObj = SpawnNpcByNpcPrefab(npcPrefab);
                break;

            case NpcScriptState.XKFangZhen:
                npcObj = SpawnNpcByNpcPrefab(npcPrefab);
                break;
            }
        }
        return(npcObj);
    }
    /// <summary>
    /// 清理暂时不用的npc数据.
    /// </summary>
    public void ClearNpcObj()
    {
        int max      = NpcList.Count;
        int indexNpc = 0;

        GameObject[]  npcArray       = new GameObject[max];
        XKNpcMoveCtrl npcMoveScript  = null;
        XKDaPaoCtrl   npcDaPaoScript = null;
        string        npcName        = "noRemovedNpc";

        if (max > 0)
        {
            for (int i = 0; i < max; i++)
            {
                //统计暂时不用的npc.
                if (NpcList[i] != null)
                {
                    switch (NpcScriptSt)
                    {
                    case NpcScriptState.XKNpcMove:
                        npcMoveScript = NpcList[i].GetComponent <XKNpcMoveCtrl>();
                        if (npcMoveScript != null &&
                            npcMoveScript.GetIsDeathNPC())
                        {
                            if (indexNpc == 0)
                            {
                                npcName = NpcList[i].name;
                            }
                            npcArray[indexNpc] = NpcList[i];
                            indexNpc++;
                        }
                        break;

                    case NpcScriptState.XKDaPao:
                        npcDaPaoScript = NpcList[i].GetComponent <XKDaPaoCtrl>();
                        if (npcDaPaoScript != null &&
                            npcDaPaoScript.GetIsDeathNpc())
                        {
                            if (indexNpc == 0)
                            {
                                npcName = NpcList[i].name;
                            }
                            npcArray[indexNpc] = NpcList[i];
                            indexNpc++;
                        }
                        break;
                    }
                }
            }

            for (int i = 0; i < indexNpc; i++)
            {
                if (npcArray[i] != null)
                {
                    if (NpcList.Contains(npcArray[i]))
                    {
                        //清理列表.
                        NpcList.Remove(npcArray[i]);
                    }
                }
            }

            for (int i = 0; i < indexNpc; i++)
            {
                if (npcArray[i] != null)
                {
                    //删除暂时不用的npc.
                    Destroy(npcArray[i]);
                }
            }
            Debug.Log("Unity: ClearNpcObj -> max == " + max + ", NpcScriptSt == " + NpcScriptSt + ", npcName == " + npcName
                      + ", cleanCount == " + indexNpc);
        }
    }
    void Awake()
    {
        SpawnParticleCom = gameObject.AddComponent <XKSpawnParticle>();
        if (NpcAniController.Length > 0)
        {
            for (int i = 0; i < NpcAniController.Length; i++)
            {
                if (NpcAniController[i] == null)
                {
                    Debug.LogWarning("NpcAniController was wrong!");
                    GameObject obj = null;
                    obj.name = "null";
                    break;
                }
            }

            int randVal = Random.Range(0, (1 + NpcAniController.Length));
            if (randVal < NpcAniController.Length && ZaiTiNpcAni != null)
            {
                ZaiTiNpcAni.runtimeAnimatorController = NpcAniController[randVal];
            }
            //ZaiTiNpcAni.runtimeAnimatorController = NpcAniController[0]; //test
        }

        if (IsTeShuFireNpc)
        {
            if (TimeFireAmmo.Length != AmmoPrefabTeShu.Length || TimeFireAmmo.Length != AmmoSpawnTranTeShu.Length)
            {
                Debug.LogWarning("IsTeShuFireNpc was true, but TimeFireAmmo or AmmoPrefabTeShu or AmmoSpawnTranTeShu length was wrong!");
                GameObject obj = null;
                obj.name = "null";
            }

            for (int i = 0; i < TimeFireAmmo.Length; i++)
            {
                if (TimeFireAmmo[i] < 0.005f)
                {
                    TimeFireAmmo[i] = 0.005f;
                }
            }
            InitNpcAmmoList();
        }

        if (ZaiTiNpcBuWaWa != null)
        {
            ZaiTiNpcBuWaWa.gameObject.SetActive(false);
        }
        NpcObj  = gameObject;
        NpcTran = transform;

        if (DeathExplodePoint == null)
        {
            DeathExplodePoint = NpcTran;
        }
//		XKNpcHealthCtrl healthScript = GetComponent<XKNpcHealthCtrl>();
//		healthScript.SetNpcJiFen(NpcJiFen);

        NpcScript = GetComponentInParent <XKNpcMoveCtrl>();
        if (NpcScript != null)
        {
            if (NpcScript.IsAniMove)
            {
                Rigidbody rig = GetComponent <Rigidbody>();
                if (rig == null)
                {
                    gameObject.AddComponent <Rigidbody>();
                }
                Invoke("DelaySetRigidbodyInfo", 0.2f);
            }
        }
        TimeTeShuFire = new float[TimeFireAmmo.Length];
    }