예제 #1
0
        /// <summary>
        /// 获取当前预览的物体,更新预览界面的角色灯光
        /// </summary>
        public void UpdatePreviewLight(GameObject preview_object)
        {
            var role_ids = GameConstHelper.GetUintList("GAME_AVAILABLE_ROLE_ID");
            var type_ids = new List <uint>(role_ids.Count);

            foreach (var rid in role_ids)
            {
                type_ids.Add(ActorHelper.RoleIdToTypeId(rid));
            }

            uint actor_type_id = 0;
            var  client_model  = preview_object.GetComponentInChildren <ActorMono>(true);

            if (client_model != null && client_model.BindActor != null)
            {
                actor_type_id = client_model.BindActor.TypeIdx;
            }

            if (type_ids.Contains(actor_type_id))
            {
                PreviewLight.SelectLight(0, ActorHelper.TypeIdToRoleId(actor_type_id));
            }
            else
            {
                PreviewLight.SelectLight(0, 0);
            }
        }
예제 #2
0
        public T CreateActor <T>(xc.UnitCacheInfo info, Quaternion rot, Monster.CreateParam createParam, bool showFashion = false, Action <Actor> cbResloaded = null) where T : Actor, new ()
        {
            if (mActorSet.ContainsKey(info.UnitID))
            {
                GameDebug.LogError("Actor's key conflict. Type: " + info.UnitID.type + ", UID: " + info.UnitID.obj_idx);
                return(null);
            }

            Vector3 scale = RoleHelp.GetPrefabScale(info);

            T actor = new T(); // Activator.CreateInstance<T>();

            actor.OnCreate(info, createParam);
            mActorSet.Add(info.UnitID, actor);

            if (info.UnitType == EUnitType.UNITTYPE_PLAYER)
            {
                var voaction = (Actor.EVocationType)ActorHelper.TypeIdToRoleId(info.AOIPlayer.type_idx);
                StartCoroutine(actor.mAvatarCtrl.CreateModelFromModleList(info.PosBorn, rot, scale, info.AOIPlayer.model_id_list, info.AOIPlayer.fashions, info.AOIPlayer.suit_effects, voaction, cbResloaded));
            }
            else
            {
                string prefab = RoleHelp.GetPrefabName(info);
//                 if(info.UnitType == EUnitType.UNITTYPE_MONSTER && info.AOIMonster != null)
//                 {
//                     if(info.AOIMonster.type_idx >= 201 && info.AOIMonster.type_idx < 208)
//                     {//守护
//                         prefab = prefab + "_pet_test";
//                     }
//                     else if (info.AOIMonster.type_idx >= 301 && info.AOIMonster.type_idx < 308)
//                     {//坐骑
//                         prefab = prefab + "_mount_test";
//                     }
//                 }
                StartCoroutine(actor.mAvatarCtrl.CreateModelFromPrefab(prefab, info.PosBorn, rot, scale, cbResloaded));
            }

            //actor.transform.position = info.PosBorn;
            actor.AfterCreate();

            return(actor);
        }
