Esempio n. 1
0
        /// <summary>
        /// Set the marquee text and replay from start.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="loop"></param>
        public void SetText(string msg, bool loop = true)
        {
            if (mTextContainer == null)
            {
                JCS_Debug.Log("Can't display the marquee text without text container");
                return;
            }

            this.mTextContainer.text = msg;

            if (!loop)
            {
                mDistanceTileAction.afterResetCallback = () =>
                {
                    mDistanceTileAction.Active = false;
                };
            }
            else
            {
                mDistanceTileAction.afterResetCallback = null;
                mDistanceTileAction.Active             = true;
            }

            mDistanceTileAction.ResetPosition();
        }
Esempio n. 2
0
        /* Variables */

        /* Setter & Getter */

        /* Functions */

        /// <summary>
        /// Initialize the whole application. (In Unity layer.)
        /// </summary>
        /// <returns></returns>
        public static bool InitializeApplication()
        {
            if (!JCS_NetworkSettings.instance.ONLINE_MODE)
            {
                return(false);
            }

            JCS_Debug.Log("Online Mode is enabled");

            // Create Connection
            if (!JCS_NetworkSettings.CreateNetwork(
                    JCS_NetworkSettings.instance.HOST_NAME,
                    JCS_NetworkSettings.instance.PORT,
                    JCS_NetworkSettings.GetPresetClientHandler()))
            {
                // Faild handle
                return(false);
            }

            // Create keys
            JCS_NetworkManager.CreateKey();

            // 這裡無法判別
            return(true);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        /// <summary>
        /// Merging two list and return the new list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lists"></param>
        /// <returns></returns>
        public static List <T> MergeList <T>(params List <T>[] lists)
        {
            if (lists.Length <= 1)
            {
                JCS_Debug.Log(
                    "You trying to merge the List less then two array?");
            }

            List <T> newList = new List <T>();

            for (int index = 0;
                 index < lists.Length;
                 ++index)
            {
                // Loop through all list.
                List <T> list = lists[index];

                if (list == null)
                {
                    continue;
                }

                for (int listIndex = 0;
                     listIndex < list.Count;
                     ++listIndex)
                {
                    // Loop through item.
                    T item = list[listIndex];

                    newList.Add(item);
                }
            }

            return(newList);
        }
        /// <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;
        }
