Exemple #1
0
        /// <summary>
        /// Convert string to byte array by charset type.
        /// </summary>
        /// <param name="data"> String data to convert to byte array. </param>
        /// <param name="charset"> Target charset type. </param>
        /// <returns> Byte array that had been converted. </returns>
        public static byte[] StringToBytes(string data, JCS_CharsetType charset)
        {
            switch (charset)
            {
            case JCS_CharsetType.DEFAULT: return(Encoding.Default.GetBytes(data));

            case JCS_CharsetType.ASCII: return(Encoding.ASCII.GetBytes(data));

            case JCS_CharsetType.UTF7: return(Encoding.UTF7.GetBytes(data));

            case JCS_CharsetType.UTF8: return(Encoding.UTF8.GetBytes(data));

            case JCS_CharsetType.UTF32: return(Encoding.UTF32.GetBytes(data));

            case JCS_CharsetType.Unicode: return(Encoding.Unicode.GetBytes(data));

            case JCS_CharsetType.BigEndianUnicode: return(Encoding.BigEndianUnicode.GetBytes(data));
            }
            JCS_Debug.LogError("This shouldn't happens, charset `string to bytes`");
            return(null);
        }
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions
        /// <summary>
        /// Set value according to the GUI type!
        /// </summary>
        private void InitValue()
        {
            switch (mSettingType)
            {
            case JCS_SoundSettingType.NONE:
                JCS_Debug.LogError("Setting with no meaning...");
                return;

            case JCS_SoundSettingType.BGM_SOUND:
                this.mSettingValue = JCS_SoundSettings.instance.GetBGM_Volume();
                break;

            case JCS_SoundSettingType.SFX_SOUND:
                this.mSettingValue = JCS_SoundSettings.instance.GetSFXSound_Volume();
                break;

            case JCS_SoundSettingType.SKILLS_SOUND:
                this.mSettingValue = JCS_SoundSettings.instance.GetSkillsSound_Volume();
                break;
            }
        }
        /// <summary>
        /// Get the tartget's transform position / local position.
        /// </summary>
        private void UpdateTargetPosition()
        {
            if (mTargetTransform == null)
            {
                if (JCS_GameSettings.instance.DEBUG_MODE)
                {
                    JCS_Debug.LogError("Can't set the position without target transform.");
                }
                return;
            }

            if (mUseLocal)
            {
                mTargetPosition = mTargetTransform.localPosition;
            }
            else
            {
                // get the target position.
                mTargetPosition = mTargetTransform.position;
            }
        }
        /// <summary>
        /// Create the clean base gui panel for JCSUnity
        /// and add in under to the canvas.
        ///
        /// Need:
        ///     1) JCS_Canvas
        /// in the scene before create base panel.
        /// </summary>
        private static GameObject CreateBaseGUIPanel()
        {
            JCS_Canvas jcsCanvas = (JCS_Canvas)FindObjectOfType(typeof(JCS_Canvas));

            if (jcsCanvas == null)
            {
                JCS_Debug.Log(
                    "Cannot find the JCS_Canvas in the hierarchy. Plz create the canvas before create the base panel.");

                return(null);
            }

            string     setting_path = "JCSUnity_Resources/GUI/JCS_BasePanel";
            GameObject basePanel    = CreateHierarchyObjectUnderCanvas(setting_path);

            Undo.RegisterCreatedObjectUndo(basePanel, "Create Base GUI Panel");

            basePanel.transform.localScale = Vector3.one;

            return(basePanel);
        }
Exemple #5
0
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// when activate from pool.
        /// </summary>
        public void Execute(string message)
        {
            if (mActive)
            {
                JCS_Debug.LogError(
                    "Call this while the object is still active.");

                return;
            }

            // set the message text
            SetText(message);

            // fade out
            mFadeObject.FadeOut();

            // slide out
            mSlideEffect.Active();

            mActive = true;
        }
        /// <summary>
        /// Merge multiple arrays into one array.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static T[] MergeArrays<T>(params T[][] arrList)
        {
            if (arrList.Length <= 1)
            {
                JCS_Debug.Log("You trying to merge the array less then two array");
            }

            int arrLen = 0;
            foreach (var arr in arrList)
                arrLen += arr.Length;

            // first combine the first two array.
            T[] data = MergeArrays2<T>(arrList[0], arrList[1]);

            // combine the rest.
            for (int index = 2; index < arrList.Length; ++index)
            {
                data = MergeArrays2<T>(data, arrList[index]);
            }
            return data;
        }
