Example #1
0
 private void OnComplete(MultiResourceObjectLoader loader)
 {
     m_resObjectLoader.Clear();
     m_resObjectLoader = null;
     if (null != m_finishAction)
     {
         Action action = m_finishAction;
         m_finishAction = null;
         action();
     }
 }
Example #2
0
 public override void Dispose()
 {
     if (m_resObjectLoader != null)
     {
         m_resObjectLoader.Clear();
         m_resObjectLoader = null;
     }
     m_finishAction = null;
     if (m_dicCfgInfo != null)
     {
         foreach (var item in m_dicCfgInfo)
         {
             Type       dataReaderTType    = typeof(DataReader <>);
             Type       dataReaderDataType = dataReaderTType.MakeGenericType(new Type[] { item.Value.type });
             MethodInfo disposeMethod      = dataReaderDataType.GetMethod("Dispose", BindingFlags.Static | BindingFlags.Public);
             disposeMethod.Invoke(null, new object[] { });
         }
     }
     base.Dispose();
 }
Example #3
0
        public void LoadResCfgs(string resDir, Action OnFinish = null)
        {
            Dispose();
            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;
                }
                //考虑下需要过滤不在此目录的文件
                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_resObjectLoader = new MultiResourceObjectLoader();
                //下载对应的资源
                m_resObjectLoader.LoadList(names, true, OnComplete, OnProgress);
            }
#if UNITY_EDITOR
            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();
                }
            }
#endif
        }