Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
Update tween module
Browse files Browse the repository at this point in the history
add tween chain
  • Loading branch information
heguanfeng committed Aug 7, 2020
1 parent 4a9cd36 commit 66b132d
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//--------------------------------------------------
// Motion Framework
// Copyright©2020-2020 何冠峰
// Licensed under the MIT license
//--------------------------------------------------

namespace MotionFramework.Tween
{
public interface ITweenChain
{
ITweenChain Append(ITweenNode node);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//--------------------------------------------------
// Motion Framework
// Copyright©2020-2020 何冠峰
// Licensed under the MIT license
//--------------------------------------------------

namespace MotionFramework.Tween
{
public static partial class TweenChainExtension
{
/// <summary>
/// 添加节点
/// </summary>
public static ITweenChain Append(this ITweenChain chain, ITweenNode node)
{
return chain.Append(node);
}

/// <summary>
/// 条件等待节点
/// </summary>
public static ITweenChain Until(this ITweenChain chain, System.Func<bool> condition)
{
return chain.Append(UntilNode.Allocate(condition));
}

/// <summary>
/// 执行节点
/// </summary>
public static ITweenChain Execute(this ITweenChain chain, System.Action execute)
{
return chain.Append(ExecuteNode.Allocate(execute));
}


/// <summary>
/// 延迟计时节点
/// </summary>
public static ITweenChain Delay(this ITweenChain chain, float delay, System.Action triggerCallback = null)
{
return chain.Append(TimerNode.AllocateDelay(delay, triggerCallback));
}

/// <summary>
/// 重复计时节点
/// 注意:该节点为无限时长
/// </summary>
public static ITweenChain Repeat(this ITweenChain chain, float delay, float interval, System.Action triggerCallback = null)
{
return chain.Append(TimerNode.AllocateRepeat(delay, interval, triggerCallback));
}

/// <summary>
/// 重复计时节点
/// </summary>
public static ITweenChain Repeat(this ITweenChain chain, float delay, float interval, float duration, System.Action triggerCallback = null)
{
return chain.Append(TimerNode.AllocateRepeat(delay, interval, duration, triggerCallback));
}

/// <summary>
/// 重复计时节点
/// </summary>
public static ITweenChain Repeat(this ITweenChain chain, float delay, float interval, long maxTriggerCount, System.Action triggerCallback = null)
{
return chain.Append(TimerNode.AllocateRepeat(delay, interval, maxTriggerCount, triggerCallback));
}

/// <summary>
/// 持续计时节点
/// </summary>
public static ITweenChain Duration(this ITweenChain chain, float delay, float duration, System.Action triggerCallback = null)
{
return chain.Append(TimerNode.AllocateDuration(delay, duration, triggerCallback));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace MotionFramework.Tween
/// 并行执行的复合节点
/// 说明:节点列表并行执行,所有子节点同时执行,所有节点都结束时复合节点结束。
/// </summary>
public class ParallelNode : ITweenNode
public class ParallelNode : ITweenNode, ITweenChain
{
public static ParallelNode Allocate(params ITweenNode[] nodes)
{
Expand Down Expand Up @@ -67,5 +67,11 @@ void ITweenNode.Kill()
{
IsDone = true;
}

ITweenChain ITweenChain.Append(ITweenNode node)
{
AddNode(node);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace MotionFramework.Tween
/// 随机执行的复合节点
/// 说明:节点列表随机执行,在随机节点结束后复合节点结束。
/// </summary>
public class SelectorNode : ITweenNode
public class SelectorNode : ITweenNode, ITweenChain
{
protected List<ITweenNode> _nodes = new List<ITweenNode>();
protected ITweenNode _selectNode;
Expand Down Expand Up @@ -69,5 +69,11 @@ void ITweenNode.Kill()
{
IsDone = true;
}

ITweenChain ITweenChain.Append(ITweenNode node)
{
AddNode(node);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace MotionFramework.Tween
/// 顺序执行的复合节点
/// 说明:节点列表依次执行,每个子节点结束之后便执行下一个节点,所有节点都结束时复合节点结束。
/// </summary>
public class SequenceNode : ITweenNode
public class SequenceNode : ITweenNode, ITweenChain
{
public static SequenceNode Allocate(params ITweenNode[] nodes)
{
Expand Down Expand Up @@ -73,5 +73,11 @@ void ITweenNode.Kill()
{
IsDone = true;
}

ITweenChain ITweenChain.Append(ITweenNode node)
{
AddNode(node);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
namespace MotionFramework.Tween
{
/// <summary>
/// 条件节点
/// 条件等待节点
/// </summary>
public class ConditionNode : ITweenNode
public class UntilNode : ITweenNode
{
public static ConditionNode Allocate(System.Func<bool> condition)
public static UntilNode Allocate(System.Func<bool> condition)
{
ConditionNode node = new ConditionNode
UntilNode node = new UntilNode
{
Condition = condition,
};
Expand Down

0 comments on commit 66b132d

Please sign in to comment.