public static bool Approach(ref float inVal, float inTarget, float inApproachSpeed) { Ross_Utils.Assert(inApproachSpeed >= 0); if (inVal < inTarget) { inVal += inApproachSpeed; if ((inVal) >= inTarget) { inVal = inTarget; return(true); } } else if (inVal > inTarget) { inVal -= inApproachSpeed; if ((inVal) <= inTarget) { inVal = inTarget; return(true); } } return(false); }
public void LoadGameData() { #if UNITY_WEBPLAYER return; #endif string path = pathForDocumentsFile(fileName); Debug.Log("try to load " + path); //if the file has not been made yet then set defaults and create it... if (!File.Exists(path)) { Debug.Log("failed to load - Create GameSave File " + fileName); this.SetGameDataDefaults(); FileStream newFile = new FileStream(path, FileMode.Create, FileAccess.Write); this.WriteGameDataToFile(newFile); newFile.Close(); return; } //Otherwise just read it Ross_Utils.Log("Read GameSave File " + fileName); FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read); this.ReadGameDataFromFile(file); file.Close(); }
//--------------------------------------------- void Update() { if (transitionTimer > 0.0f) { transitionTimer -= Time.deltaTime; if (transitionTimer <= 0.0f) { if (state == State.kShowing) { transform.localPosition = shownPosition; state = State.kShown; } else { transform.localPosition = hiddenPosition; state = State.kHidden; } } else { float ratio = 1.0f - transitionCurve.Evaluate(transitionTimer / transitionDuration); transform.localPosition = Ross_Utils.GetPositionBetween(ratio, moveFrom, moveTo); } } }
public static float GetRandBetween(float inValMin, float inValMax) { int min = (int)(inValMin * 10000.0f); int max = (int)(inValMax * 10000.0f); int outInt = min + (Ross_Utils.GetRand((max - min))); return(((float)outInt) / 10000.0f); }
//---------------------------------------------- public AchievementDetails GetAchievementDetails(Profile.Enum2 inAchievement) { for (int i = 0; i < achievementDetailsList.Length; i++) { if (achievementDetailsList[i].achievementType == inAchievement) { return(achievementDetailsList[i]); } } Ross_Utils.Assert(false); return(achievementDetailsList[0]); }
public void SaveGameData() { #if UNITY_WEBPLAYER return; #endif if (logOn) { Ross_Utils.Log("Write to GameSave File " + fileName); } string path = this.pathForDocumentsFile(fileName); FileStream file = new FileStream(path, FileMode.Open, FileAccess.Write); this.WriteGameDataToFile(file); file.Close(); }
public static Vector2 GetPositionWithinCircle(float circleRadius) { float distThing = 1000000000.0f; float sqrThing = circleRadius * circleRadius; float xPos; float yPos; do { xPos = Ross_Utils.GetRandBetween(-circleRadius, circleRadius); yPos = Ross_Utils.GetRandBetween(-circleRadius, circleRadius); distThing = Ross_Utils.GetSqrDistance(new Vector2(0, 0), new Vector2(xPos, yPos)); }while(distThing > sqrThing); return(new Vector2(xPos, yPos)); }
public static int GetNearestThing(Vector2 headPos, Vector2[] positionArray, int numItems) { float nearestDistanceSqr = -1.0f; int nearestItem = -1; for (int i = 0; i < numItems; i++) { float sqrDist = Ross_Utils.GetSqrDistance(headPos, positionArray[i]); if ((nearestItem == -1) || (sqrDist < nearestDistanceSqr)) { nearestItem = i; nearestDistanceSqr = sqrDist; } } return(nearestItem); }
public static float GetCosInterpolation(float inVal, float inMin, float inMax) { if (inVal < inMin) { inVal = inMin; } if (inVal > inMax) { inVal = inMax; } float range = inMax - inMin; Ross_Utils.Assert(range != 0.0f); float ratio = (inMax - inVal) / (inMax - inMin); ratio *= 4095.999f; Ross_Utils.Assert(initialised); return(preCalculatedCos[(int)ratio]); }
public static float GetRandomRotation() { return(Ross_Utils.GetRandBetween(0.0f, 2.0f * Mathf.PI)); }
//----------------------------------------------------------------------------- public void StartThrob() { Ross_Utils.Log("Throb: Start Throb 0"); this.StartThrobMultiple(1); }