void StartTimer(float length, DeformMode next) { isWaiting = true; startTime = Time.time; waitTime = length; nextMode = next; }
void DoWait() { if (Time.time - startTime > waitTime) { isWaiting = false; deformMode = nextMode; } }
void DeformTerrain(DeformMode deformMode) { //Check of deformer currently collides with any of terrain if (_curTerrains.Count == 0) return; float paintBrushRadius = GetComponent<CircleCollider2D>().radius * transform.localScale.x; float minX = transform.position.x - paintBrushRadius; float maxX = transform.position.x + paintBrushRadius; foreach (var terrainEditor2D in _curTerrains) { //Get array of points of terrain path in local space Vector3[] path = terrainEditor2D.GetPath(Space.Self); for (int i = 0; i < path.Length; i++) { //Check if collider overpals with any of path points if (deformMode != DeformMode.Remove) { if (GetComponent<Collider2D>().OverlapPoint(path[i] + terrainEditor2D.transform.position)) { if (deformMode == DeformMode.Dig) { path[i] -= new Vector3(0, (DeformerHardness)); } else if (deformMode == DeformMode.Raise) { path[i] += new Vector3(0, (DeformerHardness)); } //Apply noise of needed if (DeformerNoise > 0f) path[i] += new Vector3(0, UnityEngine.Random.Range(-DeformerNoise * 0.25f, DeformerNoise * 0.25f)); } } else if (path[i].x >= minX && path[i].x <= maxX) { float distX = Mathf.Abs(GetMouseWorldPosition().x - path[i].x); float ratioX = distX / paintBrushRadius; float height = Mathf.Sin((ratioX * 0.5f + 0.5f) * Mathf.PI) * paintBrushRadius; float deltaDig = Mathf.Max((GetMouseWorldPosition().y + height) - path[i].y, 0.0f); float deltaRemove = height * 2.0f - deltaDig; path[i].y -= Mathf.Max(deltaRemove, 0.0f); //Apply noise of needed if (DeformerNoise > 0f) path[i] += new Vector3(0, UnityEngine.Random.Range(-DeformerNoise * 0.25f, DeformerNoise * 0.25f)); } } //Apply deformation terrainEditor2D.ApplyDeform(path, true); } }
void TerrainEditorWindow(int windowId) { //Detect when mouse cursor inside region (TerrainEditorWindow) GUILayout.BeginArea(new Rect(0, 0, 400, 240)); if (GUILayoutUtility.GetRect(10, 50, 400, 240).Contains(Event.current.mousePosition)) { onWindow = true; } else { onWindow = false; } GUILayout.EndArea(); GUILayout.BeginVertical(); //Shared GUI GUILayout.Space(10f); GUILayout.BeginHorizontal(); GUILayout.Label("Area:", new GUILayoutOption[] { GUILayout.Width(75f) }); area = GUILayout.HorizontalSlider(area, 1f, 13f, new GUILayoutOption[] { GUILayout.Width(250f), GUILayout.Height(15f) }); GUILayout.Label((Mathf.Round(area * 100f) / 100f).ToString(), new GUILayoutOption[] { GUILayout.Width(250f), GUILayout.Height(20f) }); //Change brush texture size if area value was changed if (GUI.changed) { brushScaling(); } GUILayout.EndHorizontal(); GUILayout.Space(10f); GUILayout.BeginHorizontal(); GUILayout.Label("Strength:", new GUILayoutOption[] { GUILayout.Width(75f) }); strength = GUILayout.HorizontalSlider(strength, 1f, 13f, new GUILayoutOption[] { GUILayout.Width(250f), GUILayout.Height(15f) }); GUILayout.Label((Mathf.Round(strength * 100f) / 100f).ToString(), new GUILayoutOption[] { GUILayout.Width(250f), GUILayout.Height(20f) }); GUILayout.EndHorizontal(); //Deform GUI GUILayout.Space(10); deformMode = (DeformMode)GUILayout.Toolbar((int)deformMode, deformModeNames, GUILayout.Height(25)); GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("Reset Terrain Height", new GUILayoutOption[] { GUILayout.Height(30f) })) { tData.SetHeights(0, 0, saved); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
// Use this for initialization void Start() { deformMode = DeformMode.Off; isOff = false; smallRadius = 2f; bigRadius = 4.5f; innerRadius = .5f; maxHeight = 15f; epsilon = .5f; middlePosition = new Vector3(5, 5, 0); currentRadius = smallRadius; isWaiting = false; circleSpeed = .003f; storedVector = new Vector3(0, 0, 0); risingDuration = 3f; fallingDuration = 6f; finalDuration = 5f; startingSmallCircleScale = 0f; intensityController = GameObject.Find("IntensityObj").GetComponent <IntensityController> (); sweepUpRadius = 5f; }
void DeformTerrain(DeformMode deformMode) { //Check of deformer currently collides with any of terrain if (_curTerrains.Count == 0) { return; } foreach (var terrainEditor2D in _curTerrains) { //Get array of points of terrain path in local space Vector3[] path = terrainEditor2D.GetPath(Space.Self); for (int i = 0; i < path.Length; i++) { //Check if collider overpals with any of path points if (GetComponent <Collider2D>().OverlapPoint(path[i] + terrainEditor2D.transform.position)) { if (deformMode == DeformMode.Dig) { path[i] -= new Vector3(0, (DeformerHardness)); } else { path[i] += new Vector3(0, (DeformerHardness)); } //Apply noise of needed if (DeformerNoise > 0f) { path[i] += new Vector3(0, UnityEngine.Random.Range(-DeformerNoise * 0.25f, DeformerNoise * 0.25f)); } } } //Apply deformation terrainEditor2D.ApplyDeform(path); } }
void StartTimerAndSetMode(float length, DeformMode next, DeformMode current) { deformMode = current; StartTimer(length, next); }
void StartFinalFalling() { deformMode = DeformMode.FinalFallingCircle; finalStartTime = Time.time; }
void StartFalling() { deformMode = DeformMode.FallingCircle; fallingStartTime = Time.time; }
void StartRising() { deformMode = DeformMode.RisingCircle; risingStartTime = Time.time; }
public void UpdateDeformMode(DeformMode newDeformMode) { deformMode = newDeformMode; }