public void Update(DwarfTime time) { if (ScreenSaver == null) { ScreenSaver = new Terrain2D(Game); } if (CurrentState != "" && States[CurrentState].IsInitialized) { States[CurrentState].Update(time); if (CurrentState != "" && States[CurrentState].Transitioning != GameState.TransitionMode.Running) { States[CurrentState].TransitionValue += (float)(TransitionSpeed * time.ElapsedRealTime.TotalSeconds); States[CurrentState].TransitionValue = Math.Min(States[CurrentState].TransitionValue, 1.001f); } } if (NextState != "" && States[NextState].IsInitialized) { //States[NextState].Update(time); if (States[NextState].Transitioning != GameState.TransitionMode.Running) { States[NextState].TransitionValue += (float)(TransitionSpeed * time.ElapsedRealTime.TotalSeconds); States[NextState].TransitionValue = Math.Min(States[NextState].TransitionValue, 1.001f); if (States[NextState].TransitionValue >= 1.0) { TransitionComplete(); } } } }
public override void OnInspectorGUI() { Terrain2D terrain = (Terrain2D)target; EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); if (EditorGUI.EndChangeCheck()) { // in case they added something or edited something terrain.UpdatePoints(); } }
void OnEnable() { terrain = target as Terrain2D; if (terrain != null) { terrain.Setup(); } editorSettings = serializedObject.FindProperty("EditorSettings"); editModeEnabled = editorSettings.FindPropertyRelative("editModeEnabled"); mode = editorSettings.FindPropertyRelative("mode"); markSize = editorSettings.FindPropertyRelative("markSize"); }
protected void OnEnable() { _terrain = target as Terrain2D; _meshRenderer = _terrain.GetComponent <MeshRenderer>(); _keyPointsProperty = serializedObject.FindProperty("_keyPoints"); _widthProperty = serializedObject.FindProperty("_width"); _heightProperty = serializedObject.FindProperty("_height"); _lineWidthProperty = serializedObject.FindProperty("_lineWidth"); _qualityProperty = serializedObject.FindProperty("_quality"); _groundUVOffsetProperty = serializedObject.FindProperty("_groundUVOffset"); _groundUVScaleProperty = serializedObject.FindProperty("_groundUVScale"); _colliderTypeProperty = serializedObject.FindProperty("_colliderType"); }
private void OnSceneGUI() { Terrain2D terrain = (Terrain2D)target; Vector3 pos = terrain.transform.position; EditorGUI.BeginChangeCheck(); for (int i = 0; i < terrain.points.Count; i++) { terrain.points[i] = Handles.PositionHandle(pos + (Vector3)terrain.points[i], Quaternion.identity) - pos; /*if (i > 0) * { * Debug.DrawLine(terrain.points[i] + pos, terrain.points[i - 1] + pos); * }*/ } if (EditorGUI.EndChangeCheck()) { terrain.UpdatePoints(); } }
public void Update(DwarfTime time) { #if DEBUG Microsoft.Xna.Framework.Input.KeyboardState k = Microsoft.Xna.Framework.Input.Keyboard.GetState(); if (k.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Home)) { try { GameState.Game.GraphicsDevice.Reset(); } catch (Exception exception) { } } #endif if (ScreenSaver == null) { ScreenSaver = new Terrain2D(Game); } if (NextState != null && NextState.IsInitialized) { if (CurrentState != null) { CurrentState.OnExit(); CurrentState.OnPopped(); } CurrentState = NextState; NextState = null; } if (CurrentState != null && CurrentState.IsInitialized) { CurrentState.Update(time); } }
public void Init(int terrainsCount, Terrain2DSettings settings, Transform followTarget) { if (terrainsCount < 2) { terrainsCount = 2; } _terrains2D = new Terrain2D [terrainsCount]; for (int i = 0; i < terrainsCount; i++) { GameObject terrain = new GameObject("Terrain"); terrain.transform.parent = transform; _terrain2DLenght = settings.meshOffset * (settings.meshResolution - 1) * 2f; terrain.transform.localPosition = Vector3.right * _terrain2DLenght * i; _terrains2D[i] = new Terrain2D(terrain, settings); } _currenTerrain = 0; _followTarget = followTarget; }
public void Update(DwarfTime time) { if (ScreenSaver == null) { ScreenSaver = new Terrain2D(Game); } if (NextState != null && NextState.IsInitialized) { if (CurrentState != null) { CurrentState.OnExit(); CurrentState.OnPopped(); } CurrentState = NextState; NextState = null; } if (CurrentState != null && CurrentState.IsInitialized) { CurrentState.Update(time); } }
void OnDisable() { terrain = null; }
public void Init() { _terrain2D = new Terrain2D(gameObject, _settings); }
public void Dig(Vector3 pos, int radius) { if (radius == 1) { pos.z = -10; RaycastHit hit; Physics.Raycast(pos, transform.forward, out hit, 1000, ly); if (hit.transform == null) { return; } //print(hit.transform.name); Vector2 pixelUV = hit.textureCoord; Terrain2D t = hit.transform.parent.parent.gameObject.GetComponent <Terrain2D>(); if (t != null) { Vector2 size = new Vector2(t.texture.width, t.texture.height); // print(pixelUV.x * size.x); t.texture.SetPixel((int)(pixelUV.x * size.x), (int)(pixelUV.y * size.y), Color.clear); float i = (int)(pixelUV.y * size.y) * t.texture.width + (int)(pixelUV.x * size.x); t.m_Colors[(int)i] = Color.clear; t.texture.Apply(); t.GenCollider(); // t.apc.RecalculatePolygon(); // t.apc2.RecalculatePolygon(); } } else { pos.z = -10; RaycastHit hit; Physics.Raycast(pos, transform.forward, out hit, 1000, ly); if (hit.transform == null) { return; } if (radius % 2 > 0) { Debug.Log("Radius not dividable"); return; } //print(hit.transform.name); Vector2 pixelUV = hit.textureCoord; Terrain2D t = hit.transform.parent.parent.gameObject.GetComponent <Terrain2D>(); if (t != null) { Vector2 size = new Vector2(t.texture.width, t.texture.height); // print(pixelUV.x * size.x); float w = t.texture.width; float h = t.texture.height; int l = t.texture.width * t.texture.height; // t.apc.RecalculatePolygon(); // t.apc2.RecalculatePolygon(); int r = radius / 2; for (int y = -r; y < r; y++) { for (int x = -r; x < r; x++) { int yC = ((int)(pixelUV.y * size.y) + y); int xC = ((int)(pixelUV.x * size.x) + x); if (yC >= 0 && xC >= 0 && xC <= w && yC <= h && (yC * w + xC) < l) { t.texture.SetPixel(xC, yC, Color.clear); float i = yC * w + xC; t.m_Colors[(int)i] = Color.clear; } } } t.texture.Apply(); t.GenCollider(); } } }
void SplitTerrain() { if (terrainParts.magnitude == 0) { string dividers = ""; for (int i = 1; i < texture.height; i++) { if ((texture.height % i) == 0) { dividers += i.ToString(); dividers += ","; } } print("Dividers " + dividers); } if ((texture.width % terrainParts.x + texture.height % terrainParts.y) > 0) { Debug.LogError("Resolution not dividable by " + terrainParts.ToString()); Debug.Break(); return; } terrains = new Terrain2D[(int)terrainParts.x, (int)terrainParts.y]; // List<Terrain2D> terrainz = new List<Terrain2D>(); for (int x = 0; x < terrainParts.x; x++) { for (int y = 0; y < terrainParts.y; y++) { GameObject go = Instantiate(terrainPrefab, Vector3.zero, Quaternion.identity) as GameObject; go.name = x.ToString() + " , " + y.ToString(); go.transform.parent = transform; go.transform.localPosition = new Vector3(x * texture.width / terrainParts.x / PixelsPerUnit, y * texture.height / terrainParts.y / PixelsPerUnit); go.transform.localScale = scale; Terrain2D t2d = go.GetComponent <Terrain2D>(); t2d.termain = this; Texture2D tex = new Texture2D((int)(texture.width / terrainParts.x), (int)(texture.height / terrainParts.y)); tex.filterMode = FilterMode.Point; Color[] c = texture.GetPixels((int)(x * texture.width / terrainParts.x), (int)(y * texture.height / terrainParts.y), (int)(texture.width / terrainParts.x), (int)(texture.height / terrainParts.y)); tex.SetPixels(c); tex.wrapMode = TextureWrapMode.Clamp; tex.Apply(); Sprite s = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), PixelsPerUnit); /* * BoxCollider2D b = go.AddComponent<BoxCollider2D>(); * Vector3 v = t2d.sprite.bounds.size; * b.size = v; */ terrains[x, y] = t2d; t2d.sprite.sprite = s; t2d.texture = tex; t2d.bc2d = go.AddComponent <BoxCollider2D>(); t2d.backCollider.localScale = new Vector3(t2d.bc2d.size.x, t2d.bc2d.size.y, 1); Destroy(t2d.bc2d); // terrainz.Add(t2d); } } //terrains = new Terrain2D[terrainz.Count]; // terrains = terrainz.ToArray(); }