Esempio n. 6
0
        /// <summary>
        /// Callback when message received.
        /// </summary>
        /// <param name="buffer"> buffer we received. </param>
        public void MessageReceived(byte[] buffer)
        {
            // convert byte array to stream
            Stream stream = new MemoryStream(buffer);

            // using byte reader for the stream.
            BinaryReader     br    = new BinaryReader(stream);
            JCS_BinaryReader jcsbr = new JCS_BinaryReader(br);

            short packetId = jcsbr.ReadShort();

            /**
             * NOTE(jenchieh): packet responded does not need a handler
             * to handle to response. I think is good if we have it inside
             * check if the packet get handler, but I think is easier if
             * just want to check if the packet responded or not. So I
             * decide to have this function here instead inside the
             * packet handler check under.
             */
            // packet responded!
            JCS_PacketLostPreventer.instance.AddRespondPacketId(packetId);

            JCS_Client client = JCS_ClientManager.LOCAL_CLIENT;

            if (IsPacketOutdated(jcsbr, client, packetId))
            {
                return;
            }

            // handler depends on the client/server mode.
            JCS_PacketHandler packetHandler =
                JCS_DefaultPacketProcessor.GetProcessor(
                    JCS_NetworkSettings.instance.CLIENT_MODE
                    ).GetHandler(packetId);

            if (packetHandler != null && packetHandler.validateState(client))
            {
                // set the client and packet data buffer sequence.
                packetHandler.Client     = client;
                packetHandler.PacketData = jcsbr;

                // register request.
                JCS_ServerRequestProcessor.instance.RegisterRequest(packetHandler.handlePacket, jcsbr, client);
            }
            else
            {
                if (packetHandler == null)
                {
                    JCS_Debug.Log("Exception during processing packet: null");
                }
                else
                {
                    JCS_Debug.Log("Exception during processing packet: " + packetHandler);
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Reward example function. Your function should be
 /// similar to this.
 /// </summary>
 /// <param name="result"> result for the reward video? </param>
 private void OnRewardAdWatched(ShowResult result)
 {
     if (result == ShowResult.Failed)
     {
         JCS_Debug.Log(this, "Reward Ads video get Failed.");
     }
     else if (result == ShowResult.Finished)
     {
         JCS_Debug.Log(this, "Reward Ads video get Finished.");
     }
     else if (result == ShowResult.Skipped)
     {
         JCS_Debug.Log(this, "Reward Ads video get Skipped.");
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Get the selection depends on the direction.
        /// </summary>
        /// <param name="bs"> Button Selection object to use to find out the actual button selection. </param>
        /// <param name="direction"> Target direction. </param>
        /// <returns>
        /// Button selection in target button selection's up/down/right/left button selection.
        /// </returns>
        public JCS_ButtonSelection GetButtonSelectionByDirection(JCS_ButtonSelection bs, Direction direction)
        {
            switch (direction)
            {
            case Direction.UP: return(bs.UpSelection);

            case Direction.DOWN: return(bs.DownSelection);

            case Direction.RIGHT: return(bs.RightSelection);

            case Direction.LEFT: return(bs.LeftSelection);
            }

            JCS_Debug.Log("Failed to get button selection by direction, this should not happens...");
            return(null);
        }
Esempio n. 9
0
        /// <summary>
        /// Save the game data into binary file format.
        /// </summary>
        /// <typeparam name="T"> type of the data save. </typeparam>
        /// <param name="filePath"> where to save. </param>
        /// <param name="fileName"> name of the file u want to save. </param>
        public void Save <T>(string filePath, string fileName)
        {
            // if Directory does not exits, create it prevent error!
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            InitJCSFile();

            using (var stream = new FileStream(filePath + fileName, FileMode.Create))
            {
                var binFmt = new BinaryFormatter();
                JCS_Debug.Log(Copyright);
                binFmt.Serialize(stream, this);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Create a tween panel.
        /// </summary>
        private static GameObject CreateTweenPanel()
        {
            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_TweenPanel";
            GameObject tweenPanel   = CreateHierarchyObjectUnderCanvas(setting_path);

            Undo.RegisterCreatedObjectUndo(tweenPanel, "Create Tween Panel");

            return(tweenPanel);
        }
Esempio n. 11
0
        /// <summary>
        /// Create the Game Object during the editing time and
        /// put under JCS_Canvas object.
        ///
        /// Save O(n) time complexity during editing time.
        /// </summary>
        /// <param name="settingPath"> path to spawn </param>
        /// <param name="jcsCanvas"> canvas to set on. </param>
        /// <returns> object just spawned. </returns>
        private static GameObject CreateHierarchyObjectUnderCanvas(string settingPath, JCS_Canvas jcsCanvas)
        {
            if (jcsCanvas == null)
            {
                JCS_Debug.Log("Can't find JCS_Canvas in hierarchy. Plz create canvas before creating new panel.");
                return(null);
            }

            // spawn the object first.
            GameObject hierarchyObj = CreateHierarchyObject(settingPath);

            // set the canvas as parent.
            hierarchyObj.transform.SetParent(jcsCanvas.transform);

            // init position.
            hierarchyObj.transform.localPosition = Vector3.zero;

            return(hierarchyObj);
        }
Esempio n. 12
0
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// Spawn a random transform.
        /// </summary>
        public void SpawnATransform()
        {
            int spawnIndex = JCS_Random.Range(0, mSpawnList.Count);

            // check null ref.
            if (mSpawnList[spawnIndex] == null)
            {
                JCS_Debug.Log(
                    "Cannot spawn a null reference. Plz check the spawn list if there are transform attach or empty slot.");
                return;
            }

            // spawn a object
            Transform objSpawned = (Transform)JCS_Utility.SpawnGameObject(
                mSpawnList[spawnIndex],
                this.transform.position);


            // randomize the position a bit.
            Vector3 randPos = JCS_Utility.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.position,
                new Vector3(mRandPosRangeX, mRandPosRangeY, mRandPosRangeZ),
                new JCS_Bool3(mRandPosX, mRandPosY, mRandPosZ));

            // randomize the rotation a bit.
            Vector3 randRot = JCS_Utility.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.eulerAngles,
                new Vector3(mRandRotRangeX, mRandRotRangeY, mRandRotRangeZ),
                new JCS_Bool3(mRandRotationX, mRandRotationY, mRandRotationZ));

            // randomize the rotation a bit.
            Vector3 randScale = JCS_Utility.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.localScale,
                new Vector3(mRandScaleRangeX, mRandScaleRangeY, mRandScaleRangeZ),
                new JCS_Bool3(mRandScaleX, mRandScaleY, mRandScaleZ));

            objSpawned.transform.position    = randPos;
            objSpawned.transform.eulerAngles = randRot;
            objSpawned.transform.localScale  = randScale;
        }
Esempio n. 13
0
        /// <summary>
        /// Create the clean dialogue panel for JCSUnity; and add in under to
        /// the canvas.
        ///
        /// Need:
        ///     1) JCS_Canvas
        /// in the scene before create dialogue panel.
        /// </summary>
        private static GameObject CreateDialoguePanel()
        {
            var canvas = (JCS_Canvas)FindObjectOfType(typeof(JCS_Canvas));

            if (canvas == null)
            {
                JCS_Debug.Log("Can't find JCS_Canvas in hierarchy. Plz create canvas before creating new panel.");
                return(null);
            }

            const string setting_path  = "UI/JCS_DialoguePanel";
            GameObject   dialoguePanel = CreateHierarchyObjectUnderCanvas(setting_path);

            Undo.RegisterCreatedObjectUndo(dialoguePanel, "Create Dialogue Panel");

            dialoguePanel.transform.localScale = Vector3.one;
            dialoguePanel.name = "_DialoguePanel (Created)";

            return(dialoguePanel);
        }
Esempio n. 14
0
        /// <summary>
        /// Create a tween panel.
        /// </summary>
        private static GameObject CreateTweenPanel()
        {
            JCS_Canvas jcsCanvas = (JCS_Canvas)FindObjectOfType(typeof(JCS_Canvas));

            if (jcsCanvas == null)
            {
                JCS_Debug.Log("Can't find JCS_Canvas in hierarchy. Plz create canvas before creating new panel.");
                return(null);
            }

            const string setting_path = "JCSUnity_Resources/GUI/JCS_TweenPanel";
            GameObject   tweenPanel   = CreateHierarchyObjectUnderCanvas(setting_path);

            Undo.RegisterCreatedObjectUndo(tweenPanel, "Create Tween Panel");

            tweenPanel.transform.localScale = Vector3.one;
            tweenPanel.name = "_TweenPanel (Created)";

            return(tweenPanel);
        }
Esempio n. 15
0
        /// <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);
        }
Esempio n. 16
0
 /* Default callback function pointer. */
 private static void JoystickPluggedDefaultCallback()
 {
     JCS_Debug.Log("At least one joystick connected!!!");
 }
        protected void OnTriggerStay(Collider other)
        {
            CharacterController cc = other.GetComponent <CharacterController>();

            if (cc == null)
            {
                return;
            }

            bool isTopOfBox = JCS_Physics.TopOfBoxWithSlope(cc, mPlatformCollider);

            if (isTopOfBox)
            {
                Physics.IgnoreCollision(
                    mPlatformCollider,
                    cc,
                    false);
            }
            else
            {
                Physics.IgnoreCollision(
                    mPlatformCollider,
                    cc,
                    true);
            }

            JCS_2DSideScrollerPlayer p = other.GetComponent <JCS_2DSideScrollerPlayer>();

            if (p == null)
            {
                return;
            }

            bool isJumpDown = p.IsDownJump();

            if (!mCanBeDownJump)
            {
                // if cannot be down jump, fore it to false.
                isJumpDown = false;
            }

            if (p.CharacterState == JCS_2DCharacterState.CLIMBING ||
                isJumpDown)
            {
                // IMPORTANT(JenChieh): Note that IgnoreCollision will reset
                // the trigger state of affected colliders,
                // so you might receive OnTriggerExit and
                // OnTriggerEnter messages in response to
                // calling this.
                Physics.IgnoreCollision(
                    mPlatformCollider,
                    p.GetCharacterController(),
                    true);
            }

            if (isJumpDown && isTopOfBox)
            {
                if (JCS_PlatformSettings.instance != null)
                {
                    /**
                     * Make the player go down ward, so it will not stop by
                     * the other collision detection. In order not to let the
                     * render frame goes off. set the value as small as possible.
                     */
                    p.VelY = -JCS_PlatformSettings.instance.POSITION_PLATFORM_DOWN_JUMP_FORCE;
                }
                else
                {
                    JCS_Debug.Log(
                        "No platform setting, could not set the down jump force...");
                }
            }

            p.ResetingCollision = true;
        }
        /* Setter & Getter */

        /* Functions */

        public override void OnClick()
        {
            JCS_Debug.Log(echoString);
        }
 public override void JCS_OnClickCallback()
 {
     JCS_Debug.Log(echoString);
 }
Esempio n. 20
0
        /// <summary>
        /// Create 9x9 slide panel.
        ///
        /// Need:
        ///     1) JCS_Camera
        ///     2) JCS_Canvas
        /// in the scene before create 9 x 9 slide panel.
        /// </summary>
        private static void CreateSlidePanel()
        {
            JCS_Canvas jcsCanvas = (JCS_Canvas)FindObjectOfType(typeof(JCS_Canvas));

            if (jcsCanvas == null)
            {
                JCS_Debug.Log("Can't find JCS_Canvas in hierarchy. Plz create canvas before creating new panel.");
                return;
            }

            // find the camera in the scene.
            JCS_2DCamera cam = (JCS_2DCamera)FindObjectOfType(typeof(JCS_Camera));

            if (cam == null)
            {
                JCS_Debug.Log("Can't find JCS_Canvas in hierarchy. Plz create canvas before creating new panel.");
                return;
            }

            const string settingPath = "JCSUnity_Resources/LevelDesignUI/JCS_SlideScreenPanelHolder";

            // spawn the pane holder.
            JCS_SlideScreenPanelHolder panelHolder9x9 = CreateHierarchyObjectUnderCanvas(settingPath, jcsCanvas).GetComponent <JCS_SlideScreenPanelHolder>();

            // create the array of panel.
            panelHolder9x9.slidePanels = new RectTransform[9];

            int starting_pos_x = -1920;
            int starting_pos_y = 1080;

            const string slidePanelPath = "JCSUnity_Resources/LevelDesignUI/JCS_SlidePanel";

            int index = 0;

            // create all nine panel and assign to the slide panel.
            for (int row = 0; row < 3; ++row)
            {
                for (int column = 0; column < 3; ++column)
                {
                    // get the rect transform from the slide panel object.
                    RectTransform slidePanel = CreateHierarchyObjectUnderCanvas(slidePanelPath, jcsCanvas).GetComponent <RectTransform>();

                    // set the position into 9x9.
                    Vector3 slidePanelNewPos = slidePanel.localPosition;
                    slidePanelNewPos.x       = starting_pos_x - (starting_pos_x * column);
                    slidePanelNewPos.y       = starting_pos_y - (starting_pos_y * row);
                    slidePanel.localPosition = slidePanelNewPos;

                    // set scale to one.
                    slidePanel.localScale = Vector3.one;

                    Image panelImage = slidePanel.GetComponent <Image>();
                    if (panelImage != null)
                    {
                        panelImage.color = JCS_Random.RandomColor();
                    }

                    // assign to slide panel holder.
                    panelHolder9x9.slidePanels[index] = slidePanel;

                    ++index;
                }
            }

            const string            slideScreenCameraPath = "JCSUnity_Resources/Camera/JCS_2DSlideScreenCamera";
            JCS_2DSlideScreenCamera slideScreenCamera     = CreateHierarchyObject(slideScreenCameraPath).GetComponent <JCS_2DSlideScreenCamera>();

            Undo.RegisterCreatedObjectUndo(slideScreenCamera, "Create 2D Slide Screen Camera");

            slideScreenCamera.name = "_2DSlideScreenCamera (Created)";

            // set the panel holder.
            slideScreenCamera.PanelHolder = panelHolder9x9;

            slideScreenCamera.SetJCS2DCamera(cam);

            // set to default 2d.
            slideScreenCamera.UnityGUIType = JCS_UnityGUIType.uGUI_2D;
        }
Esempio n. 21
0
 private static void JoystickUnPluggedDefaultCallback()
 {
     JCS_Debug.Log("No joystick connected...");
 }