update
This commit is contained in:
@@ -1,78 +1,76 @@
|
||||
import { _decorator, Component, instantiate, Node, Prefab, Quat, Vec3 } from 'cc'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
import { Component, Node, Prefab, Quat, Vec3, _decorator, instantiate } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('LoadingPrefab')
|
||||
export default class LoadingPrefab extends Component {
|
||||
public static instance: Node
|
||||
private static prefab: Prefab
|
||||
public static LoadingZorderIndex: number = 99
|
||||
@property({ type: Node })
|
||||
loadingSp: Node | null = null
|
||||
public static instance: Node
|
||||
private static prefab: Prefab
|
||||
public static LoadingZorderIndex: number = 99
|
||||
@property({ type: Node })
|
||||
loadingSp: Node | null = null
|
||||
|
||||
private _quatCache: Quat
|
||||
private _vec3Cache: Vec3
|
||||
onLoad() {
|
||||
this._quatCache = new Quat()
|
||||
this._vec3Cache = new Vec3()
|
||||
}
|
||||
private _quatCache: Quat
|
||||
private _vec3Cache: Vec3
|
||||
|
||||
start() {}
|
||||
onLoad() {
|
||||
this._quatCache = new Quat()
|
||||
this._vec3Cache = new Vec3()
|
||||
}
|
||||
|
||||
public static close() {
|
||||
if (!LoadingPrefab.instance) {
|
||||
return
|
||||
}
|
||||
LoadingPrefab.instance.removeFromParent()
|
||||
LoadingPrefab.instance.destroy()
|
||||
LoadingPrefab.instance = null
|
||||
}
|
||||
start() {}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
GameConfig.GameName + '/' + 'share/uicomponent/LoadingPrefab',
|
||||
(loadedResource) => {
|
||||
LoadingPrefab.prefab = loadedResource
|
||||
resolve()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
public static close() {
|
||||
if (!LoadingPrefab.instance) return
|
||||
|
||||
private static createLoadingPrefab(parentNode: Node = null) {
|
||||
let dialogNode: Node = instantiate(LoadingPrefab.prefab)
|
||||
LoadingPrefab.instance = dialogNode
|
||||
if (!parentNode) {
|
||||
parentNode = DialogBase.GetRootCanvas()
|
||||
}
|
||||
parentNode.insertChild(dialogNode, LoadingPrefab.LoadingZorderIndex)
|
||||
dialogNode.setPosition(0, 0)
|
||||
}
|
||||
LoadingPrefab.instance.removeFromParent()
|
||||
LoadingPrefab.instance.destroy()
|
||||
LoadingPrefab.instance = null
|
||||
}
|
||||
|
||||
public static async show(parentNode: Node = null) {
|
||||
if (LoadingPrefab.instance) return
|
||||
if (!LoadingPrefab.prefab) {
|
||||
await LoadingPrefab.preLoad()
|
||||
}
|
||||
this.createLoadingPrefab(parentNode)
|
||||
}
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/LoadingPrefab`,
|
||||
(loadedResource) => {
|
||||
LoadingPrefab.prefab = loadedResource
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
this.loadingSp.getRotation(this._quatCache)
|
||||
Quat.toEuler(this._vec3Cache, this._quatCache)
|
||||
this._vec3Cache.z += 10
|
||||
this.loadingSp.setRotationFromEuler(this._vec3Cache)
|
||||
if (this._vec3Cache.z >= 360) {
|
||||
this.loadingSp.getRotation(Quat.IDENTITY)
|
||||
}
|
||||
}
|
||||
private static createLoadingPrefab(parentNode: Node = null) {
|
||||
const dialogNode: Node = instantiate(LoadingPrefab.prefab)
|
||||
LoadingPrefab.instance = dialogNode
|
||||
if (!parentNode) parentNode = DialogBase.GetRootCanvas()
|
||||
|
||||
public static clear() {
|
||||
LoadingPrefab.instance = null
|
||||
LoadingPrefab.prefab = null
|
||||
}
|
||||
parentNode.insertChild(dialogNode, LoadingPrefab.LoadingZorderIndex)
|
||||
dialogNode.setPosition(0, 0)
|
||||
}
|
||||
|
||||
public static async show(parentNode: Node = null) {
|
||||
if (LoadingPrefab.instance) return
|
||||
if (!LoadingPrefab.prefab) await LoadingPrefab.preLoad()
|
||||
|
||||
this.createLoadingPrefab(parentNode)
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
this.loadingSp.getRotation(this._quatCache)
|
||||
Quat.toEuler(this._vec3Cache, this._quatCache)
|
||||
this._vec3Cache.z += 10
|
||||
this.loadingSp.setRotationFromEuler(this._vec3Cache)
|
||||
if (this._vec3Cache.z >= 360) this.loadingSp.getRotation(Quat.IDENTITY)
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
LoadingPrefab.instance = null
|
||||
LoadingPrefab.prefab = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user