薛鸿潇 5 роки тому
батько
коміт
f254b9a442

+ 2 - 1
.gitignore

@@ -3,4 +3,5 @@
 /mk_framework/temp
 .vscode
 /mk_framework/assets/scene/TestScene.fire
-/mk_framework/assets/scene/TestScene.fire.meta
+/mk_framework/assets/scene/TestScene.fire.meta
+/mk_framework/build

+ 61 - 0
mk_framework/assets/script/game/component/tween/RopeSwung.ts

@@ -0,0 +1,61 @@
+
+const { ccclass, property, executeInEditMode, playOnFocus } = cc._decorator;
+/**
+ * 绳索摆动效果
+ * @author 薛鸿潇
+ */
+@ccclass
+@executeInEditMode()
+@playOnFocus()
+export default class RopeSwung extends cc.Component {
+
+    @property({ displayName: '摆动角度' }) private angle: number = 15;
+    @property({ displayName: '摆动时间', tooltip: '摆动1/4距离消耗的时间' }) private time: number = 1;
+
+    /** 编辑器预览 */
+    private _edit_play: boolean = false;
+    @property({ displayName: '编辑器预览' })
+    get edit_play(): boolean {
+        if (this._edit_play && !this.edit_playing) this.initShakeSlow();
+        this.edit_playing = this._edit_play;
+        return this._edit_play;
+    }
+    set edit_play(v: boolean) {
+        this._edit_play = v;
+        if (!v) this.stop();
+    }
+    /** 编辑器是否正在播放 */
+    private edit_playing = false;
+
+    onLoad() {
+
+    }
+
+    start() {
+        if (CC_EDITOR) {
+            if (this.edit_play) {
+                this.initShakeSlow()
+            }
+        } else {
+            this.initShakeSlow()
+        }
+    }
+    /**
+     * 缓慢摇动
+     * @param node 动画节点
+     */
+    private initShakeSlow() {
+        let node = this.node;
+        let rotate1 = cc.tween().to(this.time, { angle: { value: this.angle, easing: 'sineOut' } })
+        let rotate2 = cc.tween().to(this.time, { angle: { value: 0, easing: 'sineIn' } })
+        let rotate3 = cc.tween().to(this.time, { angle: { value: -this.angle, easing: 'sineOut' } })
+        let rotate4 = cc.tween().to(this.time, { angle: { value: 0, easing: 'sineIn' } })
+        let sequence1 = cc.tween().sequence(rotate1, rotate2, rotate3, rotate4)
+        cc.tween(node).then(sequence1).repeatForever().start();
+    }
+    /** 停止动画 */
+    private stop() {
+        this.node.stopAllActions();
+    }
+
+}

+ 9 - 0
mk_framework/assets/script/game/component/tween/RopeSwung.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "93753008-b78e-47c2-8a94-f28e9579ed30",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}