예제 #3
0
        public void UpdateUnitCache(bool doAll, UnitCacheDataFilter filter)
        {
            const int MAX_PROCESS_UNIT_PER_FRAME = 3;

            for (int i = 0; mUnitCacheData.Count != 0; ++i)
            {
                if (!doAll)
                {
                    if (i >= MAX_PROCESS_UNIT_PER_FRAME)
                    {
                        break;
                    }
                }

                UnitCacheInfo info = PopUnitCacheData();

                if (info == null)
                {
                    continue;
                }

                if (info.UnitType != EUnitType.UNITTYPE_PLAYER && info.UnitType != EUnitType.UNITTYPE_NPC &&
                    info.UnitType != EUnitType.UNITTYPE_MONSTER && info.UnitType != EUnitType.UNITTYPE_PET)
                {
                    continue;
                }

                if (filter != null && !filter(info))
                {
                    continue;
                }

                Actor actor = null;
                if (info.CacheType == UnitCacheInfo.EType.ET_Create)
                {
                    float rawY = info.PosBorn.y;
                    info.PosBorn = PhysicsHelp.GetPosition(info.PosBorn.x, info.PosBorn.z);
                    if (info.UnitType == EUnitType.UNITTYPE_PLAYER)
                    {
                        if (info.UnitID.Equals(mGame.LocalPlayerID))// 创建本地玩家
                        {
                            actor = mGame.GetLocalPlayer();
                            if (actor == null)
                            {
                                var vocation = (Actor.EVocationType)ActorHelper.TypeIdToRoleId(info.AOIPlayer.type_idx);
                                info.AOIPlayer.model_id_list = ReplaceModelList(info.AOIPlayer.model_id_list, vocation, false);
                                actor = ActorManager.Instance.CreateActor <LocalPlayer>(info, info.Rotation, null);
                                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_LOCALPLAYER_CREATE, new CEventBaseArgs(actor));
                            }
                        }
                        else// 创建其他玩家
                        {
                            if (ActorManager.Instance.ActorSet.ContainsKey(info.UnitID))
                            {
                                GameDebug.Log(string.Format("Player(ID: {0}) has been created.", info.UnitID.obj_idx));
                                continue;
                            }

                            actor = ActorManager.Instance.CreateActor <RemotePlayer>(info, info.Rotation, null);

                            // FIXME 创建本地玩家的时候也会发送该消息
                            ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_REMOTEPLAYER_CREATE, new CEventBaseArgs(actor));
                        }
                    }
                    else if (info.UnitType == EUnitType.UNITTYPE_NPC)
                    {
                        actor = ActorManager.Instance.CreateActor <NpcPlayer>(info, info.ClientNpc.Rotation, null);
                    }
                    else if (info.UnitType == EUnitType.UNITTYPE_MONSTER)
                    {
                        if (ActorManager.Instance.ActorSet.ContainsKey(info.UnitID))
                        {
                            GameDebug.LogError(string.Format("Monster(ID: {0}) has been created.", info.UnitID.obj_idx));
                            continue;
                        }
                        Monster.CreateParam createParam = new Monster.CreateParam();
                        createParam.is_pet = false;
                        if (ActorHelper.IsSummon(info.UnitID.obj_idx))
                        {
                            createParam.summon     = true;
                            createParam.summonType = Monster.MonsterType.SummonRemoteMonster;
                            if (info.ParentActor != null)
                            {
                                createParam.master = info.ParentActor.UID;
                                // 判断是不是本地召唤怪
                                if (createParam.master.Equals(Game.Instance.LocalPlayerID) == true)
                                {
                                    createParam.summonType = Monster.MonsterType.SummonLocalMonster;
                                }
                            }
                        }
                        var obj = ActorManager.Instance.CreateActor <Monster>(info, info.Rotation, createParam);
                    }
                    else if (info.UnitType == EUnitType.UNITTYPE_PET)
                    {
                        if (ActorManager.Instance.ActorSet.ContainsKey(info.UnitID))
                        {
                            GameDebug.LogError(string.Format("Pet(ID: {0}) has been created.", info.UnitID.obj_idx));
                            continue;
                        }

                        Monster.CreateParam createParam = new Monster.CreateParam();
                        createParam.is_pet = true;
                        createParam.summon = false;
                        if (info.ParentActor != null)
                        {
                            createParam.master = info.ParentActor.UID;
                        }

                        if (info.AOIPet.is_local)
                        {
                            ActorManager.Instance.CreateActor <LocalPet>(info, info.Rotation, createParam);
                        }
                        else
                        {
                            ActorManager.Instance.CreateActor <RemotePet>(info, info.Rotation, createParam);
                        }
                    }
                }
                else if (info.CacheType == UnitCacheInfo.EType.ET_Destroy)
                {
                    ActorManager.Instance.DestroyActor(info.UnitID, 0);
                }
                else
                {
                    GameDebug.LogError("Error Cache data!");
                }
            }
        }