public void LoadMapOnScene(MapsSaved map)
    {
        foreach (var item in pathsSaved.paths)
        {
            DestroyImmediate(item);
        }

        pathsSaved.paths.Clear();
        pathsSaved.objectType.Clear();
        pathsSaved.positions.Clear();

        int count = map.paths.Count;

        for (int i = 0; i < count; i++)
        {
            GameObject path = (GameObject)Instantiate(pathsSaved.objectsToInstantiate[map.objectType[i]]);
            path.transform.position = map.positions[i];
            path.AddComponent <Path>().currentIndex = map.objectType[i];
            path.GetComponent <Path>().lastIndex    = map.objectType[i];
            path.GetComponent <Path>().id           = i;

            pathsSaved.paths.Add(path);
            pathsSaved.objectType.Add(map.objectType[i]);
            pathsSaved.positions.Add(path.transform.position);
        }

        _seed.transform.position = map.positions[count - 1];
        _seed.mapLoaded          = true;
    }
示例#2
0
    public void LoadMapOnScene(MapsSaved map)
    {
        foreach (var item in pathsSaved.paths)
        {
            DestroyImmediate(item);
        }
        foreach (var item in pathsSaved.vessels)
        {
            DestroyImmediate(item);
        }

        pathsSaved.paths.Clear();
        pathsSaved.objectType.Clear();
        pathsSaved.positions.Clear();
        pathsSaved.rotations.Clear();

        pathsSaved.vessels.Clear();
        pathsSaved.vesselsType.Clear();
        pathsSaved.vesselsPositions.Clear();
        pathsSaved.vesselsDistance.Clear();

        int count = map.paths.Count;

        for (int i = 0; i < count; i++)
        {
            GameObject path = (GameObject)Instantiate(pathsSaved.objectsToInstantiate[map.objectType[i]]);
            path.transform.position = map.positions[i];
            path.AddComponent <Path>().currentIndex = map.objectType[i];
            path.GetComponent <Path>().lastIndex    = map.objectType[i];
            path.GetComponent <Path>().id           = i;
            path.transform.rotation = map.rotations[i];

            pathsSaved.paths.Add(path);
            pathsSaved.objectType.Add(map.objectType[i]);
            pathsSaved.positions.Add(path.transform.position);
            pathsSaved.rotations.Add(path.transform.rotation);
        }

        _seed.transform.position = map.positions[count - 1];

        count = map.vessels.Count;

        for (int i = 0; i < count; i++)
        {
            GameObject vessel = (GameObject)Instantiate(pathsSaved.vesselsToInstantiate[map.VesselsType[i]]);
            vessel.transform.position = map.vesselsPositions[i];
            vessel.AddComponent <Vessel>().currentIndex           = map.VesselsType[i];
            vessel.GetComponent <Vessel>().lastIndex              = map.VesselsType[i];
            vessel.GetComponent <Vessel>().id                     = i;
            vessel.GetComponent <Vessel>().distanceBetweenVessels = map.vesselsDistance[i];

            pathsSaved.vessels.Add(vessel);
            pathsSaved.vesselsType.Add(map.VesselsType[i]);
            pathsSaved.vesselsPositions.Add(vessel.transform.position);
            pathsSaved.vesselsDistance.Add(vessel.GetComponent <Vessel>().distanceBetweenVessels);
        }

        _seed.mapLoaded = true;
    }
    public void LoadMaps()
    {
        List <string> tempPath = new List <string>();

        var asset = AssetDatabase.FindAssets("t:MapsSaved", null);

        EditorGUILayout.BeginVertical(GUILayout.Height(maxYSize));
        _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, true, true);

        MapsSaved currentMap = null;

        for (int i = asset.Length - 1; i >= 0; i--)
        {
            //obtengo todo el path
            string path = AssetDatabase.GUIDToAssetPath(asset[i]);
            //separo las diferentes carpetas por el carcater /
            tempPath = path.Split('/').ToList();
            //obtengo la ultima parte, que seria el nombre con la extension y saco la extension
            var currentMapName = tempPath.LastOrDefault().Split('.');
            //si el nombre que obtuve con el que escribi son iguales entonces uso ese scriptable object

            EditorGUI.BeginDisabledGroup(true);
            currentMapName[0] = EditorGUILayout.TextField("Map name", currentMapName[0]);
            EditorGUI.EndDisabledGroup();

            _seed.mapNameLoaded = currentMapName[0];

            if (!wantToDeleteList[i])
            {
                if (!wantToDeleteList[i] && GUILayout.Button("Delete map"))
                {
                    wantToDeleteList[i] = true;
                }
            }
            else
            {
                if (GUILayout.Button("No") && wantToDeleteList[i])
                {
                    wantToDeleteList[i] = false;
                }
                if (GUILayout.Button("Yes") && wantToDeleteList[i])
                {
                    AssetDatabase.DeleteAsset(path);
                }
            }

            if (GUILayout.Button("Load map"))
            {
                currentMap = AssetDatabase.LoadAssetAtPath <MapsSaved>(path);
                LoadMapOnScene(currentMap);
            }

            EditorGUILayout.Space();
        }

        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
    }
    public void SaveMap()
    {
        if (_target.mapLoaded)
        {
            if (!saveMap && GUI.Button(new Rect(20, 100, buttonWidth, buttonHeight), "Save Map"))
            {
                saveMap = true;
            }

            if (saveMap && GUI.Button(new Rect(20, 100, buttonWidth, buttonHeight), "No"))
            {
                saveMap = false;
            }
            if (saveMap && GUI.Button(new Rect(160, 100, buttonWidth, buttonHeight), "Yes"))
            {
                List <string> tempPath = new List <string>();

                var asset = AssetDatabase.FindAssets("t:MapsSaved", null);

                MapsSaved currentMap = null;

                for (int i = asset.Length - 1; i >= 0; i--)
                {
                    //obtengo todo el path
                    string path = AssetDatabase.GUIDToAssetPath(asset[i]);
                    //separo las diferentes carpetas por el carcater /
                    tempPath = path.Split('/').ToList();
                    //obtengo la ultima parte, que seria el nombre con la extension y saco la extension
                    var currentMapName = tempPath.LastOrDefault().Split('.');
                    //si el nombre que obtuve con el que escribi son iguales entonces uso ese scriptable object
                    if (currentMapName[0] == _target.mapNameLoaded)
                    {
                        currentMap = AssetDatabase.LoadAssetAtPath <MapsSaved>(path);
                        break;
                    }
                }

                if (currentMap != null)
                {
                    currentMap.paths.Clear();
                    currentMap.objectType.Clear();
                    currentMap.positions.Clear();

                    currentMap.paths.AddRange(pathsSaved.paths);
                    currentMap.objectType.AddRange(pathsSaved.objectType);
                    currentMap.positions.AddRange(pathsSaved.positions);

                    //esto hace que cuando cierro unity y lo vuelvo a abrir no se pierda la info
                    EditorUtility.SetDirty(currentMap);
                    saveMap = false;
                }
            }
        }
    }
