public void update(bool callCallBack = true) { if (!_Animating) { return; } if (_TimeElapsed < _Duration) { if (_Easing == null) { return; } _Progression = _Easing.Invoke(_TimeElapsed, _From, (_To - _From), _Duration); _ProgressPct = _TimeElapsed / _Duration; _TimeElapsed += Time.deltaTime; } else { _Progression = _To; _Animating = false; _TimeElapsed = 0.0f; _ProgressPct = 1.0f; if (callCallBack && _Callback != null) { _Callback.Invoke(); } } }
/// <summary> /// Tween to the taget position and play sound effect. /// </summary> public void Active() { if (!mOverrideTween) { if (!mTweenerHandler.IsAllDoneTweening()) { return; } } if (this.mIsActive) { return; } mTweenerHandler.DoAllTweenToTargetValue(); JCS_SoundPlayer.PlayByAttachment(mSoundPlayer, mActiveSound, JCS_SoundMethod.PLAY_SOUND_WHILE_NOT_PLAYING); if (mPanelRoot != null) { mPanelRoot.Show(true); } if (mActiveCallbackFunc != null) { mActiveCallbackFunc.Invoke(); } this.mIsActive = true; }
/// <summary> /// Loop through the execution. /// </summary> private void DoLoop() { if (!mActive) { return; } this.mTimer += Time.deltaTime; if (this.mTimer < this.mIntervalTime) { return; } if (mExecution != null) { mExecution.Invoke(); } if (mUnityExecution != null) { mUnityExecution.Invoke(); } this.mTimer = 0.0f; }
/// <summary> /// Tween back to the starting position and play sound effect. /// </summary> public void Deactive() { if (!mOverrideTween) { if (!mTweenerHandler.IsAllDoneTweening()) { return; } } if (!this.mIsActive) { return; } mTweenerHandler.DoAllTweenToStartValue(); JCS_SoundPlayer.PlayByAttachment(mSoundPlayer, mDeactiveSound, JCS_SoundMethod.PLAY_SOUND_WHILE_NOT_PLAYING); if (mDeactiveCallbackFunc != null) { mDeactiveCallbackFunc.Invoke(); } this.mIsActive = false; }
/// <summary> /// Do the timer action, execute the function pointer if the /// timer had reached repeatedly. /// </summary> private void DoAction() { if (mDidAction) { ResetTimeZone(); } mTimer += Time.deltaTime; if (mRealTimeZone > mTimer) { return; } // active actions. if (actions != null) { actions.Invoke(); } if (mUnityEvents != null) { mUnityEvents.Invoke(); } mDidAction = true; }
public static bool Button(string text, EmptyFunction func) { if (Button(text)) { func.Invoke(); return(true); } return(false); }
public static void BeginHorizontal(EmptyFunction func, bool flexibleSpace = false) { GUILayout.BeginHorizontal(); if (flexibleSpace) { GUILayout.FlexibleSpace(); } func.Invoke(); GUILayout.EndHorizontal(); }
/// <summary> /// Invoke deactive callback. /// </summary> public void DoDeactiveFunc() { if (onDeactive == null) { JCS_Debug.LogError("U have not set the DEACTIVE function ptr..."); return; } // do the action. onDeactive.Invoke(); }
/* Setter & Getters */ /* Functions */ public static void IgnoreErrors(EmptyFunction func) { try { func.Invoke(); } catch (Exception) { // .. } }
public static void BeginVertical(EmptyFunction func, string style = "box") { if (style == "") { GUILayout.BeginVertical(); } else { GUILayout.BeginVertical("box"); } func.Invoke(); GUILayout.EndVertical(); }
/// <summary> /// Check weather if the easing are done. /// </summary> private void DoDoneEasing() { // trigger callback. if (mValueCallback != null) { mValueCallback.Invoke(); } // trigger unity callback. if (mUnityCallback != null) { mUnityCallback.Invoke(); } }
private void SafeDoCallback() { if (mDestinationCallback == null) { return; } if (!this.mDoneTweenX || !this.mDoneTweenY || !this.mDoneTweenZ) { return; } mDestinationCallback.Invoke(); }
/// <summary> /// Enable applicatin start flag after the first 'Update()' /// function runs, here we have 'JCS_GameManager' to be our /// 'Update()' pioneer runner. /// </summary> private void DoApplicationStart() { if (APPLICATION_STARTS) { return; } if (onApplicationStarts != null) { onApplicationStarts.Invoke(); } APPLICATION_STARTS = true; }
/// <summary> /// Set the current playing frame by index. /// </summary> /// <param name="frame"> /// Frame index in the array, out of array play null frame. /// </param> public void PlayFrame(int frame) { this.mCurrentPlayingFrame = frame; PutAnimInFrame(); Sprite currentPlayingSprite = mAnimFrames[this.mCurrentPlayingFrame]; // set the current sprite. LocalSprite = currentPlayingSprite; // callback.. if (playFrameCallback != null) { playFrameCallback.Invoke(); } }
/// <summary> /// Default function to call this, so we dont have to /// search the function depends on name. /// /// * Good for organize code and game data file in Unity. /// </summary> public virtual void ButtonClick() { this.mIsSelectedInGroup = IsSelected(); if (!mIsSelectedInGroup) { return; } if (!mInteractable) { return; } /* System callback */ if (btnSystemCallBack != null) { btnSystemCallBack.Invoke(); } if (btnSystemCallBackBtn != null) { btnSystemCallBackBtn.Invoke(this); } if (btnSystemCallBackBtnInt != null) { btnSystemCallBackBtnInt.Invoke(this.mDialogueSelection); } /* User callback */ if (btnCallBack != null) { btnCallBack.Invoke(); } if (btnCallBackBtn != null) { btnCallBackBtn.Invoke(this); } }
/// <summary> /// Check weather if the easing are done. /// </summary> private void CheckDoneEasing() { // check if any still easing. if (mEasingA || mEasingR || mEasingG || mEasingB) { return; } // trigger callback. if (mColorCallback != null) { mColorCallback.Invoke(); } // trigger unity callback. if (mUnityCallback != null) { mUnityCallback.Invoke(); } }
/// <summary> /// Set back to starting position. /// </summary> public void ResetPosition() { if (beforeResetCallback != null) { beforeResetCallback.Invoke(); } if (mUseLocalPosition) { this.transform.localPosition = this.mOriginPos; } else { this.transform.position = this.mOriginPos; } if (afterResetCallback != null) { afterResetCallback.Invoke(); } }
/// <summary> /// Do the resizable window. /// </summary> private void DoResizableScreen() { float width = JCS_Screen.width; float height = JCS_Screen.height; if (CURRENT_SCREEN_SIZE.width == width && CURRENT_SCREEN_SIZE.height == height) { if (onScreenIdle != null) { onScreenIdle.Invoke(); } return; } if (PREV_SCREEN_SIZE.width == 0.0f || PREV_SCREEN_SIZE.height == 0.0f) { // If zero, set to the same value. PREV_SCREEN_SIZE.width = width; PREV_SCREEN_SIZE.height = height; } else { // Record previous screen info. PREV_SCREEN_SIZE.width = CURRENT_SCREEN_SIZE.width; PREV_SCREEN_SIZE.height = CURRENT_SCREEN_SIZE.height; } // Update current screen info. CURRENT_SCREEN_SIZE.width = width; CURRENT_SCREEN_SIZE.height = height; // Do callback. if (onScreenResize != null) { onScreenResize.Invoke(); } }
/// <summary> /// Call this to end the dialogue status. /// </summary> public void Dispose() { NextBtnActive(false); PrevBtnActive(false); YesBtnActive(false); NoBtnActive(false); AcceptBtnActive(false); DeclineBtnActive(false); OkBtnActive(false); // disable the exit button! ExitBtnActive(false); // dis-attach the script. mDialogueScript = null; ResetStats(); // de-active the panel transform. PanelActive(false); // de-active dialogue system. mActive = false; // Check initialize to ignore dispose called at the very beginning! if (JCS_GameManager.instance.GAME_DONE_INITIALIZE && callback_dispose != null) { callback_dispose.Invoke(); } // Play the dispose dialogue sound. JCS_SoundManager.instance.GetGlobalSoundPlayer().PlayOneShot(mDisposeSound); }
/// <summary> /// Selection this selection. /// </summary> /// <param name="selectionIndex"> index to select. </param> public void SelectSelection(int selectionIndex, bool hoverCheck = false) { if (hoverCheck) { if (JCS_Util.WithInArrayRange(selectionIndex, mSelections)) { if (mSelections[selectionIndex].Skip) { return; } } } // no need to do anything. if (mCurrentSelectIndex == selectionIndex) { return; } if (JCS_Util.WithInArrayRange(mCurrentSelectIndex, mSelections)) { // disable current active selection. mSelections[mCurrentSelectIndex].Active = false; } this.mCurrentSelectIndex = selectionIndex; this.mCurrentSelectIndex = JCS_Util.LoopInArray(this.mCurrentSelectIndex, mSelections); // active the new active selection. mSelections[mCurrentSelectIndex].Active = true; if (selectionChanged != null) { selectionChanged.Invoke(); } }
/// <summary> /// Process the user input. /// </summary> private void ProcessInput() { if (!mAction) { if (JCS_Input.GetMouseByAction(mKeyAct, mMouseButton)) { mAction = true; } if (JCS_Input.GetKey(mShootKeyCode)) { mAction = true; } } if (mAfterDelay) { mActionTimer += Time.deltaTime; if (mTimeDelayAfterShoot < mActionTimer) { // reset timer mActionTimer = 0; // can do the next shoot mAction = false; // exit delay process mAfterDelay = false; } } if (mAction && !mAfterDelay) { mActionTimer += Time.deltaTime; if (mTimeBeforeShoot < mActionTimer) { // do call back mShootCallback.Invoke(); // check able to shoot before shoot. if (mCheckAbleToShoot.Invoke()) { // Do shooting effect for (int count = 0; count < mShootCount; ++count) { Shoot(); } } // start after delay timer. mAfterDelay = true; // reset timer for "mAfterDelay" Trigger. mActionTimer = 0; } } }
public static void Indent(EmptyFunction func) { EditorGUI.indentLevel += INDENT_LEVEL; func.Invoke(); EditorGUI.indentLevel -= INDENT_LEVEL; }
public static void BeginVertical(EmptyFunction func) { GUILayout.BeginVertical("box"); func.Invoke(); GUILayout.EndVertical(); }
/// <summary> /// Main algorithm to display animation frame /// by frame. /// </summary> private void RunAnimation() { // check if the animation active. if (!mActive) { return; } // start the timer. mFrameTimer += Time.deltaTime; // get the time per seconds. // NOTE(jenchieh): multiple you own animate production first. float timePerSec = mFramePerSec * mAnimationTimeProduction; // if there is animator taking over this animation. // times the production time! if (mJCS2DAnimator != null) { timePerSec = mFramePerSec * mJCS2DAnimator.AnimationTimeProduction; } // check timer reach the next frame time. if (mFrameTimer < timePerSec) { return; } // add one frame, ready for next frame. ++mCurrentPlayingFrame; bool playNullFrame = false; // reset the timer if reach the max frame. if (mCurrentPlayingFrame >= mMaxFrame) { if (mLoop) { mCurrentPlayingFrame = 0; } else { // current frame will just be the last frame. mCurrentPlayingFrame = mMaxFrame; // Turn on the flag if play null frame at the // end of playing the animation. if (mNullSpriteAfterDonePlayingAnim) { playNullFrame = true; } } // set the flag up. mIsDonePlaying = true; // do done play call back. if (donePlayingAnimCallback != null) { donePlayingAnimCallback.Invoke(); } } if (playNullFrame) { PlayNullFrame(); } else { // set the current frame. PlayFrame(mCurrentPlayingFrame); } // reset timer. mFrameTimer = 0.0f; }
/// <summary> /// Do the core fade effect. /// </summary> private void DoFade() { if (GetObjectType() == JCS_UnityObjectType.GAME_OBJECT && JCS_GameManager.instance.GAME_PAUSE) { return; } if (!mEffect) { return; } switch (mFadeType) { case JCS_FadeType.FADE_OUT: { // Fade out effect complete if (mAlpha < mFadeOutAmount) { switch (GetObjectType()) { case JCS_UnityObjectType.GAME_OBJECT: { //this.gameObject.SetActive(false); } break; case JCS_UnityObjectType.UI: { if (mImage != null) { mImage.enabled = false; } } break; case JCS_UnityObjectType.SPRITE: { if (mSpriteRenderer != null) { mSpriteRenderer.enabled = false; } } break; case JCS_UnityObjectType.TEXT: { if (mText != null) { mText.enabled = false; } } break; } mEffect = false; // do fade out callback if (fadeOutCallback != null) { fadeOutCallback.Invoke(); } return; } mAlpha -= Time.deltaTime / mFadeTime; } break; case JCS_FadeType.FADE_IN: { // Fade in effect complete if (mAlpha > mFadeInAmount) { mEffect = false; // do fade in callback if (fadeInCallback != null) { fadeInCallback.Invoke(); } return; } mAlpha += Time.deltaTime / mFadeTime; } break; } Color screenColor = this.LocalColor; screenColor.a = mAlpha; this.LocalColor = screenColor; }
public static void Indent(EmptyFunction func) { EditorGUI.indentLevel++; func.Invoke(); EditorGUI.indentLevel--; }