Пример #1
0
        public bool AddSamples(NativeArray <float> interleavedSamples)
        {
            if (_encoderPtr == IntPtr.Zero)
            {
                // Error will have been triggered earlier
                return(false);
            }

            bool success = false;

            // Recorder clips may send empty buffers, in which case success will still be true.
            success = ProResWrapper.AddAudioSamples(_encoderPtr, interleavedSamples.ToArray(), interleavedSamples.Count());
            if (!success)
            {
                Debug.LogError("Failed to add audio samples to ProRes encoder");
            }
            return(success);
        }
    protected override void OnUpdate()
    {
        EntityCommandBuffer commandBuffer
            = CommandBufferSystem.CreateCommandBuffer();
        NativeArray <LeoPlayerGameStatus> leoPlayerGameStatuses
            = leoPlayerGameStatusesQuery.ToComponentDataArray <LeoPlayerGameStatus>(Allocator.TempJob);

        /*NativeArray<ReceiveRpcCommandRequestComponent> leoPlayerConnectReveive  // 由于发送请求需要对于每个人都发所以可以直接通过系统获取
         *  = leoPlayerGameStatusesQuery.ToComponentDataArray<ReceiveRpcCommandRequestComponent>(Allocator.TempJob);*/
        NativeArray <LeoGameStatus> leoGameStatusesArray = new NativeArray <LeoGameStatus>(new LeoGameStatus[] { new LeoGameStatus {
                                                                                                                     theGameStatus = TheGameStatus.NoReady
                                                                                                                 } }, Allocator.TempJob);

        // 删除标识防止一直执行
        commandBuffer.DestroyEntity(GetSingletonEntity <ServerGameStatusSendSystemController>());

        // 遍历每个玩家的状态进行状态判断
        var handle1 = Entities
                      .WithoutBurst()
                      .ForEach((Entity entity, in LeoGameStatus gameStatus) =>
        {
            var countPlayer = leoPlayerGameStatuses.Length;

            if (leoPlayerGameStatuses.Count(s => s.playerGameStatus == PlayerGameStatus.NotReady) == countPlayer)
            {
                leoGameStatusesArray[0] = new LeoGameStatus {
                    theGameStatus = TheGameStatus.NoReady
                };
                //commandBuffer.SetComponent<LeoGameStatus>(entity,new LeoGameStatus { theGameStatus= TheGameStatus.NoReady });
            }
            else if (leoPlayerGameStatuses.Count(s => s.playerGameStatus == PlayerGameStatus.Ready) < countPlayer)
            {
                leoGameStatusesArray[0] = new LeoGameStatus {
                    theGameStatus = TheGameStatus.PartReady
                };
                //commandBuffer.SetComponent<LeoGameStatus>(entity, new LeoGameStatus { theGameStatus = TheGameStatus.PartReady });
            }
            else if (countPlayer < 2)    // 解决只有一个玩家的时候可能提示游戏已经准备完成的问题
            {
                leoGameStatusesArray[0] = new LeoGameStatus {
                    theGameStatus = TheGameStatus.PartReady
                };
            }
            else if (leoPlayerGameStatuses.Count(s => s.playerGameStatus == PlayerGameStatus.Ready) == countPlayer)
            {
                leoGameStatusesArray[0] = new LeoGameStatus {
                    theGameStatus = TheGameStatus.AllReady
                };
                //commandBuffer.SetComponent<LeoGameStatus>(entity, new LeoGameStatus { theGameStatus = TheGameStatus.AllReady });
                // AllReady 会触发球生成

                /*World.GetOrCreateSystem<BallSpawnerSystem>(); // 这个只能在服务端添加; 出现不能在ForEach中添加动态代码的错误*/
                var tEnt = commandBuffer.CreateEntity();
                commandBuffer.AddComponent <BallSpawnerSystemController>(tEnt);
            }
            else if (leoPlayerGameStatuses.Count(s => s.playerGameStatus == PlayerGameStatus.Playing) == countPlayer)
            {
                leoGameStatusesArray[0] = new LeoGameStatus {
                    theGameStatus = TheGameStatus.Playing
                };
                //commandBuffer.SetComponent<LeoGameStatus>(entity, new LeoGameStatus { theGameStatus = TheGameStatus.Playing });
            }

            commandBuffer.SetComponent <LeoGameStatus>(entity, leoGameStatusesArray[0]);
        }).Schedule(Dependency);

        handle1.Complete();

        //完成游戏状态更新后,同步状态信息给客户端
        var handle2 = Entities
                      .ForEach((Entity ent, ref NetworkIdComponent id) =>
        {
            var entity = commandBuffer.CreateEntity();
            commandBuffer.AddComponent <LeoGameStatus>(entity, leoGameStatusesArray[0]);
            commandBuffer.AddComponent <SendRpcCommandRequestComponent>(entity,
                                                                        new SendRpcCommandRequestComponent
            {
                TargetConnection = ent
            });
        }).Schedule(handle1);

        handle2.Complete();


        Dependency = leoPlayerGameStatuses.Dispose(handle2);
        Dependency = leoGameStatusesArray.Dispose(Dependency);


        //Job.WithCode(() =>
        //{
        //    for(var i=0;i< leoPlayerGameStatuses.Length; i++)
        //    {
        //        var entity= commandBuffer.CreateEntity();
        //        commandBuffer.AddComponent<LeoGameStatus>(entity, leoGameStatusesArray[0]);
        //        commandBuffer.AddComponent<SendRpcCommandRequestComponent>(entity,
        //            new SendRpcCommandRequestComponent
        //            {
        //                TargetConnection= leoPlayerConnectReveive[i].SourceConnection
        //            });
        //    }

        //}).Schedule();
    }
Пример #3
0
 public int Invoke(NativeArray <T> arg0)
 {
     return(arg0.Count(Predicate));
 }