public CQuadtree(Vector3 up, Vector3 front, CPlanet planet, Texture2D shapeTex) { m_Planet = planet; m_ShapeTex = shapeTex; m_Up = m_SUp = up; m_Front = m_SFront = front; m_Right = -Vector3.Cross(m_Up, m_Front); m_Parent = null; m_SplitLevel = 0; m_Size = m_Planet.m_Radius * 2; m_Neighbors[0].node = m_Neighbors[1].node = m_Neighbors[2].node = m_Neighbors[3].node = null; m_Neighbors[0].isFixed = m_Neighbors[1].isFixed = m_Neighbors[2].isFixed = m_Neighbors[3].isFixed = false; m_Children[0] = m_Children[1] = m_Children[2] = m_Children[3] = null; m_NeedsRejoinCount = 0; m_HasChildren = false; m_NeedsReedge = true; m_NeedsTerrain = true; m_GapFixMask = 15; m_NormalMapTex = null; GenVolume(); m_Plane = new Plane(m_Volume.vertices[0], m_Volume.vertices[2], m_Volume.vertices[1]); }
public CPlanet Get(string id) { Planet planet = ST.GetPlanet(id); List <CFilm> cFilms = new List <CFilm>(); List <CResident> cResidents = new List <CResident>(); String name = planet.name; String population = planet.population; foreach (string filmURI in planet.films) { addFilm(cFilms, filmURI); } foreach (string resURI in planet.residents) { addRes(cResidents, resURI); } CPlanet cPlanet = new CPlanet(name, population, cFilms, cResidents); return(cPlanet); }
public void CreatePlanetsData() { CPlanet tmpPlanet; int randomType; float distance; float angle; float scale; Vector3 position; for (int i = 0; i < m_planetNumber; i++) { //randomType =(int)Mathf.Round(UnityEngine.Random.Range((float)E_PLANET_TYPE.E_BARREN, // (float)E_PLANET_TYPE.E_NB_PLANET_TYPE - 1.55f)); randomType = planetTypeComputing(); distance = (float)(cst.E_MINIMAL_PLANET_DISTANCE + (int)cst.E_DISTANCE_BETWEEN_PLANETS * i); angle = UnityEngine.Random.Range(0f, 2 * Mathf.PI); scale = 1f; position = new Vector3(distance * Mathf.Cos(angle), 0, distance * Mathf.Sin(angle)); tmpPlanet = new CPlanet(this, m_starName + "_" + i, (E_PLANET_TYPE)randomType, scale, position); m_planetList.Add(tmpPlanet); } }
public CPatchManager(CPatchConfig config, CPlanet planet) { for (byte i=0; i<16; i++) { GenGrid(i, config, planet); } }
public CPatchManager(CPatchConfig config, CPlanet planet) { for (byte i = 0; i < 16; i++) { GenGrid(i, config, planet); } }
public CLodSphere(bool outer, CPlanet planet) { CGlobal global = CGlobal.GetInstance(); m_Planet = planet; if (outer) { // outer atmosphere m_Material = (Material)Material.Instantiate(global.OuterAtmosphereMaterial); } else { // inner atmosphere m_Material = (Material)Material.Instantiate(global.InnerAtmosphereMaterial); } m_Material.SetFloat("_planetRadius", m_Planet.m_Radius); m_Material.SetFloat("_atmosRadius", m_Planet.AtmosRadius); m_Material.SetColor("_color1", m_Planet.m_AtmosColor1); m_Material.SetColor("_color2", m_Planet.m_AtmosColor2); m_Material.SetFloat("_sunIntensity", m_Planet.m_sunIntensity); m_Material.SetFloat("_horizonHeight", m_Planet.m_HorizonHeight); m_Material.SetFloat("_horizonIntensity", m_Planet.m_HorizonIntensity); m_Material.SetFloat("_horizonPower", m_Planet.m_HorizonPower); m_Material.SetFloat("_minAlpha", m_Planet.m_MinAtmosAlpha); m_Spheres = new GameObject[3]; // lod is 0:lowest, 1:mid, 2:highest detail for (int i = 0; i < 3; i++) { // save original parent transformations Vector3 parentPos = m_Planet.gameObject.transform.position; Quaternion parentQua = m_Planet.gameObject.transform.rotation; // reset parent transformations before assigning mesh data (so our vertices will be centered on the parent transform) m_Planet.gameObject.transform.position = Vector3.zero; m_Planet.gameObject.transform.rotation = Quaternion.identity; m_Spheres[i] = new GameObject("atmos lod " + i); m_Spheres[i].AddComponent <MeshFilter>(); m_Spheres[i].AddComponent <MeshRenderer>(); // ### outer atmosphere tesselation should be using AtmosSlices and AtmosStacks configs from CPatchConfig... m_Spheres[i].GetComponent <MeshFilter>().sharedMesh = global.MakeSphere((outer ? m_Planet.AtmosRadius : m_Planet.AtmosRadius * 1.25f), 15 * ((i + 1) * 4), 11 * ((i + 1) * 4)); m_Spheres[i].transform.parent = m_Planet.gameObject.transform; m_Spheres[i].renderer.sharedMaterial = m_Material; // restore parent transformations m_Planet.gameObject.transform.position = parentPos; m_Planet.gameObject.transform.rotation = parentQua; // inactivate this gameobject m_Spheres[i].hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable; } }
public CLodSphere(bool outer, CPlanet planet) { CGlobal global = CGlobal.GetInstance(); m_Planet = planet; if (outer) { // outer atmosphere m_Material = (Material)Material.Instantiate(global.OuterAtmosphereMaterial); } else { // inner atmosphere m_Material = (Material)Material.Instantiate(global.InnerAtmosphereMaterial); } m_Material.SetFloat("_planetRadius", m_Planet.m_Radius); m_Material.SetFloat("_atmosRadius", m_Planet.AtmosRadius); m_Material.SetColor("_color1", m_Planet.m_AtmosColor1); m_Material.SetColor("_color2", m_Planet.m_AtmosColor2); m_Material.SetFloat("_sunIntensity", m_Planet.m_sunIntensity); m_Material.SetFloat("_horizonHeight", m_Planet.m_HorizonHeight); m_Material.SetFloat("_horizonIntensity", m_Planet.m_HorizonIntensity); m_Material.SetFloat("_horizonPower", m_Planet.m_HorizonPower); m_Material.SetFloat("_minAlpha", m_Planet.m_MinAtmosAlpha); m_Spheres = new GameObject[3]; // lod is 0:lowest, 1:mid, 2:highest detail for (int i = 0; i < 3; i++) { // save original parent transformations Vector3 parentPos = m_Planet.gameObject.transform.position; Quaternion parentQua = m_Planet.gameObject.transform.rotation; // reset parent transformations before assigning mesh data (so our vertices will be centered on the parent transform) m_Planet.gameObject.transform.position = Vector3.zero; m_Planet.gameObject.transform.rotation = Quaternion.identity; m_Spheres[i] = new GameObject("atmos lod " + i); m_Spheres[i].AddComponent<MeshFilter>(); m_Spheres[i].AddComponent<MeshRenderer>(); // ### outer atmosphere tesselation should be using AtmosSlices and AtmosStacks configs from CPatchConfig... m_Spheres[i].GetComponent<MeshFilter>().sharedMesh = global.MakeSphere((outer ? m_Planet.AtmosRadius : m_Planet.AtmosRadius * 1.25f), 15 * ((i + 1) * 4), 11 * ((i + 1) * 4)); m_Spheres[i].transform.parent = m_Planet.gameObject.transform; m_Spheres[i].GetComponent<Renderer>().sharedMaterial = m_Material; // restore parent transformations m_Planet.gameObject.transform.position = parentPos; m_Planet.gameObject.transform.rotation = parentQua; // inactivate this gameobject m_Spheres[i].hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable; } }
void OnSceneGUI() { CPlanet p = (CPlanet)target; #if UNITY_EDITOR if (p.m_Wysiwyg) { p.LateUpdate(); } #endif }
public override void OnInspectorGUI() { CPlanet p = (CPlanet)target; DrawDefaultInspector(); if (GUI.changed) { if (!p.m_Wysiwyg) { p.Rebuild(); } } }
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); }
// 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); } }
// volume is already passed as 1/2 of the parent's volume public CQuadtree(CQuadtree parent, CBoundingVolume volume) { m_Parent = parent; m_Planet = parent.m_Planet; m_ShapeTex = parent.m_ShapeTex; m_SplitLevel = (ushort)(m_Parent.m_SplitLevel + 1); if (m_SplitLevel > m_Planet.HighestSplitLevel) m_Planet.HighestSplitLevel = m_SplitLevel; m_Size = m_Parent.m_Size / 2; // // make the new spherical projected volume // m_Volume = volume; Vector3 v1 = m_Volume.vertices[0]; Vector3 v2 = m_Volume.vertices[1]; Vector3 v3 = m_Volume.vertices[2]; Vector3 v4 = m_Volume.vertices[3]; Vector2 uv1 = m_Volume.uvs[0]; Vector2 uv2 = m_Volume.uvs[1]; Vector2 uv3 = m_Volume.uvs[2]; Vector2 uv4 = m_Volume.uvs[3]; m_SVolume = new CBoundingVolume(); m_SVolume.vertices.Add(CMath.ProjectToSphere(v1, m_Planet.m_Radius)); m_SVolume.vertices.Add(CMath.ProjectToSphere(v2, m_Planet.m_Radius)); m_SVolume.vertices.Add(CMath.ProjectToSphere(v3, m_Planet.m_Radius)); m_SVolume.vertices.Add(CMath.ProjectToSphere(v4, m_Planet.m_Radius)); m_SVolume.uvs.Add(uv1); m_SVolume.uvs.Add(uv2); m_SVolume.uvs.Add(uv3); m_SVolume.uvs.Add(uv4); // // extrapolate the flat volume vertices and uvs for normalmapping // float vertSpace = m_Size / (m_Planet.PatchConfig.PatchSize - 1); // vertex spacing Vector3 left = -m_Right; v1 += left * vertSpace + m_Up * vertSpace; v2 += m_Right * vertSpace + m_Up * vertSpace; v3 += m_Right * vertSpace - m_Up * vertSpace; v4 += left * vertSpace - m_Up * vertSpace; m_Volume.exvertices.Add(v1); m_Volume.exvertices.Add(v2); m_Volume.exvertices.Add(v3); m_Volume.exvertices.Add(v4); // -- m_Neighbors[0].node = m_Neighbors[1].node = m_Neighbors[2].node = m_Neighbors[3].node = null; m_Neighbors[0].isFixed = m_Neighbors[1].isFixed = m_Neighbors[2].isFixed = m_Neighbors[3].isFixed = false; m_Children[0] = m_Children[1] = m_Children[2] = m_Children[3] = null; m_NeedsRejoinCount = 0; m_HasChildren = false; m_NeedsReedge = true; m_NeedsTerrain = true; m_GapFixMask = 15; m_NormalMapTex = null; m_Normal = m_Parent.m_Normal; m_Up = m_Parent.m_Up; m_Center = (volume.vertices[0] + volume.vertices[1] + volume.vertices[2] + volume.vertices[3]) / 4; m_SCenter = m_Center; m_SCenter = CMath.ProjectToSphere(m_SCenter, m_Planet.m_Radius); m_SUp = m_SCenter; m_SUp.Normalize(); m_Front = m_Parent.m_Front; m_SFront = Vector3.Lerp(m_SVolume.vertices[0], m_SVolume.vertices[1], 0.5f) - m_SCenter; m_SFront.Normalize(); m_Plane = m_Parent.m_Plane; m_Right = m_Parent.m_Right; }
public CColony(CPlanet parent) { m_buildingList = new List <CBuilding>(); m_parentPlanet = parent; InitColonyResources(); }
private void GenGrid(byte edges, CPatchConfig config, CPlanet planet) { /* +++ +O+ +++ +O+ +++ +++ O+O O+O +++ +O+ +++ +O+ +O+ +++ +++ +++ +++ ++O +++ O++ +++ +++ +O+ +++ +O+ +++ +++ +O+ ++O ++O O++ O++ +++ +O+ +O+ +++ +O+ +O+ +++ +O+ O+O ++O O+O O++ +++ +O+ +O+ +O+ */ // number of triangles in one full-res line // discounting the two extremities triangles that aren't included on this edge ushort edgeFullTrianglesCount = (ushort)((config.PatchSize-1) * 2 - 2); // number of indices in one full-res edge ushort edgeFullIndexCount = (ushort)(edgeFullTrianglesCount * 3); // number of triangles in one half-res edge // discounting the two extremities triangles that aren't included on this edge ushort edgeHalfTriangleCount = (ushort)((edgeFullTrianglesCount/2) + (edgeFullTrianglesCount/4)); // number of indices in one half-res edge ushort edgeHalfIndexCount = (ushort)(edgeHalfTriangleCount * 3); // number of indices within the main part of the patch, // discounting the four edges that will sum up to this ushort mainIndexCount = (ushort)(((config.PatchSize - 3) * (config.PatchSize - 3)) * 6); // our total of indices // starts with the mainIndexCount, // and gets update with edges index counts ushort totalIndexCount = mainIndexCount; // add index count for each edge int i=1; while (i < 16) { if ((edges & i) > 0) { // half-res edge totalIndexCount += edgeHalfIndexCount; } else { // full-res edge totalIndexCount += edgeFullIndexCount; } i <<= 1; } // allocate indices (triangles) for the patch type int[] idxList = new int[totalIndexCount]; // // generate indices for the interior of the patch - at full-res // ushort idx = 0; for (ushort lin=1; lin<config.PatchSize-2; lin++) { ushort pos = (ushort)(lin * config.PatchSize); for (ushort col = 1; col < config.PatchSize - 2; col++) { ushort pp = (ushort)(pos + col); // x, x+1, x+config.PatchSize idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp+1; idxList[idx++] = pp; // x+config.PatchSize, x+1, x+1+config.PatchSize idxList[idx++] = pp + 1 + config.PatchSize; idxList[idx++] = pp+1; idxList[idx++] = pp + config.PatchSize; } } // // generate indices for the edges // // 0000 == all edges at full-res // 0001 (1) == top edge at half-res // 0010 (2) == right edge at half-res // 0100 (4) == bottom edge at half-res // 1000 (8) == left edge at half-res // // top edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Top)) > 0) { // top edge at half-resolution bool flag = false; ushort x = 0; ushort pp = 0; while (x < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize+1; idxList[idx++] = pp+2; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize-1; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp+config.PatchSize+1; } flag = !flag; } } else { // top edge at full-resolution bool flag = false; ushort x = 0; ushort pp = 0; while (x < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize+1; idxList[idx++] = pp+1; idxList[idx++] = pp+1; idxList[idx++] = pp+config.PatchSize+1; idxList[idx++] = pp+2; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize-1; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp+config.PatchSize+1; } flag = !flag; } } // // right edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Right)) > 0) { // right edge at half-resolution bool flag = false; ushort y = 0; ushort pp = (ushort)(config.PatchSize-1); while (y < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize-1; idxList[idx++] = pp+config.PatchSize*2; y += 2; pp += (ushort)(config.PatchSize*2); } else { idxList[idx++] = pp; idxList[idx++] = pp-config.PatchSize-1; idxList[idx++] = pp-1; idxList[idx++] = pp; idxList[idx++] = pp-1; idxList[idx++] = pp+config.PatchSize-1; } flag = !flag; } } else { // right edge at full-resolution bool flag = false; ushort y = 0; ushort pp = (ushort)(config.PatchSize-1); while (y < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize-1; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp+config.PatchSize-1; idxList[idx++] = pp+config.PatchSize*2; y += 2; pp += (ushort)(config.PatchSize*2); } else { idxList[idx++] = pp; idxList[idx++] = pp-config.PatchSize-1; idxList[idx++] = pp-1; idxList[idx++] = pp; idxList[idx++] = pp-1; idxList[idx++] = pp+config.PatchSize-1; } flag = !flag; } } // // bottom edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Bottom)) > 0) { // bottom edge at half-resolution bool flag = false; ushort x = 0; ushort pp = (ushort)((config.PatchSize-1) * config.PatchSize); while (x < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+2; idxList[idx++] = pp-config.PatchSize+1; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp-config.PatchSize; idxList[idx++] = pp-config.PatchSize-1; idxList[idx++] = pp; idxList[idx++] = pp-config.PatchSize+1; idxList[idx++] = pp-config.PatchSize; } flag = !flag; } } else { // bottom edge at full-resolution bool flag = false; ushort x = 0; ushort pp = (ushort)((config.PatchSize-1) * config.PatchSize); while (x < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+1; idxList[idx++] = pp-config.PatchSize+1; idxList[idx++] = pp+1; idxList[idx++] = pp+2; idxList[idx++] = pp-config.PatchSize+1; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp-config.PatchSize; idxList[idx++] = pp-config.PatchSize-1; idxList[idx++] = pp; idxList[idx++] = pp-config.PatchSize+1; idxList[idx++] = pp-config.PatchSize; } flag = !flag; } } // // left edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Left)) > 0) { // left edge at half-resolution bool flag = false; ushort y = 0; ushort pp = 0; while (y < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize*2; idxList[idx++] = pp+config.PatchSize+1; y += 2; pp += (ushort)(config.PatchSize*2); } else { idxList[idx++] = pp; idxList[idx++] = pp+1; idxList[idx++] = pp-config.PatchSize+1; idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize+1; idxList[idx++] = pp+1; } flag = !flag; } } else { // left edge at full-resolution bool flag = false; ushort y = 0; ushort pp = 0; while (y < config.PatchSize-2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp+config.PatchSize+1; idxList[idx++] = pp+config.PatchSize; idxList[idx++] = pp+config.PatchSize*2; idxList[idx++] = pp+config.PatchSize+1; y += 2; pp += (ushort)(config.PatchSize*2); } else { idxList[idx++] = pp; idxList[idx++] = pp+config.PatchSize+1; idxList[idx++] = pp+1; idxList[idx++] = pp; idxList[idx++] = pp+1; idxList[idx++] = pp-config.PatchSize+1; } flag = !flag; } } m_patches.Add(idxList); }
private void GenGrid(byte edges, CPatchConfig config, CPlanet planet) { /* +++ +O+ +++ +O+ +++ +++ O+O O+O +++ +O+ +++ +O+ +++ +O+ +++ +++ +++ +++ ++O +++ O++ +++ +++ +O+ +++ +++ +O+ +++ +++ +O+ ++O ++O O++ O++ +++ +O+ +O+ +++ +++ +O+ +O+ +++ +O+ +++ O+O ++O O+O O++ +++ +O+ +O+ +O+ */ // number of triangles in one full-res line // discounting the two extremities triangles that aren't included on this edge ushort edgeFullTrianglesCount = (ushort)((config.PatchSize - 1) * 2 - 2); // number of indices in one full-res edge ushort edgeFullIndexCount = (ushort)(edgeFullTrianglesCount * 3); // number of triangles in one half-res edge // discounting the two extremities triangles that aren't included on this edge ushort edgeHalfTriangleCount = (ushort)((edgeFullTrianglesCount / 2) + (edgeFullTrianglesCount / 4)); // number of indices in one half-res edge ushort edgeHalfIndexCount = (ushort)(edgeHalfTriangleCount * 3); // number of indices within the main part of the patch, // discounting the four edges that will sum up to this ushort mainIndexCount = (ushort)(((config.PatchSize - 3) * (config.PatchSize - 3)) * 6); // our total of indices // starts with the mainIndexCount, // and gets update with edges index counts ushort totalIndexCount = mainIndexCount; // add index count for each edge int i = 1; while (i < 16) { if ((edges & i) > 0) { // half-res edge totalIndexCount += edgeHalfIndexCount; } else { // full-res edge totalIndexCount += edgeFullIndexCount; } i <<= 1; } // allocate indices (triangles) for the patch type int[] idxList = new int[totalIndexCount]; // // generate indices for the interior of the patch - at full-res // ushort idx = 0; for (ushort lin = 1; lin < config.PatchSize - 2; lin++) { ushort pos = (ushort)(lin * config.PatchSize); for (ushort col = 1; col < config.PatchSize - 2; col++) { ushort pp = (ushort)(pos + col); // x, x+1, x+config.PatchSize idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp + 1; idxList[idx++] = pp; // x+config.PatchSize, x+1, x+1+config.PatchSize idxList[idx++] = pp + 1 + config.PatchSize; idxList[idx++] = pp + 1; idxList[idx++] = pp + config.PatchSize; } } // // generate indices for the edges // // 0000 == all edges at full-res // 0001 (1) == top edge at half-res // 0010 (2) == right edge at half-res // 0100 (4) == bottom edge at half-res // 1000 (8) == left edge at half-res // // top edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Top)) > 0) { // top edge at half-resolution bool flag = false; ushort x = 0; ushort pp = 0; while (x < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize + 1; idxList[idx++] = pp + 2; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize - 1; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp + config.PatchSize + 1; } flag = !flag; } } else { // top edge at full-resolution bool flag = false; ushort x = 0; ushort pp = 0; while (x < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize + 1; idxList[idx++] = pp + 1; idxList[idx++] = pp + 1; idxList[idx++] = pp + config.PatchSize + 1; idxList[idx++] = pp + 2; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize - 1; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp + config.PatchSize + 1; } flag = !flag; } } // // right edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Right)) > 0) { // right edge at half-resolution bool flag = false; ushort y = 0; ushort pp = (ushort)(config.PatchSize - 1); while (y < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize - 1; idxList[idx++] = pp + config.PatchSize * 2; y += 2; pp += (ushort)(config.PatchSize * 2); } else { idxList[idx++] = pp; idxList[idx++] = pp - config.PatchSize - 1; idxList[idx++] = pp - 1; idxList[idx++] = pp; idxList[idx++] = pp - 1; idxList[idx++] = pp + config.PatchSize - 1; } flag = !flag; } } else { // right edge at full-resolution bool flag = false; ushort y = 0; ushort pp = (ushort)(config.PatchSize - 1); while (y < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize - 1; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp + config.PatchSize - 1; idxList[idx++] = pp + config.PatchSize * 2; y += 2; pp += (ushort)(config.PatchSize * 2); } else { idxList[idx++] = pp; idxList[idx++] = pp - config.PatchSize - 1; idxList[idx++] = pp - 1; idxList[idx++] = pp; idxList[idx++] = pp - 1; idxList[idx++] = pp + config.PatchSize - 1; } flag = !flag; } } // // bottom edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Bottom)) > 0) { // bottom edge at half-resolution bool flag = false; ushort x = 0; ushort pp = (ushort)((config.PatchSize - 1) * config.PatchSize); while (x < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + 2; idxList[idx++] = pp - config.PatchSize + 1; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp - config.PatchSize; idxList[idx++] = pp - config.PatchSize - 1; idxList[idx++] = pp; idxList[idx++] = pp - config.PatchSize + 1; idxList[idx++] = pp - config.PatchSize; } flag = !flag; } } else { // bottom edge at full-resolution bool flag = false; ushort x = 0; ushort pp = (ushort)((config.PatchSize - 1) * config.PatchSize); while (x < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + 1; idxList[idx++] = pp - config.PatchSize + 1; idxList[idx++] = pp + 1; idxList[idx++] = pp + 2; idxList[idx++] = pp - config.PatchSize + 1; x += 2; pp += 2; } else { idxList[idx++] = pp; idxList[idx++] = pp - config.PatchSize; idxList[idx++] = pp - config.PatchSize - 1; idxList[idx++] = pp; idxList[idx++] = pp - config.PatchSize + 1; idxList[idx++] = pp - config.PatchSize; } flag = !flag; } } // // left edge // if ((edges & (1 << (int)en_NeighborDirection.NB_Left)) > 0) { // left edge at half-resolution bool flag = false; ushort y = 0; ushort pp = 0; while (y < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize * 2; idxList[idx++] = pp + config.PatchSize + 1; y += 2; pp += (ushort)(config.PatchSize * 2); } else { idxList[idx++] = pp; idxList[idx++] = pp + 1; idxList[idx++] = pp - config.PatchSize + 1; idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize + 1; idxList[idx++] = pp + 1; } flag = !flag; } } else { // left edge at full-resolution bool flag = false; ushort y = 0; ushort pp = 0; while (y < config.PatchSize - 2) { if (!flag) { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp + config.PatchSize + 1; idxList[idx++] = pp + config.PatchSize; idxList[idx++] = pp + config.PatchSize * 2; idxList[idx++] = pp + config.PatchSize + 1; y += 2; pp += (ushort)(config.PatchSize * 2); } else { idxList[idx++] = pp; idxList[idx++] = pp + config.PatchSize + 1; idxList[idx++] = pp + 1; idxList[idx++] = pp; idxList[idx++] = pp + 1; idxList[idx++] = pp - config.PatchSize + 1; } flag = !flag; } } m_patches.Add(idxList); }
// 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"); } } } } } } }
public void ShowColonyManager(CColony colony) { currentPlanet = colony.m_parentPlanet; UpdateColonyManagerImage(colony); }
public void CloseColonyManager() { currentPlanet = null; this.gameObject.SetActive(false); }