|
@@ -0,0 +1,47 @@
|
|
|
+import { _decorator, Component, Game, Node, tween, UIOpacity } from 'cc';
|
|
|
+import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
|
|
|
+import { GameEvent } from '../Enum/GameEvent';
|
|
|
+const { ccclass, property } = _decorator;
|
|
|
+
|
|
|
+@ccclass('HeadTipComponent')
|
|
|
+export class HeadTipComponent extends Component {
|
|
|
+ private _children: Node[] = [];
|
|
|
+
|
|
|
+ protected onLoad(): void {
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_HEADSHOT,this.showTip,this);
|
|
|
+ }
|
|
|
+
|
|
|
+ start() {
|
|
|
+ // 获取所有子节点
|
|
|
+ this._children = this.node.children;
|
|
|
+ // 初始隐藏所有提示
|
|
|
+ this._children.forEach(child => child.active = false);
|
|
|
+ }
|
|
|
+
|
|
|
+ showTip() {
|
|
|
+ if (this._children.length < 2) return;
|
|
|
+
|
|
|
+ // 随机选择一个子节点
|
|
|
+ const randomIndex = Math.floor(Math.random() * this._children.length);
|
|
|
+ const tipNode = this._children[randomIndex];
|
|
|
+
|
|
|
+ // 显示节点并添加淡出效果
|
|
|
+ tipNode.active = true;
|
|
|
+ const uiOpacity = tipNode.getComponent(UIOpacity) || tipNode.addComponent(UIOpacity);
|
|
|
+ uiOpacity.opacity = 255;
|
|
|
+
|
|
|
+ tween(uiOpacity)
|
|
|
+ .delay(0.5)
|
|
|
+ .to(0.3, { opacity: 0 })
|
|
|
+ .call(() => {
|
|
|
+ tipNode.active = false;
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+ }
|
|
|
+
|
|
|
+ update(deltaTime: number) {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|