[add] first

This commit is contained in:
建喵 2022-03-31 09:00:38 +08:00
commit e81e8a93eb
10 changed files with 218 additions and 0 deletions

27
README.MD Normal file
View File

@ -0,0 +1,27 @@
前言:
creator提供的"查找使用"只能显示出在某个场景或预制上;
对于哪个资源、脚本用在哪个场景、哪个预制的哪个节点上并不能很清楚地表示出来。
尤其是当项目越来越大、场景预制节点越来越多时,当不清楚资源、脚本在全部的引用位置,改动麻烦,牵一发而动全身。
先来听听群众的呼声:
https://forum.cocos.org/t/topic/51103
https://forum.cocos.org/t/topic/67449
https://forum.cocos.org/t/topic/70327
https://forum.cocos.org/t/topic/90091
那么问题来了,有没有一款能精确地显示出在哪个场景预制中,并且显示出节点的位置路径,还可以提供跳转的工具呢?
没错find-assets插件正是你想要的。
使用方式:
支持两种使用方式,一种直接拖资源到面板上;一种模糊输入脚本名,再从右边列中选择完整的脚本路径
1、直接拖资源到assets框中也可以把引用到该资源的场景和预制罗列出来使用此方式可以不局限于脚本资源也可以是场景预制图片声音动画等native-asset资源
2、输入脚本名字后在右边选择框中选择assets目录下对应的脚本路径(支持模糊搜索)后会自动在下方列表中列出引用到的场景和预制
3、双条件查询。拖动资源到assets并输入脚本选择后点击双条件查询按钮则只显示既含有该资源和脚本的场景预制
4、增加额外参数。对匹配到的资源进行参数对比参数名和参数值对上才显示一般是匹配到包含该资源的脚本用参数对该脚本进行筛选(如gif中只显示t1属性为111的test1.js)
5、增加指定场景预制。只在该场景或预制中查询否则默认整个assets目录。
6、搜索结果的提示会显示是哪个资源、脚本
7、搜索结果列表会显示场景预制名、节点名与路径、操作(高亮资源,跳转到节点,高亮节点)
插件面板的编写借鉴了插件小王子的resource插件不过在论坛上好像找不到有该帖子。。
by zilone

1
i18n/en.js Normal file
View File

@ -0,0 +1 @@
module.exports={title:"find-assets"};

1
i18n/zh.js Normal file
View File

@ -0,0 +1 @@
module.exports={title:"\u67e5\u627e\u8d44\u6e90\u5f15\u7528\u63d2\u4ef6"};

1
main.js Normal file
View File

@ -0,0 +1 @@
var $jscomp$compprop0={};module.exports={load:function(){},unload:function(){},messages:($jscomp$compprop0.open=function(){Editor.Panel.open("find-assets")},$jscomp$compprop0)};

20
package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "find-assets",
"version": "0.0.1",
"description": "The package template for getting started.",
"author": "zilone",
"main": "main.js",
"main-menu": {
"i18n:MAIN_MENU.package.title/i18n:find-assets.title": {
"message": "find-assets:open"
}
},
"panel": {
"main": "panel/index.js",
"type": "dockable",
"title": "find-assets",
"engineSupport": true,
"width": 500,
"height": 600
}
}

2
panel/index.css Normal file
View File

