private Vector3 DetermineSpawnPosition(SectorObject lastSector) { Vector3 position = Vector3.right * gap; position += lastSector.rightBoundary.position; return(position); }
private void SpawnRandomSector(Vector3 position) { string randomKey = keys[Random.Range(0, keys.Count - 1)]; SectorObject sector = poolDictionary[randomKey].Pop(position); Add(sector); }
public void DisplayGalaxyData(GalaxyData d) { allSectors.Clear(); sectorObjectPool.ReleaseAll(); float xpos = 0; float ypos = 0; for (int x = 0; x < d.sectors.Length; x++) { ypos = 0; for (int y = 0; y < d.sectors[0].Length; y++) { GameObject g = sectorObjectPool.GetGameObject(); g.transform.position = new Vector3(xpos, ypos, 0); SectorObject so = g.GetComponent <SectorObject>(); allSectors.Add(so); so.baseColor = gradient.Evaluate((float)d.sectors[x][y].SystemCount / d.maxCount); if (d.sectors[x][y].SystemCount == 0) { so.SetTransparent(true); } else { so.SetTransparent(false); so.DisplayBaseColor(); } so.DisplaySector(d.sectors[x][y]); ypos += spacing; } xpos += spacing; } }
void ClearSectorLines(int sector) { Transform sectorTransform = sectors.GetChild(sector); SectorObject so = sectorObjects[sector]; for (int i = 0; i < so.lines.Length; i++) { ClearLine(so.lines[i]); } }
void SpaceShip_TargetReached(SectorObject sender, SystemEventArgs e) { if (State == "TARGET" || State == "BATTLE") { SpaceShip ship = this.SpaceShip.Target as SpaceShip; if (ship != null) { //GameManager.Instance.BattleManager.DoBattleCommand(this, ship, "F"); } } }
void Fill(SectorObjects type) { float x, z; System.Random random = new System.Random(); do { x = random.Next(-(width / 2), (width / 2)); z = random.Next(-(height / 2), (height / 2)); }while (SectorObject.Occupied(map, x, z) == true); map.Add(new SectorObject(type, x, z)); }
//public List<string> verbs; //public List<string> counterVerbs; //private Dictionary<string, string> language; private void Start() { //Initialize dictionaries and lists pools = GetComponents <SectorPool>(); foreach (SectorPool pool in pools) { poolDictionary.Add(pool.prefabKey, pool); keys.Add(pool.prefabKey); } //Initialize activeSectors SpawnRandomSector(startingPosition.transform.position); firstSector = lastSector; //Spawn first batch of sectors for (int i = 0; i < startingCount; i++) { SpawnRandomSector(DetermineSpawnPosition(lastSector)); } }
public void RebuildSector(int sectorIndex, int floorHeight, int ceilingHeight) { Sector sector = map.sectors[sectorIndex]; sector.floorHeight = floorHeight; sector.ceilingHeight = ceilingHeight; SectorObject so = sectorObjects[sectorIndex]; Transform sectorTransform = sectors.GetChild(sectorIndex); ClearSectorLines(sectorIndex); for (int i = 0; i < so.lines.Length; i++) { var quads = BuildLine(so.lines[i]); for (int j = 0; j < quads.Length; j++) { quads[j].transform.SetParent(lines.GetChild(so.lines[i]), false); } } }
public void Add(SectorObject sector) { activeSectors.Add(sector); lastSector = sector; }
private void SpawnSector(Vector3 position, string key) { SectorObject sector = poolDictionary[key].Pop(position); Add(sector); }
public void Remove(SectorObject sector) { activeSectors.Remove(sector); firstSector = activeSectors[0]; sector.ReturnToPool(); }
// public GameObject BuildCollisionMesh() // { // GameObject output = new GameObject("Collision"); // return output; // } public GameObject BuildMesh() { // SETUP flatMaterials = MapTextureBuilder.BuildFlatMaterials(wad, MapTextureBuilder.FindMapFlats(map)); wallMaterials = MapTextureBuilder.BuildTextureMaterials(wad, MapTextureBuilder.FindMapTextures(map)); DoomTexture texture = wad.textureTable.Get("SKY1"); skyMaterial = new Material(Shader.Find("Doom/DoomSky")); skyMaterial.SetTexture("_MainTex", DoomGraphic.BuildTexture("SKY1", wad)); skyMaterial.SetTexture("_Palette", MapTextureBuilder.paletteLookup); skyMaterial.SetTexture("_Colormap", MapTextureBuilder.colormapLookup); skyMaterial.enableInstancing = true; wallMaterials.Add("_SKY", MapTextureBuilder.BuildTextureMaterial(wad, "SKY1")); GameObject output = new GameObject("MAP"); lines = new GameObject("Lines").transform; sectors = new GameObject("Sectors").transform; triggers = new GameObject("Triggers").transform; lines.parent = output.transform; sectors.parent = output.transform; triggers.parent = output.transform; sectorObjects = new SectorObject[map.sectors.Length]; for (int i = 0; i < map.sectors.Length; i++) { GameObject gameObject = new GameObject($"Sector {i}"); gameObject.transform.parent = sectors; SectorObject sectorObject = gameObject.AddComponent <SectorObject>(); sectorObject.sector = i; sectorObject.lines = map.GetLinesOfSector(i); sectorObjects[i] = sectorObject; sectorObject.floor = new GameObject("Floor").transform; sectorObject.ceiling = new GameObject("Ceiling").transform; sectorObject.floor.parent = sectorObject.transform; sectorObject.ceiling.parent = sectorObject.transform; sectorObject.initialFloorPosition = map.sectors[i].floorHeight; sectorObject.initialCeilingPosition = map.sectors[i].ceilingHeight; sectorObject.meshGenerator = this; } // SECTORS for (int i = 0; i < nodeTri.subsectorHulls.Count; i++) { if (nodeTri.subsectorHulls[i].hull.Length > 2) { Sector sector = map.sectors[nodeTri.subsectorHulls[i].sector]; Transform sectorTransform = sectors.GetChild(nodeTri.subsectorHulls[i].sector); SubsectorFloorObject( MeshFromConvexHull(nodeTri.subsectorHulls[i].hull, sector.floorHeight, false), sector, sector.floorTexture == "F_SKY1"?skyMaterial:flatMaterials[sector.floorTexture] ).transform.SetParent(sectorObjects[nodeTri.subsectorHulls[i].sector].floor, false); SubsectorCeilingObject( MeshFromConvexHull(nodeTri.subsectorHulls[i].hull, sector.ceilingHeight, true), sector, sector.ceilingTexture == "F_SKY1"?skyMaterial:flatMaterials[sector.ceilingTexture] ).transform.SetParent(sectorObjects[nodeTri.subsectorHulls[i].sector].ceiling, false); } } // WALLS triggerList = new List <LinedefTrigger>(); for (int i = 0; i < map.linedefs.Length; i++) { var line = new GameObject($"Line {i}"); var quads = BuildLine(i); for (int j = 0; j < quads.Length; j++) { quads[j].transform.SetParent(line.transform, false); } line.transform.parent = lines; if (map.linedefs[i].special != 0) { var triggerObject = new GameObject($"Trigger {i}"); var trigger = triggerObject.AddComponent <LinedefTrigger>(); triggerObject.layer = LayerMask.NameToLayer("Trigger"); triggerObject.transform.parent = triggers; trigger.linedefIndex = i; trigger.sectorTag = map.linedefs[i].tag; trigger.specialType = map.linedefs[i].special; trigger.doomMesh = this; trigger.Init(); if (trigger.triggerType == TriggerType.Use || trigger.triggerType == TriggerType.Shoot) { Mesh mesh = BuildTriggerMesh(i); triggerObject.AddComponent <MeshFilter>().sharedMesh = mesh; var collider = triggerObject.AddComponent <MeshCollider>(); collider.sharedMesh = mesh; collider.convex = true; collider.isTrigger = true; } else { triggerList.Add(trigger); } } } return(output); }
private void CreateGeometryObj(string id, GEOMETRYTYPE type, Quaternion roration, Vector3 pos, Vector3 size, Material mat, int layer, out GeometryObject obj, List <object> param = null) { obj = null; if (string.IsNullOrEmpty(id)) { return; } if (!IsObjExist(id, out obj)) { switch (type) { case GEOMETRYTYPE.GEOMETRY_TYPE_CUBE: obj = new CubeObject(id, roration, pos, size, mat, layer); break; case GEOMETRYTYPE.GEOMETRY_TYPE_TAPER: obj = new TaperObject(id, roration, pos, size, mat, layer); break; case GEOMETRYTYPE.GEOMETRY_TYPE_AXIS: obj = new AxisObject(id, roration, pos, size, mat, layer); break; case GEOMETRYTYPE.GEOMETRY_TYPE_TEXT: obj = new TextObject(id, roration, pos, size, mat, layer); break; case GEOMETRYTYPE.GEOMETRY_TYPE_RING: obj = new RingObject(id, roration, pos, size, mat, layer); break; case GEOMETRYTYPE.GEOMETRY_TYPE_SECTOR: obj = new SectorObject(id, roration, pos, size, mat, layer, param); break; case GEOMETRYTYPE.GEOMETRY_TYPE_SPHERE: obj = new SphereObject(id, roration, pos, size, mat, layer); break; default: break; } if (obj != null) { obj.DrawCounter++; m_ObjectTbl.Add(obj); } } else { if (obj != null) { obj.Rotation = roration; obj.Position = pos; obj.Scale = size; obj.DefaultMat = mat; obj.Layer = layer; obj.DrawCounter++; } } }