コード例 #1
0
ファイル: InterObject.cs プロジェクト: wuhuolong/MaxBooks
        public void FixPos()
        {
            Transform trans = m_ModelParent.transform;

            trans.position = PhysicsHelp.GetPosition(trans.position.x, trans.position.z);
            //trans.position = InstanceHelper.ClampInWalkableRange(trans.position);

            //if (Mathf.Approximately(trans.position.y, PhysicsHelp.ILLEGAL_HEIGHT))
            //{
            //    GameDebug.LogWarning(string.Format("InterObject ILLEGAL_HEIGHT {0}", trans.position.ToString()));
            //    trans.position = InstanceHelper.ClampInWalkableRange(trans.position);
            //}
        }
コード例 #2
0
        void HandleServerData(ushort protocol, byte[] data)
        {
            switch (protocol)
            {
            case NetMsg.MSG_MAP_LINE_STATE:     // 处理换线逻辑
            {
                S2CMapLineState msg = S2CPackBase.DeserializePack <S2CMapLineState>(data);
                SceneHelp.Instance.ProcessLineInfo(msg);
            }
            break;

            case NetMsg.MSG_PLAYER_DISPLAY_INFO:     // 处理查看其他玩家信息
            {
                var msg = S2CPackBase.DeserializePack <S2CPlayerDisplayInfo>(data);

                var equip_infos = msg.equips;
                m_OtherPlayerEquip.Clear();
                foreach (var info in equip_infos)
                {
                    var equip_goods = GoodsHelper.CreateEquipGoodsFromNet(info);
                    equip_goods.IsInstalledByOtherPlayer = true;
                    m_OtherPlayerEquip.Add(equip_goods);
                }
                Equip.EquipHelper.CalculatorSuitNum(m_OtherPlayerEquip);

                m_OtherPlayerEquipPosInfos = Equip.EquipHelper.GetEquipPosInfosByPkgInfos(msg.strengths, msg.baptizes);

                ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_CLICKPLAY_DISPLAY_INFO, new CEventEventParamArgs(msg.info, m_OtherPlayerEquip, m_OtherPlayerEquipPosInfos));
            }
            break;

            case NetMsg.MSG_MAP_GET_HANG_POS:     // 请求挂机位置
            {
                S2CMapGetHangPos msg = S2CPackBase.DeserializePack <S2CMapGetHangPos>(data);

                Vector3 pos = new Vector3(msg.pos.px * GlobalConst.UnitScale, 0f, msg.pos.py * GlobalConst.UnitScale);
                pos = PhysicsHelp.GetPosition(pos.x, pos.z);
                TargetPathManager.Instance.GoToConstPosition(msg.dungeon_id, msg.line_id, pos, null, () => { InstanceManager.Instance.SetOnHook(true); });
            }
            break;

            default:
                break;
            }
        }
コード例 #3
0
ファイル: ActorManager.cs プロジェクト: wuhuolong/MaxBooks
        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!");
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 通过角色id来获取角色在场景里面的偏移位置
        /// </summary>
        /// <param name="type_id"></param>
        /// <returns></returns>
        public static Vector3 GetPositionInScene(uint type_id, float x, float z)
        {
            Vector3 pos = PhysicsHelp.GetPosition(x, z);

            return(pos);
        }