@ -0,0 +1,2 @@
:host { margin: 5px; }
h2 { color: #f90; }

76
panel/index.html Normal file
View File

@ -0,0 +1,76 @@
<div id="warp" class="warp">
<ui-prop name="指定场景or预制(可选):" tooltip="只在指定的场景或预制中查找" style="height: 43px; display: flex;">
<ui-asset type="native-asset" v-value="prefabUuid" class="flex-1">
</ui-asset>
</ui-prop>
<ui-prop name="assets:" tooltip="直接拖动资源查询" style="height: 43px; display: flex;">
<ui-asset type="native-asset" v-value="assetUuid" class="flex-1">
</ui-asset>
</ui-prop>
<ui-prop name="脚本名:" tooltip="区分大小写,模糊查询后点击右边的下拉框选择符合的脚本">
<ui-input class="flex-1" v-value="inputName" v-on:confirm="onInputName"></ui-input>
<ui-select class="flex-1" v-value="compName" v-on:change="onSelected">
<template v-for="item in compNames">
<option v-bind:value="item">{{item}}</option>
</template>
</ui-select>
</ui-prop>
<ui-prop name="额外参数" tooltip="对匹配到的资源增加参数对比">
<div class="layout horizontal center flex-1 ">
<ui-checkbox v-bind:checked="isNeedParam" v-on:change="onNeedParam"></ui-checkbox>
</div>
</ui-prop>
<ui-prop name="" v-show="isNeedParam">
<div class="layout horizontal center flex-1 ">参数名
<ui-input class="flex-1" v-value="paramName"></ui-input>
</div>
<div class="layout horizontal center flex-1 ">参数值
<ui-input class="flex-1" v-value="paramValue"></ui-input>
</div>
</ui-prop>
<ui-prop name="">
<div class="self-end layout center horizontal">
<ui-button class="self-end green" v-on:confirm="onRefresh">刷新</ui-button>
<ui-button v-on:confirm="onClean">清除</ui-button>
</div>
</ui-prop>
<ui-prop name="双条件查询:" tooltip="既含有特定脚本又含有特定资源">
<div class="layout horizontal center flex-1 ">
<ui-button class="self-end blue" v-on:confirm="onDoubleSearch">双条件查询</ui-button>
</div>
</ui-prop>
<ui-prop>
<div class>{{resultTip}}</div>
</ui-prop>
<section>
<ul>
<li>
<div class="scene">场景or预制</div>
<div class="path">路径</div>
<div class="controller">操作</div>
</li>
<li v-for="item in items">
<div class="scene" :title="item.scene">{{item.scene}}</div>
<div class="path" :title="item.path">{{item.path}}</div>
<div class="controller">
<!-- <i class="fa fa-file" aria-hidden="true" title="资源高亮" @click="jumpRes(item.uuid)"></i>
<i class="fa fa-share" aria-hidden="true" title="跳转到节点" @click="jumpScene(item)"></i>
<i class="fa fa-bolt" aria-hidden="true" title="节点高亮" @click="highlight(item)"></i> -->
<ui-button v-on:confirm="jumpRes(item.uuid)">1</ui-button>
<ui-button v-on:confirm="jumpScene(item)">2</ui-button>
<ui-button v-on:confirm="highlight(item)">3</ui-button>
</div>
</li>
</ul>
</section>
</div>

12
panel/index.js Normal file
View File

@ -0,0 +1,12 @@
var FS=require("fire-fs"),PATH=require("fire-path"),fse=require("fs-extra"),Scene=Editor.require("packages://find-assets/panel/scene"),$jscomp$compprop0={};
Editor.Panel.extend({style:FS.readFileSync(Editor.url("packages://find-assets/panel/less.css","utf8")),template:FS.readFileSync(Editor.url("packages://find-assets/panel/index.html","utf8")),$:{},ready:function(){window.plugin=new window.Vue({el:this.shadowRoot,created:function(){Editor.assetdb.queryAssets("db://assets/**/*","javascript",function(a,b){for(a=0;a<b.length;a++){var c=b[a].url.replace("db://assets/","");this.scriptsArr.push(c)}this.systemScripts="cc.Scene cc.Node cc.Sprite cc.Label cc.RichText cc.Layout cc.Button cc.ParticleSystem cc.ScrollView cc.PageView cc.ProgressBar cc.Toggle cc.EditBox cc.WebView cc.VideoPlayer".split(" ");
this.scriptsArr.push.apply(this.scriptsArr,this.systemScripts)}.bind(this))},data:{prefabUuid:"",compName:"",compNames:[],inputName:"",scriptsArr:[],systemScripts:[],assetUuid:"",nodeId:null,item:null,items:[],assetItems:[],nameItems:[],resultTip:"\u641c\u7d22\u7ed3\u679c",tips:"",isNeedParam:!1,paramName:"",paramValue:""},watch:{assetUuid:function(){this.searchByAsset()}},methods:{onNeedParam:function(){this.isNeedParam=!this.isNeedParam;this.paramValue=this.paramName=""},onRefresh:function(){this.inputName?
this.searchByName():this.assetUuid&&this.searchByAsset()},onSelected:function(){this.inputName=this.compName;this.searchByName()},onInputName:function(){this.inputName&&(this.compNames=this.fuzzyQuery(this.scriptsArr,this.inputName))},fuzzyQuery:function(a,b){b=new RegExp(b);for(var c=[],e=0;e<a.length;e++)b.test(a[e])&&c.push(a[e]);return c},onClean:function(){this.items=[];this.item=null;this.compName="";this.compNames=[];this.prefabUuid=this.tips=this.resultTip=this.assetUuid=this.inputName="";
this.isNeedParam=!1;this.paramValue=this.paramName=""},onDoubleSearch:function(){for(var a=[],b=0;b<this.assetItems.length;b++)for(var c=0;c<this.nameItems.length;c++)this.nameItems[c].scene==this.assetItems[b].scene&&this.nameItems[c].path==this.assetItems[b].path&&a.push(this.nameItems[c]);this.items=a;this.tips=this.getTips(this.assetName+" \u548c "+this.scriptName);this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c";Editor.success(this.tips+"\u7684\u53cc\u6761\u4ef6\u67e5\u8be2\u7ed3\u675f")},
getTips:function(a){if(this.prefabUuid){var b=Editor.remote.assetdb.uuidToUrl(this.prefabUuid).split("/");return"\u5728"+b[b.length-1]+"\u4e0b"+a}return a},searchByAsset:function(){if(this.assetUuid){var a=Editor.assetdb.remote.uuidToUrl(this.assetUuid).split("/");this.assetName=a[a.length-1];this.tips=this.getTips(this.assetName);this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c";this.assetItems=this.resourcePath(this.assetUuid)}},searchByName:function(){if(this.inputName)if(-1==this.systemScripts.indexOf(this.inputName)){var a=
this.inputName.split("/");this.scriptName=a[a.length-1];this.tips=this.getTips(this.scriptName);this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c";this.nameItems=this.resourcePath(Editor.assetdb.remote.urlToUuid("db://assets/"+this.inputName))}else this.tips=this.getTips(this.inputName),this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c",this.nameItems=this.resourcePath(this.inputName)},resourcePath:function(a){this.item=this.nodeId=null;var b=this.items=[],c=this.paramName,e=this.paramValue;
if(this.prefabUuid){var d=Editor.assetdb.remote.assetInfoByUuid(this.prefabUuid);d.destPath=Editor.assetdb.remote.loadMetaByUuid(this.prefabUuid).dests()[0];var h=Scene.search(d,a,c,e);0<h.length&&h.forEach(function(a){b.push({scene:PATH.basename(d.path),path:a.path,uuid:d.uuid,nodeId:a.uuid})});Editor.success(this.tips+"\u67e5\u8be2\u7ed3\u675f");return b}Editor.assetdb.queryAssets("db://assets/**/*","scene",function(d,g){g.forEach(function(d){var f=Scene.search(d,a,c,e);0<f.length&&f.forEach(function(a){b.push({scene:PATH.basename(d.path),
path:a.path,uuid:d.uuid,nodeId:a.uuid})})})});Editor.assetdb.queryAssets("db://assets/**/*","prefab",function(d,g){g.forEach(function(d){var f=Scene.search(d,a,c,e);0<f.length&&f.forEach(function(a){b.push({scene:PATH.basename(d.path),path:a.path,uuid:d.uuid,nodeId:a.uuid})})});Editor.success(this.tips+"\u67e5\u8be2\u7ed3\u675f")}.bind(this));return b},jumpRes:function(a){Editor.Ipc.sendToAll("assets:hint",a)},jumpScene:function(a){this.nodeId=a.nodeId;var b=a.uuid,c=Editor.remote.assetdb.uuidToUrl(b).split(".");
c=c[c.length-1];"prefab"==c?(this.item=a,Editor.Ipc.sendToAll("scene:enter-prefab-edit-mode",b)):"fire"==c&&Editor.Ipc.sendToMain("scene:open-by-uuid",b)},highlight:function(a){var b=this;a.nodeId?(Editor.Selection.select("node",a.nodeId),Editor.Ipc.sendToAll("hierarchy:hint",a.nodeId)):Editor.Ipc.sendToPanel("scene","scene:query-hierarchy",function(c,e,d){if(c)return Editor.error(c);if(c=a.path==d[0].name?d[0].id:b.getNodeIdByPath(a.path,d[0]))Editor.Selection.select("node",c),Editor.Ipc.sendToAll("hierarchy:hint",
c)})},getNodeIdByPath:function(a,b){var c=null,e=[],d=function(b,k){for(var g=k.children,l=0;l<g.length;l++){var f=g[l],h=b+k.name+"/"+f.name;e.push(h);if(a==h){c=f.id;break}f.children&&d(b+k.name+"/",f)}};d("",b);return c}}})},messages:($jscomp$compprop0.addLog=function(a,b){window.plugin.addLog(b)},$jscomp$compprop0["scene:ready"]=function(){var a=window.plugin.nodeId;a&&setTimeout(function(){Editor.Selection.select("node",a);Editor.Ipc.sendToAll("hierarchy:hint",a)},500);window.plugin.nodeId=null},
$jscomp$compprop0["scene:enter-prefab-edit-mode"]=function(){if(window.plugin&&window.plugin.item){var a=window.plugin.item;a&&setTimeout(function(){Editor.Ipc.sendToPanel("scene","scene:query-hierarchy",function(b,c,e){if(b)return Editor.error(b);if(b=a.path==e[0].name?e[0].id:window.plugin.getNodeIdByPath(a.path,e[0]))Editor.Selection.select("node",b),Editor.Ipc.sendToAll("hierarchy:hint",b)})},1E3);window.plugin.item=null}},$jscomp$compprop0)});

68
panel/less.css Normal file
View File

@ -0,0 +1,68 @@
@import url('app://bower_components/fontawesome/css/font-awesome.min.css');
:host {
display: flex;
}
#warp {
margin: 10px;
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden;
}
header {
display: flex;
height: 50px;
}
header ui-prop {
display: flex;
flex: 1;
}
header ui-prop ui-asset {
flex: 1;
}
header i.fa {
margin: 6px 2px;
padding: 12px 6px;
cursor: pointer;
font-size: 14px;
}
section {
flex: 1;
border-radius: 4px;
border: 1px solid #666;
padding: 10px;
overflow: auto;
}
ul {
margin: 0;
padding: 0;
}
ul li {
padding: 4px 10px;
list-style: none;
display: flex;
border-bottom: 1px solid #666666;
}
ul li:last-child {
border-bottom: none;
}
ul li > div {
padding: 4px 6px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
ul li .scene {
width: 200px;
}
ul li .path {
flex: 1;
}
ul li .controller {
width: 145px;
}
ul li .controller i {
margin: 0 2px;
padding: 0 4px;
cursor: pointer;
}

10
panel/scene.js Normal file
View File

@ -0,0 +1,10 @@
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
$jscomp.SymbolClass=function(a,b){this.$jscomp$symbol$id_=a;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:b})};$jscomp.SymbolClass.prototype.toString=function(){return this.$jscomp$symbol$id_};$jscomp.Symbol=function(){function a(c){if(this instanceof a)throw new TypeError("Symbol is not a constructor");return new $jscomp.SymbolClass($jscomp.SYMBOL_PREFIX+(c||"")+"_"+b++,c)}var b=0;return a}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.iterator;a||(a=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("Symbol.iterator"));"function"!=typeof Array.prototype[a]&&$jscomp.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}});$jscomp.initSymbolIterator=function(){}};
$jscomp.initSymbolAsyncIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.asyncIterator;a||(a=$jscomp.global.Symbol.asyncIterator=$jscomp.global.Symbol("Symbol.asyncIterator"));$jscomp.initSymbolAsyncIterator=function(){}};$jscomp.iteratorPrototype=function(a){$jscomp.initSymbolIterator();a={next:a};a[$jscomp.global.Symbol.iterator]=function(){return this};return a};
$jscomp.iteratorFromArray=function(a,b){$jscomp.initSymbolIterator();a instanceof String&&(a+="");var c=0,d={next:function(){if(c<a.length){var e=c++;return{value:b(e,a[e]),done:!1}}d.next=function(){return{done:!0,value:void 0}};return d.next()}};d[Symbol.iterator]=function(){return d};return d};
$jscomp.polyfill=function(a,b,c,d){if(b){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in c||(c[e]={});c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}};$jscomp.polyfill("Array.prototype.keys",function(a){return a?a:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6","es3");
var Fs=require("fire-fs"),getParent=function(a,b){var c=null;try{switch(b.__type__){case "cc.Node":b._parent&&(c=b._parent.__id__);break;case "cc.PrefabInfo":c=b.root.__id__;break;case "cc.Scene":break;default:c=b.node.__id__}}catch(d){Editor.warn(d),Editor.warn(b)}return a[c]};exports.conversion=function(a,b){for(var c=[b._name],d="";b=getParent(a,b);)"cc.Node"===b.__type__&&(d||(d=b._id),c.splice(0,0,b._name));c=c.filter(function(a){return!!a});return{path:c.join("/"),uuid:d}};
exports.search=function(a,b,c,d){var e=[],g=Fs.readJsonSync(a.destPath);a={};for(var h=0;h<g.length;a={$jscomp$loop$prop$item$2:a.$jscomp$loop$prop$item$2},h++){a.$jscomp$loop$prop$item$2=g[h];if(Editor.Utils.UuidUtils.decompressUuid(a.$jscomp$loop$prop$item$2.__type__)===b){if(c&&a.$jscomp$loop$prop$item$2[c]!=d)continue;var k=exports.conversion(g,a.$jscomp$loop$prop$item$2);e.push(k)}Object.keys(a.$jscomp$loop$prop$item$2).some(function(a){return function(f){if((f=a.$jscomp$loop$prop$item$2[f])&&
f.__uuid__===b&&"cc.PrefabInfo"!=a.$jscomp$loop$prop$item$2.__type__&&(!c||a.$jscomp$loop$prop$item$2[c]==d))return f=exports.conversion(g,a.$jscomp$loop$prop$item$2),e.push(f),!0}}(a))}return e};