public static System.IO.Stream GetLuaStream(string name, out string location) { #if UNITY_EDITOR try { if (!string.IsNullOrEmpty(name)) { if (name.Length > 0 && name[0] == '?') { var real = name.Substring("?raw.".Length); string mod = null; string norm = real; if (real.StartsWith("mod.")) { if (real.StartsWith("mod.\"")) { var mindex = real.IndexOf('\"', "mod.\"".Length); if (mindex > 0) { mod = real.Substring("mod.\"".Length, mindex - "mod.\"".Length); norm = real.Substring(mindex + 2); } } else { var mindex = real.IndexOf('.', "mod.".Length); if (mindex > 0) { mod = real.Substring("mod.".Length, mindex - "mod.".Length); norm = real.Substring(mindex + 1); } } } norm = norm.Replace('.', '/'); bool isFileExist = false; if (mod == null) { real = "Assets/CapsSpt/" + norm + ".lua"; } else { string package; ResManager.EditorResLoader.ResRuntimeCache.ModToPackage.TryGetValue(mod, out package); if (!string.IsNullOrEmpty(package)) { real = "Packages/" + package + "/CapsSpt/" + norm + ".lua"; //real = EditorToClientUtils.GetPathFromAssetName(real); isFileExist = !string.IsNullOrEmpty(real) && PlatDependant.IsFileExist(real); } if (!isFileExist) { real = "Assets/Mods/" + mod + "/CapsSpt/" + norm + ".lua"; } } if (isFileExist || PlatDependant.IsFileExist(real)) { location = real; return(PlatDependant.OpenRead(real)); } } else { var file = "CapsSpt/" + name.Replace('.', '/') + ".lua"; string found; if (ThreadLocalObj.GetThreadId() == ThreadSafeValues.UnityThreadID) { found = ResManager.EditorResLoader.CheckDistributePath(file, true); } else { found = ResManager.EditorResLoader.CheckDistributePathSafe(file); } //if (found != null) //{ // if (found.StartsWith("Packages/")) // { // found = EditorToClientUtils.GetPathFromAssetName(found); // } //} if (found != null) { location = found; return(PlatDependant.OpenRead(found)); } } } } catch (Exception e) { PlatDependant.LogError(e); } #elif UNITY_ENGINE || UNITY_5_3_OR_NEWER try { if (name.Length > 0 && name[0] == '?') { if (name.StartsWith("?raw.")) { if (_RuntimeRawManifest != null) { var real = name.Substring("?raw.".Length); real = real.Replace("\"", ""); string archreal = Environment.Is64BitProcess ? "@64." + real : "@32." + real; CapsResManifestNode node; if (_RuntimeRawManifest.TryGetItemIgnoreExt(archreal, out node, _LuaRequireSeperateChars) || _RuntimeRawManifest.TryGetItemIgnoreExt(real, out node, _LuaRequireSeperateChars)) { if (node != null && node.Item != null) { var item = node.Item; while (item.Ref != null) { item = item.Ref; } return(GetLuaStream(item, out location)); } } } } } else { if (_RuntimeManifest != null) { var node = _RuntimeManifest.GetItem(name, _LuaRequireSeperateChars); if (node != null && node.Item != null) { var item = node.Item; while (item.Ref != null) { item = item.Ref; } return(GetLuaStream(item, out location)); } } } } catch (Exception e) { PlatDependant.LogError(e); } #else try { if (!string.IsNullOrEmpty(name)) { if (name.Length > 0 && name[0] == '?') { var real = name.Substring("?raw.".Length); string mod = null; string norm = real; if (real.StartsWith("mod.")) { if (real.StartsWith("mod.\"")) { var mindex = real.IndexOf('\"', "mod.\"".Length); if (mindex > 0) { mod = real.Substring("mod.\"".Length, mindex - "mod.\"".Length); norm = real.Substring(mindex + 2); } } else { var mindex = real.IndexOf('.', "mod.".Length); if (mindex > 0) { mod = real.Substring("mod.".Length, mindex - "mod.".Length); norm = real.Substring(mindex + 1); } } } norm = norm.Replace('.', '/'); if (mod == null) { real = "/spt/" + norm + ".lua"; } else { real = "/mod/" + mod + "/spt/" + norm + ".lua"; } var stream = ResManager.LoadFileRelative(real); if (stream != null) { location = real; return(stream); } } else { var file = "/spt/" + name.Replace('.', '/') + ".lua"; string real, mod, dist; real = ResManager.FindFile(file, out mod, out dist); if (real != null) { try { var stream = PlatDependant.OpenRead(real); if (stream != null) { location = file; if (!string.IsNullOrEmpty(dist)) { location = "/dist/" + dist + location; } if (!string.IsNullOrEmpty(mod)) { location = "/mod/" + mod + location; } return(stream); } } catch (Exception e) { PlatDependant.LogError(e); } } } } } catch (Exception e) { PlatDependant.LogError(e); } #endif location = ""; return(null); }