Exemple #1
0
 void C_vBreakableObject(GameObject target)
 {
     if (_cvBreakableObjects == false)
     {
         return;
     }
     if (target.GetComponent <vBreakableObject>())
     {
         E_Helpers.SetObjectIcon(target, E_Core.h_genericIcon);
         if (!target.GetComponent <NetworkBreakObject>())
         {
             target.AddComponent <NetworkBreakObject>();
         }
         bool sync = !FindObjectOfType <NetworkManager>().syncScenes;
         target.GetComponent <NetworkBreakObject>().GetType().GetField("syncCrossScenes", E_Helpers.allBindings).SetValue(target.GetComponent <NetworkBreakObject>(), sync);
         if (sync == true)
         {
             target.GetComponent <NetworkBreakObject>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(target.GetComponent <NetworkBreakObject>(), target.transform);
         }
         if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vBreakableObject>().OnBroken, "BreakObject", target.GetComponent <NetworkBreakObject>()))
         {
             UnityEventTools.AddPersistentListener(target.GetComponent <vBreakableObject>().OnBroken, target.GetComponent <NetworkBreakObject>().BreakObject);
         }
     }
 }
Exemple #2
0
        private void AddNetworkManagerToScene()
        {
            // Will add this new tag to the inspector if it doesn't already exist
            E_Helpers.AddInspectorTag("SpawnPoint");

            GameObject _target = null;

            if (FindObjectOfType <NetworkManager>())
            {
                _target = FindObjectOfType <NetworkManager>().gameObject;
            }
            if (!_target)
            {
                _target = new GameObject("Network Manager");
            }
            if (!_target.GetComponent <NetworkManager>())
            {
                _target.AddComponent <NetworkManager>();
            }
            if (_target.GetComponent <NetworkManager>().defaultSpawnPoint == null)
            {
                GameObject spawnPoints = (GameObject.Find("Spawn Points")) ? GameObject.Find("Spawn Points") : new GameObject("Spawn Points");
                GameObject spawnPoint  = (GameObject.Find("Player Spawn Point")) ? GameObject.Find("Player Spawn Point") : new GameObject("Player Spawn Point");
                E_Helpers.SetObjectIcon(spawnPoint, E_Core.h_spawnPointIcon);
                _target.GetComponent <NetworkManager>().defaultSpawnPoint = spawnPoint.transform;
                spawnPoints.layer = 2;
                spawnPoint.layer  = 2;
                spawnPoint.tag    = "SpawnPoint";
                spawnPoint.transform.SetParent(spawnPoints.transform);
            }
            if (_target.GetComponent <NetworkManager>().database == null)
            {
                if (System.IO.File.Exists("Assets/Resources/ScenesDatabase/ScenesDatabase.asset"))
                {
                    SceneDatabase database = AssetDatabase.LoadAssetAtPath <SceneDatabase>("Assets/Resources/ScenesDatabase/ScenesDatabase.asset");
                    if (database)
                    {
                        _target.GetComponent <NetworkManager>().database = database;
                    }
                }
                else
                {
                    Debug.LogWarning("Was unable to automatically add a \"SceneDatabase\" to the database entry on the NetworkManager. Remember to add one before making your final build!");
                }
            }
            E_Helpers.SetObjectIcon(_target, E_Core.h_networkIcon);
            Selection.activeGameObject = _target;
            _target.layer = 2; // Ignore Raycast Layer
            if (!_target.GetComponent <PlayerRespawn>())
            {
                _target.AddComponent <PlayerRespawn>();
            }
            _target.GetComponent <PlayerRespawn>().visualCountdown = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/InvectorMultiplayer/UI/RespawnCounter.prefab");
            if (EditorUtility.DisplayDialog("Friendly Reminder", "Remember to adjust the spawn point to where you want it to be. \r\n" +
                                            "\r\n",
                                            "Okay"))
            {
                Debug.Log("Successfully added the \"Network Manager\" gameobject and assigned a Spawn Point.");
            }
        }
