コード例 #1
0
        public void DrawNeutronWay(Neutron neutron)
        {
            if (neutron.CollisionPoint.Count == 0)
            {
                return;
            }

            var neutronCollisionSeries = new LineSeries
            {
                StrokeThickness             = 2,
                MarkerSize                  = 3,
                MarkerStroke                = OxyColors.Black,
                MarkerType                  = MarkerType.Circle,
                CanTrackerInterpolatePoints = false,
                //Title = $"Neutron {(SimulateOnePlotModel.Series.Count + 1).ToString("E2")}; MeanFreeLenght: {(neutron.AverageFreePathLength).ToString("E2")}; TotalLenght: {(neutron.PathLength).ToString("E2")}",
                Smooth = false,
            };

            neutron.CollisionPoint.ForEach(p => neutronCollisionSeries.Points.Add(new DataPoint(p.X, p.Y)));
            SimulateOnePlotModel.Series.Add(neutronCollisionSeries);
            SimulateOnePlot.ResetAllAxes();
            SimulateOnePlot.InvalidatePlot();
            neutron.CollisionPoint.ForEach(p => Console.WriteLine(p.X + @"; " + p.Y));
            Console.WriteLine();
        }
コード例 #2
0
    protected static void HandleJoinChannel(int ID, byte[] Player)
    {
        Player playerJoined = Player.DeserializeObject <Player>();

        //===============================================================================================================================
        Neutron.Enqueue(() => Neutron.Fire(Neutron.onPlayerJoinedChannel, new object[] { playerJoined, ID }), ref monoBehaviourActions);
    }
コード例 #3
0
    protected static void HandleJoinRoom(int roomID, byte[] player)
    {
        Player playerJoined = player.DeserializeObject <Player>();

        //=================================================================================================================================
        Neutron.Enqueue(() => Neutron.Fire(Neutron.onPlayerJoinedRoom, new object[] { playerJoined, roomID }), ref monoBehaviourActions);
    }
コード例 #4
0
 //============================================================================================================//
 protected static void HandleConnected(string status, int uniqueID)
 {
     Logger(status);
     //=============================================
     Neutron.myPlayer = new Player(uniqueID, null);
     //=============================================
     Neutron.Enqueue(() => Neutron.Fire(Neutron.onNeutronConnected, new object[] { true }), ref monoBehaviourActions);
 }
コード例 #5
0
 private void FixedUpdate()
 {
     if (!Neutron.IsMine(isMine))
     {
         GetRigidbody.velocity        = newVelocity;
         GetRigidbody.angularVelocity = newAngularVelocity;
     }
 }
コード例 #6
0
            public void NeutronTest()
            {
                var n = new Neutron(1, true);

                Assert.AreEqual(1.674929 * Math.Pow(10, -27), n.RestMass);
                Assert.AreEqual(0, n.RelativeCharge);
                Assert.AreEqual(1, n.BaryonNumber);
            }
コード例 #7
0
 //* Inicializa o cliente do servidor, o servidor também é um cliente dele mesmo.
 public void Initialize(Neutron neutron)
 {
     This = neutron;
     //* Inicia o timer do servidor....
     NetworkTime.Stopwatch.Start();
     //* Marca que a instância é do servidor.
     IsServer = true;
 }
コード例 #8
0
    protected static void HandleNavMeshAgent(int ownerID, Vector3 inputPoint)
    {
        NeutronObject obj = neutronObjects[ownerID];

        if (obj.agent != null)
        {
            Neutron.Enqueue(() => obj.agent.SetDestination(inputPoint), ref monoBehaviourActions);
        }
    }
コード例 #9
0
 void Start()
 {
     if (Neutron.IsServer(gameObject))
     {
         Destroy(this);
     }
     //==============================================//
     GetRigidbody = GetComponent <Rigidbody>();
 }
