Shuijing CreateCrystal(PATileTerrain.PATile tile, int level, PATileTerrain.TileElementType elementType) { PATileTerrain.PABuildingTile buildingTile = PATileTerrain.PABuildingTile.GetByTile(tileTerrain, tile); Shuijing shuijing = CreateCrystal(level, elementType); return(PlaceCrystal(shuijing, buildingTile)); }
void EditCrystal() { if (!CheckEditCrystal()) { return; } RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 pos; int x, y; if (Physics.Raycast(ray, out hit, Mathf.Infinity, editCrystalLayerMask)) { PATileTerrain tt = tileTerrain.IsTerrain(hit.transform); Shuijing hitShuijing = hit.transform.GetComponent <Shuijing>(); if (tt != null) { if (toPlaceBuilding == null) { SetSelectShuijing(null); Messenger <PATileTerrain.PATile> .Broadcast(UIEvent.UIEvent_ShowSelectCrystal, null); } else { pos = tileTerrain.transform.InverseTransformPoint(hit.point); x = (int)Mathf.Abs(pos.x / tileTerrain.tileSize); y = (int)Mathf.Abs(pos.z / tileTerrain.tileSize); PATileTerrain.PATile tile = tileTerrain.GetTile(x, y); PATileTerrain.PABuildingTile buildingTile = PATileTerrain.PABuildingTile.GetByTile(tileTerrain, tile); Shuijing shuijing = toPlaceBuilding as Shuijing; if (!CheckCrystalDistance(buildingTile.keyTile, shuijing)) { Messenger.Broadcast(UIEvent.UIEvent_CrystalDistanceTip); return; } PlaceCrystal(shuijing, buildingTile); shuijing.SetSelectTag(false); RepaintAllCrystals(); //PaintCrystal(shuijing); toPlaceBuilding = null; //SetSelectShuijing(shuijing); Messenger.Broadcast(TerrainManagerEvent_PlaceBuilding); } } else if (hitShuijing != null && toPlaceBuilding == null) { SetSelectShuijing(hitShuijing); MoveCameraToPos(hitShuijing.transform, MoveToCrystalCallBack); } else { SetSelectShuijing(null); } } }
public override TaskStatus OnUpdate() { GameObject terrainGo = GameObject.FindGameObjectWithTag("SurfaceTerrain"); PATileTerrain tileTerrain = terrainGo.GetComponent <PATileTerrain>(); Vector3 pos = tileTerrain.transform.InverseTransformPoint(storeHitPoint.Value); int x = (int)Mathf.Abs(pos.x / tileTerrain.tileSize); int y = (int)Mathf.Abs(pos.z / tileTerrain.tileSize); PATileTerrain.PATile tile = tileTerrain.GetTile(x, y); var currentGameObject = GetDefaultGameObject(targetGameObject.Value); if (currentGameObject != prevGameObject) { prevGameObject = currentGameObject; } animals = currentGameObject.GetComponent <Animals>(); if (animals == null) { return(TaskStatus.Failure); } if (animals.elementType == Animals.ElementType.Fire) { if (tile.element.IsFire()) { return(TaskStatus.Success); } else { return(TaskStatus.Failure); } } else if (animals.elementType == Animals.ElementType.Wood) { if (tile.element.IsWood()) { return(TaskStatus.Success); } else { return(TaskStatus.Failure); } } return(TaskStatus.Success); }
public void UpgradeSelectShuijing() { if (selectShuijing == null) { return; } PATileTerrain.PATile tile = selectShuijing.tile; int newLevel = selectShuijing.level + 1; PATileTerrain.TileElementType elementType = selectShuijing.elementType; RemoveCrystal(selectShuijing); Shuijing shuijing = CreateCrystal(tile, newLevel, elementType); //PaintCrystal(shuijing); RepaintAllCrystals(); SetSelectShuijing(null); }
bool CalTileElement(PATileTerrain.PATile tile, Vector2 crystalPos, float centerValue, float atten, PATileTerrain.TileElementType elementType) { //tile.Reset(); Vector2 tilePos = new Vector2(tile.x + 0.5f, tile.y + 0.5f); float distance = Vector2.Distance(crystalPos, tilePos); //if (tile.distance.Equals(-1)) // tile.distance = distance; //else // tile.distance = Mathf.Min(tile.distance, distance); float tileElementValue = Mathf.Max(centerValue - atten * distance, 0); if (tileElementValue > 0f) { tile.element.AddElement(elementType, tileElementValue); return(true); } return(false); }
void EditBuilding() { if (!CheckEditBuilding()) { return; } RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 pos; int x, y; if (Physics.Raycast(ray, out hit, Mathf.Infinity, editCrystalLayerMask)) { PATileTerrain tt = tileTerrain.IsTerrain(hit.transform); NestBuilding hitNest = hit.transform.GetComponent <NestBuilding>(); HatchBuilding hitHatch = hit.transform.GetComponent <HatchBuilding>(); if (tt != null) { pos = tileTerrain.transform.InverseTransformPoint(hit.point); x = (int)Mathf.Abs(pos.x / tileTerrain.tileSize); y = (int)Mathf.Abs(pos.z / tileTerrain.tileSize); PATileTerrain.PATile tile = tileTerrain.GetTile(x, y); PATileTerrain.PABuildingTile buildingTile = PATileTerrain.PABuildingTile.GetByTile(tileTerrain, tile); if (toPlaceBuilding is NestBuilding && buildingTile.keyTile.affectShuijing != null) { NestBuilding nest = toPlaceBuilding as NestBuilding; PlaceNest(nest, buildingTile); toPlaceBuilding = null; //Messenger.Broadcast(TerrainManagerEvent_PlaceBuilding); } } else if (hitNest != null && toPlaceBuilding == null) { Messenger.Broadcast(UIEvent.UIEvent_ShowSelectNest); } else if (hitHatch != null && toPlaceBuilding == null) { Messenger <int> .Broadcast(UIEvent.UIEvent_ShowHatch, hitHatch.hatchId); } } }
public bool CheckElementType(PATileTerrain.PATile checkTile) { if (checkTile == null) { return(false); } if (elementType == ElementType.Sand && checkTile.element.IsMultiElement()) { return(true); } else if (elementType == ElementType.Fire && checkTile.element.IsFire()) { return(true); } else if (elementType == ElementType.Wood && checkTile.element.IsWood()) { return(true); } return(false); }
bool CheckCrystalDistance(PATileTerrain.PATile newTile, Shuijing shuijing) { float minDistance = GetMinDistanceOfCrystal(); foreach (var crystal in tileTerrain.settings.crystals) { if (crystal.shuijing.elementType == shuijing.elementType) { continue; } PATileTerrain.PATile tile = tileTerrain.GetTile(crystal.id); float distance = tile.Distance(newTile); if (distance < minDistance) { return(false); } } return(true); }
public PATile GetTileByRay(Vector3 origin, Vector3 direction) { RaycastHit hit; Ray ray = new Ray(origin, direction); Physics.Raycast(ray, out hit, Mathf.Infinity, TerrainManager.instance.terrainChunkLayermask); //PATileTerrain tt = IsTerrain(hit.transform); //if (tt == null) // return null; if (hit.transform == null) { return(null); } Vector3 pos = transform.InverseTransformPoint(hit.point); int x = (int)Mathf.Abs(pos.x / tileSize); int y = (int)Mathf.Abs(pos.z / tileSize); PATileTerrain.PATile tile = GetTile(x, y); return(tile); }
PATileTerrain.PATile GetTileByPoint(PATileTerrain tileTerrain, Transform vPointTrans) { RaycastHit hit; Ray ray = new Ray(new Vector3(vPointTrans.position.x, vPointTrans.position.y + 100, vPointTrans.position.z), Vector3.down); Physics.Raycast(ray, out hit, Mathf.Infinity, TerrainManager.instance.terrainChunkLayermask); //PATileTerrain tt = tileTerrain.IsTerrain(hit.transform); //if (tt == null) // return null; if (hit.transform == null) { return(null); } Vector3 pos = tileTerrain.transform.InverseTransformPoint(hit.point); int x = (int)Mathf.Abs(pos.x / tileTerrain.tileSize); int y = (int)Mathf.Abs(pos.z / tileTerrain.tileSize); PATileTerrain.PATile tile = tileTerrain.GetTile(x, y); return(tile); }
public void CheckShow(PATileTerrain tileTerrain) { Vector3 boundLBPos = boxBoundLB.position; Vector3 boundLTPos = new Vector3(boxBoundLB.position.x, boxBoundLB.position.y, boxBoundRT.position.z); Vector3 boundRTPos = boxBoundRT.position; Vector3 boundRBPos = new Vector3(boxBoundRT.position.x, boxBoundLB.position.y, boxBoundLB.position.z); PATileTerrain.PATile hitTileLB = tileTerrain.GetTileByRay(boundLBPos, Vector3.down); PATileTerrain.PATile hitTileLT = tileTerrain.GetTileByRay(boundLTPos, Vector3.down); PATileTerrain.PATile hitTileRT = tileTerrain.GetTileByRay(boundRTPos, Vector3.down); PATileTerrain.PATile hitTileRB = tileTerrain.GetTileByRay(boundRBPos, Vector3.down); if (PATileTerrain.PATile.IsNotBaseElement(hitTileLB) || PATileTerrain.PATile.IsNotBaseElement(hitTileLT) || PATileTerrain.PATile.IsNotBaseElement(hitTileRT) || PATileTerrain.PATile.IsNotBaseElement(hitTileRB)) { Hide(); } else { Show(); } }
public void Reset() { building = null; closeTile = null; }
public void GenerateEggs() { int generateMaxCount = GetTerrainCommon(TerrainCommonKey.GenerateEggsCountPerDay); //int generateCount = 0; List <PATileTerrain.PATile> allTiles = new List <PATileTerrain.PATile>(); foreach (var crystal in tileTerrain.settings.crystals) { foreach (var tile in crystal.shuijing.affectTiles.Values) { allTiles.Add(tile); } } int tilesCount = allTiles.Count; if (tilesCount == 0) { return; } //Debug.Log("tilesCount " + tilesCount); int beginIndex = RandomManager.instance.Range(0, tilesCount); int step = RandomManager.instance.Range(0, tilesCount); //Debug.Log("step " + step); int index = beginIndex; for (int i = 0; i < generateMaxCount; i++) { index = index % tilesCount; //Debug.Log("index " + index); PATileTerrain.PATile tile = allTiles[index]; int eggConfigId = -1; if (tile.IsFireTile()) { eggConfigId = FireEggConfigId; } else if (tile.IsWoodTile()) { eggConfigId = WoodEggConfigId; } else { eggConfigId = UniversalEggConfigId; } EggData newEggData = new EggData(eggConfigId); GameObject newEggGo = PoolManager.Pools["Shuijing"].Spawn(newEggData.ConfigData.prefab).gameObject; Egg newEgg = newEggGo.GetComponent <Egg>(); newEgg.eggData = newEggData; PATileTerrainChunk chunk = tileTerrain.GetChunk(tile.chunkId); newEggGo.transform.SetParent(chunk.settings.buildingsRoot.transform); newEggGo.transform.position = tile.WorldPos(tileTerrain.transform); if (tile.affectShuijing != null) { tile.affectShuijing.eggs.Add(newEgg); } index += step; } }
void OnShow(PATileTerrain.PATile tile) { //this.selectTile = tile; Show(); }
public void OnSceneGUI() { if (tileTerrain == null || !tileTerrain.isCreated) return; RaycastHit hit; Ray ray; Rect winRect; int controlID = GUIUtility.GetControlID(FocusType.Passive); Event current = Event.current; EditorWindow currentWindow = EditorWindow.mouseOverWindow; if (currentWindow) { winRect = currentWindow.position; if (menuToolbar == MENU_HEIGHTS) { ray = HandleUtility.GUIPointToWorldRay(current.mousePosition); if(Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (previewProjector != null) previewProjector.transform.position = hit.point; } } else if (menuToolbar == MENU_PAINT || menuToolbar == MENU_TILE) { PATileTerrain.PATile tile = selectedTile; if (tile == null) tile = GetTile(); if (tile != null && previewProjector != null) { /*1.04*/ //previewProjector.transform.position = tileTerrain.transform.position + tile.position; previewProjector.transform.position = tileTerrain.transform.TransformPoint(tile.position); previewProjector.transform.rotation = tileTerrain.transform.localRotation; previewProjector.transform.Rotate(90.0f, 0.0f, 0.0f); } } switch (current.type) { case EventType.MouseDown: if (current.button == 0) { startAction = true; if (menuToolbar == MENU_HEIGHTS) { SetHeights((current.shift == true)); } else if (menuToolbar == MENU_PAINT) { Paint(); } } else startAction = false; break; case EventType.MouseDrag: if (startAction && menuToolbar == MENU_HEIGHTS) { SetHeights((current.shift == true)); } else if (startAction && menuToolbar == MENU_PAINT) { Paint(); } HandleUtility.Repaint(); mousePos.x = current.mousePosition.x - winRect.x; mousePos.y = winRect.height - current.mousePosition.y; break; case EventType.MouseUp: startAction = false; if (menuToolbar == MENU_TILE && current.button == 0) { selectedTile = GetTile(); Repaint(); } else if (menuToolbar == MENU_HEIGHTS && current.button == 0) { FinishSetHeights(); } else if (menuToolbar == MENU_PAINT && current.button == 0) { FinishPaint(); } break; case EventType.mouseMove: HandleUtility.Repaint(); break; case EventType.repaint: mousePos.x = current.mousePosition.x - winRect.x; mousePos.y = winRect.height - current.mousePosition.y; break; case EventType.layout: HandleUtility.AddDefaultControl(controlID); break; } } }
public void OnDisable() { menuToolbar = 0; selectedTile = null; tileTerrain = null; }
public void Reset() { startAction = false; selectedTile = null; if (previewProjector != null) previewProjector.enabled = (menuToolbar == MENU_HEIGHTS || menuToolbar == MENU_PAINT || menuToolbar == MENU_TILE); UpdatePreview(); }