void CreateListeners() { MEventListener listener = GetComponent <MEventListener>(); if (listener == null) { listener = gameObject.AddComponent <MEventListener>(); } if (listener.Events == null) { listener.Events = new List <MEventItemListener>(); } MEvent BlendS = MalbersTools.GetInstance <MEvent>("Blend Shapes"); if (listener.Events.Find(item => item.Event == BlendS) == null) { var item = new MEventItemListener() { Event = BlendS, useVoid = false, useString = true, useInt = true, }; UnityEditor.Events.UnityEventTools.AddPersistentListener(item.ResponseInt, _PinShape); UnityEditor.Events.UnityEventTools.AddPersistentListener(item.ResponseString, _PinShape); listener.Events.Add(item); Debug.Log("<B>Blend Shapes</B> Added to the Event Listeners"); } }
public virtual void Align(Transform TargetToAlign) { if (enabled && mainPoint && TargetToAlign != null) { if (AlignLookAt) { StartCoroutine(AlignLookAtTransform(TargetToAlign, mainPoint, AlignTime, AlignCurve)); //Align Look At the Zone StartCoroutine(AlignTransformRadius(TargetToAlign, mainPoint, AlignTime, LookAtRadius, AlignCurve)); //Align Look At the Zone } else { if (AlignPos) { Vector3 AlingPosition = mainPoint.position; if (SecondPoint) //In case there's a line ... move to the closest point between the two transforms { AlingPosition = MalbersTools.ClosestPointOnLine(mainPoint.position, SecondPoint.position, TargetToAlign.transform.position); } if (DoubleSided) { Vector3 AlingPosOpposite = transform.InverseTransformPoint(AlingPosition); AlingPosOpposite.z *= -1; AlingPosOpposite = transform.TransformPoint(AlingPosOpposite); var Distance1 = Vector3.Distance(TargetToAlign.transform.position, AlingPosition); var Distance2 = Vector3.Distance(TargetToAlign.transform.position, AlingPosOpposite); var AlignTransformResult = Distance2 < Distance1 ? AlingPosOpposite : AlingPosition; StartCoroutine(MalbersTools.AlignTransform_Position(TargetToAlign.transform, AlignTransformResult, AlignTime, AlignCurve)); } else { StartCoroutine(MalbersTools.AlignTransform_Position(TargetToAlign.transform, AlingPosition, AlignTime, AlignCurve)); } } if (AlignRot) { Quaternion Side1 = mainPoint.rotation; Quaternion AnimalRot = TargetToAlign.transform.rotation; if (DoubleSided) { Quaternion Side2 = mainPoint.rotation * Quaternion.Euler(0, 180, 0); var Side1Angle = Quaternion.Angle(AnimalRot, Side1); var Side2Angle = Quaternion.Angle(AnimalRot, Side2); StartCoroutine(MalbersTools.AlignTransform_Rotation(TargetToAlign.transform, Side1Angle < Side2Angle ? Side1 : Side2, AlignTime, AlignCurve)); } else { StartCoroutine(MalbersTools.AlignTransform_Rotation(TargetToAlign.transform, Side1, AlignTime, AlignCurve)); } } } } }
void Awake() { MainCamera = MalbersTools.FindMainCamera(); MainCameraT = MainCamera.transform; _t = transform; GetCenterScreen(); }
void OnTriggerExit(Collider other) { if (!active) { return; } if (MalbersTools.Layer_in_LayerMask(other.gameObject.layer, Ignore)) { return; } OnTrigger_Exit.Invoke(other); }
void Reset() { MEvent FollowUITransform = MalbersTools.GetInstance <MEvent>("Follow UI Transform"); OnAimRayTarget = new TransformEvent(); OnScreenCenter = new Vector3Event(); if (FollowUITransform != null) { UnityEditor.Events.UnityEventTools.AddPersistentListener(OnAimRayTarget, FollowUITransform.Invoke); UnityEditor.Events.UnityEventTools.AddPersistentListener(OnScreenCenter, FollowUITransform.Invoke); } }
public virtual void Set_by_BinaryIndex(int binaryCurrent) { int current = 0; for (int i = 0; i < materials.Length; i++) { if (MalbersTools.IsBitActive(binaryCurrent, i)) { current = i; //find the first active bit and get the current break; } } ChangeMaterial(current); }
public void Set_by_BinaryIndex(int binaryCurrent) { int current = 0; for (int i = 0; i < meshes.Length; i++) { if (MalbersTools.IsBitActive(binaryCurrent, i)) { current = i; //Find the first active bit and use it as current break; } } ChangeMesh(current); }
void Awake() { MainCamera = MalbersTools.FindMainCamera(); MainCameraT = MainCamera.transform; _t = transform; if (AimOrigin == null) { AimOrigin = transform; } GetCenterScreen(); }
void CreateListeners() { MEventListener listener = GetComponent <MEventListener>(); if (listener == null) { listener = gameObject.AddComponent <MEventListener>(); } if (listener.Events == null) { listener.Events = new List <MEventItemListener>(); } MEvent effectEnable = MalbersTools.GetInstance <MEvent>("Effect Enable"); MEvent effectDisable = MalbersTools.GetInstance <MEvent>("Effect Disable"); if (listener.Events.Find(item => item.Event == effectEnable) == null) { var item = new MEventItemListener() { Event = effectEnable, useVoid = false, useString = true, useInt = true }; UnityEditor.Events.UnityEventTools.AddPersistentListener(item.ResponseInt, Effect_Enable); UnityEditor.Events.UnityEventTools.AddPersistentListener(item.ResponseString, Effect_Enable); listener.Events.Add(item); Debug.Log("<B>Effect Enable</B> Added to the Event Listeners"); } if (listener.Events.Find(item => item.Event == effectDisable) == null) { var item = new MEventItemListener() { Event = effectDisable, useVoid = false, useString = true, useInt = true }; UnityEditor.Events.UnityEventTools.AddPersistentListener(item.ResponseInt, Effect_Disable); UnityEditor.Events.UnityEventTools.AddPersistentListener(item.ResponseString, Effect_Disable); listener.Events.Add(item); Debug.Log("<B>Effect Disable</B> Added to the Event Listeners"); } }
void OnTriggerStay(Collider other) { if (!active) { return; } if (ignoreTriggers && other.isTrigger) { return; } if (MalbersTools.Layer_in_LayerMask(other.gameObject.layer, Ignore)) { return; } OnTrigger_Stay.Invoke(other); }
Vector3 GetAIMDirection() { Vector3 TargetDir; if (ForcedTarget) { TargetDir = MalbersTools.DirectionTarget(AimOrigin, ForcedTarget); AimRayTargetAssist = !Limited ? ForcedTarget : null; AimPoint = ForcedTarget.position; } else { GetCenterScreen(); DirectionFromCamera(ScreenCenter, out aimHit, IgnoreTransform); AimPoint = AimHit.point; TargetDir = (AimPoint - AimOrigin.position); } return(TargetDir); }
/// <summary> /// Rotates the bones to the Look direction (Unfortunately with no Lerp between them /// </summary> void LookAtBoneSet_AnimatePhysics() { hasTarget = false; if (UseCamera || Target) { hasTarget = true; } angle = Vector3.Angle(transform.forward, direction); foreach (var bone in Bones) { if (!bone.bone) { continue; } Vector3 dir = transform.forward; if (UseCamera) { dir = cam.forward; aimHit = MalbersTools.RayCastHitToCenter(bone.bone); if (aimHit.collider) { dir = MalbersTools.DirectionTarget(bone.bone.position, aimHit.point); } } if (Target) { dir = (Target.position - bone.bone.position).normalized; } direction = Vector3.Lerp(direction, dir, Time.deltaTime * Smoothness); angle = Vector3.Angle(transform.forward, direction); //Set the angle for the current bone if ((angle < LimitAngle && active && hasTarget)) { var final = Quaternion.LookRotation(direction, Vector3.up) * Quaternion.Euler(bone.offset); var next = Quaternion.Lerp(bone.initialRotation, final, bone.weight); bone.initialRotation = Quaternion.Lerp(bone.initialRotation, next, Time.deltaTime * Smoothness * 2); moreRestore = 1; if (debug) { Debug.DrawRay(bone.bone.position, direction * 5, Color.green); } } else { moreRestore += Time.deltaTime; bone.initialRotation = Quaternion.Lerp(bone.initialRotation, bone.bone.rotation, Time.deltaTime * Smoothness * 2 * moreRestore); moreRestore = Mathf.Clamp(moreRestore, 0, 1000); //this is for not making bigger than 1000 } bone.bone.rotation = bone.initialRotation; } }
/// <summary> /// Rotates the bones to the Look direction (Only works when the animator is set to Update Mode : Normal) /// </summary> void LookAtBoneSet() { hasTarget = false; if (UseCamera || Target) { hasTarget = true; } angle = Vector3.Angle(transform.forward, direction); //Find the angle for the current bone currentSmoothness = Mathf.Lerp(currentSmoothness, IsAiming ? 1 : 0, Time.deltaTime * Smoothness); if (currentSmoothness > 0.999f) { currentSmoothness = 1; } if (currentSmoothness < 0.001f) { currentSmoothness = 0; } foreach (var bone in Bones) { if (!bone.bone) { continue; } Vector3 dir = transform.forward; if (UseCamera) { dir = cam.forward; aimHit = MalbersTools.RayCastHitToCenter(bone.bone); if (aimHit.collider) { dir = MalbersTools.DirectionTarget(bone.bone.position, aimHit.point); } } if (Target) { dir = MalbersTools.DirectionTarget(bone.bone, Target); } direction = Vector3.Lerp(direction, dir, Time.deltaTime * Smoothness); if (currentSmoothness == 0) { return; //Skip all next stuffs } if (debug) { Debug.DrawRay(bone.bone.position, direction * 15, Color.green); } var final = Quaternion.LookRotation(direction, UpVector) * Quaternion.Euler(bone.offset); var next = Quaternion.Lerp(bone.bone.rotation, final, bone.weight * currentSmoothness); bone.bone.rotation = next; } }
/// <summary> /// Rotates the bones to the Look direction (Only works when the animator is set to Update Mode : Normal) /// </summary> void LookAtBoneSet() { if (!Target && !cam) { return; //If there's no camera and no Target ignore completely } hasTarget = false; if (UseCamera || Target) { hasTarget = true; } angle = Vector3.Angle(transform.forward, direction); //Find the angle for the current bone currentSmoothness = Mathf.Lerp(currentSmoothness, IsAiming ? 1 : 0, Time.deltaTime * Smoothness); if (currentSmoothness > 0.9999f) { currentSmoothness = 1; } if (currentSmoothness < 0.0001f) { currentSmoothness = 0; } for (int i = 0; i < Bones.Length; i++) { var bone = Bones[i]; if (!bone.bone) { continue; //if There's no bone skip } Vector3 dir = transform.forward; if (UseCamera && cam) { dir = cam.forward; aimHit = MalbersTools.RayCastHitToCenter(bone.bone, ~Ignore); //Calculate the Direction from the Bone if (aimHit.collider) //if something was hit { dir = MalbersTools.DirectionTarget(bone.bone.position, aimHit.point); } } if (Target) { dir = MalbersTools.DirectionTarget(bone.bone, Target); } direction = Vector3.Lerp(direction, dir, Time.deltaTime * Smoothness); if (currentSmoothness == 0) { return; //Skip all next stuffs } if (debug && i == Bones.Length - 1) { Debug.DrawRay(bone.bone.position, direction * 15, Color.green); } var final = Quaternion.LookRotation(direction, UpVector) * Quaternion.Euler(bone.offset); var next = Quaternion.Lerp(bone.bone.rotation, final, bone.weight * currentSmoothness); bone.bone.rotation = next; } }