Example #1
0
        void InitSpriteDic()
        {
            var keys = WidgetUtility.GetKeys(type);

            if (spriteDic == null)
            {
                spriteDic = new Dictionary <string, Sprite>();
            }
            else
            {
                a : foreach (var item in spriteDic)
                {
                    if (!keys.Contains(item.Key))
                    {
                        Catch(item.Key, item.Value);
                        spriteDic.Remove(item.Key);
                        goto a;
                    }
                }
            }

            foreach (var item in keys)
            {
                if (!spriteDic.ContainsKey(item))
                {
                    spriteDic.Add(item, TryLoad(item));
                }
            }
        }
Example #2
0
        /// <summary>
        /// 从json文件中加载出配制
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static WidgetItem[] LoadWidgeItems(string json, string assetDir)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            var items = new List <WidgetItem>();

            var jsonarray = JSONNode.Parse(json).AsArray;

            foreach (var nodeItem in jsonarray)
            {
                var jsonClass = nodeItem as JSONClass;
                if (nodeItem != null && jsonClass != null)
                {
                    var item = new WidgetItem();
                    item.type      = (WidgetType)Enum.Parse(typeof(WidgetType), jsonClass[KeyWord.type].Value);
                    item.name      = jsonClass[KeyWord.name].Value;
                    item.spriteDic = LoadTextures(jsonClass, assetDir);
                    foreach (var key in WidgetUtility.GetKeys(item.type))
                    {
                        if (!item.spriteDic.ContainsKey(key))
                        {
                            item.spriteDic.Add(key, null);
                        }
                    }
                    items.Add(item);
                }
            }
            return(items.ToArray());
        }