214 lines
4.0 KiB
C#
214 lines
4.0 KiB
C#
using UnityEngine;
|
|
using uNature.Core.FoliageClasses;
|
|
using uNature.Core.Terrains;
|
|
|
|
namespace uNature.Demo
|
|
{
|
|
public class DemoControlManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private UNTerrain terrain;
|
|
|
|
[SerializeField]
|
|
private Camera renderingCamera;
|
|
|
|
[SerializeField]
|
|
private Rigidbody touchBendingBallRigid;
|
|
|
|
private bool _lodEnabled = true;
|
|
|
|
private bool _uNatureGrass = true;
|
|
|
|
private bool _windEnabled = true;
|
|
|
|
private bool _useInstancing = true;
|
|
|
|
private float _grassDensity = 1f;
|
|
|
|
private bool _castShadows;
|
|
|
|
private bool _colorMapsEnabled;
|
|
|
|
public bool lodEnabled
|
|
{
|
|
get
|
|
{
|
|
return _lodEnabled;
|
|
}
|
|
set
|
|
{
|
|
if (_lodEnabled != value)
|
|
{
|
|
_lodEnabled = value;
|
|
for (int i = 0; i < FoliageDB.unSortedPrototypes.Count; i++)
|
|
{
|
|
FoliageDB.unSortedPrototypes[i].useLODs = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool uNatureGrass
|
|
{
|
|
get
|
|
{
|
|
return _uNatureGrass;
|
|
}
|
|
set
|
|
{
|
|
if (_uNatureGrass != value)
|
|
{
|
|
_uNatureGrass = value;
|
|
if (value)
|
|
{
|
|
terrain.terrainData.ClearDetails();
|
|
FoliageCore_MainManager.instance.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
FoliageCore_MainManager.instance.enabled = false;
|
|
terrain.terrainData.ApplyBackup(terrain.terrain);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool windEnabled
|
|
{
|
|
get
|
|
{
|
|
return _windEnabled;
|
|
}
|
|
set
|
|
{
|
|
if (_windEnabled != value)
|
|
{
|
|
_windEnabled = value;
|
|
FoliageDB.instance.globalWindSettings.windSpeed = ((!value) ? 0f : 2f);
|
|
terrain.terrain.terrainData.wavingGrassSpeed = ((!value) ? 0f : 0.5f);
|
|
terrain.terrain.terrainData.wavingGrassStrength = ((!value) ? 0f : 0.5f);
|
|
terrain.terrain.terrainData.wavingGrassAmount = ((!value) ? 0f : 0.25f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool useInstancing
|
|
{
|
|
get
|
|
{
|
|
return _useInstancing;
|
|
}
|
|
set
|
|
{
|
|
if (_useInstancing != value)
|
|
{
|
|
_useInstancing = value;
|
|
for (int i = 0; i < FoliageDB.unSortedPrototypes.Count; i++)
|
|
{
|
|
FoliageDB.unSortedPrototypes[i].useInstancing = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public float grassDensity
|
|
{
|
|
get
|
|
{
|
|
return _grassDensity;
|
|
}
|
|
set
|
|
{
|
|
if (_grassDensity != value)
|
|
{
|
|
_grassDensity = value;
|
|
FoliageCore_MainManager.instance.density = value;
|
|
terrain.terrain.detailObjectDensity = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool castShadows
|
|
{
|
|
get
|
|
{
|
|
return _castShadows;
|
|
}
|
|
set
|
|
{
|
|
if (_castShadows != value)
|
|
{
|
|
_castShadows = value;
|
|
for (int i = 0; i < FoliageDB.unSortedPrototypes.Count; i++)
|
|
{
|
|
FoliageDB.unSortedPrototypes[i].castShadows = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool colorMapsEnabled
|
|
{
|
|
get
|
|
{
|
|
return _colorMapsEnabled;
|
|
}
|
|
set
|
|
{
|
|
if (_colorMapsEnabled != value)
|
|
{
|
|
_colorMapsEnabled = value;
|
|
for (int i = 0; i < FoliageDB.unSortedPrototypes.Count; i++)
|
|
{
|
|
FoliageDB.unSortedPrototypes[i].useColorMap = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.L))
|
|
{
|
|
lodEnabled = !lodEnabled;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.P))
|
|
{
|
|
uNatureGrass = !uNatureGrass;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.F2))
|
|
{
|
|
castShadows = !castShadows;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.F3))
|
|
{
|
|
colorMapsEnabled = !colorMapsEnabled;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.F4))
|
|
{
|
|
windEnabled = !windEnabled;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.F5))
|
|
{
|
|
useInstancing = !useInstancing;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.F6))
|
|
{
|
|
if (touchBendingBallRigid != null && renderingCamera != null)
|
|
{
|
|
touchBendingBallRigid.transform.position = renderingCamera.transform.position + renderingCamera.transform.forward * 1.5f;
|
|
touchBendingBallRigid.velocity = renderingCamera.transform.forward * 10f;
|
|
}
|
|
}
|
|
else if (Input.GetKey(KeyCode.Equals))
|
|
{
|
|
grassDensity = Mathf.Clamp(grassDensity + Time.deltaTime, 0f, 1f);
|
|
}
|
|
else if (Input.GetKey(KeyCode.Minus))
|
|
{
|
|
grassDensity = Mathf.Clamp(grassDensity - Time.deltaTime, 0f, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|