コード例 #10
0
 private bool OnCreatePlayer(NeutronStream.IReader reader, bool isServer, bool isMine, NeutronPlayer player, Neutron instance)
 {
     if (instance.EndPlayer(reader, out var pos, out var rot))
     {
         NeutronSchedule.ScheduleTask(() =>
         {
             Neutron.NetworkSpawn(isServer, false, player, _player, pos, rot, instance);
         });
     }
コード例 #11
0
 void Start()
 {
     if (Neutron.IsServer(gameObject))
     {
         Destroy(this);
     }
     //==============================================//
     GetAnimator = GetComponent <Animator>();
 }
コード例 #12
0
 private void CreateVirtualClients()
 {
     for (int i = 0; i < VirtualPlayerCount; i++)
     {
         Neutron neutron = Neutron.Create(ClientMode.Virtual);
         Register(neutron);
         neutron.Connect();
     }
 }
コード例 #13
0
 protected override void OnPlayerConnected(NeutronPlayer player, bool isMine, Neutron neutron)
 {
     base.OnPlayerConnected(player, isMine, neutron);
     {
         if (isMine)
         {
             neutron.JoinChannel(0);
         }
     }
 }
コード例 #14
0
    protected static void HandlePlayerDisconnected(byte[] player)
    {
        Player playerDisconnected = player.DeserializeObject <Player>();
        //===================================================================================\\
        NeutronObject obj = neutronObjects[playerDisconnected.ID];

        //===================================================================================\\
        Neutron.Enqueue(() => Destroy(obj.gameObject), ref monoBehaviourActions);
        //===================================================================================\\
        neutronObjects.Remove(obj.Infor.ownerID);
    }
コード例 #15
0
        /// <summary>
        ///* Inicia a conexão, chamado automaticamente se "AutoStartConnection" é true;
        /// </summary>
        protected void Connect(int index = 0, int timeout = 3, Authentication authentication = null)
        {
#if !UNITY_SERVER || UNITY_EDITOR
            Neutron neutron = Neutron.Client ?? Neutron.Create();
            if (!neutron.IsConnected)
            {
                Register(neutron);
            }
            neutron.Connect(index, timeout, authentication);
#endif
        }
コード例 #16
0
 void RPC()
 {
     using (NeutronWriter streamParams = new NeutronWriter())
     {
         streamParams.Write(transform.position);
         streamParams.Write(transform.rotation);
         streamParams.Write(GetRigidbody.velocity);
         streamParams.Write(GetRigidbody.angularVelocity);
         //======================================================================================================================================
         Neutron.RPC(isMine, 255, ValidationPacket.Movement, syncTime, streamParams, sendTo, false, Broadcast.Channel, (ProtocolType)(int)protocolType);
     }
 }
コード例 #17
0
 // Update is called once per frame
 void Update()
 {
     if (Neutron.IsMine)
     {
         if (GetParameters(out object[] parameters))
         {
             using (NeutronWriter streamParams = new NeutronWriter())
             {
                 streamParams.Write(parameters.Serialize());
                 //======================================================================================================================================
                 Neutron.RPC(Neutron.NeutronObject, 254, ValidationPacket.None, syncTime, streamParams, SendTo.Others, false, Broadcast.Channel, (ProtocolType)(int)protocolType);
             }
         }
     }
 }
コード例 #18
0
 void Start()
 {
     agent = GetComponent <NavMeshAgent>();
     //==============================================//
     if (Application.isEditor)
     {
         agent.radius = 0.01f;
     }
     //==============================================//
     agent.gameObject.GetComponent <Rigidbody>().isKinematic = true;
     //==============================================//
     if (Neutron.IsServer(gameObject))
     {
         Destroy(this);
     }
 }
コード例 #19
0
 void Update()
 {
     if (Neutron.IsMine(isMine))
     {
         if (Input.GetMouseButtonDown(0))
         {
             if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, 500))
             {
                 if (hit.transform.CompareTag("ground"))
                 {
                     Neutron.MoveWithMousePointer(hit.point);
                 }
             }
         }
     }
 }
コード例 #20
0
ファイル: FissileFuel.cs プロジェクト: fourls/235
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("Neutron"))
     {
         Neutron neutron = other.gameObject.GetComponent <Neutron>();
         float   chance  = 1f / (float)neutron.speedLevel;
         if (chance >= Random.value)
         {
             Destroy(other.gameObject);
             Fission();
         }
         else
         {
             neutron.Bounce(other.GetContact(0).normal);
         }
     }
 }
コード例 #21
0
    protected static void HandleInstantiate(Vector3 pos, Quaternion rot, string playerPrefab, byte[] mPlayer)
    {
        //================================================================================================================================\\
        Player playerInstantiated = mPlayer.DeserializeObject <Player>();

        //================================================================================================================================\\
        Neutron.Enqueue(() =>
        {
            GameObject playerPref = Resources.Load(playerPrefab, typeof(GameObject)) as GameObject;
            if (playerPref != null)
            {
                Neutron.onPlayerInstantiated(playerInstantiated, pos, rot, playerPref);
            }
            else
            {
                LoggerError($"CLIENT: -> Unable to load prefab {playerPrefab}");
            }
        }, ref monoBehaviourActions);
    }
コード例 #22
0
 //* Registra os eventos da instância.
 private void Register(Neutron instance)
 {
     instance.OnChannelsReceived           += OnChannelsReceived;
     instance.OnError                      += OnError;
     instance.OnMessageReceived            += OnMessageReceived;
     instance.OnNeutronAuthenticated       += OnNeutronAuthenticated;
     instance.OnNeutronConnected           += OnNeutronConnected;
     instance.OnPlayerConnected            += OnPlayerConnected;
     instance.OnPlayerCreatedRoom          += OnPlayerCreatedRoom;
     instance.OnPlayerCustomPacketReceived += OnPlayerCustomPacketReceived;
     instance.OnPlayerDisconnected         += OnPlayerDisconnected;
     instance.OnPlayerJoinedChannel        += OnPlayerJoinedChannel;
     instance.OnPlayerJoinedRoom           += OnPlayerJoinedRoom;
     instance.OnPlayerLeftChannel          += OnPlayerLeftChannel;
     instance.OnPlayerLeftRoom             += OnPlayerLeftRoom;
     instance.OnPlayerNicknameChanged      += OnPlayerNicknameChanged;
     instance.OnPlayerPropertiesChanged    += OnPlayerPropertiesChanged;
     instance.OnRoomPropertiesChanged      += OnRoomPropertiesChanged;
     instance.OnRoomsReceived              += OnRoomsReceived;
 }
