mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-06-01 13:54:05 +00:00
优化设置 node icon 的逻辑
This commit is contained in:
parent
96364845f8
commit
f15c2cb979
@ -314,23 +314,91 @@ export class Inspector extends InjectEvent {
|
|||||||
|
|
||||||
const components = node._components;
|
const components = node._components;
|
||||||
if (components) {
|
if (components) {
|
||||||
const types: CompType[] = [];
|
const names: string[] = [];
|
||||||
// widget组件的优先级低于其他渲染组件
|
|
||||||
for (let i = 0; i < components.length; i++) {
|
for (let i = 0; i < components.length; i++) {
|
||||||
const component = components[i];
|
const component = components[i];
|
||||||
const type = this.checkComponent(component);
|
const name = this.getCompName(component);
|
||||||
if (type) {
|
if (name) {
|
||||||
types.push(type);
|
names.push(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (types.length) {
|
if (names.length) {
|
||||||
//按照字母的顺序排序,目前是符合预期
|
const t = this.bestName(names);
|
||||||
types.sort();
|
if (t) {
|
||||||
return getNodeIcon(types[0]);
|
return getNodeIcon(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getNodeIcon(CompType.Node);
|
return getNodeIcon(CompType.Node);
|
||||||
}
|
}
|
||||||
|
/**挑选出最合适的组件图标依据的类型 */
|
||||||
|
private bestName(names: string[]): CompType | null {
|
||||||
|
if (names.length === 1 && names[0] === CompType.UITransform) {
|
||||||
|
return CompType.Node;
|
||||||
|
}
|
||||||
|
const typePriority: CompType[] = [
|
||||||
|
// 越靠前,优先级越搞
|
||||||
|
CompType.Camera,
|
||||||
|
CompType.Canvas,
|
||||||
|
CompType.Scene,
|
||||||
|
// 动画组件
|
||||||
|
CompType.Animation,
|
||||||
|
// 基础组件
|
||||||
|
CompType.Button,
|
||||||
|
CompType.Spirte,
|
||||||
|
CompType.Label,
|
||||||
|
CompType.RichText,
|
||||||
|
CompType.Prefab,
|
||||||
|
// UI组件
|
||||||
|
CompType.EditBox,
|
||||||
|
CompType.ScrollView,
|
||||||
|
CompType.Mask,
|
||||||
|
CompType.TiledTile,
|
||||||
|
CompType.Graphics,
|
||||||
|
CompType.ProgressBar,
|
||||||
|
CompType.Slider,
|
||||||
|
CompType.PageView,
|
||||||
|
CompType.Toggle,
|
||||||
|
CompType.ToggleGroup,
|
||||||
|
CompType.ToggleContainer,
|
||||||
|
//
|
||||||
|
CompType.ParticleSystem,
|
||||||
|
CompType.ParticleSystem2D,
|
||||||
|
CompType.Light,
|
||||||
|
CompType.VideoPlayer,
|
||||||
|
CompType.Webview,
|
||||||
|
CompType.MeshRenderer,
|
||||||
|
// UI组件
|
||||||
|
CompType.BlockInputEvents,
|
||||||
|
CompType.Layout,
|
||||||
|
CompType.Widget,
|
||||||
|
// 兜底
|
||||||
|
CompType.Node,
|
||||||
|
];
|
||||||
|
for (const key in CompType) {
|
||||||
|
const type = CompType[key];
|
||||||
|
if (type === CompType.UITransform) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const b = typePriority.find((el) => el === type);
|
||||||
|
if (!b) {
|
||||||
|
console.log(`${type} is not in typePriority`);
|
||||||
|
debugger;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < typePriority.length; i++) {
|
||||||
|
const name = typePriority[i];
|
||||||
|
if (names.indexOf(name) !== -1) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (names.length) {
|
||||||
|
// 没有从手动排序中找到,就用第一个
|
||||||
|
names.sort();
|
||||||
|
return names[0] as CompType;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private checkComponent(comp: any): CompType | null {
|
private checkComponent(comp: any): CompType | null {
|
||||||
const map = {};
|
const map = {};
|
||||||
map[CompType.Animation] = [cc.Animation];
|
map[CompType.Animation] = [cc.Animation];
|
||||||
@ -348,12 +416,16 @@ export class Inspector extends InjectEvent {
|
|||||||
map[CompType.ProgressBar] = [cc.ProgressBar];
|
map[CompType.ProgressBar] = [cc.ProgressBar];
|
||||||
map[CompType.Layout] = [cc.Layout];
|
map[CompType.Layout] = [cc.Layout];
|
||||||
map[CompType.Graphics] = [cc.Graphics];
|
map[CompType.Graphics] = [cc.Graphics];
|
||||||
|
map[CompType.ParticleSystem] = [cc.ParticleSystem, cc.ParticleSystemComponent];
|
||||||
|
// widget组件的优先级低于其他渲染组件
|
||||||
map[CompType.Widget] = [cc.Widget];
|
map[CompType.Widget] = [cc.Widget];
|
||||||
for (let key in map) {
|
for (let key in map) {
|
||||||
const item = map[key];
|
const item = map[key];
|
||||||
const ret = item.find((el: any) => {
|
const ret = item
|
||||||
return el && comp instanceof el;
|
.filter((el) => !!el)
|
||||||
});
|
.find((el: any) => {
|
||||||
|
return el && comp instanceof el;
|
||||||
|
});
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return key as CompType;
|
return key as CompType;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ export enum CompType {
|
|||||||
ScrollView = "cc.ScrollView",
|
ScrollView = "cc.ScrollView",
|
||||||
UITransform = "cc.UITransform",
|
UITransform = "cc.UITransform",
|
||||||
ParticleSystem = "cc.ParticleSystem",
|
ParticleSystem = "cc.ParticleSystem",
|
||||||
|
ParticleSystem2D = "cc.ParticleSystem2D",
|
||||||
EditBox = "cc.EditBox",
|
EditBox = "cc.EditBox",
|
||||||
TiledTile = "cc.TiledTile",
|
TiledTile = "cc.TiledTile",
|
||||||
Light = "cc.Light",
|
Light = "cc.Light",
|
||||||
@ -305,7 +306,14 @@ export function getNodeIcon(comp: CompType): string {
|
|||||||
map[CompType.Mask] = "icon_mask";
|
map[CompType.Mask] = "icon_mask";
|
||||||
map[CompType.Widget] = "icon_widget";
|
map[CompType.Widget] = "icon_widget";
|
||||||
map[CompType.ProgressBar] = "icon_progress";
|
map[CompType.ProgressBar] = "icon_progress";
|
||||||
|
map[CompType.ParticleSystem] = "icon_effect";
|
||||||
|
map[CompType.ParticleSystem2D] = "icon_effect";
|
||||||
map[CompType.Layout] = "icon_layout";
|
map[CompType.Layout] = "icon_layout";
|
||||||
map[CompType.Graphics] = "icon_graphics";
|
map[CompType.Graphics] = "icon_graphics";
|
||||||
return map[comp] || "";
|
let ret = map[comp];
|
||||||
|
if (!ret) {
|
||||||
|
console.log(`get node icon fail: ${comp}, please check.`);
|
||||||
|
ret = map[CompType.Node];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user