Exemplo n.º 1
0
        public TaskData GetTaskData()
        {
            if (taskDataInvalid)
            {
                return(null);
            }

            if (task != null && task.ExecutionState == ExecutionState.Started)
            {
                throw new InvalidStateException("Task is still running");
            }

            TaskData taskData = null;

            if (task == null)
            {
                if (CurrentException == null)
                {
                    CurrentException = new Exception("Task with id " + this.TaskId + " is null, sending empty task");
                }
            }
            else
            {
                taskData        = new TaskData();
                taskData.Data   = PersistenceUtil.Serialize(task);
                taskData.TaskId = TaskId;
            }
            return(taskData);
        }
Exemplo n.º 2
0
    static void ExportSceneAssetBundle(string directory, BuildTarget target)
    {
        directory = GetTargetDirectory(directory, target) + "scenes/";
        ReadyDirectory(directory, target);
        Dictionary <string, uint> crcList = new Dictionary <string, uint>();

        List <string> scenes = FindRemoteScenes();
        int           index  = 0;

        foreach (string scene in scenes)
        {
            uint      crc      = 0;
            string    fileName = scene.Substring(scene.LastIndexOf("/") + 1);
            string    name     = fileName.Substring(0, fileName.LastIndexOf("."));
            string    path     = directory + name + ".unity3d";
            string [] levels   = { scene };

            foreach (string s in levels)
            {
                Debug.Log("build:" + s);
            }

            BuildPipeline.BuildStreamedSceneAssetBundle(levels, path, target, out crc, 0);
            crcList.Add(name, crc);
            index++;
        }

        string json = JsonMapper.ToJson(crcList);

        PersistenceUtil.SaveTextFile(directory + "scenes.meta", json);
    }
Exemplo n.º 3
0
    IEnumerator LoadScenes(NetResult result)
    {
        yield return(Service.Run(DownloadSceneMeta(result)));

        if (result.IsFailed())
        {
            logger.LogError("Can not load scene meta.");
            yield break;
        }

#if UNITY_EDITOR && BOOT_BUNDLE_EDIT
        yield break;
#endif

        // init count
        doneCount = 0;
        string text = Service.sb.Get("loading.status.bundle.load.scene");
        if (presenter != null)
        {
            presenter.SetDescription(string.Format(text, 0));
        }

        successSceneWorkerCount = 0;
        failedSceneWorkerCount  = 0;
        for (int index = 0; index < worker; index++)
        {
            Service.Run(LoadSceneWorker(index));
        }

        // waiting load
        while (true)
        {
            yield return(new WaitForSeconds(0.1f));

            if (successSceneWorkerCount + failedSceneWorkerCount < worker)
            {
                continue;
            }
            break;
        }

        // result check
        if (failedSceneWorkerCount > 0)
        {
            result.SetSuccess(false);
        }
        else
        {
            result.SetSuccess(true);
            PersistenceUtil.SaveTextFile(remoteScenesMetaFilePath, remoteScenesMeta);
        }
    }
Exemplo n.º 4
0
        public Tuple <TaskData, DateTime> GetTaskDataSnapshot()
        {
            if (taskDataInvalid)
            {
                return(null);
            }

            Tuple <TaskData, DateTime> snapshot = null;

            if (task == null)
            {
                if (CurrentException == null)
                {
                    CurrentException = new Exception("Task with id " + this.TaskId + " is null, sending empty task");
                }
            }
            else
            {
                var taskData = new TaskData();

                var          pausedTrigger = new EventWaitHandle(false, EventResetMode.ManualReset);
                EventHandler pausedHandler = null;
                pausedHandler = (s, e) => {
                    task.TaskPaused -= pausedHandler;
                    task.TaskPaused += Task_TaskPaused;
                    pausedTrigger.Set();
                };

                task.TaskPaused -= Task_TaskPaused;
                task.TaskPaused += pausedHandler;
                task.Pause();
                pausedTrigger.WaitOne();

                taskData.Data = PersistenceUtil.Serialize(task);
                var timestamp = DateTime.Now;

                EventHandler startedHandler = null;
                startedHandler = (s, e) => {
                    task.TaskStarted -= startedHandler;
                    task.TaskStarted += Task_TaskStarted;
                };

                task.TaskStarted -= Task_TaskStarted;
                task.TaskStarted += startedHandler;
                task.Start();

                taskData.TaskId = TaskId;
                snapshot        = Tuple.Create(taskData, timestamp);
            }

            return(snapshot);
        }
    private void ReportQuestions()
    {
        StringBuilder sb = new StringBuilder();

        int count = 0;

        foreach (string key in bundles.Keys)
        {
            var container = bundles[key];
            if (container.ContainsKey("en") == true && container.ContainsKey("ko") == true)
            {
                if (questions.ContainsKey(key) == false)
                {
                    continue;
                }

                var question = questions[key];
                if (question.Contains("en") == false)
                {
                    continue;
                }

                sb.Append(key);
                sb.Append("\t");

                sb.Append("|ko| ");
                sb.Append(container["ko"].Replace("\n", "\\n"));
                sb.Append("\t");
                sb.Append("|en| ");
                sb.Append(container["en"].Replace("\n", "\\n"));
                sb.Append("\n");

                count++;
            }
        }

        string path = Application.persistentDataPath + "/QuestionStringBundle.txt";

        PersistenceUtil.SaveTextFile(path, sb.ToString());

        if (count > 0)
        {
            Debug.LogError("Question strings: " + count);
        }
    }
