public override void SessionListUpdated(Map <Guid, UdpSession> sessionList) { if (_timerRoutine != null) { StopCoroutine(_timerRoutine); _timerRoutine = null; } Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count); foreach (var session in sessionList) { PhotonSession photonSession = session.Value as PhotonSession; if (photonSession != null && photonSession.Source == UdpSessionSource.Photon) { object value; if (photonSession.Properties.TryGetValue("type", out value)) { BoltLog.Info("Room with type: {0}", value); } if (photonSession.Properties.TryGetValue("map", out value)) { BoltLog.Info("Room with map: {0}", value); } BoltMatchmaking.JoinSession(photonSession); } } }
// Bolt Events public override void SceneLoadLocalDone(string scene, IProtocolToken token) { if (scene.Equals("PhotonLobby") && sceneFlag == false) { return; } BoltLog.Info(string.Format("New scene: {0}", scene)); try { if (lobbyScene.SimpleSceneName == scene) { ChangeBodyTo(uiMainMenu); uiTopPanel.HideBackButton(); uiTopPanel.SetInGame(false); sceneFlag = true; } else { ChangeBodyTo(null); uiTopPanel.SetInGame(true); uiTopPanel.ToggleVisibility(false); uiTopPanel.SetupBackButton("Menu", ShutdownEventHandler); sceneFlag = false; } } catch (Exception e) { BoltLog.Error(e); } }
/// <summary> /// It will perform all steps to load the serialized data on re-config the entities on the project /// </summary> private static void Load() { var result = JsonSerializerUpdateUtils.LoadData(SerializedDataPath); if (result != null) { var prefabList = GetPrefabListFromProject(); foreach (var prefab in prefabList) { foreach (var updateItem in result) { if (prefab.name.Equals(updateItem.name)) { UpdateBoltEntity(prefab, updateItem); } } } BoltLog.Info("Load DONE!"); } else { BoltLog.Error("Unable to load data"); } }
IEnumerator Start() { var systems = GetComponentsInChildren <ParticleSystem>(); // find out the maximum lifetime of any particles in this effect foreach (var system in systems) { maxLifetime = Mathf.Max(system.main.startLifetimeMultiplier, maxLifetime); } // wait for random duration float stopTime = Time.time + Random.Range(minDuration, maxDuration); while (Time.time < stopTime || earlyStop) { yield return(null); } BoltLog.Info("stopping " + name); // turn off emission foreach (var system in systems) { ParticleSystem.EmissionModule em = system.emission; em.enabled = false; } BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver); // wait for any remaining particles to expire yield return(new WaitForSeconds(maxLifetime)); Destroy(gameObject); }
/// <summary> /// It will perform all necessary steps to serialize and save all configs from the entities on the current project /// </summary> private static void Save() { var prefabList = GetPrefabListFromBolt(); if (prefabList != null && prefabList.Count != 0) { var updateList = new List <UpdateItem>(); foreach (var prefabID in prefabList) { var go = PrefabDatabase.Find(prefabID); if (go != null) { var updateItem = BuildUpdateItem(go); if (updateItem != null) { updateList.Add(updateItem); } } } JsonSerializerUpdateUtils.SaveData(updateList, SerializedDataPath); BoltLog.Info("Save DONE!"); } else { BoltLog.Warn("No prefabs found to be serialized"); } }
static void NatUtility_OpenPort_Finish(NatDeviceState device, int port) { try { var natMapping = device.PortMappings.Values.FirstOrDefault(p => p.Internal == port && p.External == port); if (natMapping != null) { // set this port as open natMapping.Status = Bolt.NatPortMappingStatus.Open; // tell user about this portChanges.Enqueue(new NatPortMappingChanged { Device = device, Mapping = natMapping.Clone() }); // meep BoltLog.Info("Changed {0} on {1}", natMapping, device); } else { BoltLog.Warn("Received incorrect port mapping result from {0}", device); } } catch (Exception exn) { BoltLog.Exception(exn); } }
public void OnJoinedRoom() { BoltLog.Info("[BoltVoiceBridge] Joined Room as Player {0}", LocalPlayerID); // Reset the Group to the default group ResetVoiceGroup(); }
public override void Attached() { if (entity.isOwner) { state.tokenTest = new TestToken() { Number = 1337 }; } state.AddCallback("tokenTest", () => { BoltLog.Info("Received token in .tokenTest property {0}", state.tokenTest); }); state.SetTransforms(state.transform, transform); state.SetAnimator(GetComponentInChildren <Animator>()); // setting layerweights state.Animator.SetLayerWeight(0, 1); state.Animator.SetLayerWeight(1, 1); state.OnFire += OnFire; state.AddCallback("weapon", WeaponChanged); // setup weapon WeaponChanged(); }
public void SetupPlayer() { BoltLog.Info("SetupPlayer"); LobbyPlayerList._instance.AddPlayer(this); localPlayer = this; nameInput.interactable = true; remoteIcone.gameObject.SetActive(false); localIcone.gameObject.SetActive(true); removePlayerButton.gameObject.SetActive(false); removePlayerButton.interactable = false; ChangeReadyButtonColor(JoinColor); readyButton.transform.GetChild(0).GetComponent <Text>().text = "JOIN"; readyButton.interactable = true; //we switch from simple name display to name input colorButton.interactable = true; nameInput.interactable = true; nameInput.onEndEdit.RemoveAllListeners(); nameInput.onEndEdit.AddListener(OnNameChanged); colorButton.onClick.RemoveAllListeners(); colorButton.onClick.AddListener(OnColorClicked); readyButton.onClick.RemoveAllListeners(); readyButton.onClick.AddListener(OnReadyClicked); OnClientReady(state.Ready); }
void ChangeState(ConnectState state) { BoltLog.Info("Changing Connect State: {0} => {1}", _connectState, state); // update _connectState = state; }
public override void BoltStartDone() { if (!BoltNetwork.isRunning) { return; } if (BoltNetwork.isServer) { RoomProtocolToken token = new RoomProtocolToken() { ArbitraryData = "My DATA", }; BoltLog.Info("Starting Server"); // Start Photon Room BoltNetwork.SetServerInfo(_matchName, token); // Setup Host infoPanel.gameObject.SetActive(false); ChangeTo(lobbyPanel); backDelegate = Stop; SetServerInfo("Host", ""); // Build Server Entity //BoltEntity entity = BoltNetwork.Instantiate(BoltPrefabs.PlayerInfo); //entity.TakeControl(); } else if (BoltNetwork.isClient) { backDelegate = Stop; SetServerInfo("Client", ""); } }
public override void ControlGained() { BoltLog.Info("ControlGained"); readyButton.transform.GetChild(0).GetComponent <Text>().color = Color.white; SetupPlayer(); }
public override void BoltStartDone() { if (BoltNetwork.IsServer) { var token = new RoomProtocolToken() { ArbitraryData = "My DATA", }; BoltLog.Info("Starting Server"); // Start Photon Room BoltMatchmaking.CreateSession( sessionID: matchName, token: token ); } else if (BoltNetwork.IsClient) { if (randomJoin) { BoltMatchmaking.JoinRandomSession(); } else { ClientStaredUIHandler(); } randomJoin = false; } }
public override void Connected(BoltConnection connection) { BoltLog.Warn("Connected"); ServerAcceptToken acceptToken = connection.AcceptToken as ServerAcceptToken; if (acceptToken != null) { BoltLog.Info("AcceptToken: " + acceptToken.GetType()); BoltLog.Info("AcceptToken: " + acceptToken.data); } else { BoltLog.Warn("AcceptToken is NULL"); } ServerConnectToken connectToken = connection.ConnectToken as ServerConnectToken; if (connectToken != null) { BoltLog.Info("ConnectToken: " + connectToken.GetType()); BoltLog.Info("ConnectToken: " + connectToken.data); } else { BoltLog.Warn("ConnectToken is NULL"); } }
public override void SceneLoadLocalDone(string map) { BoltLog.Info("New scene: " + map); try { if (lobbyScene.SimpleSceneName == map) { ChangeTo(mainMenuPanel); topPanel.isInGame = false; } else if (gameScene.SimpleSceneName == map) { ChangeTo(null); backDelegate = Stop; topPanel.isInGame = true; topPanel.ToggleVisibility(false); // Spawn Player // SpawnGamePlayer(); } } catch (Exception e) { BoltLog.Exception(e); } }
private static void Clean() { try { BoltLog.Info("Start Cleaning!"); var step = 1; var total = _packets.Count; foreach (var packet in _packets) { BoltLog.Info("Packaging {0}/{1}: {2}", step++, total, packet.Path); packet.Delete(); #if BOLT_CLOUD if (packet.IsPro) { packet.DeletePacket(); } #endif } _extra.Delete(); BoltLog.Info("Packaging DONE!"); } finally { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } }
// ======= PRIVATE METHODS ===================================================================================== public static int FindMissingComponents() { int missingScriptsCount = 0; List <Component> components = new List <Component>(); var folders = new string[] { "Assets" }; var iter = AssetDatabase.FindAssets("t:Prefab", folders).GetEnumerator(); while (iter.MoveNext()) { var guid = (string)iter.Current; var path = AssetDatabase.GUIDToAssetPath(guid); var go = AssetDatabase.LoadAssetAtPath <GameObject>(path); go.GetComponentsInChildren(true, components); for (int j = 0; j < components.Count; ++j) { if (components[j] == null) { ++missingScriptsCount; BoltLog.Error("Missing script: " + path); } } components.Clear(); } if (missingScriptsCount != 0) { BoltLog.Info("Found {0} Missing Scripts", missingScriptsCount); } return(missingScriptsCount); }
/// <summary> /// This custom implementation of the Speaker Factory is very similar to the orignal, /// but besides the Speaker instance creation, also stores the reference on the Speaker Registry /// for a later use by the players /// /// <seealso cref="Photon.Voice.Unity.VoiceConnection.SimpleSpeakerFactory"/> /// </summary> /// <param name="playerId">LoadBalancingClient Player ID</param> /// <param name="voiceId">Voice ID</param> /// <param name="userData">Custom User Data</param> /// <returns>New Speaker instance</returns> protected Speaker CustomBoltSpeakerFactory(int playerId, byte voiceId, object userData) { BoltLog.Info("[BoltVoiceBridge] SpeakerFactory for Player {0}", playerId); // Store on the Registry based on the Player ID Speaker speaker; BoltVoiceSpeakerController oldSpeaker; if (speakerRegistry.TryGetValue(playerId, out oldSpeaker)) { speaker = oldSpeaker.gameObject.GetComponent <Speaker>(); } else { // Create Instance based on the Custom Speker from Bolt var speakerInstance = Instantiate(BoltSpeakerPrefab); // Get Speaker referecence speaker = speakerInstance.GetComponent <Speaker>(); // Store the player ID on our custom BoltVoiceSpeakerController var speakerController = speakerInstance.GetComponent <BoltVoiceSpeakerController>(); speakerController.PlayerID = playerId; speakerRegistry.Add(playerId, speakerController); } // Return the Speaker reference return(speaker); }
public void SendData() { var now = Time.timeSinceLevelLoad; if (BoltNetwork.IsClient && BoltNetwork.Server != null) { BoltLog.Info("Send action! Client at {0}", now); var info = string.Format("Client {0} says: {1}", ID, now); var data = Encoding.UTF8.GetBytes(info); BoltNetwork.Server.SendData(data); } if (BoltNetwork.IsServer && BoltNetwork.Clients.Any()) { BoltLog.Info("Send action! Server at {0}", now); var info = string.Format("Server says: {0}", now); var data = Encoding.UTF8.GetBytes(info); foreach (var conn in BoltNetwork.Clients) { conn.SendData(data); } } }
private void OnGUI() { if (ready && BoltNetwork.IsClient) { GUILayout.BeginVertical(GUILayout.Width(Screen.width), GUILayout.Height(Screen.height)); { GUILayout.BeginHorizontal(GUILayout.Width(Screen.width)); { size = (int)GUILayout.HorizontalSlider(size, 1, 5000); GUILayout.Label(size.ToString()); } GUILayout.EndHorizontal(); if (GUILayout.Button("Send data", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) { if (canSend) { canSend = false; GenerateData(); BoltLog.Info("Sending data with hash {0}...", hash); BoltNetwork.Server.StreamBytes(testChannel, data); } else { BoltLog.Info("Waiting data transfer..."); } } } GUILayout.EndVertical(); } }
void ShowSessionList(Dictionary <Guid, UdpSession> sessionList) { foreach (var session in sessionList) { UdpSession udpSession = session.Value as UdpSession; // Skip if is not a Photon session if (udpSession.Source != UdpSessionSource.Photon) { BoltLog.Info("UdpSession with different Source: {0}", udpSession.Source); continue; } PhotonSession photonSession = udpSession as PhotonSession; if (photonSession == null) { continue; } string sessionDescription = String.Format("{0} ({1})", photonSession.HostName, photonSession.Id); IProtocolToken token = photonSession.GetProtocolToken(); // Normal Token RoomProtocolToken roomToken = token as RoomProtocolToken; if (roomToken != null) { sessionDescription += String.Format(" :: {0}", roomToken.ArbitraryData); } object prop_type = -1; object prop_map = -1; if (photonSession.Properties.ContainsKey("t")) { prop_type = photonSession.Properties["t"]; } if (photonSession.Properties.ContainsKey("m")) { prop_map = photonSession.Properties["m"]; } sessionDescription += String.Format(" :: {0} / {1}", prop_type, prop_map); if (GUILayout.Button(sessionDescription, GUILayout.ExpandWidth(true))) { ServerConnectToken connectToken = new ServerConnectToken { data = "ConnectTokenData" }; BoltNetwork.Connect(photonSession, connectToken); } } }
public override void Enable() { lock (syncLock) { //NatUtility.Logger = new BoltLogTextWriter(); NatUtility.StartDiscovery(); BoltLog.Info("UPnP Enabled"); } }
public static void FindMissingScriptsMenu() { BoltLog.Info("Searching for Missing Scripts"); if (FindMissingComponents() == 0) { BoltLog.Info("Not found any prefab with missing scripts"); } }
void Update() { if (Input.GetKeyDown(KeyCode.Q)) { BoltLog.Info("q"); state.SetTransforms(state.transform, null); } }
private void RestoreColorData() { if (BoltNetwork.IsServer) { BoltLog.Info("adding " + GetColor()); Player_Colors.AddMaterial(GetColor()); } }
public override void SceneLoadLocalBegin(string scene, IProtocolToken token) { BoltLog.Info("SceneLoadLocalBegin-Token: {0}", token); // ui GameUI.Instantiate(); // camera PlayerCamera.Instantiate(); }
public override void SceneLoadRemoteDone(BoltConnection connection, Bolt.IProtocolToken token) { BoltLog.Info("SceneLoadRemoteDone-Token: {0}", token); if (BoltNetwork.isServer) { A2SManager.SetPlayerInfo(connection, connection.ConnectionId.ToString()); } }
public void SetOnHoverCursor() { if (_hasMouseCursorUtils) { _mouseCursorUtils.SetOnHoverCursor(); } BoltLog.Info($"{this} on enter Cursor"); }
public void SetDefaultCursor() { if (_hasMouseCursorUtils) { _mouseCursorUtils.SetDefaultCursor(); } BoltLog.Info($"{this} on exit Cursor"); }
public override void SceneLoadRemoteDone(BoltConnection connection, IProtocolToken token) { BoltLog.Info("SceneLoadRemoteDone"); if (BoltNetwork.IsClient) { ready = true; canSend = true; } }