public static void CB_COMP_PlayerNameBar(GameObject target, ref List <string> log) { if (log != null) { log.Add("Adding Player Name Bar"); } GameObject playerNameBar = E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/UI/PlayerNameBar.prefab"); if (log != null) { log.Add(" * Positioning name bar above player head..."); } Vector3 barPosition = target.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Head).position + (Vector3.up / 2); playerNameBar.transform.position = barPosition; playerNameBar.transform.SetParent(target.transform); if (!target.GetComponent <PlayerNameBar>()) { if (log != null) { log.Add("Adding PlayerNameBar component."); } target.AddComponent <PlayerNameBar>(); } BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; Text playerName = playerNameBar.transform.Find("Background").Find("PlayerName").GetComponent <Text>(); if (log != null) { log.Add("Adding name bar and player name to PlayerNameBar component."); } target.GetComponent <PlayerNameBar>().GetType().GetField("playerName", flags).SetValue(target.GetComponent <PlayerNameBar>(), playerName); target.GetComponent <PlayerNameBar>().GetType().GetField("playerBar", flags).SetValue(target.GetComponent <PlayerNameBar>(), playerNameBar); }
public static void CB_AddGlobalVoiceChat() { if (!FindObjectOfType <NetworkManager>()) { if (EditorUtility.DisplayDialog("Network Manager Not Found", "No NetworkManager was found in the scene. Please add a NetworkManager to the scene and try again.", "Okay")) { return; } } else { GameObject vc = E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/UI/Voice/VoiceRecorder.prefab"); vc.transform.SetParent(FindObjectOfType <NetworkManager>().transform); E_Helpers.SetObjectIcon(vc, E_Core.h_voiceIcon); if (EditorUtility.DisplayDialog("Added Voice Chat To Scene", "The \"VoiceRecorder\" has been successfully added to the scene. " + "Make sure that each spawnable player that you want to be able to transmit voice over the network also has the \"VoiceChat\" " + "component on them. This can be done when first setting up your player using the Convert Player menu. Read the help window " + "on this component for other needed items if doing this manually.", "Okay")) { Selection.activeGameObject = vc; } } }
public static void CB_AddStaminaBar() { GameObject target = Selection.activeGameObject; if (target == null) { if (EditorUtility.DisplayDialog("Select Valid Player", "You don't seem to have anything selected. Please select a valid player " + "before attempting to select this menu item.", "Okay")) { } } else if (!target.GetComponent <vThirdPersonController>()) { if (EditorUtility.DisplayDialog("Select Valid Player", "The current selected object doesn't appear to be a player. Please select a player " + "then select this menu item again to add the stamina bar to the selected player.", "Okay")) { } } else { GameObject staminaBar = E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/UI/FloatingStaminaBar.prefab"); staminaBar.transform.SetParent(target.transform); staminaBar.GetComponent <FloatingBar>().controller = target.GetComponent <vThirdPersonController>(); if (target.GetComponent <Animator>() && target.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Head)) { staminaBar.transform.position = target.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Head).position + Vector3.up / 2; if (EditorUtility.DisplayDialog("Success!", "Successfully added the health bar to your player.", "Great!")) { } } else { staminaBar.transform.localPosition = Vector3.zero; if (EditorUtility.DisplayDialog("Partial Success", "Successfully added the health bar to your player but was unable to determine where the head of your " + "player was. You will need to manually position the floating bar where you want it to be.", "Great!")) { } } Selection.activeGameObject = staminaBar; } }
public static void CB_CreatePlayerList() { PlayerList listComp = FindObjectOfType <PlayerList>(); if (!listComp) { GameObject playerList = E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/UI/PlayerList.prefab"); playerList.transform.SetParent(FindObjectOfType <NetworkManager>().transform); listComp = playerList.GetComponent <PlayerList>(); } //ChatBox Events ChatBox chatbox = FindObjectOfType <ChatBox>(); if (!E_PlayerEvents.HasUnityEvent(chatbox.OnYouSubscribeToDataChannel, "SetPlayerList", listComp)) { UnityEventTools.AddPersistentListener(chatbox.OnYouSubscribeToDataChannel, listComp.SetPlayerList); } if (!E_PlayerEvents.HasUnityEvent(chatbox.OnYouSubscribeToDataChannel, "UpdateLocationToCurrentScene", listComp)) { UnityEventTools.AddPersistentListener(chatbox.OnYouSubscribeToDataChannel, listComp.UpdateLocationToCurrentScene); } if (!E_PlayerEvents.HasUnityEvent(chatbox.OnUserSubscribedToDataChannel, "AddPlayer", listComp)) { UnityEventTools.AddPersistentListener(chatbox.OnUserSubscribedToDataChannel, listComp.AddPlayer); } if (!E_PlayerEvents.HasUnityEvent(chatbox.OnUserUnSubscribedToDataChannel, "RemovePlayer", listComp)) { UnityEventTools.AddPersistentListener(chatbox.OnUserUnSubscribedToDataChannel, listComp.RemovePlayer); } //Network Manager Events NetworkManager nm = FindObjectOfType <NetworkManager>(); if (!E_PlayerEvents.HasUnityEvent(nm.roomEvents._onJoinedRoom, "UpdateLocationToGoingToScene", listComp)) { UnityEventTools.AddPersistentListener(nm.roomEvents._onJoinedRoom, listComp.UpdateLocationToGoingToScene); } if (!E_PlayerEvents.HasUnityEvent(nm.roomEvents._onJoinedRoom, "ClearPlayerList", listComp)) { UnityEventTools.AddPersistentListener(nm.otherEvents._onDisconnected, listComp.ClearPlayerList); } E_Helpers.SetObjectIcon(listComp.gameObject, E_Core.h_playerlistIcon); }
public static void CB_AddDeathCamera() { GameObject deathCam = E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/DeathCamera.prefab"); NetworkManager nm = FindObjectOfType <NetworkManager>(); if (nm == null) { if (EditorUtility.DisplayDialog("Missing Network Manager", "This component was added to the scene but there was not NetworkManager found in this scene. " + "It is highly suggested that you make this a child of the NetworkManager or of something " + "that is persistant between scenes.", "Okay")) { } } else { deathCam.transform.SetParent(nm.gameObject.transform); Selection.activeGameObject = deathCam; if (FindObjectOfType <SyncPlayer>()) { if (EditorUtility.DisplayDialog("Player Found In Scene", "A convert multiplayer character was found in the scene do you want to add the unity events " + "necessary to enable the death camera system on player death?", "Yes", "No")) { foreach (SyncPlayer player in FindObjectsOfType <SyncPlayer>()) { if (!E_PlayerEvents.HasUnityEvent(player.gameObject.GetComponent <vThirdPersonController>().onDead, "DeadEnableDeathCam", player)) { UnityEventTools.AddPersistentListener(player.gameObject.GetComponent <vThirdPersonController>().onDead, player.DeadEnableDeathCam); } } if (EditorUtility.DisplayDialog("Remember To Save!", "Remember to save the changes back to the prefab on these converted players!", "Okay Thanks!")) { } } else { DisplayEventRequirement(); } } else { DisplayEventRequirement(); } } void DisplayEventRequirement() { if (EditorUtility.DisplayDialog("Friendly Reminder For Missing Events", "This will not trigger by itself. You will be required to trigger it when you want to " + "allow the player to switch to targeting other players. A chain of events is available " + "for you to add if you would like:\n\n" + "vThirdPersonController (On Dead Event): Add SyncPlayer.DeadEnableDeathCam event", "Okay Thanks!")) { } } }
public static void CB_COMP_PlayerVoiceChat(GameObject target, ref List <string> log) { if (!target.GetComponent <Speaker>()) { if (log != null) { log.Add("Adding Speaker component."); } target.AddComponent <Speaker>(); } if (!target.GetComponent <PhotonVoiceView>()) { if (log != null) { log.Add("Adding PhotonVoiceView component."); } target.AddComponent <PhotonVoiceView>(); } if (!target.GetComponent <VoiceChat>()) { if (log != null) { log.Add("Adding VoiceChat component."); } target.AddComponent <VoiceChat>(); } if (log != null) { log.Add("Setting VoiceChat component values."); } target.GetComponent <VoiceChat>().GetType().GetField("isPlayer", E_Helpers.allBindings).SetValue(target.GetComponent <VoiceChat>(), true); if (target.GetComponent <VoiceChat>().speakerImage == null) { if (log != null) { log.Add("Adding speaker image to VoiceChat component."); } GameObject speakerIcon = E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/UI/Voice/IsSpeakingImage.prefab"); if (target.GetComponent <Animator>()) { speakerIcon.transform.SetParent(target.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Chest)); speakerIcon.GetComponent <RectTransform>().localPosition = new Vector3(0, 0, 0); } else { speakerIcon.transform.SetParent(target.transform); } target.GetComponent <VoiceChat>().speakerImage = speakerIcon; } if (log != null) { log.Add("Setting PhotonVoiceView component values."); } target.GetComponent <PhotonVoiceView>().AutoCreateRecorderIfNotFound = false; target.GetComponent <PhotonVoiceView>().UsePrimaryRecorder = true; target.GetComponent <PhotonVoiceView>().SetupDebugSpeaker = true; try { target.GetComponent <PhotonVoiceView>().SpeakerInUse = target.GetComponent <Speaker>(); } catch (Exception ex) { log.Add(""); log.Add("---------------------------------"); log.Add(ex.Message); log.Add("Failed to add the `SpeakerInUse` value. You will need to do this manually."); log.Add("Assign the `Speaker` component into the `PhotonVoiceView`'s `SpeakerInUse` value."); log.Add("---------------------------------"); log.Add(""); } }
public static void CB_AddFreeForAllModernUI() { if (EditorUtility.DisplayDialog("Are you sure?", "This will overwrite the settings for your teamName, initialTeamSpawnPointNames, " + "autoSpawnPlayer, and allowTeamDamaging options on your NetworkManager component. " + "Do you want to continue?", "Yes, Add ModernUI", "No")) { GameObject ui = (GameObject.Find("ModernUI") != null) ? GameObject.Find("ModernUI") : E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/UI/PreBuilt/ModernUI.prefab"); NetworkManager nm = FindObjectOfType <NetworkManager>(); ui.transform.SetParent(nm.transform); //Setup team settings nm.allowTeamDamaging = true; nm.teamName = ""; nm.initalTeamSpawnPointNames.Clear(); nm.autoSpawnPlayer = false; //Capture Event Groups UnityEvent joinRoomEvents = nm.roomEvents._onJoinedRoom; UnityEvent onLeftLobby = nm.lobbyEvents._onLeftLobby; PlayerEvent onPlayerEnter = nm.playerEvents._onPlayerEnteredRoom; PlayerEvent onPlayerLeft = nm.playerEvents._onPlayerLeftRoom; StringUnityEvent joinRoomFailedEvents = nm.roomEvents._onJoinRoomFailed; StringUnityEvent createRoomFailedEvents = nm.roomEvents._onCreateRoomFailed; StringUnityEvent onDisconnected = nm.otherEvents._onDisconnected; StringUnityEvent onConnectionFailedEvents = nm.otherEvents._onConnectionFail; StringUnityEvent photonFailedEvents = nm.otherEvents._onFailedToConnectToPhoton; if (!E_PlayerEvents.HasUnityEvent(createRoomFailedEvents, "NetworkErrorOccured", ui.GetComponent <UICoreLogic>())) { UnityEventTools.AddPersistentListener(createRoomFailedEvents, ui.GetComponent <UICoreLogic>().NetworkErrorOccured); } if (!E_PlayerEvents.HasUnityEvent(joinRoomFailedEvents, "NetworkErrorOccured", ui.GetComponent <UICoreLogic>())) { UnityEventTools.AddPersistentListener(joinRoomFailedEvents, ui.GetComponent <UICoreLogic>().NetworkErrorOccured); } if (!E_PlayerEvents.HasUnityEvent(onDisconnected, "NetworkErrorOccured", ui.GetComponent <UICoreLogic>())) { UnityEventTools.AddPersistentListener(onDisconnected, ui.GetComponent <UICoreLogic>().NetworkErrorOccured); } if (!E_PlayerEvents.HasUnityEvent(photonFailedEvents, "NetworkErrorOccured", ui.GetComponent <UICoreLogic>())) { UnityEventTools.AddPersistentListener(photonFailedEvents, ui.GetComponent <UICoreLogic>().NetworkErrorOccured); } if (!E_PlayerEvents.HasUnityEvent(onConnectionFailedEvents, "NetworkErrorOccured", ui.GetComponent <UICoreLogic>())) { UnityEventTools.AddPersistentListener(onConnectionFailedEvents, ui.GetComponent <UICoreLogic>().NetworkErrorOccured); } E_Helpers.SetObjectIcon(ui, E_Core.h_uiIcon); Debug.Log("Successfully added \"ModernUI\" and setup the UnityEvents in the \"Network Manager\" and the \"ModernUI\"."); if (EditorUtility.DisplayDialog("Successfully Added ModernUI!", "The UICoreLogic has a \"selectablePlayers\" gameobject array that must be populated with your converted players that " + "are stored in the \"Resources\" folder. A helper menu option is available for you to automatically find " + "all of your converted players in the \"Resources\" folder and add it to this components array.\n\n" + "You can find this helper method under CB Games > UI > Add > All Player Prefabs To UICoreLogic.", "Thanks For The Tip!")) { Selection.activeGameObject = ui.gameObject; } } }
public static void CB_AddGlobalChatBox() { if (!FindObjectOfType <NetworkManager>()) { if (EditorUtility.DisplayDialog("Missing Network Manager", "No NetworkManager object was found in this scene. In order for this component to work properly there must be a network manager in the scene. Please add a \"NetworkManager\" component to the scene.", "Okay")) { } } else if (FindObjectOfType <ChatBox>()) { Selection.activeGameObject = FindObjectOfType <ChatBox>().gameObject; if (EditorUtility.DisplayDialog("Scene Already Has ChatBox", "This scene already contains a \"ChatBox\" component. You should never add more than one at a time to a scene.", "Okay")) { } } else { string chatBoxPrefabPath = string.Format("Assets{0}InvectorMultiplayer{0}UI{0}ChatBox.prefab", Path.DirectorySeparatorChar); GameObject ChatBox = E_Helpers.CreatePrefabFromPath(chatBoxPrefabPath); ChatBox.transform.SetParent(FindObjectOfType <NetworkManager>().transform); ChatBox.GetComponent <ChatBox>().nm = FindObjectOfType <NetworkManager>(); ChatBox.GetComponent <ChatBox>().GetType().GetField("openChatWindowOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> { "T" }); ChatBox.GetComponent <ChatBox>().GetType().GetField("closeWindowOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> { "Escape" }); ChatBox.GetComponent <ChatBox>().GetType().GetField("sendChatOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> { "KeypadEnter", "Return" }); E_Helpers.SetObjectIcon(ChatBox, E_Core.h_textChatIcon); //Join Room Events if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "SetActiveRoomAsChannelName", ChatBox.GetComponent <ChatBox>())) { UnityEventTools.AddPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().SetActiveRoomAsChannelName); } if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "Connect", ChatBox.GetComponent <ChatBox>())) { UnityEventTools.AddPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().Connect); } if (E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "EnableVisualBox", ChatBox.GetComponent <ChatBox>())) { UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().EnableVisualBox, true); } //Left Room Events if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onLeftRoom, "EnableVisualBox", ChatBox.GetComponent <ChatBox>())) { UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onLeftRoom, ChatBox.GetComponent <ChatBox>().EnableVisualBox, false); } //Joined Room Failed Events if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinRoomFailed, "SetActiveChannel", ChatBox.GetComponent <ChatBox>())) { UnityEventTools.AddStringPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinRoomFailed, ChatBox.GetComponent <ChatBox>().SetActiveChannel, "lobbyChat"); } // Misc - OnDisconnect Events if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, "Disconnect", ChatBox.GetComponent <ChatBox>())) { UnityEventTools.AddStringPersistentListener(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, ChatBox.GetComponent <ChatBox>().Disconnect, ""); } if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, "EnableChat", ChatBox.GetComponent <ChatBox>())) { UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, ChatBox.GetComponent <ChatBox>().EnableChat, false); } } }