private void FindPlayerSpawnPositionsInScene() { PlayersSpawnPositions.Clear(); // Try to find already placed player spawn positions in the scene AbstractPlayerSpawnPosition[] spawnPositions = FindObjectsOfType <AbstractPlayerSpawnPosition>(); foreach (AbstractPlayerSpawnPosition spawnPosition in spawnPositions) { PlayersSpawnPositions.Add(spawnPosition.PayerID, spawnPosition); } // Determine spawn positions relative to this transform if no PlayerSpawnPosition found in scene if (MotherOfManagers.Instance.IsSpawnGhostPlayerPositionsIfNotFound == true) { int angle; for (int i = 1; i < 5; i++) { angle = 90 * i; EPlayerID playerID = BUtils.GetPlayerIDFrom(i); if (PlayersSpawnPositions.ContainsKey(playerID) == false) { AbstractPlayerSpawnPosition spawnGhost = Instantiate(playerSpawnPositionPrefab); spawnGhost.PayerID = playerID; spawnGhost.Position = transform.position + Vector3.forward * 3.0f + Vector3.left * 3.0f; spawnGhost.transform.RotateAround(transform.position, Vector3.up, angle); spawnGhost.Rotation = transform.rotation; PlayersSpawnPositions.Add(playerID, spawnGhost); } } } }
private void OnTestAnimationButton() { if (BUtils.IsEditorPlaying() == true) { StartAnimation(); } }
public void LoadRepObject() { if (replicatedObject == null) { if (IS_NOT_NULL(replicatedObjectPrefab)) { replicatedObject = Instantiate(replicatedObjectPrefab); } } string serializedBAnchorInformation = PlayerPrefs.GetString("TEST_Anchor", "Not_Init"); if (serializedBAnchorInformation == "Not_Init") { LogConsoleError("Trying to load a BAnchor that was never saved"); return; } //BAnchorInformation bAnchorInformation = JsonConvert.DeserializeObject<BAnchorInformation>(serializedBAnchorInformation); BAnchorInformation bAnchorInformation = BUtils.DeserializeObject <BAnchorInformation>(serializedBAnchorInformation); if (IS_NOT_NULL(bAnchorInformation)) { replicatedObject.SetTransformedPosition(bAnchorInformation.TransformedPosition); replicatedObject.SetTransformedRotation(bAnchorInformation.TransformedRotation); } }
private void On_TouchJoystick_Moved(EInputAxis inputAxis, EInputButton inputButton, Vector2 newInputValues) { if ((inputAxis != EInputAxis.NONE) && (IS_KEY_CONTAINED(oldInputValuesMap, inputAxis))) //&& (Mathf.Abs(newInputValues.x) + Mathf.Abs(newInputValues.y) > BConsts.JOYSTICK_DEAD_ZONE)) { Vector2 oldInputValues = oldInputValuesMap[inputAxis]; float inputDistance = Vector2.Distance(oldInputValues, newInputValues); // Is new joystick input different enough from last registred one? //if (inputDistance > BConsts.THRESHOLD_JOYSTICK_DISTANCE_MOVEMENT) //{ //newInputValues.Normalize(); float newX = newInputValues.x; float newY = newInputValues.y; if (MotherOfManagers.Instance.TransformInpuAxisToCameraDirection == true) { BUtils.TransformAxisToCamera(ref newX, ref newY, Camera.main.transform.forward); } oldInputValuesMap[inputAxis] = new Vector2(newX, newY); InvokeAxisUpdated(EControllerID.TOUCH, EInputAxis.MOVEMENT, newX, newY); //} } }
public override void OnReplicatedEvent(string serializedBEHandle) { //H deserializedBEHandle = JsonConvert.DeserializeObject<H>(serializedBEHandle); H deserializedBEHandle = BUtils.DeserializeObject <H>(serializedBEHandle); OnProceedInvokation(deserializedBEHandle); }
/* On Clients */ private void On_NETWORK_PlayerJoined(BEHandle <EPlayerID, EControllerID> handle) { if (ARE_NOT_EQUAL(localNetworkID, handle.InvokingNetworkID) && ARE_NOT_EQUAL(localNetworkID, ENetworkID.HOST) && InputManager.Instance.IsControllerConnected(handle.Arg2) == false) { // Connect Controller InputManager.Instance.ConnectController(handle.Arg2); // Update Party Map if (IS_KEY_NOT_CONTAINED(partyMap, handle.Arg2)) { partyMap.Add(handle.Arg2, handle.Arg1); } // Join Player IS_TRUE(PlayerManager.Instance.JoinPlayer(handle.Arg1, handle.Arg2)); // Spawn Player ENetworkID networkID = BUtils.GetNetworkIDFrom(handle.Arg2); AbstractNetPlayer newPlayer = (AbstractNetPlayer)PlayerManager.Instance.SpawnPlayer(handle.Arg1); if (IS_NOT_NULL(newPlayer) && IS_NOT_NONE(networkID)) { newPlayer.SetOwner(networkID); } } }
public void SetRepObject() { if (IS_NOT_NULL(ARManager.Instance)) { // Spawn or replace if (replicatedObject == null) { if (IS_NOT_NULL(replicatedObjectPrefab)) { replicatedObject = Instantiate(replicatedObjectPrefab, ARCursor.Instance.GetCursorPosition(), ARCursor.Instance.GetCursorRotation()); } } else { replicatedObject.transform.position = ARCursor.Instance.GetCursorPosition(); replicatedObject.transform.rotation = ARCursor.Instance.GetCursorRotation(); } BAnchorInformation anchorInformation = replicatedObject.GetBAnchorInformation(); string serializedBAnchorInformation = BUtils.SerializeObject(anchorInformation); // Save position and rotation PlayerPrefs.SetString("TEST_Anchor", serializedBAnchorInformation); } }
public void OnProceedInvokation(H eventHandle) { // Debug event string debugMessage = eventHandle.GetDebugMessage(); if ((MotherOfManagers.Instance.IsDebugLogEvents == true) && (debugMessage != "") && (eventHandle.DebugEvent == true)) { string networkID = ""; if (MotherOfManagers.Instance.IsDebugEventsNetworkID == true) { networkID = " - Sent by : " + eventHandle.InvokingNetworkID; } Debug.Log("<color=green>[EVENT]</color> " + "<color=red>[" + BUtils.GetTimeAsString() + "] </color>" + BEventName + " : " + debugMessage + networkID); } // Invoke event to all local listeners if (Event != null) { Event.Invoke(eventHandle); } }
private void On_NETWORK_CalculateRTT(BEHandle <ENetworkID, int> handle) { ENetworkID requestingNetworkID = handle.Arg1; int startTime = handle.Arg2; // Half-way if (BEventManager.Instance.LocalNetworkID != requestingNetworkID) { BEventsCollection.NETWORK_CalculateRTT.Invoke(new BEHandle <ENetworkID, int>(requestingNetworkID, startTime), BEventReplicationType.TO_TARGET, false, requestingNetworkID); } // Round Trip else { CurrentPing = BUtils.GetTimeAsInt() - startTime; if (CurrentPing < pingDropTreshold) { CalculateAvgPing(CurrentPing); } else { LogConsole("Ping dropped : " + CurrentPing); } } }
protected override void OnGUI() { base.OnGUI(); string ipAddress = BUtils.GetLocalIPAddress(); GUI.Box(new Rect(10, Screen.height - 50, 100, 30), ipAddress); }
protected override void Awake() { base.Awake(); LocalIPAddress = BUtils.GetLocalIPAddress(); SetBEventDispatcher(MotherOfManagers.Instance.EventDispatcherType); }
public void Server_RequestBroadcastEvent(AbstractBEHandle bEHandle, BEventReplicationType eventInvocationType, ENetworkID callingNetworkID, ENetworkID targetNetworkID) { //Debug.Log("Server_RequestBroadcastEvent : " + callingNetworkID + " - " + eventInvocationType); string serializedBEHandle = BUtils.SerializeObject(bEHandle); Server_OnBroadcastEvent(serializedBEHandle, eventInvocationType, callingNetworkID, targetNetworkID); }
private void ApplyRandomFroce() { gameObject.SetActive(true); Vector3 randomForce = BUtils.GetRandomVector(forceIntensity, forceIntensity); myRigidBody.AddForce(randomForce, ForceMode.Impulse); Vector3 randomRotation = BUtils.GetRandomVector(0.0f, 360.0f); myRigidBody.AddTorque(randomRotation, ForceMode.Impulse); }
private void On_NETWORK_NewNetworkIDConnected(BEHandle <ENetworkID> handle) { if (BEventManager.Instance.LocalNetworkID == ENetworkID.HOST) { EControllerID newControllerID = BUtils.GetControllerIDFrom(handle.Arg1); if (IS_NOT_NONE(newControllerID) && InputManager.Instance.IsControllerConnected(newControllerID) == false) { StartCoroutine(JoinConnectedPlayerCoroutine(handle, newControllerID)); } } }
private void OnTriggerEnter(Collider other) { // Should only be called on locally owned objects if (dZPlayer && owner == BEventManager.Instance.LocalNetworkID) { BallDroneBAnchor ballDrone = BUtils.GetComponentInHierarchy <BallDroneBAnchor>(other.gameObject); if (ballDrone) { CatchBallDrone(ballDrone); } } }
public void OnBEventReplicated(string serializedBEHandle) { //AbstractBEHandle deserializedBEHandle = JsonConvert.DeserializeObject<AbstractBEHandle>(serializedBEHandle); AbstractBEHandle deserializedBEHandle = BUtils.DeserializeObject <AbstractBEHandle>(serializedBEHandle); string callingBEventName = deserializedBEHandle.InvokingBEventName; if ((IS_NOT_NULL(BEventsCollection.Instance.AllReplicatedBEvent)) && (IS_KEY_CONTAINED(BEventsCollection.Instance.AllReplicatedBEvent, callingBEventName)) && (IS_NOT_NULL(BEventsCollection.Instance.AllReplicatedBEvent[callingBEventName]))) { BEventsCollection.Instance.AllReplicatedBEvent[callingBEventName].OnReplicatedEvent(serializedBEHandle); } }
private void Publish_TOPIC_BROADCAST_BEVENT(AbstractBEHandle bEHandle, ENetworkID targetNetworkID) { // Debug if (MotherOfManagers.Instance.DebugUbiiTopicPublish) { LogConsole("Publish_TOPIC_BROADCAST_BEVENT"); } if (ARE_NOT_EQUAL(LocalNetworkID, targetNetworkID)) { string serializedBEHandle = BUtils.SerializeObject(bEHandle); Publish(UbiiParser.UnityToProto(TOPIC_BROADCAST_BEVENT, joinedHostGuid + "|" + targetNetworkID + "|" + serializedBEHandle)); } }
private void On_NETWORK_NetworkIDDisconnected(BEHandle <ENetworkID> handle) { if (BEventManager.Instance.LocalNetworkID == ENetworkID.HOST) { EControllerID controllerID = BUtils.GetControllerIDFrom(handle.Arg1); if (IS_NOT_NONE(controllerID) && IS_TRUE(InputManager.Instance.IsControllerConnected(controllerID)) && IS_KEY_CONTAINED(partyMap, controllerID)) { EPlayerID playerID = partyMap[controllerID]; if (IS_NOT_NONE(playerID)) { partyMap.Remove(controllerID); // Disconnect Controller (-> Remove from party) InputManager.Instance.DisconnectController(controllerID); BEventsCollection.NETWORK_PlayerLeft.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID), BEventReplicationType.TO_ALL_OTHERS, true); } } } }
private void ProcessRaycastHit(RaycastHit hit) { IRayCastable rayCastable = BUtils.GetComponentInHierarchy <IRayCastable>(hit.transform.gameObject, true); if (rayCastable != null) { // Enter if (rayCastablesMap.ContainsKey(rayCastable) == false) { rayCastable.OnRayHoverEnter(); rayCastablesMap.Add(rayCastable, true); InvokeEventIfBound(OnRayCastableEnter, rayCastable); } // Stay else if (rayCastablesMap.ContainsKey(rayCastable) == true && rayCastablesMap[rayCastable] == false) { rayCastablesMap[rayCastable] = true; InvokeEventIfBound(OnRayCastableStay, rayCastable); } } }
public override void StartAnimation() { if (StartValue == null) { return; } if (EndValue == null) { return; } if (AnimatedTransform == null) { AnimatedTransform = transform; } if (StartFromCurrentTransform) { if (PlayInReverse == false) { startTransform = BUtils.GetTransformStruct(transform); endTransform = BUtils.GetTransformStruct(EndValue); } else { startTransform = BUtils.GetTransformStruct(StartValue); endTransform = BUtils.GetTransformStruct(transform); } } else { startTransform = BUtils.GetTransformStruct(StartValue); endTransform = BUtils.GetTransformStruct(EndValue); } base.StartAnimation(); }
public void SpawnAllJoinedPlayers() { LogConsole("Spawning remaining AI players"); // Fill empty slots with AI int emptySlots = 4 - GetJoinedPlayers().Count; int remainingAI = MotherOfManagers.Instance.MaximumNumberOfAIToSpawn; while ((emptySlots > 0) && (remainingAI > 0)) { EControllerID aIControllerID = BUtils.GetAIControllerIDFrom(MotherOfManagers.Instance.MaximumNumberOfAIToSpawn - remainingAI + 1); JoinNextAIPlayer(aIControllerID); emptySlots--; remainingAI--; } foreach (EPlayerID playerID in GetJoinedPlayers()) { if (IS_KEY_NOT_CONTAINED(ActivePlayers, playerID)) { SpawnPlayer(playerID); } } }
public AbstractBEHandle() { InvocationTime = BUtils.GetTimeAsInt(); }
public void Publish_TOPIC_TEST_INT(int integer) { LogConsole("Publish_TOPIC_TEST_INT : " + integer + " - " + BUtils.GetTimeAsString()); Publish(UbiiParser.UnityToProto(TOPIC_TEST_INT, integer)); }
private void Button_ReleaseBall() { ReleaseBall(BUtils.GetRandomVector(1.0f, 1.0f)); }
public void Rpc_TestInteger(int integer) { Debug.Log("Rpc_TestInteger : " + integer + " - " + BUtils.GetTimeAsString()); }
private void On_TOPIC_TEST_INT(TopicDataRecord topicDataRecord) { LogConsole("On_TOPIC_TEST_INT : " + topicDataRecord.Double + " - " + BUtils.GetTimeAsString()); }
private void RequestPing() { int currentTime = BUtils.GetTimeAsInt(); BEventsCollection.NETWORK_CalculateRTT.Invoke(new BEHandle <ENetworkID, int>(BEventManager.Instance.LocalNetworkID, currentTime), BEventReplicationType.TO_TARGET, false, ENetworkID.HOST); }