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()); }
/// <summary> /// 仅在创建游戏实体时初始化, 拖拽效果不会调用 /// </summary> public void InitController(int itemInstanceId) { _creationController = GetComponent <CreationController>(); _srcItem = ItemAsset.ItemMgr.Instance.Get(itemInstanceId); _lifeCmpt = _srcItem.GetCmpt <ItemAsset.LifeLimit>(); _energyCmpt = _srcItem.GetCmpt <ItemAsset.Energy>(); // PeEntity int id = WorldInfoMgr.Instance.FetchNonRecordAutoId(); _creationPeEntity = EntityMgr.Instance.InitEntity(id, gameObject); _creationPeEntity.carrier = this as CarrierController; // ViewCmpt var view = gameObject.AddComponent <CreationViewCmpt>(); _creationPeEntity.viewCmpt = view; view.Init(creationController); // PeTrans PeTrans tr = gameObject.AddComponent <PeTrans>(); _creationPeEntity.peTrans = tr; tr.SetModel(transform); tr.bound = _creationController.bounds; // SkEntity _creationSkEntity = gameObject.AddComponent <CreationSkEntity>(); _creationSkEntity.Init(this); _creationPeEntity.skEntity = _creationSkEntity; _creationSkEntity.m_Attrs = new PESkEntity.Attr[5]; for (int i = 0; i < _creationSkEntity.m_Attrs.Length; i++) { _creationSkEntity.m_Attrs[i] = new PESkEntity.Attr(); } _creationSkEntity.m_Attrs[0].m_Type = AttribType.Hp; _creationSkEntity.m_Attrs[0].m_Value = _lifeCmpt.floatValue.current; _creationSkEntity.m_Attrs[1].m_Type = AttribType.HpMax; _creationSkEntity.m_Attrs[1].m_Value = _lifeCmpt.valueMax; _creationSkEntity.m_Attrs[2].m_Type = AttribType.CampID; _creationSkEntity.m_Attrs[2].m_Value = 0; _creationSkEntity.m_Attrs[3].m_Type = AttribType.DamageID; _creationSkEntity.m_Attrs[3].m_Value = 0; _creationSkEntity.m_Attrs[4].m_Type = AttribType.DefaultPlayerID; _creationSkEntity.m_Attrs[4].m_Value = 99; _creationSkEntity.onHpChange += (skEntity, deltaHp) => { _lifeCmpt.floatValue.current = _creationSkEntity.GetAttribute(AttribType.Hp); OnHpChange(deltaHp, _lifeCmpt.floatValue.current <= 0); }; _creationSkEntity.InitEntity(); // Physics _rigidbody = gameObject.AddComponent <Rigidbody>(); _rigidbody.mass = mass; _rigidbody.centerOfMass = centerOfMass; // 椭球体的惯性张量 作为基数 var size = creationController.bounds.size; _rigidbody.inertiaTensor = Vector3.Scale( inertiaTensorScale, _rigidbody.mass * 0.05f * new Vector3( size.y * size.y + size.z * size.z, size.x * size.x + size.z * size.z, size.x * size.x + size.y * size.y)); _rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous; _rigidbody.interpolation = RigidbodyInterpolation.None; _rigidbody.useGravity = true; _rigidbody.isKinematic = true; _rigidbody.maxAngularVelocity = PEVCConfig.instance.maxRigidbodyAngularSpeed; InitDrags(out _standardDrag, out _underwaterDrag, out _standardAngularDrag, out _underwaterAngularDrag); // Network InitNetwork(); // Weapons LoadParts(ref _weapons); for (int i = 0; i < _weapons.Length; i++) { _weapons[i].Init(i); } SetOwner(null); // InitOtherThings InitOtherThings(); // Damage Controller gameObject.AddComponent <CreationDamageController>().Init(this); // LOD gameObject.AddComponent <DragCreationLodCmpt>(); gameObject.AddComponent <DragItemLogicCreation>(); }