Exemple #3
0
 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;
         }
     }
 }
Exemple #4
0
        public static void CB_AddRespawnPoint()
        {
            // Will add this new tag to the inspector if it doesn't already exist
            E_Helpers.AddInspectorTag("RespawnPoint");

            GameObject respawnPoint = new GameObject("Respawn Point");

            respawnPoint.layer = 2;
            respawnPoint.tag   = "RespawnPoint";

            GameObject respawnPointParentGO = null;

            if (!GameObject.Find("Spawn Points"))
            {
                respawnPointParentGO       = new GameObject("Spawn Points");
                respawnPointParentGO.layer = 2;
                Debug.Log("Generated \"Spawn Points\" holder gameObject.");
            }
            else
            {
                respawnPointParentGO = GameObject.Find("Spawn Points");
            }
            respawnPoint.transform.SetParent(respawnPointParentGO.transform);
            respawnPoint.transform.position = E_Helpers.PositionInFrontOfEditorCamera();
            E_Helpers.SetObjectIcon(respawnPoint, E_Core.h_respawnPointIcon);
            Selection.activeGameObject = respawnPoint;
            Debug.Log("Added a new \"Respawn Point\" gameobject to the scene.");
        }
Exemple #5
0
 public static void CB_COMP_vHealthController(GameObject target)
 {
     if (target.GetComponent <vHealthController>())
     {
         if (!target.GetComponent <SyncHealthController>())
         {
             target.AddComponent <SyncHealthController>();
         }
         E_Helpers.SetObjectIcon(target, E_Core.h_genericIcon);
         vHealthController hc = target.GetComponent <vHealthController>();
         if (!E_PlayerEvents.HasUnityEvent(hc.onReceiveDamage, "SendDamageOverNetwork", target.GetComponent <SyncHealthController>()))
         {
             UnityEventTools.AddPersistentListener(hc.onReceiveDamage, target.GetComponent <SyncHealthController>().SendDamageOverNetwork);
         }
     }
     if (target.GetComponentInChildren <vHealthController>())
     {
         foreach (vHealthController hc in target.GetComponentsInChildren <vHealthController>())
         {
             if (!hc.gameObject.GetComponent <SyncHealthController>())
             {
                 hc.gameObject.AddComponent <SyncHealthController>();
             }
             E_Helpers.SetObjectIcon(hc.gameObject, E_Core.h_genericIcon);
             if (!E_PlayerEvents.HasUnityEvent(hc.onReceiveDamage, "SendDamageOverNetwork", hc.gameObject.GetComponent <SyncHealthController>()))
             {
                 UnityEventTools.AddPersistentListener(hc.onReceiveDamage, hc.gameObject.GetComponent <SyncHealthController>().SendDamageOverNetwork);
             }
         }
     }
 }
Exemple #6
0
 void C_Rigidbodies(GameObject target)
 {
     if (_cRigidbodies == false)
     {
         return;
     }
     if (target.GetComponent <Rigidbody>())
     {
         E_Helpers.SetObjectIcon(target, E_Core.h_genericIcon);
         if (target.GetComponent <vBreakableObject>())
         {
             return;
         }
         if (!target.GetComponent <PhotonRigidbodyView>())
         {
             target.AddComponent <PhotonRigidbodyView>();
         }
         if (!target.GetComponent <PhotonView>())
         {
             target.AddComponent <PhotonView>();
         }
         List <Component> observables = target.GetComponent <PhotonView>().ObservedComponents;
         if (observables == null || !observables.Contains(target.GetComponent <PhotonRigidbodyView>()))
         {
             observables = new List <Component>();
             observables.Add(target.GetComponent <PhotonRigidbodyView>());
         }
         target.GetComponent <PhotonView>().ObservedComponents = observables;
         target.GetComponent <PhotonView>().Synchronization    = ViewSynchronization.ReliableDeltaCompressed;
     }
 }
