super-hero/assets/cc-game/scripts/global/GameAssets.ts

88 lines
2.6 KiB
TypeScript

import { SpriteFrame } from 'cc';
import { Prefab } from 'cc';
import { SpriteAtlas } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { GameDefine } from '../config/GameDefine';
const { ccclass, property } = _decorator;
@ccclass('GameAssets')
export class GameAssets extends Component {
// @property(SpriteAtlas) public assetAtlas: SpriteAtlas = null!;
public static instance: GameAssets = null!;
@property(Prefab) heroPrefab: Prefab = null!;
@property(Prefab) creepMeleePrefab: Prefab = null!;
@property(Prefab) creepRangePrefab: Prefab = null!;
@property(Prefab) activeSkillPrefabs: Prefab[] = [];
@property(Prefab) bossMeleePrefab: Prefab = null!;
@property(Prefab) bossRangePrefab: Prefab = null!;
@property(Prefab) bossSlowPrefab: Prefab = null!;
@property(Prefab) psIconPrefabs: Prefab[] = [];
@property(Prefab) asIconPrefabs: Prefab[] = [];
@property(Prefab) rewardItemPrefabs: Prefab[] = [];
@property(Prefab) listGameObjectPrefabs: Prefab[] = [];
protected onLoad(): void {
GameAssets.instance = this;
}
public getActiveSkill(type: number): Prefab
{
if (type >= 0 && type < this.activeSkillPrefabs.length)
return this.activeSkillPrefabs[type];
return null;
}
public getBossPrefabById(bossId: string)
{
switch (bossId)
{
case "B1":
return this.bossMeleePrefab;
case "B2":
return this.bossRangePrefab;
}
}
public getCreepPrefabByType(creepType: string) {
switch (creepType.toLowerCase()) {
case "melee":
return this.creepMeleePrefab;
case "range":
return this.creepRangePrefab;
}
}
public getSkillIconByName(skillName: string)
{
var index = Number(skillName.split('S')[1]) - 1;
return skillName.includes("AS") ? this.asIconPrefabs[index] : this.psIconPrefabs[index];
}
public getRewardItemPrefab(rewardName: string)
{
switch (rewardName) {
case GameDefine.REWARD_TYPE.GOLD:
return this.rewardItemPrefabs[0];
case GameDefine.REWARD_TYPE.KEY:
return this.rewardItemPrefabs[1];
case GameDefine.REWARD_TYPE.ENERGY:
return this.rewardItemPrefabs[2];
default:
return null;
}
}
public getGameObjectPrefabByNo(objectNo: number) {
return this.listGameObjectPrefabs[objectNo - 1];
}
}