private static async ETVoid CreateOtherCube(int account, Vector3 InitPosition, ETTaskCompletionSource <OtherCube> tcs) { try { GameObject resObj = await ETModel.Game.Scene.GetComponent <ResourcesAsyncComponent>().LoadAssetAsync <GameObject>(Assets.LoadAssetAsync("Assets/Bundles/Prefab/OtherCube.prefab", typeof(GameObject))); ReferenceCollector rc = resObj.GetComponent <ReferenceCollector>(); GameObject otherCubeObj = GameObject.Instantiate <GameObject>(rc.Get <GameObject>("OtherCube")); GameObject otherDirCubeObj = GameObject.Instantiate <GameObject>(rc.Get <GameObject>("OtherDirCube")); GameObject ganFire = GameObject.Instantiate <GameObject>(rc.Get <GameObject>("gunFire")); OtherCube otherCube = ComponentFactory.Create <OtherCube, int, GameObject, GameObject>(account, otherCubeObj, otherDirCubeObj, false); //添加攻击脚本 OtherCubeAttackComponent otherCubeAttackComponent = otherCube.AddComponent <OtherCubeAttackComponent, GameObject>(ganFire); //添加网络同步组件 OtherCubeNetSyncComponent otherCubeNetSyncComponent = otherCube.AddComponent <OtherCubeNetSyncComponent, int, Vector3>(account, InitPosition); tcs.SetResult(otherCube); } catch (Exception e) { Log.Error(e); tcs.SetResult(null); } }
/// <summary> /// 移除一个其它Cube /// </summary> public void RemoveOneOtherCube(int Account) { if (otherCubeAccountToNetSyncComponent.TryGetValue(Account, out OtherCubeNetSyncComponent otherCubeNet)) { otherCubeAccountToNetSyncComponent.Remove(Account); OtherCube otherCube = otherCubeNet.otherCube; otherCube.Dispose(); } else { Debug.LogError("错误,没有找到需要移除的OtherCube"); } }
protected override async ETTask Run(ETModel.Session session, G2C_OtherPlayerEnterMap message) { Log.Info("其它玩家进入Map: " + message.Account); OtherCubeNetSyncComponent NetSyncComponent = Game.Scene.GetComponent <OtherCubeManagerComponent>() .GetNetSyncComponentByOtherCubeAccount(message.Account); if (NetSyncComponent != null) { NetSyncComponent.NetWorkAsyncPosition(new Vector3(message.PositionX, message.PositionY, message.PositionZ), Quaternion.identity, Vector3.zero); } else { OtherCube otherCube = await OtherCubeFactory.Create(message.Account, new Vector3(message.PositionX, message.PositionY, message.PositionZ)); } await ETTask.CompletedTask; }
public void Start() { otherCube = this.GetParent <OtherCube>(); //获取Transform OtherCube_Transform = otherCube.otherCube_GameObject.GetComponent <Transform>(); OtherCube_Transform.position = InitPosition; OtherDirCube_Transform = otherCube.otherDirCube_GameObject.GetComponent <Transform>(); OtherDirCube_Transform.position = InitPosition; //获取Rigidbody OtherDirCube_Rigidbody = OtherDirCube_Transform.GetComponent <Rigidbody>(); //添加网络组件到集中管理 Game.Scene.GetComponent <OtherCubeManagerComponent>() .AddNetSyncComponentByOtherCubeAccount(Account, this); //获取攻击控制组件 otherCubeAttackComponent = otherCube.GetComponent <OtherCubeAttackComponent>(); }