void apparitionPlanete(Material planetMaterial, Planet planet) { if (globalGalaxyList == null) { globalGalaxyList = (GalaxyList)Resources.Load("Databases/GalaxyDatabase"); } if (!planetInfo.activeSelf) { planetInfo.SetActive(true); } setPlanetPosition(planet.galaxy, planet.stellarSystem, planet.planetID); SetPlanetInfo(planet); planetTextFieldName.text = planet.name; Renderer rend = new Renderer(); rend = sphere.GetComponent <Renderer>(); rend.material = planetMaterial; if (!sphere.activeSelf) { sphere.SetActive(true); } if (!planetTextName.activeSelf) { planetTextName.SetActive(true); } }
public static GalaxyList createGalaxyDatabase() { asset = ScriptableObject.CreateInstance <GalaxyList>(); AssetDatabase.CreateAsset(asset, "Assets/Resources/Databases/GalaxyDatabase.asset"); AssetDatabase.SaveAssets(); return(asset); }
Planet loadFromJson(Planet planet) { if (globalGalaxyList == null) { globalGalaxyList = (GalaxyList)Resources.Load("Databases/GalaxyDatabase"); } string filePath = Application.dataPath + "/Scenes/PlanetSaves/planetDataG" + planet.galaxy + "S" + planet.stellarSystem + "P" + planet.planetID + ".json"; if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); globalGalaxyList.galaxyList [planet.galaxy].stellarSystemList [planet.stellarSystem].planetList [planet.planetID].formatPlanetFromJson(JsonUtility.FromJson <PlanetToJson> (dataAsJson)); return(planet); } return(planet); }
private Material randomPlanetMaterial(string planetType, int galaxy, int stellarSystem, int planetNumber) { if (globalGalaxyList == null) { globalGalaxyList = (GalaxyList)Resources.Load("Databases/GalaxyDatabase"); } if (globalGalaxyList.galaxyList [galaxy].stellarSystemList [stellarSystem].planetList [planetNumber].planetMaterial == null) { List <string> materialList = new List <string> (); foreach (Object o in Resources.LoadAll("PlanetsTextures/" + planetType, typeof(Material))) { materialList.Add(o.name); } int randomMaterial = UnityEngine.Random.Range(0, materialList.Count); globalGalaxyList.galaxyList [galaxy].stellarSystemList [stellarSystem].planetList [planetNumber].planetMaterial = (Material)Resources.Load("PlanetsTextures/" + planetType + "/" + materialList [randomMaterial], typeof(Material)); } return(globalGalaxyList.galaxyList [galaxy].stellarSystemList [stellarSystem].planetList [planetNumber].planetMaterial); }
public void savePlanet(Planet planetToSave) { if (globalGalaxyList == null) { globalGalaxyList = (GalaxyList)Resources.Load("Databases/GalaxyDatabase"); } if (globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].savedMapHeight.GetLength(0) == 0) { globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].savedMapHeight = new int[planetToSave.savedMapHeight.GetLength(0)]; } planetToSave.savedMapHeight.CopyTo(globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].savedMapHeight, 0); int maximalHeight = GameObject.FindGameObjectWithTag("grid").GetComponent <PlanetGenerator> ().maximalHeight; if (globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].savedMapMatrix == null) { globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].savedMapMatrix = new int[planetToSave.savedMapMatrix.GetLength(0), maximalHeight]; } for (int x = 0; x < planetToSave.savedMapMatrix.GetLength(0); x++) { for (int y = 0; y < planetToSave.savedMapMatrix.GetLength(1); y++) { globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].savedMapMatrix[x, y] = planetToSave.savedMapMatrix[x, y]; } } globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].tilesType = planetToSave.tilesType; globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].playerLastPosition = new Vector3(0, 0, 0); globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID].playerLastPosition = planetToSave.playerLastPosition; saveToJson(globalGalaxyList.galaxyList [planetToSave.galaxy].stellarSystemList [planetToSave.stellarSystem].planetList [planetToSave.planetID]); }
public void OnGoToThePlanetClick() { if (globalGalaxyList == null) { globalGalaxyList = (GalaxyList)Resources.Load("Databases/GalaxyDatabase"); } if (systemTextName.activeSelf) { systemTextName.SetActive(false); systemGroupName.SetActive(false); } if (planetTextName.activeSelf) { planetTextName.SetActive(false); } if (sphere.activeSelf) { sphere.SetActive(false); } if (planetInfo.activeSelf) { planetInfo.SetActive(false); } if (galaxyTextName.activeSelf) { galaxyTextName.SetActive(false); galaxyGroupName.SetActive(false); } TPscript.setPlanet(loadFromJson(globalGalaxyList.galaxyList[a].stellarSystemList[b].planetList[c])); dashboard.SetActive(!dashboard.activeSelf); }
public void GenerateWorld() { globalGalaxyList = (GalaxyList)Resources.Load("Databases/GalaxyDatabase"); // Initialisation des variables et de la grid Initialisation(); if (planet.savedMapHeight.GetLength(0) == 0 || planet.savedMapMatrix == null) { planet.savedMapHeight = new int[planet.horizontalSize + sizeInterpolation]; planet.savedMapMatrix = new int[planet.horizontalSize + sizeInterpolation, maximalHeight]; planet.playerLastPosition = new Vector3(0, 0, 0); // Generation des vecteurs ainsi que de leur type de tile GenerateTileSettings(); planet.tilesType = new List <TileBase> (); planet.tilesType.Insert(0, (TileBase)null); planet.tilesType.Add(planet.planetType.ruleTile); planet.tilesType.Add(planet.planetType.unbreakableTile); unbreakableTileID = 2; // Ajout des tiles indestructibles for (int i = 0; i < planet.savedMapMatrix.GetLength(0); i++) { planet.savedMapMatrix [i, 0] = unbreakableTileID; } Vector2[] octaveOffsets = new Vector2[3]; InitVarCaves(ref octaveOffsets, planet.seedCave, 3, new Vector2(5f, 5f)); float maxNoiseHeight = float.MinValue; float minNoiseHeight = float.MaxValue; float halfWidth = 400 / 2f; float halfHeight = 100 / 2f; // Ajout des grottes AddPerlinNoiseCave(halfWidth, halfHeight, 20f, 3, 0.289f, 3f, octaveOffsets, maxNoiseHeight, minNoiseHeight, 0.0f, 0.30f, 0, planet.verticalSize / 2, Mathf.RoundToInt(planet.verticalSize * 0.05f)); AddPerlinNoiseCave(halfWidth, halfHeight, planet.caveWidth, 3, 0.439f, 3f, octaveOffsets, maxNoiseHeight, minNoiseHeight, 0.23f, planet.caveQuantity, 0, 1, planet.verticalSize / 2); // Ajout des minerais foreach (Ore ore in planet.oreList) { octaveOffsets = new Vector2[3]; InitVarCaves(ref octaveOffsets, ore.seedDeposit, 3, new Vector2(5f, 5f)); planet.tilesType.Add(ore.tile); AddPerlinNoiseArea(halfWidth, halfHeight, ore.depositWidth, 3, 0.0f, 3f, octaveOffsets, maxNoiseHeight, minNoiseHeight, 0.0f, ore.depositRarity / 10f, planet.tilesType.Count - 1, ore.area); } planet.tilesType.Add(planet.planetType.chestSprite); int nbTourDeBoucle = 0; int startingPos; bool chestPosFounded; bool restart; // Ajout des coffres int numChest = 0; while (numChest < planet.numberOfChest) { startingPos = Mathf.RoundToInt(UnityEngine.Random.Range(0, planet.savedMapMatrix.GetLength(0) - 1)); chestPosFounded = false; restart = false; for (int i = startingPos; i < planet.savedMapMatrix.GetLength(0) && !chestPosFounded && !restart; i++) { for (int j = 0; j < planet.savedMapHeight [i] && !chestPosFounded && !restart; j++) { if (planet.savedMapMatrix [i, j] == planet.tilesType.Count - 1) { restart = true; } else if (planet.savedMapMatrix [i, j] == 0) { planet.savedMapMatrix [i, j] = planet.tilesType.Count - 1; chestPosFounded = true; //print ("Chest placed !, [x,y] = ["+i+","+j+"]"); } } } nbTourDeBoucle++; if (!restart) { numChest++; } } // Ajout de la végétation List <int> allDifferentTreeSize = new List <int>(); // Ajout à tilesType et sauvegarde des différentes tailles d'arbres for (int i = 0; i < planet.planetType.treeList.Count; i++) { Flora tree = planet.planetType.treeList [i]; planet.tilesType.Add(tree.tree); if (!allDifferentTreeSize.Contains(tree.sizeX)) { AddSorted(allDifferentTreeSize, tree.sizeX); } } if (allDifferentTreeSize.Count > 0) { int largestTreeSize = allDifferentTreeSize[allDifferentTreeSize.Count - 1]; // Calculer toutes les positions possibles for (int i = 0; i < planet.savedMapMatrix.GetLength(0) - largestTreeSize; i++) { bool hasSpace = true; int randomTreeSize = UnityEngine.Random.Range(0, allDifferentTreeSize.Count); for (int k = 0; k < allDifferentTreeSize[randomTreeSize]; k++) { if (planet.savedMapMatrix [i + k, planet.savedMapHeight [i]] != 0 || planet.savedMapMatrix [i + k, planet.savedMapHeight [i] - 1] == 0) { hasSpace = false; break; } } if (hasSpace) { int randomStartNumber = UnityEngine.Random.Range(0, planet.planetType.treeList.Count); int valueInArray = randomStartNumber; for (int j = 0; j < planet.planetType.treeList.Count; j++) { valueInArray = mod(j + valueInArray, planet.planetType.treeList.Count); if (planet.planetType.treeList [valueInArray].sizeX == allDifferentTreeSize [randomTreeSize]) { break; } } planet.savedMapMatrix [i, planet.savedMapHeight [i]] = 100 + planet.tilesType.Count - planet.planetType.treeList.Count + valueInArray; i += allDifferentTreeSize[randomTreeSize]; } } } float xPos = (planet.savedMapMatrix.GetLength(0) * frontGround.cellSize.x) / 2; int numeroXdanslaliste = frontGround.WorldToCell(new Vector3(xPos, 0f, 0f)).x; int numeroYdanslaliste = planet.savedMapHeight [numeroXdanslaliste]; float yPos = numeroYdanslaliste * frontGround.cellSize.y; mainCharacter.transform.position = new Vector3(xPos, yPos + 0.9f, 0f); } else { mainCharacter.transform.position = new Vector3(planet.playerLastPosition.x, planet.playerLastPosition.y + 0.9f, planet.playerLastPosition.z); } /* * for (int i = 0; i < planet.savedMapMatrix.GetLength (0); i++) * for (int j = planet.savedMapHeight [i] - 1; j >= planet.savedMapHeight [i] - fieldOfRender.y - 5; j--) { * frontGround.SetTile (new Vector3Int (i, j, 0), planet.tilesType [planet.savedMapMatrix [i, j]]); * frontGround.SetColliderType (new Vector3Int (i, j, 0), ColliderCheckNeighboor(i,j)); * if (j < planet.savedMapHeight [i] - 1) * backGround.SetTile (new Vector3Int (i, j, 0), planet.planetType.backgroundTile); * } */ currentPos = frontGround.WorldToCell(mainCharacter.transform.position); }
static void Init() { globalGalaxyList = (GalaxyList)Resources.Load("Databases/GalaxyDatabase"); }