Exemple #7
0
 public static void CB_COMP_vBreakableObject(GameObject target)
 {
     if (target.GetComponent <vBreakableObject>())
     {
         if (!target.GetComponent <NetworkBreakObject>())
         {
             target.AddComponent <NetworkBreakObject>();
         }
         E_Helpers.SetObjectIcon(target, E_Core.h_genericIcon);
         if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vBreakableObject>().OnBroken, "BreakObject", target.GetComponent <NetworkBreakObject>()))
         {
             UnityEventTools.AddPersistentListener(target.GetComponent <vBreakableObject>().OnBroken, target.GetComponent <NetworkBreakObject>().BreakObject);
         }
     }
     if (target.GetComponentInChildren <vBreakableObject>())
     {
         foreach (vBreakableObject bo in target.GetComponentsInChildren <vBreakableObject>())
         {
             if (!bo.gameObject.GetComponent <NetworkBreakObject>())
             {
                 bo.gameObject.AddComponent <NetworkBreakObject>();
             }
             if (!E_PlayerEvents.HasUnityEvent(bo.OnBroken, "BreakObject", bo.gameObject.GetComponent <NetworkBreakObject>()))
             {
                 UnityEventTools.AddPersistentListener(bo.OnBroken, bo.gameObject.GetComponent <NetworkBreakObject>().BreakObject);
             }
             E_Helpers.SetObjectIcon(bo.gameObject, E_Core.h_genericIcon);
         }
     }
 }
Exemple #8
0
        public static void CB_COMP_vItemCollection(GameObject target)
        {
            //BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
            GameObject      go = null;
            vItemCollection ic = null;

            if (target.GetComponent <vItemCollection>())
            {
                go = target;
                ic = target.GetComponent <vItemCollection>();
            }
            else if (target.GetComponentInChildren <vItemCollection>())
            {
                go = target.GetComponentInChildren <vItemCollection>().transform.gameObject;
                ic = target.GetComponentInChildren <vItemCollection>();
            }
            if (go)
            {
                if (!go.GetComponent <SyncItemCollection>())
                {
                    go.AddComponent <SyncItemCollection>();
                }
                go.GetComponent <SyncItemCollection>().OnPressActionInput           = ic.OnPressActionInput;
                go.GetComponent <SyncItemCollection>().onPressActionInputWithTarget = ic.onPressActionInputWithTarget;
                go.GetComponent <SyncItemCollection>().onPressActionDelay           = ic.onPressActionDelay;
                bool sync = !FindObjectOfType <NetworkManager>().syncScenes;
                if (sync == true)
                {
                    go.GetComponent <SyncItemCollection>().OnSceneEnterUpdate = ic.OnPressActionInput;
                    if (ic.transform.parent != null)
                    {
                        go.GetComponent <SyncItemCollection>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), ic.transform.parent);
                    }
                    else
                    {
                        go.GetComponent <SyncItemCollection>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), ic.transform);
                    }
                }
                go.GetComponent <SyncItemCollection>().GetType().GetField("syncCrossScenes", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), sync);
                //bool skipStart = (ic.items.Count > 0);
                go.GetComponent <SyncItemCollection>().GetType().GetField("skipStartCheck", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), false);
                go.GetComponent <SyncItemCollection>().GetType().GetField("syncCreateDestroy", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), true);
                go.GetComponent <SyncItemCollection>().GetType().GetField("resourcesPrefab", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), ic.transform.root.name);

                ic.OnPressActionInput           = new UnityEvent();
                ic.onPressActionInputWithTarget = new OnDoActionWithTarget();
                ic.onPressActionDelay           = 0;

                UnityEventTools.AddPersistentListener(ic.onPressActionInputWithTarget, go.GetComponent <SyncItemCollection>().Collect);

                E_Helpers.SetObjectIcon(go, E_Core.h_genericIcon);

                CB_COMP_SHOOTER_vItemCollection(ic, go);
            }
        }
