├── .gitignore
├── Base
├── GF
│ ├── EventPool
│ │ ├── BaseEventArgs.cs
│ │ ├── EventPool.Event.cs
│ │ ├── EventPool.cs
│ │ └── EventPoolMode.cs
│ ├── GameFrameworkAction.cs
│ ├── GameFrameworkEntry.cs
│ ├── GameFrameworkEventArgs.cs
│ ├── GameFrameworkException.cs
│ ├── GameFrameworkFunc.cs
│ ├── GameFrameworkModule.cs
│ ├── ReferencePool
│ │ ├── IReference.cs
│ │ ├── ReferencePool.ReferenceCollection.cs
│ │ ├── ReferencePool.cs
│ │ └── ReferencePoolInfo.cs
│ └── TaskPool
│ │ ├── ITask.cs
│ │ ├── ITaskAgent.cs
│ │ └── TaskPool.cs
└── UnityGF
│ ├── BaseComponent.cs
│ ├── GameEntry.cs
│ └── ShutdownType.cs
├── Editor
├── AssetBundleAnalyzer
│ ├── AssetBundleAnalyzer.cs
│ ├── AssetBundleAnalyzerController.CircularDependencyChecker.cs
│ ├── AssetBundleAnalyzerController.Stamp.cs
│ ├── AssetBundleAnalyzerController.cs
│ ├── AssetsOrder.cs
│ ├── DependencyData.cs
│ └── ScatteredAssetsOrder.cs
├── AssetBundleBuilder
│ ├── AssetBundleBuilder.cs
│ ├── AssetBundleBuilderConfigPathAttribute.cs
│ ├── AssetBundleBuilderController.AssetBundleCode.cs
│ ├── AssetBundleBuilderController.AssetBundleData.cs
│ ├── AssetBundleBuilderController.AssetData.cs
│ ├── AssetBundleBuilderController.BuildReport.cs
│ ├── AssetBundleBuilderController.VersionListData.cs
│ ├── AssetBundleBuilderController.cs
│ ├── BuildAssetBundle.cs
│ └── IBuildEventHandler.cs
├── AssetBundleCollection
│ ├── Asset.cs
│ ├── AssetBundle.cs
│ ├── AssetBundleCollection.cs
│ ├── AssetBundleCollectionConfigPathAttribute.cs
│ ├── AssetBundleLoadType.cs
│ └── AssetBundleType.cs
├── AssetBundleEditor
│ ├── AssetBundleEditor.AssetBundleFolder.cs
│ ├── AssetBundleEditor.AssetBundleItem.cs
│ ├── AssetBundleEditor.MenuState.cs
│ ├── AssetBundleEditor.cs
│ ├── AssetBundleEditorConfigPathAttribute.cs
│ ├── AssetBundleEditorController.cs
│ ├── AssetSorterType.cs
│ ├── SourceAsset.cs
│ └── SourceFolder.cs
├── AssetBundleXml
│ └── CreateXml.cs
└── Misc
│ ├── BuildSettings.cs
│ ├── BuildSettingsConfigPathAttribute.cs
│ ├── ConfigPathAttribute.cs
│ ├── ContextMenu.cs
│ ├── Help.cs
│ ├── HelperInfo.cs
│ ├── LogRedirection.cs
│ ├── OpenFolder.cs
│ └── Type.cs
├── Events
├── GF
│ ├── EventManager.cs
│ ├── GameEventArgs.cs
│ └── IEventManager.cs
└── UnityGF
│ ├── Editor
│ └── EventComponentInspector.cs
│ └── EventComponent.cs
├── Example
├── AssetBundleEditor.xml
├── GameObject.prefab
├── TestAset
│ ├── Cube.prefab
│ └── Sphere.prefab
├── test.cs
└── test.unity
├── LICENSE
├── Libraries
└── ICSharpCode.SharpZipLib.dll
├── Log
└── GF
│ ├── Log.ILogHelper.cs
│ ├── Log.cs
│ └── LogLevel.cs
├── ObjectPool
├── GF
│ ├── IObjectPool.cs
│ ├── IObjectPoolManager.cs
│ ├── ObjectBase.cs
│ ├── ObjectInfo.cs
│ ├── ObjectPoolBase.cs
│ ├── ObjectPoolManager.Object.cs
│ ├── ObjectPoolManager.ObjectPool.cs
│ ├── ObjectPoolManager.cs
│ └── ReleaseObjectFilterCallback.cs
└── UnityGF
│ ├── Editor
│ └── ObjectPoolComponentInspector.cs
│ └── ObjectPoolComponent.cs
├── README.md
├── Resource
├── Impl
│ ├── GF
│ │ ├── Constant.cs
│ │ ├── DecryptResourceCallback.cs
│ │ ├── LoadAssetCallbacks.cs
│ │ ├── LoadAssetDependencyAssetCallback.cs
│ │ ├── LoadAssetFailureCallback.cs
│ │ ├── LoadAssetSuccessCallback.cs
│ │ ├── LoadAssetUpdateCallback.cs
│ │ ├── LoadBytesCallback.cs
│ │ ├── LoadResourceAgentHelperErrorEventArgs.cs
│ │ ├── LoadResourceAgentHelperLoadCompleteEventArgs.cs
│ │ ├── LoadResourceAgentHelperParseBytesCompleteEventArgs.cs
│ │ ├── LoadResourceAgentHelperReadBytesCompleteEventArgs.cs
│ │ ├── LoadResourceAgentHelperReadFileCompleteEventArgs.cs
│ │ ├── LoadResourceAgentHelperUpdateEventArgs.cs
│ │ ├── LoadResourceProgress.cs
│ │ ├── LoadResourceStatus.cs
│ │ ├── LoadSceneCallbacks.cs
│ │ ├── LoadSceneDependencyAssetCallback.cs
│ │ ├── LoadSceneFailureCallback.cs
│ │ ├── LoadSceneSuccessCallback.cs
│ │ ├── LoadSceneUpdateCallback.cs
│ │ ├── ResourceInitCompleteEventArgs.cs
│ │ ├── ResourceManager.AssetDependencyInfo.cs
│ │ ├── ResourceManager.AssetInfo.cs
│ │ ├── ResourceManager.LoadType.cs
│ │ ├── ResourceManager.ReadWriteResourceInfo.cs
│ │ ├── ResourceManager.ResourceGroup.cs
│ │ ├── ResourceManager.ResourceInfo.cs
│ │ ├── ResourceManager.ResourceIniter.cs
│ │ ├── ResourceManager.ResourceLoader.AssetObject.cs
│ │ ├── ResourceManager.ResourceLoader.LoadAssetTask.cs
│ │ ├── ResourceManager.ResourceLoader.LoadDependencyAssetTask.cs
│ │ ├── ResourceManager.ResourceLoader.LoadResourceAgent.WaitingType.cs
│ │ ├── ResourceManager.ResourceLoader.LoadResourceAgent.cs
│ │ ├── ResourceManager.ResourceLoader.LoadResourceTaskBase.cs
│ │ ├── ResourceManager.ResourceLoader.LoadSceneTask.cs
│ │ ├── ResourceManager.ResourceLoader.ResourceObject.cs
│ │ ├── ResourceManager.ResourceLoader.cs
│ │ ├── ResourceManager.ResourceName.cs
│ │ ├── ResourceManager.ResourceNameComparer.cs
│ │ ├── ResourceManager.cs
│ │ ├── ResourceMode.cs
│ │ ├── UnloadSceneCallbacks.cs
│ │ ├── UnloadSceneFailureCallback.cs
│ │ └── UnloadSceneSuccessCallback.cs
│ └── UnityGF
│ │ ├── Editor
│ │ ├── GameFrameworkInspector.cs
│ │ └── ResourceComponentInspector.cs
│ │ └── Runtime
│ │ ├── DefaultLoadResourceAgentHelper.cs
│ │ ├── DefaultResourceHelper.cs
│ │ ├── EditorResourceComponent.cs
│ │ ├── LoadResourceAgentHelperBase.cs
│ │ ├── ReadWritePathType.cs
│ │ ├── ResourceComponent.cs
│ │ ├── ResourceHelperBase.cs
│ │ ├── ResourceInitCompleteEventArgs.cs
│ │ └── SceneAsset.cs
└── Interface
│ ├── ILoadResourceAgentHelper.cs
│ ├── IResourceHelper.cs
│ └── IResourceManager.cs
├── Scene
├── GF
│ ├── ISceneManager.cs
│ ├── LoadSceneDependencyAssetEventArgs.cs
│ ├── LoadSceneFailureEventArgs.cs
│ ├── LoadSceneSuccessEventArgs.cs
│ ├── LoadSceneUpdateEventArgs.cs
│ ├── SceneManager.cs
│ ├── UnloadSceneFailureEventArgs.cs
│ └── UnloadSceneSuccessEventArgs.cs
└── UnityGF
│ ├── Editor
│ └── SceneComponentInspector.cs
│ ├── LoadSceneDependencyAssetEventArgs.cs
│ ├── LoadSceneFailureEventArgs.cs
│ ├── LoadSceneSuccessEventArgs.cs
│ ├── LoadSceneUpdateEventArgs.cs
│ ├── SceneComponent.cs
│ ├── UnloadSceneFailureEventArgs.cs
│ └── UnloadSceneSuccessEventArgs.cs
└── Utility
├── Assembly.cs
├── Converter.cs
├── Encryption.cs
├── Path.cs
├── Random.cs
├── Text.cs
├── Unity
├── DefaultZipHelper.cs
├── Helper.cs
└── UnityExtension.cs
├── Utility.cs
├── Verifier.Crc32.cs
├── Verifier.cs
├── Zip.IZipHelper.cs
└── Zip.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 | [Bb]uild/
5 | [Bb]uilds/
6 | Assets/AssetStoreTools*
7 |
8 | # Visual Studio cache directory
9 | .vs/
10 |
11 | # Autogenerated VS/MD/Consulo solution and project files
12 | ExportedObj/
13 | .consulo/
14 | *.csproj
15 | *.unityproj
16 | *.sln
17 | *.suo
18 | *.tmp
19 | *.user
20 | *.userprefs
21 | *.pidb
22 | *.booproj
23 | *.svd
24 | *.pdb
25 | *.opendb
26 |
27 | # Unity3D generated meta files
28 | *.pidb.meta
29 | *.pdb.meta
30 | *.meta
31 |
32 | # Unity3D Generated File On Crash Reports
33 | sysinfo.txt
34 |
35 | # Builds
36 | *.apk
37 | *.unitypackage
38 |
--------------------------------------------------------------------------------
/Base/GF/EventPool/BaseEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 事件基类。
12 | ///
13 | public abstract class BaseEventArgs : GameFrameworkEventArgs, IReference
14 | {
15 | ///
16 | /// 获取类型编号。
17 | ///
18 | public abstract int Id
19 | {
20 | get;
21 | }
22 |
23 | ///
24 | /// 清理引用。
25 | ///
26 | public abstract void Clear();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Base/GF/EventPool/EventPool.Event.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | internal partial class EventPool
11 | {
12 | ///
13 | /// 事件结点。
14 | ///
15 | private sealed class Event
16 | {
17 | private readonly object m_Sender;
18 | private readonly T m_EventArgs;
19 |
20 | public Event(object sender, T e)
21 | {
22 | m_Sender = sender;
23 | m_EventArgs = e;
24 | }
25 |
26 | public object Sender
27 | {
28 | get
29 | {
30 | return m_Sender;
31 | }
32 | }
33 |
34 | public T EventArgs
35 | {
36 | get
37 | {
38 | return m_EventArgs;
39 | }
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Base/GF/EventPool/EventPoolMode.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework
11 | {
12 | ///
13 | /// 事件池模式。
14 | ///
15 | [Flags]
16 | internal enum EventPoolMode
17 | {
18 | ///
19 | /// 默认事件池模式,即必须存在有且只有一个事件处理函数。
20 | ///
21 | Default = 0,
22 |
23 | ///
24 | /// 允许不存在事件处理函数。
25 | ///
26 | AllowNoHandler = 1,
27 |
28 | ///
29 | /// 允许存在多个事件处理函数。
30 | ///
31 | AllowMultiHandler = 2,
32 |
33 | ///
34 | /// 允许存在重复的事件处理函数。
35 | ///
36 | AllowDuplicateHandler = 4,
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Base/GF/GameFrameworkEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework
11 | {
12 | ///
13 | /// 游戏框架中包含事件数据的类的基类。
14 | ///
15 | public abstract class GameFrameworkEventArgs : EventArgs
16 | {
17 | ///
18 | /// 初始化游戏框架中包含事件数据的类的新实例。
19 | ///
20 | public GameFrameworkEventArgs()
21 | {
22 |
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Base/GF/GameFrameworkException.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 | using System.Runtime.Serialization;
10 |
11 | namespace GameFramework
12 | {
13 | ///
14 | /// 游戏框架异常类。
15 | ///
16 | [Serializable]
17 | public class GameFrameworkException : Exception
18 | {
19 | ///
20 | /// 初始化游戏框架异常类的新实例。
21 | ///
22 | public GameFrameworkException()
23 | : base()
24 | {
25 |
26 | }
27 |
28 | ///
29 | /// 使用指定错误消息初始化游戏框架异常类的新实例。
30 | ///
31 | /// 描述错误的消息。
32 | public GameFrameworkException(string message)
33 | : base(message)
34 | {
35 |
36 | }
37 |
38 | ///
39 | /// 使用指定错误消息和对作为此异常原因的内部异常的引用来初始化游戏框架异常类的新实例。
40 | ///
41 | /// 解释异常原因的错误消息。
42 | /// 导致当前异常的异常。如果 innerException 参数不为空引用,则在处理内部异常的 catch 块中引发当前异常。
43 | public GameFrameworkException(string message, Exception innerException)
44 | : base(message, innerException)
45 | {
46 |
47 | }
48 |
49 | ///
50 | /// 用序列化数据初始化游戏框架异常类的新实例。
51 | ///
52 | /// 存有有关所引发异常的序列化的对象数据。
53 | /// 包含有关源或目标的上下文信息。
54 | protected GameFrameworkException(SerializationInfo info, StreamingContext context)
55 | : base(info, context)
56 | {
57 |
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Base/GF/GameFrameworkModule.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 游戏框架模块抽象类。
12 | ///
13 | internal abstract class GameFrameworkModule
14 | {
15 | ///
16 | /// 获取游戏框架模块优先级。
17 | ///
18 | /// 优先级较高的模块会优先轮询,并且关闭操作会后进行。
19 | internal virtual int Priority
20 | {
21 | get
22 | {
23 | return 0;
24 | }
25 | }
26 |
27 | ///
28 | /// 游戏框架模块轮询。
29 | ///
30 | /// 逻辑流逝时间,以秒为单位。
31 | /// 真实流逝时间,以秒为单位。
32 | internal abstract void Update(float elapseSeconds, float realElapseSeconds);
33 |
34 | ///
35 | /// 关闭并清理游戏框架模块。
36 | ///
37 | internal abstract void Shutdown();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Base/GF/ReferencePool/IReference.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 引用接口。
12 | ///
13 | public interface IReference
14 | {
15 | ///
16 | /// 清理引用。
17 | ///
18 | void Clear();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Base/GF/ReferencePool/ReferencePoolInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 引用池信息。
12 | ///
13 | public sealed class ReferencePoolInfo
14 | {
15 | private readonly string m_TypeName;
16 | private readonly int m_UnusedReferenceCount;
17 | private readonly int m_UsingReferenceCount;
18 | private readonly int m_AcquireReferenceCount;
19 | private readonly int m_ReleaseReferenceCount;
20 | private readonly int m_AddReferenceCount;
21 | private readonly int m_RemoveReferenceCount;
22 |
23 | ///
24 | /// 初始化引用池信息的新实例。
25 | ///
26 | /// 引用池类型名称。
27 | /// 未使用引用数量。
28 | /// 正在使用引用数量。
29 | /// 获取引用数量。
30 | /// 归还引用数量。
31 | /// 增加引用数量。
32 | /// 移除引用数量。
33 | public ReferencePoolInfo(string typeName, int unusedReferenceCount, int usingReferenceCount, int acquireReferenceCount, int releaseReferenceCount, int addReferenceCount, int removeReferenceCount)
34 | {
35 | m_TypeName = typeName;
36 | m_UnusedReferenceCount = unusedReferenceCount;
37 | m_UsingReferenceCount = usingReferenceCount;
38 | m_AcquireReferenceCount = acquireReferenceCount;
39 | m_ReleaseReferenceCount = releaseReferenceCount;
40 | m_AddReferenceCount = addReferenceCount;
41 | m_RemoveReferenceCount = removeReferenceCount;
42 | }
43 |
44 | ///
45 | /// 获取引用池类型名称。
46 | ///
47 | public string TypeName
48 | {
49 | get
50 | {
51 | return m_TypeName;
52 | }
53 | }
54 |
55 | ///
56 | /// 获取未使用引用数量。
57 | ///
58 | public int UnusedReferenceCount
59 | {
60 | get
61 | {
62 | return m_UnusedReferenceCount;
63 | }
64 | }
65 |
66 | ///
67 | /// 获取正在使用引用数量。
68 | ///
69 | public int UsingReferenceCount
70 | {
71 | get
72 | {
73 | return m_UsingReferenceCount;
74 | }
75 | }
76 |
77 | ///
78 | /// 获取获取引用数量。
79 | ///
80 | public int AcquireReferenceCount
81 | {
82 | get
83 | {
84 | return m_AcquireReferenceCount;
85 | }
86 | }
87 |
88 | ///
89 | /// 获取归还引用数量。
90 | ///
91 | public int ReleaseReferenceCount
92 | {
93 | get
94 | {
95 | return m_ReleaseReferenceCount;
96 | }
97 | }
98 |
99 | ///
100 | /// 获取增加引用数量。
101 | ///
102 | public int AddReferenceCount
103 | {
104 | get
105 | {
106 | return m_AddReferenceCount;
107 | }
108 | }
109 |
110 | ///
111 | /// 获取移除引用数量。
112 | ///
113 | public int RemoveReferenceCount
114 | {
115 | get
116 | {
117 | return m_RemoveReferenceCount;
118 | }
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/Base/GF/TaskPool/ITask.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 任务接口。
12 | ///
13 | internal interface ITask
14 | {
15 | ///
16 | /// 获取任务的序列编号。
17 | ///
18 | int SerialId
19 | {
20 | get;
21 | }
22 |
23 | ///
24 | /// 获取任务的优先级。
25 | ///
26 | int Priority
27 | {
28 | get;
29 | }
30 |
31 | ///
32 | /// 获取任务是否完成。
33 | ///
34 | bool Done
35 | {
36 | get;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Base/GF/TaskPool/ITaskAgent.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 任务代理接口。
12 | ///
13 | /// 任务类型。
14 | internal interface ITaskAgent where T : ITask
15 | {
16 | ///
17 | /// 获取任务。
18 | ///
19 | T Task
20 | {
21 | get;
22 | }
23 |
24 | ///
25 | /// 初始化任务代理。
26 | ///
27 | void Initialize();
28 |
29 | ///
30 | /// 任务代理轮询。
31 | ///
32 | /// 逻辑流逝时间,以秒为单位。
33 | /// 真实流逝时间,以秒为单位。
34 | void Update(float elapseSeconds, float realElapseSeconds);
35 |
36 | ///
37 | /// 关闭并清理任务代理。
38 | ///
39 | void Shutdown();
40 |
41 | ///
42 | /// 开始处理任务。
43 | ///
44 | /// 要处理的任务。
45 | void Start(T task);
46 |
47 | ///
48 | /// 停止正在处理的任务并重置任务代理。
49 | ///
50 | void Reset();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Base/UnityGF/BaseComponent.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using GameFramework;
4 | using GameFramework.Resource;
5 | using UnityEngine;
6 |
7 | namespace UnityGameFramework.Runtime
8 | {
9 | public class BaseComponent : MonoBehaviour
10 | {
11 | public bool EditorResourceMode;
12 | public IResourceManager EditorResourceHelper;
13 |
14 | void Awake()
15 | {
16 | GameEntry.RegisterComponent(this);
17 | }
18 | // Use this for initialization
19 | void Start()
20 | {
21 |
22 | }
23 |
24 | // Update is called once per frame
25 | void Update()
26 | {
27 | GameFrameworkEntry.Update(Time.deltaTime, Time.unscaledDeltaTime);
28 | }
29 |
30 | private void OnDestroy()
31 | {
32 | #if UNITY_5_6_OR_NEWER
33 | Application.lowMemory -= OnLowMemory;
34 | #endif
35 | GameFrameworkEntry.Shutdown();
36 | }
37 |
38 |
39 | private void OnLowMemory()
40 | {
41 | Log.Info("Low memory reported...");
42 |
43 | ObjectPoolComponent objectPoolComponent = GameEntry.GetComponent();
44 | if (objectPoolComponent != null)
45 | {
46 | objectPoolComponent.ReleaseAllUnused();
47 | }
48 |
49 | ResourceComponent resourceCompoent = GameEntry.GetComponent();
50 | if (resourceCompoent != null)
51 | {
52 | resourceCompoent.ForceUnloadUnusedAssets(true);
53 | }
54 | }
55 |
56 | internal void Shutdown()
57 | {
58 | Destroy(gameObject);
59 | }
60 | }
61 |
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/Base/UnityGF/ShutdownType.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Runtime
9 | {
10 | ///
11 | /// 关闭游戏框架类型。
12 | ///
13 | public enum ShutdownType
14 | {
15 | ///
16 | /// 仅关闭游戏框架。
17 | ///
18 | None = 0,
19 |
20 | ///
21 | /// 关闭游戏框架并重启游戏。
22 | ///
23 | Restart,
24 |
25 | ///
26 | /// 关闭游戏框架并退出游戏。
27 | ///
28 | Quit,
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Editor/AssetBundleAnalyzer/AssetBundleAnalyzerController.CircularDependencyChecker.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System.Collections.Generic;
9 | using System.Linq;
10 |
11 | namespace UnityGameFramework.Editor.AssetBundleTools
12 | {
13 | internal sealed partial class AssetBundleAnalyzerController
14 | {
15 | private sealed class CircularDependencyChecker
16 | {
17 | private readonly Stamp[] m_Stamps;
18 |
19 | public CircularDependencyChecker(Stamp[] stamps)
20 | {
21 | m_Stamps = stamps;
22 | }
23 |
24 | public string[][] Check()
25 | {
26 | HashSet hosts = new HashSet();
27 | foreach (Stamp stamp in m_Stamps)
28 | {
29 | hosts.Add(stamp.HostAssetName);
30 | }
31 |
32 | List results = new List();
33 | foreach (string host in hosts)
34 | {
35 | LinkedList route = new LinkedList();
36 | HashSet visited = new HashSet();
37 | if (Check(host, route, visited))
38 | {
39 | results.Add(route.ToArray());
40 | }
41 | }
42 |
43 | return results.ToArray();
44 | }
45 |
46 | private bool Check(string host, LinkedList route, HashSet visited)
47 | {
48 | visited.Add(host);
49 | route.AddLast(host);
50 |
51 | foreach (Stamp stamp in m_Stamps)
52 | {
53 | if (host != stamp.HostAssetName)
54 | {
55 | continue;
56 | }
57 |
58 | if (visited.Contains(stamp.DependencyAssetName))
59 | {
60 | route.AddLast(stamp.DependencyAssetName);
61 | return true;
62 | }
63 |
64 | if (Check(stamp.DependencyAssetName, route, visited))
65 | {
66 | return true;
67 | }
68 | }
69 |
70 | route.RemoveLast();
71 | visited.Remove(host);
72 | return false;
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Editor/AssetBundleAnalyzer/AssetBundleAnalyzerController.Stamp.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | internal sealed partial class AssetBundleAnalyzerController
11 | {
12 | private struct Stamp
13 | {
14 | private readonly string m_HostAssetName;
15 | private readonly string m_DependencyAssetName;
16 |
17 | public Stamp(string hostAssetName, string dependencyAssetName)
18 | {
19 | m_HostAssetName = hostAssetName;
20 | m_DependencyAssetName = dependencyAssetName;
21 | }
22 |
23 | public string HostAssetName
24 | {
25 | get
26 | {
27 | return m_HostAssetName;
28 | }
29 | }
30 |
31 | public string DependencyAssetName
32 | {
33 | get
34 | {
35 | return m_DependencyAssetName;
36 | }
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Editor/AssetBundleAnalyzer/AssetsOrder.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | internal enum AssetsOrder
11 | {
12 | AssetNameAsc,
13 | AssetNameDesc,
14 | DependencyAssetBundleCountAsc,
15 | DependencyAssetBundleCountDesc,
16 | DependencyAssetCountAsc,
17 | DependencyAssetCountDesc,
18 | ScatteredDependencyAssetCountAsc,
19 | ScatteredDependencyAssetCountDesc,
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Editor/AssetBundleAnalyzer/DependencyData.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace UnityGameFramework.Editor.AssetBundleTools
11 | {
12 | internal sealed class DependencyData
13 | {
14 | private List m_DependencyAssetBundles;
15 | private List m_DependencyAssets;
16 | private List m_ScatteredDependencyAssetNames;
17 |
18 | public DependencyData()
19 | {
20 | m_DependencyAssetBundles = new List();
21 | m_DependencyAssets = new List();
22 | m_ScatteredDependencyAssetNames = new List();
23 | }
24 |
25 | public int DependencyAssetBundleCount
26 | {
27 | get
28 | {
29 | return m_DependencyAssetBundles.Count;
30 | }
31 | }
32 |
33 | public int DependencyAssetCount
34 | {
35 | get
36 | {
37 | return m_DependencyAssets.Count;
38 | }
39 | }
40 |
41 | public int ScatteredDependencyAssetCount
42 | {
43 | get
44 | {
45 | return m_ScatteredDependencyAssetNames.Count;
46 | }
47 | }
48 |
49 | public void AddDependencyAsset(Asset asset)
50 | {
51 | if (!m_DependencyAssetBundles.Contains(asset.AssetBundle))
52 | {
53 | m_DependencyAssetBundles.Add(asset.AssetBundle);
54 | }
55 |
56 | m_DependencyAssets.Add(asset);
57 | }
58 |
59 | public void AddScatteredDependencyAsset(string dependencyAssetName)
60 | {
61 | m_ScatteredDependencyAssetNames.Add(dependencyAssetName);
62 | }
63 |
64 | public AssetBundle[] GetDependencyAssetBundles()
65 | {
66 | return m_DependencyAssetBundles.ToArray();
67 | }
68 |
69 | public Asset[] GetDependencyAssets()
70 | {
71 | return m_DependencyAssets.ToArray();
72 | }
73 |
74 | public string[] GetScatteredDependencyAssetNames()
75 | {
76 | return m_ScatteredDependencyAssetNames.ToArray();
77 | }
78 |
79 | public void RefreshData()
80 | {
81 | m_DependencyAssetBundles.Sort(DependencyAssetBundlesComparer);
82 | m_DependencyAssets.Sort(DependencyAssetsComparer);
83 | m_ScatteredDependencyAssetNames.Sort();
84 | }
85 |
86 | private int DependencyAssetBundlesComparer(AssetBundle a, AssetBundle b)
87 | {
88 | return a.FullName.CompareTo(b.FullName);
89 | }
90 |
91 | private int DependencyAssetsComparer(Asset a, Asset b)
92 | {
93 | return a.Name.CompareTo(b.Name);
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/Editor/AssetBundleAnalyzer/ScatteredAssetsOrder.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | internal enum ScatteredAssetsOrder
11 | {
12 | AssetNameAsc,
13 | AssetNameDesc,
14 | HostAssetCountAsc,
15 | HostAssetCountDesc,
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Editor/AssetBundleBuilder/AssetBundleBuilderConfigPathAttribute.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | ///
11 | /// AssetBundleBuilder 配置路径属性。
12 | ///
13 | public sealed class AssetBundleBuilderConfigPathAttribute : ConfigPathAttribute
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Editor/AssetBundleBuilder/AssetBundleBuilderController.AssetBundleCode.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using UnityEditor;
9 |
10 | namespace UnityGameFramework.Editor.AssetBundleTools
11 | {
12 | internal partial class AssetBundleBuilderController
13 | {
14 | private sealed class AssetBundleCode
15 | {
16 | private readonly BuildTarget m_BuildTarget;
17 | private readonly int m_Length;
18 | private readonly int m_HashCode;
19 | private readonly int m_ZipLength;
20 | private readonly int m_ZipHashCode;
21 |
22 | public AssetBundleCode(BuildTarget buildTarget, int length, int hashCode, int zipLength, int zipHashCode)
23 | {
24 | m_BuildTarget = buildTarget;
25 | m_Length = length;
26 | m_HashCode = hashCode;
27 | m_ZipLength = zipLength;
28 | m_ZipHashCode = zipHashCode;
29 | }
30 |
31 | public BuildTarget BuildTarget
32 | {
33 | get
34 | {
35 | return m_BuildTarget;
36 | }
37 | }
38 |
39 | public int Length
40 | {
41 | get
42 | {
43 | return m_Length;
44 | }
45 | }
46 |
47 | public int HashCode
48 | {
49 | get
50 | {
51 | return m_HashCode;
52 | }
53 | }
54 |
55 | public int ZipLength
56 | {
57 | get
58 | {
59 | return m_ZipLength;
60 | }
61 | }
62 |
63 | public int ZipHashCode
64 | {
65 | get
66 | {
67 | return m_ZipHashCode;
68 | }
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Editor/AssetBundleBuilder/AssetBundleBuilderController.AssetData.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | internal partial class AssetBundleBuilderController
11 | {
12 | private sealed class AssetData
13 | {
14 | private readonly string m_Guid;
15 | private readonly string m_Name;
16 | private readonly int m_Length;
17 | private readonly int m_HashCode;
18 | private readonly string[] m_DependencyAssetNames;
19 |
20 | public AssetData(string guid, string name, int length, int hashCode, string[] dependencyAssetNames)
21 | {
22 | m_Guid = guid;
23 | m_Name = name;
24 | m_Length = length;
25 | m_HashCode = hashCode;
26 | m_DependencyAssetNames = dependencyAssetNames;
27 | }
28 |
29 | public string Guid
30 | {
31 | get
32 | {
33 | return m_Guid;
34 | }
35 | }
36 |
37 | public string Name
38 | {
39 | get
40 | {
41 | return m_Name;
42 | }
43 | }
44 |
45 | public int Length
46 | {
47 | get
48 | {
49 | return m_Length;
50 | }
51 | }
52 |
53 | public int HashCode
54 | {
55 | get
56 | {
57 | return m_HashCode;
58 | }
59 | }
60 |
61 | public string[] GetDependencyAssetNames()
62 | {
63 | return m_DependencyAssetNames;
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Editor/AssetBundleBuilder/AssetBundleBuilderController.VersionListData.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | internal partial class AssetBundleBuilderController
11 | {
12 | private sealed class VersionListData
13 | {
14 | public VersionListData(string path, int length, int hashCode, int zipLength, int zipHashCode)
15 | {
16 | Path = path;
17 | Length = length;
18 | HashCode = hashCode;
19 | ZipLength = zipLength;
20 | ZipHashCode = zipHashCode;
21 | }
22 |
23 | public string Path
24 | {
25 | get;
26 | private set;
27 | }
28 |
29 | public int Length
30 | {
31 | get;
32 | private set;
33 | }
34 |
35 | public int HashCode
36 | {
37 | get;
38 | private set;
39 | }
40 |
41 | public int ZipLength
42 | {
43 | get;
44 | private set;
45 | }
46 |
47 | public int ZipHashCode
48 | {
49 | get;
50 | private set;
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Editor/AssetBundleBuilder/BuildAssetBundle.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using UnityEditor;
10 | using UnityEngine;
11 |
12 | namespace UnityGameFramework.Editor.AssetBundleTools
13 | {
14 | ///
15 | /// 生成资源包。
16 | ///
17 | internal sealed class BuildAssetBundle
18 | {
19 | ///
20 | /// 运行生成资源包。
21 | ///
22 | [MenuItem("Game Framework/AssetBundle Tools/Build AssetBundle", false, 30)]
23 | private static void Run()
24 | {
25 | AssetBundleBuilderController controller = new AssetBundleBuilderController();
26 | if (!controller.Load())
27 | {
28 | throw new GameFrameworkException("Load configuration failure.");
29 | }
30 | else
31 | {
32 | Debug.Log("Load configuration success.");
33 | }
34 |
35 | if (!controller.IsValidOutputDirectory)
36 | {
37 | throw new GameFrameworkException(string.Format("Output directory '{0}' is invalid.", controller.OutputDirectory));
38 | }
39 |
40 | if (!controller.BuildAssetBundles())
41 | {
42 | throw new GameFrameworkException("Build AssetBundles failure.");
43 | }
44 | else
45 | {
46 | Debug.Log("Build AssetBundles success.");
47 | controller.Save();
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Editor/AssetBundleCollection/Asset.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using UnityEditor;
9 |
10 | namespace UnityGameFramework.Editor.AssetBundleTools
11 | {
12 | ///
13 | /// 资源。
14 | ///
15 | internal sealed class Asset
16 | {
17 | private Asset(string guid, AssetBundle assetBundle)
18 | {
19 | Guid = guid;
20 | AssetBundle = assetBundle;
21 | }
22 |
23 | public string Guid
24 | {
25 | get;
26 | private set;
27 | }
28 |
29 | public string Name
30 | {
31 | get
32 | {
33 | return AssetDatabase.GUIDToAssetPath(Guid);
34 | }
35 | }
36 |
37 | public AssetBundle AssetBundle
38 | {
39 | get;
40 | private set;
41 | }
42 |
43 | public static Asset Create(string guid)
44 | {
45 | return new Asset(guid, null);
46 | }
47 |
48 | public static Asset Create(string guid, AssetBundle assetBundle)
49 | {
50 | return new Asset(guid, assetBundle);
51 | }
52 |
53 | public void SetAssetBundle(AssetBundle assetBundle)
54 | {
55 | AssetBundle = assetBundle;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Editor/AssetBundleCollection/AssetBundle.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace UnityGameFramework.Editor.AssetBundleTools
11 | {
12 | ///
13 | /// 资源包。
14 | ///
15 | internal sealed class AssetBundle
16 | {
17 | private readonly List m_Assets;
18 |
19 | private AssetBundle(string name, string variant, AssetBundleLoadType loadType, bool packed)
20 | {
21 | m_Assets = new List();
22 |
23 | Name = name;
24 | Variant = variant;
25 | Type = AssetBundleType.Unknown;
26 | LoadType = loadType;
27 | Packed = packed;
28 | }
29 |
30 | public string Name
31 | {
32 | get;
33 | private set;
34 | }
35 |
36 | public string Variant
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | public string FullName
43 | {
44 | get
45 | {
46 | return Variant != null ? string.Format("{0}.{1}", Name, Variant) : Name;
47 | }
48 | }
49 |
50 | public AssetBundleType Type
51 | {
52 | get;
53 | private set;
54 | }
55 |
56 | public AssetBundleLoadType LoadType
57 | {
58 | get;
59 | private set;
60 | }
61 |
62 | public bool Packed
63 | {
64 | get;
65 | private set;
66 | }
67 |
68 | public static AssetBundle Create(string name, string variant, AssetBundleLoadType loadType, bool packed)
69 | {
70 | return new AssetBundle(name, variant, loadType, packed);
71 | }
72 |
73 | public Asset[] GetAssets()
74 | {
75 | return m_Assets.ToArray();
76 | }
77 |
78 | public void Rename(string name, string variant)
79 | {
80 | Name = name;
81 | Variant = variant;
82 | }
83 |
84 | public void SetLoadType(AssetBundleLoadType loadType)
85 | {
86 | LoadType = loadType;
87 | }
88 |
89 | public void SetPacked(bool packed)
90 | {
91 | Packed = packed;
92 | }
93 |
94 | public void AssignAsset(Asset asset, bool isScene)
95 | {
96 | if (asset.AssetBundle != null)
97 | {
98 | asset.AssetBundle.Unassign(asset);
99 | }
100 |
101 | Type = isScene ? AssetBundleType.Scene : AssetBundleType.Asset;
102 | asset.SetAssetBundle(this);
103 | m_Assets.Add(asset);
104 | m_Assets.Sort(AssetComparer);
105 | }
106 |
107 | public void Unassign(Asset asset)
108 | {
109 | asset.SetAssetBundle(null);
110 | m_Assets.Remove(asset);
111 | if (m_Assets.Count <= 0)
112 | {
113 | Type = AssetBundleType.Unknown;
114 | }
115 | }
116 |
117 | public void Clear()
118 | {
119 | foreach (Asset asset in m_Assets)
120 | {
121 | asset.SetAssetBundle(null);
122 | }
123 |
124 | m_Assets.Clear();
125 | }
126 |
127 | private int AssetComparer(Asset a, Asset b)
128 | {
129 | return a.Guid.CompareTo(b.Guid);
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/Editor/AssetBundleCollection/AssetBundleCollectionConfigPathAttribute.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | ///
11 | /// AssetBundleCollection 配置路径属性。
12 | ///
13 | public sealed class AssetBundleCollectionConfigPathAttribute : ConfigPathAttribute
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Editor/AssetBundleCollection/AssetBundleLoadType.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | ///
11 | /// 资源加载方式类型。
12 | ///
13 | internal enum AssetBundleLoadType
14 | {
15 | ///
16 | /// 从文件加载。
17 | ///
18 | LoadFromFile = 0,
19 |
20 | ///
21 | /// 从内存加载。
22 | ///
23 | LoadFromMemory,
24 |
25 | ///
26 | /// 从内存快速解密加载。
27 | ///
28 | LoadFromMemoryAndQuickDecrypt,
29 |
30 | ///
31 | /// 从内存解密加载。
32 | ///
33 | LoadFromMemoryAndDecrypt,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Editor/AssetBundleCollection/AssetBundleType.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | ///
11 | /// 资源包类型。
12 | ///
13 | internal enum AssetBundleType
14 | {
15 | ///
16 | /// 未知。
17 | ///
18 | Unknown = 0,
19 |
20 | ///
21 | /// 存放资源的资源包。
22 | ///
23 | Asset,
24 |
25 | ///
26 | /// 存放场景的资源包。
27 | ///
28 | Scene,
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Editor/AssetBundleEditor/AssetBundleEditor.AssetBundleItem.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using UnityEditor;
10 | using UnityEngine;
11 |
12 | namespace UnityGameFramework.Editor.AssetBundleTools
13 | {
14 | internal partial class AssetBundleEditor
15 | {
16 | private sealed class AssetBundleItem
17 | {
18 | private static Texture s_CachedUnknownIcon = null;
19 | private static Texture s_CachedAssetIcon = null;
20 | private static Texture s_CachedSceneIcon = null;
21 |
22 | public AssetBundleItem(string name, AssetBundle assetBundle, AssetBundleFolder folder)
23 | {
24 | if (assetBundle == null)
25 | {
26 | throw new GameFrameworkException("AssetBundle is invalid.");
27 | }
28 |
29 | if (folder == null)
30 | {
31 | throw new GameFrameworkException("AssetBundle folder is invalid.");
32 | }
33 |
34 | Name = name;
35 | AssetBundle = assetBundle;
36 | Folder = folder;
37 | }
38 |
39 | public string Name
40 | {
41 | get;
42 | private set;
43 | }
44 |
45 | public AssetBundle AssetBundle
46 | {
47 | get;
48 | private set;
49 | }
50 |
51 | public AssetBundleFolder Folder
52 | {
53 | get;
54 | private set;
55 | }
56 |
57 | public string FromRootPath
58 | {
59 | get
60 | {
61 | return (Folder.Folder == null ? Name : string.Format("{0}/{1}", Folder.FromRootPath, Name));
62 | }
63 | }
64 |
65 | public int Depth
66 | {
67 | get
68 | {
69 | return Folder != null ? Folder.Depth + 1 : 0;
70 | }
71 | }
72 |
73 | public Texture Icon
74 | {
75 | get
76 | {
77 | switch (AssetBundle.Type)
78 | {
79 | case AssetBundleType.Asset:
80 | return CachedAssetIcon;
81 | case AssetBundleType.Scene:
82 | return CachedSceneIcon;
83 | default:
84 | return CachedUnknownIcon;
85 | }
86 | }
87 | }
88 |
89 | private static Texture CachedUnknownIcon
90 | {
91 | get
92 | {
93 | if (s_CachedUnknownIcon == null)
94 | {
95 | s_CachedUnknownIcon = EditorGUIUtility.IconContent("Prefab Icon").image;
96 | }
97 |
98 | return s_CachedUnknownIcon;
99 | }
100 | }
101 |
102 | private static Texture CachedAssetIcon
103 | {
104 | get
105 | {
106 | if (s_CachedAssetIcon == null)
107 | {
108 | s_CachedAssetIcon = EditorGUIUtility.IconContent("PrefabNormal Icon").image;
109 | }
110 |
111 | return s_CachedAssetIcon;
112 | }
113 | }
114 |
115 | private static Texture CachedSceneIcon
116 | {
117 | get
118 | {
119 | if (s_CachedSceneIcon == null)
120 | {
121 | s_CachedSceneIcon = EditorGUIUtility.IconContent("SceneAsset Icon").image;
122 | }
123 |
124 | return s_CachedSceneIcon;
125 | }
126 | }
127 | }
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/Editor/AssetBundleEditor/AssetBundleEditor.MenuState.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | internal sealed partial class AssetBundleEditor
11 | {
12 | private enum MenuState
13 | {
14 | Normal,
15 | Add,
16 | Rename,
17 | Remove,
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Editor/AssetBundleEditor/AssetBundleEditorConfigPathAttribute.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | ///
11 | /// AssetBundleEditor 配置路径属性。
12 | ///
13 | public sealed class AssetBundleEditorConfigPathAttribute : ConfigPathAttribute
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Editor/AssetBundleEditor/AssetSorterType.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor.AssetBundleTools
9 | {
10 | internal enum AssetSorterType
11 | {
12 | Path,
13 | Name,
14 | Guid,
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Editor/AssetBundleEditor/SourceAsset.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using UnityEditor;
10 | using UnityEngine;
11 |
12 | namespace UnityGameFramework.Editor.AssetBundleTools
13 | {
14 | internal sealed class SourceAsset
15 | {
16 | private Texture m_CachedIcon;
17 |
18 | public SourceAsset(string guid, string path, string name, SourceFolder folder)
19 | {
20 | if (folder == null)
21 | {
22 | throw new GameFrameworkException("Source asset folder is invalid.");
23 | }
24 |
25 | Guid = guid;
26 | Path = path;
27 | Name = name;
28 | Folder = folder;
29 | m_CachedIcon = null;
30 | }
31 |
32 | public string Guid
33 | {
34 | get;
35 | private set;
36 | }
37 |
38 | public string Path
39 | {
40 | get;
41 | private set;
42 | }
43 |
44 | public string Name
45 | {
46 | get;
47 | private set;
48 | }
49 |
50 | public SourceFolder Folder
51 | {
52 | get;
53 | private set;
54 | }
55 |
56 | public string FromRootPath
57 | {
58 | get
59 | {
60 | return (Folder.Folder == null ? Name : string.Format("{0}/{1}", Folder.FromRootPath, Name));
61 | }
62 | }
63 |
64 | public int Depth
65 | {
66 | get
67 | {
68 | return Folder != null ? Folder.Depth + 1 : 0;
69 | }
70 | }
71 |
72 | public Texture Icon
73 | {
74 | get
75 | {
76 | if (m_CachedIcon == null)
77 | {
78 | m_CachedIcon = AssetDatabase.GetCachedIcon(Path);
79 | }
80 |
81 | return m_CachedIcon;
82 | }
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Editor/AssetBundleXml/CreateXml.cs:
--------------------------------------------------------------------------------
1 | //创建者:Icarus
2 | //手动滑稽,滑稽脸
3 | //ヾ(•ω•`)o
4 | //2018年06月20日 20:30:37
5 | //Assembly-CSharp-Editor
6 |
7 |
8 | using System.IO;
9 | using UnityEditor;
10 | using UnityEngine;
11 | using UnityGameFramework.Editor;
12 | using UnityGameFramework.Editor.AssetBundleTools;
13 |
14 | namespace Icarus.Asset.AssetBundlesBrowser.UnityGameFramework
15 | {
16 | public class CreateXml
17 | {
18 | static string _getXmlPath()
19 | {
20 | return Type.GetConfigurationPath() ?? GameFramework.Utility.Path.GetCombinePath(Application.dataPath, "GameFramework/Configs/AssetBundleEditor.xml");
21 | }
22 |
23 | private const string XML =
24 | @"
25 |
26 |
27 |
28 |
29 | Assets
30 |
31 |
32 |
33 | t:Scene t:Prefab t:Shader t:Model t:Material t:Texture t:AudioClip t:AnimationClip t:AnimatorController t:Font t:TextAsset t:ScriptableObject
34 | l:AssetBundleInclusive
35 | t:Script
36 | l:AssetBundleExclusive
37 | Name
38 |
39 |
40 |
41 | ";
42 | [MenuItem("Game Framework/AssetBundle Tools/Xml 模板生成")]
43 | public static void CreateDefaultXml()
44 | {
45 | var path = _getXmlPath();
46 | var dir = Path.GetDirectoryName(path);
47 | if (!Directory.Exists(dir))
48 | {
49 | Directory.CreateDirectory(dir);
50 | }
51 | File.WriteAllText(path, XML);
52 | Debug.Log("创建完成.路径:"+path);
53 | AssetDatabase.Refresh();
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Editor/Misc/BuildSettingsConfigPathAttribute.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Editor
9 | {
10 | ///
11 | /// BuildSettings 配置路径属性。
12 | ///
13 | public sealed class BuildSettingsConfigPathAttribute : ConfigPathAttribute
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Editor/Misc/ConfigPathAttribute.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace UnityGameFramework.Editor
11 | {
12 | ///
13 | /// 配置路径属性。
14 | ///
15 | public abstract class ConfigPathAttribute : Attribute
16 | {
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Editor/Misc/Help.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using UnityEditor;
9 | using UnityEngine;
10 |
11 | namespace UnityGameFramework.Editor
12 | {
13 | ///
14 | /// 帮助相关的实用函数。
15 | ///
16 | internal static class Help
17 | {
18 | internal static void ShowComponentHelp(string componentName)
19 | {
20 | ShowHelp(string.Format("http://gameframework.cn/archives/category/module/buildin/{0}/", componentName));
21 | }
22 |
23 | [MenuItem("Game Framework/Documentation", false, 90)]
24 | private static void ShowDocumentation()
25 | {
26 | ShowHelp("http://gameframework.cn/");
27 | }
28 |
29 | [MenuItem("Game Framework/API Reference", false, 91)]
30 | private static void ShowAPI()
31 | {
32 | ShowHelp("http://gameframework.cn/api/");
33 | }
34 |
35 | private static void ShowHelp(string uri)
36 | {
37 | Application.OpenURL(uri);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Editor/Misc/HelperInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using System.Collections.Generic;
10 | using UnityEditor;
11 | using UnityEngine;
12 |
13 | namespace UnityGameFramework.Editor
14 | {
15 | internal sealed class HelperInfo where T : MonoBehaviour
16 | {
17 | private const string CustomOptionName = "";
18 |
19 | private readonly string m_Name;
20 |
21 | private SerializedProperty m_HelperTypeName;
22 | private SerializedProperty m_CustomHelper;
23 | private string[] m_HelperTypeNames;
24 | private int m_HelperTypeNameIndex;
25 |
26 | public HelperInfo(string name)
27 | {
28 | m_Name = name;
29 |
30 | m_HelperTypeName = null;
31 | m_CustomHelper = null;
32 | m_HelperTypeNames = null;
33 | m_HelperTypeNameIndex = 0;
34 | }
35 |
36 | public void Init(SerializedObject serializedObject)
37 | {
38 | m_HelperTypeName = serializedObject.FindProperty(string.Format("m_{0}HelperTypeName", m_Name));
39 | m_CustomHelper = serializedObject.FindProperty(string.Format("m_Custom{0}Helper", m_Name));
40 | }
41 |
42 | public void Draw()
43 | {
44 | string displayName = Utility.Text.FieldNameForDisplay(m_Name);
45 | int selectedIndex = EditorGUILayout.Popup(string.Format("{0} Helper", displayName), m_HelperTypeNameIndex, m_HelperTypeNames);
46 | if (selectedIndex != m_HelperTypeNameIndex)
47 | {
48 | m_HelperTypeNameIndex = selectedIndex;
49 | m_HelperTypeName.stringValue = (selectedIndex <= 0 ? null : m_HelperTypeNames[selectedIndex]);
50 | }
51 |
52 | if (m_HelperTypeNameIndex <= 0)
53 | {
54 | EditorGUILayout.PropertyField(m_CustomHelper);
55 | if (m_CustomHelper.objectReferenceValue == null)
56 | {
57 | EditorGUILayout.HelpBox(string.Format("You must set Custom {0} Helper.", displayName), MessageType.Error);
58 | }
59 | }
60 | }
61 |
62 | public void Refresh()
63 | {
64 | List helperTypeNameList = new List();
65 | helperTypeNameList.Add(CustomOptionName);
66 | helperTypeNameList.AddRange(Type.GetTypeNames(typeof(T)));
67 | m_HelperTypeNames = helperTypeNameList.ToArray();
68 |
69 | m_HelperTypeNameIndex = 0;
70 | if (!string.IsNullOrEmpty(m_HelperTypeName.stringValue))
71 | {
72 | m_HelperTypeNameIndex = helperTypeNameList.IndexOf(m_HelperTypeName.stringValue);
73 | if (m_HelperTypeNameIndex <= 0)
74 | {
75 | m_HelperTypeNameIndex = 0;
76 | m_HelperTypeName.stringValue = null;
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Editor/Misc/LogRedirection.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using System.Reflection;
10 | using System.Text.RegularExpressions;
11 | using UnityEditor;
12 | using UnityEditor.Callbacks;
13 | using UnityEditorInternal;
14 | using UnityEngine;
15 |
16 | namespace UnityGameFramework.Editor
17 | {
18 | ///
19 | /// 日志重定向相关的实用函数。
20 | ///
21 | internal static class LogRedirection
22 | {
23 | private static readonly Regex LogRegex = new Regex(@" \(at (.+)\:(\d+)\)\r?\n");
24 |
25 | [OnOpenAsset(0)]
26 | private static bool OnOpenAsset(int instanceId, int line)
27 | {
28 | string selectedStackTrace = GetSelectedStackTrace();
29 | if (string.IsNullOrEmpty(selectedStackTrace))
30 | {
31 | return false;
32 | }
33 |
34 | if (!selectedStackTrace.Contains("UnityGameFramework.Runtime.DefaultLogHelper:Log"))
35 | {
36 | return false;
37 | }
38 |
39 | Match match = LogRegex.Match(selectedStackTrace);
40 | if (!match.Success)
41 | {
42 | return false;
43 | }
44 |
45 | if (!match.Groups[1].Value.Contains("DefaultLogHelper.cs"))
46 | {
47 | return false;
48 | }
49 |
50 | // 跳过第一次匹配的堆栈
51 | match = match.NextMatch();
52 | if (!match.Success)
53 | {
54 | return false;
55 | }
56 |
57 | if (match.Groups[1].Value.Contains("Log.cs"))
58 | {
59 | // 直接使用 GameFramework.dll 源码而非 dll 的工程会多一次匹配的堆栈
60 | match = match.NextMatch();
61 | if (!match.Success)
62 | {
63 | return false;
64 | }
65 | }
66 |
67 | InternalEditorUtility.OpenFileAtLineExternal(Utility.Path.GetCombinePath(Application.dataPath, match.Groups[1].Value.Substring(7)), int.Parse(match.Groups[2].Value));
68 | return true;
69 | }
70 |
71 | private static string GetSelectedStackTrace()
72 | {
73 | Assembly editorWindowAssembly = typeof(EditorWindow).Assembly;
74 | if (editorWindowAssembly == null)
75 | {
76 | return null;
77 | }
78 |
79 | System.Type consoleWindowType = editorWindowAssembly.GetType("UnityEditor.ConsoleWindow");
80 | if (consoleWindowType == null)
81 | {
82 | return null;
83 | }
84 |
85 | FieldInfo consoleWindowFieldInfo = consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic);
86 | if (consoleWindowFieldInfo == null)
87 | {
88 | return null;
89 | }
90 |
91 | EditorWindow consoleWindow = consoleWindowFieldInfo.GetValue(null) as EditorWindow;
92 | if (consoleWindow == null)
93 | {
94 | return null;
95 | }
96 |
97 | if (consoleWindow != EditorWindow.focusedWindow)
98 | {
99 | return null;
100 | }
101 |
102 | FieldInfo activeTextFieldInfo = consoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic);
103 | if (activeTextFieldInfo == null)
104 | {
105 | return null;
106 | }
107 |
108 | return (string)activeTextFieldInfo.GetValue(consoleWindow);
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/Editor/Misc/OpenFolder.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using System.Diagnostics;
10 | using UnityEditor;
11 | using UnityEngine;
12 |
13 | namespace UnityGameFramework.Editor
14 | {
15 | ///
16 | /// 打开文件夹相关的实用函数。
17 | ///
18 | internal static class OpenFolder
19 | {
20 | ///
21 | /// 打开 Temporary Cache Path 文件夹。
22 | ///
23 | [MenuItem("Game Framework/Open Folder/Temporary Cache Path", false, 10)]
24 | private static void OpenFolderTemporaryCachePath()
25 | {
26 | InternalOpenFolder(Application.temporaryCachePath);
27 | }
28 |
29 | ///
30 | /// 打开 Persistent Data Path 文件夹。
31 | ///
32 | [MenuItem("Game Framework/Open Folder/Persistent Data Path", false, 11)]
33 | private static void OpenFolderPersistentDataPath()
34 | {
35 | InternalOpenFolder(Application.persistentDataPath);
36 | }
37 |
38 | ///
39 | /// 打开 Streaming Assets Path 文件夹。
40 | ///
41 | [MenuItem("Game Framework/Open Folder/Streaming Assets Path", false, 12)]
42 | private static void OpenFolderStreamingAssetsPath()
43 | {
44 | InternalOpenFolder(Application.streamingAssetsPath);
45 | }
46 |
47 | ///
48 | /// 打开 Data Path 文件夹。
49 | ///
50 | [MenuItem("Game Framework/Open Folder/Data Path", false, 13)]
51 | private static void OpenFolderDataPath()
52 | {
53 | InternalOpenFolder(Application.dataPath);
54 | }
55 |
56 | private static void InternalOpenFolder(string folder)
57 | {
58 | folder = string.Format("\"{0}\"", folder);
59 | switch (Application.platform)
60 | {
61 | case RuntimePlatform.WindowsEditor:
62 | Process.Start("Explorer.exe", folder.Replace('/', '\\'));
63 | break;
64 | case RuntimePlatform.OSXEditor:
65 | Process.Start("open", folder);
66 | break;
67 | default:
68 | throw new GameFrameworkException(string.Format("Not support open folder on '{0}' platform.", Application.platform.ToString()));
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Editor/Misc/Type.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using System.Collections.Generic;
10 | using System.Reflection;
11 |
12 | namespace UnityGameFramework.Editor
13 | {
14 | ///
15 | /// 类型相关的实用函数。
16 | ///
17 | internal static class Type
18 | {
19 | private static readonly string[] AssemblyNames =
20 | {
21 | #if UNITY_2017_3_OR_NEWER
22 | "UnityGameFramework.Runtime",
23 | #endif
24 | "Assembly-CSharp"
25 | };
26 |
27 | private static readonly string[] EditorAssemblyNames =
28 | {
29 | #if UNITY_2017_3_OR_NEWER
30 | "UnityGameFramework.Editor",
31 | #endif
32 | "Assembly-CSharp-Editor"
33 | };
34 |
35 | ///
36 | /// 获取配置路径。
37 | ///
38 | /// 配置类型。
39 | /// 配置路径。
40 | internal static string GetConfigurationPath() where T : ConfigPathAttribute
41 | {
42 | foreach (System.Type type in Utility.Assembly.GetTypes())
43 | {
44 | if (!type.IsAbstract || !type.IsSealed)
45 | {
46 | continue;
47 | }
48 |
49 | foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
50 | {
51 | if (fieldInfo.FieldType == typeof(string) && fieldInfo.IsDefined(typeof(T), false))
52 | {
53 | return (string)fieldInfo.GetValue(null);
54 | }
55 | }
56 |
57 | foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
58 | {
59 | if (propertyInfo.PropertyType == typeof(string) && propertyInfo.IsDefined(typeof(T), false))
60 | {
61 | return (string)propertyInfo.GetValue(null, null);
62 | }
63 | }
64 | }
65 |
66 | return null;
67 | }
68 |
69 | ///
70 | /// 获取指定基类的所有子类的名称。
71 | ///
72 | /// 基类类型。
73 | /// 指定基类的所有子类的名称。
74 | internal static string[] GetTypeNames(System.Type typeBase)
75 | {
76 | return GetTypeNames(typeBase, AssemblyNames);
77 | }
78 |
79 | ///
80 | /// 获取指定基类的所有子类的名称。
81 | ///
82 | /// 基类类型。
83 | /// 指定基类的所有子类的名称。
84 | internal static string[] GetEditorTypeNames(System.Type typeBase)
85 | {
86 | return GetTypeNames(typeBase, EditorAssemblyNames);
87 | }
88 |
89 | private static string[] GetTypeNames(System.Type typeBase, string[] assemblyNames)
90 | {
91 | List typeNames = new List();
92 | foreach (string assemblyName in assemblyNames)
93 | {
94 | Assembly assembly = null;
95 | try
96 | {
97 | assembly = Assembly.Load(assemblyName);
98 | }
99 | catch
100 | {
101 | continue;
102 | }
103 |
104 | if (assembly == null)
105 | {
106 | continue;
107 | }
108 |
109 | System.Type[] types = assembly.GetTypes();
110 | foreach (System.Type type in types)
111 | {
112 | if (type.IsClass && !type.IsAbstract && typeBase.IsAssignableFrom(type))
113 | {
114 | typeNames.Add(type.FullName);
115 | }
116 | }
117 | }
118 |
119 | typeNames.Sort();
120 | return typeNames.ToArray();
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/Events/GF/EventManager.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework.Event
11 | {
12 | ///
13 | /// 事件管理器。
14 | ///
15 | internal sealed class EventManager : GameFrameworkModule, IEventManager
16 | {
17 | private readonly EventPool m_EventPool;
18 |
19 | ///
20 | /// 初始化事件管理器的新实例。
21 | ///
22 | public EventManager()
23 | {
24 | m_EventPool = new EventPool(EventPoolMode.AllowNoHandler | EventPoolMode.AllowMultiHandler);
25 | }
26 |
27 | ///
28 | /// 获取事件数量。
29 | ///
30 | public int Count
31 | {
32 | get
33 | {
34 | return m_EventPool.Count;
35 | }
36 | }
37 |
38 | ///
39 | /// 获取游戏框架模块优先级。
40 | ///
41 | /// 优先级较高的模块会优先轮询,并且关闭操作会后进行。
42 | internal override int Priority
43 | {
44 | get
45 | {
46 | return 100;
47 | }
48 | }
49 |
50 | ///
51 | /// 事件管理器轮询。
52 | ///
53 | /// 逻辑流逝时间,以秒为单位。
54 | /// 真实流逝时间,以秒为单位。
55 | internal override void Update(float elapseSeconds, float realElapseSeconds)
56 | {
57 | m_EventPool.Update(elapseSeconds, realElapseSeconds);
58 | }
59 |
60 | ///
61 | /// 关闭并清理事件管理器。
62 | ///
63 | internal override void Shutdown()
64 | {
65 | m_EventPool.Shutdown();
66 | }
67 |
68 | ///
69 | /// 检查订阅事件处理函数。
70 | ///
71 | /// 事件类型编号。
72 | /// 要检查的事件处理函数。
73 | /// 是否存在事件处理函数。
74 | public bool Check(int id, EventHandler handler)
75 | {
76 | return m_EventPool.Check(id, handler);
77 | }
78 |
79 | ///
80 | /// 订阅事件处理函数。
81 | ///
82 | /// 事件类型编号。
83 | /// 要订阅的事件处理函数。
84 | public void Subscribe(int id, EventHandler handler)
85 | {
86 | m_EventPool.Subscribe(id, handler);
87 | }
88 |
89 | ///
90 | /// 取消订阅事件处理函数。
91 | ///
92 | /// 事件类型编号。
93 | /// 要取消订阅的事件处理函数。
94 | public void Unsubscribe(int id, EventHandler handler)
95 | {
96 | m_EventPool.Unsubscribe(id, handler);
97 | }
98 |
99 | ///
100 | /// 设置默认事件处理函数。
101 | ///
102 | /// 要设置的默认事件处理函数。
103 | public void SetDefaultHandler(EventHandler handler)
104 | {
105 | m_EventPool.SetDefaultHandler(handler);
106 | }
107 |
108 | ///
109 | /// 抛出事件,这个操作是线程安全的,即使不在主线程中抛出,也可保证在主线程中回调事件处理函数,但事件会在抛出后的下一帧分发。
110 | ///
111 | /// 事件源。
112 | /// 事件参数。
113 | public void Fire(object sender, GameEventArgs e)
114 | {
115 | m_EventPool.Fire(sender, e);
116 | }
117 |
118 | ///
119 | /// 抛出事件立即模式,这个操作不是线程安全的,事件会立刻分发。
120 | ///
121 | /// 事件源。
122 | /// 事件参数。
123 | public void FireNow(object sender, GameEventArgs e)
124 | {
125 | m_EventPool.FireNow(sender, e);
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/Events/GF/GameEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Event
9 | {
10 | ///
11 | /// 游戏逻辑事件基类。
12 | ///
13 | public abstract class GameEventArgs : BaseEventArgs
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Events/GF/IEventManager.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework.Event
11 | {
12 | ///
13 | /// 事件管理器接口。
14 | ///
15 | public interface IEventManager
16 | {
17 | ///
18 | /// 获取事件数量。
19 | ///
20 | int Count
21 | {
22 | get;
23 | }
24 |
25 | ///
26 | /// 检查订阅事件处理函数。
27 | ///
28 | /// 事件类型编号。
29 | /// 要检查的事件处理函数。
30 | /// 是否存在事件处理函数。
31 | bool Check(int id, EventHandler handler);
32 |
33 | ///
34 | /// 订阅事件处理函数。
35 | ///
36 | /// 事件类型编号。
37 | /// 要订阅的事件处理函数。
38 | void Subscribe(int id, EventHandler handler);
39 |
40 | ///
41 | /// 取消订阅事件处理函数。
42 | ///
43 | /// 事件类型编号。
44 | /// 要取消订阅的事件处理函数。
45 | void Unsubscribe(int id, EventHandler handler);
46 |
47 | ///
48 | /// 设置默认事件处理函数。
49 | ///
50 | /// 要设置的默认事件处理函数。
51 | void SetDefaultHandler(EventHandler handler);
52 |
53 | ///
54 | /// 抛出事件,这个操作是线程安全的,即使不在主线程中抛出,也可保证在主线程中回调事件处理函数,但事件会在抛出后的下一帧分发。
55 | ///
56 | /// 事件源。
57 | /// 事件参数。
58 | void Fire(object sender, GameEventArgs e);
59 |
60 | ///
61 | /// 抛出事件立即模式,这个操作不是线程安全的,事件会立刻分发。
62 | ///
63 | /// 事件源。
64 | /// 事件参数。
65 | void FireNow(object sender, GameEventArgs e);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Events/UnityGF/Editor/EventComponentInspector.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using UnityEditor;
9 | using UnityGameFramework.Runtime;
10 |
11 | namespace UnityGameFramework.Editor
12 | {
13 | [CustomEditor(typeof(EventComponent))]
14 | internal sealed class EventComponentInspector : GameFrameworkInspector
15 | {
16 | public override void OnInspectorGUI()
17 | {
18 | base.OnInspectorGUI();
19 |
20 | if (!EditorApplication.isPlaying)
21 | {
22 | EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info);
23 | return;
24 | }
25 |
26 | EventComponent t = (EventComponent)target;
27 |
28 | if (PrefabUtility.GetPrefabType(t.gameObject) != PrefabType.Prefab)
29 | {
30 | EditorGUILayout.LabelField("Event Count", t.Count.ToString());
31 | }
32 |
33 | Repaint();
34 | }
35 |
36 | private void OnEnable()
37 | {
38 |
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Events/UnityGF/EventComponent.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using GameFramework.Event;
10 | using System;
11 | using UnityEngine;
12 |
13 | namespace UnityGameFramework.Runtime
14 | {
15 | ///
16 | /// 事件组件。
17 | ///
18 | [DisallowMultipleComponent]
19 | [AddComponentMenu("Game Framework/Event")]
20 | public sealed class EventComponent : MonoBehaviour
21 | {
22 | private IEventManager m_EventManager = null;
23 |
24 | ///
25 | /// 获取事件数量。
26 | ///
27 | public int Count
28 | {
29 | get
30 | {
31 | return m_EventManager.Count;
32 | }
33 | }
34 |
35 | ///
36 | /// 游戏框架组件初始化。
37 | ///
38 | void Awake()
39 | {
40 | GameEntry.RegisterComponent(this);
41 | m_EventManager = GameFrameworkEntry.GetModule();
42 | if (m_EventManager == null)
43 | {
44 | Log.Fatal("Event manager is invalid.");
45 | return;
46 | }
47 | }
48 |
49 | private void Start()
50 | {
51 |
52 | }
53 |
54 | ///
55 | /// 检查订阅事件处理回调函数。
56 | ///
57 | /// 事件类型编号。
58 | /// 要检查的事件处理回调函数。
59 | /// 是否存在事件处理回调函数。
60 | public bool Check(int id, EventHandler handler)
61 | {
62 | return m_EventManager.Check(id, handler);
63 | }
64 |
65 | ///
66 | /// 订阅事件处理回调函数。
67 | ///
68 | /// 事件类型编号。
69 | /// 要订阅的事件处理回调函数。
70 | public void Subscribe(int id, EventHandler handler)
71 | {
72 | m_EventManager.Subscribe(id, handler);
73 | }
74 |
75 | ///
76 | /// 取消订阅事件处理回调函数。
77 | ///
78 | /// 事件类型编号。
79 | /// 要取消订阅的事件处理回调函数。
80 | public void Unsubscribe(int id, EventHandler handler)
81 | {
82 | m_EventManager.Unsubscribe(id, handler);
83 | }
84 |
85 | ///
86 | /// 设置默认事件处理函数。
87 | ///
88 | /// 要设置的默认事件处理函数。
89 | public void SetDefaultHandler(EventHandler handler)
90 | {
91 | m_EventManager.SetDefaultHandler(handler);
92 | }
93 |
94 | ///
95 | /// 抛出事件,这个操作是线程安全的,即使不在主线程中抛出,也可保证在主线程中回调事件处理函数,但事件会在抛出后的下一帧分发。
96 | ///
97 | /// 事件发送者。
98 | /// 事件内容。
99 | public void Fire(object sender, GameEventArgs e)
100 | {
101 | m_EventManager.Fire(sender, e);
102 | }
103 |
104 | ///
105 | /// 抛出事件立即模式,这个操作不是线程安全的,事件会立刻分发。
106 | ///
107 | /// 事件发送者。
108 | /// 事件内容。
109 | public void FireNow(object sender, GameEventArgs e)
110 | {
111 | m_EventManager.FireNow(sender, e);
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/Example/AssetBundleEditor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assets
6 |
7 | t:Scene t:Prefab t:Shader t:Model t:Material t:Texture t:AudioClip t:AnimationClip t:AnimatorController t:Font t:TextAsset t:ScriptableObject
8 | l:AssetBundleInclusive
9 | t:Script
10 | l:AssetBundleExclusive
11 | Name
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Example/TestAset/Cube.prefab:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1001 &100100000
4 | Prefab:
5 | m_ObjectHideFlags: 1
6 | serializedVersion: 2
7 | m_Modification:
8 | m_TransformParent: {fileID: 0}
9 | m_Modifications: []
10 | m_RemovedComponents: []
11 | m_ParentPrefab: {fileID: 0}
12 | m_RootGameObject: {fileID: 1051329608636010}
13 | m_IsPrefabParent: 1
14 | --- !u!1 &1051329608636010
15 | GameObject:
16 | m_ObjectHideFlags: 0
17 | m_PrefabParentObject: {fileID: 0}
18 | m_PrefabInternal: {fileID: 100100000}
19 | serializedVersion: 5
20 | m_Component:
21 | - component: {fileID: 4719680303658222}
22 | - component: {fileID: 33079812943154446}
23 | - component: {fileID: 23009693297311978}
24 | - component: {fileID: 65675028101028294}
25 | m_Layer: 0
26 | m_Name: Cube
27 | m_TagString: Untagged
28 | m_Icon: {fileID: 0}
29 | m_NavMeshLayer: 0
30 | m_StaticEditorFlags: 0
31 | m_IsActive: 1
32 | --- !u!4 &4719680303658222
33 | Transform:
34 | m_ObjectHideFlags: 1
35 | m_PrefabParentObject: {fileID: 0}
36 | m_PrefabInternal: {fileID: 100100000}
37 | m_GameObject: {fileID: 1051329608636010}
38 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
39 | m_LocalPosition: {x: 0, y: 0, z: 0}
40 | m_LocalScale: {x: 1, y: 1, z: 1}
41 | m_Children: []
42 | m_Father: {fileID: 0}
43 | m_RootOrder: 0
44 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
45 | --- !u!23 &23009693297311978
46 | MeshRenderer:
47 | m_ObjectHideFlags: 1
48 | m_PrefabParentObject: {fileID: 0}
49 | m_PrefabInternal: {fileID: 100100000}
50 | m_GameObject: {fileID: 1051329608636010}
51 | m_Enabled: 1
52 | m_CastShadows: 1
53 | m_ReceiveShadows: 1
54 | m_DynamicOccludee: 1
55 | m_MotionVectors: 1
56 | m_LightProbeUsage: 1
57 | m_ReflectionProbeUsage: 1
58 | m_RenderingLayerMask: 4294967295
59 | m_Materials:
60 | - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
61 | m_StaticBatchInfo:
62 | firstSubMesh: 0
63 | subMeshCount: 0
64 | m_StaticBatchRoot: {fileID: 0}
65 | m_ProbeAnchor: {fileID: 0}
66 | m_LightProbeVolumeOverride: {fileID: 0}
67 | m_ScaleInLightmap: 1
68 | m_PreserveUVs: 0
69 | m_IgnoreNormalsForChartDetection: 0
70 | m_ImportantGI: 0
71 | m_StitchLightmapSeams: 0
72 | m_SelectedEditorRenderState: 3
73 | m_MinimumChartSize: 4
74 | m_AutoUVMaxDistance: 0.5
75 | m_AutoUVMaxAngle: 89
76 | m_LightmapParameters: {fileID: 0}
77 | m_SortingLayerID: 0
78 | m_SortingLayer: 0
79 | m_SortingOrder: 0
80 | --- !u!33 &33079812943154446
81 | MeshFilter:
82 | m_ObjectHideFlags: 1
83 | m_PrefabParentObject: {fileID: 0}
84 | m_PrefabInternal: {fileID: 100100000}
85 | m_GameObject: {fileID: 1051329608636010}
86 | m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
87 | --- !u!65 &65675028101028294
88 | BoxCollider:
89 | m_ObjectHideFlags: 1
90 | m_PrefabParentObject: {fileID: 0}
91 | m_PrefabInternal: {fileID: 100100000}
92 | m_GameObject: {fileID: 1051329608636010}
93 | m_Material: {fileID: 0}
94 | m_IsTrigger: 0
95 | m_Enabled: 1
96 | serializedVersion: 2
97 | m_Size: {x: 1, y: 1, z: 1}
98 | m_Center: {x: 0, y: 0, z: 0}
99 |
--------------------------------------------------------------------------------
/Example/TestAset/Sphere.prefab:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1001 &100100000
4 | Prefab:
5 | m_ObjectHideFlags: 1
6 | serializedVersion: 2
7 | m_Modification:
8 | m_TransformParent: {fileID: 0}
9 | m_Modifications: []
10 | m_RemovedComponents: []
11 | m_ParentPrefab: {fileID: 0}
12 | m_RootGameObject: {fileID: 1099576357046862}
13 | m_IsPrefabParent: 1
14 | --- !u!1 &1099576357046862
15 | GameObject:
16 | m_ObjectHideFlags: 0
17 | m_PrefabParentObject: {fileID: 0}
18 | m_PrefabInternal: {fileID: 100100000}
19 | serializedVersion: 5
20 | m_Component:
21 | - component: {fileID: 4290752381175072}
22 | - component: {fileID: 33683223718712270}
23 | - component: {fileID: 23329846480611154}
24 | - component: {fileID: 135822131267452308}
25 | m_Layer: 0
26 | m_Name: Sphere
27 | m_TagString: Untagged
28 | m_Icon: {fileID: 0}
29 | m_NavMeshLayer: 0
30 | m_StaticEditorFlags: 0
31 | m_IsActive: 1
32 | --- !u!4 &4290752381175072
33 | Transform:
34 | m_ObjectHideFlags: 1
35 | m_PrefabParentObject: {fileID: 0}
36 | m_PrefabInternal: {fileID: 100100000}
37 | m_GameObject: {fileID: 1099576357046862}
38 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
39 | m_LocalPosition: {x: 0, y: 0, z: 0}
40 | m_LocalScale: {x: 1, y: 1, z: 1}
41 | m_Children: []
42 | m_Father: {fileID: 0}
43 | m_RootOrder: 0
44 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
45 | --- !u!23 &23329846480611154
46 | MeshRenderer:
47 | m_ObjectHideFlags: 1
48 | m_PrefabParentObject: {fileID: 0}
49 | m_PrefabInternal: {fileID: 100100000}
50 | m_GameObject: {fileID: 1099576357046862}
51 | m_Enabled: 1
52 | m_CastShadows: 1
53 | m_ReceiveShadows: 1
54 | m_DynamicOccludee: 1
55 | m_MotionVectors: 1
56 | m_LightProbeUsage: 1
57 | m_ReflectionProbeUsage: 1
58 | m_RenderingLayerMask: 4294967295
59 | m_Materials:
60 | - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
61 | m_StaticBatchInfo:
62 | firstSubMesh: 0
63 | subMeshCount: 0
64 | m_StaticBatchRoot: {fileID: 0}
65 | m_ProbeAnchor: {fileID: 0}
66 | m_LightProbeVolumeOverride: {fileID: 0}
67 | m_ScaleInLightmap: 1
68 | m_PreserveUVs: 0
69 | m_IgnoreNormalsForChartDetection: 0
70 | m_ImportantGI: 0
71 | m_StitchLightmapSeams: 0
72 | m_SelectedEditorRenderState: 3
73 | m_MinimumChartSize: 4
74 | m_AutoUVMaxDistance: 0.5
75 | m_AutoUVMaxAngle: 89
76 | m_LightmapParameters: {fileID: 0}
77 | m_SortingLayerID: 0
78 | m_SortingLayer: 0
79 | m_SortingOrder: 0
80 | --- !u!33 &33683223718712270
81 | MeshFilter:
82 | m_ObjectHideFlags: 1
83 | m_PrefabParentObject: {fileID: 0}
84 | m_PrefabInternal: {fileID: 100100000}
85 | m_GameObject: {fileID: 1099576357046862}
86 | m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
87 | --- !u!135 &135822131267452308
88 | SphereCollider:
89 | m_ObjectHideFlags: 1
90 | m_PrefabParentObject: {fileID: 0}
91 | m_PrefabInternal: {fileID: 100100000}
92 | m_GameObject: {fileID: 1099576357046862}
93 | m_Material: {fileID: 0}
94 | m_IsTrigger: 0
95 | m_Enabled: 1
96 | serializedVersion: 2
97 | m_Radius: 0.5
98 | m_Center: {x: 0, y: 0, z: 0}
99 |
--------------------------------------------------------------------------------
/Example/test.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using GameFramework;
4 | using GameFramework.Event;
5 | using GameFramework.Resource;
6 | using UnityEngine;
7 | using UnityGameFramework.Runtime;
8 |
9 | public class test : MonoBehaviour
10 | {
11 | public string AssetName;
12 | private EventComponent _eventComponent;
13 | private BaseComponent _baseComponent;
14 | private ResourceComponent _resourceComponent;
15 |
16 | // Use this for initialization
17 | void Start()
18 | {
19 | _eventComponent = GameEntry.GetComponent();
20 | _baseComponent = GameEntry.GetComponent();
21 | _resourceComponent = GameEntry.GetComponent();
22 | if (!_baseComponent)
23 | {
24 | Debug.LogError("Base component is invalid.");
25 | return;
26 | }
27 | if (!_baseComponent.EditorResourceMode)
28 | {
29 | _resourceComponent.SetResourceMode(ResourceMode.Package);
30 | var eventArgs = ReferencePool.Acquire();
31 | _eventComponent.Subscribe(eventArgs.Id, _loadAsset);
32 | ReferencePool.Release(eventArgs);
33 | _resourceComponent.InitResources();
34 | }
35 | else
36 | {
37 | _load();
38 | }
39 | }
40 |
41 | private void _loadAsset(object sender, GameEventArgs e)
42 | {
43 | _load();
44 | }
45 |
46 | [ContextMenu("加载资源")]
47 | void _load()
48 | {
49 | _resourceComponent.LoadAsset(AssetName, new LoadAssetCallbacks(_loadAssetSuccessCallback, _loadAssetFailureCallback, _loadAssetUpdateCallback));
50 | }
51 |
52 | private void _loadAssetUpdateCallback(string assetname, float progress, object userdata)
53 | {
54 | Debug.LogFormat("加载中.加载进度:{0}", progress);
55 | }
56 |
57 | private void _loadAssetFailureCallback(string assetname, LoadResourceStatus status, string errormessage, object userdata)
58 | {
59 | Debug.LogErrorFormat("加载失败.资源名:{0},状态:{1},错误信息:{2}", assetname, status, errormessage);
60 | }
61 |
62 | private void _loadAssetSuccessCallback(string assetname, object asset, float duration, object userdata)
63 | {
64 | var gameobject = (GameObject) asset;
65 | Instantiate(gameobject);
66 | Debug.LogFormat("资源名为:{0},duration:{1}", assetname, duration);
67 | }
68 |
69 | // Update is called once per frame
70 | void Update()
71 | {
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Icarus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Libraries/ICSharpCode.SharpZipLib.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yika-aixi/GameFrameworkAssetBundleEditor/c58aab76b401fe0052c940311af63e19a0a1b483/Libraries/ICSharpCode.SharpZipLib.dll
--------------------------------------------------------------------------------
/Log/GF/Log.ILogHelper.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | public static partial class Log
11 | {
12 | ///
13 | /// 日志辅助器接口。
14 | ///
15 | public interface ILogHelper
16 | {
17 | ///
18 | /// 记录日志。
19 | ///
20 | /// 日志等级。
21 | /// 日志内容。
22 | void Log(LogLevel level, object message);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Log/GF/LogLevel.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 日志等级。
12 | ///
13 | public enum LogLevel
14 | {
15 | ///
16 | /// 调试。
17 | ///
18 | Debug,
19 |
20 | ///
21 | /// 信息。
22 | ///
23 | Info,
24 |
25 | ///
26 | /// 警告。
27 | ///
28 | Warning,
29 |
30 | ///
31 | /// 错误。
32 | ///
33 | Error,
34 |
35 | ///
36 | /// 严重错误。
37 | ///
38 | Fatal
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ObjectPool/GF/ObjectInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework.ObjectPool
11 | {
12 | ///
13 | /// 对象信息。
14 | ///
15 | public struct ObjectInfo
16 | {
17 | private readonly string m_Name;
18 | private readonly bool m_Locked;
19 | private readonly int m_Priority;
20 | private readonly DateTime m_LastUseTime;
21 | private readonly int m_SpawnCount;
22 |
23 | ///
24 | /// 初始化对象信息的新实例。
25 | ///
26 | /// 对象名称。
27 | /// 对象是否被加锁。
28 | /// 对象的优先级。
29 | /// 对象上次使用时间。
30 | /// 对象的获取计数。
31 | public ObjectInfo(string name, bool locked, int priority, DateTime lastUseTime, int spawnCount)
32 | {
33 | m_Name = name;
34 | m_Locked = locked;
35 | m_Priority = priority;
36 | m_LastUseTime = lastUseTime;
37 | m_SpawnCount = spawnCount;
38 | }
39 |
40 | ///
41 | /// 获取对象名称。
42 | ///
43 | public string Name
44 | {
45 | get
46 | {
47 | return m_Name;
48 | }
49 | }
50 |
51 | ///
52 | /// 获取对象是否被加锁。
53 | ///
54 | public bool Locked
55 | {
56 | get
57 | {
58 | return m_Locked;
59 | }
60 | }
61 |
62 | ///
63 | /// 获取对象的优先级。
64 | ///
65 | public int Priority
66 | {
67 | get
68 | {
69 | return m_Priority;
70 | }
71 | }
72 |
73 | ///
74 | /// 获取对象上次使用时间。
75 | ///
76 | public DateTime LastUseTime
77 | {
78 | get
79 | {
80 | return m_LastUseTime;
81 | }
82 | }
83 |
84 | ///
85 | /// 获取对象是否正在使用。
86 | ///
87 | public bool IsInUse
88 | {
89 | get
90 | {
91 | return m_SpawnCount > 0;
92 | }
93 | }
94 |
95 | ///
96 | /// 获取对象的获取计数。
97 | ///
98 | public int SpawnCount
99 | {
100 | get
101 | {
102 | return m_SpawnCount;
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/ObjectPool/GF/ObjectPoolBase.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework.ObjectPool
11 | {
12 | ///
13 | /// 对象池基类。
14 | ///
15 | public abstract class ObjectPoolBase
16 | {
17 | private readonly string m_Name;
18 |
19 | ///
20 | /// 初始化对象池基类的新实例。
21 | ///
22 | public ObjectPoolBase()
23 | : this(null)
24 | {
25 |
26 | }
27 |
28 | ///
29 | /// 初始化对象池基类的新实例。
30 | ///
31 | /// 对象池名称。
32 | public ObjectPoolBase(string name)
33 | {
34 | m_Name = name ?? string.Empty;
35 | }
36 |
37 | ///
38 | /// 获取对象池名称。
39 | ///
40 | public string Name
41 | {
42 | get
43 | {
44 | return m_Name;
45 | }
46 | }
47 |
48 | ///
49 | /// 获取对象池对象类型。
50 | ///
51 | public abstract Type ObjectType
52 | {
53 | get;
54 | }
55 |
56 | ///
57 | /// 获取对象池中对象的数量。
58 | ///
59 | public abstract int Count
60 | {
61 | get;
62 | }
63 |
64 | ///
65 | /// 获取对象池中能被释放的对象的数量。
66 | ///
67 | public abstract int CanReleaseCount
68 | {
69 | get;
70 | }
71 |
72 | ///
73 | /// 获取是否允许对象被多次获取。
74 | ///
75 | public abstract bool AllowMultiSpawn
76 | {
77 | get;
78 | }
79 |
80 | ///
81 | /// 获取或设置对象池自动释放可释放对象的间隔秒数。
82 | ///
83 | public abstract float AutoReleaseInterval
84 | {
85 | get;
86 | set;
87 | }
88 |
89 | ///
90 | /// 获取或设置对象池的容量。
91 | ///
92 | public abstract int Capacity
93 | {
94 | get;
95 | set;
96 | }
97 |
98 | ///
99 | /// 获取或设置对象池对象过期秒数。
100 | ///
101 | public abstract float ExpireTime
102 | {
103 | get;
104 | set;
105 | }
106 |
107 | ///
108 | /// 获取或设置对象池的优先级。
109 | ///
110 | public abstract int Priority
111 | {
112 | get;
113 | set;
114 | }
115 |
116 | ///
117 | /// 释放对象池中的可释放对象。
118 | ///
119 | public abstract void Release();
120 |
121 | ///
122 | /// 释放对象池中的可释放对象。
123 | ///
124 | /// 尝试释放对象数量。
125 | public abstract void Release(int toReleaseCount);
126 |
127 | ///
128 | /// 释放对象池中的所有未使用对象。
129 | ///
130 | public abstract void ReleaseAllUnused();
131 |
132 | ///
133 | /// 获取所有对象信息。
134 | ///
135 | /// 所有对象信息。
136 | public abstract ObjectInfo[] GetAllObjectInfos();
137 |
138 | internal abstract void Update(float elapseSeconds, float realElapseSeconds);
139 |
140 | internal abstract void Shutdown();
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/ObjectPool/GF/ReleaseObjectFilterCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 | using System.Collections.Generic;
10 |
11 | namespace GameFramework.ObjectPool
12 | {
13 | ///
14 | /// 释放对象筛选函数。
15 | ///
16 | /// 对象类型。
17 | /// 要筛选的对象集合。
18 | /// 需要释放的对象数量。
19 | /// 对象过期参考时间。
20 | /// 经筛选需要释放的对象集合。
21 | public delegate LinkedList ReleaseObjectFilterCallback(LinkedList candidateObjects, int toReleaseCount, DateTime expireTime) where T : ObjectBase;
22 | }
23 |
--------------------------------------------------------------------------------
/ObjectPool/UnityGF/Editor/ObjectPoolComponentInspector.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using GameFramework.ObjectPool;
10 | using System.Collections.Generic;
11 | using UnityEditor;
12 | using UnityEngine;
13 | using UnityGameFramework.Runtime;
14 |
15 | namespace UnityGameFramework.Editor
16 | {
17 | [CustomEditor(typeof(ObjectPoolComponent))]
18 | internal sealed class ObjectPoolComponentInspector : GameFrameworkInspector
19 | {
20 | private HashSet m_OpenedItems = new HashSet();
21 |
22 | public override void OnInspectorGUI()
23 | {
24 | base.OnInspectorGUI();
25 |
26 | if (!EditorApplication.isPlaying)
27 | {
28 | EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info);
29 | return;
30 | }
31 |
32 | ObjectPoolComponent t = (ObjectPoolComponent)target;
33 |
34 | if (PrefabUtility.GetPrefabType(t.gameObject) != PrefabType.Prefab)
35 | {
36 | EditorGUILayout.LabelField("Object Pool Count", t.Count.ToString());
37 |
38 | ObjectPoolBase[] objectPools = t.GetAllObjectPools(true);
39 | foreach (ObjectPoolBase objectPool in objectPools)
40 | {
41 | DrawObjectPool(objectPool);
42 | }
43 | }
44 |
45 | Repaint();
46 | }
47 |
48 | private void OnEnable()
49 | {
50 |
51 | }
52 |
53 | private void DrawObjectPool(ObjectPoolBase objectPool)
54 | {
55 | string fullName = Utility.Text.GetFullName(objectPool.ObjectType, objectPool.Name);
56 | bool lastState = m_OpenedItems.Contains(fullName);
57 | bool currentState = EditorGUILayout.Foldout(lastState, string.IsNullOrEmpty(objectPool.Name) ? "" : objectPool.Name);
58 | if (currentState != lastState)
59 | {
60 | if (currentState)
61 | {
62 | m_OpenedItems.Add(fullName);
63 | }
64 | else
65 | {
66 | m_OpenedItems.Remove(fullName);
67 | }
68 | }
69 |
70 | if (currentState)
71 | {
72 | EditorGUILayout.BeginVertical("box");
73 | {
74 | EditorGUILayout.LabelField("Type", objectPool.ObjectType.FullName);
75 | EditorGUILayout.LabelField("Auto Release Interval", objectPool.AutoReleaseInterval.ToString());
76 | EditorGUILayout.LabelField("Capacity", objectPool.Capacity.ToString());
77 | EditorGUILayout.LabelField("Used Count", objectPool.Count.ToString());
78 | EditorGUILayout.LabelField("Can Release Count", objectPool.CanReleaseCount.ToString());
79 | EditorGUILayout.LabelField("Expire Time", objectPool.ExpireTime.ToString());
80 | EditorGUILayout.LabelField("Priority", objectPool.Priority.ToString());
81 | ObjectInfo[] objectInfos = objectPool.GetAllObjectInfos();
82 | if (objectInfos.Length > 0)
83 | {
84 | foreach (ObjectInfo objectInfo in objectInfos)
85 | {
86 | EditorGUILayout.LabelField(objectInfo.Name, string.Format("{0}, {1}, {2}, {3}", objectInfo.Locked.ToString(), objectPool.AllowMultiSpawn ? objectInfo.SpawnCount.ToString() : objectInfo.IsInUse.ToString(), objectInfo.Priority.ToString(), objectInfo.LastUseTime.ToString("yyyy-MM-dd HH:mm:ss")));
87 | }
88 | }
89 | else
90 | {
91 | GUILayout.Label("Object Pool is Empty ...");
92 | }
93 | }
94 | EditorGUILayout.EndVertical();
95 |
96 | EditorGUILayout.Separator();
97 | }
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GameFrameworkAssetBundleEditor
2 | 从UnityGameFramework提取的AB编辑器以及资源管理器(更新部分被我删除,只有加载),Editor和AB都可以正常加载了.
3 | 提取里GF的(Event,对象池,任务池,引用池,Log,AB,资源管理器,场景管理器)
4 |
5 | 框架地址:https://github.com/EllanJiang/UnityGameFramework
6 |
7 | 框架文档:http://gameframework.cn/
8 |
9 | 使用 AssetBundle 编辑工具教程:http://gameframework.cn/archives/320
10 |
11 | 使用 AssetBundle 构建工具教程:http://gameframework.cn/archives/356
12 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/Constant.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 资源相关常量。
12 | ///
13 | internal static class Constant
14 | {
15 | ///
16 | /// 默认资源加载优先级。
17 | ///
18 | internal const int DefaultPriority = 0;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/DecryptResourceCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 解密资源回调函数。
12 | ///
13 | /// 资源名称。
14 | /// 变体名称。
15 | /// 资源加载方式。
16 | /// 资源大小。
17 | /// 资源哈希值。
18 | /// 资源是否在只读区。
19 | /// 待解密的资源二进制流。
20 | /// 解密后的资源二进制流。
21 | public delegate byte[] DecryptResourceCallback(string name, string variant, int loadType, int length, int hashCode, bool storageInReadOnly, byte[] bytes);
22 | }
23 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadAssetDependencyAssetCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源时加载依赖资源回调函数。
12 | ///
13 | /// 要加载的资源名称。
14 | /// 被加载的依赖资源名称。
15 | /// 当前已加载依赖资源数量。
16 | /// 总共加载依赖资源数量。
17 | /// 用户自定义数据。
18 | public delegate void LoadAssetDependencyAssetCallback(string assetName, string dependencyAssetName, int loadedCount, int totalCount, object userData);
19 | }
20 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadAssetFailureCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源失败回调函数。
12 | ///
13 | /// 要加载的资源名称。
14 | /// 加载资源状态。
15 | /// 错误信息。
16 | /// 用户自定义数据。
17 | public delegate void LoadAssetFailureCallback(string assetName, LoadResourceStatus status, string errorMessage, object userData);
18 | }
19 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadAssetSuccessCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源成功回调函数。
12 | ///
13 | /// 要加载的资源名称。
14 | /// 已加载的资源。
15 | /// 加载持续时间。
16 | /// 用户自定义数据。
17 | public delegate void LoadAssetSuccessCallback(string assetName, object asset, float duration, object userData);
18 | }
19 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadAssetUpdateCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源更新回调函数。
12 | ///
13 | /// 要加载的资源名称。
14 | /// 加载资源进度。
15 | /// 用户自定义数据。
16 | public delegate void LoadAssetUpdateCallback(string assetName, float progress, object userData);
17 | }
18 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadBytesCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | ///读取数据流回调函数。
12 | ///
13 | /// 文件路径。
14 | /// 数据流。
15 | /// 错误信息。
16 | public delegate void LoadBytesCallback(string fileUri, byte[] bytes, string errorMessage);
17 | }
18 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceAgentHelperErrorEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源代理辅助器错误事件。
12 | ///
13 | public sealed class LoadResourceAgentHelperErrorEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载资源代理辅助器错误事件的新实例。
17 | ///
18 | /// 加载资源状态。
19 | /// 错误信息。
20 | public LoadResourceAgentHelperErrorEventArgs(LoadResourceStatus status, string errorMessage)
21 | {
22 | Status = status;
23 | ErrorMessage = errorMessage;
24 | }
25 |
26 | ///
27 | /// 获取加载资源状态。
28 | ///
29 | public LoadResourceStatus Status
30 | {
31 | get;
32 | private set;
33 | }
34 |
35 | ///
36 | /// 获取错误信息。
37 | ///
38 | public string ErrorMessage
39 | {
40 | get;
41 | private set;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceAgentHelperLoadCompleteEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源代理辅助器异步加载资源完成事件。
12 | ///
13 | public sealed class LoadResourceAgentHelperLoadCompleteEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载资源代理辅助器异步加载资源完成事件的新实例。
17 | ///
18 | /// 加载的资源。
19 | public LoadResourceAgentHelperLoadCompleteEventArgs(object asset)
20 | {
21 | Asset = asset;
22 | }
23 |
24 | ///
25 | /// 获取加载的资源。
26 | ///
27 | public object Asset
28 | {
29 | get;
30 | private set;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceAgentHelperParseBytesCompleteEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源代理辅助器异步将资源二进制流转换为加载对象完成事件。
12 | ///
13 | public sealed class LoadResourceAgentHelperParseBytesCompleteEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载资源代理辅助器异步将资源二进制流转换为加载对象完成事件的新实例。
17 | ///
18 | /// 资源对象。
19 | public LoadResourceAgentHelperParseBytesCompleteEventArgs(object resource)
20 | {
21 | Resource = resource;
22 | }
23 |
24 | ///
25 | /// 获取加载对象。
26 | ///
27 | public object Resource
28 | {
29 | get;
30 | private set;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceAgentHelperReadBytesCompleteEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源代理辅助器异步读取资源二进制流完成事件。
12 | ///
13 | public sealed class LoadResourceAgentHelperReadBytesCompleteEventArgs : GameFrameworkEventArgs
14 | {
15 | private readonly byte[] m_Bytes;
16 |
17 | ///
18 | /// 初始化加载资源代理辅助器异步读取资源二进制流完成事件的新实例。
19 | ///
20 | /// 资源的二进制流。
21 | /// 资源加载方式。
22 | public LoadResourceAgentHelperReadBytesCompleteEventArgs(byte[] bytes, int loadType)
23 | {
24 | m_Bytes = bytes;
25 | LoadType = loadType;
26 | }
27 |
28 | ///
29 | /// 获取资源加载方式。
30 | ///
31 | public int LoadType
32 | {
33 | get;
34 | private set;
35 | }
36 |
37 | ///
38 | /// 获取资源的二进制流。
39 | ///
40 | /// 资源的二进制流。
41 | public byte[] GetBytes()
42 | {
43 | return m_Bytes;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceAgentHelperReadFileCompleteEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源代理辅助器异步将资源文件转换为加载对象完成事件。
12 | ///
13 | public sealed class LoadResourceAgentHelperReadFileCompleteEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载资源代理辅助器异步将资源文件转换为加载对象完成事件的新实例。
17 | ///
18 | /// 资源对象。
19 | public LoadResourceAgentHelperReadFileCompleteEventArgs(object resource)
20 | {
21 | Resource = resource;
22 | }
23 |
24 | ///
25 | /// 获取加载对象。
26 | ///
27 | public object Resource
28 | {
29 | get;
30 | private set;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceAgentHelperUpdateEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源代理辅助器更新事件。
12 | ///
13 | public sealed class LoadResourceAgentHelperUpdateEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载资源代理辅助器更新事件的新实例。
17 | ///
18 | /// 进度类型。
19 | /// 进度。
20 | public LoadResourceAgentHelperUpdateEventArgs(LoadResourceProgress type, float progress)
21 | {
22 | Type = type;
23 | Progress = progress;
24 | }
25 |
26 | ///
27 | /// 获取进度类型。
28 | ///
29 | public LoadResourceProgress Type
30 | {
31 | get;
32 | private set;
33 | }
34 |
35 | ///
36 | /// 获取进度。
37 | ///
38 | public float Progress
39 | {
40 | get;
41 | private set;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceProgress.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源进度类型。
12 | ///
13 | public enum LoadResourceProgress
14 | {
15 | ///
16 | /// 读取资源包。
17 | ///
18 | ReadResource,
19 |
20 | ///
21 | /// 加载资源包。
22 | ///
23 | LoadResource,
24 |
25 | ///
26 | /// 加载资源。
27 | ///
28 | LoadAsset,
29 |
30 | ///
31 | /// 加载场景。
32 | ///
33 | LoadScene,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadResourceStatus.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载资源状态。
12 | ///
13 | public enum LoadResourceStatus
14 | {
15 | ///
16 | /// 加载资源完成。
17 | ///
18 | Ok = 0,
19 |
20 | ///
21 | /// 资源尚未准备完毕。
22 | ///
23 | NotReady,
24 |
25 | ///
26 | /// 资源不存在于磁盘上。
27 | ///
28 | NotExist,
29 |
30 | ///
31 | /// 依赖资源错误。
32 | ///
33 | DependencyError,
34 |
35 | ///
36 | /// 资源类型错误。
37 | ///
38 | TypeError,
39 |
40 | ///
41 | /// 加载子资源错误。
42 | ///
43 | ChildAssetError,
44 |
45 | ///
46 | /// 加载场景资源错误。
47 | ///
48 | SceneAssetError,
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadSceneDependencyAssetCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载场景时加载依赖资源回调函数。
12 | ///
13 | /// 要加载的场景资源名称。
14 | /// 被加载的依赖资源名称。
15 | /// 当前已加载依赖资源数量。
16 | /// 总共加载依赖资源数量。
17 | /// 用户自定义数据。
18 | public delegate void LoadSceneDependencyAssetCallback(string sceneAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData);
19 | }
20 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadSceneFailureCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载场景失败回调函数。
12 | ///
13 | /// 要加载的场景资源名称。
14 | /// 加载场景状态。
15 | /// 错误信息。
16 | /// 用户自定义数据。
17 | public delegate void LoadSceneFailureCallback(string sceneAssetName, LoadResourceStatus status, string errorMessage, object userData);
18 | }
19 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadSceneSuccessCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载场景成功回调函数。
12 | ///
13 | /// 要加载的场景资源名称。
14 | /// 加载持续时间。
15 | /// 用户自定义数据。
16 | public delegate void LoadSceneSuccessCallback(string sceneAssetName, float duration, object userData);
17 | }
18 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/LoadSceneUpdateCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 加载场景更新回调函数。
12 | ///
13 | /// 要加载的场景资源名称。
14 | /// 加载场景进度。
15 | /// 用户自定义数据。
16 | public delegate void LoadSceneUpdateCallback(string sceneAssetName, float progress, object userData);
17 | }
18 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceInitCompleteEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 资源初始化完成事件。
12 | ///
13 | public sealed class ResourceInitCompleteEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化资源初始化完成事件的新实例。
17 | ///
18 | public ResourceInitCompleteEventArgs()
19 | {
20 |
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.AssetDependencyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | ///
13 | /// 资源依赖信息。
14 | ///
15 | private struct AssetDependencyInfo
16 | {
17 | private readonly string m_AssetName;
18 | private readonly string[] m_DependencyAssetNames;
19 | private readonly string[] m_ScatteredDependencyAssetNames;
20 |
21 | ///
22 | /// 初始化资源依赖信息的新实例。
23 | ///
24 | /// 资源名称。
25 | /// 依赖资源名称。
26 | /// 依赖零散资源名称。
27 | public AssetDependencyInfo(string assetName, string[] dependencyAssetNames, string[] scatteredDependencyAssetNames)
28 | {
29 | m_AssetName = assetName;
30 | m_DependencyAssetNames = dependencyAssetNames;
31 | m_ScatteredDependencyAssetNames = scatteredDependencyAssetNames;
32 | }
33 |
34 | ///
35 | /// 获取资源名称。
36 | ///
37 | public string AssetName
38 | {
39 | get
40 | {
41 | return m_AssetName;
42 | }
43 | }
44 |
45 | ///
46 | /// 获取依赖资源名称。
47 | ///
48 | /// 依赖资源名称。
49 | public string[] GetDependencyAssetNames()
50 | {
51 | return m_DependencyAssetNames;
52 | }
53 |
54 | ///
55 | /// 获取依赖零散资源名称。
56 | ///
57 | /// 依赖零散资源名称。
58 | public string[] GetScatteredDependencyAssetNames()
59 | {
60 | return m_ScatteredDependencyAssetNames;
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.AssetInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | ///
13 | /// 资源信息。
14 | ///
15 | private struct AssetInfo
16 | {
17 | private readonly string m_AssetName;
18 | private readonly ResourceName m_ResourceName;
19 |
20 | ///
21 | /// 初始化资源信息的新实例。
22 | ///
23 | /// 资源名称。
24 | /// 所在资源名称。
25 | public AssetInfo(string assetName, ResourceName resourceName)
26 | {
27 | m_AssetName = assetName;
28 | m_ResourceName = resourceName;
29 | }
30 |
31 | ///
32 | /// 获取资源名称。
33 | ///
34 | public string AssetName
35 | {
36 | get
37 | {
38 | return m_AssetName;
39 | }
40 | }
41 |
42 | ///
43 | /// 获取所在资源名称。
44 | ///
45 | public ResourceName ResourceName
46 | {
47 | get
48 | {
49 | return m_ResourceName;
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.LoadType.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | ///
13 | /// 资源加载方式类型。
14 | ///
15 | private enum LoadType
16 | {
17 | ///
18 | /// 从文件加载。
19 | ///
20 | LoadFromFile = 0,
21 |
22 | ///
23 | /// 从内存加载。
24 | ///
25 | LoadFromMemory,
26 |
27 | ///
28 | /// 从内存快速解密加载。
29 | ///
30 | LoadFromMemoryAndQuickDecrypt,
31 |
32 | ///
33 | /// 从内存解密加载。
34 | ///
35 | LoadFromMemoryAndDecrypt,
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ReadWriteResourceInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | private struct ReadWriteResourceInfo
13 | {
14 | private readonly LoadType m_LoadType;
15 | private readonly int m_Length;
16 | private readonly int m_HashCode;
17 |
18 | public ReadWriteResourceInfo(LoadType loadType, int length, int hashCode)
19 | {
20 | m_LoadType = loadType;
21 | m_Length = length;
22 | m_HashCode = hashCode;
23 | }
24 |
25 | public LoadType LoadType
26 | {
27 | get
28 | {
29 | return m_LoadType;
30 | }
31 | }
32 |
33 | public int Length
34 | {
35 | get
36 | {
37 | return m_Length;
38 | }
39 | }
40 |
41 | public int HashCode
42 | {
43 | get
44 | {
45 | return m_HashCode;
46 | }
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ResourceInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | ///
13 | /// 资源信息。
14 | ///
15 | private struct ResourceInfo
16 | {
17 | private readonly ResourceName m_ResourceName;
18 | private readonly LoadType m_LoadType;
19 | private readonly int m_Length;
20 | private readonly int m_HashCode;
21 | private readonly bool m_StorageInReadOnly;
22 |
23 | ///
24 | /// 初始化资源信息的新实例。
25 | ///
26 | /// 资源名称。
27 | /// 资源加载方式。
28 | /// 资源大小。
29 | /// 资源哈希值。
30 | /// 资源是否在只读区。
31 | public ResourceInfo(ResourceName resourceName, LoadType loadType, int length, int hashCode, bool storageInReadOnly)
32 | {
33 | m_ResourceName = resourceName;
34 | m_LoadType = loadType;
35 | m_Length = length;
36 | m_HashCode = hashCode;
37 | m_StorageInReadOnly = storageInReadOnly;
38 | }
39 |
40 | ///
41 | /// 获取资源名称。
42 | ///
43 | public ResourceName ResourceName
44 | {
45 | get
46 | {
47 | return m_ResourceName;
48 | }
49 | }
50 |
51 | ///
52 | /// 获取资源加载方式。
53 | ///
54 | public LoadType LoadType
55 | {
56 | get
57 | {
58 | return m_LoadType;
59 | }
60 | }
61 |
62 | ///
63 | /// 获取资源大小。
64 | ///
65 | public int Length
66 | {
67 | get
68 | {
69 | return m_Length;
70 | }
71 | }
72 |
73 | ///
74 | /// 获取资源哈希值。
75 | ///
76 | public int HashCode
77 | {
78 | get
79 | {
80 | return m_HashCode;
81 | }
82 | }
83 |
84 | ///
85 | /// 获取资源是否在只读区。
86 | ///
87 | public bool StorageInReadOnly
88 | {
89 | get
90 | {
91 | return m_StorageInReadOnly;
92 | }
93 | }
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ResourceLoader.LoadAssetTask.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework.Resource
11 | {
12 | internal partial class ResourceManager
13 | {
14 | private partial class ResourceLoader
15 | {
16 | private sealed class LoadAssetTask : LoadResourceTaskBase
17 | {
18 | private readonly LoadAssetCallbacks m_LoadAssetCallbacks;
19 |
20 | public LoadAssetTask(string assetName, Type assetType, int priority, ResourceInfo resourceInfo, string resourceChildName, string[] dependencyAssetNames, string[] scatteredDependencyAssetNames, LoadAssetCallbacks loadAssetCallbacks, object userData)
21 | : base(assetName, assetType, priority, resourceInfo, resourceChildName, dependencyAssetNames, scatteredDependencyAssetNames, userData)
22 | {
23 | m_LoadAssetCallbacks = loadAssetCallbacks;
24 | }
25 |
26 | public override bool IsScene
27 | {
28 | get
29 | {
30 | return false;
31 | }
32 | }
33 |
34 | public override void OnLoadAssetSuccess(LoadResourceAgent agent, object asset, float duration)
35 | {
36 | base.OnLoadAssetSuccess(agent, asset, duration);
37 | if (m_LoadAssetCallbacks.LoadAssetSuccessCallback != null)
38 | {
39 | m_LoadAssetCallbacks.LoadAssetSuccessCallback(AssetName, asset, duration, UserData);
40 | }
41 | }
42 |
43 | public override void OnLoadAssetFailure(LoadResourceAgent agent, LoadResourceStatus status, string errorMessage)
44 | {
45 | base.OnLoadAssetFailure(agent, status, errorMessage);
46 | if (m_LoadAssetCallbacks.LoadAssetFailureCallback != null)
47 | {
48 | m_LoadAssetCallbacks.LoadAssetFailureCallback(AssetName, status, errorMessage, UserData);
49 | }
50 | }
51 |
52 | public override void OnLoadAssetUpdate(LoadResourceAgent agent, LoadResourceProgress type, float progress)
53 | {
54 | base.OnLoadAssetUpdate(agent, type, progress);
55 | if (type == LoadResourceProgress.LoadAsset)
56 | {
57 | if (m_LoadAssetCallbacks.LoadAssetUpdateCallback != null)
58 | {
59 | m_LoadAssetCallbacks.LoadAssetUpdateCallback(AssetName, progress, UserData);
60 | }
61 | }
62 | }
63 |
64 | public override void OnLoadDependencyAsset(LoadResourceAgent agent, string dependencyAssetName, object dependencyAsset)
65 | {
66 | base.OnLoadDependencyAsset(agent, dependencyAssetName, dependencyAsset);
67 | if (m_LoadAssetCallbacks.LoadAssetDependencyAssetCallback != null)
68 | {
69 | m_LoadAssetCallbacks.LoadAssetDependencyAssetCallback(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData);
70 | }
71 | }
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ResourceLoader.LoadDependencyAssetTask.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | private partial class ResourceLoader
13 | {
14 | private sealed class LoadDependencyAssetTask : LoadResourceTaskBase
15 | {
16 | private readonly LoadResourceTaskBase m_MainTask;
17 |
18 | public LoadDependencyAssetTask(string assetName, int priority, ResourceInfo resourceInfo, string resourceChildName, string[] dependencyAssetNames, string[] scatteredDependencyAssetNames, LoadResourceTaskBase mainTask, object userData)
19 | : base(assetName, null, priority, resourceInfo, resourceChildName, dependencyAssetNames, scatteredDependencyAssetNames, userData)
20 | {
21 | m_MainTask = mainTask;
22 | m_MainTask.TotalDependencyAssetCount++;
23 | }
24 |
25 | public override bool IsScene
26 | {
27 | get
28 | {
29 | return false;
30 | }
31 | }
32 |
33 | public override void OnLoadAssetSuccess(LoadResourceAgent agent, object asset, float duration)
34 | {
35 | base.OnLoadAssetSuccess(agent, asset, duration);
36 | m_MainTask.OnLoadDependencyAsset(agent, AssetName, asset);
37 | }
38 |
39 | public override void OnLoadAssetFailure(LoadResourceAgent agent, LoadResourceStatus status, string errorMessage)
40 | {
41 | base.OnLoadAssetFailure(agent, status, errorMessage);
42 | m_MainTask.OnLoadAssetFailure(agent, LoadResourceStatus.DependencyError, string.Format("Can not load dependency asset '{0}', internal status '{1}', internal error message '{2}'.", AssetName, status.ToString(), errorMessage));
43 | }
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ResourceLoader.LoadResourceAgent.WaitingType.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | private partial class ResourceLoader
13 | {
14 | private partial class LoadResourceAgent
15 | {
16 | private enum WaitingType
17 | {
18 | None = 0,
19 | WaitForAsset,
20 | WaitForDependencyAsset,
21 | WaitForResource,
22 | }
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ResourceLoader.LoadSceneTask.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | internal partial class ResourceManager
11 | {
12 | private partial class ResourceLoader
13 | {
14 | private sealed class LoadSceneTask : LoadResourceTaskBase
15 | {
16 | private readonly LoadSceneCallbacks m_LoadSceneCallbacks;
17 |
18 | public LoadSceneTask(string sceneAssetName, int priority, ResourceInfo resourceInfo, string resourceChildName, string[] dependencyAssetNames, string[] scatteredDependencyAssetNames, LoadSceneCallbacks loadSceneCallbacks, object userData)
19 | : base(sceneAssetName, null, priority, resourceInfo, resourceChildName, dependencyAssetNames, scatteredDependencyAssetNames, userData)
20 | {
21 | m_LoadSceneCallbacks = loadSceneCallbacks;
22 | }
23 |
24 | public override bool IsScene
25 | {
26 | get
27 | {
28 | return true;
29 | }
30 | }
31 |
32 | public override void OnLoadAssetSuccess(LoadResourceAgent agent, object asset, float duration)
33 | {
34 | base.OnLoadAssetSuccess(agent, asset, duration);
35 | if (m_LoadSceneCallbacks.LoadSceneSuccessCallback != null)
36 | {
37 | m_LoadSceneCallbacks.LoadSceneSuccessCallback(AssetName, duration, UserData);
38 | }
39 | }
40 |
41 | public override void OnLoadAssetFailure(LoadResourceAgent agent, LoadResourceStatus status, string errorMessage)
42 | {
43 | base.OnLoadAssetFailure(agent, status, errorMessage);
44 | if (m_LoadSceneCallbacks.LoadSceneFailureCallback != null)
45 | {
46 | m_LoadSceneCallbacks.LoadSceneFailureCallback(AssetName, status, errorMessage, UserData);
47 | }
48 | }
49 |
50 | public override void OnLoadAssetUpdate(LoadResourceAgent agent, LoadResourceProgress type, float progress)
51 | {
52 | base.OnLoadAssetUpdate(agent, type, progress);
53 | if (type == LoadResourceProgress.LoadScene)
54 | {
55 | if (m_LoadSceneCallbacks.LoadSceneUpdateCallback != null)
56 | {
57 | m_LoadSceneCallbacks.LoadSceneUpdateCallback(AssetName, progress, UserData);
58 | }
59 | }
60 | }
61 |
62 | public override void OnLoadDependencyAsset(LoadResourceAgent agent, string dependencyAssetName, object dependencyAsset)
63 | {
64 | base.OnLoadDependencyAsset(agent, dependencyAssetName, dependencyAsset);
65 | if (m_LoadSceneCallbacks.LoadSceneDependencyAssetCallback != null)
66 | {
67 | m_LoadSceneCallbacks.LoadSceneDependencyAssetCallback(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData);
68 | }
69 | }
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ResourceLoader.ResourceObject.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.ObjectPool;
9 |
10 | namespace GameFramework.Resource
11 | {
12 | internal partial class ResourceManager
13 | {
14 | private partial class ResourceLoader
15 | {
16 | ///
17 | /// 资源对象。
18 | ///
19 | private sealed class ResourceObject : ObjectBase
20 | {
21 | private readonly IResourceHelper m_ResourceHelper;
22 |
23 | public ResourceObject(string name, object target, IResourceHelper resourceHelper)
24 | : base(name, target)
25 | {
26 | if (resourceHelper == null)
27 | {
28 | throw new GameFrameworkException("Resource helper is invalid.");
29 | }
30 |
31 | m_ResourceHelper = resourceHelper;
32 | }
33 |
34 | protected internal override void Release(bool isShutdown)
35 | {
36 | m_ResourceHelper.Release(Target);
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceManager.ResourceNameComparer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace GameFramework.Resource
11 | {
12 | internal partial class ResourceManager
13 | {
14 | ///
15 | /// 资源名称比较器。
16 | ///
17 | private sealed class ResourceNameComparer : IComparer, IEqualityComparer
18 | {
19 | public int Compare(ResourceName x, ResourceName y)
20 | {
21 | return x.CompareTo(y);
22 | }
23 |
24 | public bool Equals(ResourceName x, ResourceName y)
25 | {
26 | return x.Equals(y);
27 | }
28 |
29 | public int GetHashCode(ResourceName obj)
30 | {
31 | return obj.GetHashCode();
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/ResourceMode.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 资源模式。
12 | ///
13 | public enum ResourceMode
14 | {
15 | ///
16 | /// 未指定。
17 | ///
18 | Unspecified = 0,
19 |
20 | ///
21 | /// 单机模式。
22 | ///
23 | Package,
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/UnloadSceneCallbacks.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 卸载场景回调函数集。
12 | ///
13 | public sealed class UnloadSceneCallbacks
14 | {
15 | private readonly UnloadSceneSuccessCallback m_UnloadSceneSuccessCallback;
16 | private readonly UnloadSceneFailureCallback m_UnloadSceneFailureCallback;
17 |
18 | ///
19 | /// 初始化卸载场景回调函数集的新实例。
20 | ///
21 | /// 卸载场景成功回调函数。
22 | public UnloadSceneCallbacks(UnloadSceneSuccessCallback unloadSceneSuccessCallback)
23 | : this(unloadSceneSuccessCallback, null)
24 | {
25 |
26 | }
27 |
28 | ///
29 | /// 初始化卸载场景回调函数集的新实例。
30 | ///
31 | /// 卸载场景成功回调函数。
32 | /// 卸载场景失败回调函数。
33 | public UnloadSceneCallbacks(UnloadSceneSuccessCallback unloadSceneSuccessCallback, UnloadSceneFailureCallback unloadSceneFailureCallback)
34 | {
35 | if (unloadSceneSuccessCallback == null)
36 | {
37 | throw new GameFrameworkException("Unload scene success callback is invalid.");
38 | }
39 |
40 | m_UnloadSceneSuccessCallback = unloadSceneSuccessCallback;
41 | m_UnloadSceneFailureCallback = unloadSceneFailureCallback;
42 | }
43 |
44 | ///
45 | /// 获取卸载场景成功回调函数。
46 | ///
47 | public UnloadSceneSuccessCallback UnloadSceneSuccessCallback
48 | {
49 | get
50 | {
51 | return m_UnloadSceneSuccessCallback;
52 | }
53 | }
54 |
55 | ///
56 | /// 获取卸载场景失败回调函数。
57 | ///
58 | public UnloadSceneFailureCallback UnloadSceneFailureCallback
59 | {
60 | get
61 | {
62 | return m_UnloadSceneFailureCallback;
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/UnloadSceneFailureCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 卸载场景失败回调函数。
12 | ///
13 | /// 要卸载的场景资源名称。
14 | /// 用户自定义数据。
15 | public delegate void UnloadSceneFailureCallback(string sceneAssetName, object userData);
16 | }
17 |
--------------------------------------------------------------------------------
/Resource/Impl/GF/UnloadSceneSuccessCallback.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 卸载场景成功回调函数。
12 | ///
13 | /// 要卸载的场景资源名称。
14 | /// 用户自定义数据。
15 | public delegate void UnloadSceneSuccessCallback(string sceneAssetName, object userData);
16 | }
17 |
--------------------------------------------------------------------------------
/Resource/Impl/UnityGF/Editor/GameFrameworkInspector.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using UnityEditor;
9 |
10 | namespace UnityGameFramework.Editor
11 | {
12 | ///
13 | /// 游戏框架 Inspector 抽象类。
14 | ///
15 | public abstract class GameFrameworkInspector : UnityEditor.Editor
16 | {
17 | private bool m_IsCompiling = false;
18 |
19 | ///
20 | /// 绘制事件。
21 | ///
22 | public override void OnInspectorGUI()
23 | {
24 | if (m_IsCompiling && !EditorApplication.isCompiling)
25 | {
26 | m_IsCompiling = false;
27 | OnCompileComplete();
28 | }
29 | else if (!m_IsCompiling && EditorApplication.isCompiling)
30 | {
31 | m_IsCompiling = true;
32 | OnCompileStart();
33 | }
34 | }
35 |
36 | ///
37 | /// 编译开始事件。
38 | ///
39 | protected virtual void OnCompileStart()
40 | {
41 |
42 | }
43 |
44 | ///
45 | /// 编译完成事件。
46 | ///
47 | protected virtual void OnCompileComplete()
48 | {
49 |
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Resource/Impl/UnityGF/Runtime/LoadResourceAgentHelperBase.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Resource;
9 | using System;
10 | using UnityEngine;
11 |
12 | namespace UnityGameFramework.Runtime
13 | {
14 | ///
15 | /// 加载资源代理辅助器基类。
16 | ///
17 | public abstract class LoadResourceAgentHelperBase : MonoBehaviour, ILoadResourceAgentHelper
18 | {
19 | ///
20 | /// 加载资源代理辅助器异步加载资源更新事件。
21 | ///
22 | public abstract event EventHandler LoadResourceAgentHelperUpdate;
23 |
24 | ///
25 | /// 加载资源代理辅助器异步读取资源文件完成事件。
26 | ///
27 | public abstract event EventHandler LoadResourceAgentHelperReadFileComplete;
28 |
29 | ///
30 | /// 加载资源代理辅助器异步读取资源二进制流完成事件。
31 | ///
32 | public abstract event EventHandler LoadResourceAgentHelperReadBytesComplete;
33 |
34 | ///
35 | /// 加载资源代理辅助器异步将资源二进制流转换为加载对象完成事件。
36 | ///
37 | public abstract event EventHandler LoadResourceAgentHelperParseBytesComplete;
38 |
39 | ///
40 | /// 加载资源代理辅助器异步加载资源完成事件。
41 | ///
42 | public abstract event EventHandler LoadResourceAgentHelperLoadComplete;
43 |
44 | ///
45 | /// 加载资源代理辅助器错误事件。
46 | ///
47 | public abstract event EventHandler LoadResourceAgentHelperError;
48 |
49 | ///
50 | /// 通过加载资源代理辅助器开始异步读取资源文件。
51 | ///
52 | /// 要加载资源的完整路径名。
53 | public abstract void ReadFile(string fullPath);
54 |
55 | ///
56 | /// 通过加载资源代理辅助器开始异步读取资源二进制流。
57 | ///
58 | /// 要加载资源的完整路径名。
59 | /// 资源加载方式。
60 | public abstract void ReadBytes(string fullPath, int loadType);
61 |
62 | ///
63 | /// 通过加载资源代理辅助器开始异步将资源二进制流转换为加载对象。
64 | ///
65 | /// 要加载资源的二进制流。
66 | public abstract void ParseBytes(byte[] bytes);
67 |
68 | ///
69 | /// 通过加载资源代理辅助器开始异步加载资源。
70 | ///
71 | /// 资源。
72 | /// 要加载的子资源名。
73 | /// 要加载资源的类型。
74 | /// 要加载的资源是否是场景。
75 | public abstract void LoadAsset(object resource, string resourceChildName, Type assetType, bool isScene);
76 |
77 | ///
78 | /// 重置加载资源代理辅助器。
79 | ///
80 | public abstract void Reset();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Resource/Impl/UnityGF/Runtime/ReadWritePathType.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Runtime
9 | {
10 | ///
11 | /// 读写区路径类型。
12 | ///
13 | public enum ReadWritePathType
14 | {
15 | ///
16 | /// 未指定。
17 | ///
18 | Unspecified = 0,
19 |
20 | ///
21 | /// 临时缓存。
22 | ///
23 | TemporaryCache,
24 |
25 | ///
26 | /// 持久化数据。
27 | ///
28 | PersistentData,
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Resource/Impl/UnityGF/Runtime/ResourceHelperBase.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Resource;
9 | using UnityEngine;
10 |
11 | namespace UnityGameFramework.Runtime
12 | {
13 | ///
14 | /// 资源辅助器基类。
15 | ///
16 | public abstract class ResourceHelperBase : MonoBehaviour, IResourceHelper
17 | {
18 | ///
19 | /// 直接从指定文件路径读取数据流。
20 | ///
21 | /// 文件路径。
22 | /// 读取数据流回调函数。
23 | public abstract void LoadBytes(string fileUri, LoadBytesCallback loadBytesCallback);
24 |
25 | ///
26 | /// 卸载场景。
27 | ///
28 | /// 场景资源名称。
29 | /// 卸载场景回调函数集。
30 | /// 用户自定义数据。
31 | public abstract void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData);
32 |
33 | ///
34 | /// 释放资源。
35 | ///
36 | /// 要释放的资源。
37 | public abstract void Release(object objectToRelease);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Resource/Impl/UnityGF/Runtime/ResourceInitCompleteEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Event;
9 |
10 | namespace UnityGameFramework.Runtime
11 | {
12 | ///
13 | /// 资源初始化完成事件。
14 | ///
15 | public sealed class ResourceInitCompleteEventArgs : GameEventArgs
16 | {
17 | ///
18 | /// 资源初始化完成事件编号。
19 | ///
20 | public static readonly int EventId = typeof(ResourceInitCompleteEventArgs).GetHashCode();
21 |
22 | ///
23 | /// 获取资源初始化完成事件编号。
24 | ///
25 | public override int Id
26 | {
27 | get
28 | {
29 | return EventId;
30 | }
31 | }
32 |
33 | ///
34 | /// 清理资源初始化完成事件。
35 | ///
36 | public override void Clear()
37 | {
38 |
39 | }
40 |
41 | ///
42 | /// 填充资源初始化完成事件。
43 | ///
44 | /// 内部事件。
45 | /// 资源初始化完成事件。
46 | public ResourceInitCompleteEventArgs Fill(GameFramework.Resource.ResourceInitCompleteEventArgs e)
47 | {
48 | return this;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Resource/Impl/UnityGF/Runtime/SceneAsset.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace UnityGameFramework.Runtime
9 | {
10 | internal sealed class SceneAsset
11 | {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Resource/Interface/ILoadResourceAgentHelper.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework.Resource
11 | {
12 | ///
13 | /// 加载资源代理辅助器接口。
14 | ///
15 | public interface ILoadResourceAgentHelper
16 | {
17 | ///
18 | /// 加载资源代理辅助器异步加载资源更新事件。
19 | ///
20 | event EventHandler LoadResourceAgentHelperUpdate;
21 |
22 | ///
23 | /// 加载资源代理辅助器异步读取资源文件完成事件。
24 | ///
25 | event EventHandler LoadResourceAgentHelperReadFileComplete;
26 |
27 | ///
28 | /// 加载资源代理辅助器异步读取资源二进制流完成事件。
29 | ///
30 | event EventHandler LoadResourceAgentHelperReadBytesComplete;
31 |
32 | ///
33 | /// 加载资源代理辅助器异步将资源二进制流转换为加载对象完成事件。
34 | ///
35 | event EventHandler LoadResourceAgentHelperParseBytesComplete;
36 |
37 | ///
38 | /// 加载资源代理辅助器异步加载资源完成事件。
39 | ///
40 | event EventHandler LoadResourceAgentHelperLoadComplete;
41 |
42 | ///
43 | /// 加载资源代理辅助器错误事件。
44 | ///
45 | event EventHandler LoadResourceAgentHelperError;
46 |
47 | ///
48 | /// 通过加载资源代理辅助器开始异步读取资源文件。
49 | ///
50 | /// 要加载资源的完整路径名。
51 | void ReadFile(string fullPath);
52 |
53 | ///
54 | /// 通过加载资源代理辅助器开始异步读取资源二进制流。
55 | ///
56 | /// 要加载资源的完整路径名。
57 | /// 资源加载方式。
58 | void ReadBytes(string fullPath, int loadType);
59 |
60 | ///
61 | /// 通过加载资源代理辅助器开始异步将资源二进制流转换为加载对象。
62 | ///
63 | /// 要加载资源的二进制流。
64 | void ParseBytes(byte[] bytes);
65 |
66 | ///
67 | /// 通过加载资源代理辅助器开始异步加载资源。
68 | ///
69 | /// 资源。
70 | /// 要加载的子资源名。
71 | /// 要加载资源的类型。
72 | /// 要加载的资源是否是场景。
73 | void LoadAsset(object resource, string resourceChildName, Type assetType, bool isScene);
74 |
75 | ///
76 | /// 重置加载资源代理辅助器。
77 | ///
78 | void Reset();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/Resource/Interface/IResourceHelper.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Resource
9 | {
10 | ///
11 | /// 资源辅助器接口。
12 | ///
13 | public interface IResourceHelper
14 | {
15 | ///
16 | /// 直接从指定文件路径读取数据流。
17 | ///
18 | /// 文件路径。
19 | /// 读取数据流回调函数。
20 | void LoadBytes(string fileUri, LoadBytesCallback loadBytesCallback);
21 |
22 | ///
23 | /// 卸载场景。
24 | ///
25 | /// 场景资源名称。
26 | /// 卸载场景回调函数集。
27 | /// 用户自定义数据。
28 | void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData);
29 |
30 | ///
31 | /// 释放资源。
32 | ///
33 | /// 要释放的资源。
34 | void Release(object objectToRelease);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Scene/GF/LoadSceneDependencyAssetEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Scene
9 | {
10 | ///
11 | /// 加载场景时加载依赖资源事件。
12 | ///
13 | public sealed class LoadSceneDependencyAssetEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载场景时加载依赖资源事件的新实例。
17 | ///
18 | /// 场景资源名称。
19 | /// 被加载的依赖资源名称。
20 | /// 当前已加载依赖资源数量。
21 | /// 总共加载依赖资源数量。
22 | /// 用户自定义数据。
23 | public LoadSceneDependencyAssetEventArgs(string sceneAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData)
24 | {
25 | SceneAssetName = sceneAssetName;
26 | DependencyAssetName = dependencyAssetName;
27 | LoadedCount = loadedCount;
28 | TotalCount = totalCount;
29 | UserData = userData;
30 | }
31 |
32 | ///
33 | /// 获取场景资源名称。
34 | ///
35 | public string SceneAssetName
36 | {
37 | get;
38 | private set;
39 | }
40 |
41 | ///
42 | /// 获取被加载的依赖资源名称。
43 | ///
44 | public string DependencyAssetName
45 | {
46 | get;
47 | private set;
48 | }
49 |
50 | ///
51 | /// 获取当前已加载依赖资源数量。
52 | ///
53 | public int LoadedCount
54 | {
55 | get;
56 | private set;
57 | }
58 |
59 | ///
60 | /// 获取总共加载依赖资源数量。
61 | ///
62 | public int TotalCount
63 | {
64 | get;
65 | private set;
66 | }
67 |
68 | ///
69 | /// 获取用户自定义数据。
70 | ///
71 | public object UserData
72 | {
73 | get;
74 | private set;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Scene/GF/LoadSceneFailureEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Scene
9 | {
10 | ///
11 | /// 加载场景失败事件。
12 | ///
13 | public sealed class LoadSceneFailureEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载场景失败事件的新实例。
17 | ///
18 | /// 场景资源名称。
19 | /// 错误信息。
20 | /// 用户自定义数据。
21 | public LoadSceneFailureEventArgs(string sceneAssetName, string errorMessage, object userData)
22 | {
23 | SceneAssetName = sceneAssetName;
24 | ErrorMessage = errorMessage;
25 | UserData = userData;
26 | }
27 |
28 | ///
29 | /// 获取场景资源名称。
30 | ///
31 | public string SceneAssetName
32 | {
33 | get;
34 | private set;
35 | }
36 |
37 | ///
38 | /// 获取错误信息。
39 | ///
40 | public string ErrorMessage
41 | {
42 | get;
43 | private set;
44 | }
45 |
46 | ///
47 | /// 获取用户自定义数据。
48 | ///
49 | public object UserData
50 | {
51 | get;
52 | private set;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Scene/GF/LoadSceneSuccessEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Scene
9 | {
10 | ///
11 | /// 加载场景成功事件。
12 | ///
13 | public sealed class LoadSceneSuccessEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载场景成功事件的新实例。
17 | ///
18 | /// 场景资源名称。
19 | /// 加载持续时间。
20 | /// 用户自定义数据。
21 | public LoadSceneSuccessEventArgs(string sceneAssetName, float duration, object userData)
22 | {
23 | SceneAssetName = sceneAssetName;
24 | Duration = duration;
25 | UserData = userData;
26 | }
27 |
28 | ///
29 | /// 获取场景资源名称。
30 | ///
31 | public string SceneAssetName
32 | {
33 | get;
34 | private set;
35 | }
36 |
37 | ///
38 | /// 获取加载持续时间。
39 | ///
40 | public float Duration
41 | {
42 | get;
43 | private set;
44 | }
45 |
46 | ///
47 | /// 获取用户自定义数据。
48 | ///
49 | public object UserData
50 | {
51 | get;
52 | private set;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Scene/GF/LoadSceneUpdateEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Scene
9 | {
10 | ///
11 | /// 加载场景更新事件。
12 | ///
13 | public sealed class LoadSceneUpdateEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化加载场景更新事件的新实例。
17 | ///
18 | /// 场景资源名称。
19 | /// 加载场景进度。
20 | /// 用户自定义数据。
21 | public LoadSceneUpdateEventArgs(string sceneAssetName, float progress, object userData)
22 | {
23 | SceneAssetName = sceneAssetName;
24 | Progress = progress;
25 | UserData = userData;
26 | }
27 |
28 | ///
29 | /// 获取场景资源名称。
30 | ///
31 | public string SceneAssetName
32 | {
33 | get;
34 | private set;
35 | }
36 |
37 | ///
38 | /// 获取加载场景进度。
39 | ///
40 | public float Progress
41 | {
42 | get;
43 | private set;
44 | }
45 |
46 | ///
47 | /// 获取用户自定义数据。
48 | ///
49 | public object UserData
50 | {
51 | get;
52 | private set;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Scene/GF/UnloadSceneFailureEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Scene
9 | {
10 | ///
11 | /// 卸载场景失败事件。
12 | ///
13 | public sealed class UnloadSceneFailureEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化卸载场景失败事件的新实例。
17 | ///
18 | /// 场景资源名称。
19 | /// 用户自定义数据。
20 | public UnloadSceneFailureEventArgs(string sceneAssetName, object userData)
21 | {
22 | SceneAssetName = sceneAssetName;
23 | UserData = userData;
24 | }
25 |
26 | ///
27 | /// 获取场景资源名称。
28 | ///
29 | public string SceneAssetName
30 | {
31 | get;
32 | private set;
33 | }
34 |
35 | ///
36 | /// 获取用户自定义数据。
37 | ///
38 | public object UserData
39 | {
40 | get;
41 | private set;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Scene/GF/UnloadSceneSuccessEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework.Scene
9 | {
10 | ///
11 | /// 卸载场景成功事件。
12 | ///
13 | public sealed class UnloadSceneSuccessEventArgs : GameFrameworkEventArgs
14 | {
15 | ///
16 | /// 初始化卸载场景成功事件的新实例。
17 | ///
18 | /// 场景资源名称。
19 | /// 用户自定义数据。
20 | public UnloadSceneSuccessEventArgs(string sceneAssetName, object userData)
21 | {
22 | SceneAssetName = sceneAssetName;
23 | UserData = userData;
24 | }
25 |
26 | ///
27 | /// 获取场景资源名称。
28 | ///
29 | public string SceneAssetName
30 | {
31 | get;
32 | private set;
33 | }
34 |
35 | ///
36 | /// 获取用户自定义数据。
37 | ///
38 | public object UserData
39 | {
40 | get;
41 | private set;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Scene/UnityGF/Editor/SceneComponentInspector.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using UnityEditor;
9 | using UnityEngine;
10 | using UnityGameFramework.Runtime;
11 |
12 | namespace UnityGameFramework.Editor
13 | {
14 | [CustomEditor(typeof(SceneComponent))]
15 | internal sealed class SceneComponentInspector : GameFrameworkInspector
16 | {
17 | private SerializedProperty m_EnableLoadSceneSuccessEvent = null;
18 | private SerializedProperty m_EnableLoadSceneFailureEvent = null;
19 | private SerializedProperty m_EnableLoadSceneUpdateEvent = null;
20 | private SerializedProperty m_EnableLoadSceneDependencyAssetEvent = null;
21 | private SerializedProperty m_EnableUnloadSceneSuccessEvent = null;
22 | private SerializedProperty m_EnableUnloadSceneFailureEvent = null;
23 | private SerializedProperty _baseComponent = null;
24 | private SerializedProperty _eventComponent = null;
25 | public override void OnInspectorGUI()
26 | {
27 | base.OnInspectorGUI();
28 |
29 | serializedObject.Update();
30 |
31 | SceneComponent t = (SceneComponent)target;
32 | EditorGUI.BeginDisabledGroup(true);
33 | EditorGUILayout.PropertyField(_baseComponent);
34 | EditorGUILayout.PropertyField(_eventComponent);
35 | EditorGUI.EndDisabledGroup();
36 | EditorGUILayout.PropertyField(m_EnableLoadSceneSuccessEvent);
37 | EditorGUILayout.PropertyField(m_EnableLoadSceneFailureEvent);
38 | EditorGUILayout.PropertyField(m_EnableLoadSceneUpdateEvent);
39 | EditorGUILayout.PropertyField(m_EnableLoadSceneDependencyAssetEvent);
40 | EditorGUILayout.PropertyField(m_EnableUnloadSceneSuccessEvent);
41 | EditorGUILayout.PropertyField(m_EnableUnloadSceneFailureEvent);
42 |
43 | serializedObject.ApplyModifiedProperties();
44 |
45 | if (EditorApplication.isPlaying && PrefabUtility.GetPrefabType(t.gameObject) != PrefabType.Prefab)
46 | {
47 | EditorGUILayout.LabelField("Loaded Scene Asset Names", GetSceneNameString(t.GetLoadedSceneAssetNames()));
48 | EditorGUILayout.LabelField("Loading Scene Asset Names", GetSceneNameString(t.GetLoadingSceneAssetNames()));
49 | EditorGUILayout.LabelField("Unloading Scene Asset Names", GetSceneNameString(t.GetUnloadingSceneAssetNames()));
50 | EditorGUILayout.ObjectField("Main Camera", t.MainCamera, typeof(Camera), true);
51 |
52 | Repaint();
53 | }
54 | }
55 |
56 | private void OnEnable()
57 | {
58 | _baseComponent = serializedObject.FindProperty("_baseComponent");
59 | _eventComponent = serializedObject.FindProperty("_eventComponent");
60 |
61 | m_EnableLoadSceneSuccessEvent = serializedObject.FindProperty("m_EnableLoadSceneSuccessEvent");
62 | m_EnableLoadSceneFailureEvent = serializedObject.FindProperty("m_EnableLoadSceneFailureEvent");
63 | m_EnableLoadSceneUpdateEvent = serializedObject.FindProperty("m_EnableLoadSceneUpdateEvent");
64 | m_EnableLoadSceneDependencyAssetEvent = serializedObject.FindProperty("m_EnableLoadSceneDependencyAssetEvent");
65 | m_EnableUnloadSceneSuccessEvent = serializedObject.FindProperty("m_EnableUnloadSceneSuccessEvent");
66 | m_EnableUnloadSceneFailureEvent = serializedObject.FindProperty("m_EnableUnloadSceneFailureEvent");
67 | }
68 |
69 | private string GetSceneNameString(string[] sceneAssetNames)
70 | {
71 | if (sceneAssetNames == null || sceneAssetNames.Length <= 0)
72 | {
73 | return "";
74 | }
75 |
76 | string sceneNameString = string.Empty;
77 | foreach (string sceneAssetName in sceneAssetNames)
78 | {
79 | if (!string.IsNullOrEmpty(sceneNameString))
80 | {
81 | sceneNameString += ", ";
82 | }
83 |
84 | sceneNameString += SceneComponent.GetSceneName(sceneAssetName);
85 | }
86 |
87 | return sceneNameString;
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/Scene/UnityGF/LoadSceneDependencyAssetEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Event;
9 |
10 | namespace UnityGameFramework.Runtime
11 | {
12 | ///
13 | /// 加载场景时加载依赖资源事件。
14 | ///
15 | public sealed class LoadSceneDependencyAssetEventArgs : GameEventArgs
16 | {
17 | ///
18 | /// 加载场景时加载依赖资源事件编号。
19 | ///
20 | public static readonly int EventId = typeof(LoadSceneDependencyAssetEventArgs).GetHashCode();
21 |
22 | ///
23 | /// 获取加载场景时加载依赖资源事件编号。
24 | ///
25 | public override int Id
26 | {
27 | get
28 | {
29 | return EventId;
30 | }
31 | }
32 |
33 | ///
34 | /// 获取场景资源名称。
35 | ///
36 | public string SceneAssetName
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | ///
43 | /// 获取被加载的依赖资源名称。
44 | ///
45 | public string DependencyAssetName
46 | {
47 | get;
48 | private set;
49 | }
50 |
51 | ///
52 | /// 获取当前已加载依赖资源数量。
53 | ///
54 | public int LoadedCount
55 | {
56 | get;
57 | private set;
58 | }
59 |
60 | ///
61 | /// 获取总共加载依赖资源数量。
62 | ///
63 | public int TotalCount
64 | {
65 | get;
66 | private set;
67 | }
68 |
69 | ///
70 | /// 获取用户自定义数据。
71 | ///
72 | public object UserData
73 | {
74 | get;
75 | private set;
76 | }
77 |
78 | ///
79 | /// 清理加载场景时加载依赖资源事件。
80 | ///
81 | public override void Clear()
82 | {
83 | SceneAssetName = default(string);
84 | DependencyAssetName = default(string);
85 | LoadedCount = default(int);
86 | TotalCount = default(int);
87 | UserData = default(object);
88 | }
89 |
90 | ///
91 | /// 填充加载场景时加载依赖资源事件。
92 | ///
93 | /// 内部事件。
94 | /// 加载场景时加载依赖资源事件。
95 | public LoadSceneDependencyAssetEventArgs Fill(GameFramework.Scene.LoadSceneDependencyAssetEventArgs e)
96 | {
97 | SceneAssetName = e.SceneAssetName;
98 | DependencyAssetName = e.DependencyAssetName;
99 | LoadedCount = e.LoadedCount;
100 | TotalCount = e.TotalCount;
101 | UserData = e.UserData;
102 |
103 | return this;
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/Scene/UnityGF/LoadSceneFailureEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Event;
9 |
10 | namespace UnityGameFramework.Runtime
11 | {
12 | ///
13 | /// 加载场景失败事件。
14 | ///
15 | public sealed class LoadSceneFailureEventArgs : GameEventArgs
16 | {
17 | ///
18 | /// 加载场景失败事件编号。
19 | ///
20 | public static readonly int EventId = typeof(LoadSceneFailureEventArgs).GetHashCode();
21 |
22 | ///
23 | /// 获取加载场景失败事件编号。
24 | ///
25 | public override int Id
26 | {
27 | get
28 | {
29 | return EventId;
30 | }
31 | }
32 |
33 | ///
34 | /// 获取场景资源名称。
35 | ///
36 | public string SceneAssetName
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | ///
43 | /// 获取错误信息。
44 | ///
45 | public string ErrorMessage
46 | {
47 | get;
48 | private set;
49 | }
50 |
51 | ///
52 | /// 获取用户自定义数据。
53 | ///
54 | public object UserData
55 | {
56 | get;
57 | private set;
58 | }
59 |
60 | ///
61 | /// 清理加载场景失败事件。
62 | ///
63 | public override void Clear()
64 | {
65 | SceneAssetName = default(string);
66 | ErrorMessage = default(string);
67 | UserData = default(object);
68 | }
69 |
70 | ///
71 | /// 填充加载场景失败事件。
72 | ///
73 | /// 内部事件。
74 | /// 加载场景失败事件。
75 | public LoadSceneFailureEventArgs Fill(GameFramework.Scene.LoadSceneFailureEventArgs e)
76 | {
77 | SceneAssetName = e.SceneAssetName;
78 | ErrorMessage = e.ErrorMessage;
79 | UserData = e.UserData;
80 |
81 | return this;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Scene/UnityGF/LoadSceneSuccessEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Event;
9 |
10 | namespace UnityGameFramework.Runtime
11 | {
12 | ///
13 | /// 加载场景成功事件。
14 | ///
15 | public sealed class LoadSceneSuccessEventArgs : GameEventArgs
16 | {
17 | ///
18 | /// 加载场景成功事件编号。
19 | ///
20 | public static readonly int EventId = typeof(LoadSceneSuccessEventArgs).GetHashCode();
21 |
22 | ///
23 | /// 获取加载场景成功事件编号。
24 | ///
25 | public override int Id
26 | {
27 | get
28 | {
29 | return EventId;
30 | }
31 | }
32 |
33 | ///
34 | /// 获取场景资源名称。
35 | ///
36 | public string SceneAssetName
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | ///
43 | /// 获取加载持续时间。
44 | ///
45 | public float Duration
46 | {
47 | get;
48 | private set;
49 | }
50 |
51 | ///
52 | /// 获取用户自定义数据。
53 | ///
54 | public object UserData
55 | {
56 | get;
57 | private set;
58 | }
59 |
60 | ///
61 | /// 清理加载场景成功事件。
62 | ///
63 | public override void Clear()
64 | {
65 | SceneAssetName = default(string);
66 | Duration = default(float);
67 | UserData = default(object);
68 | }
69 |
70 | ///
71 | /// 填充加载场景成功事件。
72 | ///
73 | /// 内部事件。
74 | /// 加载场景成功事件。
75 | public LoadSceneSuccessEventArgs Fill(GameFramework.Scene.LoadSceneSuccessEventArgs e)
76 | {
77 | SceneAssetName = e.SceneAssetName;
78 | Duration = e.Duration;
79 | UserData = e.UserData;
80 |
81 | return this;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Scene/UnityGF/LoadSceneUpdateEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Event;
9 |
10 | namespace UnityGameFramework.Runtime
11 | {
12 | ///
13 | /// 加载场景更新事件。
14 | ///
15 | public sealed class LoadSceneUpdateEventArgs : GameEventArgs
16 | {
17 | ///
18 | /// 加载场景更新事件编号。
19 | ///
20 | public static readonly int EventId = typeof(LoadSceneUpdateEventArgs).GetHashCode();
21 |
22 | ///
23 | /// 获取加载场景更新事件编号。
24 | ///
25 | public override int Id
26 | {
27 | get
28 | {
29 | return EventId;
30 | }
31 | }
32 |
33 | ///
34 | /// 获取场景资源名称。
35 | ///
36 | public string SceneAssetName
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | ///
43 | /// 获取加载场景进度。
44 | ///
45 | public float Progress
46 | {
47 | get;
48 | private set;
49 | }
50 |
51 | ///
52 | /// 获取用户自定义数据。
53 | ///
54 | public object UserData
55 | {
56 | get;
57 | private set;
58 | }
59 |
60 | ///
61 | /// 清理加载场景更新事件。
62 | ///
63 | public override void Clear()
64 | {
65 | SceneAssetName = default(string);
66 | Progress = default(float);
67 | UserData = default(object);
68 | }
69 |
70 | ///
71 | /// 填充加载场景更新事件。
72 | ///
73 | /// 内部事件。
74 | /// 加载场景更新事件。
75 | public LoadSceneUpdateEventArgs Fill(GameFramework.Scene.LoadSceneUpdateEventArgs e)
76 | {
77 | SceneAssetName = e.SceneAssetName;
78 | Progress = e.Progress;
79 | UserData = e.UserData;
80 |
81 | return this;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Scene/UnityGF/UnloadSceneFailureEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Event;
9 |
10 | namespace UnityGameFramework.Runtime
11 | {
12 | ///
13 | /// 卸载场景失败事件。
14 | ///
15 | public sealed class UnloadSceneFailureEventArgs : GameEventArgs
16 | {
17 | ///
18 | /// 加载场景失败事件编号。
19 | ///
20 | public static readonly int EventId = typeof(UnloadSceneFailureEventArgs).GetHashCode();
21 |
22 | ///
23 | /// 获取加载场景失败事件编号。
24 | ///
25 | public override int Id
26 | {
27 | get
28 | {
29 | return EventId;
30 | }
31 | }
32 |
33 | ///
34 | /// 获取场景资源名称。
35 | ///
36 | public string SceneAssetName
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | ///
43 | /// 获取用户自定义数据。
44 | ///
45 | public object UserData
46 | {
47 | get;
48 | private set;
49 | }
50 |
51 | ///
52 | /// 清理卸载场景失败事件。
53 | ///
54 | public override void Clear()
55 | {
56 | SceneAssetName = default(string);
57 | UserData = default(object);
58 | }
59 |
60 | ///
61 | /// 填充卸载场景失败事件。
62 | ///
63 | /// 内部事件。
64 | /// 卸载场景失败事件。
65 | public UnloadSceneFailureEventArgs Fill(GameFramework.Scene.UnloadSceneFailureEventArgs e)
66 | {
67 | SceneAssetName = e.SceneAssetName;
68 | UserData = e.UserData;
69 |
70 | return this;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Scene/UnityGF/UnloadSceneSuccessEventArgs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework.Event;
9 |
10 | namespace UnityGameFramework.Runtime
11 | {
12 | ///
13 | /// 卸载场景成功事件。
14 | ///
15 | public sealed class UnloadSceneSuccessEventArgs : GameEventArgs
16 | {
17 | ///
18 | /// 加载场景成功事件编号。
19 | ///
20 | public static readonly int EventId = typeof(UnloadSceneSuccessEventArgs).GetHashCode();
21 |
22 | ///
23 | /// 获取加载场景成功事件编号。
24 | ///
25 | public override int Id
26 | {
27 | get
28 | {
29 | return EventId;
30 | }
31 | }
32 |
33 | ///
34 | /// 获取场景资源名称。
35 | ///
36 | public string SceneAssetName
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | ///
43 | /// 获取用户自定义数据。
44 | ///
45 | public object UserData
46 | {
47 | get;
48 | private set;
49 | }
50 |
51 | ///
52 | /// 清理卸载场景成功事件。
53 | ///
54 | public override void Clear()
55 | {
56 | SceneAssetName = default(string);
57 | UserData = default(object);
58 | }
59 |
60 | ///
61 | /// 填充卸载场景成功事件。
62 | ///
63 | /// 内部事件。
64 | /// 卸载场景成功事件。
65 | public UnloadSceneSuccessEventArgs Fill(GameFramework.Scene.UnloadSceneSuccessEventArgs e)
66 | {
67 | SceneAssetName = e.SceneAssetName;
68 | UserData = e.UserData;
69 |
70 | return this;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Utility/Assembly.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 | using System.Collections.Generic;
10 |
11 | namespace GameFramework
12 | {
13 | public static partial class Utility
14 | {
15 | ///
16 | /// 程序集相关的实用函数。
17 | ///
18 | public static class Assembly
19 | {
20 | private static readonly System.Reflection.Assembly[] s_Assemblies = null;
21 | private static readonly Dictionary s_CachedTypes = new Dictionary();
22 |
23 | static Assembly()
24 | {
25 | s_Assemblies = AppDomain.CurrentDomain.GetAssemblies();
26 | }
27 |
28 | ///
29 | /// 获取已加载的程序集。
30 | ///
31 | /// 已加载的程序集。
32 | public static System.Reflection.Assembly[] GetAssemblies()
33 | {
34 | return s_Assemblies;
35 | }
36 |
37 | ///
38 | /// 获取已加载的程序集中的所有类型。
39 | ///
40 | /// 已加载的程序集中的所有类型。
41 | public static Type[] GetTypes()
42 | {
43 | List allTypes = new List();
44 | for (int i = 0; i < s_Assemblies.Length; i++)
45 | {
46 | allTypes.AddRange(s_Assemblies[i].GetTypes());
47 | }
48 |
49 | return allTypes.ToArray();
50 | }
51 |
52 | ///
53 | /// 获取已加载的程序集中的指定类型。
54 | ///
55 | /// 要获取的类型名。
56 | /// 已加载的程序集中的指定类型。
57 | public static Type GetType(string typeName)
58 | {
59 | if (string.IsNullOrEmpty(typeName))
60 | {
61 | throw new GameFrameworkException("Type name is invalid.");
62 | }
63 |
64 | Type type = null;
65 | if (s_CachedTypes.TryGetValue(typeName, out type))
66 | {
67 | return type;
68 | }
69 |
70 | type = Type.GetType(typeName);
71 | if (type != null)
72 | {
73 | s_CachedTypes.Add(typeName, type);
74 | return type;
75 | }
76 |
77 | foreach (System.Reflection.Assembly assembly in s_Assemblies)
78 | {
79 | type = Type.GetType(string.Format("{0}, {1}", typeName, assembly.FullName));
80 | if (type != null)
81 | {
82 | s_CachedTypes.Add(typeName, type);
83 | return type;
84 | }
85 | }
86 |
87 | return null;
88 | }
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/Utility/Encryption.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System;
9 |
10 | namespace GameFramework
11 | {
12 | public static partial class Utility
13 | {
14 | ///
15 | /// 加密解密相关的实用函数。
16 | ///
17 | internal static class Encryption
18 | {
19 | private const int QuickEncryptLength = 220;
20 |
21 | ///
22 | /// 将 bytes 使用 code 做异或运算的快速版本。
23 | ///
24 | /// 原始二进制流。
25 | /// 异或二进制流。
26 | /// 异或后的二进制流。
27 | public static byte[] GetQuickXorBytes(byte[] bytes, byte[] code)
28 | {
29 | return GetXorBytes(bytes, code, QuickEncryptLength);
30 | }
31 |
32 | ///
33 | /// 将 bytes 使用 code 做异或运算。
34 | ///
35 | /// 原始二进制流。
36 | /// 异或二进制流。
37 | /// 异或计算长度,若小于等于 0,则计算整个二进制流。
38 | /// 异或后的二进制流。
39 | public static byte[] GetXorBytes(byte[] bytes, byte[] code, int length = 0)
40 | {
41 | if (bytes == null)
42 | {
43 | return null;
44 | }
45 |
46 | if (code == null)
47 | {
48 | throw new GameFrameworkException("Code is invalid.");
49 | }
50 |
51 | int codeLength = code.Length;
52 | if (codeLength <= 0)
53 | {
54 | throw new GameFrameworkException("Code length is invalid.");
55 | }
56 |
57 | int codeIndex = 0;
58 | int bytesLength = bytes.Length;
59 | if (length <= 0 || length > bytesLength)
60 | {
61 | length = bytesLength;
62 | }
63 |
64 | byte[] result = new byte[bytesLength];
65 | Buffer.BlockCopy(bytes, 0, result, 0, bytesLength);
66 |
67 | for (int i = 0; i < length; i++)
68 | {
69 | result[i] ^= code[codeIndex++];
70 | codeIndex = codeIndex % codeLength;
71 | }
72 |
73 | return result;
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Utility/Random.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | public static partial class Utility
11 | {
12 | ///
13 | /// 随机相关的实用函数。
14 | ///
15 | public static class Random
16 | {
17 | private static System.Random s_Random = new System.Random();
18 |
19 | ///
20 | /// 设置随机数种子。
21 | ///
22 | /// 随机数种子。
23 | public static void SetSeed(int seed)
24 | {
25 | s_Random = new System.Random(seed);
26 | }
27 |
28 | ///
29 | /// 返回非负随机数。
30 | ///
31 | /// 大于等于零且小于 System.Int32.MaxValue 的 32 位带符号整数。
32 | public static int GetRandom()
33 | {
34 | return s_Random.Next();
35 | }
36 |
37 | ///
38 | /// 返回一个小于所指定最大值的非负随机数。
39 | ///
40 | /// 要生成的随机数的上界(随机数不能取该上界值)。maxValue 必须大于等于零。
41 | /// 大于等于零且小于 maxValue 的 32 位带符号整数,即:返回值的范围通常包括零但不包括 maxValue。不过,如果 maxValue 等于零,则返回 maxValue。
42 | public static int GetRandom(int maxValue)
43 | {
44 | return s_Random.Next(maxValue);
45 | }
46 |
47 | ///
48 | /// 返回一个指定范围内的随机数。
49 | ///
50 | /// 返回的随机数的下界(随机数可取该下界值)。
51 | /// 返回的随机数的上界(随机数不能取该上界值)。maxValue 必须大于等于 minValue。
52 | /// 一个大于等于 minValue 且小于 maxValue 的 32 位带符号整数,即:返回的值范围包括 minValue 但不包括 maxValue。如果 minValue 等于 maxValue,则返回 minValue。
53 | public static int GetRandom(int minValue, int maxValue)
54 | {
55 | return s_Random.Next(minValue, maxValue);
56 | }
57 |
58 | ///
59 | /// 返回一个介于 0.0 和 1.0 之间的随机数。
60 | ///
61 | /// 大于等于 0.0 并且小于 1.0 的双精度浮点数。
62 | public static double GetRandomDouble()
63 | {
64 | return s_Random.NextDouble();
65 | }
66 |
67 | ///
68 | /// 用随机数填充指定字节数组的元素。
69 | ///
70 | /// 包含随机数的字节数组。
71 | public static void GetRandomBytes(byte[] buffer)
72 | {
73 | s_Random.NextBytes(buffer);
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Utility/Unity/DefaultZipHelper.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using ICSharpCode.SharpZipLib.GZip;
10 | using System.IO;
11 |
12 | namespace UnityGameFramework.Runtime
13 | {
14 | ///
15 | /// 压缩解压缩辅助器。
16 | ///
17 | public class DefaultZipHelper : Utility.Zip.IZipHelper
18 | {
19 | ///
20 | /// 压缩数据。
21 | ///
22 | /// 要压缩的数据。
23 | /// 压缩后的数据。
24 | public byte[] Compress(byte[] bytes)
25 | {
26 | if (bytes == null || bytes.Length <= 0)
27 | {
28 | return bytes;
29 | }
30 |
31 | MemoryStream memoryStream = null;
32 | try
33 | {
34 | memoryStream = new MemoryStream();
35 | using (GZipOutputStream gZipOutputStream = new GZipOutputStream(memoryStream))
36 | {
37 | gZipOutputStream.Write(bytes, 0, bytes.Length);
38 | }
39 |
40 | return memoryStream.ToArray();
41 | }
42 | finally
43 | {
44 | if (memoryStream != null)
45 | {
46 | memoryStream.Dispose();
47 | memoryStream = null;
48 | }
49 | }
50 | }
51 |
52 | ///
53 | /// 解压缩数据。
54 | ///
55 | /// 要解压缩的数据。
56 | /// 解压缩后的数据。
57 | public byte[] Decompress(byte[] bytes)
58 | {
59 | if (bytes == null || bytes.Length <= 0)
60 | {
61 | return bytes;
62 | }
63 |
64 | MemoryStream decompressedStream = null;
65 | MemoryStream memoryStream = null;
66 | try
67 | {
68 | decompressedStream = new MemoryStream();
69 | memoryStream = new MemoryStream(bytes);
70 | using (GZipInputStream gZipInputStream = new GZipInputStream(memoryStream))
71 | {
72 | memoryStream = null;
73 | int bytesRead = 0;
74 | byte[] clip = new byte[0x1000];
75 | while ((bytesRead = gZipInputStream.Read(clip, 0, clip.Length)) != 0)
76 | {
77 | decompressedStream.Write(clip, 0, bytesRead);
78 | }
79 | }
80 |
81 | return decompressedStream.ToArray();
82 | }
83 | finally
84 | {
85 | if (decompressedStream != null)
86 | {
87 | decompressedStream.Dispose();
88 | decompressedStream = null;
89 | }
90 |
91 | if (memoryStream != null)
92 | {
93 | memoryStream.Dispose();
94 | memoryStream = null;
95 | }
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Utility/Unity/Helper.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using GameFramework;
9 | using UnityEngine;
10 |
11 | namespace UnityGameFramework.Runtime
12 | {
13 | ///
14 | /// 辅助器创建器相关的实用函数。
15 | ///
16 | public static class Helper
17 | {
18 | ///
19 | /// 创建辅助器。
20 | ///
21 | /// 要创建的辅助器类型。
22 | /// 要创建的辅助器类型名称。
23 | /// 若要创建的辅助器类型为空时,使用的自定义辅助器类型。
24 | /// 创建的辅助器。
25 | public static T CreateHelper(string helperTypeName, T customHelper) where T : MonoBehaviour
26 | {
27 | return CreateHelper(helperTypeName, customHelper, 0);
28 | }
29 |
30 | ///
31 | /// 创建辅助器。
32 | ///
33 | /// 要创建的辅助器类型。
34 | /// 要创建的辅助器类型名称。
35 | /// 若要创建的辅助器类型为空时,使用的自定义辅助器类型。
36 | /// 要创建的辅助器索引。
37 | /// 创建的辅助器。
38 | public static T CreateHelper(string helperTypeName, T customHelper, int index) where T : MonoBehaviour
39 | {
40 | T helper = null;
41 | if (!string.IsNullOrEmpty(helperTypeName))
42 | {
43 | System.Type helperType = Utility.Assembly.GetType(helperTypeName);
44 | if (helperType == null)
45 | {
46 | Log.Warning("Can not find helper type '{0}'.", helperTypeName);
47 | return null;
48 | }
49 |
50 | if (!typeof(T).IsAssignableFrom(helperType))
51 | {
52 | Log.Warning("Type '{0}' is not assignable from '{1}'.", typeof(T).FullName, helperType.FullName);
53 | return null;
54 | }
55 |
56 | helper = (T)(new GameObject()).AddComponent(helperType);
57 | }
58 | else if (customHelper == null)
59 | {
60 | Log.Warning("You must set custom helper with '{0}' type first.", typeof(T).FullName);
61 | return null;
62 | }
63 | else if (customHelper.gameObject.InScene())
64 | {
65 | helper = (index > 0 ? Object.Instantiate(customHelper) : customHelper);
66 | }
67 | else
68 | {
69 | helper = Object.Instantiate(customHelper);
70 | }
71 |
72 | return helper;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Utility/Utility.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | ///
11 | /// 实用函数集。
12 | ///
13 | public static partial class Utility
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Utility/Verifier.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | using System.IO;
9 | using System.Security.Cryptography;
10 | using System.Text;
11 |
12 | namespace GameFramework
13 | {
14 | public static partial class Utility
15 | {
16 | ///
17 | /// 校验相关的实用函数。
18 | ///
19 | public static partial class Verifier
20 | {
21 | private static readonly byte[] Zero = new byte[] { 0, 0, 0, 0 };
22 |
23 | ///
24 | /// 计算二进制流的 CRC32。
25 | ///
26 | /// 指定的二进制流。
27 | /// 计算后的 CRC32。
28 | public static byte[] GetCrc32(byte[] bytes)
29 | {
30 | if (bytes == null)
31 | {
32 | return Zero;
33 | }
34 |
35 | using (MemoryStream memoryStream = new MemoryStream(bytes))
36 | {
37 | Crc32 calculator = new Crc32();
38 | byte[] result = calculator.ComputeHash(memoryStream);
39 | calculator.Clear();
40 | return result;
41 | }
42 | }
43 |
44 | ///
45 | /// 计算指定文件的 CRC32。
46 | ///
47 | /// 指定文件的完全限定名称。
48 | /// 计算后的 CRC32。
49 | public static byte[] GetCrc32(string fileName)
50 | {
51 | if (!File.Exists(fileName))
52 | {
53 | return Zero;
54 | }
55 |
56 | using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
57 | {
58 | Crc32 calculator = new Crc32();
59 | byte[] result = calculator.ComputeHash(fileStream);
60 | calculator.Clear();
61 | return result;
62 | }
63 | }
64 |
65 | ///
66 | /// 计算二进制流的 MD5。
67 | ///
68 | /// 指定的二进制流。
69 | /// 计算后的 MD5。
70 | public static string GetMD5(byte[] bytes)
71 | {
72 | MD5 alg = new MD5CryptoServiceProvider();
73 | byte[] data = alg.ComputeHash(bytes);
74 | StringBuilder stringBuilder = new StringBuilder();
75 | for (int i = 0; i < data.Length; i++)
76 | {
77 | stringBuilder.Append(data[i].ToString("x2"));
78 | }
79 |
80 | return stringBuilder.ToString();
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Utility/Zip.IZipHelper.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | public static partial class Utility
11 | {
12 | public static partial class Zip
13 | {
14 | ///
15 | /// 压缩解压缩辅助器接口。
16 | ///
17 | public interface IZipHelper
18 | {
19 | ///
20 | /// 压缩数据。
21 | ///
22 | /// 要压缩的数据。
23 | /// 压缩后的数据。
24 | byte[] Compress(byte[] bytes);
25 |
26 | ///
27 | /// 解压缩数据。
28 | ///
29 | /// 要解压缩的数据。
30 | /// 解压缩后的数据。
31 | byte[] Decompress(byte[] bytes);
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Utility/Zip.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------
2 | // Game Framework v3.x
3 | // Copyright © 2013-2018 Jiang Yin. All rights reserved.
4 | // Homepage: http://gameframework.cn/
5 | // Feedback: mailto:jiangyin@gameframework.cn
6 | //------------------------------------------------------------
7 |
8 | namespace GameFramework
9 | {
10 | public static partial class Utility
11 | {
12 | ///
13 | /// 压缩解压缩相关的实用函数。
14 | ///
15 | public static partial class Zip
16 | {
17 | private static IZipHelper s_ZipHelper = null;
18 |
19 | ///
20 | /// 设置压缩解压缩辅助器。
21 | ///
22 | /// 要设置的压缩解压缩辅助器。
23 | public static void SetZipHelper(IZipHelper zipHelper)
24 | {
25 | s_ZipHelper = zipHelper;
26 | }
27 |
28 | ///
29 | /// 压缩数据。
30 | ///
31 | /// 要压缩的数据。
32 | /// 压缩后的数据。
33 | public static byte[] Compress(byte[] bytes)
34 | {
35 | if (s_ZipHelper == null)
36 | {
37 | throw new GameFrameworkException("Zip helper is invalid.");
38 | }
39 |
40 | return s_ZipHelper.Compress(bytes);
41 | }
42 |
43 | ///
44 | /// 解压缩数据。
45 | ///
46 | /// 要解压缩的数据。
47 | /// 解压缩后的数据。
48 | public static byte[] Decompress(byte[] bytes)
49 | {
50 | if (s_ZipHelper == null)
51 | {
52 | throw new GameFrameworkException("Zip helper is invalid.");
53 | }
54 |
55 | return s_ZipHelper.Decompress(bytes);
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------