first commit
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Category("Animation")]
|
||||
public class PlayAnimationAdvanced : ActionTask<Animation>
|
||||
{
|
||||
|
||||
[RequiredField]
|
||||
public BBParameter<AnimationClip> animationClip;
|
||||
public WrapMode animationWrap;
|
||||
public AnimationBlendMode blendMode;
|
||||
[SliderField(0, 2)]
|
||||
public float playbackSpeed = 1;
|
||||
[SliderField(0, 1)]
|
||||
public float crossFadeTime = 0.25f;
|
||||
public PlayDirections playDirection = PlayDirections.Forward;
|
||||
public BBParameter<string> mixTransformName;
|
||||
public BBParameter<int> animationLayer;
|
||||
public bool queueAnimation;
|
||||
public bool waitActionFinish = true;
|
||||
|
||||
private string animationToPlay = string.Empty;
|
||||
private int dir = -1;
|
||||
private Transform mixTransform;
|
||||
|
||||
protected override string info {
|
||||
get { return "Anim " + animationClip.ToString(); }
|
||||
}
|
||||
|
||||
protected override string OnInit() {
|
||||
agent.AddClip(animationClip.value, animationClip.value.name);
|
||||
animationClip.value.legacy = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
|
||||
if ( playDirection == PlayDirections.Toggle )
|
||||
dir = -dir;
|
||||
|
||||
if ( playDirection == PlayDirections.Backward )
|
||||
dir = -1;
|
||||
|
||||
if ( playDirection == PlayDirections.Forward )
|
||||
dir = 1;
|
||||
|
||||
agent.AddClip(animationClip.value, animationClip.value.name);
|
||||
animationToPlay = animationClip.value.name;
|
||||
|
||||
if ( !string.IsNullOrEmpty(mixTransformName.value) ) {
|
||||
mixTransform = FindTransform(agent.transform, mixTransformName.value);
|
||||
if ( !mixTransform ) {
|
||||
ParadoxNotion.Services.Logger.LogWarning("Cant find transform with name '" + mixTransformName.value + "' for PlayAnimation Action", LogTag.EXECUTION, this);
|
||||
}
|
||||
|
||||
} else {
|
||||
mixTransform = null;
|
||||
}
|
||||
|
||||
animationToPlay = animationClip.value.name;
|
||||
|
||||
if ( mixTransform ) {
|
||||
agent[animationToPlay].AddMixingTransform(mixTransform, true);
|
||||
}
|
||||
|
||||
agent[animationToPlay].layer = animationLayer.value;
|
||||
agent[animationToPlay].speed = dir * playbackSpeed;
|
||||
agent[animationToPlay].normalizedTime = Mathf.Clamp01(-dir);
|
||||
agent[animationToPlay].wrapMode = animationWrap;
|
||||
agent[animationToPlay].blendMode = blendMode;
|
||||
|
||||
if ( queueAnimation ) {
|
||||
agent.CrossFadeQueued(animationToPlay, crossFadeTime);
|
||||
} else {
|
||||
agent.CrossFade(animationToPlay, crossFadeTime);
|
||||
}
|
||||
|
||||
if ( !waitActionFinish ) {
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
|
||||
if ( elapsedTime >= ( agent[animationToPlay].length / playbackSpeed ) - crossFadeTime ) {
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
|
||||
Transform FindTransform(Transform parent, string name) {
|
||||
|
||||
if ( parent.name == name )
|
||||
return parent;
|
||||
|
||||
var transforms = parent.GetComponentsInChildren<Transform>();
|
||||
|
||||
foreach ( var t in transforms ) {
|
||||
if ( t.name == name )
|
||||
return t;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd97af9e2cdb80849986192c53640eab
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Animation (Legacy)/PlayAnimationAdvanced.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Category("Animation")]
|
||||
public class PlayAnimationSimple : ActionTask<Animation>
|
||||
{
|
||||
|
||||
[RequiredField]
|
||||
public BBParameter<AnimationClip> animationClip;
|
||||
[SliderField(0, 1)]
|
||||
public float crossFadeTime = 0.25f;
|
||||
public WrapMode animationWrap = WrapMode.Loop;
|
||||
public bool waitActionFinish = true;
|
||||
|
||||
//holds the last played animationClip.value for each agent
|
||||
private static Dictionary<Animation, AnimationClip> lastPlayedClips = new Dictionary<Animation, AnimationClip>();
|
||||
|
||||
protected override string info {
|
||||
get { return "Anim " + animationClip.ToString(); }
|
||||
}
|
||||
|
||||
protected override string OnInit() {
|
||||
agent.AddClip(animationClip.value, animationClip.value.name);
|
||||
animationClip.value.legacy = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
|
||||
AnimationClip last = null;
|
||||
if ( lastPlayedClips.TryGetValue(agent, out last) && last == animationClip.value ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
|
||||
lastPlayedClips[agent] = animationClip.value;
|
||||
agent[animationClip.value.name].wrapMode = animationWrap;
|
||||
agent.CrossFade(animationClip.value.name, crossFadeTime);
|
||||
|
||||
if ( !waitActionFinish ) {
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
|
||||
if ( elapsedTime >= animationClip.value.length - crossFadeTime ) {
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ee037a87018d194e9552fc9c1575e28
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Animation (Legacy)/PlayAnimationSimple.cs
|
||||
uploadId: 704937
|
||||
Reference in New Issue
Block a user