public static NetworkInterface GetNetwork(this PeEntity entity) { if (null == entity) { return(null); } NetCmpt net = entity.GetCmpt <NetCmpt>(); if (null == net) { return(null); } return(net.network); }
private void RPC_S2C_InitData(uLink.BitStream stream, uLink.NetworkMessageInfo info) { ItemAsset.ItemObject item = stream.Read <ItemAsset.ItemObject>(); _pos = transform.position = stream.Read <Vector3>(); rot = transform.rotation = stream.Read <Quaternion>(); HP = stream.Read <float>(); MaxHP = stream.Read <float>(); Fuel = stream.Read <float>(); MaxFuel = stream.Read <float>(); authId = stream.Read <int>(); _ownerId = stream.Read <int>(); if (null == item) { Debug.LogWarning("CreationNetwork RPC_S2C_InitData null item."); return; } DragArticleAgent agent = DragArticleAgent.Create(DragArticleAgent.CreateItemDrag(item.protoId), _pos, Vector3.one, rot, _id, this, true); if (agent != null && null != agent.itemLogic && null != agent.itemLogic.gameObject) { OnSpawned(agent.itemLogic.gameObject); _entity = agent.itemLogic.gameObject.GetComponent <WhiteCat.CreationSkEntity>(); if (_entity != null) { NetCmpt net = _entity.GetComponent <NetCmpt>(); if (null == net) { net = _entity.gameObject.AddComponent <NetCmpt>(); } net.network = this; } } else { Debug.LogWarningFormat("CreationNetwork RPC_S2C_InitData invalide agent:{0}", item.protoId); } OnSkAttrInitEvent += SendBaseAttr; StartCoroutine(SyncMove()); }
protected virtual void ResetContorller() { PeEntity entity = EntityMgr.Instance.Get(Id); if (null != entity) { NetCmpt net = entity.GetCmpt <NetCmpt>(); if (null != net) { net.SetController(hasOwnerAuth); } } if (hasOwnerAuth) { enabled = false; } else { enabled = true; } InitForceData(); }
// public override void OnPeMsg(EMsg msg, params object[] args) // { // switch (msg) // { // case EMsg.Lod_Collider_Destroying: // canGetAuth = false; // lastAuthId = authId; // if (hasOwnerAuth) // { //#if UNITY_EDITOR // Debug.LogFormat("<color=blue>you lost [{0}]'s authority.</color>", Id); //#endif // authId = -1; // RPCServer(EPacketType.PT_InGame_LostController); // } // ResetContorller(); // break; // case EMsg.Lod_Collider_Created: // canGetAuth = true; // if (!hasAuth) // { // RPCServer(EPacketType.PT_InGame_SetController); // } // else // { // ResetContorller(); //#if UNITY_EDITOR // PlayerNetwork p = PlayerNetwork.GetPlayer(authId); // if (null != p) // Debug.LogFormat("<color=blue>{0} got [{1}]'s authority.</color>", p.RoleName, Id); //#endif // } // break; // } // } internal void CreateAi() { _entity = PeEntityCreator.Instance.CreateMonsterNet(Id, ExternId, Vector3.zero, Quaternion.identity, Vector3.one, Scale, _buffId); if (null == _entity) { return; } if (_fixId != -1) { SceneEntityCreatorArchiver.Instance.SetEntityByFixedSpId(_fixId, _entity); // if (_entity.monster) _entity.monster.Ride(false); } _entity.monster.Ride(_canride); _viewTrans = _entity.GetCmpt <PeTrans>(); if (null == _viewTrans) { Debug.LogError("entity has no ViewCmpt"); return; } _viewTrans.position = transform.position; _move = _entity.GetCmpt <Motion_Move>(); NetCmpt net = _entity.GetCmpt <NetCmpt>(); if (null == net) { net = _entity.Add <NetCmpt>(); } net.network = this; MonsterProtoDb.Item data = MonsterProtoDb.Get(ExternId); if (null == data) { gameObject.name = string.Format("TemplateId:{0}, Id:{1}", ExternId, Id); } else { gameObject.name = string.Format("{0}, TemplateId:{1}, Id:{2}", data.name, ExternId, Id); } if (-1 != _groupId) { AIGroupNetWork.OnMonsterAdd(_groupId, this, _entity); } if (-1 != _tdId) { AiTowerDefense.OnMonsterAdd(_tdId, this, _entity); if (_entity.monster) { _entity.monster.Ride(false); } } if (-1 != _dungeonId) { _entity.SetAttribute(AttribType.CampID, DungeonMonster.CAMP_ID); _entity.SetAttribute(AttribType.DamageID, DungeonMonster.DAMAGE_ID); if (_entity.monster) { _entity.monster.Ride(false); } } if (-1 != _colorType) { PeEntityCreator.InitMonsterSkinRandomNet(_entity, _colorType); } if (-1 != _playerId) { _entity.SetAttribute(AttribType.DefaultPlayerID, _playerId); } OnSpawned(_entity.GetGameObject()); if (_entity.Race == ERace.Mankind && _entity.proto == EEntityProto.Monster) { _move.AddNetTransInfo(transform.position, rot.eulerAngles, _move.speed, GameTime.Timer.Second); } else { _move.NetMoveTo(transform.position, Vector3.zero); } // if (_move is Motion_Move_Motor) //(_move as Motion_Move_Motor).NetMoveTo( transform.position,Vector3.zero); }