All the utility function put here.
        /// <summary>
        /// Initialize damage text to the array.
        /// </summary>
        private void InitDamageTextToArray()
        {
            mDamageTexts = new JCS_Vector <JCS_DamageText>(mNumberOfHandle);

            if (mDamageText == null)
            {
                return;
            }

            for (int count = 0; count < mNumberOfHandle; ++count)
            {
                // spawn a new game object,
                // and get the component
                JCS_DamageText dt = JCS_Util.SpawnGameObject(
                    mDamageText,
                    mDamageText.transform.position,
                    mDamageText.transform.rotation) as JCS_DamageText;

                // add to array
                mDamageTexts.set(count, dt);

                // set parent
                dt.transform.SetParent(this.transform);
            }
        }
        /// <summary>
        /// Spawn all particle base on the count.
        /// </summary>
        public void SpawnParticles()
        {
            // check if particles already spawned?
            if (mParticleSpawned)
            {
                return;
            }

            if (mParticle == null)
            {
                JCS_Debug.Log(
                    "No particle assign!");
                return;
            }

            for (int index = 0;
                 index < mNumOfParticle;
                 ++index)
            {
                JCS_Particle trans = (JCS_Particle)JCS_Util.SpawnGameObject(mParticle);
                mParticles.push(trans);

                // disable the object
                trans.gameObject.SetActive(false);

                if (mSetChild)
                {
                    // set parent
                    trans.transform.SetParent(this.transform);
                }
            }

            mParticleSpawned = true;
        }