Exemple #9
0
        public static void CB_Scene_AddExit()
        {
            NetworkManager nm = GameObject.FindObjectOfType <NetworkManager>();

            if (!nm)
            {
                if (EditorUtility.DisplayDialog("No Found Network Manager", "The \"NetworkManager\" component doesn't exist in this scene. Please add it before continuing.",
                                                "Okay"))
                {
                }
                return;
            }
            GameObject sceneManager = GameObject.Find("SceneManager");

            if (!sceneManager)
            {
                sceneManager = new GameObject("SceneManager");
            }

            GameObject exitPoint = new GameObject("Exit Point");

            E_Helpers.SetObjectIcon(exitPoint, E_Core.h_sceneExitIcon);

            exitPoint.AddComponent <SceneTransition>();
            exitPoint.AddComponent <SetLoadingScreen>();

            SceneDatabase database = (SceneDatabase)AssetDatabase.LoadAssetAtPath(string.Format("Assets{0}Resources{0}ScenesDatabase{0}ScenesDatabase.asset", Path.DirectorySeparatorChar), typeof(SceneDatabase));

            exitPoint.GetComponent <SceneTransition>().SetDatabase(database);
            exitPoint.GetComponent <SceneTransition>().sendAllTogether = nm.syncScenes;

            UnityEvent beforeTravel = (UnityEvent)exitPoint.GetComponent <SceneTransition>().GetType().GetField("BeforeTravel", E_Helpers.allBindings).GetValue(exitPoint.GetComponent <SceneTransition>());

            if (beforeTravel == null)
            {
                exitPoint.GetComponent <SceneTransition>().GetType().GetField("BeforeTravel", E_Helpers.allBindings).SetValue(exitPoint.GetComponent <SceneTransition>(), new UnityEvent());
                beforeTravel = (UnityEvent)exitPoint.GetComponent <SceneTransition>().GetType().GetField("BeforeTravel", E_Helpers.allBindings).GetValue(exitPoint.GetComponent <SceneTransition>());
            }

            UnityEventTools.AddPersistentListener(beforeTravel, exitPoint.GetComponent <SetLoadingScreen>().EnableLoadingScreen);

            exitPoint.GetComponent <BoxCollider>().isTrigger = true;

            exitPoint.layer = 2;
            exitPoint.transform.SetParent(sceneManager.transform);
            exitPoint.transform.position = E_Helpers.PositionInFrontOfEditorCamera();
            Selection.activeGameObject   = exitPoint;

            Debug.Log("Successfully created scene exit point!");
        }
Exemple #10
0
        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);
        }
Exemple #11
0
 void C_vHealthController(GameObject target)
 {
     if (_cvHealthController == false)
     {
         return;
     }
     if (target.GetComponent <vHealthController>() && !target.GetComponent <vThirdPersonController>())
     {
         E_Helpers.SetObjectIcon(target, E_Core.h_genericIcon);
         if (!target.GetComponent <SyncHealthController>())
         {
             target.AddComponent <SyncHealthController>();
         }
         if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vHealthController>().onReceiveDamage, "SendDamageOverNetwork", target.GetComponent <SyncHealthController>()))
         {
             UnityEventTools.AddPersistentListener(target.GetComponent <vHealthController>().onReceiveDamage, target.GetComponent <SyncHealthController>().SendDamageOverNetwork);
         }
     }
 }
Exemple #12
0
 public static void CB_PreviewCamPoint()
 {
     if (!FindObjectOfType <PreviewCamera>())
     {
         if (EditorUtility.DisplayDialog("Missing \"PreviewCamera\" Component!", "Unable to find the \"PreviewCamera\" component in the scene. Please run \"CB Games/Add/Camera/Preview Camera Component\" before running this.",
                                         "Okay"))
         {
         }
     }
     else
     {
         PreviewCamera cam   = FindObjectOfType <PreviewCamera>();
         GameObject    point = new GameObject("CameraPoint");
         E_Helpers.SetObjectIcon(point, E_Core.h_cameraPath);
         point.transform.SetParent(cam.transform);
         cam.cameraPoints.Add(point.transform);
         Debug.Log("Successfully added camera point to the scene.");
     }
 }