Exemple #7
0
        /// <summary>
        /// Update the space to each digit.
        /// </summary>
        /// <param name="interval"> target interval </param>
        public void UpdateIntervalForEachDigit(float interval)
        {
            // update interval
            this.mDigitInterval = interval;

            for (int digit = 0;
                 digit < mDigitsRendererSlot.Length;
                 ++digit)
            {
                if (mDigitsRendererSlot[digit] == null)
                {
                    JCS_Debug.LogError(
                        "Digit slot cannot be null references...");
                    continue;
                }

                Vector3 newPos = mDigitsRendererSlot[digit].LocalPosition;
                newPos.x += -(interval * digit);
                mDigitsRendererSlot[digit].LocalPosition = newPos;
            }
        }
Exemple #8
0
        public static bool GetJoystickKeyByAction(
            JCS_KeyActionType act,
            JCS_JoystickIndex id,
            JCS_JoystickButton key,
            bool ignorePause = false)
        {
            switch (act)
            {
            case JCS_KeyActionType.KEY:
                return(GetJoystickKey(id, key, ignorePause));

            case JCS_KeyActionType.KEY_DOWN:
                return(GetJoystickKeyDown(id, key, ignorePause));

            case JCS_KeyActionType.KEY_UP:
                return(GetJoystickKeyUp(id, key, ignorePause));
            }

            JCS_Debug.LogError("This cannot happed.");
            return(false);
        }
        /// <summary>
        /// Algorithm to do the main action from this event.
        /// </summary>
        public void SpawnObjects()
        {
            Transform spawnTrans = null;

            for (int counter = 0;
                 counter < mObjectsToSpawn;
                 ++counter)
            {
                // get the random object from the list.
                spawnTrans = mObjectList.GetRandomObjectFromList();

                // check if null.
                if (spawnTrans == null)
                {
                    JCS_Debug.LogError(
                        "Spawning object detect that are null references... Could not spawn the object!");

                    break;
                }


                // spawn the object by transform.
                // and get the object which we just spawned.
                spawnTrans = (Transform)JCS_Utility.SpawnGameObject(spawnTrans, this.transform.position);

                // apply random position
                spawnTrans.transform.position = RandTransform(spawnTrans.position);

                // apply random rotation
                spawnTrans.transform.eulerAngles = RandDegree(spawnTrans.eulerAngles);

                JCS_ApplyDamageTextToLiveObjectAction adtaThis    = this.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>();
                JCS_ApplyDamageTextToLiveObjectAction adtaSpawned = spawnTrans.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>();
                if (adtaThis != null && adtaSpawned != null)
                {
                    // copy the apply damage text information to spawned object!
                    adtaSpawned.CopyToThis(adtaThis);
                }
            }
        }
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        /// <summary>
        /// Spawn the text pool base on number of handle.
        /// </summary>
        private void SpawnTextPool()
        {
            if (mLogText == null)
            {
                JCS_Debug.LogReminders(
                    "No log text assign in the text pool...");

                return;
            }


            // NOTE(JenChieh): this might change in
            // the future.
            // Get the log system from the
            // same transfrom/node.
            JCS_IGLogSystem logSystem = this.GetComponent <JCS_IGLogSystem>();


            mLogTexts = new JCS_Vector <JCS_LogText>(mNumberOfHandle);

            for (int count = 0;
                 count < mNumberOfHandle;
                 ++count)
            {
                // spawn a new game object,
                // and get the component
                JCS_LogText logText = (JCS_LogText)JCS_Utility.SpawnGameObject(mLogText);

                // add to array
                mLogTexts.set(count, logText);

                // set parent
                JCS_Utility.SetParentWithoutLosingInfo(logText.transform, this.transform);

                // NOTE(JenChieh): this might change in
                // the future.
                // set the log system if there is one.
                logText.SetIGLogSystem(logSystem);
            }
        }
Exemple #11
0
        /// <summary>
        /// Hide the description dialogue.
        /// </summary>
        public void JCS_HideDescDialogue()
        {
            if (mDescDialogue == null)
            {
                JCS_Debug.LogError("No dialogue object attached...");
                return;
            }

#if (UNITY_STANDALONE || UNITY_EDITOR)
            // is is still on top of the image, return it
            if (JCS_Utility.MouseOverGUI(mRectTransform, mRootPanel))
            {
                return;
            }
#endif

            mDescDialogue.HideDialogueWithoutSound();

#if (UNITY_STANDALONE || UNITY_EDITOR)
            mShowing = false;
#endif
        }
