void Start() { GameObject hexMapEditorGO = GameObject.Find("Hex Map Editor"); if (hexMapEditorGO != null) { _hexMapEditor = hexMapEditorGO.GetComponent <HexMapEditor>(); //_hexMapEditor.AddHandler(gameObject); } GameObject hexMapGeneratorGO = GameObject.Find("Hex Map Generator"); if (hexMapGeneratorGO != null) { _hexMapGenerator = hexMapGeneratorGO.GetComponent <HexMapGenerator>(); } GameObject prefabManagerGO = GameObject.Find("Prefab Manager"); if (prefabManagerGO != null) { _prefabManager = prefabManagerGO.GetComponent <PrefabManager>(); } //defaults RiverModeIgnore.Value = true; RoadModeIgnore.Value = true; WalledModeIgnore.Value = true; TexturesList.SelectItem(0); }
public IEnumerator chooseAndSetWaterTest() { SceneManager.LoadScene("Scene", LoadSceneMode.Single); yield return(new WaitForSeconds(1.0f)); GameObject[] go = SceneManager.GetActiveScene().GetRootGameObjects(); HexMapEditor editor = go[3].transform.Find("Hex Map Editor").GetComponent <HexMapEditor>(); HexGrid grid = go[1].gameObject.GetComponent <HexGrid>(); HexGridChunk[] chunks = grid.getHexGridChunks(); HexCell[] cells = chunks[0].getCells(); HexDirection direction = HexDirection.NE; HexCell cell = cells[4].GetNeighbor(direction).GetNeighbor(direction) .GetNeighbor(direction); int waterLevel = 1; editor.SetApplyWaterLevel(true); editor.SetWaterLevel(waterLevel); editor.HandleTestInput(cell); Assert.AreEqual(waterLevel, editor.activeWaterLevel); foreach (GameObject g in go) { GameObject.Destroy(g); } SceneManager.UnloadScene("Scene"); }
private void Start() { _gameManager = GameManager.currentManager; _hexEditor = _gameManager._hexMapEditor; _nutrientManager = NutrientManager.currentNutrientManager; _camera = Camera.main; }
//public Terrain terrain; private void Awake() { hexGrid = hexGrid.GetComponent <HexGrid>(); hexMapEditor = hexMapEditor.GetComponent <HexMapEditor>(); preSelectCell = new HexCell[2]; preSelectCell.SetValue(null, 0); preSelectCell.SetValue(null, 1); }
static void editorMap() { HexMapEditor win = (HexMapEditor)EditorWindow.GetWindow(typeof(HexMapEditor), false, "MapEditor", false); win.autoRepaintOnSceneChange = true; win.Show(true); SceneView.onSceneGUIDelegate += SceneGUI; }
private void Awake() { ISDEBUGSCENE = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.ToLower().Contains("debug"); if (ISDEBUGSCENE && !_initialized) { InitializeDebugWorld(); return; } world = this; FollowCamera = this.followCamera; WORLD_DATAPATH = Application.persistentDataPath + "/Worlds/"; if (!Directory.Exists(WORLD_DATAPATH)) { Directory.CreateDirectory(WORLD_DATAPATH); } worldType = WorldType.CLASSM; worldName = "AlphaWorld"; tribes = new Dictionary <HexCell, Tribe>(); civilizations = new List <Civilization>(); civilizations.Add(new Civilization(BASE_SPECIES.Gnat, "DaGnats", true, 5, 15)); HexMetrics.Initialize(worldType); hexGrid = HexGrid.generate(this); mapCam.grid = hexGrid; //masterTerrain = GetComponent<RAKTerrainMaster>(); if (editing) { editor = Instantiate(RAKUtilities.getWorldPrefab("HexMapEditor")).GetComponent <HexMapEditor>(); } for (int count = 0; count < NUMBEROFSTARTINGCIVS; count++) { Tribe tribe = new Tribe(1200, BASE_SPECIES.Gnat); HexCell cell = tribe.FindHome(this, true); //civilizations[0].AddTribe(tribe); addTribe(tribe, cell); } hexGrid.RefreshAllChunks(); mainMenu = new MenuController(creatureBrowserPrefab, worldBrowserPrefab, debugMenuPrefab); if (AutoLoadArea) { HexCell autoLoadCell = hexGrid.GetCell(new Vector3(0, 0, 0)); LoadArea(autoLoadCell); mainMenu.Initialize(RootMenu.CreatureBrowser); } else { mainMenu.Initialize(RootMenu.WorldBrowser); } _initialized = true; }
void UseItem() { if (Action.itemIndex == -1 || itemList.GetItem(Action.itemIndex) == null) { return; } //Debug.Log("使用 " + Action.itemIndex); int targetIndex; if (Input.GetMouseButtonUp(0)) { targetIndex = HexMapEditor.GetPointedIndex(); //Debug.Log("1" + targetIndex); int range = itemList.GetItem(Action.itemIndex).range; //Debug.Log("2"); if (hexGrid.GetRoleID(targetIndex) == -1) { if (range != 0) { //Debug.Log("3" + hexGrid.GetRoleID(targetIndex)); return; } } //Debug.Log("4"); Action.targetIndex = targetIndex; //Debug.Log("5"); int myIndex = hexGrid.GetCellIndex(transform.position); //Debug.Log("6"); if (!hexGrid.CheckInRange(myIndex, targetIndex, range)) { if (range != 0) { //Debug.Log("7"); return; } } //Debug.Log("8"); itemList.UseItem(id, hexGrid.GetRoleID(targetIndex), Action.itemIndex); //Debug.Log("9"); } }
private void BuildRiverOrRoad(HexMapEditor mapEditor, int numIterations, int minLength, int maxLength, bool isRoad) { for (int i = 0; i < numIterations; ++i) { int startX = Random.Range(0, mapEditor.HexGrid.NumCellsX); int startZ = Random.Range(0, mapEditor.HexGrid.NumCellsZ); int length = Random.Range(minLength, maxLength); HexCell currentCell = mapEditor.HexGrid.GetCell(new HexCoordinates(startX, startZ)); if (currentCell != null) { HexCell lastCell = null; for (int r = 2; r < length; ++r) { HexDirection dir = (HexDirection)0; HexCell neighbourCell = null; for (int j = 0; j < 5; ++j) { dir = (HexDirection)Random.Range(0, 6); //dir = HexDirection.E; neighbourCell = currentCell.GetNeighbour(dir); if (neighbourCell != null && neighbourCell != lastCell) { break; } } if (neighbourCell != null) { if (isRoad) { currentCell.AddRoad(dir); } else { currentCell.SetOutgoingRiver(dir); } lastCell = currentCell; currentCell = neighbourCell; } } } } }
void Move() { if (!EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonUp(0)) { int index = hexGrid.GetCellIndex(transform.position); //当前人物位置 int pointed = HexMapEditor.GetPointedIndex(); //当前光标位置 //检测是否在移动范围,是否有其他人,是否有充足能量 if (hexGrid.CheckInRange(index, pointed, 10) && hexGrid.GetRoleID(pointed) == -1 && UseEnergy(1)) { hexGrid.SetRoleID(index, -1); hexGrid.SetRoleID(pointed, id); AddEXP(1); transform.position = HexMapEditor.GetPointedVec(); } } }
public IEnumerator showGridUITest() { SceneManager.LoadScene("Scene", LoadSceneMode.Single); yield return(new WaitForSeconds(1.0f)); GameObject[] go = SceneManager.GetActiveScene().GetRootGameObjects(); HexMapEditor editor = go[3].transform.Find("Hex Map Editor").GetComponent <HexMapEditor>(); editor.ShowUI(true); CollectionAssert.DoesNotContain(editor.terrainMaterial.shaderKeywords, "GRID_ON"); foreach (GameObject g in go) { GameObject.Destroy(g); } SceneManager.UnloadScene("Scene"); }
public IEnumerator chooseRoadTest() { SceneManager.LoadScene("Scene", LoadSceneMode.Single); yield return(new WaitForSeconds(1.0f)); GameObject[] go = SceneManager.GetActiveScene().GetRootGameObjects(); HexMapEditor editor = go[3].transform.Find("Hex Map Editor").GetComponent <HexMapEditor>(); HexGrid grid = go[1].gameObject.GetComponent <HexGrid>(); HexGridChunk[] chunks = grid.getHexGridChunks(); HexCell[] cells = chunks[0].getCells(); HexDirection direction = HexDirection.NE; HexCell cell = cells[4].GetNeighbor(direction).GetNeighbor(direction) .GetNeighbor(direction); HexCell neighbor = cell.GetNeighbor(HexDirection.E); int elevationLevel = 1; editor.SetApplyElevation(true); editor.SetElevation(elevationLevel); editor.HandleTestInput(cell); editor.SetApplyElevation(false); editor.SetRoadMode((int)HexMapEditor.OptionalToggle.Yes); editor.HandleTestInput(neighbor); Assert.IsTrue(cell.HasRoadThroughEdge(HexDirection.E)); Assert.IsTrue(neighbor.HasRoadThroughEdge(HexDirection.W)); editor.SetRoadMode((int)HexMapEditor.OptionalToggle.No); editor.HandleTestInput(neighbor); Assert.IsFalse(cell.HasRoadThroughEdge(HexDirection.E)); Assert.IsFalse(neighbor.HasRoadThroughEdge(HexDirection.W)); foreach (GameObject g in go) { GameObject.Destroy(g); } SceneManager.UnloadScene("Scene"); }
// Update is called once per frame void Update() { //Debug.Log(hexGrid.PointedTag()); switch (hexGrid.GetRoleID(HexMapEditor.GetPointedIndex())) { case 0: ShowRoleInfo(0); break; case 1: ShowRoleInfo(1); break; case 2: ShowRoleInfo(2); break; case 3: ShowRoleInfo(3); break; default: break; } }
//bool isDrag; private void Awake() { hexGrid = GameObject.FindObjectOfType <HexGrid>(); hexMapEditor = GameObject.FindObjectOfType <HexMapEditor>(); }
// Use this for initialization void Start() { currentIndex = 0; this.character = GetComponent <Character> (); editor = GameInformation.currentHexGrid.GetComponentInChildren <HexMapEditor> (); }
private void Update() { HexMapEditor mapEditor = HexMapEditor; if (mapEditor != null && !m_haveBuilt) { for (int i = 0; i < TerrainIterations; ++i) { HexCell hexCell = mapEditor.HexGrid.GetRandomCell(); int brushSize = Random.Range(1, 4); int elevation = Random.Range(1, 3); int terrainType = Random.Range(0, 5); mapEditor.SetBrushSize(brushSize); mapEditor.SetElevation(elevation); mapEditor.SetTerrainType(terrainType); //mapEditor.SE(color); mapEditor.EditCells(hexCell); } if (Rivers) { BuildRiverOrRoad(mapEditor, NumRivers, 8, 15, false); } if (Roads) { BuildRiverOrRoad(mapEditor, NumRoads, 8, 15, true); } if (Water) { for (int i = 0; i < NumWater; ++i) { HexCell hexCell = mapEditor.HexGrid.GetRandomCell(); int brushSize = Random.Range(1, 4); int waterLevel = Random.Range(0, 2); mapEditor.SetBrushSize(brushSize); mapEditor.SetWaterLevel(waterLevel); mapEditor.SetApplyElevation(false); mapEditor.SetApplyWaterLevel(true); mapEditor.EditCells(hexCell); } } mapEditor.SetBrushSize(1); mapEditor.SetApplyElevation(false); mapEditor.SetApplyWaterLevel(false); mapEditor.SetRiverMode((int)OptionalToggle.Ignore); mapEditor.SetRoadMode((int)OptionalToggle.Ignore); for (int i = 0; i < UrbanFeatureIterations; ++i) { HexCell hexCell = mapEditor.HexGrid.GetRandomCell(); hexCell.UrbanDensityLevel = Random.Range(1, 4); hexCell.FarmDensityLevel = Random.Range(1, 4); hexCell.PlantDensityLevel = Random.Range(1, 4); } for (int i = 0; i < NumWalls; ++i) { HexCell hexCell = mapEditor.HexGrid.GetRandomCell(); hexCell.Walled = true; } for (int i = 0; i < NumSpecials; ++i) { HexCell hexCell = mapEditor.HexGrid.GetRandomCell(); hexCell.SpecialFeatureIndex = Random.Range(1, 4); } for (int i = 0; i < NumUnits; ++i) { HexCell hexCell = mapEditor.HexGrid.GetRandomCell(); mapEditor.CreateUnit(hexCell); } m_haveBuilt = true; } }
private void Awake() { hexGrid = hexGrid.GetComponent <HexGrid>(); hexMapEditor = hexMapEditor.GetComponent <HexMapEditor>(); }
private void Awake() { toggle = GetComponent <Toggle>(); hexMapEditor = GetComponentInParent <HexMapEditor>(); }
private void Awake() { Instance = this; mainCam = Camera.main; hexGrid = GameObject.Find("HexGrid").GetComponent <HexGrid>(); #region Get Init Component MyU.GetCom(out editModeToggle, "Toggle_EditMode", transform); MyU.GetGo(out leftEditorBg, "Editor_LeftBg", transform); MyU.BeginParent(leftEditorBg); MyU.GetCom(out ToggleGroup colorToggleGroup, "ToggleGroup_Color"); MyU.GetCom(out Toggle elevationToggle, "Toggle_Elevation"); MyU.GetCom(out Slider elevationSlider, "Slider_Elevation"); MyU.GetCom(out Toggle waterToggle, "Toggle_Water"); MyU.GetCom(out Slider waterSlider, "Slider_Water"); MyU.GetCom(out ToggleGroup riverToggleGroup, "ToggleGroup_River"); MyU.GetCom(out ToggleGroup roadToggleGroup, "ToggleGroup_Road"); MyU.GetCom(out Slider brushSlider, "Slider_BrustSize"); MyU.GetCom(out Toggle gridToggle, "Toggle_Grid"); MyU.GetGo(out rightEditorBg, "Editor_RightBg", transform); MyU.BeginParent(rightEditorBg); MyU.GetCom(out Toggle urbanToggle, "Toggle_Urban"); MyU.GetCom(out Slider urbanSlider, "Slider_Urban"); MyU.GetCom(out Toggle farmToggle, "Toggle_Farm"); MyU.GetCom(out Slider farmSlider, "Slider_Farm"); MyU.GetCom(out Toggle plantToggle, "Toggle_Plant"); MyU.GetCom(out Slider plantSlider, "Slider_Plant"); MyU.GetCom(out Toggle specialToggle, "Toggle_Special"); MyU.GetCom(out Slider specialSlider, "Slider_Special"); MyU.GetCom(out ToggleGroup walledToggleGroup, "ToggleGroup_Walled"); MyU.GetCom(out Transform fileBg, "Bg_File"); MyU.GetCom(out saveLoadUI, fileBg); MyU.GetCom(out newMapUI, fileBg); var colorToggles = colorToggleGroup.GetComponentsInChildren <Toggle>(); var riverToggles = riverToggleGroup.GetComponentsInChildren <Toggle>(); var roadToggles = roadToggleGroup.GetComponentsInChildren <Toggle>(); var walledToggles = walledToggleGroup.GetComponentsInChildren <Toggle>(); MyU.AddValChange(plantSlider, val => activePlantLevel = (int)val); MyU.AddValChange(editModeToggle, SetEditMode); MyU.AddValChange(elevationToggle, bo => applyElevation = bo); MyU.AddValChange(elevationSlider, val => activeElevation = (int)val); MyU.AddValChange(waterToggle, bo => applyWaterLevel = bo); MyU.AddValChange(waterSlider, val => activeWaterLevel = (int)val); MyU.AddValChange(brushSlider, val => brushSize = (int)val); MyU.AddValChange(gridToggle, ShowGrid); MyU.AddValChange(urbanToggle, bo => applyUrbanLevel = bo); MyU.AddValChange(urbanSlider, val => activeUrbanLevel = (int)val); MyU.AddValChange(farmToggle, bo => applyFarmLevel = bo); MyU.AddValChange(farmSlider, val => activeFarmLevel = (int)val); MyU.AddValChange(specialToggle, bo => applySpecialLevel = bo); MyU.AddValChange(specialSlider, val => activeSpecialLevel = (int)val); MyU.AddValChange(plantToggle, bo => applyPlantLevel = bo); InitToggles(colorToggles, SetColor); InitToggles(riverToggles, SetRiverMode); InitToggles(roadToggles, SetRoadMode); InitToggles(walledToggles, SetWalledMode); #endregion saveLoadUI.Init(hexGrid); newMapUI.Init(hexGrid); }
void Start() { mapEditor = GameInformation.currentHexGrid.GetComponentInChildren <HexMapEditor> (); buttonText = GetComponentInChildren <Text> (); }
private void Awake() { //saveButton = GetComponent<Button>(); //loadButton = GetComponent<Button>(); hexMapEditor = GetComponentInParent <HexMapEditor>(); }