diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Animation/ScriptBindings |
Diffstat (limited to 'Runtime/Animation/ScriptBindings')
6 files changed, 2152 insertions, 0 deletions
diff --git a/Runtime/Animation/ScriptBindings/Animations.txt b/Runtime/Animation/ScriptBindings/Animations.txt new file mode 100644 index 0000000..ddeb57e --- /dev/null +++ b/Runtime/Animation/ScriptBindings/Animations.txt @@ -0,0 +1,721 @@ +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/Animation/Animation.h" +#include "Runtime/Animation/AnimationClip.h" +#include "Runtime/Animation/AnimationManager.h" +#include "Runtime/Animation/AnimationState.h" +#include "Runtime/Animation/Animator.h" +#include "Runtime/Animation/Motion.h" +#include "Runtime/Graphics/Transform.h" +#include "Runtime/Animation/AnimationCurveUtility.h" +#include "Runtime/Mono/MonoBehaviour.h" +#include "Runtime/Mono/MonoScript.h" +#include "Runtime/Scripting/ScriptingManager.h" +#include "Runtime/Scripting/ScriptingUtility.h" +#include "Runtime/Scripting/ScriptingExportUtility.h" +#include "Runtime/Scripting/Backend/ScriptingTypeRegistry.h" +#include "Runtime/Scripting/ScriptingObjectWithIntPtrField.h" +#include "Runtime/mecanim/human/human.h" +#include "Runtime/mecanim/generic/crc32.h" +#include "Runtime/Animation/AnimationUtility.h" +#include "Runtime/Scripting/Scripting.h" + +using namespace Unity; + +CSRAW + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; + +namespace UnityEngine +{ + +// Determines how time is treated outside of the keyframed range of an [[AnimationClip]] or [[AnimationCurve]]. +ENUM WrapMode + // When time reaches the end of the animation clip, the clip will automatically stop playing and time will be reset to beginning of the clip. + Once = 1, + + // When time reaches the end of the animation clip, time will continue at the beginning. + Loop = 2, + + // When time reaches the end of the animation clip, time will ping pong back between beginning and end. + PingPong = 4, + + // Reads the default repeat mode set higher up. + Default = 0, + + // Plays back the animation. When it reaches the end, it will keep playing the last frame and never stop playing. + ClampForever = 8, + + //*undocumented* + Clamp = 1, +END + +// AnimationEvent lets you call a script function similar to SendMessage as part of playing back an animation. +CSRAW [StructLayout (LayoutKind.Sequential)] +CLASS AnimationEvent + CSRAW [NotRenamed] + CSRAW internal IntPtr m_Ptr; + CSRAW int m_OwnsData; + + C++RAW + + struct AnimationEventMono + { + AnimationEvent* m_Ptr; + int m_OwnsData; + }; + + C++RAW + void VerifyReadOnly (ScriptingObjectWithIntPtrField<AnimationEvent>& self) + { +#if ENABLE_MONO + if (ExtractMonoObjectData<AnimationEventMono> (self.object).m_OwnsData != 1) + Scripting::RaiseMonoException("AnimationEvents sent by an Animation Event callback may not modify the AnimationEvent data"); +#endif + } + + C++RAW + inline AnimationEvent* GetAnimationEvent (ScriptingObjectWithIntPtrField<AnimationEvent>& self) + { + AnimationEvent* event = self.GetPtr(); + if (!event) + Scripting::RaiseNullException("Animation Event is out of scope"); + + return event; + } + + // Creates a new animation event + CSRAW public AnimationEvent () + { + m_OwnsData = 1; + Create(); + } + + THREAD_SAFE + CUSTOM private void Create () + { + self.SetPtr(new AnimationEvent()); + } + + CSRAW ~AnimationEvent () + { + if (m_OwnsData != 0) + Destroy(); + } + + THREAD_SAFE + CUSTOM private void Destroy () + { + delete self.GetPtr(); + } + + OBSOLETE warning Use stringParameter instead + CUSTOM_PROP string data { return scripting_string_new(GetAnimationEvent(self)->stringParameter); } { VerifyReadOnly(self); GetAnimationEvent(self)->stringParameter = value.AsUTF8(); } + + // String parameter that is stored in the event and will be sent to the function. + CUSTOM_PROP string stringParameter { return scripting_string_new(GetAnimationEvent(self)->stringParameter); } { VerifyReadOnly(self); GetAnimationEvent(self)->stringParameter = value.AsUTF8(); } + + // Float parameter that is stored in the event and will be sent to the function. + CUSTOM_PROP float floatParameter { return GetAnimationEvent(self)->floatParameter; } { VerifyReadOnly(self); GetAnimationEvent(self)->floatParameter = value; } + + // int parameter that is stored in the event and will be sent to the function. + CUSTOM_PROP int intParameter { return GetAnimationEvent(self)->intParameter; } { VerifyReadOnly(self); GetAnimationEvent(self)->intParameter = value; } + + // Object reference parameter that is stored in the event and will be sent to the function. + CUSTOM_PROP Object objectReferenceParameter { return Scripting::ScriptingWrapperFor(GetAnimationEvent(self)->objectReferenceParameter); } { VerifyReadOnly(self); GetAnimationEvent(self)->objectReferenceParameter = (Object*)value; } + + // The name of the function that will be called. + CUSTOM_PROP string functionName { return scripting_string_new(GetAnimationEvent(self)->functionName); } { VerifyReadOnly(self);GetAnimationEvent(self)->functionName = value.AsUTF8(); } + + // The time at which the event will be fired off. + CUSTOM_PROP float time { return GetAnimationEvent(self)->time; } { VerifyReadOnly(self); GetAnimationEvent(self)->time = value; } + + // Function call options. + CUSTOM_PROP SendMessageOptions messageOptions { return GetAnimationEvent(self)->messageOptions; } { VerifyReadOnly(self); GetAnimationEvent(self)->messageOptions = value; } + + // The animation state that fired this event (RO). + CUSTOM_PROP AnimationState animationState + { + return TrackedReferenceBaseToScriptingObject(GetAnimationEvent(self)->stateSender, animationState); + } + +END + +// Stores keyframe based animations. +CLASS AnimationClip : Motion + + // Creates a new animation clip + CSRAW public AnimationClip() + { + Internal_CreateAnimationClip(this); + } + + CUSTOM private static void Internal_CreateAnimationClip ([Writable]AnimationClip self) + { + Object* animClip = NEW_OBJECT(AnimationClip); + animClip->Reset(); + Scripting::ConnectScriptingWrapperToObject (self.GetScriptingObject(), animClip); + animClip->AwakeFromLoad(kInstantiateOrCreateFromCodeAwakeFromLoad); + } + + // Animation length in seconds (RO) + CUSTOM_PROP float length { return self->GetRange ().second; } + + + CUSTOM_PROP internal float startTime { return self->GetRange ().first; } + CUSTOM_PROP internal float stopTime { return self->GetRange ().second; } + + + // Frame rate at which keyframes are sampled (RO) + AUTO_PROP float frameRate GetSampleRate SetSampleRate + + + // Assigns the curve to animate a specific property. + CUSTOM void SetCurve (string relativePath, Type type, string propertyName, AnimationCurve curve) + { +#if ENABLE_MONO + Scripting::RaiseIfNull(type); + MonoClass* klass = GetScriptingTypeRegistry().GetType(type); + MonoScript* script = NULL; + int classID = Scripting::GetClassIDFromScriptingClass(klass); + if (classID == ClassID(MonoBehaviour)) + { + script = GetMonoScriptManager().FindRuntimeScript(klass); + if (script == NULL) + { + ErrorString("The script class couldn't be found"); + return; + } + } + + self->SetCurve(relativePath, classID, script, propertyName, curve.GetPtr(), true); +#endif + } + + //*undocumented* + AUTO void EnsureQuaternionContinuity(); + + // Clears all curves from the clip. + AUTO void ClearCurves(); + + // Sets the default wrap mode used in the animation state. + AUTO_PROP WrapMode wrapMode GetWrapMode SetWrapMode + + // Adds an animation event to the clip. + CUSTOM void AddEvent (AnimationEvent evt) + { + Scripting::RaiseIfNull(evt.GetPtr()); + self->AddRuntimeEvent(*GetAnimationEvent(evt)); + } + + // AABB of this Animation Clip in local space of Animation component that it is attached too. + AUTO_PROP Bounds localBounds GetBounds SetBounds + +END + +// A single keyframe that can be injected into an animation curve. +STRUCT Keyframe + CSRAW float m_Time; + CSRAW float m_Value; + CSRAW float m_InTangent; + CSRAW float m_OutTangent; + + CSRAW + #if UNITY_EDITOR + int m_TangentMode; + #endif + + // Create a keyframe. + CSRAW public Keyframe (float time, float value) + { + m_Time = time; + m_Value = value; + m_InTangent = 0; + m_OutTangent = 0; + #if UNITY_EDITOR + m_TangentMode = 0; + #endif + } + + // Create a keyframe. + CSRAW public Keyframe (float time, float value, float inTangent, float outTangent) + { + m_Time = time; + m_Value = value; + m_InTangent = inTangent; + m_OutTangent = outTangent; + #if UNITY_EDITOR + m_TangentMode = 0; + #endif + } + + // The time of the keyframe. + CSRAW public float time { get { return m_Time; } set { m_Time = value; } } + + // The value of the curve at keyframe. + CSRAW public float value { get { return m_Value; } set { m_Value = value; } } + + // Describes the tangent when approaching this point from the previous point in the curve. + CSRAW public float inTangent { get { return m_InTangent; } set { m_InTangent = value; } } + + // Describes the tangent when leaving this point towards the next point in the curve. + CSRAW public float outTangent { get { return m_OutTangent; } set { m_OutTangent = value; } } + + // The tangent mode of the keyframe. + // This is used only in the editor and will always return 0 in the player. + CSRAW public int tangentMode + { + get { + #if UNITY_EDITOR + return m_TangentMode; + #else + return 0; + #endif + } + set { + #if UNITY_EDITOR + m_TangentMode = value; + #endif + } + } + +END + +CSRAW #pragma warning disable 414 + +// An animation curve. Lets you add keyframes and evaluate the curve at a given time. +C++RAW + static void CleanupAnimationCurve(void* animationCurve){ delete ((AnimationCurve*)animationCurve); }; +// A collection of curves form an [[AnimationClip]]. +CSRAW [StructLayout (LayoutKind.Sequential)] +THREAD_SAFE +CLASS AnimationCurve + CSRAW + internal IntPtr m_Ptr; + + THREAD_SAFE + CUSTOM private void Cleanup () { CleanupAnimationCurve(self.GetPtr()); } + + CSRAW + ~AnimationCurve() + { + Cleanup (); + } + + // Evaluate the curve at /time/. + CUSTOM float Evaluate (float time) + { + return self->Evaluate(time); + } + + // All keys defined in the animation curve. + CSRAW public Keyframe[] keys { get { return GetKeys(); } set { SetKeys(value); } } + + // Add a new key to the curve. + CUSTOM int AddKey (float time, float value) { return AddKeySmoothTangents(*self, time, value); } + + // Add a new key to the curve. + CSRAW public int AddKey (Keyframe key) { return AddKey_Internal(key); } + + CUSTOM private int AddKey_Internal (Keyframe key) { return self->AddKey (key); } + + // Removes the keyframe at /index/ and inserts key. + CUSTOM int MoveKey (int index, Keyframe key) + { + if (index >= 0 && index < self->GetKeyCount()) + return MoveCurveKey(*self, index, key); + else { + Scripting::RaiseOutOfRangeException(""); + return 0; + } + } + + // Removes a key + CUSTOM void RemoveKey (int index) + { + if (index >= 0 && index < self->GetKeyCount()) + self->RemoveKeys(self->begin() + index, self->begin() + index + 1); + else + Scripting::RaiseOutOfRangeException(""); + } + + // Retrieves the key at index (RO) + CSRAW public Keyframe this [int index] + { + get { return GetKey_Internal(index); } + } + + // The number of keys in the curve (RO) + CUSTOM_PROP int length { return self->GetKeyCount(); } + + // Replace all keyframes with the /keys/ array. + CUSTOM private void SetKeys (Keyframe[] keys) + { + KeyframeTpl<float>* first = Scripting::GetScriptingArrayStart<KeyframeTpl<float> > (keys); + self->Assign(first, first + GetScriptingArraySize(keys)); + self->Sort(); + } + + CUSTOM private Keyframe GetKey_Internal (int index) + { + if (index >= 0 && index < self->GetKeyCount()) + { + return self->GetKey(index); + } + else + { + Scripting::RaiseOutOfRangeException(""); + return KeyframeTpl<float>(); + } + } + + CUSTOM private Keyframe[] GetKeys () + { + if (self->GetKeyCount() <= 0) + return CreateEmptyStructArray(MONO_COMMON.keyframe); + return CreateScriptingArray(&self->GetKey(0), self->GetKeyCount(), MONO_COMMON.keyframe); + } + + // Smooth the in and out tangents of the keyframe at /index/. + CUSTOM void SmoothTangents (int index, float weight) + { + if (index >= 0 && index < self->GetKeyCount()) + RecalculateSplineSlope(*self, index, weight); + else + Scripting::RaiseOutOfRangeException(""); + } + + // A straight Line starting at /timeStart/, /valueStart/ and ending at /timeEnd/, /valueEnd/ + CSRAW public static AnimationCurve Linear (float timeStart, float valueStart, float timeEnd, float valueEnd) + { + float tangent = (valueEnd - valueStart) / (timeEnd - timeStart); + Keyframe[] keys = { new Keyframe(timeStart, valueStart, 0.0F, tangent), new Keyframe(timeEnd, valueEnd, tangent, 0.0F) }; + return new AnimationCurve(keys); + } + + // An ease-in and out curve starting at /timeStart/, /valueStart/ and ending at /timeEnd/, /valueEnd/. + CSRAW public static AnimationCurve EaseInOut (float timeStart, float valueStart, float timeEnd, float valueEnd) + { + Keyframe[] keys = { new Keyframe(timeStart, valueStart, 0.0F, 0.0F), new Keyframe(timeEnd, valueEnd, 0.0F, 0.0F) }; + return new AnimationCurve(keys); + } + + // The behaviour of the animation before the first keyframe + CUSTOM_PROP WrapMode preWrapMode { return self->GetPreInfinity(); } { self->SetPreInfinity(value); } + // The behaviour of the animation after the last keyframe + CUSTOM_PROP WrapMode postWrapMode { return self->GetPostInfinity(); } { self->SetPostInfinity(value); } + + // Creates an animation curve from arbitrary number of keyframes. + CSRAW public AnimationCurve (params Keyframe[] keys) { Init(keys); } + + CONDITIONAL UNITY_FLASH || UNITY_WINRT + // *undocumented* + CSRAW public AnimationCurve(IntPtr nativeptr) { m_Ptr = nativeptr; } + + // Creates an empty animation curve + CSRAW public AnimationCurve () { Init(null); } + + THREAD_SAFE + CUSTOM private void Init (Keyframe[] keys) + { + self.SetPtr(new AnimationCurve(), CleanupAnimationCurve); + #if UNITY_WINRT + if (keys != SCRIPTING_NULL) AnimationCurve_CUSTOM_SetKeys(self.object, keys); + #else + if (keys != SCRIPTING_NULL) AnimationCurve_CUSTOM_SetKeys(self, keys); + #endif + } + +END + +CSRAW #pragma warning restore 414 + + +// Used by Animation.Play function. +ENUM PlayMode + // Will stop all animations that were started in the same layer. This is the default when playing animations. + StopSameLayer = 0, + // Will stop all animations that were started with this component before playing + StopAll = 4, +END + +// Used by Animation.Play function. +ENUM QueueMode + // Will start playing after all other animations have stopped playing + CompleteOthers = 0, + + // Starts playing immediately. This can be used if you just want to quickly create a duplicate animation. + PlayNow = 2 +END + +// Used by Animation.Play function. +ENUM AnimationBlendMode + // Animations will be blended + Blend = 0, + // Animations will be added + Additive = 1 +END + + +//*undocumented* - deprecated +CSRAW public enum AnimationPlayMode { Stop = 0, Queue = 1, Mix = 2 } + +// This enum controlls culling of Animation component. +ENUM AnimationCullingType + // Animation culling is disabled - object is animated even when offscreen. + AlwaysAnimate = 0, + + // Animation is disabled when renderers are not visible. + BasedOnRenderers = 1, + + // Animation is disabled when Animation::ref::localBounds are not visible. + BasedOnClipBounds = 2, + + // Animation is disabled when Animation::ref::localBounds are not visible. + BasedOnUserBounds = 3 +END + +// The animation component is used to play back animations. +CLASS Animation : Behaviour, IEnumerable + // The default animation. + AUTO_PTR_PROP AnimationClip clip GetClip SetClip + + // Should the default animation clip (Animation.clip) automatically start playing on startup. + AUTO_PROP bool playAutomatically GetPlayAutomatically SetPlayAutomatically + + // How should time beyond the playback range of the clip be treated? + AUTO_PROP WrapMode wrapMode GetWrapMode SetWrapMode + + // Stops all playing animations that were started with this Animation. + AUTO void Stop (); + + // Stops an animation named /name/. + CSRAW public void Stop (string name) { Internal_StopByName(name); } + CUSTOM private void Internal_StopByName (string name) { return self->Stop (name); } + + // Rewinds the animation named /name/. + CSRAW public void Rewind (string name) { Internal_RewindByName(name); } + CUSTOM private void Internal_RewindByName (string name) { self->Rewind(name); } + + // Rewinds all animations + AUTO void Rewind (); + + // Samples animations at the current state. + AUTO void Sample (); + + // Are we playing any animations? + AUTO_PROP bool isPlaying IsPlaying + + // Is the animation named /name/ playing? + CUSTOM bool IsPlaying (string name) { return self->IsPlaying (name); } + + + // Returns the animation state named /name/. + CSRAW public AnimationState this [string name] + { + get { return GetState(name); } + } + + /// *listonly* + CSRAW public bool Play (PlayMode mode = PlayMode.StopSameLayer) { return PlayDefaultAnimation (mode); } + + // Plays animation without any blending. + CUSTOM bool Play (string animation, PlayMode mode = PlayMode.StopSameLayer) { return self->Play(animation, mode); } + + // Fades the animation with name /animation/ in over a period of /time/ seconds and fades other animations out. + CUSTOM void CrossFade (string animation, float fadeLength = 0.3F, PlayMode mode = PlayMode.StopSameLayer) { self->CrossFade(animation, fadeLength, mode); } + + // Blends the animation named /animation/ towards /targetWeight/ over the next /time/ seconds. + CUSTOM void Blend (string animation, float targetWeight = 1.0F, float fadeLength = 0.3F) { self->Blend(animation, targetWeight, fadeLength); } + + + // Cross fades an animation after previous animations has finished playing. + CUSTOM AnimationState CrossFadeQueued (string animation, float fadeLength = 0.3F, QueueMode queue = QueueMode.CompleteOthers, PlayMode mode = PlayMode.StopSameLayer) + { + AnimationState* as = self->QueueCrossFade(animation, fadeLength, queue, mode); + return TrackedReferenceBaseToScriptingObject(as,animationState); + } + + + // Plays an animation after previous animations has finished playing. + CUSTOM AnimationState PlayQueued (string animation, QueueMode queue = QueueMode.CompleteOthers, PlayMode mode = PlayMode.StopSameLayer) + { + AnimationState* as = self->QueuePlay(animation, queue, mode); + return TrackedReferenceBaseToScriptingObject(as, animationState); + } + + + // Adds a /clip/ to the animation with name /newName/. + CSRAW public void AddClip (AnimationClip clip, string newName) { AddClip (clip, newName, Int32.MinValue, Int32.MaxValue); } + + // Adds /clip/ to the only play between /firstFrame/ and /lastFrame/. The new clip will also be added to the animation with name /newName/. + CUSTOM void AddClip (AnimationClip clip, string newName, int firstFrame, int lastFrame, bool addLoopFrame = false) { self->AddClip(*clip, newName, firstFrame, lastFrame, addLoopFrame); } + + // Remove clip from the animation list. + CUSTOM void RemoveClip (AnimationClip clip) { self->RemoveClip (*clip); } + + // Remove clip from the animation list. + CSRAW public void RemoveClip (string clipName) { RemoveClip2(clipName); } + + // Get the number of clips currently assigned to this animation + CUSTOM int GetClipCount () { return self->GetClipCount(); } + + CUSTOM private void RemoveClip2 (string clipName) { self->RemoveClip (clipName); } + + CUSTOM private bool PlayDefaultAnimation (PlayMode mode) { return self->Play(mode); } + + //*undocumented* deprecated + OBSOLETE warning use PlayMode instead of AnimationPlayMode. + CSRAW public bool Play (AnimationPlayMode mode) { return PlayDefaultAnimation((PlayMode)mode); } + //*undocumented* deprecated + OBSOLETE warning use PlayMode instead of AnimationPlayMode. + CSRAW public bool Play (string animation, AnimationPlayMode mode) { return Play(animation, (PlayMode)mode); } + + + // Synchronizes playback speed of all animations in the /layer/. + AUTO void SyncLayer(int layer); + + //*undocumented* Documented separately + CSRAW public IEnumerator GetEnumerator () + { + return new Animation.Enumerator (this); + } + //*undocumented* + CLASS private Enumerator : IEnumerator + CSRAW + private Animation m_Outer; + private int m_CurrentIndex = -1; + + internal Enumerator (Animation outer) { m_Outer = outer; } + //*undocumented* + public object Current + { + get { return m_Outer.GetStateAtIndex (m_CurrentIndex); } + } + + //*undocumented* + public bool MoveNext () + { + int childCount = m_Outer.GetStateCount(); + m_CurrentIndex++; + return m_CurrentIndex < childCount; + } + + //*undocumented* + public void Reset () { m_CurrentIndex = -1; } + END + + CUSTOM internal AnimationState GetState(string name) + { + AnimationState* state = self->GetState(name); + return TrackedReferenceBaseToScriptingObject(state, animationState); + } + + CUSTOM internal AnimationState GetStateAtIndex (int index) + { + + Animation& selfRef = *self; + if (index >= 0 || index < selfRef.GetAnimationStateCount()) + { + return TrackedReferenceBaseToScriptingObject(&selfRef.GetAnimationStateAtIndex (index), animationState); + } + Scripting::RaiseMonoException("Animation State out of bounds!"); + return SCRIPTING_NULL; + } + + CUSTOM internal int GetStateCount () { return self->GetAnimationStateCount(); } + + OBSOLETE planned Returns the animation clip named /name/. + CSRAW public AnimationClip GetClip (string name) { + AnimationState state = GetState(name); + if (state) + return state.clip; + else + return null; + } + + + // When turned on, animations will be executed in the physics loop. This is only useful in conjunction with kinematic rigidbodies. + AUTO_PROP bool animatePhysics GetAnimatePhysics SetAnimatePhysics + + // When turned on, Unity might stop animating if it thinks that the results of the animation won't be visible to the user. + OBSOLETE warning Use cullingType instead + CUSTOM_PROP bool animateOnlyIfVisible + { + Animation::CullingType type = self->GetCullingType(); + AssertMsg(type == Animation::kCulling_AlwaysAnimate || type == Animation::kCulling_BasedOnRenderers, + "Culling type %d cannot be converted to animateOnlyIfVisible. animateOnlyIfVisible is obsolete, please use cullingType instead.", type); + return type == Animation::kCulling_BasedOnRenderers; + } + { + self->SetCullingType(value ? Animation::kCulling_BasedOnRenderers : Animation::kCulling_AlwaysAnimate); + } + + // Controls culling of this Animation component. + AUTO_PROP AnimationCullingType cullingType GetCullingType SetCullingType + + // AABB of this Animation animation component in local space. + AUTO_PROP Bounds localBounds GetLocalAABB SetLocalAABB + +END + +// The AnimationState gives full control over animation blending. +CLASS AnimationState : TrackedReference + + // Enables / disables the animation. + + AUTO_PROP bool enabled GetEnabled SetEnabled + + // The weight of animation + AUTO_PROP float weight GetWeight SetWeight + + // Wrapping mode of the animation. + AUTO_PROP WrapMode wrapMode GetWrapMode SetWrapMode + + // The current time of the animation + AUTO_PROP float time GetTime SetTime + + // The normalized time of the animation. + AUTO_PROP float normalizedTime GetNormalizedTime SetNormalizedTime + + // The playback speed of the animation. 1 is normal playback speed. + AUTO_PROP float speed GetSpeed SetSpeed + + // The normalized playback speed. + AUTO_PROP float normalizedSpeed GetNormalizedSpeed SetNormalizedSpeed + + // The length of the animation clip in seconds. + AUTO_PROP float length GetLength + + // The layer of the animation. When calculating the final blend weights, animations in higher layers will get their weights + AUTO_PROP int layer GetLayer SetLayer + + // The clip that is being played by this animation state. + AUTO_PTR_PROP AnimationClip clip GetClip + + // Adds a transform which should be animated. This allows you to reduce the number of animations you have to create. + CUSTOM void AddMixingTransform (Transform mix, bool recursive = true) { self->AddMixingTransform(*mix, recursive); } + + // Removes a transform which should be animated. + CUSTOM void RemoveMixingTransform (Transform mix) { self->RemoveMixingTransform(*mix); } + + // The name of the animation + CUSTOM_PROP string name { return scripting_string_new(self->GetName()); } { self->SetName(value.AsUTF8()); } + + // Which blend mode should be used? + AUTO_PROP AnimationBlendMode blendMode GetBlendMode SetBlendMode +END + +CLASS GameObject : Object + + // Samples an animation at a given time for any animated properties. + CUSTOM void SampleAnimation (AnimationClip animation, float time) { SampleAnimation (*self, *animation, time, animation->GetWrapMode()); } + +END + + +CSRAW } diff --git a/Runtime/Animation/ScriptBindings/AnimatorBindings.txt b/Runtime/Animation/ScriptBindings/AnimatorBindings.txt new file mode 100644 index 0000000..d729bc7 --- /dev/null +++ b/Runtime/Animation/ScriptBindings/AnimatorBindings.txt @@ -0,0 +1,677 @@ + +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/Mono/MonoBehaviour.h" +#include "Runtime/Graphics/Transform.h" +#include "Runtime/Mono/MonoScript.h" +#include "Runtime/Mono/MonoManager.h" +#include "Runtime/Animation/Animator.h" +#include "Runtime/Animation/RuntimeAnimatorController.h" +#include "Runtime/Animation/Avatar.h" +#include "Runtime/mecanim/human/human.h" +#include "Runtime/mecanim/generic/crc32.h" +#include "Runtime/Animation/AnimationClip.h" +#include "Runtime/Animation/AnimatorOverrideController.h" +#include "Runtime/Scripting/ScriptingExportUtility.h" +#include "Runtime/Scripting/ScriptingUtility.h" +#include "Runtime/Scripting/Scripting.h" + +using namespace Unity; + +CSRAW + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; + +namespace UnityEngine +{ + +// Target +ENUM AvatarTarget + // The root, the position of the game object + Root = 0, + // The body, center of mass + Body = 1, + // The left foot + LeftFoot = 2, + // The right foot + RightFoot = 3, + // The left hand + LeftHand = 4, + // The right hand + RightHand = 5, +END + +// IK Goal +ENUM AvatarIKGoal + // The left foot + LeftFoot = 0, + // The right foot + RightFoot = 1, + // The left hand + LeftHand = 2, + // The right hand + RightHand = 3 +END + +// Information about what animation clips is played and its weight +STRUCT AnimationInfo + + // Animation clip that is played + CSRAW public AnimationClip clip { get {return m_ClipInstanceID != 0 ? ClipInstanceToScriptingObject(m_ClipInstanceID) : null; } } + + // The weight of the animation clip + CSRAW public float weight { get { return m_Weight;}} + + CUSTOM private static AnimationClip ClipInstanceToScriptingObject(int instanceID) + { + return Scripting::ScriptingWrapperFor(PPtr<AnimationClip>(instanceID)); + } + + CSRAW private int m_ClipInstanceID; + CSRAW private float m_Weight; +END + +C++RAW + +struct MonoAnimationInfo +{ + int clipInstanceID; + float weight; +}; + +void AnimationInfoToMono ( const AnimationInfo& src, MonoAnimationInfo &dest) +{ + dest.clipInstanceID = src.clip.IsValid() ? src.clip.GetInstanceID() : 0; + dest.weight = src.weight; +} + +static int ScriptingStringToCRC32 (ICallString& stringValue); + + +// Culling mode for the Animator +ENUM AnimatorCullingMode + + // Always animate the entire character. Object is animated even when offscreen. + AlwaysAnimate = 0, + + // Animation is disabled when renderers are not visible. + BasedOnRenderers = 1 +END + +// Information about the current or next state +STRUCT AnimatorStateInfo + + // Does /name/ match the name of the active state in the statemachine. + CSRAW public bool IsName (string name) { int hash = Animator.StringToHash (name); return hash == m_Name || hash == m_Path; } + + // For backwards compatibility this is actually the path... + // In the future it would be good to come up with a new name for the name & path. + CSRAW public int nameHash { get { return m_Path; } } + + // Normalized time of the State + CSRAW public float normalizedTime { get { return m_NormalizedTime; } } + + // Current duration of the state + CSRAW public float length { get { return m_Length; } } + + // The Tag of the State + CSRAW public int tagHash { get { return m_Tag; } } + + // Does /tag/ match the tag of the active state in the statemachine. + CSRAW public bool IsTag (string tag) { return Animator.StringToHash (tag) == m_Tag; } + + // Is the state looping + CSRAW public bool loop { get { return m_Loop != 0;} } + + CSRAW private int m_Name; + CSRAW private int m_Path; + CSRAW private float m_NormalizedTime; + CSRAW private float m_Length; + CSRAW private int m_Tag; + CSRAW private int m_Loop; +END + +// Information about the current transition +STRUCT AnimatorTransitionInfo + + // Does /name/ match the name of the active Transition. + CSRAW public bool IsName (string name) { return Animator.StringToHash (name) == m_Name ; } + + // Does /userName/ match the name of the active Transition. + CSRAW public bool IsUserName (string name) { return Animator.StringToHash (name) == m_UserName ; } + + // The unique name of the Transition + CSRAW public int nameHash { get { return m_Name; } } + + // The user-specidied name of the Transition + CSRAW public int userNameHash { get { return m_UserName; } } + + // Normalized time of the Transition + CSRAW public float normalizedTime { get { return m_NormalizedTime; } } + + + CSRAW private int m_Name; + CSRAW private int m_UserName; + CSRAW private float m_NormalizedTime; + +END + + + +// To specify position and rotation weight mask for Animator::MatchTarget +STRUCT MatchTargetWeightMask + + // MatchTargetWeightMask contructor + CSRAW public MatchTargetWeightMask(Vector3 positionXYZWeight, float rotationWeight) + { + m_PositionXYZWeight = positionXYZWeight; + m_RotationWeight = rotationWeight; + } + + // Position XYZ weight + CSRAW public Vector3 positionXYZWeight + { + get { return m_PositionXYZWeight;} + set { m_PositionXYZWeight = value; } + } + + // Rotation weight + CSRAW public float rotationWeight + { + get { return m_RotationWeight;} + set { m_RotationWeight =value;} + } + + CSRAW private Vector3 m_PositionXYZWeight; + CSRAW private float m_RotationWeight; +END + +C++RAW + enum HumanBodyBones { Hips=0, LeftUpperLeg, RightUpperLeg, LeftLowerLeg, RightLowerLeg, LeftFoot, RightFoot, Spine, Chest, Neck, Head, LeftShoulder, RightShoulder, LeftUpperArm, RightUpperArm, LeftLowerArm, RightLowerArm, LeftHand, RightHand, LeftToes, RightToes, LeftEye, RightEye, Jaw, LastBone}; + + +// Interface to control the Mecanim animation system +CLASS Animator : Behaviour + + // Returns true if the current rig is optimizable + CUSTOM_PROP bool isOptimizable { return self->IsOptimizable(); } + + // Returns true if the current rig is ''humanoid'', false if it is ''generic'' + CUSTOM_PROP bool isHuman { return self->IsHuman(); } + + // Returns true if the current generic rig has a root motion + CUSTOM_PROP bool hasRootMotion { return self->HasRootMotion(); } + + // Returns the scale of the current Avatar for a humanoid rig, (1 by default if the rig is generic) + CUSTOM_PROP float humanScale { return self->GetHumanScale(); } + + // Gets the value of a float parameter + CSRAW public float GetFloat(string name) { return GetFloatString(name); } + // Gets the value of a float parameter + CSRAW public float GetFloat(int id) { return GetFloatID(id); } + // Sets the value of a float parameter + CSRAW public void SetFloat(string name, float value) { SetFloatString(name, value);} + // Sets the value of a float parameter + CSRAW public void SetFloat(string name, float value, float dampTime, float deltaTime) { SetFloatStringDamp(name, value, dampTime, deltaTime);} + + // Sets the value of a float parameter + CSRAW public void SetFloat(int id, float value) { SetFloatID(id, value);} + // Sets the value of a float parameter + CSRAW public void SetFloat(int id, float value, float dampTime, float deltaTime) { SetFloatIDDamp(id, value, dampTime, deltaTime); } + + // Gets the value of a bool parameter + CSRAW public bool GetBool(string name) { return GetBoolString(name);} + // Gets the value of a bool parameter + CSRAW public bool GetBool(int id) { return GetBoolID(id);} + // Sets the value of a bool parameter + CSRAW public void SetBool(string name, bool value) { SetBoolString(name, value);} + // Sets the value of a bool parameter + CSRAW public void SetBool(int id, bool value) { SetBoolID(id, value);} + + // Gets the value of an integer parameter + CSRAW public int GetInteger(string name) { return GetIntegerString(name);} + // Gets the value of an integer parameter + CSRAW public int GetInteger(int id) { return GetIntegerID(id);} + // Sets the value of an integer parameter + CSRAW public void SetInteger(string name, int value) { SetIntegerString(name, value);} + + // Sets the value of an integer parameter + CSRAW public void SetInteger(int id, int value) { SetIntegerID(id, value); } + + // Sets the trigger parameter on + CSRAW public void SetTrigger(string name) { SetTriggerString(name); } + + // Sets the trigger parameter at on + CSRAW public void SetTrigger(int id) { SetTriggerID(id); } + + // Resets the trigger parameter at off + CSRAW public void ResetTrigger(string name) { ResetTriggerString(name); } + + // Resets the trigger parameter at off + CSRAW public void ResetTrigger(int id) { ResetTriggerID(id); } + + // Returns true if a parameter is controlled by an additional curve on an animation + CSRAW public bool IsParameterControlledByCurve(string name) { return IsParameterControlledByCurveString(name); } + // Returns true if a parameter is controlled by an additional curve on an animation + CSRAW public bool IsParameterControlledByCurve(int id) { return IsParameterControlledByCurveID(id); } + + // Gets the avatar delta position for the last evaluated frame + CUSTOM_PROP Vector3 deltaPosition { return self->GetDeltaPosition(); } + // Gets the avatar delta rotation for the last evaluated frame + CUSTOM_PROP Quaternion deltaRotation { return self->GetDeltaRotation(); } + + // The root position, the position of the game object + CUSTOM_PROP Vector3 rootPosition { return self->GetAvatarPosition();} { self->SetAvatarPosition(value);} + // The root rotation, the rotation of the game object + CUSTOM_PROP Quaternion rootRotation { return self->GetAvatarRotation();} { self->SetAvatarRotation(value);} + + // Root is controlled by animations + CUSTOM_PROP bool applyRootMotion { return self->GetApplyRootMotion(); } { self->SetApplyRootMotion(value); } + + // When turned on, animations will be executed in the physics loop. This is only useful in conjunction with kinematic rigidbodies. + CUSTOM_PROP bool animatePhysics { return self->GetAnimatePhysics(); } { self->SetAnimatePhysics(value); } + + // Tell if the corresponding Character has transform hierarchy. + CUSTOM_PROP bool hasTransformHierarchy { return self->GetHasTransformHierarchy(); } + + // The current gravity weight based on current animations that are played + CUSTOM_PROP float gravityWeight { return self->GetGravityWeight(); } + + // The position of the body center of mass + CUSTOM_PROP Vector3 bodyPosition { return self->GetBodyPosition(); } { self->SetBodyPosition(value); } + // The rotation of the body center of mass + CUSTOM_PROP Quaternion bodyRotation { return self->GetBodyRotation(); } { self->SetBodyRotation(value); } + + // Gets the position of an IK goal + CUSTOM Vector3 GetIKPosition( AvatarIKGoal goal) { return self->GetGoalPosition(goal) ;} + // Sets the position of an IK goal + CUSTOM void SetIKPosition( AvatarIKGoal goal, Vector3 goalPosition) { self->SetGoalPosition(goal,goalPosition); } + + // Gets the rotation of an IK goal + CUSTOM Quaternion GetIKRotation( AvatarIKGoal goal) { return self->GetGoalRotation(goal); } + // Sets the rotation of an IK goal + CUSTOM void SetIKRotation( AvatarIKGoal goal, Quaternion goalRotation) { self->SetGoalRotation(goal, goalRotation); } + + // Gets the translative weight of an IK goal (0 = at the original animation before IK, 1 = at the goal) + CUSTOM float GetIKPositionWeight ( AvatarIKGoal goal) { return self->GetGoalWeightPosition(goal); } + // Sets the translative weight of an IK goal (0 = at the original animation before IK, 1 = at the goal) + CUSTOM void SetIKPositionWeight ( AvatarIKGoal goal, float value) { self->SetGoalWeightPosition(goal,value); } + + // Gets the rotational weight of an IK goal (0 = rotation before IK, 1 = rotation at the IK goal) + CUSTOM float GetIKRotationWeight( AvatarIKGoal goal) { return self->GetGoalWeightRotation(goal); } + // Sets the rotational weight of an IK goal (0 = rotation before IK, 1 = rotation at the IK goal) + CUSTOM void SetIKRotationWeight( AvatarIKGoal goal, float value) { self->SetGoalWeightRotation(goal,value); } + + // Sets the look at position + CUSTOM void SetLookAtPosition(Vector3 lookAtPosition) { self->SetLookAtPosition(lookAtPosition); } + + //Set look at weights + CUSTOM void SetLookAtWeight(float weight, float bodyWeight = 0.00f, float headWeight = 1.00f, float eyesWeight = 0.00f, float clampWeight = 0.50f) + { + self->SetLookAtBodyWeight(weight*bodyWeight); + self->SetLookAtHeadWeight(weight*headWeight); + self->SetLookAtEyesWeight(weight*eyesWeight); + self->SetLookAtClampWeight(clampWeight); + } + + // Automatic stabilization of feet during transition and blending + CUSTOM_PROP bool stabilizeFeet { return self->GetStabilizeFeet(); } { self->SetStabilizeFeet(value);} + + // The AnimatorController layer count + CUSTOM_PROP int layerCount { return self->GetLayerCount(); } + // Gets name of the layer + CUSTOM string GetLayerName( int layerIndex) { return scripting_string_new(self->GetLayerName(layerIndex)) ; } + // Gets the layer's current weight + CUSTOM float GetLayerWeight( int layerIndex) { return self->GetLayerWeight(layerIndex) ; } + // Sets the layer's current weight + CUSTOM void SetLayerWeight( int layerIndex, float weight) { self->SetLayerWeight(layerIndex, weight); } + + + // Gets the current State information on a specified AnimatorController layer + CUSTOM AnimatorStateInfo GetCurrentAnimatorStateInfo(int layerIndex) + { + AnimatorStateInfo info; + self->GetAnimatorStateInfo (layerIndex, true, info); + return info; + } + + // Gets the next State information on a specified AnimatorController layer + CUSTOM AnimatorStateInfo GetNextAnimatorStateInfo(int layerIndex) + { + AnimatorStateInfo info; + self->GetAnimatorStateInfo(layerIndex, false, info); + return info; + } + + // Gets the Transition information on a specified AnimatorController layer + CUSTOM AnimatorTransitionInfo GetAnimatorTransitionInfo(int layerIndex) + { + AnimatorTransitionInfo info; + self->GetAnimatorTransitionInfo(layerIndex, info); + return info; + } + + CONDITIONAL !UNITY_FLASH + // Gets the list of AnimationInfo currently played by the current state + CUSTOM AnimationInfo[] GetCurrentAnimationClipState (int layerIndex) + { + dynamic_array<AnimationInfo> clips (kMemTempAlloc); + self->GetAnimationClipState(layerIndex, true, clips); + return DynamicArrayToScriptingStructArray(clips, GetMonoManager().GetCommonClasses().animationInfo, AnimationInfoToMono); + } + + CONDITIONAL !UNITY_FLASH + // Gets the list of AnimationInfo currently played by the next state + CUSTOM AnimationInfo[] GetNextAnimationClipState (int layerIndex) + { + dynamic_array<AnimationInfo> clips (kMemTempAlloc); + self->GetAnimationClipState(layerIndex, false, clips); + return DynamicArrayToScriptingStructArray(clips, GetMonoManager().GetCommonClasses().animationInfo, AnimationInfoToMono); + } + + // Is the specified AnimatorController layer in a transition + CUSTOM bool IsInTransition(int layerIndex) { return self->IsInTransition(layerIndex); } + + + // Blends pivot point between body center of mass and feet pivot. At 0%, the blending point is body center of mass. At 100%, the blending point is feet pivot + CUSTOM_PROP float feetPivotActive { return self->GetFeetPivotActive(); } { self->SetFeetPivotActive(value);} + // Gets the pivot weight + CUSTOM_PROP float pivotWeight { return self->GetPivotWeight(); } + // Get the current position of the pivot + CUSTOM_PROP Vector3 pivotPosition { return self->GetPivotPosition(); } + + + // Automatically adjust the gameobject position and rotation so that the AvatarTarget reaches the matchPosition when the current state is at the specified progress + CUSTOM void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget targetBodyPart, MatchTargetWeightMask weightMask, float startNormalizedTime, float targetNormalizedTime = 1) + { + self->MatchTarget(matchPosition, matchRotation, (int)targetBodyPart, weightMask, startNormalizedTime, targetNormalizedTime); + } + + // Interrupts the automatic target matching + CUSTOM void InterruptMatchTarget(bool completeMatch = true) { self->InterruptMatchTarget(completeMatch);} + // If automatic matching is active + CUSTOM_PROP bool isMatchingTarget{ return self->IsMatchingTarget();} + + + // The playback speed of the Animator. 1 is normal playback speed + CUSTOM_PROP float speed { return self->GetSpeed() ; } { self->SetSpeed(value);} + + // Force the normalized time of a state to a user defined value + OBSOLETE warning ForceStateNormalizedTime is deprecated. Please use Play or CrossFade instead. + CSRAW public void ForceStateNormalizedTime(float normalizedTime) { Play(0, 0, normalizedTime); } + + + CSRAW public void CrossFade (string stateName, float transitionDuration, int layer = -1, float normalizedTime = float.NegativeInfinity) + { + CrossFade (StringToHash(stateName), transitionDuration, layer, normalizedTime); + } + CUSTOM void CrossFade (int stateNameHash, float transitionDuration, int layer = -1, float normalizedTime = float.NegativeInfinity) + { + self->GotoState(layer, stateNameHash, normalizedTime, transitionDuration); + } + + CSRAW public void Play (string stateName, int layer = -1, float normalizedTime = float.NegativeInfinity) + { + Play (StringToHash(stateName), layer, normalizedTime); + } + CUSTOM void Play (int stateNameHash, int layer = -1, float normalizedTime = float.NegativeInfinity) + { + self->GotoState(layer, stateNameHash, normalizedTime, 0.0F); + } + + + + // Sets an AvatarTarget and a targetNormalizedTime for the current state + CUSTOM void SetTarget(AvatarTarget targetIndex, float targetNormalizedTime) {self->SetTarget((int)targetIndex, targetNormalizedTime);} + // Returns the position of the target specified by SetTarget(AvatarTarget targetIndex, float targetNormalizedTime)) + CUSTOM_PROP Vector3 targetPosition { return self->GetTargetPosition(); } + // Returns the rotation of the target specified by SetTarget(AvatarTarget targetIndex, float targetNormalizedTime)) + CUSTOM_PROP Quaternion targetRotation { return self->GetTargetRotation(); } + + + OBSOLETE error use mask and layers to control subset of transfroms in a skeleton + CUSTOM bool IsControlled(Transform transform) {return false;} + + // Returns ture if a transform a bone controlled by human + CUSTOM internal bool IsBoneTransform(Transform transform) {return self->IsBoneTransform(transform);} + + CUSTOM_PROP internal Transform avatarRoot {return Scripting::ScriptingWrapperFor(self->GetAvatarRoot());} + + // Returns transform mapped to this human bone id + CUSTOM Transform GetBoneTransform(HumanBodyBones humanBoneId) {return Scripting::ScriptingWrapperFor(self->GetBoneTransform((int)humanBoneId));} + + // Controls culling of this Animator component. + AUTO_PROP AnimatorCullingMode cullingMode GetCullingMode SetCullingMode + + // Sets the animator in playback mode + CUSTOM void StartPlayback() { self->StartPlayback();} + + // Stops animator playback mode + CUSTOM void StopPlayback() { self->StopPlayback();} + + // Plays recorded data + CUSTOM_PROP float playbackTime {return self->GetPlaybackTime(); } { self->SetPlaybackTime(value);} + + // Sets the animator in record mode + CUSTOM void StartRecording(int frameCount) { self->StartRecording(frameCount);} + + // Stops animator record mode + CUSTOM void StopRecording() { self->StopRecording();} + + // The time at which the recording data starts + CUSTOM_PROP float recorderStartTime { return self->GetRecorderStartTime();} {} + + // The time at which the recoding data stops + CUSTOM_PROP float recorderStopTime { return self->GetRecorderStopTime();} {} + + // The runtime representation of AnimatorController that controls the Animator + CUSTOM_PROP RuntimeAnimatorController runtimeAnimatorController {return Scripting::ScriptingWrapperFor(self->GetRuntimeAnimatorController());} { self->SetRuntimeAnimatorController(value);} + + C++RAW static int ScriptingStringToCRC32 (ICallString& stringValue) + { + if(stringValue.IsNull()) return 0; + #if ENABLE_MONO + const gunichar2* chars = mono_string_chars(stringValue.str); + const size_t length = stringValue.Length(); + + if (IsUtf16InAsciiRange (chars, length)) + { + return mecanim::processCRC32UTF16Ascii (chars, length); + } + else + #endif + { + return mecanim::processCRC32 (stringValue.AsUTF8().c_str()); + } + } + + // Generates an parameter id from a string + THREAD_SAFE + CUSTOM static int StringToHash (string name) { return ScriptingStringToCRC32(name); } + + // Gets/Sets the current Avatar + CUSTOM_PROP Avatar avatar {return Scripting::ScriptingWrapperFor(self->GetAvatar());} { self->SetAvatar(value);} + +C++RAW + + #define GET_NAME_IMPL(Func,x) \ + x value; \ + GetSetValueResult result = self->Func(ScriptingStringToCRC32(name), value); \ + if (result != kGetSetSuccess) \ + self->ValidateParameterString (result, name); \ + return value; + + #define SET_NAME_IMPL(Func) \ + GetSetValueResult result = self->Func(ScriptingStringToCRC32(name), value); \ + if (result != kGetSetSuccess) \ + self->ValidateParameterString (result, name); + + + #define GET_ID_IMPL(Func,x) \ + x value; \ + GetSetValueResult result = self->Func(id, value); \ + if (result != kGetSetSuccess) \ + self->ValidateParameterID (result, id); \ + return value; + + #define SET_ID_IMPL(Func) \ + GetSetValueResult result = self->Func(id, value); \ + if (result != kGetSetSuccess) \ + self->ValidateParameterID (result, id); + + + // Internal + CUSTOM private void SetFloatString(string name, float value) { SET_NAME_IMPL(SetFloat) } + CUSTOM private void SetFloatID(int id, float value) { SET_ID_IMPL (SetFloat) } + + CUSTOM private float GetFloatString(string name) { GET_NAME_IMPL(GetFloat, float) } + CUSTOM private float GetFloatID(int id) { GET_ID_IMPL (GetFloat, float) } + + CUSTOM private void SetBoolString(string name, bool value) { SET_NAME_IMPL(SetBool) } + CUSTOM private void SetBoolID(int id, bool value) { SET_ID_IMPL (SetBool) } + + CUSTOM private bool GetBoolString(string name) { GET_NAME_IMPL(GetBool, bool) } + CUSTOM private bool GetBoolID(int id) { GET_ID_IMPL (GetBool, bool) } + + + CUSTOM private void SetIntegerString(string name, int value) { SET_NAME_IMPL(SetInteger) } + CUSTOM private void SetIntegerID(int id, int value) { SET_ID_IMPL (SetInteger)} + + CUSTOM private int GetIntegerString(string name) { GET_NAME_IMPL(GetInteger, int) } + CUSTOM private int GetIntegerID(int id) { GET_ID_IMPL (GetInteger, int) } + + CUSTOM private void SetTriggerString(string name) + { + GetSetValueResult result = self->SetTrigger(ScriptingStringToCRC32(name)); + if (result != kGetSetSuccess) + self->ValidateParameterString (result, name); + } + + CUSTOM private void SetTriggerID(int id) + { + GetSetValueResult result = self->SetTrigger(id); + if (result != kGetSetSuccess) + self->ValidateParameterID (result, id); + } + + CUSTOM private void ResetTriggerString(string name) + { + GetSetValueResult result = self->ResetTrigger(ScriptingStringToCRC32(name)); + if (result != kGetSetSuccess) + self->ValidateParameterString (result, name); + } + + CUSTOM private void ResetTriggerID(int id) + { + GetSetValueResult result = self->ResetTrigger(id); + if (result != kGetSetSuccess) + self->ValidateParameterID (result, id); + } + + CUSTOM private bool IsParameterControlledByCurveString(string name) + { + GetSetValueResult result = self->ParameterControlledByCurve(ScriptingStringToCRC32(name)); + if (result == kParameterIsControlledByCurve) + return true; + else if (result == kGetSetSuccess) + return false; + else + { + self->ValidateParameterString (result, name); + return false; + } + } + + CUSTOM private bool IsParameterControlledByCurveID(int id) + { + GetSetValueResult result = self->ParameterControlledByCurve(id); + if (result == kParameterIsControlledByCurve) + return true; + else if (result == kGetSetSuccess) + return false; + else + { + self->ValidateParameterID (result, id); + return false; + } + } + + CUSTOM private void SetFloatStringDamp(string name, float value, float dampTime, float deltaTime) + { + GetSetValueResult result = self->SetFloatDamp(ScriptingStringToCRC32(name), value, dampTime, deltaTime); + if (result != kGetSetSuccess) + self->ValidateParameterString (result, name); + } + + CUSTOM private void SetFloatIDDamp(int id, float value, float dampTime, float deltaTime) + { + GetSetValueResult result = self->SetFloatDamp(id, value, dampTime, deltaTime); + if (result != kGetSetSuccess) + self->ValidateParameterID (result, id); + } + + // True if additional layers affect the center of mass + CUSTOM_PROP bool layersAffectMassCenter {return self->GetLayersAffectMassCenter();} { self->SetLayersAffectMassCenter(value);} + + + // Get left foot bottom height. + CUSTOM_PROP float leftFeetBottomHeight {return self->GetLeftFeetBottomHeight();} + + // Get right foot bottom height. + CUSTOM_PROP float rightFeetBottomHeight {return self->GetRightFeetBottomHeight();} + + CONDITIONAL UNITY_EDITOR + CUSTOM_PROP internal bool supportsOnAnimatorMove { return self->SupportsOnAnimatorMove (); } + + CONDITIONAL UNITY_EDITOR + CUSTOM internal void WriteDefaultPose() { self->WriteDefaultPose(); } + + CUSTOM void Update(float deltaTime) { self->Update(deltaTime);} + + CONDITIONAL UNITY_EDITOR + // Evalutes only the StateMachine, does not write into transforms, uses previous deltaTime + // Mostly used for editor previews ( BlendTrees ) + CUSTOM internal void EvaluateSM() {self->EvaluateSM();} + + CONDITIONAL UNITY_EDITOR + CUSTOM internal string GetCurrentStateName(int layerIndex) { return scripting_string_new(self->GetAnimatorStateName(layerIndex,true));} + + CONDITIONAL UNITY_EDITOR + CUSTOM internal string GetNextStateName(int layerIndex) { return scripting_string_new(self->GetAnimatorStateName(layerIndex,false));} + + CUSTOM_PROP private bool isInManagerList { return self->IsInManagerList();} + + AUTO_PROP bool logWarnings GetLogWarnings SetLogWarnings + AUTO_PROP bool fireEvents GetFireEvents SetFireEvents + + + + + OBSOLETE warning GetVector is deprecated. + CSRAW public Vector3 GetVector(string name) { return Vector3.zero; } + OBSOLETE warning GetVector is deprecated. + CSRAW public Vector3 GetVector(int id) { return Vector3.zero; } + OBSOLETE warning SetVector is deprecated. + CSRAW public void SetVector(string name, Vector3 value) { } + OBSOLETE warning SetVector is deprecated. + CSRAW public void SetVector(int id, Vector3 value) { } + + OBSOLETE warning GetQuaternion is deprecated. + CSRAW public Quaternion GetQuaternion(string name) { return Quaternion.identity;} + OBSOLETE warning GetQuaternion is deprecated. + CSRAW public Quaternion GetQuaternion(int id) { return Quaternion.identity; } + OBSOLETE warning SetQuaternion is deprecated. + CSRAW public void SetQuaternion(string name, Quaternion value) { } + OBSOLETE warning SetQuaternion is deprecated. + CSRAW public void SetQuaternion(int id, Quaternion value) { } + +END + + + + +CSRAW } diff --git a/Runtime/Animation/ScriptBindings/AnimatorOverrideControllerBindings.txt b/Runtime/Animation/ScriptBindings/AnimatorOverrideControllerBindings.txt new file mode 100644 index 0000000..9f73f79 --- /dev/null +++ b/Runtime/Animation/ScriptBindings/AnimatorOverrideControllerBindings.txt @@ -0,0 +1,138 @@ +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/Mono/MonoBehaviour.h" +#include "Runtime/Mono/MonoScript.h" +#include "Runtime/Graphics/Transform.h" +#include "Runtime/Animation/AnimatorOverrideController.h" +#include "Runtime/Animation/AnimationClip.h" +#include "Runtime/Animation/RuntimeAnimatorController.h" +#include "Runtime/Scripting/ScriptingExportUtility.h" + +using namespace Unity; + +CSRAW + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; + +namespace UnityEngine +{ + +CSRAW [System.Serializable] +CSRAW [StructLayout (LayoutKind.Sequential)] +CLASS AnimationClipPair + public AnimationClip originalClip; + public AnimationClip overrideClip; +END + +// AnimatorOverrideController definition +CLASS AnimatorOverrideController : RuntimeAnimatorController + + // Creates a new animation clip + CSRAW public AnimatorOverrideController() + { + Internal_CreateAnimationSet(this); + } + + CUSTOM private static void Internal_CreateAnimationSet ([Writable]AnimatorOverrideController self) + { + Object* animationSet = NEW_OBJECT(AnimatorOverrideController); + animationSet->Reset(); + Scripting::ConnectScriptingWrapperToObject (self.GetScriptingObject(), animationSet); + animationSet->AwakeFromLoad(kInstantiateOrCreateFromCodeAwakeFromLoad); + } + + // The runtime representation of AnimatorController that controls the Animator + CUSTOM_PROP RuntimeAnimatorController runtimeAnimatorController {return Scripting::ScriptingWrapperFor(self->GetAnimatorController());} { self->SetAnimatorController(value);} + + // Returns the animation clip named /name/. + CSRAW public AnimationClip this [string name] + { + get { return Internal_GetClipByName(name, true); } + set { Internal_SetClipByName(name, value); } + } + + CUSTOM private AnimationClip Internal_GetClipByName(string name, bool returnEffectiveClip) + { + return Scripting::ScriptingWrapperFor(self->GetClip( name, returnEffectiveClip )); + } + + CUSTOM private void Internal_SetClipByName(string name, AnimationClip clip) + { + return self->SetClip( name, clip ); + } + + // Returns the animation clip named /name/. + CSRAW public AnimationClip this [AnimationClip clip] + { + get { return Internal_GetClip(clip, true); } + set { Internal_SetClip(clip, value); } + } + + CUSTOM private AnimationClip Internal_GetClip(AnimationClip originalClip, bool returnEffectiveClip) + { + return Scripting::ScriptingWrapperFor(self->GetClip( originalClip, returnEffectiveClip)); + } + + CUSTOM private void Internal_SetClip(AnimationClip originalClip, AnimationClip overrideClip) + { + return self->SetClip( originalClip, overrideClip ); + } + + CONDITIONAL UNITY_EDITOR + CSRAW internal delegate void OnOverrideControllerDirtyCallback(); + + CONDITIONAL UNITY_EDITOR + CSRAW internal OnOverrideControllerDirtyCallback OnOverrideControllerDirty; + + CONDITIONAL UNITY_EDITOR + CSRAW internal static void OnInvalidateOverrideController(AnimatorOverrideController controller) + { + if(controller.OnOverrideControllerDirty != null) + controller.OnOverrideControllerDirty(); + } + + CSRAW public AnimationClipPair[] clips + { + get + { + AnimationClip[] originalAnimationClips = GetOriginalClips(); + + AnimationClipPair[] clipPair = new AnimationClipPair[originalAnimationClips.Length]; + for(int i=0;i<originalAnimationClips.Length;i++) + { + clipPair[i] = new AnimationClipPair(); + clipPair[i].originalClip = originalAnimationClips[i]; + clipPair[i].overrideClip = Internal_GetClip(originalAnimationClips[i], false); + } + + return clipPair; + } + set + { + for(int i=0;i<value.Length;i++) + Internal_SetClip(value[i].originalClip, value[i].overrideClip); + } + } + + CUSTOM private AnimationClip[] GetOriginalClips() + { + return CreateScriptingArrayFromUnityObjects(self->GetOriginalClips(), ClassID(AnimationClip)); + } + + CUSTOM private AnimationClip[] GetOverrideClips() + { + return CreateScriptingArrayFromUnityObjects(self->GetOverrideClips(), ClassID(AnimationClip)); + } + + CONDITIONAL UNITY_EDITOR + CUSTOM public void PerformOverrideClipListCleanup() + { + return self->PerformOverrideClipListCleanup(); + } +END + +CSRAW } diff --git a/Runtime/Animation/ScriptBindings/Avatar.txt b/Runtime/Animation/ScriptBindings/Avatar.txt new file mode 100644 index 0000000..52b0e93 --- /dev/null +++ b/Runtime/Animation/ScriptBindings/Avatar.txt @@ -0,0 +1,340 @@ +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/Mono/MonoBehaviour.h" +#include "Runtime/Mono/MonoScript.h" +#include "Runtime/Graphics/Transform.h" +#include "Runtime/Animation/Avatar.h" +#include "Runtime/mecanim/human/human.h" + +using namespace Unity; + +CSRAW + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; + +namespace UnityEngine +{ + +ENUM internal BodyDoF + + SpineFrontBack = 0, + SpineLeftRight, + SpineRollLeftRight, + ChestFrontBack, + ChestLeftRight, + ChestRollLeftRight, + LastBodyDoF +END + +ENUM internal HeadDoF + NeckFrontBack = 0, + NeckLeftRight, + NeckRollLeftRight, + HeadFrontBack, + HeadLeftRight, + HeadRollLeftRight, + LeftEyeDownUp, + LeftEyeInOut, + RightEyeDownUp, + RightEyeInOut, + JawDownUp, + JawLeftRight, + LastHeadDoF +END + +ENUM internal LegDoF + UpperLegFrontBack = 0, + UpperLegInOut, + UpperLegRollInOut, + LegCloseOpen, + LegRollInOut, + FootCloseOpen, + FootInOut, + ToesUpDown, + LastLegDoF +END + +ENUM internal ArmDoF + ShoulderDownUp = 0, + ShoulderFrontBack, + ArmDownUp, + ArmFrontBack, + ArmRollInOut, + ForeArmCloseOpen, + ForeArmRollInOut, + HandDownUp, + HandInOut, + LastArmDoF +END + +ENUM internal FingerDoF + ProximalDownUp = 0, + ProximalInOut, + IntermediateCloseOpen, + DistalCloseOpen, + LastFingerDoF +END + +ENUM internal DoF + BodyDoFStart = 0, + HeadDoFStart = (int)BodyDoFStart + (int)BodyDoF.LastBodyDoF, + LeftLegDoFStart = (int)HeadDoFStart + (int)HeadDoF.LastHeadDoF, + RightLegDoFStart = (int)LeftLegDoFStart + (int)LegDoF.LastLegDoF, + LeftArmDoFStart = (int)RightLegDoFStart + (int)LegDoF.LastLegDoF, + RightArmDoFStart = (int)LeftArmDoFStart + (int)ArmDoF.LastArmDoF, + + LeftThumbDoFStart = (int)RightArmDoFStart + (int)ArmDoF.LastArmDoF, + LeftIndexDoFStart = (int)LeftThumbDoFStart + (int)FingerDoF.LastFingerDoF, + LeftMiddleDoFStart = (int)LeftIndexDoFStart + (int)FingerDoF.LastFingerDoF, + + LeftRingDoFStart = (int)LeftMiddleDoFStart + (int)FingerDoF.LastFingerDoF, + LeftLittleDoFStart = (int)LeftRingDoFStart + (int)FingerDoF.LastFingerDoF, + + RightThumbDoFStart = (int)LeftLittleDoFStart + (int)FingerDoF.LastFingerDoF, + RightIndexDoFStart = (int)RightThumbDoFStart + (int)FingerDoF.LastFingerDoF, + RightMiddleDoFStart = (int)RightIndexDoFStart + (int)FingerDoF.LastFingerDoF, + RightRingDoFStart = (int)RightMiddleDoFStart + (int)FingerDoF.LastFingerDoF, + RightLittleDoFStart = (int)RightRingDoFStart + (int)FingerDoF.LastFingerDoF, + + LastDoF = (int)RightLittleDoFStart + (int)FingerDoF.LastFingerDoF +END + +// Human Body Bones +ENUM HumanBodyBones + // This is the Hips bone + Hips = 0, + + // This is the Left Upper Leg bone + LeftUpperLeg = 1, + + // This is the Right Upper Leg bone + RightUpperLeg = 2, + + // This is the Left Knee bone + LeftLowerLeg = 3, + + // This is the Right Knee bone + RightLowerLeg = 4, + + // This is the Left Ankle bone + LeftFoot = 5, + + // This is the Right Ankle bone + RightFoot = 6, + + // This is the first Spine bone + Spine = 7, + + // This is the Chest bone + Chest = 8, + + // This is the Neck bone + Neck = 9, + + // This is the Head bone + Head = 10, + + // This is the Left Shoulder bone + LeftShoulder = 11, + + // This is the Right Shoulder bone + RightShoulder = 12, + + // This is the Left Upper Arm bone + LeftUpperArm = 13, + + // This is the Right Upper Arm bone + RightUpperArm = 14, + + // This is the Left Elbow bone + LeftLowerArm = 15, + + // This is the Right Elbow bone + RightLowerArm = 16, + + // This is the Left Wrist bone + LeftHand = 17, + + // This is the Right Wrist bone + RightHand = 18, + + // This is the Left Toes bone + LeftToes = 19, + + // This is the Right Toes bone + RightToes = 20, + + // This is the Left Eye bone + LeftEye = 21, + + // This is the Right Eye bone + RightEye = 22, + + // This is the Jaw bone + Jaw = 23, + + // This is the Last bone index delimiter + LastBone = 24 +END + +ENUM internal HumanFingerBones + ThumbProximal = 0, + ThumbIntermediate, + ThumbDistal, + + IndexProximal, + IndexIntermediate, + IndexDistal, + + MiddleProximal, + MiddleIntermediate, + MiddleDistal, + + RingProximal, + RingIntermediate, + RingDistal, + + LittleProximal, + LittleIntermediate, + LittleDistal, + LastBone +END + +ENUM internal HumanBodyPart + BodyStart = 0, + LeftFingerStart = (int)BodyStart + (int)HumanBodyBones.LastBone, + RightFingerStart = (int)LeftFingerStart + (int)HumanFingerBones.LastBone +END + +ENUM internal HumanParameter + UpperArmTwist = 0, + LowerArmTwist, + UpperLegTwist, + LowerLegTwist, + ArmStretch, + LegStretch, + FeetSpacing +END + + +// Avatar definition +CLASS Avatar : Object + // Return true if this avatar is a valid mecanim avatar. It can be a generic avatar or a human avatar. + CUSTOM_PROP bool isValid { + return self->IsValid(); + } + + // Return true if this avatar is a valid human avatar. + CUSTOM_PROP bool isHuman + { + return self->IsValid() && self->GetAsset()->isHuman(); + } + + CUSTOM internal void SetMuscleMinMax(int muscleId, float min, float max) + { + self->SetMuscleMinMax(muscleId, min, max); + } + + CUSTOM internal void SetParameter(int parameterId, float value) + { + self->SetParameter(parameterId, value); + } + + CUSTOM internal float GetAxisLength(int humanId) + { + return self->GetAxisLength(humanId); + } + + CUSTOM internal Quaternion GetPreRotation(int humanId) + { + return self->GetPreRotation(humanId); + } + + CUSTOM internal Quaternion GetPostRotation(int humanId) + { + return self->GetPostRotation(humanId); + } + + CUSTOM internal Quaternion GetZYPostQ(int humanId, Quaternion parentQ, Quaternion q) { + return self->GetZYPostQ(humanId, parentQ, q); + } + + CUSTOM internal Quaternion GetZYRoll(int humanId, Vector3 uvw) { + return self->GetZYRoll(humanId, uvw); + } + + CUSTOM internal Vector3 GetLimitSign(int humanId){ + return self->GetLimitSign(humanId); + } + +END + +// Humanoid definition +CLASS HumanTrait : Object + + // Number of muscles + CUSTOM_PROP static int MuscleCount + { + return HumanTrait::MuscleCount; + } + + // Muscle's name + CUSTOM_PROP static string[] MuscleName + { + return Scripting::StringVectorToMono( HumanTrait::GetMuscleName() ); + } + + // Number of bones + CUSTOM_PROP static int BoneCount + { + return HumanTrait::BoneCount; + } + + // Bone's name + CUSTOM_PROP static string[] BoneName + { + return Scripting::StringVectorToMono( HumanTrait::GetBoneName() ); + } + + // Return muscle index linked to bone i, dofIndex allow you to choose between X, Y and Z muscle's axis + CUSTOM static int MuscleFromBone(int i, int dofIndex){ + return HumanTrait::MuscleFromBone(i, dofIndex); + } + + // Return bone index linked to muscle i + CUSTOM static int BoneFromMuscle(int i){ + return HumanTrait::BoneFromMuscle(i); + } + + // Return true if bone i is a required bone. + CUSTOM static bool RequiredBone(int i){ + return HumanTrait::RequiredBone(i); + } + + // Number of required bones. + CUSTOM_PROP static int RequiredBoneCount + { + return HumanTrait::RequiredBoneCount(); + } + + CUSTOM internal static bool HasCollider(Avatar avatar, int i){ + return HumanTrait::HasCollider(*avatar, i); + } + + // Return default minimum values for muscle. + CUSTOM static float GetMuscleDefaultMin(int i){ + return HumanTrait::GetMuscleDefaultMin(i); + } + + // Return default maximum values for muscle. + CUSTOM static float GetMuscleDefaultMax(int i){ + return HumanTrait::GetMuscleDefaultMax(i); + } + +END + +CSRAW } diff --git a/Runtime/Animation/ScriptBindings/AvatarBuilderBindings.txt b/Runtime/Animation/ScriptBindings/AvatarBuilderBindings.txt new file mode 100644 index 0000000..641af63 --- /dev/null +++ b/Runtime/Animation/ScriptBindings/AvatarBuilderBindings.txt @@ -0,0 +1,250 @@ +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/Mono/MonoBehaviour.h" +#include "Runtime/Mono/MonoScript.h" + +#include "Runtime/Scripting/ScriptingManager.h" +#include "Runtime/Scripting/ScriptingUtility.h" +#include "Runtime/Scripting/ScriptingExportUtility.h" + +#include "Runtime/Graphics/Transform.h" +#include "Runtime/Animation/AvatarBuilder.h" +#include "Runtime/Animation/Avatar.h" +#include "Runtime/Scripting/Scripting.h" + +using namespace Unity; + +CSRAW + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; + +namespace UnityEngine +{ + +STRUCT SkeletonBone + CSRAW public string name; + + CSRAW public Vector3 position; + CSRAW public Quaternion rotation; + CSRAW public Vector3 scale; + CSRAW public int transformModified; +END + +C++RAW + +struct MonoSkeletonBone { + ScriptingStringPtr name; + Vector3f position; + Quaternionf rotation; + Vector3f scale; + int transformModified; +}; + +void SkeletonBoneToMono (const SkeletonBone &src, MonoSkeletonBone &dest) { + dest.name = scripting_string_new(src.m_Name); + dest.position = src.m_Position; + dest.rotation = src.m_Rotation; + dest.scale = src.m_Scale; + dest.transformModified = src.m_TransformModified ? 1 : 0; +} + +void SkeletonBoneFromMono (const MonoSkeletonBone &src, SkeletonBone &dest) { + dest.m_Name = scripting_cpp_string_for(src.name); + dest.m_Position = src.position; + dest.m_Rotation = src.rotation; + dest.m_Scale = src.scale; + dest.m_TransformModified = src.transformModified != 0; +} + +STRUCT HumanLimit + CSRAW + + Vector3 m_Min; + Vector3 m_Max; + Vector3 m_Center; + float m_AxisLength; + int m_UseDefaultValues; + + public bool useDefaultValues { get { return m_UseDefaultValues != 0; } set { m_UseDefaultValues = value ? 1 : 0; } } + public Vector3 min { get { return m_Min; } set { m_Min = value; } } + public Vector3 max { get { return m_Max; } set { m_Max = value; } } + public Vector3 center { get { return m_Center; } set { m_Center = value; } } + public float axisLength { get { return m_AxisLength; } set { m_AxisLength = value; } } +END + +C++RAW + +struct MonoHumanLimit { + + Vector3f m_Min; + Vector3f m_Max; + Vector3f m_Center; + float m_AxisLength; + int m_UseDefaultValues; +}; + +void HumanLimitToMono (const SkeletonBoneLimit &src, MonoHumanLimit &dest) { + dest.m_UseDefaultValues = src.m_Modified ? 0 : 1; + dest.m_Min = src.m_Min; + dest.m_Max = src.m_Max; + dest.m_Center = src.m_Value; + dest.m_AxisLength = src.m_Length; +} + +void HumanLimitFromMono (const MonoHumanLimit &src, SkeletonBoneLimit &dest) { + dest.m_Modified = src.m_UseDefaultValues == 1 ? false : true; + dest.m_Min = src.m_Min; + dest.m_Max = src.m_Max; + dest.m_Value = src.m_Center; + dest.m_Length = src.m_AxisLength; +} + +STRUCT HumanBone + CSRAW + string m_BoneName; + string m_HumanName; + public HumanLimit limit; + + public string boneName { get { return m_BoneName; } set { m_BoneName = value; } } + public string humanName { get { return m_HumanName; } set { m_HumanName = value; } } +END + +C++RAW + +struct MonoHumanBone { + ScriptingStringPtr m_BoneName; + ScriptingStringPtr m_HumanName; + MonoHumanLimit m_Limit; +}; + +void HumanBoneToMono (const HumanBone &src, MonoHumanBone &dest) +{ + dest.m_BoneName = scripting_string_new(src.m_BoneName); + dest.m_HumanName = scripting_string_new(src.m_HumanName); + HumanLimitToMono(src.m_Limit, dest.m_Limit); +} + +void HumanBoneFromMono (const MonoHumanBone &src, HumanBone &dest) +{ + dest.m_BoneName = scripting_cpp_string_for(src.m_BoneName); + dest.m_HumanName = scripting_cpp_string_for(src.m_HumanName); + HumanLimitFromMono(src.m_Limit, dest.m_Limit); +} + +STRUCT HumanDescription + CSRAW + public HumanBone[] human; + public SkeletonBone[] skeleton; + + float m_ArmTwist; + float m_ForeArmTwist; + float m_UpperLegTwist; + float m_LegTwist; + float m_ArmStretch; + float m_LegStretch; + float m_FeetSpacing; + + public float upperArmTwist { get { return m_ArmTwist; } set { m_ArmTwist = value;} } + public float lowerArmTwist { get { return m_ForeArmTwist; } set { m_ForeArmTwist = value;} } + public float upperLegTwist { get { return m_UpperLegTwist; } set { m_UpperLegTwist = value;} } + public float lowerLegTwist { get { return m_LegTwist; } set { m_LegTwist = value;} } + public float armStretch { get { return m_ArmStretch; } set { m_ArmStretch = value;} } + public float legStretch { get { return m_LegStretch; } set { m_LegStretch = value;} } + public float feetSpacing { get { return m_FeetSpacing; } set { m_FeetSpacing = value;} } +END + +C++RAW + +struct MonoHumanDescription { + ScriptingArrayPtr m_Human; + ScriptingArrayPtr m_Skeleton; + + float m_ArmTwist; + float m_ForeArmTwist; + float m_UpperLegTwist; + float m_LegTwist; + float m_ArmStretch; + float m_LegStretch; + float m_FeetSpacing; +}; + + +void HumanDescriptionToMono (const HumanDescription &src, MonoHumanDescription &dest) +{ + if (src.m_Skeleton.size() <= 0) + dest.m_Skeleton = CreateEmptyStructArray(MONO_COMMON.skeletonBone); + else + dest.m_Skeleton = CreateScriptingArray(&src.m_Skeleton[0], src.m_Skeleton.size(), MONO_COMMON.skeletonBone); + + if (src.m_Human.size() <= 0) + dest.m_Human = CreateEmptyStructArray(MONO_COMMON.humanBone); + else + dest.m_Human = CreateScriptingArray(&src.m_Human[0], src.m_Human.size(), MONO_COMMON.humanBone); + + dest.m_ArmTwist = src.m_ArmTwist; + dest.m_ForeArmTwist = src.m_ForeArmTwist; + + dest.m_UpperLegTwist = src.m_UpperLegTwist; + dest.m_LegTwist = src.m_LegTwist; + dest.m_ArmStretch = src.m_ArmStretch; + dest.m_LegStretch = src.m_LegStretch; + dest.m_FeetSpacing = src.m_FeetSpacing; +} + +void HumanDescriptionFromMono (const MonoHumanDescription &src, HumanDescription &dest) +{ + ScriptingStructArrayToVector<SkeletonBone, MonoSkeletonBone>(src.m_Skeleton, dest.m_Skeleton, SkeletonBoneFromMono); + ScriptingStructArrayToVector<HumanBone, MonoHumanBone>(src.m_Human, dest.m_Human, HumanBoneFromMono); + + dest.m_ArmTwist = src.m_ArmTwist; + dest.m_ForeArmTwist = src.m_ForeArmTwist; + + dest.m_UpperLegTwist = src.m_UpperLegTwist; + dest.m_LegTwist = src.m_LegTwist; + dest.m_ArmStretch = src.m_ArmStretch; + dest.m_LegStretch = src.m_LegStretch; + dest.m_FeetSpacing = src.m_FeetSpacing; +} + +CLASS AvatarBuilder + CUSTOM static Avatar BuildHumanAvatar(GameObject go, HumanDescription monoHumanDescription) { + Avatar* avatar = NEW_OBJECT(Avatar); + avatar->Reset(); + + HumanDescription humanDescription; + HumanDescriptionFromMono(monoHumanDescription, humanDescription); + + AvatarBuilder::Options options; + options.avatarType = kHumanoid; + options.useMask = true; + + std::string error = AvatarBuilder::BuildAvatar(*avatar, *go, false, humanDescription, options); + if(!error.empty()) + ErrorString(error); + + avatar->AwakeFromLoad(kInstantiateOrCreateFromCodeAwakeFromLoad); + + return Scripting::ScriptingWrapperFor(avatar); + } + + CUSTOM static Avatar BuildGenericAvatar(GameObject go, string rootMotionTransformName) { + Avatar* avatar = NEW_OBJECT(Avatar); + avatar->Reset(); + + HumanDescription humanDescription; + humanDescription.m_RootMotionBoneName = rootMotionTransformName.AsUTF8().c_str(); + std::string error = AvatarBuilder::BuildAvatar(*avatar, *go, false, humanDescription); + if(!error.empty()) + ErrorString(error); + + avatar->AwakeFromLoad(kInstantiateOrCreateFromCodeAwakeFromLoad); + + return Scripting::ScriptingWrapperFor(avatar); + } +END + +CSRAW } diff --git a/Runtime/Animation/ScriptBindings/RuntimeAnimatorControllerBindings.txt b/Runtime/Animation/ScriptBindings/RuntimeAnimatorControllerBindings.txt new file mode 100644 index 0000000..98ddbfd --- /dev/null +++ b/Runtime/Animation/ScriptBindings/RuntimeAnimatorControllerBindings.txt @@ -0,0 +1,26 @@ +C++RAW +#include "UnityPrefix.h" +#include "Runtime/Mono/MonoManager.h" + +CSRAW +using System; +using UnityEngine; +using Object=UnityEngine.Object; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; + +namespace UnityEngine +{ + + +/// Runtime representation of the AnimatorController +/// Used to change at runtime the AnimatorController of an Animator +NONSEALED_CLASS public RuntimeAnimatorController : Object +END + + + + + +CSRAW } |