Exemple #13
0
        public static void CB_AddSpawnPoint()
        {
            // Will add this new tag to the inspector if it doesn't already exist
            E_Helpers.AddInspectorTag("SpawnPoint");

            GameObject spawnPoint = new GameObject("Player Spawn Point");

            spawnPoint.layer = 2;
            spawnPoint.tag   = "SpawnPoint";

            if (!FindObjectOfType <NetworkManager>())
            {
                if (EditorUtility.DisplayDialog("Missing Network Manager", "No NetworkManager object was found in this scene. Be sure to add one since that is what these spawn points are for. :) \r\n" +
                                                "\r\n" +
                                                "",
                                                "Okay"))
                {
                }
            }
            GameObject spawnPointParentGO = null;

            if (!GameObject.Find("Spawn Points"))
            {
                spawnPointParentGO       = new GameObject("Spawn Points");
                spawnPointParentGO.layer = 2;
                spawnPointParentGO.tag   = "SpawnPoints";
                Debug.Log("Generated \"Spawn Points\" holder gameObject.");
            }
            else
            {
                spawnPointParentGO = GameObject.Find("Spawn Points");
            }
            spawnPoint.transform.SetParent(spawnPointParentGO.transform);
            spawnPoint.transform.position = E_Helpers.PositionInFrontOfEditorCamera();
            E_Helpers.SetObjectIcon(spawnPoint, E_Core.h_spawnPointIcon);
            Selection.activeGameObject = spawnPoint;
            Debug.Log("Added a new \"Player Spawn Point\" gameobject to the scene.");
        }
Exemple #14
0
        public static void CB_Scene_AddEntrance()
        {
            GameObject sceneManager = GameObject.Find("SceneManager");

            if (!sceneManager)
            {
                sceneManager = new GameObject("SceneManager");
            }

            if (!E_Helpers.InspectorTagExists("LoadPoint"))
            {
                E_Helpers.AddInspectorTag("LoadPoint");
            }
            GameObject entrancePoint = new GameObject("Scene Entrance Point");

            E_Helpers.SetObjectIcon(entrancePoint, E_Core.h_sceneEntranceIcon);
            entrancePoint.layer = 2;
            entrancePoint.tag   = "LoadPoint";
            entrancePoint.transform.SetParent(sceneManager.transform);
            entrancePoint.transform.position = E_Helpers.PositionInFrontOfEditorCamera();
            Selection.activeGameObject       = entrancePoint;
            Debug.Log("Successfully created scene entrance point!");
        }