Exemple #12
0
        /// <summary>
        ///
        /// </summary>
        public void AttackSound()
        {
            if (!mOverrideSound)
            {
                // do not override the sound
                if (mJCSSoundPlayer.GetAudioSource().isPlaying)
                {
                    return;
                }
            }

            int rand = Random.Range(0, mAttackSounds.Length);

            if (mAttackSounds[rand] == null)
            {
                JCS_Debug.LogError(
                    "Play sound with null references...");

                return;
            }
            mJCSSoundPlayer.PlayOneShot(mAttackSounds[rand], JCS_SoundSettings.instance.GetSkillsSound_Volume());
        }
        /// <summary>
        /// Decode the buffer by the public key.
        /// </summary>
        /// <param name="message"> buffer to decode. </param>
        /// <returns> decoded message. </returns>
        public System.Object Decode(System.Object message)
        {
            byte[] undecrypted = (byte[])message;

            int packetLength = undecrypted.Length - JCS_NetworkConstant.DECODE_BUFFER_LEN;

            // Check packet length
            if (undecrypted.Length < 0 || undecrypted.Length > JCS_NetworkConstant.INBUFSIZE)
            {
                // TODO(JenChieh): split the packet system
                JCS_Debug.LogError("JCS_PacketDecoder",
                                   "Packet recieved is too big!!!");
                return(null);
            }

            // decrypt packet and check if damaged / wrong packet
            for (int index = 0;
                 index < JCS_NetworkConstant.DECODE_BUFFER_LEN;
                 ++index)
            {
                if ((char)undecrypted[index] != (char)JCS_NetworkConstant.DECODE_BUFFER[index])
                {
                    JCS_Debug.LogError(
                        "Wrong Packet Header!!!");
                    return(null);
                }
            }

            // Get the real message
            byte[] decryptedBuffer = new byte[packetLength];
            for (int index = 0;
                 index < packetLength;
                 ++index)
            {
                decryptedBuffer[index] = undecrypted[index + JCS_NetworkConstant.DECODE_BUFFER_LEN];
            }

            return(decryptedBuffer);
        }
        private void Update()
        {
            // check if action triggered?
            if (!mAction || mTargetTransform == null)
            {
#if (UNITY_EDITOR)
                if (JCS_GameSettings.instance.DEBUG_MODE)
                {
                    JCS_Debug.LogError(
                        "No target found...");
                }
#endif
                return;
            }

            float currentDistance = Vector3.Distance(this.transform.position, mTargetTransform.position);

            if (mFadeEffect)
            {
                if (currentDistance <= mFadeDistance)
                {
                    float alphaDeltaDistance = mFadeDistance - mDestroyDistance;
                    if (mFadeType == FadeType.IN)
                    {
                        mAlphaObject.TargetAlpha = (currentDistance - mDestroyDistance) / alphaDeltaDistance;
                    }
                    else if (mFadeType == FadeType.OUT)
                    {
                        mAlphaObject.TargetAlpha = 1 - (currentDistance - mDestroyDistance) / alphaDeltaDistance;
                    }
                }
            }


            if (currentDistance <= mDestroyDistance)
            {
                Destroy(this.gameObject);
            }
        }
Exemple #15
0
        /// <summary>
        /// Make value approach to the target value by
        /// increment/decrement one.
        /// </summary>
        /// <param name="currentVal"></param>
        /// <param name="targetVal"></param>
        /// <returns></returns>
        public static int ApproachTo(int currentVal, int targetVal)
        {
            if (currentVal == targetVal)
            {
                return(currentVal);
            }

            if (currentVal < targetVal)
            {
                return(++currentVal);
            }

            if (targetVal < currentVal)
            {
                return(--currentVal);
            }

            JCS_Debug.LogError(
                "Errors with approaching to a value...");

            return(0);
        }
