This commit is contained in:
2026-05-30 09:16:35 +07:00
parent 2f87ce19a7
commit 1c0ee6efb7
4001 changed files with 3363438 additions and 1738 deletions

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c468d3c4271625747837f4a3db1aa488
folderAsset: yes
timeCreated: 1544056112
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,121 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Invector.vEventSystems
{
[CustomEditor(typeof(vAnimatorEvent))]
public class vAnimatorEventEditor : UnityEditor.Editor
{
public vAnimatorEvent animatorEvent;
public GUISkin skin;
public GUIStyle timeLineStyle;
private void OnEnable()
{
animatorEvent = target as vAnimatorEvent;
}
public override void OnInspectorGUI()
{
if (!skin) skin = Resources.Load("vSkin") as GUISkin;
if (timeLineStyle == null) timeLineStyle = new GUIStyle(EditorStyles.inspectorFullWidthMargins);
serializedObject.Update();
EditorGUILayout.BeginVertical(skin.box);
EditorGUILayout.HelpBox("<b>Make sure to use a lower value than the Exit Time of this State.</b>", MessageType.Warning);
var events = serializedObject.FindProperty("eventTriggers");
if (GUILayout.Button("Add Event", skin.button, GUILayout.ExpandWidth(true)))
{
events.arraySize++;
events.GetArrayElementAtIndex(events.arraySize - 1).FindPropertyRelative("eventName").stringValue = "New Event";
}
for (int i = 0; i < events.arraySize; i++)
{
if (!DraEvent(events, i)) break;
}
EditorGUILayout.EndVertical();
serializedObject.ApplyModifiedProperties();
}
public bool DraEvent(SerializedProperty list, int index)
{
EditorGUILayout.BeginVertical(skin.box, GUILayout.ExpandWidth(true));
{
var eventName = list.GetArrayElementAtIndex(index).FindPropertyRelative("eventName");
var eventTriggerType = list.GetArrayElementAtIndex(index).FindPropertyRelative("eventTriggerType");
var normalizedTime = list.GetArrayElementAtIndex(index).FindPropertyRelative("normalizedTime");
var width = 30;
EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
{
eventName.stringValue = EditorGUILayout.TextField(GUIContent.none, eventName.stringValue, GUILayout.ExpandWidth(true));
if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(width)))
{
list.DeleteArrayElementAtIndex(index);
return false;
}
}
EditorGUILayout.EndHorizontal();
eventTriggerType.enumValueIndex = (int)(vAnimatorEvent.vAnimatorEventTrigger.vAnimatorEventTriggerType)EditorGUILayout.EnumPopup("Type",(vAnimatorEvent.vAnimatorEventTrigger.vAnimatorEventTriggerType)eventTriggerType.enumValueIndex);
var valueSelected = (vAnimatorEvent.vAnimatorEventTrigger.vAnimatorEventTriggerType)eventTriggerType.enumValueIndex;
switch (valueSelected)
{
case vAnimatorEvent.vAnimatorEventTrigger.vAnimatorEventTriggerType.NormalizedTime:
Rect rect = GUILayoutUtility.GetLastRect();
GUILayout.Space(20);
var color = GUI.color;
rect.y += 20;
rect.width -= width;
GUI.Box(rect, "", skin.GetStyle("AnimatorEventBar"));
int number = 0;
for (int i = 0; i < 101; i++)
{
timeLineStyle.alignment = TextAnchor.UpperCenter;
var rectAdjust = new Rect(rect.position.x + ((rect.width - 5) * (0.01f * i)), rect.position.y, 2.5f, 15);
var par = i % 10f;
timeLineStyle.fontSize = par == 0 ? 15 : par == 5 ? (rect.width * 0.01f > 3f) ? 10 : 5 : (rect.width * 0.01f > 4f) ? 5 : 1;
rectAdjust.y += par == 0 ? -2 : par == 5 ? (rect.width * 0.01f > 3f) ? -1 : 0 : 0;
timeLineStyle.normal.textColor = Color.grey;
GUI.Box(rectAdjust, "|", timeLineStyle);
rectAdjust.y = rect.position.y + 5;
if (par == 0)
{
timeLineStyle.normal.textColor = Color.black;
timeLineStyle.alignment = TextAnchor.MiddleLeft;
timeLineStyle.fontSize = Mathf.Clamp((int)(rect.width * 0.02f), 6, 10);
rectAdjust.width = 25;
rectAdjust.height = 15;
rectAdjust.x += number < 10 ? -1 : -7;
GUI.Label(rectAdjust, (number * 0.1f).ToString(), timeLineStyle);
number++;
}
}
GUI.color = color;
rect.x -= 5;
rect.width += 10;
normalizedTime.floatValue = GUI.HorizontalSlider(rect, normalizedTime.floatValue, 0f, 1f, GUIStyle.none, skin.GetStyle("AnimatorEventThumb"));
rect.x = rect.x + rect.width - 3;
rect.width = width - 2;
normalizedTime.floatValue = EditorGUI.FloatField(rect, (float)System.Math.Round(normalizedTime.floatValue, 2));
break;
}
}
EditorGUILayout.EndVertical();
return true;
}
protected void DrawNormalizeEventStyle()
{
}
public override bool UseDefaultMargins()
{
return false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c42db7cd67599b24c8dcc3c52e92fc83
timeCreated: 1542813635
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,85 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Invector.vEventSystems
{
[CustomEditor(typeof(vAnimatorTagAdvanced))]
public class vAnimatorTagAdvancedEditor : vAnimatorTagEditor
{
public override bool DrawTag(SerializedProperty list, int index)
{
GUILayout.BeginHorizontal(skin.box);
GUILayout.BeginVertical();
var tagToDraw = list.GetArrayElementAtIndex(index);
var tagName = tagToDraw.FindPropertyRelative("tagName");
var enumTagType = tagToDraw.FindPropertyRelative("tagType");
var normalizedTime = tagToDraw.FindPropertyRelative("normalizedTime");
DrawTagField(tagName);
EditorGUILayout.PropertyField(enumTagType, GUILayout.Height(15));
Vector2 minMax = normalizedTime.vector2Value;
var _enumTagType = (vAnimatorTagAdvanced.vAnimatorEventTriggerType)(enumTagType.enumValueIndex);
switch(_enumTagType)
{
case vAnimatorTagAdvanced.vAnimatorEventTriggerType.AllByNormalizedTime:
GUILayout.Label("Enter in " + minMax.x.ToString("0.00") + " - Exit in "+minMax.y.ToString("0.00"));
GUILayout.BeginHorizontal();
minMax.x = EditorGUILayout.FloatField(minMax.x,GUILayout.MaxWidth(40));
EditorGUILayout.MinMaxSlider(ref minMax.x, ref minMax.y, 0, 1f);
minMax.y = EditorGUILayout.FloatField(minMax.y, GUILayout.MaxWidth(40));
GUILayout.EndHorizontal();
if(GUI.changed)
{
minMax.x =(float) System.Math.Round(minMax.x, 2);
minMax.y = (float)System.Math.Round(minMax.y, 2);
normalizedTime.vector2Value = minMax;
}
break;
case vAnimatorTagAdvanced.vAnimatorEventTriggerType.EnterStateExitByNormalized:
GUILayout.Label("Exit in " + minMax.y.ToString("0.00"));
minMax.y = EditorGUILayout.Slider(minMax.y, 0, 1f);
if (GUI.changed)
{
minMax.x = 0;
minMax.y = (float)System.Math.Round(minMax.y, 2);
normalizedTime.vector2Value = minMax;
}
break;
case vAnimatorTagAdvanced.vAnimatorEventTriggerType.EnterByNormalizedExitState:
GUILayout.Label("Enter in " + minMax.x.ToString("0.00"));
minMax.x = EditorGUILayout.Slider(minMax.x, 0, 1f);
if (GUI.changed)
{
minMax.x = (float)System.Math.Round(minMax.x, 2);
minMax.y = 0;
normalizedTime.vector2Value = minMax;
}
break;
}
GUILayout.EndVertical();
if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
{
list.DeleteArrayElementAtIndex(index);
return false;
}
GUILayout.EndHorizontal();
return true;
}
protected override void AddTag(SerializedProperty list, string tag)
{
list.arraySize++;
var p = list.GetArrayElementAtIndex(list.arraySize - 1);
p.FindPropertyRelative("tagName").stringValue = tag;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 040e47635276c35468fdb6a920366ef1
timeCreated: 1542821872
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,116 @@
using UnityEditor;
using UnityEngine;
namespace Invector.vEventSystems
{
[CustomEditor(typeof(vAnimatorTag), true)]
public class vAnimatorTagEditor : UnityEditor.Editor
{
public GUISkin skin;
Rect buttonRect;
protected virtual string[] propertiesExcluded => new string[] { "tags", "stateInfos" };
public override void OnInspectorGUI()
{
if (!skin) skin = Resources.Load("vSkin") as GUISkin;
serializedObject.Update();
GUILayout.BeginVertical(skin.box);
DrawPropertiesExcluding(serializedObject, propertiesExcluded);
var tags = serializedObject.FindProperty("tags");
if (GUILayout.Button("Add New Tag", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
PopupWindow.Show(buttonRect, new TagListPopup((string value) => { Undo.RecordObject(serializedObject.targetObject, "Add Tag"); AddTag(tags, value); serializedObject.ApplyModifiedProperties(); }));
}
if (Event.current.type == EventType.Repaint) buttonRect = GUILayoutUtility.GetLastRect();
for (int i = 0; i < tags.arraySize; i++)
{
if (!DrawTag(tags, i)) break;
}
GUILayout.EndVertical();
serializedObject.ApplyModifiedProperties();
}
protected virtual void AddTag(SerializedProperty list, string tag)
{
list.arraySize++;
list.GetArrayElementAtIndex(list.arraySize - 1).stringValue = tag;
}
public virtual bool DrawTag(SerializedProperty list, int index)
{
GUILayout.BeginHorizontal(skin.box);
GUILayout.BeginVertical();
DrawTagField(list.GetArrayElementAtIndex(index));
GUILayout.Space(-10);
GUILayout.EndVertical();
if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
{
list.DeleteArrayElementAtIndex(index);
return false;
}
GUILayout.EndHorizontal();
return true;
}
public virtual void DrawTagField(SerializedProperty tag)
{
var info = EditorGUIUtility.IconContent("_Help");
info.tooltip = vAnimatorTagEditorHelper.GetTooltip(tag.stringValue);
bool isDefault = vAnimatorTagEditorHelper.IsDefaultTag(tag.stringValue);
GUILayout.BeginHorizontal();
GUILayout.Label(info);
Color color = GUI.contentColor;
GUI.contentColor = isDefault ? Color.green : color;
tag.stringValue = EditorGUILayout.TextField(tag.stringValue, isDefault ? vAnimatorTagEditorHelper.DefaultTagStyle : vAnimatorTagEditorHelper.CustomTagStyle);
GUI.contentColor = color;
GUILayout.EndHorizontal();
}
public class TagListPopup : PopupWindowContent
{
Vector2 scrollview;
System.Action<string> onSelect;
GUIStyle style;
public TagListPopup(System.Action<string> onSelect)
{
this.onSelect = onSelect;
style = new GUIStyle(GUI.skin.box);
style.fontStyle = FontStyle.Italic;
}
public override Vector2 GetWindowSize()
{
float height = GUI.skin.box.CalcHeight(new GUIContent("TAG"), 200) + EditorGUIUtility.standardVerticalSpacing * 2;
float minHeight = height * 10;
height *= vAnimatorTagEditorHelper.TAGS.Count + 1;
return new Vector2(200, Mathf.Min(height, minHeight) + EditorGUIUtility.standardVerticalSpacing * 4);
}
public override void OnGUI(Rect rect)
{
GUILayout.BeginArea(rect);
scrollview = GUILayout.BeginScrollView(scrollview);
if (GUILayout.Button(new GUIContent("Add Custom Tag...", "Create a New Custom Tag"), style, GUILayout.ExpandWidth(true)))
{
onSelect?.Invoke("");
editorWindow.Close();
}
foreach (string key in vAnimatorTagEditorHelper.TAGS.Keys)
{
string tooltip = vAnimatorTagEditorHelper.GetTooltip(key);
if (GUILayout.Button(new GUIContent(key, tooltip), "box", GUILayout.ExpandWidth(true)))
{
onSelect?.Invoke(key);
editorWindow.Close();
}
}
GUILayout.EndScrollView();
GUILayout.EndArea();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ccd2dec28aae60c4cb7bcec0a0d4e5a9
timeCreated: 1542821872
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Reflection;
namespace Invector
{
[InitializeOnLoad]
public static class vAnimatorTagEditorHelper
{
private static GUIStyle _customTagStyle;
private static GUIStyle _defaultTagStyle;
static vAnimatorTagEditorHelper()
{
TAGS = new Dictionary<string, TooltipAttribute>();
FieldInfo[] fields = typeof(vAnimatorTags).GetFields(BindingFlags.Public | BindingFlags.Static);
for (int i = 0; i < fields.Length; i++)
{
if(fields[i].FieldType.Equals(typeof(string)))
{
string fieldvalue = (string)fields[i].GetValue(null);
if(!TAGS.ContainsKey(fieldvalue))
{
TAGS.Add(fieldvalue, fields[i].GetCustomAttribute<TooltipAttribute>());
}
}
}
}
public static string GetTooltip(string tag)
{
if (TAGS!=null && TAGS.ContainsKey(tag))
{
TooltipAttribute tooltipAttribute = TAGS[tag];
string tooltip = tooltipAttribute!=null ? tooltipAttribute.tooltip : "";
return tooltip;
}
return "You can use custom tags with the method 'IsAnimatorTag(customTag)' to create special conditions in your code while this animation is being played";
}
public static Dictionary<string, TooltipAttribute> TAGS
{
get;
private set;
}
public static GUIStyle CustomTagStyle
{
get
{
if (_customTagStyle == null)
{
_customTagStyle = new GUIStyle(EditorStyles.textField);
_customTagStyle.fontStyle = FontStyle.Italic;
_customTagStyle.fontSize = EditorStyles.textField.fontSize - 1;
}
return _customTagStyle;
}
}
public static GUIStyle DefaultTagStyle
{
get
{
if(_defaultTagStyle==null)
{
_defaultTagStyle = new GUIStyle(EditorStyles.textField);
_defaultTagStyle.fontStyle = FontStyle.Bold;
}
return _defaultTagStyle;
}
}
public static bool IsDefaultTag(string tag)
{
return TAGS != null && TAGS.ContainsKey(tag);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 81c54afc56909af44b2fb77cd6059f43
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,166 @@
using System.Collections.Generic;
using UnityEngine;
namespace Invector.vEventSystems
{
public class vAnimatorEvent : StateMachineBehaviour
{
[System.Serializable]
public class vAnimatorEventTrigger
{
public enum vAnimatorEventTriggerType
{
NormalizedTime, EnterState, ExitState
}
public string eventName = "New Event";
public vAnimatorEventTriggerType eventTriggerType = vAnimatorEventTriggerType.NormalizedTime;
public float normalizedTime;
private int loopCount;
public event OnTriggerEvent onTriggerEvent;
public void UpdateEventTrigger(float normalizedTime)
{
var normalizedTimeClamped = Mathf.Clamp(normalizedTime, 0, loopCount + 1f);
if (normalizedTimeClamped >= loopCount + this.normalizedTime)
{
if (onTriggerEvent != null)
{
onTriggerEvent(eventName);
}
loopCount++;
}
}
public void TriggerEvent()
{
if (onTriggerEvent != null)
{
onTriggerEvent(eventName);
}
}
public void Init()
{
loopCount = 0;
}
}
public List<vAnimatorEventTrigger> eventTriggers;
public delegate void OnTriggerEvent(string eventName);
protected bool hasNormalizedEvents;
public bool HasEvent(string eventName)
{
return eventTriggers.Exists(e => e.eventName.Equals(eventName));
}
public void RegisterEvents(string eventName, OnTriggerEvent onTriggerEvent)
{
var _events = eventTriggers.FindAll(e => e.eventName.Equals(eventName));
for (int i = 0; i < _events.Count; i++)
{
_events[i].onTriggerEvent -= onTriggerEvent;
_events[i].onTriggerEvent += onTriggerEvent;
}
}
public void RemoveEvents(string eventName, OnTriggerEvent onTriggerEvent)
{
var _events = eventTriggers.FindAll(e => e.eventName.Equals(eventName));
for (int i = 0; i < _events.Count; i++)
{
_events[i].onTriggerEvent -= onTriggerEvent;
}
}
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
for (int i = 0; i < eventTriggers.Count; i++)
{
if (eventTriggers[i].eventTriggerType == vAnimatorEventTrigger.vAnimatorEventTriggerType.EnterState)
{
eventTriggers[i].TriggerEvent();
}
else if (eventTriggers[i].eventTriggerType == vAnimatorEventTrigger.vAnimatorEventTriggerType.NormalizedTime)
{
hasNormalizedEvents = true;
eventTriggers[i].Init();
eventTriggers[i].UpdateEventTrigger(stateInfo.normalizedTime);
}
}
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (!stateInfo.loop && stateInfo.normalizedTime > 1 || !hasNormalizedEvents)
{
return;
}
for (int i = 0; i < eventTriggers.Count; i++)
{
if (eventTriggers[i].eventTriggerType == vAnimatorEventTrigger.vAnimatorEventTriggerType.NormalizedTime)
{
eventTriggers[i].UpdateEventTrigger(stateInfo.normalizedTime);
}
}
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
for (int i = 0; i < eventTriggers.Count; i++)
{
if (eventTriggers[i].eventTriggerType == vAnimatorEventTrigger.vAnimatorEventTriggerType.ExitState)
{
eventTriggers[i].TriggerEvent();
}
}
}
}
}
namespace Invector
{
public static class vAnimatorEventExtencion
{
/// <summary>
/// Add event to the <seealso cref="vAnimatorEvent"/> in animator
/// </summary>
/// <param name="animator">target animator</param>
/// <param name="eventName">event name</param>
/// <param name="onTriggerEventAction">action to add to <seealso cref="vEventSystems.vAnimatorEvent"/></param>
public static void RegisterEvent(this Animator animator, string eventName, vEventSystems.vAnimatorEvent.OnTriggerEvent onTriggerEventAction)
{
if (animator)
{
var behaviours = animator.GetBehaviours<vEventSystems.vAnimatorEvent>();
for (int i = 0; i < behaviours.Length; i++)
{
if (behaviours[i].HasEvent(eventName))
{
behaviours[i].RegisterEvents(eventName, onTriggerEventAction);
}
}
}
}
/// <summary>
/// Remove event of the <seealso cref="vEventSystems.vAnimatorEvent"/> in animator
/// </summary>
/// <param name="animator">target animator</param>
/// <param name="eventName">event name</param>
/// <param name="onTriggerEventAction">action to remove of the <seealso cref="vAnimatorEvent"/></param>
public static void RemoveEvent(this Animator animator, string eventName, vEventSystems.vAnimatorEvent.OnTriggerEvent onTriggerEventAction)
{
if (animator)
{
var behaviours = animator.GetBehaviours<vEventSystems.vAnimatorEvent>();
for (int i = 0; i < behaviours.Length; i++)
{
if (behaviours[i].HasEvent(eventName))
{
behaviours[i].RemoveEvents(eventName, onTriggerEventAction);
}
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f223dbf5c9c4b5f46a7dbfa1a717fc27
timeCreated: 1542810410
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,135 @@
using System.Collections.Generic;
using UnityEngine;
namespace Invector.vEventSystems
{
[vClassHeader("Animator Event Receiver")]
public class vAnimatorEventReceiver : vMonoBehaviour
{
[Tooltip("Check this option if the Animator component is on the parent of this GameObject")]
public bool getAnimatorInParent;
[vHelpBox("Use <b>vAnimatorEvent</b> on a AnimatorState to trigger a Event below", vHelpBoxAttribute.MessageType.Info)]
public List<vAnimatorEvent> animatorEvents;
[System.Serializable]
public class vAnimatorEvent
{
[System.Serializable]
public class StateEvent : UnityEngine.Events.UnityEvent<string> { }
public string eventName;
public bool debug;
public StateEvent onTriggerEvent;
public virtual void OnTriggerEvent(string eventName)
{
if (debug)
{
Debug.Log("<color=green><b>Event " + eventName + " was called</b></color>");
}
onTriggerEvent.Invoke(eventName);
}
}
private bool hasValidBehaviours;
private bool hasAnimator;
private void Start()
{
RegisterEvents();
}
private void OnDisable()
{
RemoveEvents();
}
public void OnEnable()
{
if (hasAnimator && hasValidBehaviours)
{
RemoveEvents();
RegisterEvents();
}
}
private void OnDestroy()
{
RemoveEvents();
}
public virtual void RegisterEvents()
{
if (animatorEvents.Count > 0)
{
var animator = getAnimatorInParent ? GetComponentInParent<Animator>() : GetComponent<Animator>();
if (getAnimatorInParent && animator.gameObject == gameObject && transform.parent)
{
animator = transform.parent.GetComponentInParent<Animator>();
}
if (animator)
{
hasAnimator = true;
var behaviours = animator.GetBehaviours<Invector.vEventSystems.vAnimatorEvent>();
for (int a = 0; a < animatorEvents.Count; a++)
{
var hasEvent = false;
for (int i = 0; i < behaviours.Length; i++)
{
if (behaviours[i].HasEvent(animatorEvents[a].eventName))
{
behaviours[i].RegisterEvents(animatorEvents[a].eventName, animatorEvents[a].OnTriggerEvent);
if (animatorEvents[a].debug)
{
Debug.Log("<color=green>" + gameObject.name + " Register event : " + animatorEvents[a].eventName + "</color> in the " + animator.gameObject.name, gameObject);
}
hasValidBehaviours = true;
hasEvent = true;
}
}
if (!hasEvent && animatorEvents[a].debug)
{
Debug.LogWarning(animator.gameObject.name + " Animator doesn't have Event with name: " + animatorEvents[a].eventName, gameObject);
}
}
}
else
{
Debug.LogWarning("Can't Find Animator to register Events in " + gameObject.name + (getAnimatorInParent ? " Parent" : ""), gameObject);
}
}
}
public virtual void RemoveEvents()
{
if (!hasAnimator || !hasValidBehaviours)
{
return;
}
if (animatorEvents.Count > 0)
{
var animator = getAnimatorInParent ? GetComponentInParent<Animator>() : GetComponent<Animator>();
if (animator)
{
var behaviours = animator.GetBehaviours<Invector.vEventSystems.vAnimatorEvent>();
for (int a = 0; a < animatorEvents.Count; a++)
{
for (int i = 0; i < behaviours.Length; i++)
{
if (behaviours[i].HasEvent(animatorEvents[a].eventName))
{
behaviours[i].RemoveEvents(animatorEvents[a].eventName, animatorEvents[a].OnTriggerEvent);
if (animatorEvents[a].debug)
{
Debug.Log("<color=red>" + gameObject.name + " Remove event : " + animatorEvents[a].eventName + "</color> Of the " + animator.gameObject.name, gameObject);
}
}
}
}
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 393a4106eb54f894a900c48422883d15
timeCreated: 1542762980
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
using UnityEngine;
public class vAnimatorIncreaseDecreaseValue : StateMachineBehaviour
{
public string targetFloat;
public bool decrease;
private float time;
public float speed = 1;
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (!decrease) time += Time.deltaTime * speed;
else time -= Time.deltaTime * speed;
animator.SetFloat(targetFloat, time);
}
// OnStateMove is called right after Animator.OnAnimatorMove()
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that processes and affects root motion
//}
// OnStateIK is called right after Animator.OnAnimatorIK()
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that sets up animation IK (inverse kinematics)
//}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 313cea8496c09c74aa3c474ed08d4a63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using UnityEngine;
namespace Invector.Utils
{
public class vResetTrigger : StateMachineBehaviour
{
public bool resetOnEnter,resetOnExit;
public string trigger;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if(resetOnEnter)
animator.ResetTrigger(trigger);
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (resetOnExit)
animator.ResetTrigger(trigger);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bddd5b9ffd2ac5f4abd68d6c9df44779
timeCreated: 1558124328
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
namespace Invector
{
public class vAnimatorSetBool : vAnimatorSetValue<bool>
{
[vHelpBox("Random Value between True and False")]
public bool randomEnter;
public bool randomExit;
protected override bool GetEnterValue()
{
return randomEnter ? UnityEngine.Random.Range(0,100)>50 : base.GetEnterValue();
}
protected override bool GetExitValue()
{
return randomExit ? UnityEngine.Random.Range(0, 100)>50 : base.GetExitValue();
}
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
//override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
//override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 00fede628fd16c84893b0e6fb236264f
timeCreated: 1544029143
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
namespace Invector
{
public class vAnimatorSetFloat : vAnimatorSetValue<float>
{
[vHelpBox("Random Value between Default Value and Max Value")]
public bool randomEnter;
[vHideInInspector("randomEnter")]
public float maxEnterValue;
public bool randomExit;
[vHideInInspector("randomExit")]
public float maxExitValue;
[vHelpBox("Use this in <b>Random mode</b> to generat a rounded value")]
public bool roundValue;
[UnityEngine.Tooltip("Digits after the comma")]
[vHideInInspector("roundValue")]
public int roundDigits =1;
[UnityEngine.Tooltip("Invert number randomly")]
public bool randomInvert;
protected override float GetEnterValue()
{
var val = 0f;
if(randomEnter)
{
val = UnityEngine.Random.Range(base.GetEnterValue(), maxEnterValue);
if (roundValue) val =(float) System.Math.Round(val, roundDigits);
}
else val = base.GetEnterValue();
if (randomInvert)
{
if (UnityEngine.Random.Range(0, 100) > 50) val *= -1;
}
return val;
}
protected override float GetExitValue()
{
var val = 0f;
if (randomEnter)
{
val = UnityEngine.Random.Range(base.GetExitValue(), maxEnterValue);
if (roundValue) val = (float)System.Math.Round(val, roundDigits);
}
else val = base.GetExitValue();
if (randomInvert)
{
if (UnityEngine.Random.Range(0, 100) > 50) val *= -1;
}
return val;
}
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
//override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
//override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3e7281fa362187f4a80ff9a5e86aedc5
timeCreated: 1544029143
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
namespace Invector
{
public class vAnimatorSetInt : vAnimatorSetValue<int>
{
vFisherYatesRandom random = new vFisherYatesRandom();
[vHelpBox("Random Value between Default Value and Max Value")]
public bool randomEnter;
[vHideInInspector("randomEnter")]
public int maxEnterValue;
public bool randomExit;
[vHideInInspector("randomExit")]
public int maxExitValue;
protected override int GetEnterValue()
{
return randomEnter ? random.Range(base.GetEnterValue(), maxEnterValue) : base.GetEnterValue();
}
protected override int GetExitValue()
{
return randomExit ? random.Range(base.GetExitValue(), maxExitValue) : base.GetExitValue();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4971f2abc3e4f6746b768f2ab57d497b
timeCreated: 1544029143
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
using UnityEngine;
public class vAnimatorSetTrigger : StateMachineBehaviour
{
public bool setOnEnter, setOnExit;
public string trigger;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (setOnEnter)
animator.SetTrigger(trigger);
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (setOnExit)
animator.SetTrigger(trigger);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b0137783fa327dd49b5c6281d64d24e7
timeCreated: 1563411986
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
using System;
using UnityEngine;
namespace Invector
{
[Serializable]
public abstract class vAnimatorSetValue<T> : StateMachineBehaviour where T : IConvertible
{
public string animatorParameter = "My Animator Parameter";
public bool setOnEnter;
[vHideInInspector("setOnEnter")]
public T enterValue;
public bool setOnExit;
[vHideInInspector("setOnExit")]
public T exitValue;
protected virtual T GetEnterValue()
{
return enterValue;
}
protected virtual T GetExitValue()
{
return exitValue;
}
override public sealed void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (setOnEnter)
{
if (typeof(T).Equals(typeof(int)))
animator.SetInteger(animatorParameter, (int)(object)GetEnterValue());
else if (typeof(T).Equals(typeof(float)))
animator.SetFloat(animatorParameter, (float)(object)GetEnterValue());
else if (typeof(T).Equals(typeof(bool)))
animator.SetBool(animatorParameter, (bool)(object)GetEnterValue());
}
}
override public sealed void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (setOnExit)
{
if (typeof(T).Equals(typeof(int)))
animator.SetInteger(animatorParameter, (int)(object)GetExitValue());
else if (typeof(T).Equals(typeof(float)))
animator.SetFloat(animatorParameter, (float)(object)GetExitValue());
else if (typeof(T).Equals(typeof(bool)))
animator.SetBool(animatorParameter, (bool)(object)GetExitValue());
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f4a2739c02b8e6848a989653d09be345
timeCreated: 1544029143
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using UnityEngine;
namespace Invector.vEventSystems
{
public class vAnimatorTag : vAnimatorTagBase
{
public string[] tags = new string[] { "CustomAction" };
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
base.OnStateEnter(animator, stateInfo, layerIndex);
if (stateInfos != null)
{
for (int i = 0; i < tags.Length; i++)
{
for (int a = 0; a < stateInfos.Count; a++)
{
stateInfos[a].AddStateInfo(tags[i], layerIndex);
}
}
}
OnStateEnterEvent(tags.vToList());
}
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
base.OnStateUpdate(animator, stateInfo, layerIndex);
if (stateInfos != null)
{
for (int a = 0; a < stateInfos.Count; a++)
{
stateInfos[a].UpdateStateInfo(layerIndex, stateInfo.normalizedTime, stateInfo.shortNameHash);
}
}
}
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (stateInfos != null)
{
for (int i = 0; i < tags.Length; i++)
{
for (int a = 0; a < stateInfos.Count; a++)
stateInfos[a].RemoveStateInfo(tags[i], layerIndex);
}
}
base.OnStateExit(animator, stateInfo, layerIndex);
OnStateExitEvent(tags.vToList());
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d23a79fe8deb55a4fb192f4d8b417fea
timeCreated: 1519142239
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,145 @@
using System.Collections.Generic;
using UnityEngine;
namespace Invector.vEventSystems
{
public class vAnimatorTagAdvanced : vAnimatorTagBase
{
public enum vAnimatorEventTriggerType
{
AllByNormalizedTime, EnterStateExitByNormalized, EnterByNormalizedExitState, EnterStateExitState
}
[System.Serializable]
public class vAdvancedTags
{
public string tagName;
public vAnimatorEventTriggerType tagType = vAnimatorEventTriggerType.AllByNormalizedTime;
public Vector2 normalizedTime = new Vector2(0.1f, 0.8f);
private int loopCount;
public vAdvancedTags(string tag)
{
this.tagName = tag;
this.tagType = vAnimatorEventTriggerType.AllByNormalizedTime;
}
bool isEnter;
bool isExit;
public void UpdateEventTrigger(float normalizedTime, List<vAnimatorStateInfos> stateInfos, int layer, float speed = 1,bool looping= false, bool inExit = false, bool debug = false)
{
var normalizedTimeClamped = normalizedTime % 1;
if (!isEnter && !inExit && tagType != vAnimatorEventTriggerType.EnterStateExitByNormalized &&
tagType != vAnimatorEventTriggerType.EnterStateExitState && normalizedTimeClamped >= this.normalizedTime.x )
{
if (debug) Debug.Log("ADD TAG " + tagName + " in " + normalizedTime);
AddTag(stateInfos, layer);
}
if (!isExit && isEnter && tagType != vAnimatorEventTriggerType.EnterByNormalizedExitState &&
tagType != vAnimatorEventTriggerType.EnterStateExitState && (normalizedTimeClamped >= this.normalizedTime.y || inExit))
{
RemoveTag(stateInfos, layer);
if (debug) Debug.Log("REMOVE TAG " + tagName + " in " + normalizedTime);
}
if (looping && normalizedTime > loopCount + 1)
{
isEnter = false;
isExit = false;
loopCount++;
}
}
public void AddTag(List<vAnimatorStateInfos> stateInfos, int layer)
{
for (int i = 0; i < stateInfos.Count; i++)
stateInfos[i].AddStateInfo(tagName, layer);
isEnter = true;
}
public void RemoveTag(List<vAnimatorStateInfos> stateInfos, int layer)
{
for (int i = 0; i < stateInfos.Count; i++)
{
stateInfos[i].RemoveStateInfo(tagName, layer); isExit = true;
}
}
public void Init(List<vAnimatorStateInfos> stateInfos, int layer)
{
if(isEnter && !isExit)
{
RemoveTag(stateInfos, layer);
}
isEnter = false;
isExit = false;
loopCount = 0;
}
}
public bool debug;
public List<vAdvancedTags> tags = new List<vAdvancedTags>() { new vAdvancedTags("CustomAction") };
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
base.OnStateEnter(animator, stateInfo, layerIndex);
if (stateInfos != null)
{
for (int i = 0; i < tags.Count; i++)
{
tags[i].Init(stateInfos,layerIndex);
if (debug) Debug.Log("Init " + tags[i].tagName + " OnStateEnter ");
if (tags[i].tagType == vAnimatorEventTriggerType.EnterStateExitState || tags[i].tagType == vAnimatorEventTriggerType.EnterStateExitByNormalized)
{
if (debug) Debug.Log("ADD TAG " + tags[i].tagName + " OnStateEnter ");
tags[i].AddTag(stateInfos, layerIndex);
}
else
tags[i].UpdateEventTrigger(stateInfo.normalizedTime, stateInfos, layerIndex, animator.speed,stateInfo.loop, false, debug);
}
}
}
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (stateInfos != null)
{
for (int i = 0; i < tags.Count; i++)
{
if (tags[i].tagType != vAnimatorEventTriggerType.EnterStateExitState)
tags[i].UpdateEventTrigger(stateInfo.normalizedTime, stateInfos, layerIndex, animator.speed, stateInfo.loop, false, debug);
}
for (int a = 0; a < stateInfos.Count; a++)
{
stateInfos[a].UpdateStateInfo(layerIndex, stateInfo.normalizedTime, stateInfo.shortNameHash);
}
}
base.OnStateUpdate(animator, stateInfo, layerIndex);
}
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (stateInfos != null)
{
for (int i = 0; i < tags.Count; i++)
{
if (tags[i].tagType == vAnimatorEventTriggerType.EnterStateExitState || tags[i].tagType == vAnimatorEventTriggerType.EnterByNormalizedExitState)
{
if (debug) Debug.Log("REMOVE TAG " + tags[i].tagName + " OnStateExit ");
tags[i].RemoveTag(stateInfos, layerIndex);
}
else
{
tags[i].UpdateEventTrigger(stateInfo.normalizedTime, stateInfos, layerIndex, animator.speed, stateInfo.loop, true, debug);
}
}
}
base.OnStateExit(animator, stateInfo, layerIndex);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5f3b04f29aa5b134b99e94c78b296dcf
timeCreated: 1563393673
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections.Generic;
using UnityEngine;
namespace Invector.vEventSystems
{
public abstract class vAnimatorTagBase : StateMachineBehaviour
{
public delegate void OnStateTrigger(List<string> tags);
public List<vAnimatorStateInfos> stateInfos = new List<vAnimatorStateInfos>();
public event OnStateTrigger onStateEnter;
public event OnStateTrigger onStateExit;
public virtual void AddStateInfoListener(vAnimatorStateInfos stateInfo)
{
if (!stateInfos.Contains(stateInfo))
{
stateInfos.Add(stateInfo);
}
}
public virtual void RemoveStateInfoListener(vAnimatorStateInfos stateInfo)
{
if (stateInfos.Contains(stateInfo))
{
stateInfos.Remove(stateInfo);
}
}
protected virtual void OnStateEnterEvent(List<string> tags)
{
if (onStateEnter != null)
onStateEnter(tags);
}
protected virtual void OnStateExitEvent(List<string> tags)
{
if (onStateEnter != null)
onStateExit(tags);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: de3c236429d76fa4fb7d65e6e501f656
timeCreated: 1563393518
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,137 @@
using UnityEngine;
namespace Invector.vEventSystems
{
public class vAnimatorTagByParamenter : vAnimatorTag
{
public enum ParamenterType
{
Bool, Float, Int
}
public enum NumberCompare
{
Equals, Greater, Less
}
public string paramenterName;
public ParamenterType paramenterType;
[vCheckProperty("paramenterType", ParamenterType.Bool, hideInInspector = true)]
public bool boolValue;
[vCheckProperty("paramenterType", ParamenterType.Float, hideInInspector = true)]
public float floatValue;
[vCheckProperty("paramenterType", ParamenterType.Int, hideInInspector = true)]
public int intValue;
[vCheckProperty("paramenterType", ParamenterType.Bool, hideInInspector = true, invertResult = true)]
public NumberCompare compare;
[vReadOnly] public bool tagAdded;
vAnimatorParameter paramenter;
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (paramenter == null) paramenter = new vAnimatorParameter(animator, paramenterName);
///don't do anything
}
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
base.OnStateUpdate(animator, stateInfo, layerIndex);
CheckForParamenter(animator, layerIndex);
}
private void CheckForParamenter(Animator animator, int layerIndex)
{
if (paramenter.isValid)
{
bool isValid = false;
switch (paramenterType)
{
case ParamenterType.Float:
isValid = CompareNumber(floatValue, animator.GetFloat(paramenter), compare);
break;
case ParamenterType.Int:
isValid = CompareNumber(intValue, animator.GetInteger(paramenter), compare);
break;
case ParamenterType.Bool:
isValid = boolValue == animator.GetBool(paramenter);
break;
}
if (isValid != tagAdded)
{
tagAdded = isValid;
if (isValid)
{
AddTags(layerIndex);
}
else
{
RemoveTags(layerIndex);
}
}
}
}
void AddTags(int layerIndex)
{
if (stateInfos != null)
{
for (int i = 0; i < tags.Length; i++)
{
for (int a = 0; a < stateInfos.Count; a++)
{
stateInfos[a].AddStateInfo(tags[i], layerIndex);
}
}
}
}
void RemoveTags(int layerIndex)
{
if (stateInfos != null)
{
for (int i = 0; i < tags.Length; i++)
{
for (int a = 0; a < stateInfos.Count; a++)
{
stateInfos[a].RemoveStateInfo(tags[i], layerIndex);
}
}
}
}
bool CompareNumber(float a, float b, NumberCompare compare)
{
switch (compare)
{
case NumberCompare.Equals:
Debug.Log($"{b} == {a}");
return b == a;
case NumberCompare.Greater:
Debug.Log($"{b} > {a}");
return b > a;
case NumberCompare.Less:
Debug.Log($"{b} < {a}");
return b < a;
}
return false;
}
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (tagAdded)
{
tagAdded = false;
base.OnStateExit(animator, stateInfo, layerIndex);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 577d140dc31f50e4aaace33c11e23be5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEngine;
namespace Invector
{
public static partial class vAnimatorTags
{
[Tooltip("Use to lock the controller movement to use the root movement instead")]
public const string LockMovement = "LockMovement";
[Tooltip("Use to lock the controller rotation to use the root rotation instead")]
public const string LockRotation = "LockRotation";
[Tooltip("Use for Generic Actions like push lever, it will lock the players input, movement and rotation and use the animation root motion")]
public const string CustomAction = "CustomAction";
[Tooltip("Use to identify if this is a Airborne animation")]
public const string Airborne = "Airborne";
[Tooltip("Use to Ignore the Headtrack")]
public const string IgnoreHeadtrack = "IgnoreHeadtrack";
[Tooltip("Use to identify a Death animation")]
public const string Dead = "Dead";
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3a53c78ce94812c45a50fd08c068e33f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using Invector;
using UnityEngine;
public class vChangeAnimatorUpdateMode : MonoBehaviour
{
public Animator animator;
private readonly AnimatorUpdateMode initialState = AnimatorUpdateMode.Fixed;
public void Reset()
{
animator = GetComponentInParent<Animator>();
}
private void Start()
{
if (!animator) animator = GetComponentInParent<Animator>();
}
public void ChangeToUnscaledTime()
{
if (Time.timeScale == 0)
{
vTime.useUnscaledTime = true;
animator.updateMode = AnimatorUpdateMode.UnscaledTime;
}
}
public void ChangeToAnimatePhysics()
{
animator.updateMode = AnimatorUpdateMode.Fixed;
vTime.useUnscaledTime = false;
}
public void ChangeToInitialState()
{
animator.updateMode = initialState;
vTime.useUnscaledTime =initialState== AnimatorUpdateMode.UnscaledTime ?true:false;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 93dccd0079a44644690bde51cf65d442
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace Invector.Utils
{
public class vSetAnimatorLayerWeight : MonoBehaviour
{
public Animator animator;
public int layer;
public float weight;
public float speed;
[Invector.vReadOnly]
protected float currentWeight;
private void Update()
{
currentWeight = Mathf.Lerp(currentWeight, weight, speed * Time.deltaTime);
animator.SetLayerWeight(layer, currentWeight);
}
public void SetWeight(float value)
{
weight = value;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c62b00526b41b3f49ba7c01b105e9733
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,126 @@
using UnityEngine;
namespace Invector.Utils
{
[vClassHeader("Set Animator Value", useHelpBox = true, helpBoxText = "Use this component to set animator value using events")]
public class vSetAnimatorValue : vMonoBehaviour
{
[vSelectableString("Set Float exemple", "ParamenterName,Float,1.0")]
[vSelectableString("Set Integer exemple", "ParamenterName,Int,1")]
[vSelectableString("Set Bool exemple", "ParamenterName,Bool,true")]
[vSelectableString("Set Trigger exemple", "ParamenterName,Trigger,Set")]
[vSelectableString("Reset Trigger exemple", "ParamenterName,Trigger,Reset")]
[vHelpBox("SetValueByExpression examples", vHelpBoxAttribute.MessageType.Info)]
[Tooltip("Target Animator to set value")]
public Animator targetAnimator;
[Tooltip("Target paramenter for normal methods\nDon't will be used when using SetValueByExpression method")]
public string targetParamenter;
[SerializeField, vReadOnly]
protected int paramenterHash;
enum ValueType
{
Float, Int, Bool, Trigger
}
public void SetTargetAnimator(Animator animator)
{
targetAnimator = animator;
}
public void SetTrigger()
{
targetAnimator.SetTrigger(paramenterHash);
}
public void ResetTrigger()
{
targetAnimator.ResetTrigger(paramenterHash);
}
public void SetBoolean(bool value)
{
targetAnimator.SetBool(paramenterHash, value);
}
public void SetInteger(int value)
{
targetAnimator.SetInteger(paramenterHash, value);
}
public void SetFloat(float value)
{
targetAnimator.SetFloat(paramenterHash, value);
}
public void SetTargetParamenter(string targetParamenter)
{
this.targetParamenter = targetParamenter;
}
public void SetValueByExpression(string expression)
{
string[] splited = expression.Split(',');
if (splited.Length < 3)
{
Debug.LogWarning($"Expression :<color=green>{expression}</color> does't match any valid expression");
return;
}
string parameterName = splited[0];
if (System.Enum.TryParse<ValueType>(splited[1], out ValueType valueType))
{
var value = splited[2];
bool setFail = false;
switch (valueType)
{
case ValueType.Bool:
if (System.Boolean.TryParse(value, out bool boolValue))
{
targetAnimator.SetBool(parameterName, boolValue);
}
else
{
setFail = true;
}
break;
case ValueType.Int:
if (System.Int32.TryParse(value, out int intValue))
{
targetAnimator.SetInteger(targetParamenter, intValue);
}
else
{
setFail = true;
}
break;
case ValueType.Float:
if (System.Double.TryParse(value, out double doubleValue))
{
targetAnimator.SetFloat(parameterName, (float)doubleValue);
}
else
{
setFail = true;
}
break;
case ValueType.Trigger:
if (value == "Set")
{
targetAnimator.SetTrigger(parameterName);
}
else if (value == "Reset")
{
targetAnimator.ResetTrigger(parameterName);
}
else
{
setFail = true;
}
break;
}
if (setFail)
{
Debug.LogWarning($"Expression :<color=green>{value}</color> does't match any valid value");
}
}
else
{
Debug.LogWarning($"Expression :<color=green>{splited[0]}</color> does't match any animator value");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4bc693a7cefca084a80e8ad337098256
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections.Generic;
namespace Invector
{
public class vTriggerSoundByState : StateMachineBehaviour
{
public GameObject audioSource;
public List<AudioClip> sounds;
public float triggerTime;
private vFisherYatesRandom _random;
private bool isTrigger;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
isTrigger = false;
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (stateInfo.normalizedTime % 1 >= triggerTime && !isTrigger)
{
TriggerSound(animator, stateInfo, layerIndex);
}
else if (stateInfo.normalizedTime % 1 < triggerTime && isTrigger) isTrigger = false;
}
void TriggerSound(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (_random == null)
_random = new vFisherYatesRandom();
isTrigger = true;
GameObject audioObject = null;
if (audioSource != null)
audioObject = Instantiate(audioSource.gameObject, animator.transform.position, Quaternion.identity) as GameObject;
else
{
audioObject = new GameObject("audioObject");
audioObject.transform.position = animator.transform.position;
}
if (audioObject != null)
{
var source = audioObject.gameObject.GetComponent<AudioSource>();
var clip = sounds[_random.Next(sounds.Count)];
source.PlayOneShot(clip);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ae6dcf6552bd02645a9ceb894d7a6cfa
timeCreated: 1461723406
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class vUseRootMotion : StateMachineBehaviour
{
// OnStateMove is called before OnStateMove is called on any state inside this state machine
override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.ApplyBuiltinRootMotion();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26c66b0e3fe82a44ea5f4ea510c6de6c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: