KEngine.KResourceModule.GetResourceFullPath C# (CSharp) Méthode

GetResourceFullPath() public static méthode

根据相对路径,获取到StreamingAssets完整路径,或Resources中的路径
public static GetResourceFullPath ( string url, bool withFileProtocol, string &fullPath, bool isLog = true ) : GetResourceFullPathType
url string
withFileProtocol bool
fullPath string
isLog bool
Résultat GetResourceFullPathType
        public static GetResourceFullPathType GetResourceFullPath(string url, bool withFileProtocol, out string fullPath,
             bool isLog = true)
        {
            if (string.IsNullOrEmpty(url))
                Log.Error("尝试获取一个空的资源路径!");

            string docUrl;
            bool hasDocUrl = TryGetDocumentResourceUrl(url, withFileProtocol, out docUrl);

            string inAppUrl;
            bool hasInAppUrl;
            {
                hasInAppUrl = TryGetInAppStreamingUrl(url, withFileProtocol, out inAppUrl);
            }

            if (ResourcePathPriorityType == KResourcePathPriorityType.PersistentDataPathPriority) // 優先下載資源模式
            {
                if (hasDocUrl)
                {
                    if (Application.isEditor)
                        Log.Warning("[Use PersistentDataPath] {0}", docUrl);
                    fullPath = docUrl;
                    return GetResourceFullPathType.InDocument;
                }
                // 優先下載資源,但又沒有下載資源文件!使用本地資源目錄
            }

            if (!hasInAppUrl) // 连本地资源都没有,直接失败吧 ?? 沒有本地資源但又遠程資源?竟然!!?
            {
                if (isLog)
                    Log.Error("[Not Found] StreamingAssetsPath Url Resource: {0}", url);
                fullPath = null;
                return GetResourceFullPathType.Invalid;
            }

            fullPath = inAppUrl; // 直接使用本地資源!

            return GetResourceFullPathType.InApp;
        }

Same methods

KResourceModule::GetResourceFullPath ( string url, bool withFileProtocol = true, bool isLog = true ) : string

Usage Example

Exemple #1
0
        /// <summary>
        /// Convenient method to load file sync auto.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static byte[] LoadSync(string url)
        {
            string fullUrl;
            var    getResPathType = KResourceModule.GetResourceFullPath(url, false, out fullUrl);

            if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid)
            {
                if (Debug.isDebugBuild)
                {
                    Log.Error("[HotBytesLoader]Error Path: {0}", url);
                }
                return(null);
            }

            byte[] bytes;
            if (getResPathType == KResourceModule.GetResourceFullPathType.InApp)
            {
                if (Application.isEditor) // Editor mode : 读取Product配置目录
                {
                    var loadSyncPath = Path.Combine(KResourceModule.ProductPathWithoutFileProtocol, url);
                    bytes = KResourceModule.ReadAllBytes(loadSyncPath);
                }
                else // product mode: read streamingAssetsPath
                {
                    bytes = KResourceModule.LoadSyncFromStreamingAssets(url);
                }
            }
            else
            {
                bytes = KResourceModule.ReadAllBytes(fullUrl);
            }
            return(bytes);
        }
All Usage Examples Of KEngine.KResourceModule::GetResourceFullPath