优化若干代码
This commit is contained in:
@@ -1,57 +1,51 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Prefab,
|
||||
NodePool,
|
||||
Vec2,
|
||||
instantiate,
|
||||
Node,
|
||||
Vec3,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
|
||||
import ScorePrefab from '../prefab/ScorePrefab'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ScoreManager')
|
||||
export default class ScoreManager extends Component {
|
||||
public static instance: ScoreManager = null
|
||||
@property({ type: Prefab })
|
||||
private scrorePrefab: Prefab | null = null
|
||||
private scorePool: NodePool
|
||||
onLoad() {
|
||||
ScoreManager.instance = this
|
||||
this.scorePool = new NodePool()
|
||||
}
|
||||
public static instance: ScoreManager = null
|
||||
@property({ type: Prefab })
|
||||
private scrorePrefab: Prefab | null = null
|
||||
private scorePool: NodePool
|
||||
|
||||
public addScore(score: number, p: Vec2) {
|
||||
let scorePrefab: ScorePrefab = this.createScore(score)
|
||||
this.node.addChild(scorePrefab.node)
|
||||
scorePrefab.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
scorePrefab.init(score)
|
||||
scorePrefab.playMoveEffect(new Vec2(-472.398, -547.481), () => {
|
||||
this.destroyScore(scorePrefab)
|
||||
FishUI.instance.jf_score += score
|
||||
FishUI.instance.refreshScore()
|
||||
})
|
||||
}
|
||||
onLoad() {
|
||||
ScoreManager.instance = this
|
||||
this.scorePool = new NodePool()
|
||||
}
|
||||
|
||||
private createScore(score: number): ScorePrefab {
|
||||
let scoreNode: Node
|
||||
if (this.scorePool && this.scorePool.size() > 0) {
|
||||
scoreNode = this.scorePool.get()
|
||||
} else {
|
||||
scoreNode = instantiate(this.scrorePrefab)
|
||||
}
|
||||
return scoreNode.getComponent(ScorePrefab)
|
||||
}
|
||||
public addScore(score: number, p: Vec2) {
|
||||
let scorePrefab: ScorePrefab = this.createScore(score)
|
||||
this.node.addChild(scorePrefab.node)
|
||||
scorePrefab.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
scorePrefab.init(score)
|
||||
scorePrefab.playMoveEffect(new Vec2(-472.398, -547.481), () => {
|
||||
this.destroyScore(scorePrefab)
|
||||
FishUI.instance.jf_score += score
|
||||
FishUI.instance.refreshScore()
|
||||
})
|
||||
}
|
||||
|
||||
private destroyScore(scorePrefab: ScorePrefab) {
|
||||
this.scorePool.put(scorePrefab.node)
|
||||
}
|
||||
private createScore(score: number): ScorePrefab {
|
||||
let scoreNode: Node
|
||||
if (this.scorePool && this.scorePool.size() > 0) {
|
||||
scoreNode = this.scorePool.get()
|
||||
} else {
|
||||
scoreNode = instantiate(this.scrorePrefab)
|
||||
}
|
||||
return scoreNode.getComponent(ScorePrefab)
|
||||
}
|
||||
|
||||
onDisable() {}
|
||||
onDestroy() {
|
||||
ScoreManager.instance = null
|
||||
}
|
||||
private destroyScore(scorePrefab: ScorePrefab) {
|
||||
this.scorePool.put(scorePrefab.node)
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
ScoreManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user