示例#5
0
    public void LoadMaps()
    {
        List <string> tempPath = new List <string>();

        var asset = AssetDatabase.FindAssets("t:MapsSaved", null);

        _searchMap = EditorGUILayout.TextField("Search map:", _searchMap);

        EditorGUILayout.Space();

        if (asset.Length <= 0)
        {
            EditorGUILayout.HelpBox("There are no maps saved! You have to create a new one before", MessageType.Info);
        }

        EditorGUILayout.HelpBox("Last map loaded is written with bold letters", MessageType.Info);

        EditorGUILayout.BeginVertical(GUILayout.Height(maxYSize));
        _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, true, true);

        MapsSaved currentMap = null;

        for (int i = asset.Length - 1; i >= 0; i--)
        {
            //obtengo todo el path
            string path = AssetDatabase.GUIDToAssetPath(asset[i]);
            //separo las diferentes carpetas por el carcater /
            tempPath = path.Split('/').ToList();
            //obtengo la ultima parte, que seria el nombre con la extension y saco la extension
            var currentMapName = tempPath.LastOrDefault().Split('.');
            //si el nombre que obtuve con el que escribi son iguales entonces uso ese scriptable object

            if (!string.IsNullOrEmpty(_searchMap) && !currentMapName[0].ToLower().Contains(_searchMap.ToLower()))
            {
                continue;
            }

            if (_seed.mapLoadedIndex == i)
            {
                EditorGUILayout.LabelField("Map name: " + currentMapName[0], EditorStyles.boldLabel);
                EditorGUILayout.LabelField("Total polygons: " + AssetDatabase.LoadAssetAtPath <MapsSaved>(path).totalPolygons, EditorStyles.boldLabel);
                EditorGUILayout.LabelField("Path: " + path, EditorStyles.boldLabel);
            }
            else
            {
                EditorGUILayout.LabelField("Map name: " + currentMapName[0]);
                EditorGUILayout.LabelField("Total polygons: " + AssetDatabase.LoadAssetAtPath <MapsSaved>(path).totalPolygons);
                EditorGUILayout.LabelField("Path: " + path);
            }

            //EditorGUI.EndDisabledGroup();

            if (!wantToDeleteList[i])
            {
                if (!wantToDeleteList[i] && GUILayout.Button("Delete map"))
                {
                    wantToDeleteList[i] = true;
                }
            }
            else
            {
                if (GUILayout.Button("No") && wantToDeleteList[i])
                {
                    wantToDeleteList[i] = false;
                }
                if (GUILayout.Button("Yes") && wantToDeleteList[i])
                {
                    wantToDeleteList[i] = false;
                    AssetDatabase.DeleteAsset(path);
                    if (_seed.currentMap == currentMap)
                    {
                        _seed.mapLoaded      = false;
                        _seed.mapLoadedIndex = -1;
                    }
                }
            }

            if (GUILayout.Button("Load map"))
            {
                _seed.mapNameLoaded  = currentMapName[0];
                currentMap           = AssetDatabase.LoadAssetAtPath <MapsSaved>(path);
                _seed.currentMap     = currentMap;
                _seed.mapLoadedIndex = i;
                LoadMapOnScene(currentMap);
            }

            EditorGUILayout.Space();
        }

        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
    }
    public void SaveMap()
    {
        if (pathsSaved == null)
        {
            return;
        }

        _mapName = EditorGUILayout.TextField("Map name", _mapName);

        if (String.IsNullOrEmpty(_mapName))
        {
            EditorGUILayout.HelpBox("Name field is empty!", MessageType.Warning);
        }

        if (CheckIfNameExist(_mapName, _fullPath))
        {
            EditorGUILayout.HelpBox("That name is already in use!", MessageType.Warning);
        }

        EditorGUILayout.LabelField("Path Selected: " + _fullPath);

        if (!CheckPathSelected())
        {
            EditorGUILayout.HelpBox("Select the folder where you wish to save the map!", MessageType.Warning);
        }

        EditorGUILayout.LabelField("Total polygons: " + pathsSaved.totalPolygons);

        if (GUILayout.Button("Select folder"))
        {
            string tempPathSeparated = "";
            _path = EditorUtility.OpenFolderPanel("Select folder", "Assets/", string.Empty);

            tempPathSeparated = _path.Split(new[] { "/" }, StringSplitOptions.None).Last();
            if (tempPathSeparated == "Assets")
            {
                _path = _path + "/";
            }

            _fullPath = _path;
            if (!String.IsNullOrEmpty(_path))
            {
                _path = _path.Split(new[] { "Assets/" }, StringSplitOptions.None)[1];
            }

            Repaint();
        }

        if (GUILayout.Button("Save map"))
        {
            List <string> tempPath = new List <string>();
            if (CheckPathSelected())
            {
                if (!String.IsNullOrEmpty(_mapName))
                {
                    if (!CheckIfNameExist(_mapName, _fullPath))
                    {
                        if (pathsSaved.paths.Count > 0)
                        {
                            ScriptableObjectUtility.CreateAsset <MapsSaved>(_path + "/" + _mapName);

                            var asset = AssetDatabase.FindAssets("t:MapsSaved", null);

                            MapsSaved currentMap = null;

                            for (int i = asset.Length - 1; i >= 0; i--)
                            {
                                //obtengo todo el path
                                string path = AssetDatabase.GUIDToAssetPath(asset[i]);
                                //separo las diferentes carpetas por el carcater /
                                tempPath = path.Split('/').ToList();

                                if (!String.IsNullOrEmpty(_path))
                                {
                                    if (path == "Assets/" + _path + "/" + _mapName + ".asset")
                                    {
                                        if (File.Exists(_fullPath + "/" + tempPath.Last()))
                                        {
                                            currentMap           = AssetDatabase.LoadAssetAtPath <MapsSaved>("Assets/" + _path + "/" + _mapName + ".asset");
                                            _seed.mapNameLoaded  = _mapName;
                                            _seed.mapLoaded      = true;
                                            _seed.currentMap     = currentMap;
                                            _seed.mapLoadedIndex = i;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    if (path == "Assets/" + _mapName + ".asset")
                                    {
                                        if (File.Exists(_fullPath + "/" + tempPath.Last()))
                                        {
                                            currentMap           = AssetDatabase.LoadAssetAtPath <MapsSaved>("Assets/" + _mapName + ".asset");
                                            _seed.mapNameLoaded  = _mapName;
                                            _seed.mapLoaded      = true;
                                            _seed.currentMap     = currentMap;
                                            _seed.mapLoadedIndex = i;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (currentMap != null)
                            {
                                currentMap.paths.AddRange(pathsSaved.paths);
                                currentMap.objectType.AddRange(pathsSaved.objectType);
                                currentMap.positions.AddRange(pathsSaved.positions);
                                currentMap.rotations.AddRange(pathsSaved.rotations);

                                currentMap.vessels.AddRange(pathsSaved.vessels);
                                currentMap.VesselsType.AddRange(pathsSaved.vesselsType);
                                currentMap.vesselsPositions.AddRange(pathsSaved.vesselsPositions);
                                currentMap.vesselsDistance.AddRange(pathsSaved.vesselsDistance);

                                currentMap.totalPolygons = pathsSaved.totalPolygons;
                                //esto hace que cuando cierro unity y lo vuelvo a abrir no se pierda la info
                                EditorUtility.SetDirty(currentMap);

                                Close();
                            }
                        }
                    }
                }
            }
        }

        if (pathsSaved.paths.Count <= 0)
        {
            EditorGUILayout.HelpBox("There are no objects created in the map!", MessageType.Warning);
        }
    }
示例#7
0
    public void SaveMap()
    {
        _mapName = EditorGUILayout.TextField("Map name", _mapName);

        EditorGUI.BeginDisabledGroup(true);
        _path = EditorGUILayout.TextField("Path Selected", _path);
        EditorGUI.EndDisabledGroup();

        if (GUILayout.Button("Select folder"))
        {
            _path = EditorUtility.OpenFolderPanel("Select folder", "Assets/", _path);

            if (!String.IsNullOrEmpty(_path))
            {
                _path = _path.Split(new[] { "Assets/" }, StringSplitOptions.None)[1];
            }

            Repaint();
        }

        if (GUILayout.Button("Save map"))
        {
            List <string> tempPath = new List <string>();

            if (!String.IsNullOrEmpty(_mapName))
            {
                if (!CheckIfNameExist(_mapName))
                {
                    if (pathsSaved.paths.Count > 0)
                    {
                        ScriptableObjectUtility.CreateAsset <MapsSaved>(_path + "/" + _mapName);

                        var asset = AssetDatabase.FindAssets("t:MapsSaved", null);

                        MapsSaved currentMap = null;

                        for (int i = asset.Length - 1; i >= 0; i--)
                        {
                            //obtengo todo el path
                            string path = AssetDatabase.GUIDToAssetPath(asset[i]);
                            //separo las diferentes carpetas por el carcater /
                            tempPath = path.Split('/').ToList();
                            //obtengo la ultima parte, que seria el nombre con la extension y saco la extension
                            var currentMapName = tempPath.LastOrDefault().Split('.');
                            //si el nombre que obtuve con el que escribi son iguales entonces uso ese scriptable object
                            if (currentMapName[0] == _mapName)
                            {
                                currentMap = AssetDatabase.LoadAssetAtPath <MapsSaved>(path);
                                break;
                            }
                        }

                        if (currentMap != null)
                        {
                            currentMap.paths.AddRange(pathsSaved.paths);
                            currentMap.objectType.AddRange(pathsSaved.objectType);
                            currentMap.positions.AddRange(pathsSaved.positions);

                            //esto hace que cuando cierro unity y lo vuelvo a abrir no se pierda la info
                            EditorUtility.SetDirty(currentMap);
                        }
                    }
                }
            }
        }

        if (String.IsNullOrEmpty(_mapName))
        {
            EditorGUILayout.HelpBox("Name field is empty!", MessageType.Warning);
        }

        if (pathsSaved.paths.Count <= 0)
        {
            EditorGUILayout.HelpBox("There are no paths created!", MessageType.Warning);
        }

        if (CheckIfNameExist(_mapName))
        {
            EditorGUILayout.HelpBox("That name is already in use!", MessageType.Warning);
        }
    }