123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { Node, Prefab, _decorator, assetManager, find, instantiate, sys } from 'cc';
- import { UserModel } from '../Model/UserModel';
- const { ccclass, property } = _decorator;
- @ccclass('UserManager')
- export class UserManager {
- private static _instance: UserManager | null = null;
- public static get instance(): UserManager {
- if (!this._instance) this._instance = new UserManager();
- return this._instance;
- }
- public userModel: UserModel = null;
- initilizeModel(): void {
- this.userModel = new UserModel();
- this.userModel.initialize();
- }
- /**
- * 增加体力
- * @param value 增加的数量
- * @returns 增加后的体力值
- */
- public addPower(value: number): number {
- this.userModel.powerCurrent = Math.min(this.userModel.powerCurrent + value, this.userModel.powerMax);
- return this.userModel.powerCurrent;
- }
- /**
- * 减少体力
- * @param value 减少的数量
- * @returns 是否成功减少
- */
- public reducePower(value: number): boolean {
- if (this.userModel.powerCurrent >= value) {
- this.userModel.powerCurrent -= value;
- return true;
- }
- return false;
- }
- }
|