コード例 #5
0
        void HandleServerData(ushort pro, byte[] data)
        {
            switch (pro)
            {
            case NetMsg.MSG_MWAR_DEBUG_BULLET:     // 响应服务端的子弹位置调试的消息
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }
            }
            break;

            case NetMsg.MSG_MWAR_DEBUG_WORD:     // 绘制服务端发来的文字
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                S2CMwarDebugWord debugWord = S2CPackBase.DeserializePack <S2CMwarDebugWord>(data);

                Vector3    pos    = PhysicsHelp.GetPosition(debugWord.px / 100.0f, debugWord.py / 100.0f);
                Object     prefab = Resources.Load("core/prefabs/AttackSphere");
                GameObject testGo = GameObject.Instantiate(prefab, pos, Quaternion.identity) as GameObject;
                testGo.transform.localScale = Vector3.one * (1.0f) / 100.0f * 2;
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugWord.color);
                testGo.GetComponent <Renderer>().material.SetColor("_Color", col);

                testGo.AddComponent <DelayDestroyComponent>().DelayTime = debugWord.time;

                UI3DText ui3dText = testGo.AddComponent <UI3DText>();
                ui3dText.Text      = System.Text.Encoding.UTF8.GetString(debugWord.word);
                ui3dText.TextColor = col;
                ui3dText.FontSize  = (int)debugWord.size;
                ui3dText.UpdatePosition(pos, Vector3.zero, Vector3.zero);
                //ui3dText.SetOwnerTrans(null);

                break;
            }

            case NetMsg.MSG_MWAR_DEBUG_POS:     // 绘制服务端发送过来的位置
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                var debugPos = S2CPackBase.DeserializePack <S2CMwarDebugPos>(data);

                Vector3    pos    = PhysicsHelp.GetPosition(debugPos.px / 100.0f, debugPos.py / 100.0f);
                Object     prefab = Resources.Load("core/prefabs/AttackSphere");
                GameObject testGo = GameObject.Instantiate(prefab, pos, Quaternion.identity) as GameObject;
                testGo.transform.localScale = Vector3.one * debugPos.radius / 100.0f * 2;
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugPos.color);
                testGo.GetComponent <Renderer>().material.SetColor("_Color", col);

                testGo.AddComponent <DelayDestroyComponent>().DelayTime = 0.5f;
            }
            break;

            case NetMsg.MSG_MWAR_DEBUG_LINE:     // 绘制服务端发送过来的线段
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                S2CMwarDebugLine debugLine = S2CPackBase.DeserializePack <S2CMwarDebugLine>(data);

                float   height    = PhysicsHelp.GetHeight(debugLine.px1 / 100.0f, debugLine.py1 / 100.0f);
                Vector3 pos1      = new Vector3(debugLine.px1 / 100.0f, height, debugLine.py1 / 100.0f);
                Vector3 pos2      = new Vector3(debugLine.px2 / 100.0f, height, debugLine.py2 / 100.0f);
                Vector3 dir       = (pos2 - pos1);
                Vector3 dirNormal = dir.normalized;
                if (dirNormal == Vector3.zero)
                {
                    return;
                }

                Vector3 middlePos = (pos1 + pos2) / 2.0f;

                Object     prefab = Resources.Load("core/prefabs/AttackCube");
                GameObject testGo = GameObject.Instantiate(prefab, middlePos, Quaternion.identity) as GameObject;

                testGo.transform.localScale = new Vector3(debugLine.radius * 2.0f / 100.0f, debugLine.radius * 2.0f / 100.0f, (pos2 - pos1).magnitude);
                testGo.transform.rotation   = Quaternion.LookRotation(dirNormal, Vector3.up);
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugLine.color);
                testGo.GetComponent <Renderer>().material.SetColor("_Color", col);

                testGo.AddComponent <DelayDestroyComponent>().DelayTime = debugLine.time;
            }
            break;

            case NetMsg.MSG_MWAR_DEBUG_CIRCLE:    // 绘制服务端发送过来的圆环
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                var     debugCircle = S2CPackBase.DeserializePack <S2CMwarDebugCircle>(data);
                float   height      = PhysicsHelp.GetHeight(debugCircle.px / 100.0f, debugCircle.py / 100.0f);
                Vector3 pos         = new Vector3(debugCircle.px / 100.0f, height, debugCircle.py / 100.0f);

                Object     prefab = Resources.Load("Core/Prefabs/AttackCircle");
                GameObject testGo = GameObject.Instantiate(prefab, pos, Quaternion.identity) as GameObject;

                testGo.transform.localScale = new Vector3(debugCircle.size / 100.0f, 1.0f, debugCircle.size / 100.0f);
                testGo.transform.rotation   = Quaternion.identity;
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugCircle.color);
                testGo.GetComponentInChildren <Renderer>().material.SetColor("Tint Color", col);
                testGo.AddComponent <DelayDestroyComponent>().DelayTime = debugCircle.time * GlobalConst.MilliToSecond;
            } break;
            }
        }