-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.11.92 整理 ResKit 的示例 & 增加自定义扩展 Res 的示例
- Loading branch information
1 parent
db507f8
commit 4733280
Showing
103 changed files
with
364 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions
4
...amework/Examples/0.PackageKitExample.meta → ...xamples/2.ResKitExample/0.BasicUsage.meta
100755 → 100644
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
Unity2017/Assets/QFramework/Framework/Examples/2.ResKitExample/10.CustomResExample.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...ets/QFramework/Framework/Examples/2.ResKitExample/10.CustomResExample/CustomResExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using UnityEngine; | ||
|
||
namespace QFramework | ||
{ | ||
public class CustomResExample : MonoBehaviour | ||
{ | ||
// 自定义的 Res | ||
public class MyRes : Res | ||
{ | ||
public MyRes(string name) | ||
{ | ||
mAssetName = name; | ||
} | ||
|
||
// 同步加载(自己实现) | ||
public override bool LoadSync() | ||
{ | ||
// Asset = 加载的结果给 Asset 赋值 | ||
State = ResState.Ready; | ||
return true; | ||
} | ||
|
||
// 异步加载(自己实现) | ||
public override void LoadAsync() | ||
{ | ||
// Asset = 加载的结果给 Asset 赋值 | ||
State = ResState.Ready; | ||
} | ||
|
||
|
||
// 释放资源(自己实现) | ||
protected override void OnReleaseRes() | ||
{ | ||
// 卸载操作 | ||
// Asset = null | ||
State = ResState.Waiting; | ||
} | ||
} | ||
|
||
// 自定义的 Res 创建器(包含识别功能) | ||
public class MyResCreator : IResCreator | ||
{ | ||
public bool Match(ResSearchKeys resSearchKeys) | ||
{ | ||
return resSearchKeys.AssetName.StartsWith("myres://"); | ||
} | ||
|
||
public IRes Create(ResSearchKeys resSearchKeys) | ||
{ | ||
return new MyRes(resSearchKeys.AssetName); | ||
} | ||
} | ||
|
||
// Use this for initialization | ||
void Start() | ||
{ | ||
// 添加创建器 | ||
ResFactory.AddResCreator<MyResCreator>(); | ||
|
||
var resLoader = ResLoader.Allocate(); | ||
|
||
var resSearchKeys = ResSearchKeys.Allocate("myres://hello_world"); | ||
|
||
var myRes = resLoader.LoadResSync(resSearchKeys); | ||
|
||
resSearchKeys.Recycle2Cache(); | ||
|
||
Debug.Log(myRes.AssetName); | ||
Debug.Log(myRes.State); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...Framework/Framework/Examples/2.ResKitExample/10.CustomResExample/CustomResExample.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.