Esempio n. 1
0
        public ResourcesFile FindResourcesFile(ISerializedFile ifile, string resName)
        {
            SerializedFile file = (SerializedFile)ifile;

            resName = FilenameUtils.FixResourcePath(resName);

            // check asset bundles / web files
            string filePath = file.FilePath;

            foreach (ResourcesFile res in m_resources)
            {
                if (res.FilePath == filePath && res.Name == resName)
                {
                    return(res.CreateReference());
                }
            }

            string resPath = m_resourceCallback?.Invoke(resName);

            if (resPath == null)
            {
                return(null);
            }
            using (SmartStream stream = SmartStream.OpenRead(resPath))
            {
                return(new ResourcesFile(stream, resPath, resName, 0, stream.Length));
            }
        }
        public ResourcesFile FindResourcesFile(ISerializedFile ifile, string fileName)
        {
            SerializedFile file = (SerializedFile)ifile;

            fileName = FilenameUtils.FixResourcePath(fileName);

            // check asset bundles / web files
            string filePath = file.FilePath;

            foreach (ResourcesFile res in m_resources)
            {
                if (res.FilePath == filePath && res.Name == fileName)
                {
                    return(res);
                }
            }

            // check manualy loaded resource files
            string dirPath = Path.GetDirectoryName(filePath) ?? string.Empty;
            string resPath = Path.Combine(dirPath, fileName);

            foreach (ResourcesFile res in m_resources)
            {
                if (res.FilePath == resPath && res.Name == fileName)
                {
                    return(res);
                }
            }

            // lazy loading
            if (FileMultiStream.Exists(resPath))
            {
                Stream        stream    = FileMultiStream.OpenRead(resPath);
                ResourcesFile resesFile = new ResourcesFile(resPath, fileName, stream);
                m_resources.Add(resesFile);
                return(resesFile);
            }
            return(null);
        }