Exemple #16
0
        private void LateUpdate()
        {
            mLastFramePosition = this.transform.position;

            if (mHitLeft && VelX < 0)
            {
                VelX = 0;
            }
            else if (mHitRight && VelX > 0)
            {
                VelX = 0;
            }

#if (UNITY_EDITOR)
            // draw the collider each frame.
            JCS_Debug.DrawCollider(mBoxCollider2d, Color.cyan);
            JCS_Debug.DrawCollider(mBoxCollider2d, Color.blue, mLastFrameColliderPosition);
#endif

            // record down the last frame's collider's position
            mLastFrameColliderPosition = JCS_Physics.GetColliderPosition(mBoxCollider2d);
        }
        /// <summary>
        /// Update second interval.
        /// </summary>
        public void UpdateSecondInterval()
        {
            if (mDigitSecond1 == null || mDigitSecond2 == null)
            {
                JCS_Debug.LogError("Digit slot cannot be null references");
                return;
            }

            float unitInterval = (mDigitUnitInterval * 0);

            Vector3 newPos = mDigitSecond1.transform.localPosition;

            newPos.x += -(mDigitInterval * 0) - unitInterval;
            mDigitSecond1.transform.localPosition = newPos;

            newPos    = mDigitSecond2.transform.localPosition;
            newPos.x += -(mDigitInterval * 1) - unitInterval;
            mDigitSecond2.transform.localPosition = newPos;

            // record down the last digit's localPosition.
            mLastInterval = newPos.x;
        }
Exemple #18
0
        /// <summary>
        /// Fade out the sound.
        /// </summary>
        /// <param name="target_volume"></param>
        /// <param name="time"></param>
        public void FadeOut(float target_volume, float time)
        {
            if (mType == JCS_FadeType.FADE_OUT)
            {
                JCS_Debug.LogError("Already fade out");
                return;
            }

            if (mAudioSource == null)
            {
                JCS_Debug.LogError("Can't do the fade out effect without audio source");
                return;
            }

            SetFadeOutTime(time);

            mTargetVolume = target_volume;
            mRecordVolume = mAudioSource.volume;

            mType   = JCS_FadeType.FADE_OUT;
            mEffect = true;
        }
Exemple #19
0
        /// <summary>
        /// 使用於 如果已經計算好公式了!
        /// </summary>
        /// <param name="attacker"> Attacker </param>
        /// <param name="damages"> sequence of damage </param>
        /// <param name="pos"> damage text position </param>
        /// <param name="criticalChance"> chance of spawning red text </param>
        public void ApplyDamageText(
            Transform attacker,
            int[] damages,
            Vector2 pos,
            int criticalChance,
            AudioClip hitSound = null)
        {
            // set the last attack in the safe way.
            SetLastAttacker(attacker);

            // Damage text version
            if (mDamageTextEffect)
            {
                JCS_MixDamageTextPool mixTP = JCS_UtilitiesManager.instance.GetMixDamageTextPool();
                if (mixTP == null)
                {
                    JCS_Debug.LogError(
                        "There is no Mix Damage Text Pool in the scene. Consider to grab one?");
                    return;
                }

                // spawn the damage text
                mixTP.DamageTextSpawnerSimple(
                    damages,
                    pos,
                    criticalChance,
                    IsPlayer,
                    hitSound);
            }
            // Do damage without damage text.
            else
            {
                // no need to do anything cuz is
                // pre-calculate already.
            }

            ReceiveDamage(damages, attacker);
        }
Exemple #20
0
        /// <summary>
        /// Helper function to spawn the damaget text
        /// so scripter will not have to do all the drug code over and
        /// over agian!
        /// </summary>
        /// <param name="minDamage"> minimum of damage we produce </param>
        /// <param name="maxDamage"> maximum of damage we produce </param>
        /// <param name="pos"> position of damage text we spawn </param>
        /// <param name="hit"> how many damage text we spawn </param>
        /// <returns> data we produced </returns>
        public int[] DamageTextSpawnerSimple(
            int minDamage,
            int maxDamage,
            Vector3 pos,
            int hit,
            AudioClip hitSound = null)
        {
            if (minDamage > maxDamage)
            {
                JCS_Debug.LogError("Min damage cannot be higher or equal to the max damage!");
                return(null);
            }

            if (minDamage < 0 || maxDamage < 0)
            {
                JCS_Debug.LogError("Min or Max damage cannot be lower than 0!");
                return(null);
            }

            if (hit <= 0)
            {
                JCS_Debug.LogError("Hit count should not be equal or lower than 0!");
                return(null);
            }

            int[] damages = new int[hit];

            for (int index = 0; index < hit; ++index)
            {
                int dm = Random.Range(minDamage, maxDamage);
                damages[index] = dm;
            }

            SpawnDamagetTexts(damages, pos, hitSound);

            // return the damages we just create!
            return(damages);
        }
