mirror of
https://github.com/soarqin/DSP_Mods_TO.git
synced 2025-12-19 21:13:29 +08:00
add XianTu
This commit is contained in:
50
XianTu/AssetsLoader/ABEmbeddedAssetsLoad.cs
Normal file
50
XianTu/AssetsLoader/ABEmbeddedAssetsLoad.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
internal class ABEmbeddedAssetsLoad : ABLoad
|
||||
{
|
||||
public ABEmbeddedAssetsLoad(string filename, string assetsNamespace = null)
|
||||
{
|
||||
var stackTrace = new StackTrace();
|
||||
var frame = stackTrace.GetFrame(1);
|
||||
var assembly = frame.GetMethod().DeclaringType.Assembly;
|
||||
var flag = assetsNamespace == null;
|
||||
if (flag)
|
||||
{
|
||||
assetsNamespace = assembly.FullName.Split([','])[0];
|
||||
}
|
||||
LoadAssetsFromEmbedded(filename, assetsNamespace, assembly);
|
||||
}
|
||||
|
||||
private void LoadAssetsFromEmbedded(string filename, string assetsNamespace, Assembly assembly)
|
||||
{
|
||||
var text = assetsNamespace + "." + filename;
|
||||
var manifestResourceStream = assembly.GetManifestResourceStream(text);
|
||||
var flag = manifestResourceStream == null;
|
||||
if (flag)
|
||||
{
|
||||
Debug.Log(string.Concat(["在", assembly.FullName, "找不到内嵌的资源", text, ",请检查内嵌资源中是否有它:"]));
|
||||
foreach (var text2 in assembly.GetManifestResourceNames())
|
||||
{
|
||||
Debug.Log(text2);
|
||||
}
|
||||
Debug.Log("------------------------");
|
||||
}
|
||||
else
|
||||
{
|
||||
Ab = AssetBundle.LoadFromStream(manifestResourceStream);
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
public ABEmbeddedAssetsLoad(string filename, string dllFilepath, string dllNamespace)
|
||||
{
|
||||
var assembly = Assembly.LoadFrom(dllFilepath);
|
||||
LoadAssetsFromEmbedded(filename, dllNamespace, assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
XianTu/AssetsLoader/ABFileLoad.cs
Normal file
13
XianTu/AssetsLoader/ABFileLoad.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
internal class ABFileLoad : ABLoad
|
||||
{
|
||||
public ABFileLoad(string filepath)
|
||||
{
|
||||
Ab = AssetBundle.LoadFromFile(filepath);
|
||||
Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
80
XianTu/AssetsLoader/ABLoad.cs
Normal file
80
XianTu/AssetsLoader/ABLoad.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public abstract class ABLoad : ILoad
|
||||
{
|
||||
protected void Init()
|
||||
{
|
||||
foreach (var text in Ab.GetAllAssetNames())
|
||||
{
|
||||
var flag = text.Contains("prefabs");
|
||||
if (flag)
|
||||
{
|
||||
PrefabPath = text.Substring(0, text.IndexOf("prefabs", StringComparison.OrdinalIgnoreCase));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject LoadPrefab(string path)
|
||||
{
|
||||
var flag = Ab == null;
|
||||
GameObject gameObject;
|
||||
if (flag)
|
||||
{
|
||||
Debug.Log("内嵌的AB包没有找到");
|
||||
gameObject = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag2 = path.Contains("/");
|
||||
if (flag2)
|
||||
{
|
||||
path = Path.Combine(PrefabPath, path);
|
||||
var flag3 = !path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase);
|
||||
if (flag3)
|
||||
{
|
||||
path += ".prefab";
|
||||
}
|
||||
}
|
||||
gameObject = Ab.LoadAsset<GameObject>(path);
|
||||
}
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
public string LoadText(string path)
|
||||
{
|
||||
var flag = Ab == null;
|
||||
string text;
|
||||
if (flag)
|
||||
{
|
||||
Debug.Log("内嵌的AB包没有找到");
|
||||
text = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag2 = path.Contains("/");
|
||||
if (flag2)
|
||||
{
|
||||
path = Path.Combine(_txtPath, path);
|
||||
var flag3 = !path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase);
|
||||
if (flag3)
|
||||
{
|
||||
path += ".prefab";
|
||||
}
|
||||
}
|
||||
text = Ab.LoadAsset<TextAsset>(path).text;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
protected string PrefabPath;
|
||||
|
||||
protected AssetBundle Ab;
|
||||
|
||||
private string _txtPath;
|
||||
}
|
||||
}
|
||||
28
XianTu/AssetsLoader/ABLoader.cs
Normal file
28
XianTu/AssetsLoader/ABLoader.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.IO;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public static class ABLoader
|
||||
{
|
||||
public static ABLoad LoadFromFile(string abFilename, string dir)
|
||||
{
|
||||
var text = Path.Combine(dir, abFilename);
|
||||
return new ABFileLoad(text);
|
||||
}
|
||||
|
||||
public static ABLoad LoadFromFile(string filepath)
|
||||
{
|
||||
return new ABFileLoad(filepath);
|
||||
}
|
||||
|
||||
public static ABLoad LoadFromEmbeddedAssets(string abFilename, string defaultNamespace = null)
|
||||
{
|
||||
return new ABEmbeddedAssetsLoad(abFilename, defaultNamespace);
|
||||
}
|
||||
|
||||
public static ABLoad LoadFromDll(string abFilename, string dllFilepath, string dllDefaultNameSpace)
|
||||
{
|
||||
return new ABEmbeddedAssetsLoad(abFilename, dllFilepath, dllDefaultNameSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
XianTu/AssetsLoader/ILoad.cs
Normal file
11
XianTu/AssetsLoader/ILoad.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public interface ILoad
|
||||
{
|
||||
GameObject LoadPrefab(string path);
|
||||
|
||||
string LoadText(string path);
|
||||
}
|
||||
}
|
||||
17
XianTu/AssetsLoader/ResourceLoad.cs
Normal file
17
XianTu/AssetsLoader/ResourceLoad.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public class ResourceLoad : ILoad
|
||||
{
|
||||
public GameObject LoadPrefab(string path)
|
||||
{
|
||||
return Resources.Load<GameObject>(path);
|
||||
}
|
||||
|
||||
public string LoadText(string path)
|
||||
{
|
||||
return Resources.Load<TextAsset>(path).text;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user