https://github.com/ailhc/scriptableasset_example
https://github.com/ailhc/scriptableasset_example
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ailhc/scriptableasset_example
- Owner: AILHC
- Created: 2024-05-01T02:10:06.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-07T05:32:12.000Z (over 1 year ago)
- Last Synced: 2025-02-21T12:26:15.392Z (over 1 year ago)
- Language: TypeScript
- Size: 1.45 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ScriptableAsset
## 简介
提供和**Unity**的**ScriptableObject**的一样的功能
方便配置复杂结构的数据,方便协作,方便引用其他资源
和平时配置`prefab`的`component`数据一样,但不需要节点,不需要挂组件
## 引擎版本支持
`>= 3.7.0`
3.7.x的对于显示有些问题

不影响正常使用
## 测试的发布平台
| H5 | 微信小游戏 | Android原生 | iOS原生 | 抖音小游戏 | OPPO小游戏 | vivo小游戏 |
| --- | --------- | ----------- | ------- | -------- | ------- | ------- |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
## 特性和规划
- [x] 自定义ScriptableAsset类型
- [x] 预览和编辑
- [x] 拖拽赋值到组件字段(指定自定义ScriptableAsset类型)识别
- [x] 使用装饰器添加右键创建按钮
- [x] 兼容3.7.x
- [x] 测试更多发布平台
- [ ] 支持搜索
- [ ] 支持自定义ScriptableAsset的Inspector
## 使用
### 示例项目
Gitee [scriptableasset_example](https://gitee.com/AIGAMESTUDIO.AILHC/scriptableasset_example)
GitHub [scriptableasset_example](https://github.com/AILHC/scriptableasset_example)
### 创建
>自动添加到右键菜单,创建自定义类型数据文件
>ps:需要复制示例的脚本模板到项目中:`.creator\asset-template\typescript\ScriptableAssetScriptTemplate`

### 可视化修改配置
>修改配置和修改Component的字段数据一样
可以使用任何CocosCreator提供的属性装饰器

参考更多用法:[Cocos Creator 3.8 手册 - 装饰器使用](https://docs.cocos.com/creator/manual/zh/scripting/decorator.html#type-%E5%8F%82%E6%95%B0)
### 引用和加载
>和其他资源(cc.Prefab、cc.AudioClip、等)一样,进行引用和加载,以及对依赖资源加载,无需而外处理
#### 被引用
```typescript
import { _decorator, Component, Node } from 'cc';
import { bh } from 'db://scriptable-asset/scriptable_runtime';
import { CharSA } from './scripts/CharSA';
import { CharRender } from './scripts/CharRender';
const { ccclass, property } = _decorator;
@ccclass('TestRefScriptableAsset')
export class TestRefScriptableAsset extends Component {
// private _charData: CharSA;
// @property(bh.ScriptableAsset)
// get charData(): CharSA{
// return this._charData;
// };
// set charData(value: CharSA){
// debugger
// this._charData = value;
// }
// @bh.scriptableAsset
// charData: CharSA;
@property(CharRender)
charRender: CharRender;
@property(CharSA)
charData: CharSA;
start() {
console.log(this.charData.charName);
this.charRender.setCharAsset(this.charData);
}
update(deltaTime: number) {
}
}
```
界面

#### 动态加载
```typescript
import { _decorator, assetManager, Component, director, Node } from 'cc';
import { CharRender } from './CharRender';
import { CharSA } from './CharSA';
const { ccclass, property } = _decorator;
@ccclass('TestLoadScriptableAssetDynamic')
export class TestLoadScriptableAssetDynamic extends Component {
/**
*
*/
@property(CharRender)
charRender: CharRender = null;
@property
assetPath: string = "char/char_datas/CharSA"
start() {
}
update(deltaTime: number) {
}
loadScriptableAsset() {
assetManager.loadBundle('scriptable_asset_test_res', (err, bundle) => {
if (err) {
console.error(err);
return;
}
bundle.load(this.assetPath, (err, asset:CharSA) => {
if (err) {
console.error(err);
return;
}
console.log(asset);
this.charRender.setCharAsset(asset);
});
});
}
}
```
## 已知问题
- 自定义且用ccclass装饰器的类,非继承Component的,比如CustomClasss,需要赋予初始值
- 使用具体的ScriptableAsset类型会字段赋值旁边的打开搜索功能会搜索不到,需要使用基类ScriptableAsset作为字段装饰器类型,或者直接使用`@bh.scriptableAsset`来标记
```ts
@bh.scriptableAsset
charData: CharSA;
```
- 删除ScriptableAsset脚本,会让依赖的地方显示为UnknownType,恢复脚本后,重启编辑器即可
## 其他作品
- 编辑器控制台增强插件 [EditorConsoleEnhancer](https://store.cocos.com/app/detail/6147)
- 让你5000+资源的项目开发如燕般轻盈流畅。 [Aswallow](https://store.cocos.com/app/zh/detail/2948)
- [完美typescript插件模板][Cocos Store](https://store.cocos.com/app/detail/2736)
## 联系
### 邮件反馈
505126057@qq.com
### Discord 频道 & QQ 频道
[点击链接加入QQ频道【游戏开发者联盟】](https://pd.qq.com/s/12xollzi9)
[**Join Our Discord Channel**](https://discord.com/channels/1233676496049274890/1233676883409768468)
### 加群交流反馈
QQ群:1103157878
### 关注作者获取更多内容
微信搜索公众号:玩转游戏开发
或扫码关注:
## 版权声明
本引擎插件(以下简称"插件")由本人开发。插件的所有权和知识产权均归本人所有。不得重复发布本插件。
## 购买须知
本产品为付费虚拟商品,一经购买成功概不退款,请在购买前谨慎确认购买内容。
## 更新日志
### `v1.0.5`
- 修复打包压缩bug
### `v1.0.4`
- 优化文档
- package.json中编辑器的兼容性修改
### `v1.0.3`
- 兼容 3.7.x
- 修复文档图片链接失效问题
### `v1.0.2`
兼容3.8.3
### `v1.0.1`
初次发布版本