protected void Start() { texture.Initialize(); float feedKillRadius = .005f; float abRatesRadius = .00001f; if (randomizer == null) { randomizer = ScriptableObject.CreateInstance <RDPresetRandomizer> (); //randomizer.InitAroundBase ( Parameters, regionRadius ); randomizer.InitAroundBase(Parameters, new PV[] { new PV("convCell", 0f), new PV("convAdj", 0f), new PV("convDiag", 0f), new PV("feedRate", feedKillRadius), new PV("killRate", feedKillRadius), new PV("aRate", abRatesRadius), new PV("bRate", abRatesRadius), new PV("deltaTime", 0f) }); } feedKillData = new DynamicData(string.Format("regionRadius={0},regionRadiusBackup={0}!", feedKillRadius)); ABRatesData = new DynamicData(string.Format("regionRadius={0},regionRadiusBackup={0}!", feedKillRadius)); m_RegionBackup = Parameters.Copy(); }
public void InitAroundBase(RDPreset preset, float radius) { Type targetType = typeof(RDPreset); Type ownType = typeof(RDPresetRandomizer); foreach (string property in propertyNames) { System.Reflection.FieldInfo targetField = targetType.GetField(property); System.Reflection.FieldInfo ownField = ownType.GetField(property); float baseValue = ( float )targetField.GetValue(preset); RG range = new RG(baseValue, baseValue - radius, baseValue + radius); ownField.SetValue(this, range); } }
public void Randomize() { if (m_PresetUnique == false) { Parameters = Instantiate <RDPreset> (_parameters); } if (randomizer == null) { randomizer = ScriptableObject.CreateInstance <RDPresetRandomizer> (); } randomizer.Apply(_parameters); texture.Initialize(); needsUpdate = true; }
public void Apply(RDPreset preset) { Type targetType = typeof(RDPreset); Type ownType = typeof(RDPresetRandomizer); foreach (string property in propertyNames) { System.Reflection.FieldInfo targetField = targetType.GetField(property); System.Reflection.FieldInfo ownField = ownType.GetField(property); RG range = ( RG )ownField.GetValue(this); // Randomize range.Fuzzy(); targetField.SetValue(preset, range.value); } }
public void InitAroundBase(RDPreset preset, PropValueKey[] pairs) { Type targetType = typeof(RDPreset); Type ownType = typeof(RDPresetRandomizer); foreach (PropValueKey pair in pairs) { string property = pair.prop; float radius = ( float )pair.value; System.Reflection.FieldInfo targetField = targetType.GetField(property); System.Reflection.FieldInfo ownField = ownType.GetField(property); float baseValue = ( float )targetField.GetValue(preset); RG range = new RG(baseValue, baseValue - radius, baseValue + radius); ownField.SetValue(this, range); } }
public RDPreset Copy(RDPreset target = null) { if (target == null) { target = ScriptableObject.CreateInstance <RDPreset> (); } target.convCell = convCell; target.convAdj = convAdj; target.convDiag = convDiag; target.aRate = aRate; target.bRate = bRate; target.feedRate = feedRate; target.killRate = killRate; target.deltaTime = deltaTime; return(target); }
protected void Update() { if (resetRegion) { m_RegionBackup.Copy(_parameters); feedKillData.Set("regionRadius", feedKillData.Get("regionRadiusBackup").value); ABRatesData.Set("regionRadius", ABRatesData.Get("regionRadiusBackup").value); resetRegion = false; updateRegion = true; } if (updateRegion) { if (m_PresetUnique == false) { Parameters = Instantiate <RDPreset> (_parameters); } float feedKillRadius = feedKillData.Get("regionRadius").value; feedKillData.Set("regionRadiusBackup", feedKillRadius); float ABRatesRadius = ABRatesData.Get("regionRadius").value; ABRatesData.Set("regionRadiusBackup", ABRatesRadius); randomizer.InitAroundBase(Parameters, new PV[] { new PV("feedRate", feedKillRadius), new PV("killRate", feedKillRadius), new PV("aRate", ABRatesRadius), new PV("bRate", ABRatesRadius) }); updateRegion = false; Vector2 feedKillUV = new Vector2(randomizer.Unlerp("feedRate", _parameters.feedRate), randomizer.Unlerp("killRate", _parameters.killRate)); UVParameters(feedKillUV, 4); Vector2 ABUV = new Vector2(randomizer.Unlerp("aRate", _parameters.aRate), randomizer.Unlerp("bRate", _parameters.bRate)); UVParameters(ABUV, 2); Parameters.Copy(m_RegionBackup); } if (feedKillValue == null) { feedKillValue = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform; feedKillValue.name = "feedKill"; feedKillValue.localScale = Vector3.one * .01f; feedKillValue.GetComponent <Renderer> ().material.color = Color.blue; Vector2 feedKillUV = new Vector2(randomizer.Unlerp("feedRate", _parameters.feedRate), randomizer.Unlerp("killRate", _parameters.killRate)); Debug.Log(feedKillUV); feedKillValue.position = GetComponent <MeshFilter> ().UVToWorldPos(feedKillUV, new int[] { 4, 5 }); ABRatesValue = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform; ABRatesValue.name = "ABRates"; ABRatesValue.localScale = Vector3.one * .01f; ABRatesValue.GetComponent <Renderer> ().material.color = Color.green; Vector2 ABUV = new Vector2(randomizer.Unlerp("aRate", _parameters.aRate), randomizer.Unlerp("bRate", _parameters.bRate)); ABRatesValue.position = GetComponent <MeshFilter> ().UVToWorldPos(ABUV, new int[] { 2, 3 }); } if (Input.GetMouseButton(0)) { if (m_PresetUnique == false) { Parameters = Instantiate <RDPreset> (_parameters); } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit) && hit.transform == transform) { Vector2 uv = hit.textureCoord; int tIndex = hit.triangleIndex; Debug.LogFormat("Triangle index = {0}", tIndex); UVParameters(uv, tIndex); } } }