Exemplo n.º 6
0
    bool Load()
    {
        string text = PersistenceUtil.LoadDecryptTextFile("setting");

        if (text.Length == 0)
        {
            return(false);
        }

        try {
            values = JsonMapper.ToObject <Setting>(text);
        }
        catch (Exception e) {
            logger.LogError(e.ToString());
            return(false);
        }

        return(values != null);
    }
Exemplo n.º 7
0
    static void ExportResource(string directory, BuildTarget target)
    {
        directory = GetTargetDirectory(directory, target) + "resources/";
        ReadyDirectory(directory, target);

        List <Object>             objects = new List <Object>();
        List <string>             files   = TraverseTree("Assets/Resources2Pack");
        Dictionary <string, uint> crcList = new Dictionary <string, uint>();

        foreach (string file in files)
        {
            Object obj = AssetDatabase.LoadAssetAtPath <Object>(file);
            objects.Add(obj);
            Object[] selection = objects.ToArray();

            string fileName = file.Substring(file.LastIndexOf("/") + 1);
            string name     = fileName.Substring(0, fileName.LastIndexOf("."));
            string path     = directory + name + ".unity3d";
            if (name.Length == 0)
            {
                continue;
            }

            if (crcList.ContainsKey(name))
            {
                Debug.LogError(name + " is already exist!");
            }

            uint crc = 0;
            BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, out crc,
                                           BuildAssetBundleOptions.CollectDependencies |
                                           BuildAssetBundleOptions.CompleteAssets,
                                           target);
            objects.Clear();
            crcList.Add(name, crc);
        }

        string json = JsonMapper.ToJson(crcList);

        PersistenceUtil.SaveTextFile(directory + "resources.meta", json);
    }
Exemplo n.º 8
0
        public void Start(byte[] serializedJob)
        {
            try {
                creationTime = DateTime.Now;
                task         = PersistenceUtil.Deserialize <ITask>(serializedJob);

                RegisterJobEvents();

                task.Start();
                if (!startTaskSem.WaitOne(Settings.Default.ExecutorSemTimeouts))
                {
                    throw new TimeoutException("Timeout when starting the task. TaskStarted event was not fired.");
                }
            }
            catch (Exception e) {
                HandleStartStopPauseError(e);
            }
            finally {
                taskStartedSem.Set();
            }
        }
    private void ReportUntranslated()
    {
        StringBuilder sb = new StringBuilder();

        int count = 0;

        foreach (string key in bundles.Keys)
        {
            var container = bundles[key];
            if (container.ContainsKey("en") == false)
            {
                sb.Append(key);
                sb.Append("\n");

                foreach (string lang in container.Keys)
                {
                    sb.Append("    |");
                    sb.Append(lang);
                    sb.Append("| ");
                    sb.Append(container[lang].Replace("\n", "\\n"));
                    sb.Append("\n");
                }

                sb.Append("    |en| \n");
                count++;
            }
        }

        string path = Application.persistentDataPath + "/UntranslatedStringBundle.txt";

        PersistenceUtil.SaveTextFile(path, sb.ToString());

        if (count > 0)
        {
            Debug.LogError("Untranslated strings: " + count);
        }
    }
Exemplo n.º 10
0
    IEnumerator DownloadSceneMeta(NetResult result)
    {
        // get local
        string localMeta = PersistenceUtil.LoadTextFile(remoteScenesMetaFilePath);

        if (localMeta.Length > 0)
        {
            try {
                localScenes = JsonMapper.ToObject <Dictionary <string, uint> >(localMeta);
            }
            catch (Exception e) {
                logger.LogWarning(e.ToString());
            }
        }

        // get remote
        using (WWW www = new WWW(cdnScenesMeta)) {
            yield return(www);

            if (www.error != null)
            {
                result.SetSuccess(false);
                yield break;
            }

            try {
                remoteScenes     = JsonMapper.ToObject <Dictionary <string, uint> >(www.text);
                remoteScenesMeta = www.text;
                result.SetSuccess(true);
            }
            catch (Exception e) {
                result.SetSuccess(false);
                logger.LogError(e.ToString());
            }
        }
    }
Exemplo n.º 11
0
    bool Save()
    {
        string text = JsonMapper.ToJson(values);

        return(PersistenceUtil.SaveEncryptTextFile("setting", text));
    }
Exemplo n.º 12
0
        static void OnAliasCommandPageReturn(object sender, ReturnEventArgs <string> e)
        {
            var page = (TextInputPage)sender;

            PersistenceUtil.AliasPartialCommand((CommandExecutor)page.UserValue, e.Result);
        }
Exemplo n.º 13
0
        static void OnAliasFacetPageReturn(object sender, ReturnEventArgs <string> e)
        {
            var page = (TextInputPage)sender;

            PersistenceUtil.SetFacetMonikerAlias((FacetMoniker)page.UserValue, e.Result);
        }