Beispiel #1
0
    /// <summary>
    /// 加载字典
    /// </summary>
    /// <param name="dictionaryPath"></param>
    public static void Load(string dictionaryPath)
    {
        var text = LResources.Load <TextAsset>(dictionaryPath);

        if (text == null)
        {
            Debug.LogError("没有找到当前语言对应的资源" + dictionaryPath);
            return;
        }
        //从JSON解析字典
        var jDic = JObject.Parse(text.text);

        foreach (JToken kv in jDic)
        {
            string key = kv.Name;
            if (Ins.Dict.ContainsKey(key))
            {
                Debug.LogError(string.Format("发现重复的key{0},将替换该key对应的值", key));
                Ins.Dict[key] = kv.AsString();
            }
            else
            {
                Ins.Dict.Add(key, kv.AsString());
            }
        }
    }
 public void ReAssign()
 {
     if (text == null)
     {
         text = GetComponent <Text>();
     }
     if (text != null)
     {
         if (onFontReq != null)
         {
             text.font = onFontReq(this.fontPath);
         }
         else
         {
             if (Application.isPlaying)
             {
                 text.font = LResources.Load <Font>(this.fontPath);
             }
             else
             {
                 text.font = Resources.Load <Font>(this.fontPath);
             }
         }
     }
 }
Beispiel #3
0
        public NicknameLibrary()
        {
            TextAsset textAsset = LResources.Load <TextAsset>("NickNameLibrary");

            this.WordList = new List <List <string> >();
            string[] lines        = textAsset.text.Split("\n".ToCharArray());
            string[] fistLineWord = lines[0].Split(',');
            for (int index = 0; index < fistLineWord.Length; index++)
            {
                this.WordList.Add(new List <string>());
            }

            foreach (var line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                string[] word = line.Split(',');
                for (int i = 0; i < word.Length; i++)
                {
                    if (!string.IsNullOrEmpty(word[i]))
                    {
                        this.WordList[i].Add(word[i]);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 打开数据库<para/>
        /// 会自动将数据库文件写入到外部,Close的时候删除
        /// </summary>
        /// <returns></returns>
        public bool Open()
        {
            if (dbAccess.IsOpen)
            {
                Debug.LogError(DbName + "已经是打开的了");
                return(false);
            }

            _realDbPath = null;
            if (AllowDebug)
            {
                if (File.Exists(DbName))
                {
                    _realDbPath = DbName;
                    Debug.Log("找到调试数据库" + _realDbPath);
                    _useDebugDb = true;
                    Password    = "";                 //调试数据库的密码应该为空
                }
            }

            if (_realDbPath == null)
            {
                var nameWithoutExt = Path.GetFileNameWithoutExtension(DbName);
                var asset          = LResources.Load <TextAsset>(nameWithoutExt);
                if (asset == null || asset.bytes == null)
                {
                    throw new Exception("没有找到数据库资源");
                }
                // 写出数据库文件
                var tmpFileName = string.Format(".{0}.tmp", nameWithoutExt);
                _realDbPath = Path.Combine(Application.persistentDataPath, tmpFileName);
                File.WriteAllBytes(_realDbPath, asset.bytes);
            }
            if (!File.Exists(_realDbPath))
            {
                throw new Exception("数据库文件不存在");
            }
            if (this.AllowDebug)
            {
                Debug.Log("DB File path:" + this._realDbPath);
            }
            // 连接数据库
            return(dbAccess.OpenFromFile(_realDbPath, Password));
        }
Beispiel #5
0
        void Awake()
        {
            Text text = this.gameObject.GetComponent <Text>();

            if (null == text)
            {
                return;
            }
            // font
            if (!string.IsNullOrEmpty(FontPath))
            {
                text.font = LResources.Load <Font>(FontPath);
            }
            // text
            if (string.IsNullOrEmpty(text.text) && !string.IsNullOrEmpty(Key))
            {
                text.text = Key.ToLocalized();
            }
        }
Beispiel #6
0
 public void ReAssign()
 {
     if (image == null)
     {
         image = GetComponent <Image>();
     }
     if (image != null)
     {
         if (!string.IsNullOrEmpty(this.atlasPath))
         {//如果该路径不为空.
             if (Application.isPlaying)
             {
                 image.sprite = LResources.Load <Atlas>(this.atlasPath)?.GetSprite(this.spriteName);
             }
             else
             {
                 image.sprite = Resources.Load <Atlas>(this.atlasPath)?.GetSprite(this.spriteName);
             }
         }
         else
         {//如果该路径为空.
             if (Application.isPlaying)
             {
                 image.sprite = LResources.Load <Sprite>(this.spriteName);//加载根目录下的图片.
             }
             else
             {
                 image.sprite = Resources.Load <Sprite>(this.spriteName);
             }
         }
         if (this.autoResize)
         {
             this.image.SetNativeSize();
         }
     }
 }