/// <summary> /// /// </summary> /// <param name="diffIndex"></param> private void ApplyTargetForAnim(int diffIndex) { JCS_RollSelectorButton currentBtn = null; JCS_RollSelectorButton targetBtn = null; Vector3[] newTargetPosHolder = new Vector3[mButtons.Length]; int[] scrollIndexHolder = new int[mButtons.Length]; // asymp scale effect Vector3[] newRecordScaleHolder = new Vector3[mButtons.Length]; Vector3[] newTowardScaleHolder = new Vector3[mButtons.Length]; for (int index = 0; index < mButtons.Length; ++index) { int overflowIndex = JCS_Mathf.OverFlowIndex(index + diffIndex, mButtons.Length); currentBtn = mButtons[index]; targetBtn = mButtons[overflowIndex]; if (currentBtn == null || targetBtn == null) { JCS_Debug.LogError("Missing `JCS_Button` assign in the inspector..."); continue; } Vector3 newTargetPos = currentBtn.SimpleTrackAction.TargetPosition; newTargetPos = targetBtn.SimpleTrackAction.TargetPosition; newTargetPosHolder[index] = newTargetPos; scrollIndexHolder[index] = targetBtn.ScrollIndex; if (mAsympEffect) { newRecordScaleHolder[index] = targetBtn.GetScaleEffect().RecordScale; newTowardScaleHolder[index] = targetBtn.GetScaleEffect().TowardScale; } } for (int index = 0; index < mButtons.Length; ++index) { currentBtn = mButtons[index]; currentBtn.SimpleTrackAction.TargetPosition = newTargetPosHolder[index]; currentBtn.ScrollIndex = scrollIndexHolder[index]; if (mAsympEffect) { JCS_ScaleEffect se = currentBtn.GetScaleEffect(); se.RecordScale = newRecordScaleHolder[index]; se.TowardScale = newTowardScaleHolder[index]; se.Active(); } } }
/// <summary> /// /// </summary> /// <param name="type"></param> public void TurnFace(JCS_2DFaceType type) { Vector3 originalScale = this.gameObject.transform.localScale; float absoluteOriginalScale = JCS_Mathf.AbsoluteValue(originalScale.x); this.gameObject.transform.localScale = new Vector3((int)type * absoluteOriginalScale, originalScale.y, originalScale.z); mFace = type; }
private void Update() { #if (UNITY_EDITOR) Test(); #endif if (mTargetTransform == null) { return; } InputCamera(); // update the angle from target we are following mTargetAngle = mTargetTransform.localEulerAngles.y; DoFollowing(); DoResetToAxis(); UpDownMovement(); // get the wheel value from the Unity API // (physical layer[mouse wheel] -> // os layer[windows7] -> // application layer[Unity itself]) -> // to here... mWheelDegree = Input.GetAxis("Mouse ScrollWheel"); ZoomCamera(mWheelDegree); // Fix the speed if reach the distance! FixedMinMaxDistance(); Vector3 newPos = Vector3.forward * mTargetScrollSpeed * Time.deltaTime; // if is valid, do action. if (!JCS_Mathf.IsNaN(newPos)) { // record down the position before calling the // translate function Vector3 currentPos = this.transform.position; // do translate base on the scrolling distance // we get from the input buffer. this.transform.Translate(newPos); // get the updated position! Vector3 afterTransPos = this.transform.position; // update the track position mTrackPosition += afterTransPos - currentPos; } // asymptotic back to zero mTargetScrollSpeed += (0 - mTargetScrollSpeed) / mScrollSpeedFriction * Time.deltaTime; }
/// <summary> /// Initialize all the buttons' scale size. /// </summary> private void InitAsympScale() { // if not this effect, return it. if (!mAsympEffect) { return; } JCS_RollSelectorButton currentBtn = null; int centerIndex = JCS_Mathf.FindMiddleIndex(mButtons.Length); // initialzie the scroll index. for (int index = 0; index < mButtons.Length; ++index) { currentBtn = mButtons[index]; Vector3 scale = Vector3.zero; if (index <= centerIndex) { scale = (mAsympDiffScale * index) + mAsympDiffScale; } else { scale = (mAsympDiffScale * (index - ((index - centerIndex) * 2))) + mAsympDiffScale; } if (mPanelRoot != null) { scale.x /= mPanelRoot.PanelDeltaWidthRatio; scale.y /= mPanelRoot.PanelDeltaHeightRatio; } JCS_ScaleEffect se = currentBtn.GetScaleEffect(); if (se == null) { JCS_Debug.LogError( "JCS_ScaleEffect are null but we still want the effect. plz make sure all the button have JCS_ScaleEffet component!"); // close the effect. mAsympEffect = false; return; } se.RecordScale += scale; // the change value plus the original scale. // so it will keep the original setting form the // level designer. se.TowardScale += scale + se.GetScaleValue(); se.JCS_OnMouseOver(); } }
private void Start() { // set all action to this move speed mGoStraightAction.MoveSpeed = MoveSpeed; // if tracking are using the smooth track. // move speed have to be positive in order to get to the // correct direction. mTrackAction.MoveSpeed = JCS_Mathf.ToPositive(MoveSpeed); }
/* Functions */ private void Awake() { instance = CheckSingleton(instance, this); // This will only run once at the time when // the application is starts. if (!JCS_ApplicationSettings.instance.APPLICATION_STARTS) { // Calculate standard screen width and screen height. { float gcd = JCS_Mathf.GCD(STANDARD_SCREEN_WIDTH, STANDARD_SCREEN_HEIGHT); ASPECT_RATIO_SCREEN_WIDTH = (int)((float)STANDARD_SCREEN_WIDTH / gcd); ASPECT_RATIO_SCREEN_HEIGHT = (int)((float)STANDARD_SCREEN_HEIGHT / gcd); } if (RESIZE_TO_ASPECT_WHEN_APP_STARTS) { // Force resize screen/window to certain aspect // ratio once. ForceAspectScreenOnce(true); } if (RESIZE_TO_STANDARD_WHEN_APP_STARTS) { // Force resize screen/window to standard // resolution once. ForceStandardScreenOnce(true); } /* * NOTE(jenchieh): This is really weird, that even we * use 'Screen.SetResolution' function, the 'Screen.width' * and 'Screen.height' will not change immediately. * We just have to get it ourselves in all resize event * function like above these functions. * * -> ForceAspectScreenOnce * -> ForceStandardScreenOnce * */ // Record down the starting screen width and screen height. //STARTING_SCREEN_WIDTH = Screen.width; //STARTING_SCREEN_HEIGHT = Screen.height; } else { // Othereise, check if new scene loaded resize the // screen once? if (RESIZE_TO_ASPECT_EVERYTIME_SCENE_LOADED) { ForceAspectScreenOnce(); } } }
/// <summary> /// Check if the character controller top of the box without /// slope calculation. /// </summary> /// <param name="cap"> character controller to test. </param> /// <param name="rect"> box to test. </param> /// <returns> /// true : is top of box. /// false : vice versa. /// </returns> public static bool TopOfBox(CharacterController cap, BoxCollider rect) { Vector3 rectScale = rect.transform.localScale; Vector3 capScale = cap.transform.localScale; rectScale = JCS_Mathf.AbsoluteValue(rectScale); capScale = JCS_Mathf.AbsoluteValue(capScale); //float rWidth = rect.size.x * rectScale.x; float rHeight = rect.size.y * rectScale.y; Vector3 rectCenter = new Vector3( rect.center.x * rectScale.x, rect.center.y * rectScale.y, rect.center.z * rectScale.z); Vector3 cCenter = new Vector3( cap.center.x * capScale.x, cap.center.y * capScale.y, cap.center.z * capScale.z); float cR = cap.radius * capScale.x; float cH = (cap.height - (cap.radius * 2.0f)) * capScale.y; if (cH < 0) { cH = 0; } float rTopBound = rect.transform.position.y + rectCenter.y + (rHeight / 2.0f); float cBotBound = cap.transform.position.y + cCenter.y - (cH / 2.0f) - cR; #if (UNITY_EDITOR) Debug.DrawLine(rect.transform.position + rectCenter, new Vector3( rect.transform.position.x, rTopBound, rect.transform.position.z) , Color.cyan); Debug.DrawLine(cap.transform.position + cCenter, new Vector3( cap.transform.position.x, cBotBound, cap.transform.position.z) , Color.blue); #endif if (rTopBound <= cBotBound) { return(true); } return(false); }
/// <summary> /// Check if the value are able to cast. /// Mana value must higher than the cast value. /// </summary> /// <param name="val"> value to cast </param> /// <returns> true: able to cast, /// false: not able to cast </returns> public override bool IsAbleToCast(float val) { // able to cast the spell if (GetCurrentValue() >= JCS_Mathf.ToPositive(val)) { return(true); } // not able to cast the spell return(false); }
/// <summary> /// Reset the camera to certain axis. /// </summary> private void DoResetToAxis() { if (!mDoReset) { return; } Vector2 selfPos = new Vector2( this.transform.position.x, this.transform.position.z); Vector2 targetPos = new Vector2( mTargetTransform.position.x, mTargetTransform.position.z); // radius = distance between the two but not including y axis. float radius = Vector2.Distance(selfPos, targetPos); float diameter = radius * 2; float circumference = diameter * Mathf.PI; float currentAngle = this.transform.localEulerAngles.y; float circumferenceDistance = circumference * (mResetTargetAngle - currentAngle) / 360.0f; if (JCS_Mathf.isPositive(circumferenceDistance)) { if (circumferenceDistance + mAcceptRange <= 0 || mCheckState == CheckState.NEGATIVE) { mDoReset = false; return; } RotateAroundRight(); mCheckState = CheckState.POSITIVE; } else { if (circumferenceDistance + mAcceptRange >= 0 || mCheckState == CheckState.POSITIVE) { mDoReset = false; return; } RotateAroundLeft(); mCheckState = CheckState.NEGATIVE; } }
/// <summary> /// /// </summary> private void SpawnAttackAnimation() { if (mAtkAnim == null) { JCS_Debug.LogReminders( "JCS_SwingAttackAction", @"No animation assign but u still want to spawn a animation..."); return; } GameObject gm = new GameObject(); #if (UNITY_EDITOR) gm.name = "JCS_SwingAttackAction"; #endif // set the effect transform. if (mAsSamePosition) { gm.transform.position = this.mAtkAnimSpawnTrans.position; } if (mAsSameRotation) { gm.transform.rotation = this.mAtkAnimSpawnTrans.rotation; } if (mAsSameScale) { gm.transform.localScale = this.mAtkAnimSpawnTrans.localScale; } gm.transform.position += mAnimOffsetPosition; gm.transform.localScale += mAnimOffsetScale; if (this.transform.localScale.x < 0) { Vector3 newScale = gm.transform.localScale; newScale.x = JCS_Mathf.ToNegative(newScale.x); gm.transform.localScale = newScale; } SpriteRenderer sr = gm.AddComponent <SpriteRenderer>(); sr.sortingOrder = mOrderLayer; Animator animator = gm.AddComponent <Animator>(); animator.runtimeAnimatorController = mAtkAnim; animator.speed = animator.speed * JCS_Mathf.Reciprocal(mAnimSpeed); JCS_DestroyAnimEndEvent dae = gm.AddComponent <JCS_DestroyAnimEndEvent>(); dae.LoopTimes = mLoopTimes; }
/// <summary> /// Do the revolution rotate base on speed. /// </summary> /// <param name="speed"> direction and speed. </param> private void RotateAround(float speed) { if (mTargetTransform == null) { JCS_Debug.LogError("There is no target to reset the camera!"); return; } // to the rotate formula. this.transform.position = JCS_Mathf.RotatePointY(transform.position, Mathf.Cos(speed / 1000), Mathf.Sin(speed / 1000), mTargetTransform.position); // NOTE(jenchieh): also set to the track position. mTrackPosition = this.transform.position; }
/// <summary> /// Start sliding the screen out the scene. /// </summary> /// <param name="align"> align type </param> public void StartSlideOut(JCS_Align align, float time) { Vector2 sizeDelta = JCS_Canvas.GuessCanvas().AppRect.sizeDelta; float imageSize = 1200; float distanceX = sizeDelta.x + imageSize; float distanceY = sizeDelta.y + imageSize; // NOTE(jenchieh): this is just some tweeking. mTweener.DurationX = time; mTweener.DurationY = time; mTweener.DurationZ = time; Vector3 tweenTo = this.transform.localPosition; switch (align) { // going left showing from right // ============-------------- case JCS_Align.ALIGN_RIGHT: { tweenTo.x = JCS_Mathf.ToNegative(distanceX); } break; // going right showing from left // -----------============= case JCS_Align.ALIGN_LEFT: { tweenTo.x = JCS_Mathf.ToPositive(distanceX); } break; case JCS_Align.ALIGN_BOTTOM: { tweenTo.y = JCS_Mathf.ToPositive(distanceY); } break; case JCS_Align.ALIGN_TOP: { tweenTo.y = JCS_Mathf.ToNegative(distanceY); } break; } // start sliding mTweener.DoTween(tweenTo); }
/// <summary> /// Return CharacterController's collider's center as /// a global position. /// </summary> /// <returns> CharacterController's collider's center as a /// global position. </returns> public static Vector3 GetColliderCenterPosition(CharacterController cap) { Vector3 capScale = cap.transform.localScale; capScale = JCS_Mathf.AbsoluteValue(capScale); Vector3 cCenter = new Vector3( cap.center.x * capScale.x, cap.center.y * capScale.y, cap.center.z * capScale.z); Vector3 capCenterPos = cap.transform.position + cCenter; return(capCenterPos); }
//---------------------- // Protected Functions //---------------------- // Private Functions /// <summary> /// Do the Hour GUI. /// </summary> /// <param name="hour"> time to apply. </param> private void DoHourUI(float hour) { if (mDigitHour1 == null || mDigitHour2 == null) { JCS_Debug.LogError( "Digit slot cannot be null references..."); return; } int valDigit = JCS_Mathf.GetSingleDigit(1, (int)hour); mDigitHour1.LocalSprite = GetSingleDigitSprite(valDigit); valDigit = JCS_Mathf.GetSingleDigit(2, (int)hour); mDigitHour2.LocalSprite = GetSingleDigitSprite(valDigit); }
/// <summary> /// Do the Seconds GUI. /// </summary> /// <param name="second"> time to apply. </param> private void DoSecondUI(float second) { if (mDigitSecond1 == null || mDigitSecond2 == null) { JCS_Debug.LogError( "Digit slot cannot be null references..."); return; } int valDigit = JCS_Mathf.GetSingleDigit(1, (int)second); mDigitSecond1.LocalSprite = GetSingleDigitSprite(valDigit); valDigit = JCS_Mathf.GetSingleDigit(2, (int)second); mDigitSecond2.LocalSprite = GetSingleDigitSprite(valDigit); }
/// <summary> /// Return BoxCollider's center as a global position. /// </summary> /// <returns> box collider's center as a global position. </returns> public static Vector3 GetColliderCenterPosition(BoxCollider rect) { Vector3 rectScale = rect.transform.localScale; rectScale = JCS_Mathf.AbsoluteValue(rectScale); // 取得Collider的中心"相對位置". Vector3 rectCenter = new Vector3( rect.center.x * rectScale.x, rect.center.y * rectScale.y, rect.center.z * rectScale.z); // 所以要相加才能得到正確的"世界位置"! // * cCenter + cap.transform.position 同理. return(rectCenter + rect.transform.position); }
/// <summary> /// Do the Minute GUI. /// </summary> /// <param name="minute"> time to apply. </param> private void DoMinuteUI(float minute) { if (mDigitMinute1 == null || mDigitMinute2 == null) { JCS_Debug.LogError( "Digit slot cannot be null references..."); return; } int valDigit = JCS_Mathf.GetSingleDigit(1, (int)minute); mDigitMinute1.LocalSprite = GetSingleDigitSprite(valDigit); valDigit = JCS_Mathf.GetSingleDigit(2, (int)minute); mDigitMinute2.LocalSprite = GetSingleDigitSprite(valDigit); }
/// <summary> /// Set on/off position to the current transform position. /// </summary> private void SetStartingPosition() { if (!mOnOffStartingPosition) { return; } if (mIsOn) { this.mOnPos = mToggleSign.transform.localPosition; this.mOffPos = JCS_Mathf.ToNegative(mToggleSign.transform.localPosition); } else { this.mOffPos = mToggleSign.transform.localPosition; this.mOnPos = JCS_Mathf.ToNegative(mToggleSign.transform.localPosition); } }
/// <summary> /// Calculate the the closest point by range and targetPos. /// </summary> /// <param name="targetPos"></param> /// <returns></returns> private Vector3 CalculateClosest(Vector3 targetPos, float distance) { Vector3 newTargetPos = targetPos; Vector3 vec = this.transform.position - targetPos; vec = vec.normalized; float hyp = JCS_Mathf.PythagoreanTheorem(vec.x, vec.z, JCS_Mathf.TriSides.hyp); float ratio = distance / hyp; newTargetPos.x += vec.x * ratio; newTargetPos.z += vec.z * ratio; newTargetPos.y = this.transform.position.y; return(newTargetPos); }
/// <summary> /// Return Box Collider's width and height. /// </summary> /// <param name="cap"> object we want to take from </param> /// <returns> x : width, y : height </returns> public static Vector2 GetColliderWidthHeight(BoxCollider rect) { // holder Vector2 widthHeight = Vector2.zero; Vector3 rectScale = rect.transform.localScale; rectScale = JCS_Mathf.AbsoluteValue(rectScale); float rWidth = rect.size.x * rectScale.x; float rHeight = rect.size.y * rectScale.y; // apply to holder widthHeight.x = rWidth; widthHeight.y = rHeight; return(widthHeight); }
//---------------------- // Protected Functions //---------------------- // Private Functions /// <summary> /// Calculate the range and position relationship /// in order to find the best destination in the /// navigation map. /// /// IMPORTANT(JenChieh): if the vector does not in the range, /// enemy will stay at the place they are, which mean enemy /// will do nothing... /// </summary> /// <returns> result destination </returns> private Vector3 CalculateRange(Vector3 targetPos) { Vector3 newTargetPos = targetPos; // set up the unknown angle // 隨機"內角" float angle = JCS_Random.Range(0, 360); // define offset float hypOffset = JCS_Random.Range( -mAdjustRangeDistance, mAdjustRangeDistance); // add offset to current distance (hyp) float hyp = mRangeDistance + hypOffset; float opp = Mathf.Sin(angle) * hyp; float adj = JCS_Mathf.PythagoreanTheorem(hyp, opp, JCS_Mathf.TriSides.adj); bool flipX = JCS_Mathf.IsPossible(50); bool flipZ = JCS_Mathf.IsPossible(50); if (flipX) { newTargetPos.x -= adj; } else { newTargetPos.x += adj; } if (flipZ) { newTargetPos.z -= opp; } else { newTargetPos.z += opp; } return(newTargetPos); }
/// <summary> /// Main algorithm to approach to targe score. /// </summary> private void DoDeltaCurrentScore() { if (!mActive) { return; } if (System.Math.Round(mTargetNumber, mRoundPlace) == System.Math.Round(mCurrentNumber, mRoundPlace)) { mActive = false; return; } mAnimNumberTimer += Time.deltaTime; if (mAnimNumberTimer < mAnimNumberTime) { return; } float additionNumber = (mRoundPlace == 0.0f) ? 1.0f : 1.0f / Mathf.Pow(10.0f, mRoundPlace); bool wasLarger = (mTargetNumber < mCurrentNumber); if (wasLarger) { additionNumber = JCS_Mathf.ToNegative(additionNumber); } additionNumber *= mDeltaProduct; mCurrentNumber += additionNumber; if ((wasLarger && mTargetNumber > mCurrentNumber) || (!wasLarger && mTargetNumber < mCurrentNumber)) { mCurrentNumber = mTargetNumber; } UpdateTextRender(); // Reset timer. this.mAnimNumberTimer = 0.0f; }
/// <summary> /// Do score align after updating score. /// </summary> private void DoScoreAlign(int targetScore) { // digit cannot be zero, must at least be one. int newDigitCount = JCS_Mathf.DigitCountIncludeZero(targetScore); int diffDigitCount = newDigitCount - mCurrentDigitCount; // No difference, no need to do anything. if (diffDigitCount == 0) { return; } mCurrentDigitCount = newDigitCount; // We don't need to do align if the visible // digit count would not change. if (!mClearEmptyLeftZero) { return; } switch (mTextAlign) { case JCS_TextAlign.CENTER: { MoveDigits(mDigitInterval * diffDigitCount / 2); } break; case JCS_TextAlign.RIGHT: { // Default is right, no need to do anything. } break; case JCS_TextAlign.LEFT: { MoveDigits(mDigitInterval * diffDigitCount); } break; } }
/// <summary> /// Fix the speed/range if reach /// the min/max distance. /// </summary> private void FixedMinMaxDistance() { float currentDistance = Vector3.Distance(this.transform.position, mTargetTransform.position); if (JCS_Mathf.isPositive(mTargetScrollSpeed)) { if (currentDistance < mMinDistance) { mTargetScrollSpeed = 0; } } else { if (currentDistance > mMaxDistance) { mTargetScrollSpeed = 0; } } }
/// <summary> /// Check if a collider under the bottom of the box collider. /// </summary> /// <param name="cap"></param> /// <param name="rect"></param> /// <returns></returns> public static bool BottomOfBox(CharacterController cap, BoxCollider rect) { Vector3 rectScale = rect.transform.localScale; Vector3 capScale = cap.transform.localScale; rectScale = JCS_Mathf.AbsoluteValue(rectScale); capScale = JCS_Mathf.AbsoluteValue(capScale); //float rWidth = rect.size.x * rectScale.x; float rHeight = rect.size.y * rectScale.y; Vector3 rectCenter = new Vector3( rect.center.x * rectScale.x, rect.center.y * rectScale.y, rect.center.z * rectScale.z); Vector3 cCenter = new Vector3( cap.center.x * capScale.x, cap.center.y * capScale.y, cap.center.z * capScale.z); float cR = cap.radius * capScale.x; float cH = (cap.height - (cap.radius * 2.0f)) * capScale.y; if (cH < 0) { cH = 0; } float cTopBound = cap.transform.position.y + cCenter.y + (cH / 2.0f) + cR; float rBotBound = rect.transform.position.y + rectCenter.y - (rHeight / 2.0f); if (cTopBound <= rBotBound) { return(true); } return(false); }
/// <summary> /// Walk depends on the status. /// </summary> /// <param name="status"></param> public void WalkByStatus(Status status) { switch (status) { case Status.IDLE: { Walk(0); // stop walking if (mLiveObjectAnimator != null) { mLiveObjectAnimator.DoAnimation(JCS_LiveObjectState.STAND); } } break; case Status.LEFT: { Walk(JCS_Mathf.ToNegative(mWalkSpeed)); if (mLiveObjectAnimator != null) { mLiveObjectAnimator.DoAnimation(JCS_LiveObjectState.WALK); } } break; case Status.RIGHT: { Walk(JCS_Mathf.ToPositive(mWalkSpeed)); if (mLiveObjectAnimator != null) { mLiveObjectAnimator.DoAnimation(JCS_LiveObjectState.WALK); } } break; } }
/// <summary> /// Set the page using page index. (x-axis) /// </summary> /// <param name="page"> Index of the page. </param> public void SetPageX(int page) { int delta = page - (int)this.mCurrentPage.x; if (delta == 0) { return; } int count = JCS_Mathf.AbsoluteValue(delta); for (int countX = 0; countX < count; ++countX) { if (JCS_Mathf.IsPositive(delta)) { SwitchScene(JCS_2D4Direction.RIGHT); } else { SwitchScene(JCS_2D4Direction.LEFT); } } }
/// <summary> /// Set the page using page index. (y-axis) /// </summary> /// <param name="page"> Index of the page. </param> public void SetPageY(int page) { int delta = page - (int)this.mCurrentPage.y; if (delta == 0) { return; } int count = JCS_Mathf.AbsoluteValue(delta); for (int countY = 0; countY < count; ++countY) { if (JCS_Mathf.IsPositive(delta)) { SwitchScene(JCS_2D4Direction.TOP); } else { SwitchScene(JCS_2D4Direction.BOTTOM); } } }
/// <summary> /// Return Character controller's collider's width and height. /// </summary> /// <param name="cap"> Character Controller component want to check. </param> /// <returns> x : width, y : height </returns> public static Vector2 GetColliderWidthHeight(CharacterController cap) { // holder Vector2 capWH = Vector2.zero; Vector3 capScale = cap.transform.localScale; capScale = JCS_Mathf.AbsoluteValue(capScale); float cR = cap.radius * capScale.x; float cH = cap.height * capScale.y; if (cH < 0) { cH = 0; } // apply to holder capWH.x = cR * 2; capWH.y = cH; return(capWH); }
/// <summary> /// Do the GUI score logic. /// </summary> /// <param name="score"> score to apply. </param> private void DoScoreGUI(int score) { // check the first non zero from the left. bool meetNonZero = false; for (int digit = mDigitsRendererSlot.Length - 1; digit >= 0; --digit) { if (mDigitsRendererSlot[digit] == null) { JCS_Debug.LogError( "Digit slot cannot be null references..."); continue; } int valDigit = JCS_Mathf.GetSingleDigit(digit + 1, score); mDigitsRendererSlot[digit].LocalSprite = GetSingleDigitSprite(valDigit); if (mClearEmptyLeftZero) { /** * Last digit is zero, we set to zero. so skip it. */ if (valDigit != -1) { meetNonZero = true; } if (!meetNonZero) { mDigitsRendererSlot[digit].LocalSprite = mScoreNull; } } } }