Exemple #15
0
        IEnumerator ConvertPlayer(GameObject targetObj)
        {
            GameObject _builtPrefab = null;

            convertLog.Clear();
            _converting    = true;
            _errorsOccured = false;
            if (convertLog != null)
            {
                convertLog.Add("Beginning to convert: " + targetObj.name);
            }
            if (convertLog != null)
            {
                convertLog.Add("");
            }
            if (convertLog != null)
            {
                convertLog.Add("Copying " + targetObj.name + " -> MP_" + targetObj.name);
            }

            // Copy Player GameObject
            GameObject _copiedPlayer = GameObject.Instantiate(targetObj, targetObj.transform.position + Vector3.left, Quaternion.identity) as GameObject;

            _copiedPlayer.name = _copiedPlayer.name.Replace("(Clone)", "");
            _copiedPlayer.name = "MP_" + _copiedPlayer.name;

            //Add Components
            if (CB_addVoiceChat == true)
            {
                CB_COMP_PlayerVoiceChat(_copiedPlayer, ref convertLog);
            }
            if (CB_addNameBar == true)
            {
                CB_COMP_PlayerNameBar(_copiedPlayer, ref convertLog);
            }

            CB_COMP_vMeleeCombatInput(_copiedPlayer, ref convertLog);
            CB_COMP_vWeaponHolderManager(_copiedPlayer, ref convertLog);
            CB_COMP_vGenericAction(_copiedPlayer, ref convertLog);
            CB_COMP_vMeleeManager(_copiedPlayer, ref convertLog);

            CB_COMP_vHeadTrack(_copiedPlayer, ref convertLog);
            CB_COMP_vShooterMeleeInput(_copiedPlayer, ref convertLog);
            CB_COMP_vShooterManager(_copiedPlayer, ref convertLog);
            CB_COMP_vFreeClimb(_copiedPlayer, ref convertLog);
            CB_COMP_vSwimming(_copiedPlayer, ref convertLog);
            CB_COMP_vZipline(_copiedPlayer, ref convertLog);

            CB_COMP_SyncPlayer(_copiedPlayer, ref convertLog);
            CB_COMP_vThirdPersonController(_copiedPlayer, ref convertLog);
            CB_COMP_vItemManager(_copiedPlayer, ref convertLog);
            CB_COMP_vLadderAction(_copiedPlayer, ref convertLog);

            // Make sure the file name is unique, in case an existing Prefab has the same name.
            string saveLocation = string.Format("Assets{0}Resources{0}{1}.prefab", Path.DirectorySeparatorChar, _copiedPlayer.name);

            if (E_Helpers.CreateDirectory(E_Helpers.GetDirectoryPath(saveLocation)))
            {
                if (convertLog != null)
                {
                    convertLog.Add("Created Assets/Resources directory");
                }
            }

            E_Helpers.SetObjectIcon(_copiedPlayer, E_Core.h_playerIcon);

            if (E_Helpers.FileExists(saveLocation))
            {
                if (EditorUtility.DisplayDialog("Duplicate Detected!",
                                                "A prefab with the same name already exists, would you like to overwrite it or create a new one, keeping both?",
                                                "Overwrite", "Keep Both"))
                {
                    //Overwrite
                    E_Helpers.DeleteFile(saveLocation);
                    if (convertLog != null)
                    {
                        convertLog.Add("Generating prefab at: " + saveLocation);
                    }
                    PrefabUtility.SaveAsPrefabAsset(_copiedPlayer, saveLocation);
                }
                else
                {
                    //Keep Both
                    saveLocation = AssetDatabase.GenerateUniqueAssetPath(saveLocation);
                    if (convertLog != null)
                    {
                        convertLog.Add("Generating prefab at: " + saveLocation);
                    }
                    PrefabUtility.SaveAsPrefabAsset(_copiedPlayer, saveLocation);
                }
            }
            else
            {
                saveLocation = AssetDatabase.GenerateUniqueAssetPath(saveLocation);
                if (convertLog != null)
                {
                    convertLog.Add("Generating prefab at: " + saveLocation);
                }
                PrefabUtility.SaveAsPrefabAsset(_copiedPlayer, saveLocation);
            }

            if (FindObjectOfType <NetworkManager>())
            {
                if (convertLog != null)
                {
                    convertLog.Add("Adding generated prefab to the \"playerPrefab\" field in the \"NetworkManager\"");
                }
                _builtPrefab = E_Helpers.GetPrefabReference(saveLocation);
                int timeout = 4;
                int count   = 0;
                while (_builtPrefab == null)
                {
                    if (count == timeout)
                    {
                        Debug.LogWarning("Unable to locate the player prefab to place into the NetworkManager.");
                        break;
                    }
                    yield return(new WaitForSeconds(0.5f));

                    count       += 1;
                    _builtPrefab = E_Helpers.GetPrefabReference(saveLocation);
                }
                FindObjectOfType <NetworkManager>().playerPrefab = _builtPrefab;
            }
            else
            {
                if (convertLog != null)
                {
                    convertLog.Add("WARNING: Skipped adding to \"NetworkManager\" component.");
                }
                if (EditorUtility.DisplayDialog("Unable To Find NetworkManager",
                                                "No NetworkManager was found in the scene so this converted player was not added to the \"playerPrefab\"!" +
                                                " When the NetworkManager is added to the scene make sure to add the generated prefab in the \"Resources\" folder to that field.",
                                                "Okay"))
                {
                    Debug.LogWarning("No NetworkManager component was found in the scene so this prefab was not added a spawn object. When the NetworkManager component is added to the scene please add a prefab to it.");
                }
            }
            Selection.activeObject = _copiedPlayer;

            foreach (string log in convertLog)
            {
                Debug.Log(log);
            }
            yield return(null);
        }
