Пример #1
0
        void Update()
        {
            FreshQueue();
            if (!m_IsCanShow)
            {
                return;
            }
            if (!GM.AssetManager.IsIdle)
            {
                return;
            }
            if (m_NpcQueue != null && m_NpcQueue.Count > 0)
            {
                NpcDelegate npcdata = m_NpcQueue.Dequeue();
                if (npcdata != null)
                {
                    if (npcdata.sceneid.Equals(m_CurrentSceneID) && m_ManagedNpcs != null && m_ManagedNpcs.ContainsKey(npcdata.locator))
                    {
                        Vector3    v3;
                        Quaternion rot;
                        switch (npcdata.role)
                        {
                        case NPC_ROLE.GHOST:
                            v3  = npcdata.pos;
                            rot = npcdata.quater;
                            break;

                        default:
                            GameObject locator_obj = LocatorManager.Instance.GetLocator(npcdata.locator);
                            if (locator_obj == null)
                            {
                                EB.Debug.LogWarning(string.Format("No available locator data for npc  at locator [{0}]", npcdata.locator));
                                return;
                            }
                            v3  = locator_obj.transform.position;
                            rot = locator_obj.transform.rotation;
                            break;
                        }

                        if (npcdata.key != null)
                        {
                            //夺宝奇兵等级未开放或该区服未开放判断
                            if (npcdata.role == NPC_ROLE.GHOST &&
                                (
                                    !Hotfix_LT.Data.FuncTemplateManager.Instance.GetFunc(10073).IsConditionOK() ||
                                    !Hotfix_LT.Data.EventTemplateManager.Instance.GetRealmIsOpen("main_land_ghost_start")))
                            {
                                EB.Debug.LogWarning("NPC_ROLE.GHOST Return! (10073).IsConditionOK()——{0}", Hotfix_LT.Data.FuncTemplateManager.Instance.GetFunc(10073).IsConditionOK() + ";GetRealmIsOpen——" + Hotfix_LT.Data.EventTemplateManager.Instance.GetRealmIsOpen("main_land_ghost_start"));
                                return;
                            }
                            else if (m_GroupCellManager != null && m_GroupCellManager.IsCellShowing(npcdata.key))
                            {
                                if (!npcdata.preloaded)
                                {
                                    if (m_CurrentSceneLogic != null)
                                    {
                                        m_CurrentSceneLogic.PreloadAsync(npcdata.modelname, (success) =>
                                        {
                                            npcdata.preloaded = success;
                                            m_NpcQueue.Enqueue(npcdata);
                                        });
                                    }
                                    else
                                    {
                                        EB.Debug.LogError("CurrentSceneLogic is Null");
                                    }
                                }
                                else if (m_ManagedNpcs != null && !m_ManagedNpcs[npcdata.locator].created)
                                {
                                    m_ManagedNpcs[npcdata.locator].created = true;
                                    if (m_CurrentSceneLogic != null)
                                    {
                                        #region 异步加载一个NPC
                                        m_CurrentSceneLogic.SpawnNpcAsync(npcdata.locator, npcdata.modelname, npcdata.role, v3, rot, ec =>
                                        {
                                            if (ec != null)
                                            {
                                                Player.EnemyHotfixController ehc = ec.transform.GetMonoILRComponent <Player.EnemyHotfixController>();
                                                ehc.SetBarHudState(eHeadBarHud.FightStateHud, null, m_ManagedNpcs[npcdata.locator].isfighting);
                                                ehc.Role = npcdata.role;
                                                ehc.Attr = npcdata.attr;
                                                ehc.SetNpcName(m_CurrentSceneLogic.CurrentSceneName);
                                            }
                                        });
                                        #endregion
                                    }
                                    else
                                    {
                                        EB.Debug.LogError("CurrentSceneLogic is Null");
                                    }
                                }
                            }
                        }
                        else if (m_GroupCellManager != null)
                        {
                            GroupCellKey key = m_GroupCellManager.ObjectIn(npcdata.locator, v3);
                            npcdata.key = key;
                            if (m_GroupCellManager.IsCellShowing(npcdata.key))
                            {
                                m_NpcQueue.Enqueue(npcdata);
                            }
                        }
                    }
                    else
                    {
                    }
                }
            }

            if (m_GroupCellManager != null)
            {
                var go = PlayerManager.LocalPlayerGameObject();
                m_GroupCellManager.Update(go != null ? go.transform : null);
            }
        }