public void unloadMap(AvailableMap currentLoadedScene)
        {
            GameObject.Destroy(currentMapBase);

            /*    if (currentLoadedScene.parameters.Count > 0)
             *      UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(currentLoadedScene.parameters[0]);*/
        }
        public override void RestoreFromJSON(JSONClass json, bool restorePhysical = true, bool restoreAppearance = true, JSONArray presetAtoms = null)
        {
            base.RestoreFromJSON(json, restorePhysical, restoreAppearance, presetAtoms);

            string loaderType  = json["loaderType"];
            string fileName    = json["fileName"];
            string displayName = json["displayName"];

            JSONArray para = json["parameters"].AsArray;

            List <string> parameters = new List <string>();

            if (para.Count > 0)
            {
                for (int i = 0; i < para.Count; i++)
                {
                    string val = para[i].ToString().TrimEnd('\r', '\n');
                    val = val.Replace("\"", "");
                    parameters.Add(val);
                }
            }

            if (loaderType != null && loaderType.Length > 0)
            {
                AvailableMap am = new AvailableMap(fileName.TrimEnd('\r', '\n'), displayName.TrimEnd('\r', '\n'), loaderType.TrimEnd('\r', '\n'), parameters);

                MapLoaderPlugin.Instance.LoadMap(am, loaderType);
            }
        }
Exemplo n.º 3
0
 public void unloadMap(AvailableMap currentLoadedScene)
 {
     if (currentMapBase != null)
     {
         GameObject.Destroy(currentMapBase);
     }
 }
Exemplo n.º 4
0
        public void LoadMap(AvailableMap map, string loaderType)
        {
            if (loaders.ContainsKey(loaderType.Trim()))
            {
                MapLoader loader = loaders[loaderType];

                LoadMap(map, loader);
            }
        }
Exemplo n.º 5
0
        void createMapLoadButton(GameObject mapLoadContentGO, AvailableMap map, MapLoader loader)
        {
            Transform     panelPrefab      = getTransformByNameAndRoot("Panel", SuperController.singleton.mainMenuUI);
            Transform     buttonPrefab     = getTransformByNameAndRoot("Quit Button", SuperController.singleton.mainMenuUI);
            Transform     textPrefab       = getTransformByNameAndRoot("Text", SuperController.singleton.mainMenuUI);
            RectTransform buttonPrefabRT   = buttonPrefab.GetComponent <RectTransform>();
            RectTransform textPrefabRT     = textPrefab.GetComponent <RectTransform>();
            Image         imagePrefab      = buttonPrefab.GetComponent <Image>();
            string        style            = buttonPrefab.GetComponent <UIStyleButton>().styleName;
            RectTransform mapLoadContentRT = mapLoadContentGO.GetComponent <RectTransform>();

            GameObject mapLoadButtonGO = new GameObject("mapLoadButtonGO");

            mapLoadButtonGO.transform.localScale = panelPrefab.localScale;
            mapLoadButtonGO.transform.SetParent(mapLoadContentGO.transform, false);

            Button        mapLoadButtonUI    = mapLoadButtonGO.AddComponent <Button>();
            Image         mapLoadButtonImage = mapLoadButtonGO.AddComponent <Image>();
            UIStyleButton mplbStyle          = mapLoadButtonGO.AddComponent <UIStyleButton>();
            UIStyleImage  mpliStyle          = mapLoadButtonGO.AddComponent <UIStyleImage>();
            RectTransform mapButtonRT        = mapLoadButtonGO.GetComponent <RectTransform>();

            //Copy values from existing components.
            CopyImageValues(imagePrefab, mapLoadButtonImage);
            mplbStyle.styleName = style;
            mpliStyle.styleName = style;
            CopyRectTransformValues(buttonPrefabRT, mapButtonRT);

            //Create new gameobject and ui for button text
            GameObject mapLoadTextGO = new GameObject("MapLoadText");

            mapLoadTextGO.transform.localScale = textPrefab.localScale;
            mapLoadTextGO.transform.SetParent(mapLoadButtonGO.transform, false);
            Text          mapLoadText = mapLoadTextGO.AddComponent <Text>();
            UIStyleText   mpltStyle   = mapLoadButtonGO.AddComponent <UIStyleText>();
            RectTransform mapTextRT   = mapLoadTextGO.GetComponent <RectTransform>();

            //Copy values from existing components.
            CopyRectTransformValues(textPrefabRT, mapTextRT);
            CopyTextValues(textPrefab.GetComponent <Text>(), mapLoadText);
            mpltStyle.styleName = style;
            mapLoadContentRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mapLoadContentRT.rect.height + mapButtonRT.rect.height);

            //Update new components with adjusted values.
            mapLoadText.text = loader.Mapkey() + " - " + map.displayName;

            mapLoadButtonUI.onClick.AddListener(() =>
            {
                LoadMap(map, loader);
            });
        }