Example #3
0
        /// <summary>
        /// Initialize the focus selector.
        /// </summary>
        /// <param name="rbs"></param>
        public void SetFocusSelector(JCS_RollSelectorButton rbs)
        {
            // if still animating disabled.
            if (mAnimating)
            {
                return;
            }

            // record down the last focus buttons index.
            mLastScrollIndex = mFocusBtn.ScrollIndex;

            // assign new focus button!
            this.mFocusBtn = rbs;

            foreach (JCS_RollSelectorButton btn in mButtons)
            {
                btn.SetInteractable(false);
            }

            // only enable this
            mFocusBtn.SetInteractable(true);

            // show in front.
            JCS_Util.MoveToTheLastChild(mFocusBtn.transform);

            // Active anim, so can set the focused button to center.
            FindScrollIndex();
        }
        /* Functions */

        private void Awake()
        {
            this.mEventTrigger = this.GetComponent <EventTrigger>();
            this.mButton       = this.GetComponent <Button>();
            this.mJCS_Button   = this.GetComponent <JCS_Button>();

            // Try find it.
            if (this.mText == null)
            {
                this.mText = this.GetComponentInChildren <Text>();
            }

            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerEnter,
                                          OnPointerEnter);
            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerExit,
                                          OnPointerExit);
            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerDown,
                                          OnPointerDown);
            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerUp,
                                          OnPointerUp);

            // Initialize the first color.
            if (IsButtonInteractable())
            {
                mText.color = mNormalColor;
            }
            else
            {
                mText.color = mDisabledColor;
            }
        }
        /* Functions */

        protected void Awake()
        {
            mTargetList = new JCS_Vector <JCS_Player>();

            mAudioListener = this.GetComponent <AudioListener>();

            // find the camera in the scene first
            mJCS_2DCamera = (JCS_2DCamera)FindObjectOfType(typeof(JCS_2DCamera));

            // if still null spawn a default one!
            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_Util.SpawnGameObject(
                    JCS_2DCamera.JCS_2DCAMERA_PATH,
                    transform.position,
                    transform.rotation).GetComponent <JCS_2DCamera>();
            }

            mJCS_2DCamera.SetFollowTarget(this.transform);

            // record down the fild of view
            mTargetFieldOfView = mJCS_2DCamera.fieldOfView;
        }
        /// <summary>
        ///
        /// </summary>
        private void DoAbsorbEffect()
        {
            if (mAbsorbEffect)
            {
                mAbsorbEffectTimer += Time.deltaTime;

                if (mTimeToAbsorb < mAbsorbEffectTimer)
                {
                    // start the effect
                    mGoStraightAction.MoveSpeed += (0.1f - mGoStraightAction.MoveSpeed) / mTimeToAbsorb * Time.deltaTime;

                    if (JCS_Util.WithInRange(-mAcceptTimeRange, mAcceptTimeRange, mGoStraightAction.MoveSpeed))
                    {
                        //mGoStraightAction.MoveSpeed = mRecordMoveSpeed;

                        // end the effect.
                        mAbsorbEffect = false;
                    }
                }
            }
            else
            {
                mGoStraightAction.MoveSpeed += (mRecordMoveSpeed - mGoStraightAction.MoveSpeed) / mAbsorbBackFriction * Time.deltaTime;
            }
        }
        /// <summary>
        /// Input setting for XBox 360's gamepad.
        /// </summary>
        public static void SetupXBox360Joystick()
        {
            float defalutSenstivity = JCS_InputSettings.DEFAULT_SENSITIVITY;
            float defaultDead       = JCS_InputSettings.DEFAULT_DEAD;
            float defaultGravity    = JCS_InputSettings.DEFAULT_GRAVITY;

            for (int joystickNum = 0; joystickNum < GAMEPAD_COUNT; ++joystickNum)
            {
                foreach (JCS_JoystickButton val in JCS_Util.GetValues <JCS_JoystickButton>())
                {
                    if (val == JCS_JoystickButton.NONE)
                    {
                        continue;
                    }

                    // add axis definition.
                    AddAxis(new InputAxis()
                    {
                        name           = JCS_InputSettings.GetJoystickButtonIdName(joystickNum, val),
                        positiveButton = JCS_InputSettings.GetPositiveNameByLabel(val),
                        dead           = defaultDead,
                        gravity        = defaultGravity,
                        sensitivity    = defalutSenstivity,
                        type           = JCS_InputSettings.GetAxisType(val),
                        invert         = JCS_InputSettings.IsInvert(val),
                        axis           = (int)JCS_InputSettings.GetAxisChannel(val),
                        joyNum         = joystickNum,
                    });
                }
            }
        }
        /// <summary>
        /// Active the skill.
        /// </summary>
        public void ActiveSkill()
        {
            if (mSkillAnim == null)
            {
                JCS_Debug.LogReminder(
                    "Assigning active skill action without animation is not allowed.");

                return;
            }

            GameObject obj = JCS_Util.SpawnAnimateObject(mSkillAnim, mOrderLayer);

            if (mSamePosition)
            {
                obj.transform.position = this.transform.position;
            }
            if (mSameRotation)
            {
                obj.transform.rotation = this.transform.rotation;
            }

            // 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>
        /// Spawn a support animation.
        /// </summary>
        private void SpawnSupAnim()
        {
            for (int index = 0;
                 index < mAnimDesity;
                 ++index)
            {
                // get a random animate from pool
                RuntimeAnimatorController anim = mAnimPoolSupAnim.GetRandomAnim();

                GameObject obj = JCS_Util.SpawnAnimateObjectDeathEvent(anim, mOrderLayer);

#if (UNITY_EDITOR)
                obj.name = "JCS_2DFullScreenAtkAction";
#endif

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

                AddHitSound(ref obj);
                SetToRandomPos(ref obj);
            }
        }
Example #10
0
        /// <summary>
        /// Move the last child of the current child will make the
        /// panel in front of any other GUI in the current panel.
        /// </summary>
        public void MoveToTheLastChild()
        {
            JCS_Util.MoveToTheLastChild(this.transform);

            // Once it move to the last child, meaning the window have been focus.
            SwapToTheLastOpenWindowList();
        }
        private void Start()
        {
            // pop the fade screen.
            string path = JCS_UISettings.FADE_SCREEN_PATH;

            this.mFadeScreen = JCS_Util.SpawnGameObject(path).GetComponent <JCS_FadeScreen>();
        }
Example #12
0
        /* Functions */

        private void Start()
        {
            // Only need it for the UI.
            if (GetObjectType() == JCS_UnityObjectType.UI ||
                GetObjectType() == JCS_UnityObjectType.TEXT)
            {
                // Get panel root, in order to calculate the correct distance
                // base on the resolution.
                mPanelRoot = this.GetComponentInParent <JCS_PanelRoot>();

                if (mAutoAddEvent)
                {
                    // Event trigger is the must if we need to add the
                    // event to event trigger system.
                    {
                        this.mEventTrigger = this.GetComponent <EventTrigger>();
                        if (this.mEventTrigger == null)
                        {
                            this.mEventTrigger = this.gameObject.AddComponent <EventTrigger>();
                        }
                    }

                    JCS_Util.AddEventTriggerEvent(mEventTrigger, mActiveEventTriggerType, JCS_OnMouseOver);
                    JCS_Util.AddEventTriggerEvent(mEventTrigger, mDeactiveEventTriggerType, JCS_OnMouseExit);
                }
            }

            Vector3 currentScale = this.transform.localScale;

            // record down the scale.
            mRecordScale = currentScale;
            mTargetScale = currentScale;

            SetTargetScale();
        }
Example #13
0
        /// <summary>
        /// Show the resize panel, for debugging usage.
        /// </summary>
        public void ShowResizePanel()
        {
            if (mImage == null)
            {
                mImage = JCS_Util.ForceGetComponent <Image>(this);
            }
            else
            {
                if (mShowResizePanel && mImage.enabled)
                {
                    return;
                }
            }

            // Show it.
            mImage.enabled = true;

            // Set image. Just a white sprite!
            mImage.sprite = mImageSprite;

            // Set color.
            mImage.color = mResizePanelColor;

            mShowResizePanel = true;
        }
        /// <summary>
        /// Remove linked node from the managed list.
        /// </summary>
        /// <param name="n"> Number of linked object to remove. </param>
        /// <param name="startIndex"> Starting index to remove. </param>
        /// <returns> List of removed linked object. </returns>
        public List <JCS_TransformLinkedObject> RemoveLinked(int n = 1, int startIndex = 0)
        {
            if (!JCS_Util.WithInArrayRange(startIndex, mManagedList))
            {
                JCS_Debug.LogReminder("Can't remove linked node with index lower than 0");
                return(null);
            }

            var lst = new List <JCS_TransformLinkedObject>();

            int        maxIndex = startIndex + n;
            List <int> ids      = new List <int>();

            for (int index = startIndex; index < mManagedList.Count && index < maxIndex; ++index)
            {
                JCS_TransformLinkedObject node = mManagedList[index];

                ids.Add(index); // First record it down.
                lst.Add(node);  // Added to the remove list, and ready to return.
            }

            for (int index = 0; index < ids.Count; ++index)
            {
                int id = ids[index];

                JCS_TransformLinkedObject node = mManagedList[id];
                Destroy(node.gameObject);

                mManagedList.RemoveAt(id);
            }

            OrganizedLinked();

            return(lst);
        }
Example #15
0
        /// <summary>
        /// Source: http://wiki.unity3d.com/index.php?title=LookAtMouse
        /// </summary>
        private void LookAtMouse()
        {
            float speed = 10;

            Vector3 direction = JCS_Util.VectorDirection(mDirection);

            // Generate a plane that intersects the transform's position with an upwards normal.
            Plane playerPlane = new Plane(direction, mShootAction.SpawnPoint.position);

            // Generate a ray from the cursor position
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            // Determine the point where the cursor ray intersects the plane.
            // This will be the point that the object must look towards to be looking at the mouse.
            // Raycasting to a Plane object only gives us a distance, so we'll have to take the distance,
            //   then find the point along that ray that meets that distance.  This will be the point
            //   to look at.
            float hitdist = 0.0f;

            // If the ray is parallel to the plane, Raycast will return false.
            if (playerPlane.Raycast(ray, out hitdist))
            {
                // Get the point along the ray that hits the calculated distance.
                Vector3 targetPoint = ray.GetPoint(hitdist);

                // Determine the target rotation.  This is the rotation if the transform looks at the target point.
                Quaternion targetRotation = Quaternion.LookRotation(targetPoint - mShootAction.SpawnPoint.position);

                // Smoothly rotate towards the target point.
                mShootAction.SpawnPoint.rotation = Quaternion.Slerp(mShootAction.SpawnPoint.rotation, targetRotation, speed * Time.deltaTime);
            }
        }
 /// <summary>
 /// Refresh all languages text in game.
 /// </summary>
 public void RefreshLangTexts()
 {
     this.mLangTexts = JCS_Util.RemoveEmptySlotIncludeMissing(this.mLangTexts);
     foreach (JCS_LangText txt in mLangTexts)
     {
         txt.Refresh();
     }
 }
        /* Functions */

        private void Awake()
        {
            /* Down compatible. */
            this.mSpriteRenderer = this.GetComponent <SpriteRenderer>();

            // clean up empty slot.
            mSpriteRenderers = JCS_Util.RemoveEmptySlot <SpriteRenderer>(mSpriteRenderers);
        }
Example #18
0
        private void Start()
        {
            // everytime it reload the scene.
            // move to the last child make sure everything get cover by this.
            JCS_Util.MoveToTheLastChild(this.transform);

            this.mStartingPosition = this.transform.localPosition;
        }
 /// <summary>
 /// Iterate through children and move them all to the last child
 /// once so the rendering order is preserved.
 /// </summary>
 private void ReorderChildren()
 {
     for (int count = 0; count < mRectTransform.childCount; ++count)
     {
         var trans = mRectTransform.GetChild(count);
         JCS_Util.MoveToTheLastChild(trans);
     }
 }
Example #20
0
        /// <summary>
        /// Last screenshot image's file index.
        /// </summary>
        public static int LastImageFileIndex()
        {
            var gs     = JCS_GameSettings.instance;
            var prefix = gs.SCREENSHOT_FILENAME;
            var ext    = gs.SCREENSHOT_EXTENSION;

            return(JCS_Util.LastFileIndex(SavePath(), prefix, ext));
        }
        /* Setter & Getter */

        /* Functions */

        private void Awake()
        {
            instance = this;

            // get all the scene layer in the scene.
            // so it could be manage
            mJCSOrderLayer = JCS_Util.FindObjectsOfTypeAllInHierarchy <JCS_OrderLayer>();
        }
Example #22
0
        /// <summary>
        /// Apply SPRITE to all indicator's image containers.
        /// </summary>
        /// <param name="sprite"> The sprite to apply. </param>
        private void SetSprite(Sprite sprite)
        {
            this.mIndicators = JCS_Util.RemoveEmptySlotIncludeMissing(this.mIndicators);

            foreach (Image ind in mIndicators)
            {
                ind.sprite = sprite;
            }
        }
        /// <summary>
        /// Decide what item to drop base on
        /// the array list we have!
        /// </summary>
        /// <returns> item to drop. </returns>
        private JCS_Item ItemDropped()
        {
            JCS_Item item = null;

            float totalChance = 0;

            // add all possiblity chance together.
            for (int index = 0; index < mItemSet.Length; ++index)
            {
                totalChance += mItemSet[index].dropRate;
            }

            float dropIndex = JCS_Random.Range(0, totalChance + 1);

            float accumMaxDropRate = 0;
            float accumMinDropRate = 0;

            for (int index = 0; index < mItemSet.Length; ++index)
            {
                accumMaxDropRate += mItemSet[index].dropRate;

                if (index == 0)
                {
                    if (JCS_Util.WithInRange(0, mItemSet[0].dropRate, dropIndex))
                    {
                        item = mItemSet[0].item;
                        break;
                    }

                    continue;
                }

                // 比如: 10, 20, 30, 40

                // Loop 1: 0 ~ 10
                // Loop 2: 20(30-10) ~ 30
                // Loop 3: 30(60-30) ~ 60
                // Loop 4: 40(100-60) ~ 100     每個都減掉上一個的Drop Rate!
                if (JCS_Util.WithInRange(accumMinDropRate, accumMaxDropRate, dropIndex))
                {
                    item = mItemSet[index].item;
                    break;
                }

                accumMinDropRate += mItemSet[index].dropRate;
            }

            // meaning the last one.
            if (item == null &&
                mItemSet.Length != 0 &&
                mItemSet[mItemSet.Length - 1].dropRate != 0)
            {
                item = mItemSet[mItemSet.Length - 1].item;
            }

            return(item);
        }
Example #24
0
        /* Functions */

        private void Awake()
        {
            if (mTextContainer == null)
            {
                mTextContainer = this.GetComponentInChildren <Text>();
            }

            mDistanceTileAction = JCS_Util.ForceGetComponent <JCS_3DDistanceTileAction>(mTextContainer);
        }
Example #25
0
        /* Functions */

        protected override void Awake()
        {
            base.Awake();

            // get all function pointer/formula.
            this.mEasingRed   = JCS_Util.GetEasing(mEaseTypeR);
            this.mEasingGreen = JCS_Util.GetEasing(mEaseTypeG);
            this.mEasingBlue  = JCS_Util.GetEasing(mEaseTypeB);
            this.mEasingAlpha = JCS_Util.GetEasing(mEaseTypeA);
        }
Example #26
0
        /**
         * Utils
         */

        /// <summary>
        /// Create the Game Object during editing time.
        /// </summary>
        /// <returns></returns>
        private static GameObject CreateHierarchyObject(string settingPath)
        {
            // spawn the game object.
            GameObject hierarchyObj = JCS_Util.SpawnGameObject(settingPath);

            // take away clone sign.
            hierarchyObj.name = hierarchyObj.name.Replace("(Clone)", "");

            return(hierarchyObj);
        }
        //** In Game Dialogue (Game Layer)

        /// <summary>
        /// Spawn the setting dialogue.
        /// </summary>
        public static void PopSettingDialogue()
        {
            if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.PLAYER_DIALOGUE))
            {
                return;
            }

            JCS_Util.SpawnGameObject(SETTING_PANEL);

            //PauseGame(true);
        }
Example #28
0
        /* Setter & Getter */

        /* Functions */

        private void Awake()
        {
            SpriteRenderer sp = this.GetComponent <SpriteRenderer>();

            Vector2 spriteRect = JCS_Util.GetSpriteRendererRectWithNoScale(sp);

            mWidth  = spriteRect.x;
            mHeight = spriteRect.y;

            mOriginPosition = this.transform.position;
        }
Example #29
0
        /// <summary>
        /// Re-order all the object.
        /// </summary>
        /// <param name="arr"> sorted object. </param>
        private void OriganizeChildOrder(JCS_GUIComponentLayer[] arr)
        {
            for (int index = 0; index < arr.Length; ++index)
            {
                // this will make gui ontop of each other.
                JCS_Util.MoveToTheLastChild(arr[index].transform);

                // make sure is sorted already.
                arr[index].Sorted = true;
            }
        }
        /// <summary>
        /// Spawn the talke dialogue.
        /// </summary>
        public static void PopTalkDialogue()
        {
            if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.PLAYER_DIALOGUE))
            {
                return;
            }

            JCS_Util.SpawnGameObject(TALK_DIALOGUE);

            PauseGame(true);
        }