Пример #1
0
        /// <summary>
        /// Method to do search directory and get the last file index.
        /// </summary>
        /// <param name="path"> path to search index. </param>
        /// <param name="prefixStr"> Filen name prefix. </param>
        /// <param name="ext"> Filen name extension. </param>
        /// <returns></returns>
        public static int LastFileIndex(string path, string prefixStr, string ext)
        {
            JCS_IO.CreateDirectory(path);

            var gs = JCS_GameSettings.instance;

            string fileName = "";
            string curExt   = "";
            int    last_saved_screenshot = -1;

            foreach (string file in Directory.GetFiles(path))
            {
                fileName = Path.GetFileNameWithoutExtension(file);
                curExt   = Path.GetExtension(file);

                // check if is the .png file
                // (screen shot can only be image file)
                if (!curExt.Equals(ext))
                {
                    continue;
                }

                int    index         = fileName.IndexOf(prefixStr);
                int    len           = prefixStr.Length;
                string startOfString = fileName.Substring(0, index);
                string endOfString   = fileName.Substring(index + len);
                string cleanPath     = startOfString + endOfString;

                last_saved_screenshot = System.Int32.Parse(cleanPath);
            }

            return(last_saved_screenshot);
        }
Пример #2
0
        /// <summary>
        /// Write a file and make it as cache data file.
        /// </summary>
        /// <param name="path"> Path to write to. </param>
        /// <param name="data"> Bytes data to write with. </param>
        private static void WriteFileAsCache(string path, byte[] data)
        {
            string filePath = CachePath() + path;
            string dirPath  = Path.GetDirectoryName(filePath);

            JCS_IO.CreateDirectory(dirPath);
            File.WriteAllBytes(filePath, data);
        }
Пример #3
0
        /// <summary>
        /// Take a snapshot and store image to data path.
        /// </summary>
        public string TakeSnapshotWebcam()
        {
            // No device detected!!
            // cannot take snap shot without the device!!
            if (!mDetectDevice)
            {
                JCS_Debug.LogError("No webcam detected in the current devices");
                return null;
            }

            var gs = JCS_GameSettings.instance;
            var prefix = gs.WEBCAM_FILENAME;
            var ext = gs.WEBCAM_EXTENSION;

            string savePath = SavePath();

            JCS_IO.CreateDirectory(savePath);

            Texture2D snap = new Texture2D(mWebCamTexture.width, mWebCamTexture.height);
            snap.SetPixels(mWebCamTexture.GetPixels());
            snap.Apply();

            // get the last saved webcam image's index
            int last_saved_index = LastImageFileIndex() + 1;

            string fullPath = ImagePathByIndex(last_saved_index);

            File.WriteAllBytes(fullPath, snap.EncodeToPNG());


            if (mSplash)
            {
                JCS_SceneManager sm = JCS_SceneManager.instance;

                if (sm.GetWhiteScreen() == null)
                    JCS_UtilityFunctions.PopJCSWhiteScreen();

                sm.GetWhiteScreen().FadeIn();

                // do the snap shot effect
                mSplashEffectTrigger = true;
            }

            // Stop the camera
            mWebCamTexture.Pause();

            // start the timer wait for resume
            mResumeTrigger = true;

            // play sound.
            {
                var soundm = JCS_SoundManager.instance;
                JCS_SoundPlayer sp = soundm.GetGlobalSoundPlayer();
                sp.PlayOneShot(mTakePhotoSound);
            }

            return fullPath;
        }
Пример #4
0
        /* Setter & Getter */

        /* Functions */

        private void Awake()
        {
            instance = CheckSingleton(instance, this);

            JCS_IO.CreateDirectory(JCS_GameData.SavePath());
            JCS_IO.CreateDirectory(JCS_Camera.SavePath());
            JCS_IO.CreateDirectory(JCS_Webcam.SavePath());
            JCS_IO.CreateDirectory(JCS_StreamingAssets.CachePath());
        }
Пример #5
0
        /// <summary>
        /// Load Image by file path.
        /// </summary>
        /// <param name="filePath"> Image file path. </param>
        /// <param name="pixelPerUnit"> Pixel per unit conversion to world space. </param>
        /// <returns> Sprite object. </returns>
        public static Sprite LoadImage(string filePath, float pixelPerUnit = 100.0f)
        {
            Sprite img = null;

            if (JCS_IO.IsFileOrDirectoryExists(filePath))
            {
                Texture2D tex = LoadTexture(filePath);
                img = Create(tex, 0.0f, 0.0f, tex.width, tex.height, pixelPerUnit);
            }
            return(img);
        }
Пример #6
0
        /// <summary>
        /// Save the game data into xml 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 fullFilePath)
        {
            string filePath = Path.GetDirectoryName(fullFilePath);

            JCS_IO.CreateDirectory(filePath);

            InitJCSFile();

            using (var stream = new FileStream(fullFilePath, FileMode.Create))
            {
                var XML = new XmlSerializer(typeof(T));
                XML.Serialize(stream, this);
            }
        }
        /// <summary>
        /// Save the game data into binary file format.
        /// </summary>
        /// <typeparam name="T"> type of the data save. </typeparam>
        /// <param name="fullFilePath"> file path direct where to save. </param>
        public void Save <T>(string fullFilePath)
        {
            string filePath = Path.GetDirectoryName(fullFilePath);

            JCS_IO.CreateDirectory(filePath);

            InitJCSFile();

            using (var stream = new FileStream(fullFilePath, FileMode.Create))
            {
                var binFmt = new BinaryFormatter();
                binFmt.Serialize(stream, this);
            }
        }
        /* Setter & Getter */

        /* Functions */

        private void Awake()
        {
            instance = CheckSingleton(instance, this);

            REAL_DATA_PATH            = JCS_AppData.SavePath();
            REAL_SCREENSHOT_PATH      = JCS_Camera.SavePath();
            REAL_WEBCAM_PATH          = JCS_Webcam.SavePath();
            REAL_STREAMING_CACHE_PATH = JCS_StreamingAssets.CachePath();

            JCS_IO.CreateDirectory(REAL_DATA_PATH);
            JCS_IO.CreateDirectory(REAL_SCREENSHOT_PATH);
            JCS_IO.CreateDirectory(REAL_WEBCAM_PATH);
            JCS_IO.CreateDirectory(REAL_STREAMING_CACHE_PATH);
        }
Пример #9
0
        /// <summary>
        /// Save the game data into xml 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 fullFilePath)
        {
            string filePath = Path.GetDirectoryName(fullFilePath);

            JCS_IO.CreateDirectory(filePath);

            InitJCSFile();

            using (var stream = new FileStream(fullFilePath, FileMode.Create))
            {
                string json = JsonUtility.ToJson(this);
                byte[] info = new UTF8Encoding(true).GetBytes(json);
                stream.Write(info, 0, info.Length);
            }
        }
Пример #10
0
        private bool ValidStreamingAssets(string path)
        {
            string filePath = StreamingAssetsPath() + path;

            return(JCS_IO.IsFile(filePath));
        }
Пример #11
0
        private bool ValidCacheData(string path)
        {
            string filePath = CachePath() + path;

            return(JCS_IO.IsFile(filePath));
        }