Exemplo n.º 6
0
        public void LoadMap(AvailableMap map, MapLoader loader)
        {
            if (currentLoadedScene != null)
            {
                currentLoader.unloadMap(currentLoadedScene);
            }

            currentLoadedScene = loader.loadMap(map);
            currentLoader      = loader;

            if (lm)
            {
                lm.am = currentLoadedScene;
            }
        }
Exemplo n.º 7
0
        void OnMapInit(GameObject gom, AvailableMap amp)
        {
            Atom coreControl = SuperController.singleton.GetComponent <Atom>();

            lm = coreControl.GetComponent <MapLoaderControl>();

            if (lm.controlAtom != null)
            {
                gom.transform.SetParent(getTransformByNameAndRoot("object", lm.controlAtom.transform), false);
            }

            if (lm)
            {
                lm.am = amp;
            }
        }
        public AvailableMap loadMap(AvailableMap mapName)
        {
            AssetBundle ab = MapLoaderPlugin.getBundle(mapName.fileName);

            string sceneName = "";

            mapName.parameters = new List <string>();
            if (ab != null)
            {
                if (ab.GetAllScenePaths().Length > 0)
                {
                    sceneName = ab.GetAllScenePaths()[0];
                    UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive);
                }
            }
            mapName.parameters.Add(sceneName);
            currentAvailMapLoad = mapName;
            return(mapName);
        }
Exemplo n.º 9
0
        public AvailableMap loadMap(AvailableMap mapName)
        {
            AssetBundle asb = MapLoaderPlugin.getBundle(mapName.fileName);

            if (asb != null && asb.GetAllAssetNames().Length > 0)
            {
                string asbN = asb.GetAllAssetNames()[0];

                GameObject gom = asb.LoadAsset <GameObject>(asbN);

                currentMapBase = GameObject.Instantiate(gom);

                MeshRenderer[] tt = currentMapBase.GetComponentsInChildren <MeshRenderer>();
                foreach (MeshRenderer at in tt)
                {
                    foreach (Material mx in at.sharedMaterials)
                    {
                        if (Shader.Find(mx.shader.name) != null)
                        {
                            mx.shader = Shader.Find(mx.shader.name);
                        }
                        else
                        {
                            mx.shader = Shader.Find("Standard");
                        }
                    }
                }

                SkinnedMeshRenderer[] ttx = currentMapBase.GetComponentsInChildren <SkinnedMeshRenderer>();
                foreach (SkinnedMeshRenderer at in ttx)
                {
                    foreach (Material mx in at.sharedMaterials)
                    {
                        if (Shader.Find(mx.shader.name) != null)
                        {
                            mx.shader = Shader.Find(mx.shader.name);
                        }
                        else
                        {
                            mx.shader = Shader.Find("Standard");
                        }
                    }
                }

                ParticleSystemRenderer[] psx = currentMapBase.GetComponentsInChildren <ParticleSystemRenderer>();
                foreach (ParticleSystemRenderer at in psx)
                {
                    foreach (Material mx in at.sharedMaterials)
                    {
                        if (Shader.Find(mx.shader.name) != null)
                        {
                            mx.shader = Shader.Find(mx.shader.name);
                        }
                        else
                        {
                            mx.shader = Shader.Find("Particles/Additive");
                        }
                    }
                }
            }

            onMapInit.Invoke(currentMapBase, mapName);

            return(mapName);
        }
Exemplo n.º 10
0
 public void unloadMap(AvailableMap currentLoadedScene)
 {
     GameObject.Destroy(mapRoot);
 }
