internal void AddToPool(StillElement stillElement) { stillElement.enabled = false; TerrainRamdonSpawner res = stillElement; res.transform.SetParent(transform); res.transform.position = new Vector3(); //_list.Add(res.gameObject); if (res.HType == H.Tree) { _tree.Add(res); } else if (res.HType == H.Grass) { _lawn.Add(res); } else if (res.HType == H.Stone) { _stone.Add(res); } else if (res.HType == H.Iron) { _iron.Add(res); } else if (res.HType == H.Gold) { _gold.Add(res); } else if (res.HType == H.Ornament) { _orna.Add(res); } }
public ExplorerUnit(Crystal crystal, Vector3 intersect, Vector3 currPosition, Vector3 final)//the curr Position of the Crystal reaching Final { Current = currPosition; Final = final; Key = crystal.ParentId; Intersections.Add(intersect); OrderIntersections(); Distance = Mathf.Abs(Vector3.Distance(intersect, currPosition)); Building = Brain.GetBuildingFromKey(Key); StillElement = Program.gameScene.controllerMain.TerraSpawnController.Find(crystal.ParentId); if (Building != null) { IsHasAValidObstacle = true; } else if (StillElement != null) { //Debug.Log("Hey hit random: " + StillElement.MyId); IsHasAValidObstacle = true; } else { //is set to that so if never was calculated its really far //since distance will be used for ordering Distance = 10000; } }
/// <summary> /// Returns a list of specific type element (trees, stones, iron) /// </summary> /// <param name="typePass">type of object expected (trees, stones, iron)</param> /// <returns>a list with the specific type of element passed (trees, stones, iron)</returns> private List <TerrainRamdonSpawner> ReturnListOfSpecificObj(H typePass) { StillElement still = null; List <TerrainRamdonSpawner> res = new List <TerrainRamdonSpawner>(); for (int i = 0; i < p.TerraSpawnController.AllRandomObjList.Count; i++) { still = (StillElement)p.TerraSpawnController.AllRandomObjList[i]; bool isSpawnObjOnSelRect = selectionDimRect.Contains( CamControl.CAMRTS.GetComponent <Camera>().WorldToScreenPoint( p.TerraSpawnController.AllRandomObjList[i].transform.position)); bool isRightType = CheckIfTypeOfObj(typePass, p.TerraSpawnController.AllRandomObjList[i]); if (isSpawnObjOnSelRect && isRightType) { res.Add(still); AddVisHelpList(true, still); } else if (isSpawnObjOnSelRect && typePass == H.RemoveSelection) { AddVisHelpList(false, still); } } return(res); }
public void Delete(StillElement still) { //search _crystalRegions points are var indexes = ReturnRegionsOfPointsInStructure(still); DeleteCrystals(indexes, still.MyId); }
public void Add(StillElement still) { //_info = "Still"; _siblings.Clear(); if (still.Anchors.Count > 4) { Debug.Log("acnhors:" + still.Anchors.Count + " " + still.MyId); } AddPoly(still.Anchors, still.MyId); }
/// <summary> /// Will return the region index where all the Structure points are /// </summary> /// <param name="building"></param> /// <returns></returns> private List <int> ReturnRegionsOfPointsInStillElement(StillElement still) { var points = PassAnchorsGetPositionForCrystals(still.Anchors); List <int> res = new List <int>(); for (int i = 0; i < points.Count; i++) { res.Add(ReturnMyRegion(U2D.FromV3ToV2(points[i]))); } return(res.Distinct().ToList()); }
public void ReSaveStillElement(StillElement ele) { var index = AllRandomObjList.IndexOf(ele); if (index == -1) { index = AllRandomObjList.ToList().FindIndex(a => a.MyId == ele.MyId); } AllRandomObjList[index].MaxHeight = ele.MaxHeight; AllSpawnedDataList[index].TreeHeight = ele.Height; AllSpawnedDataList[index].SeedDate = ele.SeedDate; AllSpawnedDataList[index].MaxHeight = ele.MaxHeight; AllSpawnedDataList[index].TreeFall = ele.TreeFall; AllSpawnedDataList[index].Weight = ele.Weight; }
public void RemoveStillElement(StillElement ele, Vector3 savedPos) { var index = AllRandomObjList.IndexOf(ele); AllRandomObjList.RemoveAt(index); //SpawnedData sData = new SpawnedData(ele.transform.position, ele.transform.rotation, ele.HType, // ele.RootToSpawnIndex, ele.IndexAllVertex); var sData = AllSpawnedDataList.Where(a => a.Pos == savedPos).FirstOrDefault(); //a not valid Spawner calling this if (sData == null) { return; } index = AllSpawnedDataList.IndexOf(sData); AllSpawnedDataList.RemoveAt(index); }
public List <Crystal> ReturnCrystalsThatBelongTo(StillElement still, bool includeDoor) { List <Crystal> res = new List <Crystal>(); //search _crystalRegions points are var indexes = ReturnRegionsOfPointsInStillElement(still); for (int i = 0; i < indexes.Count; i++) { var indexLoc = indexes[i]; res.AddRange(CrystalRegions[indexLoc].ObstaCrystals()); } var type = WhichType(includeDoor); if (res.Count > 0) { res = res.Where(a => a.ParentId == still.MyId && a.Type1 == type).ToList(); } return(res); }
/// <summary> /// Will return the region index where all the StillElement points are /// </summary> /// <param name="still"></param> /// <returns></returns> private List <int> ReturnRegionsOfPointsInStructure(StillElement still) { List <Vector3> points = new List <Vector3>(); var obstas = _allObstas.Where(a => a.ParentId == still.MyId).ToList(); for (int i = 0; i < obstas.Count; i++) { points.Add(U2D.FromV2ToV3(obstas[i].Position)); _allObstas.Remove(obstas[i]); } List <int> res = new List <int>(); for (int i = 0; i < points.Count; i++) { res.Add(ReturnMyRegion(U2D.FromV3ToV2(points[i]))); } return(res.Distinct().ToList()); }
private void Init() { FindSpawnersToMine(); OrderedSites = OrderSpawners(_spawnersList); //didnt find any tree. That means tht Trees prob have not been loaded yet if (OrderedSites.Count == 0 || _person.FoodSource == null) { _takeABreakNow = true; return; } _treeCenterPos = DefineMiddlePos(OrderedSites); FinRoutePoint = OrderedSites[0].Point; StillElementId = OrderedSites[0].LocMyId; _stillElement = Program.gameScene.controllerMain.TerraSpawnController.Find(StillElementId); //asking for grown in case is there but from an old list if (!_stillElement.Grown()) { StillElementId = ""; _spawnersList.Remove(_stillElement); _takeABreakNow = true; return; } HandleStillElement(); //moving the route point a bit towards the origin so when chopping tree its not inside the tree FinRoutePoint = Vector3.MoveTowards(_stillElement.transform.position, _person.Work.transform.position, 0.4f); //correcting y FinRoutePoint = new Vector3(FinRoutePoint.x, _person.transform.position.y, FinRoutePoint.z); //Debug.Log("routerBackWasInit set false"); routerBackWasInit = false; startIdleTime = 0; InitRoute(); }
//Creates the main type of objects and add them to AllRandomObjList, at the end if IsToSave is true will save it on //SaveOnListData public void CreateObjAndAddToMainList(H typePass, Vector3 pos, int rootToSpawnIndex, int index, Quaternion rot = new Quaternion(), bool replantedTree = false, float treeHeight = 0, MDate seedDate = null, float maxHeight = 0, bool treeFall = false, float weight = 0, string oldTreeID = "") { var region = MeshController.CrystalManager1.ReturnMyRegion(pos); string root = ReturnRoot(typePass, rootToSpawnIndex); TerrainRamdonSpawner temp = null; if (IsToSave) { temp = TerrainRamdonSpawner.CreateTerraSpawn(root, pos, new Vector3(0, rand.Next(0, 360), 0), index, typePass, typePass.ToString(), transform, replantedTree, treeHeight, seedDate, maxHeight); usedVertexPos[index] = true; //Debug.Log("Obj Spwned:"+temp.MyId); } else if (IsToLoadFromFile) { temp = _spawnPool.RetTerraSpawn(pos, new Vector3(), index, typePass, typePass.ToString(), transform, replantedTree, treeHeight, seedDate, maxHeight, rot); //pool emptied if (temp == null) { temp = TerrainRamdonSpawner.CreateTerraSpawn(root, pos, new Vector3(), index, typePass, typePass.ToString(), transform, replantedTree, treeHeight, seedDate, maxHeight, rot); } if (typePass == H.Tree) { var st = (StillElement)temp; st.Weight = weight; st.TreeFall = treeFall; } } temp.Region = region; //if is replant tree we want to place it first so when loading is faster if (replantedTree) { temp.MyId = oldTreeID; temp.name = oldTreeID; AllRandomObjList.Insert(0, temp); } else { if (typePass != H.Grass) { Program.gameScene.BatchAdd(temp); } AllRandomObjList.Add(temp); } if (IsToSave) { SaveOnListData(temp, typePass, rootToSpawnIndex, index, replantedTree, region); } else { var a = 1; } StillElement still = (StillElement)temp; if (still != null) { still.Start(); } }
internal void SendToPool(StillElement stillElement) { _spawnPool.AddToPool(stillElement); }