改版;适配creator3.5

This commit is contained in:
Next
2022-07-17 16:48:06 +08:00
parent 9589907747
commit 63bbf81d1a
49 changed files with 1735 additions and 42594 deletions

View File

@@ -0,0 +1,100 @@
interface IComponentProp {
name: string;
key: string;
custom?: boolean;
}
interface IComponentViewModel {
props: IComponentProp[];
}
export class ComponentManager {
static getViewModel(name: string, componentGetter: any) {
switch (name) {
case 'cc.UITransform':
return new CCUITransformModel(componentGetter);
case 'cc.Label':
return new CCLabelModel();
case 'cc.Sprite':
return new CCSpriteModel();
default:
return null
}
}
}
class CCUITransformModel implements IComponentViewModel {
private componentGetter: any;
props: IComponentProp[] = [
{ name: 'Width', key: 'width', custom: true },
{ name: 'Height', key: 'height', custom: true },
{ name: 'Anchor X', key: 'anchorX', custom: true },
{ name: 'Anchor Y', key: 'anchorY', custom: true },
]
constructor(componentGetter: any) {
this.componentGetter = componentGetter;
}
get component(): any {
return this.componentGetter();
}
get width() {
return this.componentGetter().contentSize.width;
}
set width(value: number) {
const origin = this.component.contentSize;
this.component.setContentSize(value, origin.height);
}
get height() {
return this.component.contentSize.height;
}
set height(value: number) {
const origin = this.component.contentSize;
this.component.setContentSize(origin.width, value);
}
get anchorX() {
return this.component.anchorPoint.x;
}
set anchorX(value: number) {
const origin = this.component.anchorPoint;
this.component.setAnchorPoint(value, origin.y);
}
get anchorY() {
return this.component.anchorPoint.y;
}
set anchorY(value: number) {
const origin = this.component.anchorPoint;
this.component.setAnchorPoint(origin.x, value);
}
}
class CCLabelModel implements IComponentViewModel {
props: IComponentProp[] = [
{ name: 'String', key: 'string' },
{ name: 'Color', key: 'color' },
{ name: 'Font Size', key: 'fontSize' },
{ name: 'Line Height', key: 'lineHeight' },
];
}
class CCSpriteModel implements IComponentViewModel {
props: IComponentProp[] = [
{ name: 'Color', key: 'color' },
];
}

31
src/misc/Utils.ts Normal file
View File

@@ -0,0 +1,31 @@
export default class Utils {
static checkNodeValid(ccNode: any) {
// @ts-ignore
return ccNode && cc.isValid(ccNode)
}
static outputToConsole(target: any) {
let i = 1;
// @ts-ignore
while (window['temp' + i] !== undefined) {
i++;
}
// @ts-ignore
window['temp' + i] = target;
console.log('temp' + i);
// @ts-ignore
console.log(window['temp' + i]);
}
static getComponentName(component: any) {
return component.__classname__;
}
static getComponents(ccNode: any) {
return ccNode.components.map((component: any) => {
return { name: component.__classname__, target: component }
});
}
}