예제 #1
0
 public override void Dispose()
 {
     if (m_resLoader != null)
     {
         m_resLoader.Clear();
         m_resLoader = null;
     }
     m_finishAction = null;
     base.Dispose();
 }
예제 #2
0
 private void OnComplete(MultiResourceLoader loader)
 {
     m_resLoader.Clear();
     m_resLoader = null;
     if (null != m_finishAction)
     {
         Action action = m_finishAction;
         m_finishAction = null;
         action();
     }
 }
예제 #3
0
        public void LoadResCfgs(string resDir, Action OnFinish = null)
        {
            m_finishAction = OnFinish;
            m_dicCfgInfo   = new Dictionary <string, ResCfgInfo>();
            resDir         = resDir.Replace('\\', '/');
            if (!resDir.EndsWith("/"))
            {
                resDir += "/";
            }
            if (resDir.StartsWith("/"))
            {
                resDir = resDir.Substring(1);
            }
            Assembly assembly = Assembly.GetAssembly(typeof(ResCfgSys));
            var      types    = assembly.GetTypes();

            foreach (var type in types)
            {
                object[] arr = type.GetCustomAttributes(typeof(ResCfgAttribute), false);
                if (arr.Length == 0)
                {
                    continue;
                }
                var          properties   = type.GetProperties();
                PropertyInfo propertyInfo = null;
                for (int i = 0; i < properties.Length; i++)
                {
                    object[] arrMember = properties[i].GetCustomAttributes(typeof(ResCfgKeyAttribute), false);
                    if (arrMember.Length > 0)
                    {
                        propertyInfo = properties[i];
                        break;
                    }
                }
                if (propertyInfo == null)
                {
                    CLog.LogError("配置名称:" + type.Name + "找不到唯一key的定义ResCfgAttribute");
                    continue;
                }
                string path = resDir + type.Name + ".xml";
                //考虑下需要过滤不在此目录的文件
                ResCfgInfo cfgInfo = new ResCfgInfo();
                cfgInfo.xmlPath     = resDir + type.Name + ".xml";
                cfgInfo.type        = type;
                cfgInfo.keyProperty = propertyInfo;
                m_dicCfgInfo.Add(cfgInfo.xmlPath, cfgInfo);
                //CLog.LogColorArgs(CLogColor.Red,type.Name,propertyInfo != null ? propertyInfo.Name : "null");
            }
            List <string> names = new List <string>();

            foreach (var item in m_dicCfgInfo)
            {
                names.Add(item.Value.xmlPath);
            }
            //如果是播放模式
            if (Application.isPlaying)
            {
                //下载对应的资源
                m_resLoader = new MultiResourceLoader(ResourceSys.Instance);
                m_resLoader.LoadList(names, OnComplete, OnProgress, ResourceType.Text);
            }
            else
            {
                for (int i = 0; i < names.Count; i++)
                {
                    var textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(names[i]);
                    if (textAsset != null)
                    {
                        ParseData(names[i], textAsset.text);
                    }
                }
                if (null != m_finishAction)
                {
                    Action action = m_finishAction;
                    m_finishAction = null;
                    action();
                }
            }
        }