示例#1
0
        void Setup()
        {
            string[] scenes = System.IO.Directory.GetFiles(".", "*.unity", System.IO.SearchOption.AllDirectories);

            if (selectedPackage == Packages.UnityNetworking)
            {
                NetworkManagerCustom           netManager   = (NetworkManagerCustom)AssetDatabase.LoadAssetAtPath("Assets/TanksMultiplayer/Prefabs/Network.prefab", typeof(NetworkManagerCustom));
                System.Reflection.PropertyInfo playerPrefab = netManager.GetType().GetProperty("playerPrefab");
                playerPrefab.SetValue(netManager, Resources.Load("TankFree"), null);
                AssetDatabase.ImportAsset("Assets/TanksMultiplayer/Scripts/GameManager.cs");

                Debug.Log("Tanks Multiplayer - Setup Done!");
            }

            if (selectedPackage == Packages.Mirror)
            {
                NetworkManagerCustom        netManager   = (NetworkManagerCustom)AssetDatabase.LoadAssetAtPath("Assets/TanksMultiplayer/Prefabs/Network.prefab", typeof(NetworkManagerCustom));
                System.Reflection.FieldInfo playerPrefab = netManager.GetType().GetField("playerPrefab");
                playerPrefab.SetValue(netManager, Resources.Load("TankFree"));
                AssetDatabase.ImportAsset("Assets/TanksMultiplayer/Scripts/GameManager.cs");
            }

            if (selectedPackage == Packages.Mirror && EditorUtility.DisplayDialog("Step 2: Setup Package Contents for Mirror", "Step 2 is a manual step.\n\n" +
                                                                                  "Please open all game scenes and save them once! This is needed so that Unity correctly assigns ViewIDs to networked objects.", "I understand!"))
            {
            }

            if (selectedPackage == Packages.PhotonPUN)
            {
                #if !PUN_2_OR_NEWER
                Debug.LogError("Tanks Multiplayer - Network Setup: Could not find Photon Scripting Define. Did you import Photon yet?");
                #else
                if (EditorUtility.DisplayDialog("Step 2: Setup Package Contents for Photon", "Step 2 is a manual step.\n\n" +
                                                "Please open all game scenes, unpack the 'ObjectSpawner' prefabs and save the scene. This is needed so that Photon correctly assigns ViewIDs to networked objects.\n\n" +
                                                "For a screenshot on what to do, please see our documentation PDF.", "I understand!"))
                {
                }
                #endif
            }

            foreach (string scene in scenes)
            {
                if (scene.EndsWith("Intro.unity"))
                {
                    EditorSceneManager.OpenScene(scene);
                    break;
                }
            }
        }
示例#2
0
        void Setup()
        {
            string[] scenes = System.IO.Directory.GetFiles(".", "*.unity", System.IO.SearchOption.AllDirectories);

            if (selectedPackage == Packages.UnityNetworking)
            {
                NetworkManagerCustom           netManager   = (NetworkManagerCustom)AssetDatabase.LoadAssetAtPath("Assets/TanksMultiplayer/Prefabs/Network.prefab", typeof(NetworkManagerCustom));
                System.Reflection.PropertyInfo playerPrefab = netManager.GetType().GetProperty("playerPrefab");
                playerPrefab.SetValue(netManager, Resources.Load("TankFree"), null);
                AssetDatabase.ImportAsset("Assets/TanksMultiplayer/Scripts/GameManager.cs");
            }

            if (selectedPackage == Packages.PhotonPUN)
            {
                #if !PUN_2_OR_NEWER
                Debug.LogError("Tanks Multiplayer - Network Setup: Could not find PhotonViewHandler. Did you import Photon yet?");
                #else
                EditorWindow photonWin = Photon.Pun.PhotonViewHandler.GetWindowWithRect(typeof(Photon.Pun.PhotonViewHandler), new Rect(0, 0, 0, 0));
                System.Reflection.MethodInfo hierarchyMethod = photonWin.GetType().GetMethod("HierarchyChange", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.DeclaredOnly);

                //automatic assignment of PhotonView IDs in non-loaded scenes
                foreach (string scene in scenes)
                {
                    if (scene.EndsWith("Game.unity"))
                    {
                        EditorSceneManager.OpenScene(scene);

                        //we have to disconnect all prefab connections first, because otherwise they can't be manipulated
                        //in the PhotonViewHandler.HierarchyChange method - seems like a Unity bug
                        ObjectSpawner[] objects = FindObjectsOfType(typeof(ObjectSpawner)) as ObjectSpawner[];
                        if (objects == null || objects.Length == 0)
                        {
                            continue;
                        }

                        for (int i = 0; i < objects.Length; i++)
                        {
                            if (PrefabUtility.IsPartOfPrefabInstance(objects[i]))
                            {
                                PrefabUtility.UnpackPrefabInstance(objects[i].gameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
                            }
                        }

                        hierarchyMethod.Invoke(photonWin, null);
                        EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), EditorSceneManager.GetActiveScene().path);
                    }
                }

                photonWin.Close();
                #endif
            }

            foreach (string scene in scenes)
            {
                if (scene.EndsWith("Intro.unity"))
                {
                    EditorSceneManager.OpenScene(scene);
                    break;
                }
            }

            Debug.Log("Tanks Multiplayer - Setup Done!");
        }