Example #1
0
        public NodeGroup LoadNodeGroupByJson(string path)
        {
            string content = "";

#if UNITY_EDITOR
            if (File.Exists(path))
            {
                content = File.ReadAllText(path);
            }
#else
            content = xc.DBManager.Instance.LoadDBFile(path.Replace("Assets/Res/", ""));
#endif
            if (string.IsNullOrEmpty(content) == true)
            {
                return(null);
            }
            NodeGroup             temp   = null;
            FullSerializer.fsData fsdata = FullSerializer.fsJsonParser.Parse(content);
            var serializer = new FullSerializer.fsSerializer();
            var processor  = new FileSerializerProcessor();
            serializer.AddProcessor(processor);
            serializer.TryDeserialize(fsdata, ref temp);
            if (temp != null)
            {
                RemoveNodeGroup(temp.Id);
                InitNodeGroup(temp);
                nodeGroups.Add(temp.Id, temp);
                return(temp);
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Attempts to load saved mod settings from file & updates loaded mods
        /// </summary>
        /// <returns></returns>
        public static bool LoadModSettings()
        {
            FullSerializer.fsResult result = new FullSerializer.fsResult();

            try
            {
                string filepath = Path.Combine(ModManager.instance.modDirectory, MODCONFIGFILENAME);
                if (!File.Exists(filepath))
                {
                    return(false);
                }

                var serializedData = File.ReadAllText(filepath);
                if (string.IsNullOrEmpty(serializedData))
                {
                    return(false);
                }


                List <Mod>            temp = new List <Mod>();
                FullSerializer.fsData data = FullSerializer.fsJsonParser.Parse(serializedData);
                result = _serializer.TryDeserialize <List <Mod> >(data, ref temp);

                if (result.Failed || temp.Count <= 0)
                {
                    return(false);
                }


                foreach (Mod _mod in temp)
                {
                    if (ModManager.instance.GetModIndex(_mod.Title) >= 0)
                    {
                        Mod mod = ModManager.Instance.GetMod(_mod.Title);
                        if (mod == null)
                        {
                            continue;
                        }
                        mod.Enabled      = _mod.Enabled;
                        mod.LoadPriority = _mod.LoadPriority;
                        ModManager.instance.Mods[ModManager.instance.GetModIndex(_mod.Title)] = mod;
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Format("Error trying to load mod settings: {0}", ex.Message));
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 协程加载关卡配置
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>\
        private IEnumerator CoLoadLevelFile(string path)
        {
            SGameEngine.AssetResource result = new SGameEngine.AssetResource();

            yield return(MainGame.HeartBehavior.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_asset(path, typeof(TextAsset), result)));

            if (result.asset_ == null)
            {
                yield break;
            }

            TextAsset textAsset = result.asset_ as TextAsset;

            if (textAsset == null || textAsset.text == null)
            {
                result.destroy();
                Debug.LogError("LevelManager::CoLoadLevelFile, can not read level file:" + path);
                yield break;
            }

            Neptune.Data          data   = new Neptune.Data();
            FullSerializer.fsData fsdata = FullSerializer.fsJsonParser.Parse(textAsset.text);
            var serializer = new FullSerializer.fsSerializer();
            var processor  = new Neptune.FileSerializerProcessor();

            serializer.AddProcessor(processor);
            serializer.TryDeserialize <Neptune.Data>(fsdata, ref data);

            if (data == null)
            {
                result.destroy();
                yield break;
            }

            OnLevelLoadFinished(data);
            ObjCachePoolMgr.Instance.RecycleCSharpObject(data, ObjCachePoolType.JSON, path);

            result.destroy();
        }
Example #4
0
        Neptune.Data LoadLevelFileTemporary(string path)
        {
            Neptune.Data data = null;
            if (m_NepCache.TryGetValue(path, out data))
            {
                return(data);
            }

            string text = DBManager.Instance.LoadDBFile(path.Replace("Assets/Res/", ""));

            if (string.IsNullOrEmpty(text) == true)
            {
                return(null);
            }
            data = new Neptune.Data();
            FullSerializer.fsData fsdata = FullSerializer.fsJsonParser.Parse(text);
            var serializer = new FullSerializer.fsSerializer();
            var processor  = new Neptune.FileSerializerProcessor();

            serializer.AddProcessor(processor);
            serializer.TryDeserialize <Neptune.Data>(fsdata, ref data);
            if (data == null)
            {
                return(null);
            }

            if (m_NepCache.Count >= 3)
            {
                string first_path = m_NepPath.Dequeue();
                m_NepCache.Remove(first_path);
            }

            m_NepCache[path] = data;
            m_NepPath.Enqueue(path);

            return(data);
        }