feat(3.0.0):支持creator3.0

This commit is contained in:
nextfu 2020-12-01 16:56:32 +08:00
parent 924e29ec99
commit 1017728a63
6 changed files with 46 additions and 66 deletions

View File

@ -1,4 +1,4 @@
# ccc-devtools v3.0.1
# ccc-devtools v3.0.0
Cocos Creator 网页调试工具,运行时查看、修改节点树,实时更新节点属性,可视化缓存资源。
## 功能
@ -25,27 +25,12 @@ Cocos Creator 网页调试工具,运行时查看、修改节点树,实时更
## 全局使用
1. 点击 Creator 右上角进入编辑器 resources 目录,再依次进入`static/preview-templates`目录
![t1](./screenshots/t1.png)
2. 将本项目clone到上面的目录下**如果使用下载压缩包的方式记得把后缀名-master去掉**
![t2](./screenshots/t2.png)
3. 打开 `index.jade`,找到 `body` 将中间部分替换为 `include ./ccc-devtools/index.html`**注意用tab键对齐**
![t3](./screenshots/t3.png)
Cocos Creator 3.0暂不支持全局使用
## 项目使用
Cocos Creator 从 v2.2 开始新增了自定义网页预览功能。
1. 重复上面的操作步骤,将修改后的 `preview-templates` 目录拷贝到项目根目录
2. 将 `ccc-devtools/index.html` 里所有引用的资源路径 `app/editor/static/preview-templates/ccc-devtools/...` 替换为 `ccc-devtools/...`
3. 重启 Cocos Creator
- `cd PROJECT_PATH && git clone -b v3.0.0 https://github.com/potato47/ccc-devtools.git preview-template`
- 或者手动将本项目对应分支下载到项目目录后,将名字改为 `preview-template`
## 自定义

23
index.ejs Normal file
View File

@ -0,0 +1,23 @@
<html>
<head>
<link rel="icon" href="./favicon.ico" />
<meta charset="utf-8" />
<title><%=title%></title>
<meta
name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1, minimum-scale=1,maximum-scale=1"
/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="full-screen" content="yes" />
<meta name="screen-orientation" content="portrait" />
<meta name="x5-fullscreen" content="true" />
<meta name="360-fullscreen" content="true" />
<meta name="renderer" content="webkit" />
<meta name="force-rendering" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link rel="stylesheet" type="text/css" href="./index.css" />
</head>
<body>
<%- include("./ccc-devtools/index.html") %>
</body>
</html>

View File

@ -217,6 +217,7 @@
<v-divider></v-divider>
<v-card-text>
<v-data-table :headers="cacheHeaders" :items="cacheData" :search="cacheSearchText" :sort-by="['size']"
click:row="openGithub"
:sort-desc="[true]" :footer-props="{
showFirstLastPage: true,
firstIcon: 'mdi-chevron-double-left',

View File

@ -131,49 +131,28 @@ const initConsoleUtil = function () {
return target;
}
cc.cache = function () {
let rawCacheData = cc.loader._pipes[0].pipeline._cache;
let rawCacheData = cc.loader._cache;
let cacheData = [];
let totalTextureSize = 0;
for (let k in rawCacheData) {
let item = rawCacheData[k];
if (item.type !== 'js' && item.type !== 'json') {
let itemName = '_';
let preview = '';
let content = (item.content && item.content.__classname__) ? item.content.__classname__ : item.type;
let formatSize = -1;
if (item.type === 'png' || item.type === 'jpg') {
let texture = rawCacheData[k.replace('.' + item.type, '.json')];
if (texture && texture._owner) {
itemName = texture._owner._name;
preview = texture.content.url;
}
} else {
if (item.content.name && item.content.name.length > 0) {
itemName = item.content.name;
} else if (item._owner) {
itemName = (item._owner && item._owner.name) || '_';
}
if (content === 'cc.Texture2D') {
let texture = item.content;
preview = texture._mipmaps[0].url;
let textureSize = texture.width * texture.height * ((texture._native === '.jpg' ? 3 : 4) / 1024 / 1024);
totalTextureSize += textureSize;
// sizeStr = textureSize.toFixed(3) + 'M';
formatSize = Math.round(textureSize * 1000) / 1000;
} else if (content === 'cc.SpriteFrame') {
preview = item.content._texture._mipmaps[0].url;
}
}
cacheData.push({
queueId: item.queueId,
type: item.type,
name: itemName,
preview: preview,
id: item.id,
content: content,
size: formatSize
});
let preview = '';
let type = item.__classname__;
let formatSize = -1;
if (type === 'cc.Texture2D') {
let image = item.mipmaps[0]
preview = image.url;
let textureSize = image.width * image.height * ((image._native === '.jpg' ? 3 : 4) / 1024 / 1024);
totalTextureSize += textureSize;
// sizeStr = textureSize.toFixed(3) + 'M';
formatSize = Math.round(textureSize * 1000) / 1000;
}
cacheData.push({
type: type,
preview: preview,
id: item._uuid,
size: formatSize
});
}
let cacheTitle = `缓存 [文件总数:${cacheData.length}][纹理缓存:${totalTextureSize.toFixed(2) + 'M'}]`;
return [cacheData, cacheTitle];

View File

@ -10,10 +10,8 @@ const app = new Vue({
cacheTitle: '',
cacheHeaders: [
{ text: 'Type', value: 'type' },
{ text: 'Name', value: 'name' },
{ text: 'Preivew', value: 'preview' },
{ text: 'ID', value: 'id' },
{ text: 'Content', value: 'content' },
{ text: 'Size', value: 'size' },
],
cacheRawData: [],
@ -153,7 +151,7 @@ const app = new Vue({
},
updateCacheData() {
if (this.$data.cacheOnlyTexture) {
this.$data.cacheData = this.$data.cacheRawData.filter(item => item.content === 'cc.Texture2D');
this.$data.cacheData = this.$data.cacheRawData.filter(item => item.type === 'cc.Texture2D');
} else {
this.$data.cacheData = this.$data.cacheRawData;
}

View File

@ -1,6 +0,0 @@
{
"name": "ccc-devtools",
"version": "3.0.1",
"author": "Next",
"repo": "https://github.com/potato47/ccc-devtools.git"
}