// Update is called once per frame void Update() { //Debug.LogError("===== NetMgr update !!! "); if (m_net != null) { m_net.update(); if (MainThreadFun.Count > 0) { for (int i = 0; i < MainThreadFun.Count; i++) { var child = MainThreadFun[i]; child(); } MainThreadFun.Clear(); } if (m_page == 2) { if (m_HearBeatState == 0) { m_HearBeatGapCount -= Time.deltaTime; if (m_HearBeatGapCount <= 0) { m_HearBeatState = 1; m_HearBeatSendTimeStamp = Time.realtimeSinceStartup; m_HearBeatSendTimeTicks = DateTime.Now.Ticks; m_HearBeatLastTime = UiUtil.GetNowTimeStamp(); CacheSendHeartBeat.Time = m_HearBeatLastTime; CoreEntry.netMgr.send((Int16)NetMsgDef.C_HEART_BEAT, CacheSendHeartBeat); } } else if (m_HearBeatState == 1) { if (Time.realtimeSinceStartup - m_HearBeatSendTimeStamp > HEAR_BEAT_TIME_OUT) { m_HearBeatState = 0; m_HearBeatGapCount = 0; //超时后直接重发 //AddHearBeatDelay((int)(HEAR_BEAT_TIME_OUT * 1000)); ++m_HearBeatTimeOutCount; //LogMgr.LogError("心跳超时 n:{0}", m_HearBeatTimeOutCount); } } } #if UNITY_EDITOR if (m_net.m_recordNet && Time.realtimeSinceStartup - m_StartRecordTime >= RECORD_GAP) { int sent, recv; lock (m_net) { sent = m_net.m_byteSent; recv = m_net.m_byteRecv; m_net.m_byteRecv = 0; m_net.m_byteSent = 0; } m_StartRecordTime = Time.realtimeSinceStartup; SaveNetFlow(sent, recv); } #endif } }
public GameObject LoadPet(MsgData_sSceneObjectEnterPet petStruct) { LuaTable petCfg = ConfigManager.Instance.HeroConfig.GetHeroConfig(petStruct.ConfigID); if (null == petCfg) { return(null); } float s = petCfg.Get <float>("scale"); Vector3 position = CommonTools.ServerPosToClient(petStruct.PosX, petStruct.PosY); Vector3 eulerAngle = CommonTools.ServerDirToClient(petStruct.Dir); Vector3 scale = new Vector3(s, s, s); if (petStruct.Job <= 0) { return(null); } int modelid = petCfg.Get <int>("model" + petStruct.Job); if (petStruct.Level > 0) { LuaTable petShengjieCfg = ConfigManager.Instance.HeroConfig.GetHeroShengjieConfig(petStruct.ConfigID * 100 + petStruct.Level); if (petShengjieCfg != null) { modelid = petShengjieCfg.Get <int>("model" + petStruct.Job); } } GameObject obj = CreateGameObject(modelid, position, eulerAngle, scale); if (obj == null) { return(null); } //obj.transform.localScale = Vector3.one; ActorObj actorObject = null; actorObject = obj.GetComponent <ActorObj>(); if (null != actorObject) { Object.DestroyImmediate(actorObject); } PlayerAgent agent = obj.GetComponent <PlayerAgent>(); if (null != agent) { agent.enabled = false; } PetObj pet = obj.AddComponent <PetObj>(); pet.Starlevel = petStruct.Level; pet.Qua = petStruct.Qua; pet.OwnName = UiUtil.GetNetString(petStruct.RoleName); pet.SetMaster(petStruct.Owner); //Debug.LogError("pet :" + petStruct.Owner + " id:" + petStruct.ConfigID); pet.Init(modelid, petStruct.ConfigID, petStruct.Guid); pet.ServerID = petStruct.Guid; pet.InitSpeed(CommonTools.ServerValueToClient(petStruct.Speed)); CoreEntry.gActorMgr.AddActorObj(pet); //宠物创建时,需要检查主人的显示隐藏属性 if (pet.m_MasterActor && !pet.m_MasterActor.Visiable) { pet.HideSelf(); } //ActorObj owner = CoreEntry.gActorMgr.GetPlayerActorByServerID(petStruct.Owner); //if (null != owner) //{ // if (owner.mActorType == ActorType.AT_LOCAL_PLAYER) // { // pet.ChangeWeapon(PlayerData.Instance.GetWeaponModelID()); // } // else // { // MsgData_sSceneObjectEnterHuman ownerData = CoreEntry.gSceneObjMgr.GetEntityData(petStruct.Owner) as MsgData_sSceneObjectEnterHuman; // if (null != ownerData) // { // pet.ChangeWeapon(GetWeaponModelID(ownerData.FashionState == 0 ? ownerData.FashionWeapon : 0, ownerData.ShenBin, ownerData.Weapon, ownerData.Prof)); // } // } //} return(obj); }