protected override AbstractShape createShapes(string code) { AbstractShape shape = null; switch (code) { case "Circle": shape = new CCircle(); break; case "Rectangle": shape = new CRectangle(); break; case "Polygon": shape = new CPolygon(); break; case "Star": shape = new CStar(); break; case "Group": shape = new CGroup(); break; } return(shape); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (!SolarSystemManager.m_solarSystemInstance.solarSystemViewActive) { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(mouseRay, out hit)) { MoveSelectionIcon(hit); if (Input.GetMouseButtonDown(0)) { CStar m_star = returnStarFromGameobject(hit.transform.gameObject); infoText.text = "Selected Star : \n" + "Star Name : " + m_star.m_starName + "\n" + "Star Type : " + m_star.m_starType + "\n" + "Position : " + m_star.m_starPosition + "\n" + "Number of planets : " + m_star.m_planetNumber + "\n"; } } else { selectionIcon.SetActive(false); } } } }
public CPlanet(CStar parent, string name, E_PLANET_TYPE type, float size, Vector3 position) { m_parentStar = parent; m_planetName = name; m_planetType = type; m_planetSize = size; m_planetPosition = position; m_colony = null; m_planetResources = new CResources(); switch (m_planetType) { case E_PLANET_TYPE.E_BARREN: m_planetResources.BarrenInit(); break; case E_PLANET_TYPE.E_LUSH: m_planetResources.LushInit(); break; case E_PLANET_TYPE.E_GAS_GIANT: m_planetResources.GasGiantInit(); break; } }
private void InitStars() { stars = new ArrayList(); CStar s = new CStar(100, 200, 50, 50, 0, Color.FromArgb(100, Color.Red)); stars.Add(s); }
void CreateStars() { int randomType = 0; Vector3 position = new Vector3(); float distance = 0f; float angle = 0f; float scale = 0f; int planetNumber = 0; int failCount = 0; CStar tmpStar; if (m_galaxySeedNumber != 0) { UnityEngine.Random.InitState(m_galaxySeedNumber); } //m_galaxySeedNumber = UnityEngine.Random; for (int i = 0; i < numberOfStars; i++) { randomType = (int)Mathf.Round(UnityEngine.Random.Range(0, (float)E_StarType.E_STAR_TYPE_NB - 0.55f)); //Random geometric values distance = UnityEngine.Random.Range(minimalDistanceFromCenter, galaxyRadius); angle = UnityEngine.Random.Range(0, 2 * Mathf.PI); scale = UnityEngine.Random.Range(.5f, 1.5f); planetNumber = (int)Mathf.Round(UnityEngine.Random.Range((float)cst.E_MINIMUM_PLANET_NUMBER, (float)cst.E_MAXIMUM_PLANET_NUMBER) ); position.Set(distance * Mathf.Cos(angle), 0, distance * Mathf.Sin(angle)); Collider[] tmp = Physics.OverlapSphere(position, minDistanceBetweenStars + 10f); if (tmp.Length == 0) { GameObject instance = Instantiate(Resources.Load(Constantes.prefab_names[randomType])) as GameObject; instance.transform.SetParent(this.transform); instance.transform.position = position; instance.transform.localScale = new Vector3(scale, scale, scale); // We init all stars with none faction. This will be determined later tmpStar = new CStar("Star " + i, scale, randomType, position, planetNumber, E_FACTION.E_NONE); starToGameObject.Add(tmpStar, instance); listOfStars.Add(tmpStar); failCount = 0; } else { failCount++; i--; } if (failCount > 100) { Debug.Log("Too much fails during generation, stop !"); break; } } }
private void SelectPlayerStar() { int selectedStar, selectedPlanet; selectedStar = returnStarIndexContainingLushPlanet(); if (selectedStar == -1) { Debug.Log("Alert, impossible to find star with lush planet !"); return; } selectedPlanet = returnLushPlanetIndex(selectedStar); if (selectedPlanet == -1) { Debug.Log("Alert impossible to find lush planet in star " + selectedStar); return; } CStar star = listOfStars[selectedStar]; star.m_parentFaction = E_FACTION.E_PLAYER; PlayerManager.playerInstance.m_playerStarList.Add(star); CPlanet selectStartPlanet = star.m_planetList[selectedPlanet]; CColony startColony = new CColony(selectStartPlanet); PlayerManager.playerInstance.m_playerColonyList.Add(startColony); selectStartPlanet.m_colony = startColony; GameObject instance = Instantiate(Resources.Load(Constantes.prefab_sprite_green_circle_name)) as GameObject; instance.transform.SetParent(PlayerManager.playerInstance.gameObject.transform); instance.transform.localScale *= 3f; instance.transform.position = star.m_starPosition; //store star and green circle game object in dict PlayerManager.playerInstance.m_playerStarsToCircle.Add(star, instance); GameObject instanceColonyGreenCircle = Instantiate(Resources.Load(Constantes.prefab_sprite_green_circle_name)) as GameObject; instanceColonyGreenCircle.transform.SetParent(PlayerManager.playerInstance.gameObject.transform); instanceColonyGreenCircle.transform.localScale *= 3f; instanceColonyGreenCircle.transform.position = startColony.m_parentPlanet.m_planetPosition; instanceColonyGreenCircle.gameObject.SetActive(false); // will be done in solar system view PlayerManager.playerInstance.m_playerPlanetcolonyToPlayerCircle.Add(startColony, instanceColonyGreenCircle); }
void UpdateColonyInfoInGalaxyView(CStar star) { Text[] colonyInfoTxt = m_playerColonyInfos.GetComponentsInChildren <Text>(); for (int index = 0; index < colonyInfoTxt.Length; index++) { if (colonyInfoTxt[index].name == "Text") { colonyInfoTxt[index].text = "Star : " + star.m_starName.ToString() + "\n"; colonyInfoTxt[index].text += "With " + star.m_planetNumber.ToString() + " Planets\n"; //for (int i = 0; i < star.m_planetNumber; i++) //{ // colonyInfoTxt[index].text += "Planet : " + star.m_planetList[i].m_planetName.ToString() // + " Type : " + star.m_planetList[i].m_planetType+ "\n"; //} break; } } }
// Update is called once per frame void Update() { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(mouseRay, out hit)) { GalaxyManager.galaxyInstance.MoveSelectionIcon(hit); // Entering from galaxy view to solar system view if (Input.GetMouseButtonDown(1) && !solarSystemViewActive) { m_star = GalaxyManager.galaxyInstance.returnStarFromGameobject(hit.transform.gameObject); if (m_star != null) { GalaxyManager.galaxyInstance.DestroyGalaxy(); CreateSolarSystem(); ShowPlayerColonizedPlanets(); } } else if (Input.GetMouseButtonDown(0) && solarSystemViewActive) { CPlanet planet = returnPlanetFromGameObject(hit.transform.gameObject); if (planet != null) { infoText.text = "Selected Planet : \n" + "Planet Name : " + planet.m_planetName + "\n" + "Planet Type : " + planet.m_planetType + "\n" + "Position : " + planet.m_planetPosition.ToString() + "\n"; } else if (m_centralStarToGameObject.Values.ToList().IndexOf(hit.transform.gameObject) != -1) { infoText.text = "Star of the solar system : \n" + "Name : " + m_star.m_starName + "\n" + "Type : " + m_star.m_starType + "\n"; } } } else { GalaxyManager.galaxyInstance.selectionIcon.SetActive(false); } }
public void ResetGalaxy() { SolarSystemManager.m_solarSystemInstance.DestroySolarSystem(); for (int i = 0; i < starToGameObject.Count; i++) { //GameObject instance = starToGameObject.Values.ToList()[i]; CStar tmpStar = starToGameObject.Keys.ToList()[i]; GameObject instance = Instantiate(Resources.Load(Constantes.prefab_names[(int)tmpStar.m_starType])) as GameObject; instance.transform.SetParent(this.transform); instance.transform.position = tmpStar.m_starPosition; instance.transform.localScale = new Vector3(tmpStar.m_starSize, tmpStar.m_starSize, tmpStar.m_starSize); starToGameObject[tmpStar] = instance; } //Update player stars icons for (int i = 0; i < PlayerManager.playerInstance.m_playerStarsToCircle.Values.ToList().Count; i++) { PlayerManager.playerInstance.m_playerStarsToCircle.Values.ToList()[i].SetActive(true); } resetGalaxyButton.gameObject.SetActive(false); destroyGalaxyButton.gameObject.SetActive(true); }
// Update is called once per frame void Update() { //Update in galaxy if (!SolarSystemManager.m_solarSystemInstance.solarSystemViewActive) { //check for star clicks if (Input.GetMouseButtonDown(0)) { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(mouseRay, out hit)) { CStar star = GalaxyManager.galaxyInstance.returnStarFromGameobject(hit.transform.gameObject); if (star != null) { if (star.m_parentFaction == E_FACTION.E_PLAYER) { m_playerColonyInfos.gameObject.SetActive(true); UpdateColonyInfoInGalaxyView(star); } } } else { m_playerColonyInfos.gameObject.SetActive(false); } } }// Update in solar system view else { // check for planet clicks if (Input.GetMouseButtonDown(0)) { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(mouseRay, out hit)) { CPlanet planet = SolarSystemManager.m_solarSystemInstance.returnPlanetFromGameObject(hit.transform.gameObject); if (planet != null) { if (planet.m_parentStar.m_parentFaction == E_FACTION.E_PLAYER) { if (planet.m_colony != null) { m_playerColonyInfos.gameObject.SetActive(true); UpdateColonyInfoInSolarSystemView(planet.m_colony); } } } } else { m_playerColonyInfos.gameObject.SetActive(false); } } // Check right click on colonized planet to print colony management canva; else if (Input.GetMouseButtonDown(1)) { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(mouseRay, out hit)) { CPlanet planet = SolarSystemManager.m_solarSystemInstance.returnPlanetFromGameObject(hit.transform.gameObject); if (planet != null) { if (planet.m_parentStar.m_parentFaction == E_FACTION.E_PLAYER) { if (planet.m_colony != null) { // todo m_playerColonyInfos.gameObject.SetActive(false); m_colonyManagerImage.gameObject.SetActive(true); UIColonyManager.uiColonyManagerInstance.ShowColonyManager(planet.m_colony); Debug.Log("Entering in colony management scene"); } } } } } } }