Exemple #21
0
        /// <summary>
        /// Spawn the main animattion 2.
        /// </summary>
        protected void SpawnMainAnim2()
        {
            if (mMainAnim2 == null)
            {
                JCS_Debug.LogReminder(
                    "Assigning active skill action without animation is not allowed.");

                return;
            }

            GameObject obj = JCS_Utility.SpawnAnimateObject(mMainAnim2, mOrderLayer + 1);

            if (mSamePosition)
            {
                obj.transform.position = this.transform.position + mAnimPosOffset2;
            }
            if (mSameRotation)
            {
                obj.transform.rotation = this.transform.rotation;
            }
            if (mSameScale)
            {
                obj.transform.localScale = this.transform.localScale;
            }

            // if stay with player, simple set the position to
            // same position and set to child so it will follows
            // the active target!
            if (mStayWithActiveTarget)
            {
                obj.transform.SetParent(this.transform);
            }


            // add anim death event,
            // so when animation ends destroy itself.
            obj.AddComponent <JCS_DestroyAnimEndEvent>();
        }
        /// <summary>
        /// Fade in the sound.
        /// </summary>
        /// <param name="target_volume"></param>
        /// <param name="time"></param>
        public void FadeIn(float target_volume, float time)
        {
            if (mType == JCS_FadeType.FADE_IN)
            {
                JCS_Debug.LogError("Already Fade in...");
                return;
            }

            if (mAudioSource == null)
            {
                JCS_Debug.LogError("Cannot do the fade in effect without the source...");
                return;
            }

            SetFadeInTime(time);

            mAudioSource.volume = 0;
            mTargetVolume       = target_volume;
            mRecordVolume       = target_volume;

            mType   = JCS_FadeType.FADE_IN;
            mEffect = true;
        }
Exemple #23
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        //////////// 2D //////////////////////////

        /// <summary>
        /// Iniialize the camera.
        /// </summary>
        private void InitCamera()
        {
            if (mJCS_2DCamera == null)
            {
                JCS_Debug.LogError("There is not JCS_2DCamera attach to, spawn a default one!");

                // Spawn a Default one!
                this.mJCS_2DCamera = JCS_Utility.SpawnGameObject(
                    JCS_2DCamera.JCS_2DCAMERA_PATH,
                    transform.position,
                    transform.rotation).GetComponent <JCS_2DCamera>();
            }

            // if still null, setting error!!
            if (mJCS_2DCamera == null)
            {
                JCS_Debug.LogError("The object spawn does not have the \"JCS_2DCamera\" components...");
                return;
            }

            // set target to follow!
            mJCS_2DCamera.SetFollowTarget(this.transform);
        }
Exemple #24
0
        private IEnumerator GetData()
        {
            UnityWebRequest www = UnityWebRequest.Get(requestURL);

            yield return(www.SendWebRequest());

            bool success = false;

#if UNITY_2021_1_OR_NEWER
            if (www.result == UnityWebRequest.Result.ConnectionError ||
                www.result == UnityWebRequest.Result.ProtocolError)
#else
            if (www.isNetworkError || www.isHttpError)
#endif
            {
                if (JCS_GameSettings.instance.DEBUG_MODE)
                {
                    JCS_Debug.LogWarning(www.error);
                }
            }
            else
            {
                mResultData = www.downloadHandler.data;
                WriteFileAsCache(requestPath, mResultData);

                success = true;
            }

            if (requestCallback != null)
            {
                requestCallback.Invoke(requestPath, success);
            }
            requestCallback = null;

            downloadList.Remove(requestPath);
            requesting = false;
        }
Exemple #25
0
        /// <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;
                    }
                }
            }
        }