Exemple #16
0
        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);
                }
            }
        }
Exemple #17
0
        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;
                }
            }
        }
Exemple #18
0
        void C_vItemCollection(GameObject target)
        {
            if (_cvItemCollections == false)
            {
                return;
            }
            if (!target.GetComponent <vItemCollection>())
            {
                return;
            }
            E_Helpers.SetObjectIcon(target, E_Core.h_genericIcon);
            if (!target.GetComponent <PhotonView>())
            {
                target.AddComponent <PhotonView>();
            }
            if (!target.transform.GetComponentInParent <PhotonView>() && !target.GetComponent <PhotonView>())
            {
                target.AddComponent <PhotonView>();
            }
            if (!target.GetComponent <SyncItemCollection>())
            {
                target.AddComponent <SyncItemCollection>();
            }
            bool useTarget = (target.GetComponent <vItemCollection>().onPressActionInputWithTarget.GetPersistentEventCount() > 0);

            // Copy Original Values to MP component
            target.GetComponent <SyncItemCollection>().onPressActionDelay           = target.GetComponent <vItemCollection>().onPressActionDelay;
            target.GetComponent <SyncItemCollection>().OnPressActionInput           = target.GetComponent <vItemCollection>().OnPressActionInput;
            target.GetComponent <SyncItemCollection>().onPressActionInputWithTarget = target.GetComponent <vItemCollection>().onPressActionInputWithTarget;

            target.GetComponent <SyncItemCollection>().GetType().GetField("syncCreateDestroy", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), false);
            target.GetComponent <SyncItemCollection>().GetType().GetField("skipStartCheck", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), target.GetComponent <vItemCollection>().items.Count > 0);

            // Clear Original Values
            target.GetComponent <vItemCollection>().onPressActionDelay           = 0.0f;
            target.GetComponent <vItemCollection>().OnPressActionInput           = new UnityEvent();
            target.GetComponent <vItemCollection>().onPressActionInputWithTarget = new OnDoActionWithTarget();

            // Set Scene Sync Options
            target.GetComponent <SyncItemCollection>().GetType().GetField("syncCrossScenes", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), true);
            target.GetComponent <SyncItemCollection>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), target.transform);

            if (target.GetComponent <vItemCollection>().destroyAfter == true)
            {
                target.GetComponent <SyncItemCollection>().OnSceneEnterUpdate = new UnityEvent();
                UnityEventTools.AddBoolPersistentListener(target.GetComponent <SyncItemCollection>().OnSceneEnterUpdate, target.SetActive, false);
            }

            // Set OpenChest Listener on original component
            if (useTarget == true)
            {
                UnityEventTools.AddPersistentListener(target.GetComponent <vItemCollection>().onPressActionInputWithTarget, target.GetComponent <SyncItemCollection>().Collect);
            }
            else
            {
                UnityEventTools.AddPersistentListener(target.GetComponent <vItemCollection>().OnPressActionInput, target.GetComponent <SyncItemCollection>().Collect);
            }
            //if (!E_PlayerEvents.HasUnityEvent(target.GetComponent<SyncItemCollection>().OnSceneEnterUpdate, "SetActive", target))
            //{
            //    UnityEventTools.AddBoolPersistentListener(target.GetComponent<SyncItemCollection>().OnSceneEnterUpdate, target.SetActive, false);
            //}
        }