Пример #1
0
        void FetchSelfTransforms(List <SyncGOTransforms_TransformMono> transformsList, UDPBox udpBox, IPEndPoint ipEndPoint, bool isFetchAll = false)
        {
            UDPBox_GameThreadMediator.Instance?.EnqueueToUpdateQueue(() =>
            {
                var package = new SyncGOTransformsPackage(mTemplate.HeadBytes);
                package.Op  = SyncGOTransformsPackage.EOperate.Push;

                for (int i = 0, iMax = transformsList.Count; i < iMax; i++)
                {
                    var transformMono = transformsList[i];
                    if (!transformMono.isSelfControl && !isFetchAll)
                    {
                        continue;
                    }

                    var transformInfo = new SyncGOTransformData();

                    transformInfo.NetworkID = transformMono.networkID;
                    transformInfo.Active    = transformMono.gameObject.activeSelf;
                    transformInfo.Pos_X     = transformMono.transform.position.x;
                    transformInfo.Pos_Y     = transformMono.transform.position.y;
                    transformInfo.Pos_Z     = transformMono.transform.position.z;
                    transformInfo.Euler_X   = transformMono.transform.eulerAngles.x;
                    transformInfo.Euler_Y   = transformMono.transform.eulerAngles.y;
                    transformInfo.Euler_Z   = transformMono.transform.eulerAngles.z;
                    transformInfo.SCALE_X   = transformMono.transform.localScale.x;
                    transformInfo.SCALE_Y   = transformMono.transform.localScale.y;
                    transformInfo.SCALE_Z   = transformMono.transform.localScale.z;

                    package.TransformList.Add(transformInfo);
                }

                udpBox.SendMessage(package.Serialize(), ipEndPoint);
            });
        }
Пример #2
0
        IEnumerator Start()
        {
            mPackageTemplate = new SyncGOTransformsPackage(udpBox.PackageHeadBytes);
            var waitForSecond = new WaitForSeconds(delay);

            while (true)
            {
                if (udpBox.State != UDPBoxContainer.EState.HasClients && udpBox.State != UDPBoxContainer.EState.HasServer)
                {
                    yield return(null);

                    continue;
                }

                if (udpBox.isMaster)
                {
                    mPackageTemplate.TransformList.Clear();
                    for (int i = 0, iMax = udpBox.ClientIPConnectInfoList.Count; i < iMax; i++)
                    {
                        var client = udpBox.ClientIPConnectInfoList[i];

                        mPackageTemplate.Op = SyncGOTransformsPackage.EOperate.Fetch;
                        udpBox.SendUDPMessageToRandomPort(mPackageTemplate.Serialize(), client);
                    }
                }
                else
                {
                    mPackageTemplate.Op = SyncGOTransformsPackage.EOperate.FetchAll;
                    udpBox.SendUDPMessageToRandomPort(mPackageTemplate.Serialize(), udpBox.MasterIPConnectInfo);
                }

                yield return(waitForSecond);
            }
        }
Пример #3
0
 public SyncGOTransformsHandler(byte[] packageHeadBytes)
 {
     transformsList = new List <SyncGOTransforms_TransformMono>(8);
     mTemplate      = new SyncGOTransformsPackage(packageHeadBytes);
 }