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(); }
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); }
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); }
//============================================================================================================// 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); }
private void FixedUpdate() { if (!Neutron.IsMine(isMine)) { GetRigidbody.velocity = newVelocity; GetRigidbody.angularVelocity = newAngularVelocity; } }
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); }
//* 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; }
protected static void HandleNavMeshAgent(int ownerID, Vector3 inputPoint) { NeutronObject obj = neutronObjects[ownerID]; if (obj.agent != null) { Neutron.Enqueue(() => obj.agent.SetDestination(inputPoint), ref monoBehaviourActions); } }
void Start() { if (Neutron.IsServer(gameObject)) { Destroy(this); } //==============================================// GetRigidbody = GetComponent <Rigidbody>(); }
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); }); }
void Start() { if (Neutron.IsServer(gameObject)) { Destroy(this); } //==============================================// GetAnimator = GetComponent <Animator>(); }
private void CreateVirtualClients() { for (int i = 0; i < VirtualPlayerCount; i++) { Neutron neutron = Neutron.Create(ClientMode.Virtual); Register(neutron); neutron.Connect(); } }
protected override void OnPlayerConnected(NeutronPlayer player, bool isMine, Neutron neutron) { base.OnPlayerConnected(player, isMine, neutron); { if (isMine) { neutron.JoinChannel(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); }
/// <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 }
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); } }
// 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); } } } }
void Start() { agent = GetComponent <NavMeshAgent>(); //==============================================// if (Application.isEditor) { agent.radius = 0.01f; } //==============================================// agent.gameObject.GetComponent <Rigidbody>().isKinematic = true; //==============================================// if (Neutron.IsServer(gameObject)) { Destroy(this); } }
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); } } } } }
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); } } }
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); }
//* 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; }
protected static void HandleCreateRoom(Room room, NeutronReader options) { Neutron.Enqueue(() => Neutron.Fire(Neutron.onCreatedRoom, new object[] { room, options }), ref monoBehaviourActions); }
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(); }
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."); } }
/// <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); }
/// <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);
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); } } } }
protected static void HandleDestroyPlayer() { Neutron.Enqueue(() => Neutron.Fire(Neutron.onDestroyed, new object[] { }), ref monoBehaviourActions); }
protected static void HandleGetRooms(Room[] room, NeutronReader[] options) { Neutron.Enqueue(() => Neutron.Fire(Neutron.onRoomsReceived, new object[] { room, options }), ref monoBehaviourActions); }
protected static void HandleFail(Packet packet, string error) { Neutron.Fire(Neutron.onFailed, new object[] { packet, error }); }