public void SetColor() { //get percentage of opposite color used based on health. Get that percentage of the dist from this and optimum color //and add that onto the optimum to get a blend of the 2 colors PlantRates pr = transform.root.gameObject.GetComponent <PlantRates>(); float colorPerc; if (pr.Health() >= healthToColorRatio) { colorPerc = NumOp.Cutoff(pr.Health() - GetComponent <Grow>().growthAmount, 0f, 1f); realTimeColor = NumOp.GetColorBlend(optimumColor, earlyColor, colorPerc); } else { float tmp = (healthToColorRatio - pr.Health()) * (1f / healthToColorRatio); colorPerc = NumOp.Cutoff(1f - (GetComponent <Grow>().growthAmount - tmp), 0f, 1f); realTimeColor = NumOp.GetColorBlend(optimumColor, lateColor, colorPerc); } realTimeColor = new Color(realTimeColor[0], realTimeColor[1], realTimeColor[2], alphaValue); if (debug) { print("percentage of opposite used: " + colorPerc.ToString()); } }
// Update is called once per frame void Update() { //set variables within appropriate ranges rotationOffset = NumOp.Cutoff(rotationOffset, 0f, 1f); sproutSize = NumOp.Cutoff(sproutSize, 0f, 1f); heightOffset = NumOp.Cutoff(heightOffset, 0f, 1f); angle = NumOp.Cutoff(angle, 0f, 360f); zLayer = NumOp.Cutoff(zLayer, 0, maxZLayer); if (GetComponent <Grow>().hasStarted) { if (!d) { print(String.Format("'{0}' {1}", transform.root.name, "okay")); d = true; } if ((leaves == null || leafCount != leaves.Length)) { leaves = CreateLeaves(leafCount); } float growthAmount = GetComponent <Grow>().growthAmount; SetLeavesRotation(angle * growthAmount, sproutSize * growthAmount, rotationOffset * growthAmount); SetHeightSkew(heightOffset * growthAmount, heightOffsetPower * growthAmount, invHeightSkew, leafScale * growthAmount); SetColor(); } }
// Update is called once per frame void Update() { //make sure variables stay in acceptable range expectedLifetime = NumOp.Cutoff(expectedLifetime, 1, expectedLifetime); deathTimeSkew = NumOp.Cutoff(deathTimeSkew, 0f, 1f); //get changed dependancy and balance based on the change int changedIndex = -1; for (int i = 0; i < allDependencies.Length; i++) { if (GetDepComp(allDependencies[i]).DepAmountChanged()) { changedIndex = i; } } if (changedIndex != -1) { BalanceFloats(allDependencies, changedIndex, maxEfficiency); } float actualDeathEffic = 0f; if (PlantAlive()) { currEfficiency = NumOp.Cutoff(GetCurrentEfficiency(allDependencies), 0f, 1f); //time till death decreases as efficiency lowers whereas it increases growth time //the higher the death skew, the more exponentially the currefficiency falls actualDeathEffic = currEfficiency - (currEfficiency * (deathTimeSkew * (1f - currEfficiency))); timeAliveLeft = (int)((float)expectedLifetime * actualDeathEffic); TimeToColor[] allColors = GetComponentsInChildren <TimeToColor>(); for (int i = 0; i < allColors.Length; i++) { allColors[i].alphaValue = 1f; } } else { TimeToColor[] allColors = GetComponentsInChildren <TimeToColor>(); for (int i = 0; i < allColors.Length; i++) { allColors[i].alphaValue = 0.25f; } } if (debug) { print("actual death efficiency: " + actualDeathEffic.ToString()); print("Plant Time Left (%): " + Health().ToString()); print("Plant alive: " + PlantAlive().ToString()); print(String.Format("Name: {0}, TimeAlive: {1}hrs, TimeElapsed: {2}hrs", name, timeAliveLeft, GetComponent <Timer>().timeElapsed)); } }
public void BalanceFloats(GameObject [] values, int pivotIndex, float cutOff) { //balances array so all the dependency rates add up to the cutOff //pivot is the index that the other dependencies get balanced around float decValue = 0; foreach (GameObject obj in values) { decValue = decValue + GetDepComp(obj).dependencyAmount; } if (decValue > 0) { //get max index that's not the pivot, find all indexes with the same //value and decrement them int maxIndex = -1; for (int i = 0; i < values.Length; i++) { if (i != pivotIndex) { if (maxIndex == -1 || GetDepComp(values[i]).dependencyAmount > GetDepComp(values[maxIndex]).dependencyAmount) { maxIndex = i; } } } if (maxIndex != -1) { for (int i = 0; i < values.Length; i++) { if (i != pivotIndex) { if (GetDepComp(values[i]).dependencyAmount == GetDepComp(values[maxIndex]).dependencyAmount) { GetDepComp(values[i]).dependencyAmount = GetDepComp(values[i]).dependencyAmount - decValue; } else if (decValue < 1) { GetDepComp(values[i]).dependencyAmount = GetDepComp(values[i]).dependencyAmount - (decValue / 2); } } } for (int i = 0; i < values.Length; i++) { GetDepComp(values[i]).dependencyAmount = NumOp.Cutoff(GetDepComp(values[i]).dependencyAmount, 0f, cutOff); } } } }
// Update is called once per frame void Update() { healthToColorRatio = NumOp.Cutoff(healthToColorRatio, 0f, 1f); alphaValue = NumOp.Cutoff(alphaValue, 0f, 1f); SetColor(); if (setSpriteRendererColor) { GetComponent <SpriteRenderer>().color = realTimeColor; } }
//to remove from collection public void deleteFromList() { string plantName = pManager.plantCollection[indexNum].name; //destory and reset currplant DestroyImmediate(currPlant); currPlant = null; pManager.RemovePlant(indexNum); //remove from collection indexNum = NumOp.Cutoff(indexNum, 0, pManager.plantCollection.Count - 1); //set new index pManager.gameObject.GetComponent <PopUpManager>().PopUpMessage(String.Format("'{0}' has been deleted.", plantName)); prevIndexNum = indexNum; }
// Update is called once per frame void Update() { //make sure variables stay in acceptable range expectedGrowTime = NumOp.Cutoff(expectedGrowTime, 1, expectedGrowTime); growthTimeSkew = NumOp.Cutoff(growthTimeSkew, 0f, 1f); growthStages = NumOp.Cutoff(growthStages, 0, expectedGrowTime); PlantRates pr = transform.root.gameObject.GetComponent <PlantRates>(); //time till growth increases as efficiency lowers float actualGrowthEffic = (pr.currEfficiency - (pr.currEfficiency * growthTimeSkew)); currGrowTime = expectedGrowTime + (expectedGrowTime - (int)((float)expectedGrowTime * actualGrowthEffic)); int timeElapsed = transform.root.GetComponent <Timer>().timeElapsed; if (timeTillStart - timeElapsed <= 0) { hasStarted = true; } else { hasStarted = false; } if (hasStarted) { if (growthStages <= 0) { growthAmount = 1f; } else { int stageInterval = NumOp.Cutoff(currGrowTime, 0, currGrowTime) / growthStages; if (stageInterval <= 0) { growthAmount = 1f; } else { int stage = (timeElapsed - timeTillStart) / stageInterval; growthAmount = NumOp.Cutoff((float)stage / growthStages, 0f, 1f); } } } if (debug) { print(String.Format("Name: {0}, Full Growth Time: {1}hrs, TimeElapsed: {2}hrs", name, currGrowTime, (timeElapsed - timeTillStart))); } }
public void Set(string name, float newTime, float tickSpeed) { //set a countdown timer newTime = NumOp.Cutoff(newTime, 0, newTime); if (timeStamps.ContainsKey(name) != true) { timeStamps.Add(name, newTime); onGoingTimeStamps.Add(name, Time.time); tickSpeeds.Add(name, tickSpeed); } else { timeStamps[name] = newTime; onGoingTimeStamps[name] = Time.time; tickSpeeds[name] = tickSpeed; } }
// Update is called once per frame void Update() { string[] keys = new string[timeStamps.Count]; int i = 0; foreach (KeyValuePair <string, float> kvp in timeStamps) { keys[i] = kvp.Key; i++; } foreach (string key in keys) { float dist = Time.time - onGoingTimeStamps[key]; if (dist >= tickSpeeds[key] * speed) { //countdown the timer onGoingTimeStamps[key] = onGoingTimeStamps[key] + dist; timeStamps[key] = NumOp.Cutoff(timeStamps[key] - (tickSpeeds[key] * speed), 0, timeStamps[key]); if (key == "<<tick>>" && getTicks) { hasTicked = true; timeElapsed++; } } else if (key == "<<tick>>") { hasTicked = false; } } if (getTicks != true) { hasTicked = false; } if (TimeUp("<<tick>>")) { Set("<<tick>>", maxSpeed, maxSpeed); } }
// Update is called once per frame void Update() { currValue = NumOp.Cutoff(currValue, 0, 100000000); minValue = NumOp.Cutoff(minValue, 0, minValue); maxValue = NumOp.Cutoff(maxValue, minValue, maxValue); optimumPercentage = NumOp.Cutoff(optimumPercentage, 0f, 1f); UpdateEfficiency(); if (dependencyAmount != prevDepAmount) { depAmountChanged = true; prevDepAmount = dependencyAmount; } if (debug) { print("Dependency efficieiency: " + dependencyEfficiency.ToString()); } }
public void UpdateEfficiency() { float optimumValue = minValue + ((maxValue - minValue) * optimumPercentage); optimumValue = NumOp.Cutoff(optimumValue, minValue, maxValue); // currValue = optimumValue; //Get efficiency of dependency, the closer to the optimum it is, the higher the efficiency if (currValue <= optimumValue) { dependencyEfficiency = NumOp.Cutoff((float)(currValue - minValue) / (float)(optimumValue - minValue), 0, 1f); } else { dependencyEfficiency = NumOp.Cutoff((float)(maxValue - currValue) / (float)(maxValue - optimumValue), 0, 1f); } if (debug) { print("Optimum Value: " + optimumValue.ToString()); } }
public void SetHeightSkew(float skewAmount, float offsetAmount, bool reverseSkew, Vector2 leafScale) { //sets how much the leaves' height are skewed from the centre //offsetAmount represents the amount of skew used the further //the leaf is from the center //skewAmount and offSetAMount are floats from 0 -> 1 int midInd = leaves.Length / 2; if (leaves.Length % 2 == 0) { midInd--; } for (int i = 0; i <= midInd; i++) { Vector3 interval = leafScale - ((leafScale * skewAmount) * ((i) / ((float)midInd + 1))); interval = new Vector3(interval[0], interval[1], 1); if (reverseSkew) { SetLocalScale(leaves[i], interval); SetLocalScale(leaves[leaves.Length - i - 1], interval); } else { SetLocalScale(leaves[midInd - i], interval); SetLocalScale(leaves[leaves.Length - midInd + i - 1], interval); } if (offsetAmount > 0) { skewAmount = NumOp.Cutoff(skewAmount + (skewAmount * offsetAmount), 0f, 1f); } } }
public void SetLeavesRotation(float newAngle, float anglePower, float rotationOffset) { //sets the spread of the leaves evenly around angle. //angle power is how much of the total angle is used //anglePower is a float from 0 -> 1 float maxAngle = newAngle * anglePower; float interval = maxAngle / (leaves.Length - 1); if (debug) { print("Current max angle: " + maxAngle.ToString()); print("Angle interval: " + interval.ToString()); } int midInd = leaves.Length / 2; if (leaves.Length % 2 == 0) { midInd--; } for (int i = 0; i <= midInd; i++) { //get angles on one side and mirror to the other side float zAngle = (maxAngle / 2) - (interval * i); zAngle = zAngle - ((zAngle * rotationOffset) * ((i + 1) / (1 + (float)midInd))); zAngle = NumOp.Cutoff(zAngle, 0, 360f); if (zAngle >= 0) { Vector3 rotation = new Vector3(0, 0, zAngle); leaves[i].transform.parent.rotation = Quaternion.Euler(rotation); leaves[leaves.Length - i - 1].transform.parent.rotation = Quaternion.Euler(-rotation); } } }
// Update is called once per frame void Update() { //setting the timer speed for every plant in the collection float maxSpeed = GetComponent <Timer>().maxSpeed; globalTimeSpeed = NumOp.Cutoff(1f - timeSlider.GetComponent <Slider>().value, maxSpeed, 1f); GetComponent <Timer>().speed = globalTimeSpeed / maxSpeed; //set timer speed and status for active and inactive plants foreach (GameObject plant in activePlants) { if (plant) { plant.GetComponent <Timer>().getTicks = true; } } int i = 0; while (i < plantCollection.Count) { if (plantCollection[i]) { plantCollection[i].GetComponent <Timer>().speed = GetComponent <Timer>().speed; if (!plantCollection[i].GetComponent <PlantRates>().PlantAlive()) { plantCollection[i].GetComponent <Timer>().getTicks = false; } } i++; } //Set the name of the active plant tags for (int j = 0; j < activePlants.Length; j++) { GameObject plant = activePlants[j]; foreach (PlantTag tag in plantTags) { if (tag.position == j) { string tagText; if (plant) { tagText = plant.name; if (tagText.Length > 9) { tagText = plant.name.Substring(0, 9) + "..."; } } else { tagText = "-"; } tag.nameTag.GetComponentInChildren <TextMesh>().text = tagText; } } } GetComponent <Timer>().getTicks = true; }
public void Change(string name, float amount) { //changes current time stamp by given amount amount = NumOp.Cutoff(amount, 0, amount); timeStamps[name] = timeStamps[name] + (amount - timeStamps[name]); }
public int timeElapsed; //reference of how many units of time has passed // Start is called before the first frame update void Start() { Set("<<tick>>", maxSpeed, maxSpeed); speed = NumOp.Cutoff(speed, 0f, 1f); }