diff --git a/Assets/Scenes/DemoScene.unity b/Assets/Scenes/DemoScene.unity index a2b1f0da..431b2d4b 100644 --- a/Assets/Scenes/DemoScene.unity +++ b/Assets/Scenes/DemoScene.unity @@ -259,11 +259,6 @@ PrefabInstance: propertyPath: m_Name value: TEngine objectReference: {fileID: 0} - - target: {fileID: 3463045026180535779, guid: 161ff7c8132079c4a95e2e4e70ddd41b, - type: 3} - propertyPath: m_RootOrder - value: 1 - objectReference: {fileID: 0} - target: {fileID: 3463045026180535779, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} propertyPath: m_LocalPosition.x @@ -279,11 +274,6 @@ PrefabInstance: propertyPath: m_LocalPosition.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 3463045026180535779, guid: 161ff7c8132079c4a95e2e4e70ddd41b, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - target: {fileID: 3463045026180535779, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} propertyPath: m_LocalRotation.x @@ -299,6 +289,16 @@ PrefabInstance: propertyPath: m_LocalRotation.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 3463045026180535779, guid: 161ff7c8132079c4a95e2e4e70ddd41b, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 3463045026180535779, guid: 161ff7c8132079c4a95e2e4e70ddd41b, + type: 3} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} - target: {fileID: 3463045026180535779, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} propertyPath: m_LocalEulerAnglesHint.x diff --git a/Assets/TEngine/EntryPrefab/TEngine.prefab b/Assets/TEngine/EntryPrefab/TEngine.prefab index 04049757..1246a00d 100644 --- a/Assets/TEngine/EntryPrefab/TEngine.prefab +++ b/Assets/TEngine/EntryPrefab/TEngine.prefab @@ -29,7 +29,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 3463045026180535779} - m_RootOrder: 0 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &3463045025307533305 MonoBehaviour: @@ -95,7 +95,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 3463045026180535779} - m_RootOrder: 3 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &3463045025737563820 MonoBehaviour: @@ -151,7 +151,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 3463045026180535779} - m_RootOrder: 4 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &3463045025836799504 MonoBehaviour: @@ -195,7 +195,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 3463045026180535779} - m_RootOrder: 1 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &3463045025974401033 MonoBehaviour: @@ -209,7 +209,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f010c29093f111146bfc776d19c8fb27, type: 3} m_Name: m_EditorClassIdentifier: - m_BuildInfoTextAsset: {fileID: 4900000, guid: d231f7a19087f02418363f9a6d5cb2c7, type: 3} + m_BuildInfoTextAsset: {fileID: 4900000, guid: d231f7a19087f02418363f9a6d5cb2c7, + type: 3} --- !u!1 &3463045026010536328 GameObject: m_ObjectHideFlags: 0 @@ -239,7 +240,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 3463045026180535779} - m_RootOrder: 5 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &3463045026010536330 MonoBehaviour: @@ -254,7 +255,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: ResourceMode: 1 - EditorResourceMode: 1 + m_ResourceHelperTypeName: TEngine.Runtime.DefaultResourceHelper + m_CustomResourceHelper: {fileID: 0} --- !u!1 &3463045026180535776 GameObject: m_ObjectHideFlags: 0 @@ -282,12 +284,12 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 3463045025307533286} - {fileID: 3463045025974401142} - {fileID: 3463045026377943188} - {fileID: 3463045025737563821} - {fileID: 3463045025836799505} - {fileID: 3463045026010536331} + - {fileID: 3463045025307533286} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -320,7 +322,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 3463045026180535779} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &3463045026377943191 MonoBehaviour: diff --git a/Assets/TEngine/Scripts/Editor/Helper/HelperInfo.cs b/Assets/TEngine/Scripts/Editor/Helper/HelperInfo.cs new file mode 100644 index 00000000..0b0902d5 --- /dev/null +++ b/Assets/TEngine/Scripts/Editor/Helper/HelperInfo.cs @@ -0,0 +1,90 @@ +using System.Collections.Generic; +using System.Text.RegularExpressions; +using TEngine.Runtime; +using UnityEditor; +using UnityEngine; + +namespace TEngine.Editor +{ + internal sealed class HelperInfo where T : MonoBehaviour + { + private const string CustomOptionName = ""; + + private readonly string m_Name; + + private SerializedProperty m_HelperTypeName; + private SerializedProperty m_CustomHelper; + private string[] m_HelperTypeNames; + private int m_HelperTypeNameIndex; + + public HelperInfo(string name) + { + m_Name = name; + + m_HelperTypeName = null; + m_CustomHelper = null; + m_HelperTypeNames = null; + m_HelperTypeNameIndex = 0; + } + + public void Init(SerializedObject serializedObject) + { + m_HelperTypeName = serializedObject.FindProperty(Utility.Text.Format("m_{0}HelperTypeName", m_Name)); + m_CustomHelper = serializedObject.FindProperty(Utility.Text.Format("m_Custom{0}Helper", m_Name)); + } + + public void Draw() + { + string displayName = FieldNameForDisplay(m_Name); + int selectedIndex = EditorGUILayout.Popup(Utility.Text.Format("{0} Helper", displayName), m_HelperTypeNameIndex, m_HelperTypeNames); + if (selectedIndex != m_HelperTypeNameIndex) + { + m_HelperTypeNameIndex = selectedIndex; + m_HelperTypeName.stringValue = selectedIndex <= 0 ? null : m_HelperTypeNames[selectedIndex]; + } + + if (m_HelperTypeNameIndex <= 0) + { + EditorGUILayout.PropertyField(m_CustomHelper); + if (m_CustomHelper.objectReferenceValue == null) + { + EditorGUILayout.HelpBox(Utility.Text.Format("You must set Custom {0} Helper.", displayName), MessageType.Error); + } + } + } + + public void Refresh() + { + List helperTypeNameList = new List + { + CustomOptionName + }; + + helperTypeNameList.AddRange(Type.GetRuntimeTypeNames(typeof(T))); + m_HelperTypeNames = helperTypeNameList.ToArray(); + + m_HelperTypeNameIndex = 0; + if (!string.IsNullOrEmpty(m_HelperTypeName.stringValue)) + { + m_HelperTypeNameIndex = helperTypeNameList.IndexOf(m_HelperTypeName.stringValue); + if (m_HelperTypeNameIndex <= 0) + { + m_HelperTypeNameIndex = 0; + m_HelperTypeName.stringValue = null; + } + } + } + + private string FieldNameForDisplay(string fieldName) + { + if (string.IsNullOrEmpty(fieldName)) + { + return string.Empty; + } + + string str = Regex.Replace(fieldName, @"^m_", string.Empty); + str = Regex.Replace(str, @"((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))", @" $1").TrimStart(); + return str; + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Editor/Helper/HelperInfo.cs.meta b/Assets/TEngine/Scripts/Editor/Helper/HelperInfo.cs.meta new file mode 100644 index 00000000..97cdaba3 --- /dev/null +++ b/Assets/TEngine/Scripts/Editor/Helper/HelperInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 094265dd50994f4e94edbb3efe3e2bd4 +timeCreated: 1662009511 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Editor/Inspector/ResourceComponentInspector.cs b/Assets/TEngine/Scripts/Editor/Inspector/ResourceComponentInspector.cs new file mode 100644 index 00000000..50b44923 --- /dev/null +++ b/Assets/TEngine/Scripts/Editor/Inspector/ResourceComponentInspector.cs @@ -0,0 +1,85 @@ +using System.Reflection; +using TEngine.Runtime; +using UnityEditor; + +namespace TEngine.Editor +{ + [CustomEditor(typeof(ResourceComponent))] + internal sealed class ResourceComponentInspector :TEngineInspector + { + private static readonly string[] ResourceModeNames = new string[] { "Package", "Updatable", "Updatable While Playing" }; + + private SerializedProperty m_ResourceMode = null; + + private HelperInfo m_ResourceHelperInfo = new HelperInfo("Resource"); + + private int m_ResourceModeIndex = 0; + + + private void OnEnable() + { + m_ResourceMode = serializedObject.FindProperty("ResourceMode"); + + m_ResourceHelperInfo.Init(serializedObject); + + RefreshModes(); + RefreshTypeNames(); + } + + private void RefreshModes() + { + m_ResourceModeIndex = m_ResourceMode.enumValueIndex > 0 ? m_ResourceMode.enumValueIndex - 1 : 0; + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + + serializedObject.Update(); + + ResourceComponent t = (ResourceComponent)target; + + EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); + { + if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject)) + { + EditorGUILayout.EnumPopup("Resource Mode", t.ResourceMode); + } + else + { + int selectedIndex = EditorGUILayout.Popup("Resource Mode", m_ResourceModeIndex, ResourceModeNames); + if (selectedIndex != m_ResourceModeIndex) + { + m_ResourceModeIndex = selectedIndex; + m_ResourceMode.enumValueIndex = selectedIndex + 1; + } + } + } + EditorGUI.EndDisabledGroup(); + + EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); + { + m_ResourceHelperInfo.Draw(); + } + + EditorGUI.EndDisabledGroup(); + + serializedObject.ApplyModifiedProperties(); + + Repaint(); + } + + protected override void OnCompileComplete() + { + base.OnCompileComplete(); + + RefreshTypeNames(); + } + + private void RefreshTypeNames() + { + m_ResourceHelperInfo.Refresh(); + serializedObject.ApplyModifiedProperties(); + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Editor/Inspector/ResourceComponentInspector.cs.meta b/Assets/TEngine/Scripts/Editor/Inspector/ResourceComponentInspector.cs.meta new file mode 100644 index 00000000..3ae27e67 --- /dev/null +++ b/Assets/TEngine/Scripts/Editor/Inspector/ResourceComponentInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 25466079bd094bc98a00b58d89febcf3 +timeCreated: 1662009376 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper.meta new file mode 100644 index 00000000..a2850984 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1913b7e1eaeb40f482e8d266edb4f37e +timeCreated: 1662006234 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetBundleData.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetBundleData.cs similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetBundleData.cs rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetBundleData.cs diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetBundleData.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetBundleData.cs.meta similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetBundleData.cs.meta rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetBundleData.cs.meta diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetConfig.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetConfig.cs similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetConfig.cs rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetConfig.cs diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetConfig.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetConfig.cs.meta similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetConfig.cs.meta rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetConfig.cs.meta diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetData.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetData.cs similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetData.cs rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetData.cs diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetData.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetData.cs.meta similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetData.cs.meta rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetData.cs.meta diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetTag.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetTag.cs similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetTag.cs rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetTag.cs diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/AssetTag.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetTag.cs.meta similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/AssetTag.cs.meta rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/AssetTag.cs.meta diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/DefaultResourceHelper.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/DefaultResourceHelper.cs new file mode 100644 index 00000000..9a4a000e --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/DefaultResourceHelper.cs @@ -0,0 +1,40 @@ +using System; +using UnityEngine; + +namespace TEngine.Runtime +{ + public class DefaultResourceHelper:ResourceHelperBase + { + public override GameObject Load(string path) + { + return ResMgr.Instance.Load(path); + } + + public override GameObject Load(string path, Transform parent) + { + var obj = Load(path); + + if (obj != null && parent != null) + { + obj.transform.SetParent(parent); + } + + return obj; + } + + public override T Load(string path) + { + return ResMgr.Instance.Load(path); + } + + public override void LoadAsync(string path, Action callBack) + { + ResMgr.Instance.GetGameObjectAsync(path, callBack); + } + + public override void LoadAsync(string path, Action callBack, bool withSubAsset = false) + { + ResMgr.Instance.GetAssetAtPathAsync(path, withSubAsset, callBack); + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/DefaultResourceHelper.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/DefaultResourceHelper.cs.meta new file mode 100644 index 00000000..b2fff463 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/DefaultResourceHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 66d70c0290ef4134b129edc6d77c5bed +timeCreated: 1662006279 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/ResMgr.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/ResMgr.cs similarity index 89% rename from Assets/TEngine/Scripts/Runtime/Core/Res/ResMgr.cs rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/ResMgr.cs index ec4177fd..fecebe99 100644 --- a/Assets/TEngine/Scripts/Runtime/Core/Res/ResMgr.cs +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/ResMgr.cs @@ -225,6 +225,37 @@ namespace TEngine.Runtime onComplete(GetGameObject(path)); #endif } + + public void GetAssetAtPathAsync(string path, bool withSubAssets, System.Action onComplete) where T : class + { + if (string.IsNullOrEmpty(path)) + { + onComplete(null); + } +#if ASSETBUNDLE_ENABLE + void CallBack(AssetData assetData) + { + if (assetData != null) + { + if (assetData.AssetObject is GameObject) + { + GameObject go = Object.Instantiate(assetData.AssetObject) as GameObject; + BindAssetData(go, assetData); + } + else + { + assetData.AddRef(); + } + assetData.OnAsyncLoadComplete -= CallBack; + + onComplete(assetData.AssetObject as T); + } + _assetConfig.GetAssetAtPathAsync(path, withSubAssets, CallBack); + } +#else + onComplete(GetAsset(path,withSubAssets)?.AssetObject as T); +#endif + } public void GetAssetAtPathAsync(string path, bool withSubAssets, System.Action onComplete) { diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/ResMgr.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/ResMgr.cs.meta similarity index 100% rename from Assets/TEngine/Scripts/Runtime/Core/Res/ResMgr.cs.meta rename to Assets/TEngine/Scripts/Runtime/Core/Res/DefaultResourcesHelper/ResMgr.cs.meta diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/IResourceHelper.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/IResourceHelper.cs new file mode 100644 index 00000000..b515c4a2 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/IResourceHelper.cs @@ -0,0 +1,95 @@ +using System; +using UnityEngine; + +namespace TEngine.Runtime +{ + /// + /// 游戏资源加载辅助器 + /// + public interface IResourceHelper + { + /// + /// 同步加载GameObject + /// + /// + /// + GameObject Load(string path); + + /// + /// 同步加载GameObject + /// + /// + /// + /// + GameObject Load(string path, Transform parent); + + /// + /// 同步加载泛型 + /// + /// + /// + /// + T Load(string path) where T : UnityEngine.Object; + + /// + /// 异步加载GameObject + /// + /// + /// + void LoadAsync(string path, Action callBack); + + /// + /// 异步加载泛型 + /// + /// + /// + /// + /// + void LoadAsync(string path, Action callBack, bool withSubAsset = false) where T : class; + } + + /// + /// 游戏资源加载辅助器基类 + /// + public abstract class ResourceHelperBase : UnityEngine.MonoBehaviour, IResourceHelper + { + /// + /// 同步加载GameObject + /// + /// + /// + public abstract GameObject Load(string path); + + /// + /// 同步加载GameObject + /// + /// + /// + /// + public abstract GameObject Load(string path, Transform parent); + + /// + /// 同步加载泛型 + /// + /// + /// + /// + public abstract T Load(string path) where T : UnityEngine.Object; + + /// + /// 异步加载GameObject + /// + /// + /// + public abstract void LoadAsync(string path, Action callBack); + + /// + /// 异步加载泛型 + /// + /// + /// + /// + /// + public abstract void LoadAsync(string path, Action callBack, bool withSubAsset = false) where T : class; + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/IResourceHelper.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/IResourceHelper.cs.meta new file mode 100644 index 00000000..d02b50c8 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/IResourceHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 43465b53b14046bd897a19f294a19685 +timeCreated: 1662005857 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/ResourceComponent.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/ResourceComponent.cs index 68711f54..348ee5c5 100644 --- a/Assets/TEngine/Scripts/Runtime/Core/Res/ResourceComponent.cs +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/ResourceComponent.cs @@ -12,18 +12,29 @@ namespace TEngine.Runtime { [SerializeField] public ResourceMode ResourceMode = ResourceMode.Package; - -#if UNITY_EDITOR - [SerializeField] public bool EditorResourceMode = true; -#else - private bool _editorResourceMode = false; - public bool EditorResourceMode => _editorResourceMode; -#endif - - public override void Awake() { base.Awake(); + + ResourceHelperBase resourceHelper = null; + + resourceHelper = Helper.CreateHelper(m_ResourceHelperTypeName, m_CustomResourceHelper); + if (resourceHelper == null) + { + Log.Error("Can not create resource helper."); + return; + } + + if (resourceHelper != null) + { + TResources.SetResourceHelper(resourceHelper); + } } + + [SerializeField] + private string m_ResourceHelperTypeName = "TEngine.Runtime.DefaultResourceHelper"; + + [SerializeField] + private ResourceHelperBase m_CustomResourceHelper = null; } } \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/TResource.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/TResource.cs index 6ab377c1..d4790e45 100644 --- a/Assets/TEngine/Scripts/Runtime/Core/Res/TResource.cs +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/TResource.cs @@ -6,39 +6,68 @@ namespace TEngine.Runtime /// /// 通用资源加载接口 /// - public static class TResources + public class TResources { - #region 同步加载 + private static IResourceHelper m_ResourceHelper; + /// + /// 设置游戏资源加载辅助器。 + /// + /// 游戏资源加载辅助器。 + public static void SetResourceHelper(IResourceHelper resourceHelper) + { + if (resourceHelper == null) + { + throw new Exception("Resources helper is invalid."); + } + + m_ResourceHelper = resourceHelper; + } + public static GameObject Load(string path) { - return ResMgr.Instance.Load(path); + if (m_ResourceHelper == null) + { + Log.Error("Resources helper is invalid."); + return null; + } + return m_ResourceHelper.Load(path); } public static GameObject Load(string path, Transform parent) { - var obj = Load(path); - - if (obj != null && parent != null) + if (m_ResourceHelper == null) { - obj.transform.SetParent(parent); + Log.Error("Resources helper is invalid."); + return null; } - - return obj; + return m_ResourceHelper.Load(path,parent); } public static T Load(string path) where T : UnityEngine.Object { - return ResMgr.Instance.Load(path); + if (m_ResourceHelper == null) + { + Log.Error("Resources helper is invalid."); + return null; + } + return m_ResourceHelper.Load(path); } - #endregion - #region 异步加载 public static void LoadAsync(string path, Action callBack) { - ResMgr.Instance.GetGameObjectAsync(path, callBack); + if (m_ResourceHelper == null) + { + Log.Error("Resources helper is invalid."); + return; + } + m_ResourceHelper.LoadAsync(path,callBack); } public static void LoadAsync(string path, Action callBack, bool withSubAsset = false) { - ResMgr.Instance.GetAssetAtPathAsync(path, withSubAsset, callBack); + if (m_ResourceHelper == null) + { + Log.Error("Resources helper is invalid."); + return; + } + m_ResourceHelper.LoadAsync(path,callBack,withSubAsset); } - #endregion } } \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper.meta new file mode 100644 index 00000000..c9e55956 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7fc4d5869442aff4d9ffc623d24c792f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper/TestResourceHelper.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper/TestResourceHelper.cs new file mode 100644 index 00000000..baf54418 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper/TestResourceHelper.cs @@ -0,0 +1,31 @@ +using System; +using TEngine.Runtime; +using UnityEngine; + +public class TestResourceHelper : ResourceHelperBase +{ + public override GameObject Load(string path) + { + throw new NotImplementedException(); + } + + public override GameObject Load(string path, Transform parent) + { + throw new NotImplementedException(); + } + + public override T Load(string path) + { + throw new NotImplementedException(); + } + + public override void LoadAsync(string path, Action callBack) + { + throw new NotImplementedException(); + } + + public override void LoadAsync(string path, Action callBack, bool withSubAsset = false) + { + throw new NotImplementedException(); + } +} diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper/TestResourceHelper.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper/TestResourceHelper.cs.meta new file mode 100644 index 00000000..8d59e828 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/TestResourceHelper/TestResourceHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86337800b6513e44ba3d9a553b4f6b47 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/GameProcedure/ProcedureSplash.cs b/Assets/TEngine/Scripts/Runtime/GameProcedure/ProcedureSplash.cs index 16b6c14e..4036ecda 100644 --- a/Assets/TEngine/Scripts/Runtime/GameProcedure/ProcedureSplash.cs +++ b/Assets/TEngine/Scripts/Runtime/GameProcedure/ProcedureSplash.cs @@ -27,12 +27,7 @@ namespace TEngine.Runtime // TODO: 这里可以播放一个 Splash 动画 // ... - if (ResourceComponent.Instance.EditorResourceMode == true) - { - Log.Info("编辑器模式 ChangeState"); - ChangeState(procedureOwner); - } - else if (ResourceComponent.Instance.ResourceMode == ResourceMode.Package) + if (ResourceComponent.Instance.ResourceMode == ResourceMode.Package) { Log.Info("单机模式 ChangeState"); ChangeState(procedureOwner);