private void OnValidate() { if (HeightInputType.Type == null) { HeightInput = null; } else if (HeightInput == null || HeightInput.GetType() != HeightInputType.Type) { HeightInput = Activator.CreateInstance(HeightInputType) as HeightInput; } if (DimensionsInputType.Type == null) { DimensionsInput = null; } else if (DimensionsInput == null || DimensionsInput.GetType() != DimensionsInputType.Type) { DimensionsInput = Activator.CreateInstance(DimensionsInputType) as DimensionsInput; } if (GrassMapInputType.Type == null) { GrassMapInput = null; } else if (GrassMapInput == null || GrassMapInput.GetType() != GrassMapInputType.Type) { GrassMapInput = Activator.CreateInstance(GrassMapInputType) as GrassMapInput; } if (NormalInputType.Type == null) { NormalInput = null; } else if (NormalInput == null || NormalInput.GetType() != NormalInputType.Type) { NormalInput = Activator.CreateInstance(NormalInputType) as NormalInput; } if (PositionInputType.Type == null) { PositionInput = null; } else if (PositionInput == null || PositionInput.GetType() != PositionInputType.Type) { PositionInput = Activator.CreateInstance(PositionInputType) as PositionInput; } if (PatchContainerType.Type == null) { PatchContainer = null; } else if (PatchContainer == null || PatchContainer.GetType() != PatchContainerType.Type) { PatchContainer = Activator.CreateInstance(PatchContainerType) as PatchContainer; } }
// Update is called once per frame private void Update() { ++_frames; float timeNow = Time.realtimeSinceStartup; if (Context.IsReady) { if (timeNow > _lastInterval + UpdateInterval) { _fps = (float)(_frames / (timeNow - _lastInterval)); _frames = 0; _lastInterval = timeNow; AverageFps.text = '\u00D8' + " FPS: " + _fps; Debug.Log('\u00D8' + " FPS: " + _fps); } Context.CollisionTextureRenderer.UpdateDepthTexture(); Context.WindManager.Update(); //Context.ProceduralWind.Update(); //Context.WindFieldRenderer.Update(); Context.PatchContainer.Draw(); //Context.BillboardTexturePatchContainer.Draw(); } for (int i = 0; i < _switchSimulationTexture.Length; i++) { if (Input.GetKeyDown(_switchSimulationTexture[i])) { _simulationTextureResolution = (int)Mathf.Pow(2, 3 + i); UpdateDebugInfo("Set SimulationTexture Resolution to " + _simulationTextureResolution); } } for (int i = 0; i < _testSettings.Length; i++) { if (Input.GetKeyDown(_testSettings[i])) { LoadTestSettings(i); } } if (Input.GetKeyDown(_printDebugInfo)) { UpdateDebugInfo(Context.PrintDebugInfo(), 30f); } if (Input.GetKeyDown(_toggleBlossoms)) { UpdateDebugInfo(Context.BladeContainer.Blades[0].HasBlossom ? "Deactivate Blossoms" : "Activate Blossoms"); Context.BladeContainer.Blades[0].HasBlossom = !Context.BladeContainer.Blades[0].HasBlossom; } if (Input.GetKeyDown(_forceBlossoms)) { if (!Context.BladeContainer.Blades[0].HasBlossom) { if (Context.BlossomCount == 0) { UpdateDebugInfo("Force Blossoms rendering."); Context.BlossomCount = 1; } else { UpdateDebugInfo("Deactivate force Blossoms rendering."); Context.BlossomCount = 0; } } else { UpdateDebugInfo("Cannot Force Blossoms because there are blossoms."); } } if (Input.GetKeyDown(_toggleDebugColors)) { _debugColors = !_debugColors; Shader.SetGlobalInt("RenderDebugColor", _debugColors ? 1 : 0); } if (Input.GetKeyDown(_toggleTerrain)) { FindObjectOfType <Terrain>().enabled = !FindObjectOfType <Terrain>().enabled; } if (Input.GetKeyDown(_switchCamera)) { if (!Context.Camera.GetComponent <Animator>().enabled) { _cameraBackupPos = Context.Camera.transform.position; _cameraBackupRot = Context.Camera.transform.rotation; } else { Context.Camera.transform.position = _cameraBackupPos; Context.Camera.transform.rotation = _cameraBackupRot; } Context.Camera.GetComponent <Animator>().enabled = !Context.Camera.GetComponent <Animator>().enabled; } if (Input.GetKeyDown(_switchGrassMapInput)) { if (Context.GrassMapInput.GetType() == typeof(RandomGrassMapInput)) { UpdateDebugInfo("Switch to Texture GrassMap Input"); Context.GrassMapInput = _textureGrassMapInput; Context.GrassMapInputType.Type = _textureGrassMapInputType; } else { UpdateDebugInfo("Switch to Uniform GrassMap Input"); _textureGrassMapInput = Context.GrassMapInput; _textureGrassMapInputType = Context.GrassMapInputType; Context.GrassMapInput = Activator.CreateInstance(typeof(RandomGrassMapInput)) as RandomGrassMapInput; Context.GrassMapInputType.Type = typeof(RandomGrassMapInput); } } }