cocos-animator/animator-runtime/core/AnimatorParams.ts

122 lines
3.2 KiB
TypeScript
Raw Normal View History

2021-01-19 14:30:12 +00:00
import { ParamType } from "./AnimatorCondition";
/**
*
*/
interface Param {
type: ParamType;
value: number;
}
/**
*
*/
export default class AnimatorParams {
private _paramMap: Map<string, Param> = new Map();
constructor(dataArr: any[]) {
dataArr.forEach((data: any) => {
let param: Param = {
type: data.type,
value: data.init
};
this._paramMap.set(data.param, param);
});
}
public getParamType(key: string): ParamType {
let param: Param = this._paramMap.get(key);
if (param) {
return param.type;
} else {
return null;
}
}
public setNumber(key: string, value: number) {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.NUMBER) {
param.value = value;
}
}
public setBool(key: string, value: boolean) {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.BOOLEAN) {
param.value = value ? 1 : 0;
}
}
public setTrigger(key: string) {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.TRIGGER) {
param.value = 1;
}
}
public resetTrigger(key: string) {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.TRIGGER) {
param.value = 0;
}
}
public autoTrigger(key: string) {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.AUTO_TRIGGER) {
param.value = 1;
}
}
public resetAutoTrigger(key: string) {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.AUTO_TRIGGER) {
param.value = 0;
}
}
public resetAllAutoTrigger() {
this._paramMap.forEach((param: Param, key: string) => {
if (param.type === ParamType.AUTO_TRIGGER) {
param.value = 0;
}
});
}
public getNumber(key: string): number {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.NUMBER) {
return param.value;
} else {
return 0;
}
}
public getBool(key: string): number {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.BOOLEAN) {
return param.value;
} else {
return 0;
}
}
public getTrigger(key: string): number {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.TRIGGER) {
return param.value;
} else {
return 0;
}
}
public getAutoTrigger(key: string): number {
let param: Param = this._paramMap.get(key);
if (param && param.type === ParamType.AUTO_TRIGGER) {
return param.value;
} else {
return 0;
}
}
}