コード例 #23
0
 protected static void HandleCreateRoom(Room room, NeutronReader options)
 {
     Neutron.Enqueue(() => Neutron.Fire(Neutron.onCreatedRoom, new object[] { room, options }), ref monoBehaviourActions);
 }
コード例 #24
0
 public void DrawNeutronWay(Neutron neutron)
 {
     if (neutron.CollisionPoint.Count == 0)
         return;
     
     var neutronCollisionSeries = new LineSeries
     {
         StrokeThickness = 2,
         MarkerSize = 3,
         MarkerStroke = OxyColors.Black,
         MarkerType = MarkerType.Circle,
         CanTrackerInterpolatePoints = false,
         //Title = $"Neutron {(SimulateOnePlotModel.Series.Count + 1).ToString("E2")}; MeanFreeLenght: {(neutron.AverageFreePathLength).ToString("E2")}; TotalLenght: {(neutron.PathLength).ToString("E2")}",
         Smooth = false,
     };
     neutron.CollisionPoint.ForEach(p => neutronCollisionSeries.Points.Add(new DataPoint(p.X, p.Y)));
     SimulateOnePlotModel.Series.Add(neutronCollisionSeries);
     SimulateOnePlot.ResetAllAxes();
     SimulateOnePlot.InvalidatePlot();
     neutron.CollisionPoint.ForEach(p => Console.WriteLine(p.X + @"; " + p.Y));
     Console.WriteLine();
 }
コード例 #25
0
        public void OnNeutronRegister(NeutronPlayer player, bool isServer, Scene scene, MatchmakingMode mode, INeutronMatchmaking matchmaking, Neutron neutron)
        {
            if (!_isOriginalObject)
            {
                return;
            }

            #region Prevent Being Instantiated
            if (_hasMap)
            {
                if (!(mode == _matchmakingMode))
                {
                    return;
                }

                if (matchmaking.Get.ContainsKey(_mapKey))
                {
                    string mapName = matchmaking.Get[_mapKey].ToObject <string>();
                    if (!(mapName == _mapName))
                    {
                        return;
                    }
                    else /*continue;*/ } {
            }
            else
            {
                LogHelper.Info($"This scene object({_mapName} - {matchmaking.Name}) is not linked to a map, it will be instantiated in all scenes of the specified matchmaking.");
            }
        }
コード例 #26
0
 /// <summary>
 ///* Ends a gRPC(Global Remote Procedure Call) service call.<br/>
 ///* (from client-side) use this overload to send from client to server.
 /// </summary>
 /// <param name="id">The id of the gRPC service.</param>
 /// <param name="parameters">The parameters that will be sent with the service.</param>
 /// <param name="protocol">The protocol used to send the service.</param>
 /// <param name="neutron">The neutron instance that will be responsible for ending the service.</param>
 public void End_gRPC(byte id, NeutronStream parameters, Protocol protocol, Neutron neutron)
 {
     neutron.End_gRPC(id, parameters, protocol);
 }
コード例 #27
0
 /// <summary>
 ///* Initiates a gRPC(Global Remote Procedure Call) service call.<br/>
 ///* (from client-side) use this overload to send from client to server.
 /// </summary>
 /// <param name="parameters">The parameters that will be sent with the service.</param>
 /// <param name="neutron">The neutron instance that will be responsible for starting the service.</param>
 /// <returns></returns>
 public NeutronStream.IWriter Begin_gRPC(NeutronStream parameters, Neutron neutron) => neutron.Begin_gRPC(parameters);
コード例 #28
0
 protected override void OnPlayerJoinedChannel(NeutronChannel channel, NeutronPlayer player, bool isMine, Neutron neutron)
 {
     base.OnPlayerJoinedChannel(channel, player, isMine, neutron);
     {
         if (isMine)
         {
             using (NeutronStream stream = new NeutronStream())
             {
                 var writer = neutron.BeginPlayer(stream, Vector3.zero, Quaternion.identity);
                 writer.Write();
                 neutron.EndPlayer(stream, 10);
             }
         }
     }
 }
コード例 #29
0
 protected static void HandleDestroyPlayer()
 {
     Neutron.Enqueue(() => Neutron.Fire(Neutron.onDestroyed, new object[] { }), ref monoBehaviourActions);
 }
コード例 #30
0
 protected static void HandleGetRooms(Room[] room, NeutronReader[] options)
 {
     Neutron.Enqueue(() => Neutron.Fire(Neutron.onRoomsReceived, new object[] { room, options }), ref monoBehaviourActions);
 }
コード例 #31
0
 protected static void HandleFail(Packet packet, string error)
 {
     Neutron.Fire(Neutron.onFailed, new object[] { packet, error });
 }