Ejemplo n.º 1
0
        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);
            }
        }
        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>();
        }