コード例 #1
0
        protected Asset(string filePath) : this()
        {
            FileFormatMethodInfoCollection collection = RegisterFileFormats(this.GetType());

            this.filePath = filePath;
            var extension = Path.GetExtension(filePath).ToUpper();

            collection[extension].Invoke(this, new object[] { filePath });
            lock (fileCache)
            {
                fileCache.Add(filePath, new WeakReference <Asset>(this));
            }
        }
コード例 #2
0
        internal static FileFormatMethodInfoCollection RegisterFileFormats(Type type)
        {
            if (fileFormatMethods.ContainsKey(type))
            {
                return(fileFormatMethods[type]);
            }
            Debug.LogFormat("Register file formats by asset type: {0}", type);
            var methodInfos = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
            FileFormatMethodInfoCollection methods = new FileFormatMethodInfoCollection();

            foreach (var methodInfo in methodInfos)
            {
                if (methodInfo.GetCustomAttribute <FileFormatAttribute>() == null)
                {
                    continue;
                }
                Debug.LogFormat("Format handler found: {0}", methodInfo.Name);
                methods.Add(string.Format(".{0}", methodInfo.Name).ToUpper(), methodInfo);
            }
            fileFormatMethods.Add(type, methods);
            return(methods);
        }