public void Run() { if (isExecuting) { return; } if (tgs == null) { tgs = TerrainGridSystem.instance; if (tgs == null) { return; } } if (tgs.cells == null) { return; } if (Prepare()) { if (duration == 0) { Execute(); } else { StartCoroutine(ExecuteWithDuration()); } } }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.white; tgs.OnCellHighlight += (int cellIndex, ref bool cancelHighlight) => { cancelHighlight = true; tgs.CellFadeOut(cellIndex, Color.yellow, 2f); }; tgs.OnCellClick += (int cellIndex, int buttonIndex) => MergeCell(cellIndex); // Compute sprite scale //float tileSize = Vector3.Distance(tgs.CellGetVertexPosition(0, 0), tgs.CellGetVertexPosition(0, 3)); //float spriteSize = Vector3.Distance(sprite.bounds.max, sprite.bounds.min); //float scale = tileSize / spriteSize; //for (int k=0;k<100;k++) { // GameObject o = Instantiate<GameObject>(sprite.gameObject); // o.transform.position = tgs.CellGetPosition(Random.Range(0, tgs.cellCount)); // o.transform.localScale = new Vector3(scale, scale, 1f); //} for (int k = 0; k < tgs.cellCount; k++) { tgs.CellSetColor(k, Color.yellow); } }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.black; labelStyleShadow = new GUIStyle(labelStyle); labelStyleShadow.normal.textColor = Color.black; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleCenter; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.black; sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; StartCoroutine(MoveGrid()); }
/// <summary> /// Call this method to force a configuration load. /// </summary> public void LoadConfiguration() { if (config == null) { return; } TerrainGridSystem tgs = GetTGS(); if (tgs == null) { return; } tgs.textures = textures; int[] territories = null; if (!string.IsNullOrEmpty(filterTerritories)) { string[] ss = filterTerritories.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); List <int> tt = new List <int> (); for (int k = 0; k < ss.Length; k++) { int v = 0; if (int.TryParse(ss [k], out v)) { tt.Add(v); } } territories = tt.ToArray(); } tgs.CellSetConfigurationData(config, territories); }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.black; labelStyleShadow = new GUIStyle(labelStyle); labelStyleShadow.normal.textColor = Color.black; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleCenter; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.black; sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; ball = Resources.Load <GameObject>("Ball"); ballParent = new GameObject("BallParent"); ballParent.transform.position = tgs.terrainCenter + Vector3.up * 200.0f; ResetTerrain(); }
//Animations //sleep //wake up //eat //walk //Idle //Interact with animal //could add memory banks for other animals and fruit types // Use this for initialization void Start() { //grabs Sun ref sun = GameObject.FindGameObjectWithTag("Sun"); sunScript = sun.GetComponent <Sun>(); tgs = TerrainGridSystem.instance; state = State.MOVESELECT; bigStates = BigStates.PICKGOAL; //Assign Stats hungerModifier += Random.Range(0, .3f); //socialModifier += Random.Range(0, .3f); sleepModifier += Random.Range(0, .3f); nestObject = GameObject.FindGameObjectsWithTag("Nest"); // add naming convention of + ___ specie name //Zero Meters hunger = 0; social = 0; sleep = 0; _player = GameObject.FindGameObjectWithTag("Player"); //chanceToAwaken = 10; }
void Start() { // Load marker prefabs GameObject yellowSpherePrefab = Resources.Load <GameObject>("YellowSphere"); GameObject redSpherePrefab = Resources.Load <GameObject>("RedSphere"); // Get a reference to Terrain Grid System's API tgs = TerrainGridSystem.instance; // Iterate each cell and draws a sphere on the center of the cell as well as on the vertices for (int k = 0; k < tgs.cells.Count; k++) { // Add a yellow circle on the center of the cell Vector3 worldSpaceCenter = tgs.CellGetPosition(k); GameObject yellowSphere = Instantiate(yellowSpherePrefab); yellowSphere.transform.position = worldSpaceCenter + Vector3.up * 0.1f; // For each vertex of the cell, add a red circle int vertexCount = tgs.CellGetVertexCount(k); for (int p = 0; p < vertexCount; p++) { Vector3 worldSpacePosition = tgs.CellGetVertexPosition(k, p); GameObject redSphere = Instantiate(redSpherePrefab); redSphere.transform.position = worldSpacePosition + Vector3.up * 0.1f; // note: "up" is -z (grid is x,y) - displaced to avoid z-fighting } } }
void Start() { TerrainGridSystem tgs = TerrainGridSystem.instance; int rows = tgs.rowCount; int columns = tgs.columnCount; Texture2D tex = new Texture2D(columns, rows); tex.filterMode = FilterMode.Point; Color[] colors = new Color[columns * rows]; for (int k = 0; k < colors.Length; k++) { float c = Random.value * 0.5f + 0.5f; colors[k] = new Color(c, c, 1f); } tex.SetPixels(colors); tex.Apply(); // Create a quad GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad); quad.GetComponent <Renderer>().material.mainTexture = tex; // Adjust size to match grid also considering any cell scale Bounds bounds = tgs.bounds; quad.transform.position = bounds.center; quad.transform.localScale = new Vector3(bounds.size.x, bounds.size.y, 1f); }
void Start() { // Get a reference to TGS system's API tgs = TerrainGridSystem.instance; // Read texture colors Color32[] colors = textureForCells.GetPixels32(); // Iterate cells and picks the corresponding color in the texture int cellCount = tgs.cells.Count; for (int k = 0; k < cellCount; k++) { Vector2 cellCenter = tgs.cells [k].center; // Convert the center to texture coordinates // The center is in the range of -0.5..0.5, so we add 0.5 and multiply by the texture width in pixels to get the X texture coordinate int px = (int)((cellCenter.x + 0.5f) * textureForCells.width); // Same for Y int py = (int)((cellCenter.y + 0.5f) * textureForCells.height); // Now get the color Color32 color = colors [py * textureForCells.width + px]; // And assign it to the cell tgs.CellToggleRegionSurface(k, true, color); } }
void Start() { // Create a TGS instance from scratch // Step 1: instantiate TGS prefab and position it in world space GameObject tgsGO = Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/TerrainGridSystem")); tgsGO.transform.position = new Vector3(0, 0, 500); // Step 2: get a reference to the TGS main script (this is the API) tgs = tgsGO.GetComponent <TerrainGridSystem>(); // Step 3: customize TGS look & feel (check the documentation for the complete property list) tgs.gridTopology = GRID_TOPOLOGY.Hexagonal; tgs.rowCount = 48; tgs.columnCount = 64; tgs.cellBorderColor = Color.yellow; // color of cells tgs.GetComponent <MeshRenderer>().sharedMaterial.color = Color.black; // color of grid background tgs.showTerritories = true; // territories are optional tgs.numTerritories = 8; tgs.territoryDisputedFrontierColor = Color.red; tgs.highlightMode = HIGHLIGHT_MODE.Territories; // Step 4: configure some event trigger tgs.OnCellClick += OnCellClickHandler; }
void Start() { if (tgs == null) { tgs = TerrainGridSystem.instance; } selectionSquareImage.gameObject.SetActive(false); }
void Start() { // Get a reference to Terrain Grid System's API tgs = TerrainGridSystem.instance; currentRow = 0; currentCol = 0; StartCoroutine(HighlightCell()); }
// Use this for initialization void Start() { Debug.Log("Select the sphere in the hierarchy and watch script values."); Debug.Log("Or click the sphere gameobject to print them to console."); tgs = TerrainGridSystem.instance; location.x = tgs.columnCount / 2; location.y = tgs.rowCount / 2; }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI styles labelStyle = new GUIStyle (); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.black; }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.black; }
public void Clear() { TerrainGridSystem tgs = GetTGS(); if (tgs != null) { tgs.ClearAll(); } }
public void Init <T> (TerrainGridSystem tgs) where T : Component { this.tgs = tgs; hits = new RaycastHit[20]; if (GetComponent <T> () == null) { gameObject.AddComponent <T> (); } }
public void SetupTriggers(TerrainGridSystem tgs) { TerrainTrigger trigger = terrain.gameObject.GetComponent <TerrainTrigger> (); if (trigger == null) { trigger = terrain.gameObject.AddComponent <TerrainTrigger> (); } trigger.Init <TerrainCollider> (tgs); }
TerrainGridSystem GetTGS() { TerrainGridSystem tgs = GetComponent <TerrainGridSystem> (); if (tgs == null) { Debug.Log("Terrain Grid System not found in this game object!"); return(null); } return(tgs); }
void Start() { if (GetComponent<TerrainCollider> () == null) { gameObject.AddComponent<TerrainCollider> (); } ths = transform.GetComponentInChildren<TerrainGridSystem>(); if (ths==null) { Debug.LogError("Missing Terrain Highlight System reference in Terrain Trigger script."); DestroyImmediate (this); } }
// Use this for initialization void Start() { tgs = TerrainGridSystem.instance; Color blockedColor = new Color(0.2f, 0.2f, 0.2f, 1f); for (int k = 0; k < 1500; k++) { int cellIndex = Random.Range(0, tgs.cellCount); tgs.CellToggleRegionSurface(cellIndex, true, blockedColor); tgs.CellSetCanCross(cellIndex, false); } }
void Start() { if (GetComponent <TerrainCollider> () == null) { gameObject.AddComponent <TerrainCollider> (); } ths = transform.GetComponentInChildren <TerrainGridSystem>(); if (ths == null) { Debug.LogError("Missing Terrain Highlight System reference in Terrain Trigger script."); DestroyImmediate(this); } }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.black; character = GameObject.Find("Character").GetComponent <Rigidbody>(); }
void Start() { // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.black; // hide all cells tgs = TerrainGridSystem.instance; tgs.cells.ForEach((cell) => cell.visible = true); tgs.Redraw(); // listen to events tgs.OnCellClick += (cellIndex, buttonIndex) => toggleCellVisible(cellIndex); }
public void SetupTriggers(TerrainGridSystem tgs) { for (int k = 0; k < rr.Length; k++) { if (rr[k].renderer == null) { continue; } if (rr[k].renderer.GetComponent <TerrainTrigger>() == null) { TerrainTrigger trigger = rr[k].renderer.gameObject.AddComponent <TerrainTrigger>(); trigger.Init <MeshCollider>(tgs); } } }
public static void FadeOut(TerrainGridSystem tgs, GameObject surface, Region region, Color color, float duration) { SurfaceFader fader = surface.GetComponent <SurfaceFader>(); if (fader != null) { DestroyImmediate(fader); } fader = surface.AddComponent <SurfaceFader>(); fader.tgs = tgs; fader.startTime = Time.time; fader.duration = duration + 0.0001f; fader.color = color; fader.region = region; }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.white; tgs.OnCellHighlight += (int cellIndex, ref bool cancelHighlight) => { cancelHighlight = true; tgs.CellFadeOut(cellIndex, Color.yellow, 2f); }; tgs.OnCellClick += (int cellIndex, int buttonIndex) => MergeCell(cellIndex); }
TerrainGridSystem GetTGS() { TerrainGridSystem tgs = GetComponent <TerrainGridSystem> (); if (tgs == null) { tgs = TerrainGridSystem.instance; } if (tgs == null) { Debug.Log("Terrain Grid System not found!"); return(null); } return(tgs); }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.black; // Events // OnCellMouseDown occurs when user presses the mouse button on a cell tgs.OnCellMouseDown += OnCellMouseDown; // OnCellMouseUp occurs when user releases the mouse button on a cell even after a drag // OnCellClick occurs when user presses and releases the mouse button as in a normal click tgs.OnCellClick += OnCellClick; }
void Start() { // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.black; // Get a reference to Terrain Grid System's API tgs = TerrainGridSystem.instance; // listen to events tgs.OnCellClick += (cellIndex, buttonIndex) => textureCell(cellIndex); // assign a canvas texture tgs.canvasTexture = Resources.Load <Texture2D>("Textures/worldMap"); }
/// <summary> /// Call this method to force a configuration load. /// </summary> public void LoadConfiguration() { if (config == null) { return; } TerrainGridSystem tgs = GetComponent <TerrainGridSystem>(); if (tgs == null) { Debug.Log("Terrain Grid System not found in this game object!"); return; } tgs.textures = textures; tgs.CellSetConfigurationData(config); }
void Start() { // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.black; // Get a reference to Terrain Grid System's API tgs = TerrainGridSystem.instance; // Set colors for frontiers tgs.territoryDisputedFrontierColor = Color.yellow; tgs.TerritorySetFrontierColor(0, Color.red); tgs.TerritorySetFrontierColor(1, Color.blue); // listen to events tgs.OnCellClick += (cellIndex, buttonIndex) => changeCellOwner(cellIndex); }
void OnEnable() { _blackTexture = MakeTex (4, 4, new Color (0.18f, 0.18f, 0.18f)); _blackTexture.hideFlags = HideFlags.DontSave; _headerTexture = Resources.Load<Texture2D> ("EditorHeader"); blackStyle = new GUIStyle (); blackStyle.normal.background = _blackTexture; selectionModeOptions = new string[] { "None", "Territories", "Cells" }; overlayModeOptions = new string[] { "Overlay", "Ground" }; topologyOptions = new string[] { "Irregular", "Box", "Rectangular", "Hexagonal" }; // Load UI icons Texture2D[] icons = new Texture2D[5]; icons [(int)RESHAPE_MODE.NONE] = Resources.Load<Texture2D> ("IconLock"); icons [(int)RESHAPE_MODE.ADD] = Resources.Load<Texture2D> ("IconPen"); icons [(int)RESHAPE_MODE.MOVE] = Resources.Load<Texture2D> ("IconMove"); icons [(int)RESHAPE_MODE.ERASE] = Resources.Load<Texture2D> ("IconEraser"); icons [(int)RESHAPE_MODE.MERGE] = Resources.Load<Texture2D> ("IconMerge"); reshapeToolbarIcons = new GUIContent[5]; reshapeToolbarIcons [(int)RESHAPE_MODE.NONE] = new GUIContent ("", icons [(int)RESHAPE_MODE.NONE], ""); reshapeToolbarIcons [(int)RESHAPE_MODE.ADD] = new GUIContent ("Add", icons [(int)RESHAPE_MODE.ADD], "Add a new cell to the grid"); reshapeToolbarIcons [(int)RESHAPE_MODE.MOVE] = new GUIContent ("Move", icons [(int)RESHAPE_MODE.MOVE], "Move a border point"); reshapeToolbarIcons [(int)RESHAPE_MODE.ERASE] = new GUIContent ("Erase", icons [(int)RESHAPE_MODE.ERASE], "Remove a cell"); reshapeToolbarIcons [(int)RESHAPE_MODE.MERGE] = new GUIContent ("Merge", icons [(int)RESHAPE_MODE.MERGE], "Merge two cells"); reshapeExplanation = new string[5]; reshapeExplanation [(int)RESHAPE_MODE.ADD] = "CLICK on the grid to add a new cell "; reshapeExplanation [(int)RESHAPE_MODE.MOVE] = "DRAG a border point on the grid"; reshapeExplanation [(int)RESHAPE_MODE.ERASE] = "CLICK on any cell to delete it."; reshapeExplanation [(int)RESHAPE_MODE.MERGE] = "CLICK on two or more cells in sequence to merge them."; tgs = (TerrainGridSystem)target; if (tgs.territories == null) { tgs.Init (); } HideEditorMesh(); }
// Use this for initialization void Start() { tgs = TerrainGridSystem.instance; }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init (800, 500); // setup GUI styles labelStyle = new GUIStyle (); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.black; labelStyleShadow = new GUIStyle (labelStyle); labelStyleShadow.normal.textColor = Color.black; buttonStyle = new GUIStyle (labelStyle); buttonStyle.alignment = TextAnchor.MiddleCenter; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.black; sliderStyle = new GUIStyle (); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle (); sliderThumbStyle.normal.background = Resources.Load<Texture2D> ("thumb"); sliderThumbStyle.overflow = new RectOffset (0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; ball = Resources.Load<GameObject>("Ball"); ballParent = new GameObject("BallParent"); ballParent.transform.position = tgs.terrainCenter + Vector3.up * 200.0f; ResetTerrain(); }