Exemple #26
0
        /// <summary>
        /// Create new linked node object by N count.
        /// </summary>
        /// <param name="n"> Number of linked object to create. </param>
        /// <param name="startIndex"> Starting index to create. </param>
        /// <returns> List of created linked object. </returns>
        public List <JCS_TransformLinkedObject> NewLinked(int n = 1, int startIndex = 0)
        {
            if (mClone == null)
            {
                JCS_Debug.LogReminder("Can't create new linked node without the clone");
                return(null);
            }

            if (n <= 0)
            {
                JCS_Debug.LogReminder("Can't create new linked node N lower than 1");
                return(null);
            }

            var lst = new List <JCS_TransformLinkedObject>();

            int maxIndex = startIndex + n;

            for (int index = startIndex; index < maxIndex; ++index)
            {
                var newNode = JCS_Utility.SpawnGameObject(mClone) as JCS_TransformLinkedObject;

                // Set to it centers.
                {
                    newNode.transform.SetParent(this.transform);
                    newNode.transform.localPosition = Vector3.zero;
                    newNode.transform.localScale    = Vector3.one;
                }

                lst.Add(newNode);
                mManagedList.Insert(index, newNode);
            }

            OrganizedLinked();

            return(lst);
        }
        /// <summary>
        /// Send a choice to current status.
        /// </summary>
        /// <param name="index"> index of the selection call. </param>
        /// <param name="msg"> message display in textbox </param>
        public void SendChoice(int index, string msg)
        {
            if (mSelectBtn.Length <= index)
            {
                JCS_Debug.LogWarning("Select button call is out of range");
                return;
            }

            if (mSelectBtn[index] == null)
            {
                JCS_Debug.LogWarning("There are space in the array but does no assign the value");
                return;
            }

            // set the text to the button.
            mSelectMessage[index] = msg;

            // active the button.
            SelectBtnActive(index, true);

            // Reset button selection group to make the selection
            // pointer/effect to the first selection!
            ResetButtonSelectionGroup();
        }
        //========================================
        //      Unity's function
        //------------------------------
        protected override void Awake()
        {
            base.Awake();

            // record down the position
            mRectTransform = this.GetComponent <RectTransform>();

            if (mMask == null)
            {
                JCS_Debug.LogError("No mask applied...");
                return;
            }

            this.transform.SetParent(mMask.transform);
            mMaskRectTransform = this.mMask.GetComponent <RectTransform>();

            mMaskTargetPosition = this.mMaskRectTransform.localPosition;

            // min value cannot be lower or equal to max value
            if (mMinValue >= mMaxValue)
            {
                mMinValue = mMaxValue + 1;  // force min < max value
            }
        }
Exemple #29
0
        /// <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.JCS_OnMouseOver();
                }
            }
        }
Exemple #30
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        /// <summary>
        /// Initilaize the buttons in the array.
        /// </summary>
        private void InitButton()
        {
            JCS_RollSelectorButton currentBtn = null;
            int indexCounter = 0;

            JCS_RollSelectorButton[] buttons = new JCS_RollSelectorButton[mButtons.Length];

            for (int index = 0;
                 index < mButtons.Length;
                 ++index)
            {
                currentBtn = mButtons[index];

                if (currentBtn == null)
                {
                    JCS_Debug.LogError(
                        "Missing jcs_button assign in the inspector...");
                    continue;
                }

                // set to array object to know this handler.
                currentBtn.SetRollSelector(this);


                Vector3 newPos = this.transform.localPosition;

                bool isEven = JCS_Mathf.IsEven(index);

                if (index != 0)
                {
                    currentBtn.SetInteractable(false);
                }
                else
                {
                    // the first one (center)
                    mFocusBtn = currentBtn;
                    JCS_Utility.MoveToTheLastChild(mFocusBtn.transform);
                    currentBtn.SetInteractable(true);
                    mLastScrollIndex = currentBtn.ScrollIndex;
                }

                if (!isEven)
                {
                    ++indexCounter;
                }

                float intervalDistance = mSpacing * indexCounter;

                switch (mDimension)
                {
                case JCS_2DDimensions.VERTICAL:
                {
                    if (mPanelRoot != null)
                    {
                        intervalDistance /= mPanelRoot.PanelDeltaWidthRatio;
                    }

                    if (isEven)
                    {
                        newPos.y += intervalDistance;
                    }
                    else
                    {
                        newPos.y -= intervalDistance;
                    }
                }
                break;

                case JCS_2DDimensions.HORIZONTAL:
                {
                    if (mPanelRoot != null)
                    {
                        intervalDistance /= mPanelRoot.PanelDeltaHeightRatio;
                    }

                    if (isEven)
                    {
                        newPos.x += intervalDistance;
                    }
                    else
                    {
                        newPos.x -= intervalDistance;
                    }
                }
                break;
                }

                currentBtn.GetRectTransfom().localPosition = newPos;

                // set friction.
                currentBtn.SimpleTrackAction.Friction = mScrollFriction;
                // set tracking
                currentBtn.SetTrackPosition();

                // get the correct order
                int correctIndex = 0;

                if (isEven)
                {
                    correctIndex = ((mButtons.Length - 1) - index) / 2;
                }
                else
                {
                    correctIndex = ((mButtons.Length) + index) / 2;
                }

                buttons[correctIndex] = currentBtn;
            }

            mButtons = buttons;

            // initialzie the scroll index.
            for (int index = 0;
                 index < mButtons.Length;
                 ++index)
            {
                currentBtn = mButtons[index];

                // set index.
                currentBtn.ScrollIndex = index;
            }
        }