Exemplo n.º 11
0
        public void OnLevelWasInitialized(int level)
        {
            //Make sure we're in the main VAM scenes
            if ((level == 1 || level == 6))
            {
                Atom coreControl = SuperController.singleton.GetAtomByUid("CoreControl");
                lm = coreControl.gameObject.GetComponent <MapLoaderControl>();

                if (!lm)
                {
                    lm = coreControl.gameObject.AddComponent <MapLoaderControl>();
                    coreControl.RegisterAdditionalStorable(lm);
                }
                Transform buttonPrefab   = getTransformByNameAndRoot("Quit Button", SuperController.singleton.mainMenuUI);
                Transform HRButtonPrefab = getTransformByNameAndRoot("Hard Reset Button", SuperController.singleton.mainMenuUI);

                Button mapLoadButtonUI = createMenuButton("Load External Map");
                Button unloadButtonUI  = createMenuButton("Unload External Map");

                RectTransform buttonPrefabRT = buttonPrefab.GetComponent <RectTransform>();
                //RectTransform hardResetRT = HRButtonPrefab.GetComponent<RectTransform>();
                RectTransform mapButtonRT    = mapLoadButtonUI.gameObject.GetComponent <RectTransform>();
                RectTransform unloadButtonRT = unloadButtonUI.gameObject.GetComponent <RectTransform>();

                mapButtonRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, mapButtonRT.rect.width / 2f);
                mapButtonRT.anchoredPosition = new Vector2(mapButtonRT.anchoredPosition.x - (mapButtonRT.rect.width / 2f), mapButtonRT.anchoredPosition.y + mapButtonRT.rect.height + 80f);
                unloadButtonRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, unloadButtonRT.rect.width / 2f);
                unloadButtonRT.anchoredPosition = new Vector2(unloadButtonRT.anchoredPosition.x - (unloadButtonRT.rect.width / 2f), unloadButtonRT.anchoredPosition.y + 70f);


                ScrollRect scrollRect     = createMapScrollRect();
                GameObject mapLoadPanelGO = scrollRect.gameObject;
                Scrollbar  scrollBarMB    = createScrollBar(mapLoadPanelGO);

                scrollRect.verticalScrollbar           = scrollBarMB;
                scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
                scrollRect.verticalScrollbarSpacing    = -3;

                mapLoadButtonUI.onClick.AddListener(() =>
                {
                    if (mapLoadPanelGO.activeSelf)
                    {
                        mapLoadPanelGO.SetActive(false);
                    }
                    else
                    {
                        mapLoadPanelGO.SetActive(true);
                    }
                });


                unloadButtonUI.onClick.AddListener(() =>
                {
                    if (currentLoader != null && currentLoadedScene != null)
                    {
                        currentLoader.unloadMap(currentLoadedScene);
                        currentLoader      = null;
                        currentLoadedScene = null;
                    }
                });

                GameObject mapLoadContentGO = mapLoadPanelGO.GetComponent <ScrollRect>().content.gameObject;

                foreach (KeyValuePair <AvailableMap, MapLoader> map in availableMaps)
                {
                    createMapLoadButton(mapLoadContentGO, map.Key, map.Value);
                }

                mapLoadPanelGO.SetActive(false);
            }
        }
        public AvailableMap loadMap(AvailableMap mapName)
        {
            AssetBundle asb = MapLoaderPlugin.getBundle(mapName.fileName);

            //check if there is a materials bundle as well, load it if it exists.
            string materialBundleName = "mat_etc_" + Path.GetFileName(mapName.fileName);

            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(mapName.fileName));

            string matPath = Path.Combine(di.Parent.FullName, materialBundleName);

            if (File.Exists(matPath))
            {
                AssetBundle materialBundle = MapLoaderPlugin.getBundle(matPath);
                materialBundle.LoadAllAssets();
            }

            currentMapBase = new GameObject(mapName.displayName);

            if (asb != null && asb.GetAllAssetNames().Length > 0)
            {
                foreach (string prefabName in mapName.parameters)
                {
                    GameObject gom = asb.LoadAsset <GameObject>(prefabName);

                    if (gom != null)
                    {
                        GameObject prefabAdd = GameObject.Instantiate(gom);
                        prefabAdd.transform.SetParent(currentMapBase.transform, true);
                    }
                }

                MeshRenderer[] tt = currentMapBase.GetComponentsInChildren <MeshRenderer>();
                foreach (MeshRenderer at in tt)
                {
                    foreach (Material mx in at.sharedMaterials)
                    {
                        if (Shader.Find(mx.shader.name) != null)
                        {
                            mx.shader = Shader.Find(mx.shader.name);
                        }
                        else
                        {
                            mx.shader = Shader.Find("Standard");
                        }
                    }
                }

                SkinnedMeshRenderer[] ttx = currentMapBase.GetComponentsInChildren <SkinnedMeshRenderer>();
                foreach (SkinnedMeshRenderer at in ttx)
                {
                    foreach (Material mx in at.sharedMaterials)
                    {
                        if (Shader.Find(mx.shader.name) != null)
                        {
                            mx.shader = Shader.Find(mx.shader.name);
                        }
                        else
                        {
                            mx.shader = Shader.Find("Standard");
                        }
                    }
                }

                ParticleSystemRenderer[] psx = currentMapBase.GetComponentsInChildren <ParticleSystemRenderer>();
                foreach (ParticleSystemRenderer at in psx)
                {
                    foreach (Material mx in at.sharedMaterials)
                    {
                        if (Shader.Find(mx.shader.name) != null)
                        {
                            mx.shader = Shader.Find(mx.shader.name);
                        }
                        else
                        {
                            mx.shader = Shader.Find("Particles/Additive");
                        }
                    }
                }
            }

            onMapInit.Invoke(currentMapBase, mapName);
            return(mapName);
        }
        public List <AvailableMap> getAvailableMaps(Dictionary <string, List <string> > configDirectories)
        {
            List <AvailableMap> availableMaps = new List <AvailableMap>();

            if (configDirectories.ContainsKey(MAPKEY))
            {
                foreach (string directory in configDirectories[MAPKEY])
                {
                    if (Directory.Exists(directory))
                    {
                        string[] files = Directory.GetFiles(Path.GetFullPath(directory), "*.unity3d");


                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];

                            AssetBundle mapContainer = MapLoaderPlugin.getBundle(file);

                            string[] asFiles = mapContainer.GetAllAssetNames();

                            Dictionary <string, AvailableMap> mapParams = new Dictionary <string, AvailableMap>();

                            foreach (string asFile in asFiles)
                            {
                                string lowerFile = asFile.ToLower();

                                if (lowerFile.Contains("prefabs") && !(lowerFile.Contains("cam") || lowerFile.Contains("haichi")))
                                {
                                    int lastSlash = asFile.LastIndexOf('/');

                                    string mapName = lastSlash > 8 ?asFile.Substring(lastSlash - 9, 9) : asFile;


                                    if (mapParams.ContainsKey(mapName))
                                    {
                                        mapParams[mapName].parameters.Add(asFile);
                                    }
                                    else
                                    {
                                        List <string> param = new List <string>();
                                        param.Add(asFile);
                                        AvailableMap amap = new AvailableMap(file, mapName, MAPKEY, param);
                                        mapParams.Add(mapName, amap);
                                    }
                                }
                                else if (lowerFile.Contains("map_hs") && !(lowerFile.Contains("cam") || lowerFile.Contains("haichi") || lowerFile.Contains("prefabs") || lowerFile.Contains("lightmap")))
                                {
                                    string mapName = Path.GetFileNameWithoutExtension(file);

                                    if (mapParams.ContainsKey(mapName))
                                    {
                                        mapParams[mapName].parameters.Add(asFile);
                                    }
                                    else
                                    {
                                        List <string> param = new List <string>();
                                        param.Add(asFile);
                                        AvailableMap amap = new AvailableMap(file, mapName, MAPKEY, param);
                                        mapParams.Add(mapName, amap);
                                    }
                                }
                            }

                            foreach (KeyValuePair <string, AvailableMap> mapsToAdd in mapParams)
                            {
                                availableMaps.Add(mapsToAdd.Value);
                            }
                        }
                    }
                }
            }

            return(availableMaps);
        }