mirror of
https://gitee.com/ruanwujing/green-pack-cocos
synced 2024-12-25 03:08:45 +00:00
工作流创建
This commit is contained in:
parent
cb58fcbff8
commit
cea97c0127
@ -290,7 +290,7 @@
|
||||
"_priority": 1073741824,
|
||||
"_fov": 45,
|
||||
"_fovAxis": 0,
|
||||
"_orthoHeight": 459.1304347826087,
|
||||
"_orthoHeight": 422.9685807150596,
|
||||
"_near": 1,
|
||||
"_far": 2000,
|
||||
"_color": {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { _decorator, CCBoolean, TweenEasing , CCFloat, CCString, Component, easing, Enum, EventTouch, isValid, Node, NodeEventType, Tween, tween, Vec2, Vec3 } from 'cc';
|
||||
import { GPWorkFlow, GPWorkFlowNode } from './GPWorkFlow';
|
||||
const { ccclass, property } = _decorator;
|
||||
export enum FloatType {
|
||||
None,
|
||||
@ -67,12 +68,40 @@ export class GPDrag extends Component {
|
||||
public succeedCallback:Function = null;
|
||||
private backTween:Tween<Node>
|
||||
|
||||
|
||||
public backHomeWorkFlow = new GPWorkFlow();
|
||||
start() {
|
||||
this.node.on(NodeEventType.TOUCH_START, this.OnDragStart, this)
|
||||
this.node.on(NodeEventType.TOUCH_MOVE, this.OnDragMove, this)
|
||||
this.node.on(NodeEventType.TOUCH_END, this.OnDragEnd, this)
|
||||
this.node.on(NodeEventType.TOUCH_CANCEL, this.OnDragEnd, this)
|
||||
|
||||
let moveNode = new GPWorkFlowNode();
|
||||
this.backHomeWorkFlow.headNode = moveNode;
|
||||
let self = this;
|
||||
moveNode.OnStart = (wfNode:GPWorkFlowNode)=>{
|
||||
let p = new Vec3(self.dragStartPos.x, self.dragStartPos.y, 0);
|
||||
switch(this.backHomeType) {
|
||||
case DragBackHomeType.SetPosition:
|
||||
self.node.setPosition(p)
|
||||
wfNode.done();
|
||||
break;
|
||||
case DragBackHomeType.Tween:
|
||||
self.backTween && self.backTween.stop()
|
||||
let easing:TweenEasing = EasingString[self.backTweenEasing] as TweenEasing
|
||||
self.backTween = tween(self.node)
|
||||
.to(self.backTweenTime, {position:p}, {easing:easing}).call(()=>{
|
||||
wfNode.done();
|
||||
}).start()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let arrivedNode = new GPWorkFlowNode();
|
||||
moveNode.nextNode = arrivedNode;
|
||||
arrivedNode.OnStart = (wfNode:GPWorkFlowNode)=>{
|
||||
self.OnArrivedHome();
|
||||
wfNode.done();
|
||||
}
|
||||
}
|
||||
|
||||
private OnDragStart(e:EventTouch) {
|
||||
@ -106,19 +135,8 @@ export class GPDrag extends Component {
|
||||
if (this.succeedCheck && this.succeedCheck(e)) {
|
||||
this.succeedCallback && this.succeedCallback(e)
|
||||
} else if(this.backHomeWhenFailed){
|
||||
let p = new Vec3(this.dragStartPos.x, this.dragStartPos.y, 0);
|
||||
switch(this.backHomeType) {
|
||||
case DragBackHomeType.SetPosition:
|
||||
this.node.setPosition(p)
|
||||
this.OnArrivedHome();
|
||||
break;
|
||||
case DragBackHomeType.Tween:
|
||||
this.backTween && this.backTween.stop()
|
||||
let easing:TweenEasing = EasingString[this.backTweenEasing] as TweenEasing
|
||||
this.backTween = tween(this.node)
|
||||
.to(this.backTweenTime, {position:p}, {easing:easing}).call(this.OnArrivedHome.bind(this)).start()
|
||||
break;
|
||||
}
|
||||
this.backHomeWorkFlow.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,4 +159,7 @@ export class GPDrag extends Component {
|
||||
this.node.off(NodeEventType.TOUCH_END, this.OnDragEnd, this)
|
||||
this.node.off(NodeEventType.TOUCH_CANCEL, this.OnDragEnd, this)
|
||||
}
|
||||
protected update(dt: number): void {
|
||||
this.backHomeWorkFlow.update(dt)
|
||||
}
|
||||
}
|
80
assets/scripts/components/GPWorkFlow.ts
Normal file
80
assets/scripts/components/GPWorkFlow.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export class GPWorkFlowNode {
|
||||
public OnStart:Function;
|
||||
public OnUpdate:Function;
|
||||
public OnEnd:Function;
|
||||
public nextNodes:GPWorkFlowNode[] = new Array<GPWorkFlowNode>();
|
||||
public get nextNode():GPWorkFlowNode {
|
||||
return this.nextNodes.length > 0 ? this.nextNodes[0] : null;
|
||||
}
|
||||
public set nextNode(_nextNode:GPWorkFlowNode) {
|
||||
if (this.nextNodes.length == 0) {
|
||||
this.nextNodes.push(_nextNode);
|
||||
} else {
|
||||
this.nextNodes[0] = _nextNode;
|
||||
}
|
||||
}
|
||||
private _nextIdx = -1;
|
||||
public get nextIdx() {
|
||||
return this._nextIdx;
|
||||
}
|
||||
public done(nexIdx = 0) {
|
||||
this._nextIdx = nexIdx;
|
||||
if (this.OnEnd)
|
||||
this.OnEnd(this);
|
||||
}
|
||||
public isDone() {
|
||||
return this._nextIdx >= 0;
|
||||
}
|
||||
public refresh() {
|
||||
this._nextIdx = -1;
|
||||
for (let i = 0; i < this.nextNodes.length; i++) {
|
||||
this.nextNodes[i].refresh();
|
||||
}
|
||||
}
|
||||
public start() {
|
||||
if (this.OnStart)
|
||||
this.OnStart(this);
|
||||
}
|
||||
public update(deltaTime) {
|
||||
if (this.OnUpdate)
|
||||
this.OnUpdate(this, deltaTime);
|
||||
}
|
||||
public hasNext() {
|
||||
return this.nextNodes.length > 0;
|
||||
}
|
||||
}
|
||||
export class GPWorkFlow {
|
||||
public headNode:GPWorkFlowNode;
|
||||
private curNode:GPWorkFlowNode;
|
||||
start() {
|
||||
if (this.headNode) {
|
||||
this.headNode.refresh();
|
||||
}
|
||||
this.curNode = this.headNode;
|
||||
this.curNode.start();
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
if (this.curNode != null) {
|
||||
this.curNode.update(deltaTime)
|
||||
if (this.curNode.isDone()) {
|
||||
if (this.curNode.hasNext()) {
|
||||
this.curNode = this.curNode.nextNodes[this.curNode.nextIdx];
|
||||
this.curNode.start()
|
||||
} else {
|
||||
this.curNode = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
insertHeadNode(wfNode:GPWorkFlowNode) {
|
||||
let tmp = this.headNode;
|
||||
this.headNode = wfNode;
|
||||
wfNode.nextNode = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
9
assets/scripts/components/GPWorkFlow.ts.meta
Normal file
9
assets/scripts/components/GPWorkFlow.ts.meta
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b1a29b57-56ec-43b6-a601-47be8b4e6f2a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
9
assets/scripts/testComponents.meta
Normal file
9
assets/scripts/testComponents.meta
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "c1189113-47a8-4cb4-8133-e249e6b58188",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
28
assets/scripts/testComponents/testWorkFlow.ts
Normal file
28
assets/scripts/testComponents/testWorkFlow.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { _decorator, Component, Node, tween, v3 } from 'cc';
|
||||
import { GPDrag } from '../components/GPDrag';
|
||||
import { GPWorkFlowNode } from '../components/GPWorkFlow';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('testWorkFlow')
|
||||
export class testWorkFlow extends Component {
|
||||
start() {
|
||||
let drag = this.getComponent(GPDrag)
|
||||
let testNode = new GPWorkFlowNode();
|
||||
let self = this;
|
||||
testNode.OnStart = (wfNode:GPWorkFlowNode)=>{
|
||||
tween(self.node).by(0.05, {position:v3(10, 0, 0)})
|
||||
.by(0.1, {position:v3(-20, 0, 0)})
|
||||
.by(0.05, {position:v3(10, 0, 0)})
|
||||
.call(()=>{
|
||||
wfNode.done()
|
||||
}).start()
|
||||
}
|
||||
drag.backHomeWorkFlow.insertHeadNode(testNode);
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
9
assets/scripts/testComponents/testWorkFlow.ts.meta
Normal file
9
assets/scripts/testComponents/testWorkFlow.ts.meta
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e29b8017-2918-4c92-abc1-420a6c0834d7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user