Upload from upload_mods.ps1
This commit is contained in:
8
KFAttached/Animation.meta
Normal file
8
KFAttached/Animation.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0794a4eb6ebfc3a42a72e08a17a475cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/Animation/DebugScripts.meta
Normal file
8
KFAttached/Animation/DebugScripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e258bfeacfa28e49abe1c883f258a8b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimatorActionIndexDebug : StateMachineBehaviour
|
||||
{
|
||||
public override void OnStateMachineEnter(Animator animator, int stateMachinePathHash)
|
||||
{
|
||||
Log.Out($"StateMachine enter, Animator action index: {animator.GetInteger("ExecutingActionIndex")}");
|
||||
}
|
||||
|
||||
public override void OnStateMachineExit(Animator animator, int stateMachinePathHash)
|
||||
{
|
||||
Log.Out($"StateMachine exit, Animator action index: {animator.GetInteger("ExecutingActionIndex")}");
|
||||
}
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
Log.Out($"State entered!");
|
||||
}
|
||||
|
||||
public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
if (animator.GetBool("WeaponFire"))
|
||||
{
|
||||
Log.Out($"OnStateMove: Fire trigger set, Animator action index: {animator.GetInteger("ExecutingActionIndex")}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
if (animator.GetBool("WeaponFire"))
|
||||
{
|
||||
Log.Out($"OnStateUpdate: Fire trigger set, Animator action index: {animator.GetInteger("ExecutingActionIndex")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c436ffdfb304ce144a66f57ef3e43bc4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/Animation/MonoBehaviours.meta
Normal file
8
KFAttached/Animation/MonoBehaviours.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90da1ffd0de481442b66207ea3c9263a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Binding Helpers/Animation Aim Recoil References")]
|
||||
public class AnimationAimRecoilReferences : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform[] aimRecoilTargets;
|
||||
private Vector3[] initialPositions;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (aimRecoilTargets != null)
|
||||
{
|
||||
initialPositions = new Vector3[aimRecoilTargets.Length];
|
||||
for (int i = 0; i < aimRecoilTargets.Length; i++)
|
||||
{
|
||||
initialPositions[i] = aimRecoilTargets[i].localPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Rollback()
|
||||
{
|
||||
if (aimRecoilTargets != null)
|
||||
{
|
||||
for (int i = 0; i < aimRecoilTargets.Length; i++)
|
||||
{
|
||||
aimRecoilTargets[i].localPosition = initialPositions[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ca4c020de5e68b4ca9902d948462df5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
212
KFAttached/Animation/MonoBehaviours/AnimationDelayRender.cs
Normal file
212
KFAttached/Animation/MonoBehaviours/AnimationDelayRender.cs
Normal file
@@ -0,0 +1,212 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
#if NotEditor
|
||||
using UniLinq;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.Jobs;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class AnimationDelayRender : MonoBehaviour
|
||||
{
|
||||
#if NotEditor
|
||||
[Serializable]
|
||||
public class TransformTargets
|
||||
{
|
||||
public Transform target;
|
||||
public bool includeChildren;
|
||||
}
|
||||
|
||||
public struct TransformLocalData
|
||||
{
|
||||
public Vector3 localPosition;
|
||||
public Quaternion localRotation;
|
||||
public Vector3 localScale;
|
||||
|
||||
public TransformLocalData(Vector3 localPosition, Quaternion localRotation, Vector3 localScale)
|
||||
{
|
||||
this.localPosition = localPosition;
|
||||
this.localRotation = localRotation;
|
||||
this.localScale = localScale;
|
||||
}
|
||||
}
|
||||
|
||||
private struct TransformRestoreJobs : IJobParallelForTransform
|
||||
{
|
||||
public NativeArray<TransformLocalData> data;
|
||||
public void Execute(int index, TransformAccess transform)
|
||||
{
|
||||
if (transform.isValid)
|
||||
{
|
||||
transform.SetLocalPositionAndRotation(data[index].localPosition, data[index].localRotation);
|
||||
transform.localScale = data[index].localScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct TransformRestoreAndSaveJobs : IJobParallelForTransform
|
||||
{
|
||||
public NativeArray<TransformLocalData> data;
|
||||
public void Execute(int index, TransformAccess transform)
|
||||
{
|
||||
if (transform.isValid)
|
||||
{
|
||||
TransformLocalData targetData = new TransformLocalData(transform.localPosition, transform.localRotation, transform.localScale);
|
||||
transform.SetLocalPositionAndRotation(data[index].localPosition, data[index].localRotation);
|
||||
transform.localScale = data[index].localScale;
|
||||
data[index] = targetData;
|
||||
}
|
||||
}
|
||||
}
|
||||
[NonSerialized]
|
||||
private Transform[] delayTargets;
|
||||
|
||||
private TransformLocalData[] posTargets;
|
||||
private EntityPlayerLocal player;
|
||||
|
||||
private NativeArray<TransformLocalData> data;
|
||||
TransformAccessArray transArr;
|
||||
private JobHandle restoreJob, restoreAndSaveJob;
|
||||
private bool dataInitialized = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if NotEditor
|
||||
player = GameManager.Instance?.World?.GetPrimaryPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void InitializeTarget()
|
||||
{
|
||||
var delayTargetsSet = new HashSet<Transform>();
|
||||
foreach (Transform child in transform.GetComponentsInChildren<Transform>(true).Skip(1))
|
||||
{
|
||||
delayTargetsSet.Add(child);
|
||||
}
|
||||
delayTargets = delayTargetsSet.ToArray();
|
||||
posTargets = new TransformLocalData[delayTargets.Length];
|
||||
ClearNative();
|
||||
data = new NativeArray<TransformLocalData>(delayTargets.Length, Allocator.Persistent, NativeArrayOptions.ClearMemory);
|
||||
transArr = new TransformAccessArray(delayTargets);
|
||||
}
|
||||
|
||||
private void InitializeData()
|
||||
{
|
||||
for (int i = 0; i < delayTargets.Length; i++)
|
||||
{
|
||||
Transform target = delayTargets[i];
|
||||
if (target)
|
||||
{
|
||||
data[i] = new TransformLocalData(target.localPosition, target.localRotation, target.localScale);
|
||||
}
|
||||
}
|
||||
dataInitialized = true;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
InitializeTarget();
|
||||
player.playerCamera?.gameObject.GetOrAddComponent<AnimationDelayRenderReference>().targets.Add(this);
|
||||
//var preAnimatorUpdateJob = new TransformRestoreJobs
|
||||
//{
|
||||
// data = data
|
||||
//};
|
||||
//restoreJob = preAnimatorUpdateJob.Schedule(transArr);
|
||||
StartCoroutine(EndOfFrameCo());
|
||||
Log.Out($"Delay render target count: {delayTargets.Length}");
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ClearNative();
|
||||
player.playerCamera?.gameObject.GetOrAddComponent<AnimationDelayRenderReference>().targets.Remove(this);
|
||||
StopAllCoroutines();
|
||||
dataInitialized = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//for (int i = 0; i < delayTargets.Length; i++)
|
||||
//{
|
||||
// Transform target = delayTargets[i];
|
||||
// if (target)
|
||||
// {
|
||||
// target.localPosition = posTargets[i].localPosition;
|
||||
// target.localRotation = posTargets[i].localRotation;
|
||||
// target.localScale = posTargets[i].localScale;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// delayTargets[i] = null;
|
||||
// }
|
||||
//}
|
||||
restoreJob.Complete();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!dataInitialized)
|
||||
return;
|
||||
var postAnimationUpdateJob = new TransformRestoreAndSaveJobs
|
||||
{
|
||||
data = data
|
||||
};
|
||||
restoreAndSaveJob = postAnimationUpdateJob.Schedule(transArr);
|
||||
//for (int i = 0; i < delayTargets.Length; i++)
|
||||
//{
|
||||
// Transform target = delayTargets[i];
|
||||
// if (target)
|
||||
// {
|
||||
// TransformLocalData targetData = new TransformLocalData(target.localPosition, target.localRotation, target.localScale);
|
||||
// target.localPosition = posTargets[i].localPosition;
|
||||
// target.localRotation = posTargets[i].localRotation;
|
||||
// target.localScale = posTargets[i].localScale;
|
||||
// posTargets[i] = targetData;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// delayTargets[i] = null;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
internal void PreCullCallback()
|
||||
{
|
||||
restoreAndSaveJob.Complete();
|
||||
}
|
||||
|
||||
private IEnumerator EndOfFrameCo()
|
||||
{
|
||||
yield return null;
|
||||
InitializeData();
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
var eofUpdateJob = new TransformRestoreJobs { data = data };
|
||||
restoreJob = eofUpdateJob.Schedule(transArr);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearNative()
|
||||
{
|
||||
if (data.IsCreated)
|
||||
{
|
||||
data.Dispose();
|
||||
}
|
||||
if (transArr.isCreated)
|
||||
{
|
||||
transArr.Dispose();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ba593a40bea2734a8fb4ea26a7c290e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
internal class AnimationDelayRenderReference : MonoBehaviour
|
||||
{
|
||||
#if NotEditor
|
||||
internal HashSet<AnimationDelayRender> targets = new HashSet<AnimationDelayRender>();
|
||||
private void OnPreCull()
|
||||
{
|
||||
if (targets.Count > 0)
|
||||
{
|
||||
foreach (var target in targets)
|
||||
{
|
||||
target.PreCullCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfa24b0d9ec212f4eb1f00580cfb4212
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
KFAttached/Animation/MonoBehaviours/AnimationFiringEvents.cs
Normal file
31
KFAttached/Animation/MonoBehaviours/AnimationFiringEvents.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationFiringEvents : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private ParticleSystem[] mainParticles;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (mainParticles == null)
|
||||
return;
|
||||
foreach (var ps in mainParticles)
|
||||
{
|
||||
ps.gameObject.SetActive(true);
|
||||
var emission = ps.emission;
|
||||
emission.enabled = false;
|
||||
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = ps.main;
|
||||
main.loop = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Fire(int index)
|
||||
{
|
||||
if (mainParticles == null || index < 0 || index >= mainParticles.Length)
|
||||
return;
|
||||
GameObject root = mainParticles[index].gameObject;
|
||||
root.BroadcastMessage("OnEnable", SendMessageOptions.DontRequireReceiver);
|
||||
mainParticles[index].Emit(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2a71dc0034e159458026e1103e44c62
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
381
KFAttached/Animation/MonoBehaviours/AnimationGraphBuilder.cs
Normal file
381
KFAttached/Animation/MonoBehaviours/AnimationGraphBuilder.cs
Normal file
@@ -0,0 +1,381 @@
|
||||
#if NotEditor
|
||||
#endif
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class AnimationGraphBuilder : MonoBehaviour
|
||||
{
|
||||
public enum ParamInWrapper
|
||||
{
|
||||
None,
|
||||
Vanilla,
|
||||
Weapon,
|
||||
Attachments,
|
||||
Both
|
||||
}
|
||||
private Animator animator;
|
||||
private RuntimeAnimatorController vanillaRuntimeController;
|
||||
private Avatar vanillaAvatar;
|
||||
private PlayableGraph graph;
|
||||
private AnimationLayerMixerPlayable mixer;
|
||||
private AnimatorControllerPlayable weaponControllerPlayable;
|
||||
private AnimatorControllerPlayable vanillaControllerPlayable;
|
||||
private Avatar weaponAvatar;
|
||||
private AvatarMask weaponMask;
|
||||
private bool isFpv;
|
||||
private bool isLocalPlayer = true;
|
||||
private readonly List<MonoBehaviour> graphRelatedBehaviours = new List<MonoBehaviour>();
|
||||
private AnimatorControllerParameter[] parameters;
|
||||
private readonly Dictionary<int, ParamInWrapper> paramMapping = new Dictionary<int, ParamInWrapper>();
|
||||
private readonly Dictionary<string, ParamInWrapper> paramMappingDebug = new Dictionary<string, ParamInWrapper>();
|
||||
//private Animator[] childAnimators = Array.Empty<Animator>();
|
||||
|
||||
public bool HasWeaponOverride => graph.IsValid();
|
||||
//public AnimatorControllerPlayable VanillaPlayable => vanillaControllerPlayable;
|
||||
//public AnimatorControllerPlayable WeaponPlayable => weaponControllerPlayable;
|
||||
public AnimatorControllerParameter[] Parameters => parameters;
|
||||
private AnimationTargetsAbs CurrentTarget { get; set; }
|
||||
public IAnimatorWrapper VanillaWrapper { get; private set; }
|
||||
public IAnimatorWrapper WeaponWrapper { get; private set; }
|
||||
public AttachmentWrapper AttachmentWrapper { get; private set; }
|
||||
public static IAnimatorWrapper DummyWrapper { get; } = new AnimatorWrapper(null);
|
||||
#if NotEditor
|
||||
public EntityPlayer Player { get; private set; }
|
||||
#endif
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
isFpv = transform.name == "baseRigFP";
|
||||
animator = GetComponent<Animator>();
|
||||
animator.logWarnings = false;
|
||||
VanillaWrapper = new AnimatorWrapper(animator);
|
||||
WeaponWrapper = new AnimatorWrapper(null);
|
||||
parameters = animator.parameters;
|
||||
UpdateParamMapping();
|
||||
vanillaAvatar = animator.avatar;
|
||||
#if NotEditor
|
||||
vanillaRuntimeController = isFpv ? SDCSUtils.FPAnimController : SDCSUtils.TPAnimController;
|
||||
isLocalPlayer = (Player = GetComponentInParent<EntityPlayer>()) is EntityPlayerLocal;
|
||||
#else
|
||||
vanillaRuntimeController = animator.runtimeAnimatorController;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void UpdateParamMapping()
|
||||
{
|
||||
paramMapping.Clear();
|
||||
paramMappingDebug.Clear();
|
||||
var paramList = new List<AnimatorControllerParameter>();
|
||||
paramList.AddRange(animator.parameters);
|
||||
for (int i = 0; i < VanillaWrapper.GetParameterCount(); i++)
|
||||
{
|
||||
paramMapping.Add(VanillaWrapper.GetParameter(i).nameHash, ParamInWrapper.Vanilla);
|
||||
paramMappingDebug.Add(VanillaWrapper.GetParameter(i).name, ParamInWrapper.Vanilla);
|
||||
}
|
||||
if (WeaponWrapper != null && WeaponWrapper.IsValid)
|
||||
{
|
||||
for (int i = 0; i < WeaponWrapper.GetParameterCount(); i++)
|
||||
{
|
||||
var param = WeaponWrapper.GetParameter(i);
|
||||
if (paramMapping.ContainsKey(param.nameHash))
|
||||
{
|
||||
paramMapping[param.nameHash] = ParamInWrapper.Both;
|
||||
paramMappingDebug[param.name] = ParamInWrapper.Both;
|
||||
}
|
||||
else
|
||||
{
|
||||
paramMapping.Add(param.nameHash, ParamInWrapper.Weapon);
|
||||
paramMappingDebug.Add(param.name, ParamInWrapper.Weapon);
|
||||
paramList.Add(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (AttachmentWrapper != null && AttachmentWrapper.IsValid)
|
||||
{
|
||||
foreach (var animator in AttachmentWrapper.animators)
|
||||
{
|
||||
for (int i = 0; i < animator.parameterCount; i++)
|
||||
{
|
||||
var param = animator.GetParameter(i);
|
||||
if (!paramMapping.ContainsKey(param.nameHash))
|
||||
{
|
||||
paramMapping[param.nameHash] = ParamInWrapper.Attachments;
|
||||
paramList.Add(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parameters = paramList.ToArray();
|
||||
}
|
||||
|
||||
public ParamInWrapper GetWrapperRoleByParamHash(int nameHash)
|
||||
{
|
||||
if (paramMapping.TryGetValue(nameHash, out var role))
|
||||
return role;
|
||||
return ParamInWrapper.None;
|
||||
}
|
||||
|
||||
public ParamInWrapper GetWrapperRoleByParamName(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name) || !paramMapping.TryGetValue(Animator.StringToHash(name), out var role))
|
||||
return ParamInWrapper.None;
|
||||
return role;
|
||||
}
|
||||
|
||||
public ParamInWrapper GetWrapperRoleByParam(AnimatorControllerParameter param)
|
||||
{
|
||||
if (param == null || !paramMapping.TryGetValue(param.nameHash, out var role))
|
||||
return ParamInWrapper.None;
|
||||
return role;
|
||||
}
|
||||
|
||||
public void SetChildFloat(int nameHash, float value)
|
||||
{
|
||||
if (AttachmentWrapper != null && AttachmentWrapper.IsValid)
|
||||
{
|
||||
AttachmentWrapper.SetFloat(nameHash, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetChildBool(int nameHash, bool value)
|
||||
{
|
||||
if (AttachmentWrapper != null && AttachmentWrapper.IsValid)
|
||||
{
|
||||
AttachmentWrapper.SetBool(nameHash, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetChildInteger(int nameHash, int value)
|
||||
{
|
||||
if (AttachmentWrapper != null && AttachmentWrapper.IsValid)
|
||||
{
|
||||
AttachmentWrapper.SetInteger(nameHash, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetChildTrigger(int nameHash)
|
||||
{
|
||||
if (AttachmentWrapper != null && AttachmentWrapper.IsValid)
|
||||
{
|
||||
AttachmentWrapper.SetTrigger(nameHash);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetChildTrigger(int nameHash)
|
||||
{
|
||||
if (AttachmentWrapper != null && AttachmentWrapper.IsValid)
|
||||
{
|
||||
AttachmentWrapper.ResetTrigger(nameHash);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitGraph()
|
||||
{
|
||||
animator.runtimeAnimatorController = null;
|
||||
if (graph.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
graph = PlayableGraph.Create();
|
||||
mixer = AnimationLayerMixerPlayable.Create(graph, 2);
|
||||
var output = AnimationPlayableOutput.Create(graph, "output", animator);
|
||||
output.SetSourcePlayable(mixer);
|
||||
InitVanilla();
|
||||
graph.Play();
|
||||
}
|
||||
|
||||
private void InitVanilla()
|
||||
{
|
||||
vanillaControllerPlayable = AnimatorControllerPlayable.Create(graph, vanillaRuntimeController);
|
||||
mixer.ConnectInput(0, vanillaControllerPlayable, 0, isFpv ? 0 : 1.0f);
|
||||
mixer.SetLayerAdditive(0, false);
|
||||
}
|
||||
|
||||
public void InitWeapon(Transform weaponRoot, RuntimeAnimatorController weaponRuntimeController, AvatarMask weaponMask)
|
||||
{
|
||||
InitGraph();
|
||||
InitBehaviours(weaponRoot);
|
||||
weaponAvatar = AvatarBuilder.BuildGenericAvatar(gameObject, "Origin");
|
||||
animator.avatar = weaponAvatar;
|
||||
weaponControllerPlayable = AnimatorControllerPlayable.Create(graph, weaponRuntimeController);
|
||||
mixer.ConnectInput(1, weaponControllerPlayable, 0, 1.0f);
|
||||
mixer.SetLayerAdditive(1, false);
|
||||
if (weaponMask)
|
||||
{
|
||||
mixer.SetLayerMaskFromAvatarMask(1, weaponMask);
|
||||
}
|
||||
this.weaponMask = weaponMask;
|
||||
}
|
||||
|
||||
private void DestroyGraph()
|
||||
{
|
||||
CleanupBehaviours();
|
||||
weaponMask = null;
|
||||
if (graph.IsValid())
|
||||
{
|
||||
graph.Destroy();
|
||||
}
|
||||
if (animator)
|
||||
{
|
||||
animator.runtimeAnimatorController = vanillaRuntimeController;
|
||||
animator.avatar = vanillaAvatar;
|
||||
}
|
||||
}
|
||||
|
||||
private void DestroyWeapon()
|
||||
{
|
||||
CleanupBehaviours();
|
||||
weaponMask = null;
|
||||
if (weaponControllerPlayable.IsValid())
|
||||
{
|
||||
mixer.DisconnectInput(1);
|
||||
weaponControllerPlayable.Destroy();
|
||||
}
|
||||
animator.avatar = vanillaAvatar;
|
||||
Destroy(weaponAvatar);
|
||||
animator.runtimeAnimatorController = vanillaRuntimeController;
|
||||
}
|
||||
|
||||
public void SetCurrentTarget(AnimationTargetsAbs target)
|
||||
{
|
||||
if (CurrentTarget == target)
|
||||
{
|
||||
UpdateChildAnimatorArray(target);
|
||||
return;
|
||||
}
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
#if NotEditor
|
||||
bool wasCrouching = VanillaWrapper != null && VanillaWrapper.IsValid && VanillaWrapper.GetBool(AvatarController.isCrouchingHash);
|
||||
#endif
|
||||
//var rb = animator.transform.AddMissingComponent<RigBuilder>();
|
||||
//rb.enabled = false;
|
||||
if (CurrentTarget)
|
||||
{
|
||||
CurrentTarget.SetEnabled(false);
|
||||
}
|
||||
|
||||
bool useGraph = target && (target is PlayGraphTargets || (target.ItemTpv && !isFpv));
|
||||
if (HasWeaponOverride)
|
||||
{
|
||||
if (useGraph)
|
||||
{
|
||||
DestroyWeapon();
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyGraph();
|
||||
}
|
||||
}
|
||||
|
||||
CurrentTarget = target;
|
||||
if (target)
|
||||
{
|
||||
target.SetEnabled(true);
|
||||
}
|
||||
// Log.Out($"\n#=================Rebuild Start");
|
||||
//#if NotEditor
|
||||
// Log.Out($"Remaining RigLayers on build:\n{string.Join("\n", rb.layers.Select(layer => layer.name))}");
|
||||
//#endif
|
||||
// animator.UnbindAllSceneHandles();
|
||||
// animator.UnbindAllStreamHandles();
|
||||
// rb.enabled = true;
|
||||
// animator.Rebind();
|
||||
// Log.Out($"#=================Rebuild Finish\n");
|
||||
animator.WriteDefaultValues();
|
||||
|
||||
if (useGraph)
|
||||
{
|
||||
VanillaWrapper = new PlayableWrapper(vanillaControllerPlayable);
|
||||
WeaponWrapper = new PlayableWrapper(weaponControllerPlayable);
|
||||
}
|
||||
else
|
||||
{
|
||||
VanillaWrapper = new AnimatorWrapper(animator);
|
||||
if (target)
|
||||
{
|
||||
WeaponWrapper = new AnimatorWrapper(target.ItemAnimator);
|
||||
}
|
||||
else
|
||||
{
|
||||
WeaponWrapper = DummyWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateChildAnimatorArray(target);
|
||||
UpdateParamMapping();
|
||||
#if NotEditor
|
||||
animator.SetWrappedBool(AvatarController.isCrouchingHash, wasCrouching);
|
||||
if (isFpv)
|
||||
{
|
||||
VanillaWrapper.Play("idle", 0, 0f);
|
||||
VanillaWrapper.SetInteger(AvatarController.weaponHoldTypeHash, -1);
|
||||
}
|
||||
if (wasCrouching && !isFpv && VanillaWrapper.GetLayerCount() > 4)
|
||||
{
|
||||
VanillaWrapper.Play("2HGeneric", 4, 0);
|
||||
}
|
||||
#endif
|
||||
sw.Stop();
|
||||
Log.Out($"changing animation target to {(target ? target.name : "null")} took {sw.ElapsedMilliseconds}");
|
||||
}
|
||||
|
||||
private void UpdateChildAnimatorArray(AnimationTargetsAbs target)
|
||||
{
|
||||
Animator[] childAnimators;
|
||||
if (target && target.ItemCurrentOrDefault)
|
||||
{
|
||||
List<Animator> animators = new List<Animator>();
|
||||
foreach (Transform trans in target.ItemCurrentOrDefault)
|
||||
{
|
||||
animators.AddRange(trans.GetComponentsInChildren<Animator>());
|
||||
}
|
||||
if (target.ItemAnimator)
|
||||
{
|
||||
animators.Remove(target.ItemAnimator);
|
||||
}
|
||||
childAnimators = animators.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
childAnimators = Array.Empty<Animator>();
|
||||
}
|
||||
AttachmentWrapper = new AttachmentWrapper(childAnimators);
|
||||
}
|
||||
|
||||
private void InitBehaviours(Transform weaponRoot)
|
||||
{
|
||||
foreach (var scripts in weaponRoot.GetComponents<IPlayableGraphRelated>())
|
||||
{
|
||||
var behaviour = scripts.Init(transform, isLocalPlayer);
|
||||
if (behaviour)
|
||||
{
|
||||
graphRelatedBehaviours.Add(behaviour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanupBehaviours()
|
||||
{
|
||||
foreach (var behaviour in graphRelatedBehaviours)
|
||||
{
|
||||
if (behaviour)
|
||||
{
|
||||
(behaviour as IPlayableGraphRelated)?.Disable(transform);
|
||||
}
|
||||
}
|
||||
graphRelatedBehaviours.Clear();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SetCurrentTarget(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43f465f7371212e4f8ce8241007afd67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class AnimationProceduralRecoildAbs : MonoBehaviour
|
||||
{
|
||||
public abstract void AddRecoil(Vector3 positionMultiplier, Vector3 rotationMultiplier);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ee261f617ba41e469d725bd8f2cb3c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
163
KFAttached/Animation/MonoBehaviours/AnimationRandomRecoil.cs
Normal file
163
KFAttached/Animation/MonoBehaviours/AnimationRandomRecoil.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using DG.Tweening;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Binding Helpers/Animation Random Recoil")]
|
||||
public class AnimationRandomRecoil : AnimationProceduralRecoildAbs, IPlayableGraphRelated
|
||||
#if UNITY_EDITOR
|
||||
, ISerializationCallbackReceiver
|
||||
#endif
|
||||
{
|
||||
[Header("Targets")]
|
||||
[SerializeField] private Transform target;
|
||||
[SerializeField, HideInInspector] private string targetName;
|
||||
[SerializeField] private Transform pivot;
|
||||
[SerializeField, HideInInspector] private string pivotName;
|
||||
[Header("Rotation")]
|
||||
//[SerializeField] private Vector3 minRotation = new Vector3(-5, -2, -2);
|
||||
//[SerializeField] private Vector3 maxRotation = new Vector3(0, 2, 2);
|
||||
[SerializeField] private Vector3 randomRotationMin = new Vector3(-3, -1, -1);
|
||||
[SerializeField] private Vector3 randomRotationMax = new Vector3(-1, 1, 1);
|
||||
[Header("Kickback")]
|
||||
//[SerializeField] private Vector3 minKickback = new Vector3(0, 0, -0.05f);
|
||||
//[SerializeField] private Vector3 maxKickback = new Vector3(0, 0, 0);
|
||||
[SerializeField] private Vector3 randomKickbackMin = new Vector3(0, 0, -0.025f);
|
||||
[SerializeField] private Vector3 randomKickbackMax = new Vector3(0, 0, -0.01f);
|
||||
[Header("Recoil")]
|
||||
[SerializeField, Range(0, 0.1f)] private float tweenInDuration = 0.04f;
|
||||
[SerializeField, Range(0, 5)] private float tweenOutDuration = 1.5f;
|
||||
[Header("Return")]
|
||||
[SerializeField, Range(1, 5)] private float elasticAmplitude = 1f;
|
||||
[SerializeField, Range(0, 1)] private float elasticPeriod = 0.5f;
|
||||
|
||||
private Vector3 targetRotation = Vector3.zero;
|
||||
private Vector3 targetPosition = Vector3.zero;
|
||||
private Vector3 currentRotation = Vector3.zero;
|
||||
private Vector3 currentPosition = Vector3.zero;
|
||||
private Sequence seq;
|
||||
//private bool isTweeningIn = true;
|
||||
|
||||
public override void AddRecoil(Vector3 positionMultiplier, Vector3 rotationMultiplier)
|
||||
{
|
||||
if (target && pivot)
|
||||
{
|
||||
targetPosition = Vector3.Scale(KFExtensions.Random(randomKickbackMin, randomKickbackMax), positionMultiplier);
|
||||
targetRotation = Vector3.Scale(KFExtensions.Random(randomRotationMin, randomRotationMax), rotationMultiplier);
|
||||
GameObject targetObj = target.gameObject;
|
||||
RecreateSeq();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ResetSeq();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ResetSeq();
|
||||
}
|
||||
|
||||
private void ResetSeq()
|
||||
{
|
||||
seq?.Rewind(false);
|
||||
if (target)
|
||||
{
|
||||
target.localEulerAngles = Vector3.zero;
|
||||
target.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
private void RecreateSeq()
|
||||
{
|
||||
currentPosition = Vector3.zero;
|
||||
currentRotation = Vector3.zero;
|
||||
seq?.Kill(false);
|
||||
seq = DOTween.Sequence()
|
||||
//.InsertCallback(0, () => isTweeningIn = true)
|
||||
.Insert(0, DOTween.To(() => currentRotation, (rot) => currentRotation = rot, targetRotation, tweenInDuration).SetEase(Ease.OutCubic))
|
||||
.Insert(0, DOTween.To(() => currentPosition, (pos) => currentPosition = pos, targetPosition, tweenInDuration).SetEase(Ease.OutCubic))
|
||||
//.InsertCallback(tweenInDuration, () => isTweeningIn = false)
|
||||
.Insert(tweenInDuration, DOTween.To(() => currentRotation, (rot) => currentRotation = rot, Vector3.zero, tweenOutDuration).SetEase(Ease.OutElastic, elasticAmplitude, elasticPeriod))
|
||||
.Insert(tweenInDuration, DOTween.To(() => currentPosition, (rot) => currentPosition = rot, Vector3.zero, tweenOutDuration).SetEase(Ease.OutElastic, elasticAmplitude, elasticPeriod))
|
||||
.OnUpdate(UpdateTransform)
|
||||
.SetAutoKill(true)
|
||||
.SetRecyclable();
|
||||
}
|
||||
|
||||
private void UpdateTransform()
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
target.localEulerAngles = Vector3.zero;
|
||||
target.localPosition = Vector3.zero;
|
||||
target.RotateAroundPivot(pivot, currentRotation);
|
||||
target.localPosition += currentPosition;
|
||||
}
|
||||
|
||||
//if (!isTweeningIn)
|
||||
//{
|
||||
// targetRotation = currentRotation;
|
||||
// targetPosition = currentPosition;
|
||||
//}
|
||||
}
|
||||
|
||||
public MonoBehaviour Init(Transform playerAnimatorTrans, bool isLocalPlayer)
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
var copy = playerAnimatorTrans.AddMissingComponent<AnimationRandomRecoil>();
|
||||
copy.enabled = true;
|
||||
if (target)
|
||||
{
|
||||
copy.target = this.target;
|
||||
}
|
||||
else
|
||||
{
|
||||
copy.target = playerAnimatorTrans.FindInAllChildren(targetName);
|
||||
}
|
||||
if (pivot)
|
||||
{
|
||||
copy.pivot = pivot;
|
||||
}
|
||||
else
|
||||
{
|
||||
copy.pivot = playerAnimatorTrans.FindInAllChildren(pivotName);
|
||||
}
|
||||
copy.randomRotationMin = this.randomRotationMin;
|
||||
copy.randomRotationMax = this.randomRotationMax;
|
||||
copy.randomKickbackMin = this.randomKickbackMin;
|
||||
copy.randomKickbackMax = this.randomKickbackMax;
|
||||
copy.tweenInDuration = this.tweenInDuration;
|
||||
copy.tweenOutDuration = this.tweenOutDuration;
|
||||
copy.elasticAmplitude = this.elasticAmplitude;
|
||||
copy.elasticPeriod = this.elasticPeriod;
|
||||
return copy;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Disable(Transform playerAnimatorTrans)
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
targetName = target.name;
|
||||
}
|
||||
if (pivot)
|
||||
{
|
||||
pivotName = pivot.name;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd683a2a71b72f04f88532f056986903
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
97
KFAttached/Animation/MonoBehaviours/AnimationRandomSound.cs
Normal file
97
KFAttached/Animation/MonoBehaviours/AnimationRandomSound.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Utils/Animation Random Sound")]
|
||||
public class AnimationRandomSound : MonoBehaviour, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField]
|
||||
public List<AudioSourceGroup> audioSourcesEditor;
|
||||
[NonSerialized]
|
||||
private List<AudioSourceGroup> audioSources;
|
||||
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
private List<string> list_groupnames;
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
private List<AudioClip> list_clips;
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
private List<AudioSource> list_sources;
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
private List<int> list_clip_indices;
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
private int serializedCount = 0;
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
audioSources = new List<AudioSourceGroup>();
|
||||
for (int i = 0; i < serializedCount; i++)
|
||||
{
|
||||
int index = (i == 0 ? 0 : list_clip_indices[i - 1]);
|
||||
int count = list_clip_indices[i] - index;
|
||||
audioSources.Add(new AudioSourceGroup()
|
||||
{
|
||||
groupName = list_groupnames[i],
|
||||
clips = list_clips.Skip(index).Take(count).ToArray(),
|
||||
source = list_sources[i],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
if (audioSourcesEditor != null && audioSourcesEditor.Count > 0)
|
||||
{
|
||||
serializedCount = 0;
|
||||
list_groupnames = new List<string>();
|
||||
list_clips = new List<AudioClip>();
|
||||
list_clip_indices = new List<int>();
|
||||
list_sources = new List<AudioSource>();
|
||||
for (int i = 0; i < audioSourcesEditor.Count; i++)
|
||||
{
|
||||
list_groupnames.Add(audioSourcesEditor[i].groupName);
|
||||
list_clips.AddRange(audioSourcesEditor[i].clips);
|
||||
list_sources.Add(audioSourcesEditor[i].source);
|
||||
list_clip_indices.Add(list_clips.Count);
|
||||
serializedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayRandomClip(string group)
|
||||
{
|
||||
if (audioSources == null)
|
||||
return;
|
||||
|
||||
//#if NotEditor
|
||||
// Log.Out($"play random clip {group}, groups: {string.Join("| ", audioSources.Select(g => g.groupName + $"clips: {string.Join(", ", g.clips.Select(c => c.name))}"))}");
|
||||
//#endif
|
||||
AudioSourceGroup asg = null;
|
||||
foreach (var audioSourceGroup in audioSources)
|
||||
{
|
||||
if (audioSourceGroup.groupName == group)
|
||||
{
|
||||
asg = audioSourceGroup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (asg == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int random = Random.Range(0, asg.clips.Length);
|
||||
//asg.source.clip = asg.clips[random];
|
||||
asg.source.PlayOneShot(asg.clips[random]);
|
||||
//#if NotEditor
|
||||
// Log.Out($"play clip {asg.clips[random].name}");
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 517d2eb7e1af8a740a6f8ae7cb775f5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
356
KFAttached/Animation/MonoBehaviours/AnimationReloadEvents.cs
Normal file
356
KFAttached/Animation/MonoBehaviours/AnimationReloadEvents.cs
Normal file
@@ -0,0 +1,356 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib;
|
||||
|
||||
#endif
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Utils/Animation Reload Events")]
|
||||
public class AnimationReloadEvents : MonoBehaviour, IPlayableGraphRelated
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
#if NotEditor
|
||||
player = GetComponentInParent<EntityAlive>();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnReloadFinish()
|
||||
{
|
||||
OnReloadAmmo();
|
||||
OnReloadEnd();
|
||||
}
|
||||
|
||||
public void OnReloadAmmo()
|
||||
{
|
||||
#if NotEditor
|
||||
if (actionData == null || !actionData.isReloading)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.Out($"ANIMATION RELOAD EVENT NOT RELOADING : {actionData?.invData.item.Name ?? "null"}");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (!actionData.isReloadCancelled)
|
||||
{
|
||||
player.MinEventContext.ItemActionData = actionData;
|
||||
ItemValue item = ItemClass.GetItem(actionRanged.MagazineItemNames[actionData.invData.itemValue.SelectedAmmoTypeIndex], false);
|
||||
int magSize = actionRanged.GetMaxAmmoCount(actionData);
|
||||
actionData.reloadAmount = GetAmmoCountToReload(player, item, magSize);
|
||||
if (actionData.reloadAmount > 0)
|
||||
{
|
||||
actionData.invData.itemValue.Meta = Utils.FastMin(actionData.invData.itemValue.Meta + actionData.reloadAmount, magSize);
|
||||
if (actionData.invData.item.Properties.Values[ItemClass.PropSoundIdle] != null)
|
||||
{
|
||||
actionData.invData.holdingEntitySoundID = -1;
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
Log.Out($"ANIMATION RELOAD EVENT AMMO : {actionData.invData.item.Name}");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnReloadEnd()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
animator.SetWrappedBool(Animator.StringToHash("Reload"), false);
|
||||
animator.SetWrappedBool(Animator.StringToHash("IsReloading"), false);
|
||||
animator.speed = 1f;
|
||||
#if NotEditor
|
||||
cancelReloadCo = null;
|
||||
if (actionData == null || !actionData.isReloading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
actionData.isReloading = false;
|
||||
actionData.isWeaponReloading = false;
|
||||
actionData.invData.holdingEntity.MinEventContext.ItemActionData = actionData;
|
||||
actionData.invData.holdingEntity.FireEvent(MinEventTypes.onReloadStop, true);
|
||||
actionData.invData.holdingEntity.OnReloadEnd();
|
||||
actionData.invData.holdingEntity.inventory.CallOnToolbeltChangedInternal();
|
||||
AnimationAmmoUpdateState.SetAmmoCountForEntity(actionData.invData.holdingEntity, actionData.invData.slotIdx);
|
||||
actionData.isReloadCancelled = false;
|
||||
actionData.isWeaponReloadCancelled = false;
|
||||
actionData.isChangingAmmoType = false;
|
||||
if (actionData is IModuleContainerFor<ActionModuleMultiBarrel.MultiBarrelData> dataModule)
|
||||
{
|
||||
dataModule.Instance.SetCurrentBarrel(actionData.invData.itemValue.Meta);
|
||||
}
|
||||
#if DEBUG
|
||||
Log.Out($"ANIMATION RELOAD EVENT FINISHED : {actionData.invData.item.Name}");
|
||||
#endif
|
||||
actionData = null;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnPartialReloadEnd()
|
||||
{
|
||||
#if NotEditor
|
||||
if (actionData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
player.MinEventContext.ItemActionData = actionData;
|
||||
ItemValue ammo = ItemClass.GetItem(actionRanged.MagazineItemNames[actionData.invData.itemValue.SelectedAmmoTypeIndex], false);
|
||||
int magSize = (int)EffectManager.GetValue(PassiveEffects.MagazineSize, actionData.invData.itemValue, (float)actionRanged.BulletsPerMagazine, player);
|
||||
int partialReloadCount = (int)EffectManager.GetValue(CustomEnums.PartialReloadCount, actionData.invData.itemValue, 1, player);
|
||||
actionData.reloadAmount = GetPartialReloadCount(player, ammo, magSize, partialReloadCount);
|
||||
if (actionData.reloadAmount > 0)
|
||||
{
|
||||
actionData.invData.itemValue.Meta = Utils.FastMin(actionData.invData.itemValue.Meta + actionData.reloadAmount, magSize);
|
||||
if (actionData.invData.item.Properties.Values[ItemClass.PropSoundIdle] != null)
|
||||
{
|
||||
actionData.invData.holdingEntitySoundID = -1;
|
||||
}
|
||||
}
|
||||
AnimationAmmoUpdateState.SetAmmoCountForEntity(actionData.invData.holdingEntity, actionData.invData.slotIdx);
|
||||
|
||||
if (actionData.isReloadCancelled || actionData.isWeaponReloadCancelled || actionData.invData.itemValue.Meta >= magSize || player.GetItemCount(ammo) <= 0)
|
||||
{
|
||||
Log.Out("Partial reload finished");
|
||||
animator.SetWrappedBool(Animator.StringToHash("IsReloading"), false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
//public bool ReloadUpdatedThisFrame => reloadUpdatedThisFrame;
|
||||
//private bool reloadUpdatedThisFrame = false;
|
||||
//internal void OnReloadUpdate()
|
||||
//{
|
||||
// reloadUpdatedThisFrame = true;
|
||||
//}
|
||||
|
||||
//private void OnAnimatorMove()
|
||||
//{
|
||||
// if (actionData != null)
|
||||
// {
|
||||
// //if (actionData.isReloading && !reloadUpdatedThisFrame)
|
||||
// //{
|
||||
// // Log.Warning("Animator not sending update msg this frame, reloading is cancelled!");
|
||||
// // actionData.isReloadCancelled = true;
|
||||
// // OnReloadFinish();
|
||||
// //}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //Log.Warning("actionData is null!");
|
||||
// }
|
||||
// reloadUpdatedThisFrame = false;
|
||||
//}
|
||||
|
||||
public void OnReloadStart(int actionIndex)
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
player = GetComponentInParent<EntityAlive>();
|
||||
}
|
||||
actionData = player.inventory.holdingItemData.actionData[actionIndex] as ItemActionRanged.ItemActionDataRanged;
|
||||
actionRanged = (ItemActionRanged)player.inventory.holdingItem.Actions[actionIndex];
|
||||
if (actionData == null || actionData.isReloading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionData.invData.item.Properties.Values[ItemClass.PropSoundIdle] != null && actionData.invData.holdingEntitySoundID >= 0)
|
||||
{
|
||||
Audio.Manager.Stop(actionData.invData.holdingEntity.entityId, actionData.invData.item.Properties.Values[ItemClass.PropSoundIdle]);
|
||||
}
|
||||
actionData.wasAiming = actionData.invData.holdingEntity.AimingGun;
|
||||
if (actionData.invData.holdingEntity.AimingGun && actionData.invData.item.Actions[1] is ItemActionZoom)
|
||||
{
|
||||
actionData.invData.holdingEntity.inventory.Execute(1, false, null);
|
||||
actionData.invData.holdingEntity.inventory.Execute(1, true, null);
|
||||
}
|
||||
if (animator.GetCurrentAnimatorClipInfo(0).Length != 0 && animator.GetCurrentAnimatorClipInfo(0)[0].clip.events.Length == 0)
|
||||
{
|
||||
if (actionRanged.SoundReload != null)
|
||||
{
|
||||
player.PlayOneShot(actionRanged.SoundReload.Value, false);
|
||||
}
|
||||
}
|
||||
else if (animator.GetNextAnimatorClipInfo(0).Length != 0 && animator.GetNextAnimatorClipInfo(0)[0].clip.events.Length == 0 && actionRanged.SoundReload != null)
|
||||
{
|
||||
player.PlayOneShot(actionRanged.SoundReload.Value, false);
|
||||
}
|
||||
|
||||
ItemValue itemValue = actionData.invData.itemValue;
|
||||
actionData.invData.holdingEntity.MinEventContext.ItemActionData = actionData;
|
||||
int magSize = (int)EffectManager.GetValue(PassiveEffects.MagazineSize, itemValue, actionRanged.BulletsPerMagazine, actionData.invData.holdingEntity);
|
||||
ItemActionLauncher itemActionLauncher = actionRanged as ItemActionLauncher;
|
||||
if (itemActionLauncher != null && itemValue.Meta < magSize)
|
||||
{
|
||||
ItemValue ammoValue = ItemClass.GetItem(actionRanged.MagazineItemNames[itemValue.SelectedAmmoTypeIndex], false);
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
Log.Out($"loading ammo {ammoValue.ItemClass.Name}");
|
||||
ItemActionLauncher.ItemActionDataLauncher itemActionDataLauncher = actionData as ItemActionLauncher.ItemActionDataLauncher;
|
||||
if (itemActionDataLauncher.isChangingAmmoType)
|
||||
{
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
Log.Out($"is changing ammo type {itemActionDataLauncher.isChangingAmmoType}");
|
||||
itemActionLauncher.DeleteProjectiles(actionData);
|
||||
itemActionDataLauncher.isChangingAmmoType = false;
|
||||
}
|
||||
int projectileCount = 1;
|
||||
if (!actionData.invData.holdingEntity.isEntityRemote)
|
||||
{
|
||||
projectileCount = (itemActionLauncher.HasInfiniteAmmo(actionData) ? magSize : GetAmmoCount(actionData.invData.holdingEntity, ammoValue, magSize));
|
||||
projectileCount *= getProjectileCount(itemActionDataLauncher);
|
||||
}
|
||||
int times = 1;
|
||||
IModuleContainerFor<ActionModuleMultiBarrel.MultiBarrelData> dataModule = actionData as IModuleContainerFor<ActionModuleMultiBarrel.MultiBarrelData>;
|
||||
if (dataModule != null && dataModule.Instance.oneRoundMultishot)
|
||||
{
|
||||
times = dataModule.Instance.roundsPerShot;
|
||||
}
|
||||
for (int j = itemActionDataLauncher.projectileInstance.Count; j < projectileCount; j++)
|
||||
{
|
||||
for (int i = 0; i < times; i++)
|
||||
{
|
||||
if (dataModule != null)
|
||||
{
|
||||
itemActionDataLauncher.projectileJoint = dataModule.Instance.projectileJoints[i];
|
||||
}
|
||||
itemActionDataLauncher.projectileInstance.Add(itemActionLauncher.instantiateProjectile(actionData, Vector3.zero));
|
||||
}
|
||||
}
|
||||
}
|
||||
actionData.isReloading = true;
|
||||
actionData.isWeaponReloading = true;
|
||||
actionData.invData.holdingEntity.FireEvent(MinEventTypes.onReloadStart, true);
|
||||
#if DEBUG
|
||||
Log.Out($"ANIMATION EVENT RELOAD START : {actionData.invData.item.Name}");
|
||||
#endif
|
||||
}
|
||||
|
||||
private Coroutine cancelReloadCo = null;
|
||||
|
||||
public void DelayForceCancelReload(float delay)
|
||||
{
|
||||
if (cancelReloadCo == null)
|
||||
cancelReloadCo = StartCoroutine(ForceCancelReloadCo(delay));
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (animator)
|
||||
{
|
||||
OnReloadEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ForceCancelReloadCo(float delay)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(delay);
|
||||
if (actionData != null && (actionData.isReloading || actionData.isWeaponReloading) && (actionData.isReloadCancelled || actionData.isWeaponReloadCancelled))
|
||||
OnReloadEnd();
|
||||
cancelReloadCo = null;
|
||||
}
|
||||
|
||||
public int GetAmmoCountToReload(EntityAlive ea, ItemValue ammo, int modifiedMagazineSize)
|
||||
{
|
||||
int meta = actionData.invData.itemValue.Meta;
|
||||
int target = modifiedMagazineSize - meta;
|
||||
if (actionRanged.HasInfiniteAmmo(actionData))
|
||||
{
|
||||
if (actionRanged.AmmoIsPerMagazine)
|
||||
{
|
||||
return modifiedMagazineSize;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
if (ea.bag.GetItemCount(ammo, -1, -1, true) > 0)
|
||||
{
|
||||
if (actionRanged.AmmoIsPerMagazine)
|
||||
{
|
||||
return modifiedMagazineSize * ea.bag.DecItem(ammo, 1, false, null);
|
||||
}
|
||||
res = ea.bag.DecItem(ammo, target, false, null);
|
||||
if (res == target)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
if (actionRanged.AmmoIsPerMagazine)
|
||||
{
|
||||
return modifiedMagazineSize * ea.inventory.DecItem(ammo, 1, false, null);
|
||||
}
|
||||
|
||||
if (ea.inventory.GetItemCount(ammo, false, -1, -1, true) <= 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
return res + actionData.invData.holdingEntity.inventory.DecItem(ammo, target - res, false, null);
|
||||
}
|
||||
|
||||
public int GetPartialReloadCount(EntityAlive ea, ItemValue ammo, int modifiedMagazineSize, int partialReloadCount)
|
||||
{
|
||||
int meta = actionData.invData.itemValue.Meta;
|
||||
int target = Mathf.Min(partialReloadCount, modifiedMagazineSize - meta);
|
||||
if (actionRanged.HasInfiniteAmmo(actionData))
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
if (ea.bag.GetItemCount(ammo) > 0)
|
||||
{
|
||||
res = ea.bag.DecItem(ammo, target);
|
||||
if (res == target)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
if (ea.inventory.GetItemCount(ammo) <= 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
return res + actionData.invData.holdingEntity.inventory.DecItem(ammo, target - res);
|
||||
}
|
||||
|
||||
public int GetAmmoCount(EntityAlive ea, ItemValue ammo, int modifiedMagazineSize)
|
||||
{
|
||||
return Mathf.Min(ea.bag.GetItemCount(ammo, -1, -1, true) + ea.inventory.GetItemCount(ammo, false, -1, -1, true) + actionData.invData.itemValue.Meta, modifiedMagazineSize);
|
||||
}
|
||||
|
||||
public int getProjectileCount(ItemActionData _data)
|
||||
{
|
||||
int rps = 1;
|
||||
ItemInventoryData invD = _data != null ? _data.invData : null;
|
||||
if (invD != null)
|
||||
{
|
||||
ItemClass item = invD.itemValue != null ? invD.itemValue.ItemClass : null;
|
||||
rps = (int)EffectManager.GetValue(PassiveEffects.RoundRayCount, invD.itemValue, rps, invD.holdingEntity);
|
||||
}
|
||||
return rps > 0 ? rps : 1;
|
||||
}
|
||||
|
||||
public EntityAlive player;
|
||||
public ItemActionRanged.ItemActionDataRanged actionData;
|
||||
public ItemActionRanged actionRanged;
|
||||
#endif
|
||||
private Animator animator;
|
||||
|
||||
public MonoBehaviour Init(Transform playerAnimatorTrans, bool isLocalPlayer)
|
||||
{
|
||||
var copy = playerAnimatorTrans.AddMissingComponent<AnimationReloadEvents>();
|
||||
if (copy)
|
||||
{
|
||||
copy.enabled = true;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void Disable(Transform playerAnimatorTrans)
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c245bc8d9e873ae40ac1f6078f9611c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationSmokeParticle : MonoBehaviour
|
||||
{
|
||||
private ParticleSystem ps;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (!TryGetComponent(out ps))
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ps.Clear(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 173c51f67c407a94388cc82dddafc06f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/Animation/MonoBehaviours/AnimatorWrapper.meta
Normal file
8
KFAttached/Animation/MonoBehaviours/AnimatorWrapper.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74718732aa3d8274fb470008c5d9e819
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,131 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimatorWrapper : IAnimatorWrapper
|
||||
{
|
||||
private Animator animator;
|
||||
|
||||
public bool IsValid => animator;
|
||||
|
||||
public AnimatorWrapper(Animator animator) => this.animator = animator;
|
||||
|
||||
public void CrossFade(string stateName, float transitionDuration) => animator.CrossFade(stateName, transitionDuration);
|
||||
|
||||
public void CrossFade(string stateName, float transitionDuration, int layer) => animator.CrossFade(stateName, transitionDuration, layer);
|
||||
|
||||
public void CrossFade(string stateName, float transitionDuration, int layer, float normalizedTime) => animator.CrossFade(stateName, transitionDuration, layer, normalizedTime);
|
||||
|
||||
public void CrossFade(int stateNameHash, float transitionDuration) => animator.CrossFade(stateNameHash, transitionDuration);
|
||||
|
||||
public void CrossFade(int stateNameHash, float transitionDuration, int layer) => animator.CrossFade(stateNameHash, transitionDuration, layer);
|
||||
|
||||
public void CrossFade(int stateNameHash, float transitionDuration, int layer, float normalizedTime) => animator.CrossFade(stateNameHash, transitionDuration, layer, normalizedTime);
|
||||
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration) => animator.CrossFadeInFixedTime(stateName, transitionDuration);
|
||||
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer) => animator.CrossFadeInFixedTime(stateName, transitionDuration, layer);
|
||||
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer, float fixedTime) => animator.CrossFadeInFixedTime(stateName, transitionDuration, layer, fixedTime);
|
||||
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration) => animator.CrossFadeInFixedTime(stateNameHash, transitionDuration);
|
||||
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer) => animator.CrossFadeInFixedTime(stateNameHash, transitionDuration, layer);
|
||||
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer, float fixedTime) => animator.CrossFadeInFixedTime(stateNameHash, transitionDuration, layer, fixedTime);
|
||||
|
||||
public AnimatorTransitionInfo GetAnimatorTransitionInfo(int layerIndex) => animator.GetAnimatorTransitionInfo(layerIndex);
|
||||
|
||||
public bool GetBool(string name) => animator.GetBool(name);
|
||||
|
||||
public bool GetBool(int id) => animator.GetBool(id);
|
||||
|
||||
public AnimatorClipInfo[] GetCurrentAnimatorClipInfo(int layerIndex) => animator.GetCurrentAnimatorClipInfo(layerIndex);
|
||||
|
||||
public void GetCurrentAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips) => animator.GetCurrentAnimatorClipInfo(layerIndex, clips);
|
||||
|
||||
public int GetCurrentAnimatorClipInfoCount(int layerIndex) => animator.GetCurrentAnimatorClipInfoCount(layerIndex);
|
||||
|
||||
public AnimatorStateInfo GetCurrentAnimatorStateInfo(int layerIndex) => animator.GetCurrentAnimatorStateInfo(layerIndex);
|
||||
|
||||
public float GetFloat(string name) => animator.GetFloat(name);
|
||||
|
||||
public float GetFloat(int id) => animator.GetFloat(id);
|
||||
|
||||
public int GetInteger(string name) => animator.GetInteger(name);
|
||||
|
||||
public int GetInteger(int id) => animator.GetInteger(id);
|
||||
|
||||
public int GetLayerCount() => animator.layerCount;
|
||||
|
||||
public int GetLayerIndex(string layerName) => animator.GetLayerIndex(layerName);
|
||||
|
||||
public string GetLayerName(int layerIndex) => animator.GetLayerName(layerIndex);
|
||||
|
||||
public float GetLayerWeight(int layerIndex) => animator.GetLayerWeight(layerIndex);
|
||||
|
||||
public void GetNextAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips) => animator.GetNextAnimatorClipInfo(layerIndex, clips);
|
||||
|
||||
public AnimatorClipInfo[] GetNextAnimatorClipInfo(int layerIndex) => animator.GetNextAnimatorClipInfo(layerIndex);
|
||||
|
||||
public int GetNextAnimatorClipInfoCount(int layerIndex) => animator.GetNextAnimatorClipInfoCount(layerIndex);
|
||||
|
||||
public AnimatorStateInfo GetNextAnimatorStateInfo(int layerIndex) => animator.GetNextAnimatorStateInfo(layerIndex);
|
||||
|
||||
public AnimatorControllerParameter GetParameter(int index) => animator.GetParameter(index);
|
||||
|
||||
public int GetParameterCount() => animator.parameterCount;
|
||||
|
||||
public bool HasState(int layerIndex, int stateID) => animator.HasState(layerIndex, stateID);
|
||||
|
||||
public bool IsInTransition(int layerIndex) => animator.IsInTransition(layerIndex);
|
||||
|
||||
public bool IsParameterControlledByCurve(string name) => animator.IsParameterControlledByCurve(name);
|
||||
|
||||
public bool IsParameterControlledByCurve(int id) => animator.IsParameterControlledByCurve(id);
|
||||
|
||||
public void Play(string stateName) => animator.Play(stateName);
|
||||
|
||||
public void Play(string stateName, int layer) => animator.Play(stateName, layer);
|
||||
|
||||
public void Play(string stateName, int layer, float normalizedTime) => animator.Play(stateName, layer, normalizedTime);
|
||||
|
||||
public void Play(int stateNameHash) => animator.Play(stateNameHash);
|
||||
|
||||
public void Play(int stateNameHash, int layer) => animator.Play(stateNameHash, layer);
|
||||
|
||||
public void Play(int stateNameHash, int layer, float normalizedTime) => animator.Play(stateNameHash, layer, normalizedTime);
|
||||
|
||||
public void PlayInFixedTime(string stateName) => animator.PlayInFixedTime(stateName);
|
||||
|
||||
public void PlayInFixedTime(string stateName, int layer) => animator.PlayInFixedTime(stateName, layer);
|
||||
|
||||
public void PlayInFixedTime(string stateName, int layer, float fixedTime) => animator.PlayInFixedTime(stateName, layer, fixedTime);
|
||||
|
||||
public void PlayInFixedTime(int stateNameHash) => animator.PlayInFixedTime(stateNameHash);
|
||||
|
||||
public void PlayInFixedTime(int stateNameHash, int layer) => animator.PlayInFixedTime(stateNameHash, layer);
|
||||
|
||||
public void PlayInFixedTime(int stateNameHash, int layer, float fixedTime) => animator.PlayInFixedTime(stateNameHash, layer, fixedTime);
|
||||
|
||||
public void ResetTrigger(string name) => animator.ResetTrigger(name);
|
||||
|
||||
public void ResetTrigger(int id) => animator.ResetTrigger(id);
|
||||
|
||||
public void SetBool(string name, bool value) => animator.SetBool(name, value);
|
||||
|
||||
public void SetBool(int id, bool value) => animator.SetBool(id, value);
|
||||
|
||||
public void SetFloat(string name, float value) => animator.SetFloat(name, value);
|
||||
|
||||
public void SetFloat(int id, float value) => animator.SetFloat(id, value);
|
||||
|
||||
public void SetInteger(string name, int value) => animator.SetInteger(name, value);
|
||||
|
||||
public void SetInteger(int id, int value) => animator.SetInteger(id, value);
|
||||
|
||||
public void SetLayerWeight(int layerIndex, float weight) => animator.SetLayerWeight(layerIndex, weight);
|
||||
|
||||
public void SetTrigger(string name) => animator.SetTrigger(name);
|
||||
|
||||
public void SetTrigger(int id) => animator.SetTrigger(id);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 330523dd2a309f042a9aafdb565149c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,443 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class AttachmentWrapper : IAnimatorWrapper
|
||||
{
|
||||
public Animator[] animators;
|
||||
public AttachmentWrapper(Animator[] animators)
|
||||
{
|
||||
this.animators = animators;
|
||||
}
|
||||
|
||||
public bool IsValid => animators != null && animators.Length > 0;
|
||||
|
||||
public void CrossFade(string stateName, float transitionDuration)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFade(stateName, transitionDuration);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFade(string stateName, float transitionDuration, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFade(stateName, transitionDuration, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFade(string stateName, float transitionDuration, int layer, float normalizedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFade(stateName, transitionDuration, layer, normalizedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFade(int stateNameHash, float transitionDuration)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFade(stateNameHash, transitionDuration);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFade(int stateNameHash, float transitionDuration, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFade(stateNameHash, transitionDuration, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFade(int stateNameHash, float transitionDuration, int layer, float normalizedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFade(stateNameHash, transitionDuration, layer, normalizedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFadeInFixedTime(stateName, transitionDuration);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFadeInFixedTime(stateName, transitionDuration, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer, float fixedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFadeInFixedTime(stateName, transitionDuration, layer, fixedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFadeInFixedTime(stateNameHash, transitionDuration);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFadeInFixedTime(stateNameHash, transitionDuration, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer, float fixedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.CrossFadeInFixedTime(stateNameHash, transitionDuration, layer, fixedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public AnimatorTransitionInfo GetAnimatorTransitionInfo(int layerIndex)
|
||||
{
|
||||
return animators[0].GetAnimatorTransitionInfo(layerIndex);
|
||||
}
|
||||
|
||||
public bool GetBool(string name)
|
||||
{
|
||||
return GetBool(Animator.StringToHash(name));
|
||||
}
|
||||
|
||||
public bool GetBool(int id)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
if (animator.GetBool(id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public AnimatorClipInfo[] GetCurrentAnimatorClipInfo(int layerIndex)
|
||||
{
|
||||
return animators[0].GetCurrentAnimatorClipInfo(layerIndex);
|
||||
}
|
||||
|
||||
public void GetCurrentAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips)
|
||||
{
|
||||
animators[0].GetCurrentAnimatorClipInfo(layerIndex, clips);
|
||||
}
|
||||
|
||||
public int GetCurrentAnimatorClipInfoCount(int layerIndex)
|
||||
{
|
||||
return animators[0].GetCurrentAnimatorClipInfoCount(layerIndex);
|
||||
}
|
||||
|
||||
public AnimatorStateInfo GetCurrentAnimatorStateInfo(int layerIndex)
|
||||
{
|
||||
return animators[0].GetCurrentAnimatorStateInfo(layerIndex);
|
||||
}
|
||||
|
||||
public float GetFloat(string name)
|
||||
{
|
||||
return GetFloat(Animator.StringToHash(name));
|
||||
}
|
||||
|
||||
public float GetFloat(int id)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
float value = animator.GetFloat(id);
|
||||
if (value != 0)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int GetInteger(string name)
|
||||
{
|
||||
return GetInteger(Animator.StringToHash(name));
|
||||
}
|
||||
|
||||
public int GetInteger(int id)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
int value = animator.GetInteger(id);
|
||||
if (value != 0)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int GetLayerCount()
|
||||
{
|
||||
return animators[0].layerCount;
|
||||
}
|
||||
|
||||
public int GetLayerIndex(string layerName)
|
||||
{
|
||||
return animators[0].GetLayerIndex(layerName);
|
||||
}
|
||||
|
||||
public string GetLayerName(int layerIndex)
|
||||
{
|
||||
return animators[0].GetLayerName(layerIndex);
|
||||
}
|
||||
|
||||
public float GetLayerWeight(int layerIndex)
|
||||
{
|
||||
return animators[0].GetLayerWeight(layerIndex);
|
||||
}
|
||||
|
||||
public void GetNextAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips)
|
||||
{
|
||||
animators[0].GetNextAnimatorClipInfo(layerIndex, clips);
|
||||
}
|
||||
|
||||
public AnimatorClipInfo[] GetNextAnimatorClipInfo(int layerIndex)
|
||||
{
|
||||
return animators[0].GetNextAnimatorClipInfo(layerIndex);
|
||||
}
|
||||
|
||||
public int GetNextAnimatorClipInfoCount(int layerIndex)
|
||||
{
|
||||
return animators[0].GetNextAnimatorClipInfoCount(layerIndex);
|
||||
}
|
||||
|
||||
public AnimatorStateInfo GetNextAnimatorStateInfo(int layerIndex)
|
||||
{
|
||||
return animators[0].GetNextAnimatorStateInfo(layerIndex);
|
||||
}
|
||||
|
||||
public AnimatorControllerParameter GetParameter(int index)
|
||||
{
|
||||
return animators[0].GetParameter(index);
|
||||
}
|
||||
|
||||
public int GetParameterCount()
|
||||
{
|
||||
return animators[0].parameterCount;
|
||||
}
|
||||
|
||||
public bool HasState(int layerIndex, int stateID)
|
||||
{
|
||||
return animators[0].HasState(layerIndex, stateID);
|
||||
}
|
||||
|
||||
public bool IsInTransition(int layerIndex)
|
||||
{
|
||||
return animators[0].IsInTransition(layerIndex);
|
||||
}
|
||||
|
||||
public bool IsParameterControlledByCurve(string name)
|
||||
{
|
||||
return animators[0].IsParameterControlledByCurve(name);
|
||||
}
|
||||
|
||||
public bool IsParameterControlledByCurve(int id)
|
||||
{
|
||||
return animators[0].IsParameterControlledByCurve(id);
|
||||
}
|
||||
|
||||
public void Play(string stateName)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.Play(stateName);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string stateName, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.Play(stateName, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string stateName, int layer, float normalizedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.Play(stateName, layer, normalizedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(int stateNameHash)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.Play(stateNameHash);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(int stateNameHash, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.Play(stateNameHash, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(int stateNameHash, int layer, float normalizedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.Play(stateNameHash, layer, normalizedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayInFixedTime(string stateName)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.PlayInFixedTime(stateName);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayInFixedTime(string stateName, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.PlayInFixedTime(stateName, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayInFixedTime(string stateName, int layer, float fixedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.PlayInFixedTime(stateName, layer, fixedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayInFixedTime(int stateNameHash)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.PlayInFixedTime(stateNameHash);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayInFixedTime(int stateNameHash, int layer)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.PlayInFixedTime(stateNameHash, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayInFixedTime(int stateNameHash, int layer, float fixedTime)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.PlayInFixedTime(stateNameHash, layer, fixedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetTrigger(string name)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.ResetTrigger(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetTrigger(int id)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.ResetTrigger(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBool(string name, bool value)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetBool(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBool(int id, bool value)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetBool(id, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFloat(string name, float value)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetFloat(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFloat(int id, float value)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetFloat(id, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInteger(string name, int value)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetInteger(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInteger(int id, int value)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetInteger(id, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLayerWeight(int layerIndex, float weight)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetLayerWeight(layerIndex, weight);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTrigger(string name)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetTrigger(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTrigger(int id)
|
||||
{
|
||||
foreach (var animator in animators)
|
||||
{
|
||||
animator.SetTrigger(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9aff1989baed1884fb65a80108d5ab68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,92 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
public class PlayableWrapper : IAnimatorWrapper
|
||||
{
|
||||
private AnimatorControllerPlayable playable;
|
||||
|
||||
public PlayableWrapper(AnimatorControllerPlayable playable)
|
||||
{
|
||||
this.playable = playable;
|
||||
}
|
||||
|
||||
public bool IsValid => playable.IsValid();
|
||||
|
||||
public float GetFloat(string name) => playable.GetFloat(name);
|
||||
public float GetFloat(int id) => playable.GetFloat(id);
|
||||
public void SetFloat(string name, float value) => playable.SetFloat(name, value);
|
||||
public void SetFloat(int id, float value) => playable.SetFloat(id, value);
|
||||
|
||||
public bool GetBool(string name) => playable.GetBool(name);
|
||||
public bool GetBool(int id) => playable.GetBool(id);
|
||||
public void SetBool(string name, bool value) => playable.SetBool(name, value);
|
||||
public void SetBool(int id, bool value) => playable.SetBool(id, value);
|
||||
|
||||
public int GetInteger(string name) => playable.GetInteger(name);
|
||||
public int GetInteger(int id) => playable.GetInteger(id);
|
||||
public void SetInteger(string name, int value) => playable.SetInteger(name, value);
|
||||
public void SetInteger(int id, int value) => playable.SetInteger(id, value);
|
||||
|
||||
public void SetTrigger(string name) => playable.SetTrigger(name);
|
||||
public void SetTrigger(int id) => playable.SetTrigger(id);
|
||||
public void ResetTrigger(string name) => playable.ResetTrigger(name);
|
||||
public void ResetTrigger(int id) => playable.ResetTrigger(id);
|
||||
|
||||
public bool IsParameterControlledByCurve(string name) => playable.IsParameterControlledByCurve(name);
|
||||
public bool IsParameterControlledByCurve(int id) => playable.IsParameterControlledByCurve(id);
|
||||
|
||||
public int GetLayerCount() => playable.GetLayerCount();
|
||||
public string GetLayerName(int layerIndex) => playable.GetLayerName(layerIndex);
|
||||
public int GetLayerIndex(string layerName) => playable.GetLayerIndex(layerName);
|
||||
public float GetLayerWeight(int layerIndex) => playable.GetLayerWeight(layerIndex);
|
||||
public void SetLayerWeight(int layerIndex, float weight) => playable.SetLayerWeight(layerIndex, weight);
|
||||
|
||||
public AnimatorStateInfo GetCurrentAnimatorStateInfo(int layerIndex) => playable.GetCurrentAnimatorStateInfo(layerIndex);
|
||||
public AnimatorStateInfo GetNextAnimatorStateInfo(int layerIndex) => playable.GetNextAnimatorStateInfo(layerIndex);
|
||||
public AnimatorTransitionInfo GetAnimatorTransitionInfo(int layerIndex) => playable.GetAnimatorTransitionInfo(layerIndex);
|
||||
|
||||
public AnimatorClipInfo[] GetCurrentAnimatorClipInfo(int layerIndex) => playable.GetCurrentAnimatorClipInfo(layerIndex);
|
||||
public void GetCurrentAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips) => playable.GetCurrentAnimatorClipInfo(layerIndex, clips);
|
||||
public void GetNextAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips) => playable.GetNextAnimatorClipInfo(layerIndex, clips);
|
||||
public int GetCurrentAnimatorClipInfoCount(int layerIndex) => playable.GetCurrentAnimatorClipInfoCount(layerIndex);
|
||||
public int GetNextAnimatorClipInfoCount(int layerIndex) => playable.GetNextAnimatorClipInfoCount(layerIndex);
|
||||
public AnimatorClipInfo[] GetNextAnimatorClipInfo(int layerIndex) => playable.GetNextAnimatorClipInfo(layerIndex);
|
||||
|
||||
public bool IsInTransition(int layerIndex) => playable.IsInTransition(layerIndex);
|
||||
|
||||
public int GetParameterCount() => playable.GetParameterCount();
|
||||
public AnimatorControllerParameter GetParameter(int index) => playable.GetParameter(index);
|
||||
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration) => playable.CrossFadeInFixedTime(stateName, transitionDuration);
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer) => playable.CrossFadeInFixedTime(stateName, transitionDuration, layer);
|
||||
public void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer, float fixedTime) => playable.CrossFadeInFixedTime(stateName, transitionDuration, layer, fixedTime);
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration) => playable.CrossFadeInFixedTime(stateNameHash, transitionDuration);
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer) => playable.CrossFadeInFixedTime(stateNameHash, transitionDuration, layer);
|
||||
public void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer, float fixedTime) => playable.CrossFadeInFixedTime(stateNameHash, transitionDuration, layer, fixedTime);
|
||||
|
||||
public void CrossFade(string stateName, float transitionDuration) => playable.CrossFade(stateName, transitionDuration);
|
||||
public void CrossFade(string stateName, float transitionDuration, int layer) => playable.CrossFade(stateName, transitionDuration, layer);
|
||||
public void CrossFade(string stateName, float transitionDuration, int layer, float normalizedTime) => playable.CrossFade(stateName, transitionDuration, layer, normalizedTime);
|
||||
public void CrossFade(int stateNameHash, float transitionDuration) => playable.CrossFade(stateNameHash, transitionDuration);
|
||||
public void CrossFade(int stateNameHash, float transitionDuration, int layer) => playable.CrossFade(stateNameHash, transitionDuration, layer);
|
||||
public void CrossFade(int stateNameHash, float transitionDuration, int layer, float normalizedTime) => playable.CrossFade(stateNameHash, transitionDuration, layer, normalizedTime);
|
||||
|
||||
public void PlayInFixedTime(string stateName) => playable.PlayInFixedTime(stateName);
|
||||
public void PlayInFixedTime(string stateName, int layer) => playable.PlayInFixedTime(stateName, layer);
|
||||
public void PlayInFixedTime(string stateName, int layer, float fixedTime) => playable.PlayInFixedTime(stateName, layer, fixedTime);
|
||||
public void PlayInFixedTime(int stateNameHash) => playable.PlayInFixedTime(stateNameHash);
|
||||
public void PlayInFixedTime(int stateNameHash, int layer) => playable.PlayInFixedTime(stateNameHash, layer);
|
||||
public void PlayInFixedTime(int stateNameHash, int layer, float fixedTime) => playable.PlayInFixedTime(stateNameHash, layer, fixedTime);
|
||||
|
||||
public void Play(string stateName) => playable.Play(stateName);
|
||||
public void Play(string stateName, int layer) => playable.Play(stateName, layer);
|
||||
public void Play(string stateName, int layer, float normalizedTime) => playable.Play(stateName, layer, normalizedTime);
|
||||
public void Play(int stateNameHash) => playable.Play(stateNameHash);
|
||||
public void Play(int stateNameHash, int layer) => playable.Play(stateNameHash, layer);
|
||||
public void Play(int stateNameHash, int layer, float normalizedTime) => playable.Play(stateNameHash, layer, normalizedTime);
|
||||
|
||||
public bool HasState(int layerIndex, int stateID) => playable.HasState(layerIndex, stateID);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af94698a131639a4ba070db09410d746
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
73
KFAttached/Animation/MonoBehaviours/IAnimatorWrapper.cs
Normal file
73
KFAttached/Animation/MonoBehaviours/IAnimatorWrapper.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
public interface IAnimatorWrapper
|
||||
{
|
||||
bool IsValid { get; }
|
||||
float GetFloat(string name);
|
||||
float GetFloat(int id);
|
||||
void SetFloat(string name, float value);
|
||||
void SetFloat(int id, float value);
|
||||
bool GetBool(string name);
|
||||
bool GetBool(int id);
|
||||
void SetBool(string name, bool value);
|
||||
void SetBool(int id, bool value);
|
||||
int GetInteger(string name);
|
||||
int GetInteger(int id);
|
||||
void SetInteger(string name, int value);
|
||||
void SetInteger(int id, int value);
|
||||
void SetTrigger(string name);
|
||||
void SetTrigger(int id);
|
||||
void ResetTrigger(string name);
|
||||
void ResetTrigger(int id);
|
||||
bool IsParameterControlledByCurve(string name);
|
||||
bool IsParameterControlledByCurve(int id);
|
||||
int GetLayerCount();
|
||||
string GetLayerName(int layerIndex);
|
||||
int GetLayerIndex(string layerName);
|
||||
float GetLayerWeight(int layerIndex);
|
||||
void SetLayerWeight(int layerIndex, float weight);
|
||||
AnimatorStateInfo GetCurrentAnimatorStateInfo(int layerIndex);
|
||||
AnimatorStateInfo GetNextAnimatorStateInfo(int layerIndex);
|
||||
AnimatorTransitionInfo GetAnimatorTransitionInfo(int layerIndex);
|
||||
AnimatorClipInfo[] GetCurrentAnimatorClipInfo(int layerIndex);
|
||||
void GetCurrentAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips);
|
||||
void GetNextAnimatorClipInfo(int layerIndex, List<AnimatorClipInfo> clips);
|
||||
int GetCurrentAnimatorClipInfoCount(int layerIndex);
|
||||
int GetNextAnimatorClipInfoCount(int layerIndex);
|
||||
AnimatorClipInfo[] GetNextAnimatorClipInfo(int layerIndex);
|
||||
bool IsInTransition(int layerIndex);
|
||||
int GetParameterCount();
|
||||
AnimatorControllerParameter GetParameter(int index);
|
||||
void CrossFadeInFixedTime(string stateName, float transitionDuration);
|
||||
void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer);
|
||||
void CrossFadeInFixedTime(string stateName, float transitionDuration, int layer, float fixedTime);
|
||||
void CrossFadeInFixedTime(int stateNameHash, float transitionDuration);
|
||||
void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer);
|
||||
void CrossFadeInFixedTime(int stateNameHash, float transitionDuration, int layer, float fixedTime);
|
||||
void CrossFade(string stateName, float transitionDuration);
|
||||
void CrossFade(string stateName, float transitionDuration, int layer);
|
||||
void CrossFade(string stateName, float transitionDuration, int layer, float normalizedTime);
|
||||
void CrossFade(int stateNameHash, float transitionDuration);
|
||||
void CrossFade(int stateNameHash, float transitionDuration, int layer);
|
||||
void CrossFade(int stateNameHash, float transitionDuration, int layer, float normalizedTime);
|
||||
void PlayInFixedTime(string stateName);
|
||||
void PlayInFixedTime(string stateName, int layer);
|
||||
void PlayInFixedTime(string stateName, int layer, float fixedTime);
|
||||
void PlayInFixedTime(int stateNameHash);
|
||||
void PlayInFixedTime(int stateNameHash, int layer);
|
||||
void PlayInFixedTime(int stateNameHash, int layer, float fixedTime);
|
||||
void Play(string stateName);
|
||||
void Play(string stateName, int layer);
|
||||
void Play(string stateName, int layer, float normalizedTime);
|
||||
void Play(int stateNameHash);
|
||||
void Play(int stateNameHash, int layer);
|
||||
void Play(int stateNameHash, int layer, float normalizedTime);
|
||||
bool HasState(int layerIndex, int stateID);
|
||||
}
|
||||
11
KFAttached/Animation/MonoBehaviours/IAnimatorWrapper.cs.meta
Normal file
11
KFAttached/Animation/MonoBehaviours/IAnimatorWrapper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b52da8de87636d42aa5130c88c5fe4d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
public interface IPlayableGraphRelated
|
||||
{
|
||||
MonoBehaviour Init(Transform playerAnimatorTrans, bool isLocalPlayer);
|
||||
void Disable(Transform playerAnimatorTrans);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 952699e2d9986c94bb12291f3d5e948a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
123
KFAttached/Animation/MonoBehaviours/RigWeightOverTime.cs
Normal file
123
KFAttached/Animation/MonoBehaviours/RigWeightOverTime.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Utils/Rig Weight Over Time")]
|
||||
public class RigWeightOverTime : MonoBehaviour
|
||||
{
|
||||
//[SerializeField]
|
||||
//private Transform source;
|
||||
//[SerializeField]
|
||||
//private Transform target;
|
||||
[SerializeReference]
|
||||
private Rig[] rigs;
|
||||
//[SerializeField]
|
||||
//private float distanceThreshold;
|
||||
//[SerializeField]
|
||||
//private float distanceMax;
|
||||
//private float distanceRange;
|
||||
|
||||
private (Coroutine co, bool active) copair;
|
||||
////[SerializeField]
|
||||
////private bool logDistance = false;
|
||||
|
||||
//private void Awake()
|
||||
//{
|
||||
// distanceRange = distanceMax - distanceThreshold;
|
||||
// if (distanceRange == 0)
|
||||
// {
|
||||
// throw new DivideByZeroException("Max distance is equal to threshold distance!");
|
||||
// }
|
||||
//}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
if (rigs != null)
|
||||
{
|
||||
SetWeight(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
if (copair.co != null)
|
||||
{
|
||||
StopCoroutine(copair.co);
|
||||
}
|
||||
SetWeight(0);
|
||||
}
|
||||
|
||||
public void SetRigWeight(AnimationEvent ev)
|
||||
{
|
||||
if (copair.co != null)
|
||||
{
|
||||
StopCoroutine(copair.co);
|
||||
}
|
||||
bool active = Convert.ToBoolean(ev.intParameter);
|
||||
copair = (StartCoroutine(UpdateWeight(ev.floatParameter, active)), active);
|
||||
}
|
||||
|
||||
private IEnumerator UpdateWeight(float time, bool active)
|
||||
{
|
||||
if (rigs == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (time == 0)
|
||||
{
|
||||
SetWeight(active ? 1 : 0);
|
||||
yield break;
|
||||
}
|
||||
|
||||
float curTime = 0;
|
||||
while (curTime < time)
|
||||
{
|
||||
float ratio = curTime / time;
|
||||
float weight = Mathf.Lerp(0, 1, active ? ratio : (1 - ratio));
|
||||
SetWeight(weight);
|
||||
curTime += Time.deltaTime;
|
||||
Log.Out("Set weight: " + weight);
|
||||
yield return null;
|
||||
}
|
||||
SetWeight(active ? 1 : 0);
|
||||
}
|
||||
|
||||
public void SetWeight(float weight)
|
||||
{
|
||||
foreach (var rig in rigs)
|
||||
{
|
||||
rig.weight = weight;
|
||||
}
|
||||
}
|
||||
|
||||
// private void Update()
|
||||
// {
|
||||
// StartCoroutine(UpdateWeight());
|
||||
// }
|
||||
|
||||
// private IEnumerator UpdateWeight()
|
||||
// {
|
||||
// if(distanceRange == 0 || rigs == null)
|
||||
// {
|
||||
// yield break;
|
||||
// }
|
||||
// yield return new WaitForEndOfFrame();
|
||||
// float distance = Vector3.Distance(source.position, target.position);
|
||||
// float weight = Mathf.Lerp(0, 1, (distanceMax - distance) / distanceRange);
|
||||
// foreach (Rig rig in rigs)
|
||||
// {
|
||||
// rig.weight = Mathf.Lerp(rig.weight, weight, 0.5f);
|
||||
// if(weight > 0 && weight < 1)
|
||||
// Log.Out("ratio: " + ((distanceMax - distance) / distanceRange).ToString() + " weight: " + weight.ToString());
|
||||
// }
|
||||
|
||||
//#if UNITY_EDITOR
|
||||
// if (logDistance)
|
||||
// {
|
||||
// Log.Out(Vector3.Distance(source.position, target.position).ToString());
|
||||
// }
|
||||
//#endif
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b22553f7e0b6104dac02ca4c8af2c99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/Animation/StateMachineBehaviours.meta
Normal file
8
KFAttached/Animation/StateMachineBehaviours.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 664ef95b745768746a23509d7b250fdd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationAimRecoilResetState : StateMachineBehaviour
|
||||
{
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.GetComponent<AnimationAimRecoilReferences>()?.Rollback();
|
||||
}
|
||||
|
||||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.GetComponent<AnimationAimRecoilReferences>()?.Rollback();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 248236ebc388e4c4d8e3f700b7444ab6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib.Scripts.StaticManagers;
|
||||
using KFCommonUtilityLib.Scripts.Utilities;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationAmmoUpdateState : StateMachineBehaviour
|
||||
{
|
||||
#if NotEditor
|
||||
private static int[] hash_states = new[]
|
||||
{
|
||||
Animator.StringToHash("ammoCount"),
|
||||
Animator.StringToHash("ammoCount1"),
|
||||
Animator.StringToHash("ammoCount2"),
|
||||
Animator.StringToHash("ammoCount3"),
|
||||
Animator.StringToHash("ammoCount4")
|
||||
};
|
||||
private InventorySlotGurad slotGuard = new InventorySlotGurad();
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
//var player = GameManager.Instance.World?.GetPrimaryPlayer();
|
||||
var player = animator.GetComponentInParent<EntityAlive>();
|
||||
if(slotGuard.IsValid(player))
|
||||
{
|
||||
SetAmmoCountForEntity(player, slotGuard.Slot);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetAmmoCountForEntity(EntityAlive entity, int slot)
|
||||
{
|
||||
if (entity)
|
||||
{
|
||||
var invData = entity.inventory?.slots?[slot];
|
||||
if (invData?.actionData != null)
|
||||
{
|
||||
var mapping = MultiActionManager.GetMappingForEntity(entity.entityId);
|
||||
if (mapping != null)
|
||||
{
|
||||
var metaIndices = mapping.indices;
|
||||
for (int i = 0; i < mapping.ModeCount; i++)
|
||||
{
|
||||
int metaIndex = metaIndices.GetMetaIndexForMode(i);
|
||||
int meta = invData.itemValue.GetMetaByMode(i);
|
||||
entity.emodel.avatarController.UpdateInt(hash_states[metaIndex], meta);
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
{
|
||||
Log.Out($"Setting ammoCount{(metaIndex > 0 ? metaIndex.ToString() : "")} to {meta}, stack trace:\n{StackTraceUtility.ExtractStackTrace()}");
|
||||
}
|
||||
//animator.SetInteger(hash_states[metaIndex], meta);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.emodel.avatarController.UpdateInt(hash_states[0], invData.itemValue.Meta);
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
{
|
||||
Log.Out($"Setting ammoCount to {invData.itemValue.Meta}, stack trace:\n{StackTraceUtility.ExtractStackTrace()}");
|
||||
}
|
||||
//animator.SetInteger(hash_states[0], entity.inventory.holdingItemItemValue.Meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87658b6a8bedcd14e83febff2157048c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,266 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
#endif
|
||||
|
||||
public class AnimationCustomMeleeAttackState : StateMachineBehaviour
|
||||
#if UNITY_EDITOR
|
||||
, ISerializationCallbackReceiver
|
||||
#endif
|
||||
{
|
||||
public float RaycastTime = 0.3f;
|
||||
public float CustomGrazeCastTime = 0.3f;
|
||||
public float CustomGrazeCastDuration = 0f;
|
||||
public float ImpactDuration = 0.01f;
|
||||
[Range(0.01f, 1f)]
|
||||
public float ImpactPlaybackSpeed = 1f;
|
||||
[Range(0.01f, 1f)]
|
||||
public float attackDurationNormalized = 1f;
|
||||
[Range(0f, 360f)]
|
||||
public float SwingAngle = 0f;
|
||||
[Range(-180f, 180f)]
|
||||
public float SwingDegrees = 0f;
|
||||
|
||||
[SerializeField]
|
||||
private float ClipLength = 0f;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
var context = AnimatorController.FindStateMachineBehaviourContext(this);
|
||||
if (context != null && context.Length > 0)
|
||||
{
|
||||
var state = context[0].animatorObject as AnimatorState;
|
||||
if (state != null)
|
||||
{
|
||||
var clip = state.motion as AnimationClip;
|
||||
if (clip != null)
|
||||
{
|
||||
ClipLength = clip.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NotEditor
|
||||
private readonly int AttackSpeedHash = Animator.StringToHash("MeleeAttackSpeed");
|
||||
private float calculatedRaycastTime;
|
||||
private float calculatedGrazeTime;
|
||||
private float calculatedGrazeDuration;
|
||||
private float calculatedImpactDuration;
|
||||
private float calculatedImpactPlaybackSpeed;
|
||||
private bool hasFired;
|
||||
private int actionIndex;
|
||||
private float originalMeleeAttackSpeed;
|
||||
//private bool playingImpact;
|
||||
private EntityAlive entity;
|
||||
private float attacksPerMinute;
|
||||
private float speedMultiplierToKeep = 1f;
|
||||
private InventorySlotGurad slotGurad = new InventorySlotGurad();
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
//if (playingImpact)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
hasFired = false;
|
||||
actionIndex = animator.GetWrappedInt(AvatarController.itemActionIndexHash);
|
||||
entity = animator.GetComponentInParent<EntityAlive>();
|
||||
if (!slotGurad.IsValid(entity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
//Log.Out("State entered!");
|
||||
//AnimatorClipInfo[] array = animator.GetNextAnimatorClipInfo(layerIndex);
|
||||
float length = ClipLength * attackDurationNormalized;
|
||||
////if (array.Length == 0)
|
||||
////{
|
||||
// var array = animator.GetCurrentAnimatorClipInfo(layerIndex);
|
||||
// if (array.Length == 0)
|
||||
// {
|
||||
// if (float.IsInfinity(stateInfo.length))
|
||||
// {
|
||||
// Log.Out($"Invalid clips!");
|
||||
// return;
|
||||
// }
|
||||
// length = stateInfo.length;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// length = array[0].clip.length;
|
||||
// }
|
||||
////}
|
||||
////else
|
||||
////{
|
||||
//// length = array[0].clip.length;
|
||||
////}
|
||||
//length *= attackDurationNormalized;
|
||||
attacksPerMinute = 60f / length;
|
||||
FastTags<TagGroup.Global> fastTags = ((actionIndex != 1) ? ItemActionAttack.PrimaryTag : ItemActionAttack.SecondaryTag);
|
||||
ItemValue holdingItemItemValue = entity.inventory.holdingItemItemValue;
|
||||
ItemClass itemClass = holdingItemItemValue.ItemClass;
|
||||
if (itemClass != null)
|
||||
{
|
||||
fastTags |= itemClass.ItemTags;
|
||||
}
|
||||
originalMeleeAttackSpeed = EffectManager.GetValue(PassiveEffects.AttacksPerMinute, holdingItemItemValue, attacksPerMinute, entity, null, fastTags) / 60f * length;
|
||||
animator.SetWrappedFloat(AttackSpeedHash, originalMeleeAttackSpeed);
|
||||
speedMultiplierToKeep = originalMeleeAttackSpeed;
|
||||
ItemClass holdingItem = entity.inventory.holdingItem;
|
||||
holdingItem.Properties.ParseFloat((actionIndex != 1) ? "Action0.RaycastTime" : "Action1.RaycastTime", ref RaycastTime);
|
||||
float impactDuration = -1f;
|
||||
holdingItem.Properties.ParseFloat((actionIndex != 1) ? "Action0.ImpactDuration" : "Action1.ImpactDuration", ref impactDuration);
|
||||
if (impactDuration >= 0f)
|
||||
{
|
||||
ImpactDuration = impactDuration * originalMeleeAttackSpeed;
|
||||
}
|
||||
holdingItem.Properties.ParseFloat((actionIndex != 1) ? "Action0.ImpactPlaybackSpeed" : "Action1.ImpactPlaybackSpeed", ref ImpactPlaybackSpeed);
|
||||
if (originalMeleeAttackSpeed != 0f)
|
||||
{
|
||||
calculatedRaycastTime = RaycastTime / originalMeleeAttackSpeed;
|
||||
calculatedGrazeTime = CustomGrazeCastTime / originalMeleeAttackSpeed;
|
||||
calculatedGrazeDuration = CustomGrazeCastDuration / originalMeleeAttackSpeed;
|
||||
calculatedImpactDuration = ImpactDuration / originalMeleeAttackSpeed;
|
||||
calculatedImpactPlaybackSpeed = ImpactPlaybackSpeed * originalMeleeAttackSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
calculatedRaycastTime = 0.001f;
|
||||
calculatedGrazeTime = 0.001f;
|
||||
calculatedGrazeDuration = 0.001f;
|
||||
calculatedImpactDuration = 0.001f;
|
||||
calculatedImpactPlaybackSpeed = 0.001f;
|
||||
}
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
{
|
||||
Log.Out($"original: raycast time {RaycastTime} impact duration {ImpactDuration} impact playback speed {ImpactPlaybackSpeed} clip length {length}/{stateInfo.length}");
|
||||
Log.Out($"calculated: raycast time {calculatedRaycastTime} impact duration {calculatedImpactDuration} impact playback speed {calculatedImpactPlaybackSpeed} speed multiplier {originalMeleeAttackSpeed}");
|
||||
}
|
||||
GameManager.Instance.StartCoroutine(impactStart(animator, layerIndex, length));
|
||||
GameManager.Instance.StartCoroutine(customGrazeStart(length));
|
||||
}
|
||||
|
||||
private IEnumerator impactStart(Animator animator, int layer, float length)
|
||||
{
|
||||
yield return new WaitForSeconds(Mathf.Max(calculatedRaycastTime, 0));
|
||||
if (!hasFired)
|
||||
{
|
||||
hasFired = true;
|
||||
if (entity != null && !entity.isEntityRemote && actionIndex >= 0)
|
||||
{
|
||||
ItemActionDynamicMelee.ItemActionDynamicMeleeData itemActionDynamicMeleeData = entity.inventory.holdingItemData.actionData[actionIndex] as ItemActionDynamicMelee.ItemActionDynamicMeleeData;
|
||||
if (itemActionDynamicMeleeData != null)
|
||||
{
|
||||
if ((entity.inventory.holdingItem.Actions[actionIndex] as ItemActionDynamicMelee).Raycast(itemActionDynamicMeleeData))
|
||||
{
|
||||
GameManager.Instance.StartCoroutine(impactStop(animator, layer, length));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
private IEnumerator impactStop(Animator animator, int layer, float length)
|
||||
{
|
||||
//playingImpact = true;
|
||||
//animator.Play(0, layer, Mathf.Min(1f, calculatedRaycastTime * attackDurationNormalized / length));
|
||||
if (animator)
|
||||
{
|
||||
//Log.Out("Impact start!");
|
||||
animator.SetWrappedFloat(AttackSpeedHash, calculatedImpactPlaybackSpeed);
|
||||
}
|
||||
speedMultiplierToKeep = calculatedImpactPlaybackSpeed;
|
||||
yield return new WaitForSeconds(calculatedImpactDuration);
|
||||
if (animator)
|
||||
{
|
||||
//Log.Out("Impact stop!");
|
||||
animator.SetWrappedFloat(AttackSpeedHash, originalMeleeAttackSpeed);
|
||||
}
|
||||
speedMultiplierToKeep = originalMeleeAttackSpeed;
|
||||
//playingImpact = false;
|
||||
yield break;
|
||||
}
|
||||
|
||||
private IEnumerator customGrazeStart(float length)
|
||||
{
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
{
|
||||
Log.Out($"Custom graze time: {calculatedGrazeTime} original {CustomGrazeCastTime}");
|
||||
}
|
||||
yield return new WaitForSeconds(calculatedGrazeTime);
|
||||
if (entity != null && !entity.isEntityRemote && actionIndex >= 0)
|
||||
{
|
||||
ItemActionDynamicMelee.ItemActionDynamicMeleeData itemActionDynamicMeleeData = entity.inventory.holdingItemData.actionData[actionIndex] as ItemActionDynamicMelee.ItemActionDynamicMeleeData;
|
||||
if (itemActionDynamicMeleeData != null)
|
||||
{
|
||||
GameManager.Instance.StartCoroutine(customGrazeUpdate(itemActionDynamicMeleeData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator customGrazeUpdate(ItemActionDynamicMelee.ItemActionDynamicMeleeData data)
|
||||
{
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
{
|
||||
Log.Out($"Custom graze duration: {calculatedGrazeDuration} original {CustomGrazeCastDuration}");
|
||||
}
|
||||
if (calculatedGrazeDuration <= 0f)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
float grazeStart = Time.time;
|
||||
float normalizedTime = 0f;
|
||||
var action = entity.inventory.holdingItem.Actions[actionIndex] as ItemActionDynamicMelee;
|
||||
while (normalizedTime <= 1)
|
||||
{
|
||||
if (!slotGurad.IsValid(data.invData.holdingEntity))
|
||||
{
|
||||
Log.Out($"Invalid graze!");
|
||||
yield break;
|
||||
}
|
||||
float originalSwingAngle = action.SwingAngle;
|
||||
float originalSwingDegrees = action.SwingDegrees;
|
||||
action.SwingAngle = SwingAngle;
|
||||
action.SwingDegrees = SwingDegrees;
|
||||
bool grazeResult = action.GrazeCast(data, normalizedTime);
|
||||
if (ConsoleCmdReloadLog.LogInfo)
|
||||
{
|
||||
Log.Out($"GrazeCast {grazeResult}!");
|
||||
}
|
||||
action.SwingAngle = originalSwingAngle;
|
||||
action.SwingDegrees = originalSwingDegrees;
|
||||
yield return null;
|
||||
normalizedTime = (Time.time - grazeStart) / calculatedGrazeDuration;
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
//if (entity != null && !entity.isEntityRemote && actionIndex >= 0 && entity.inventory.holdingItemData.actionData[actionIndex] is ItemActionDynamicMelee.ItemActionDynamicMeleeData)
|
||||
//{
|
||||
// animator.SetFloat(AttackSpeedHash, originalMeleeAttackSpeed);
|
||||
//}
|
||||
animator.SetWrappedFloat(AttackSpeedHash, originalMeleeAttackSpeed);
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
//float normalizedTime = stateInfo.normalizedTime;
|
||||
//if (float.IsInfinity(normalizedTime) || float.IsNaN(normalizedTime))
|
||||
//{
|
||||
// animator.Play(animator.GetNextAnimatorStateInfo(layerIndex).shortNameHash, layerIndex);
|
||||
//}
|
||||
animator.SetWrappedFloat(AttackSpeedHash, speedMultiplierToKeep);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fef84a89943f52c418487a560eb789c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,94 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib.Scripts.StaticManagers;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationCustomReloadState : StateMachineBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float ForceCancelReloadDelay = 1f;
|
||||
[SerializeField]
|
||||
private bool DoNotForceCancel = false;
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.speed = 1f;
|
||||
animator.SetWrappedBool(Animator.StringToHash("Reload"), false);
|
||||
animator.SetWrappedBool(Animator.StringToHash("IsReloading"), true);
|
||||
#if NotEditor
|
||||
if (player == null)
|
||||
{
|
||||
player = animator.GetComponentInParent<EntityAlive>();
|
||||
}
|
||||
int actionIndex = MultiActionManager.GetActionIndexForEntity(player);
|
||||
#if DEBUG
|
||||
Log.Out($"start reload {actionIndex}");
|
||||
#endif
|
||||
actionData = player.inventory.holdingItemData.actionData[actionIndex] as ItemActionRanged.ItemActionDataRanged;
|
||||
if (eventBridge == null)
|
||||
{
|
||||
eventBridge = animator.GetComponent<AnimationReloadEvents>();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
Log.Out($"ANIMATOR STATE ENTER : {actionData.invData.item.Name}");
|
||||
#endif
|
||||
eventBridge.OnReloadStart(actionIndex);
|
||||
//eventBridge.OnReloadUpdate();
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.speed = 1f;
|
||||
#if NotEditor
|
||||
//eventBridge.OnReloadUpdate();
|
||||
if (actionData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (actionData.isReloading)
|
||||
{
|
||||
eventBridge.OnReloadFinish();
|
||||
}
|
||||
#endif
|
||||
//actionData.isReloading = false;
|
||||
//actionData.isReloadCancelled = false;
|
||||
//actionData.isChangingAmmoType = false;
|
||||
#if DEBUG && NotEditor
|
||||
Log.Out($"ANIMATOR STATE EXIT : {actionData.invData.item.Name}");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
//eventBridge.OnReloadUpdate();
|
||||
if (actionData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (actionData.isReloadCancelled)
|
||||
{
|
||||
animator.speed = 30f;
|
||||
|
||||
if (!DoNotForceCancel)
|
||||
{
|
||||
eventBridge.DelayForceCancelReload(ForceCancelReloadDelay);
|
||||
}
|
||||
#if DEBUG
|
||||
Log.Out($"ANIMATOR UPDATE: RELOAD CANCELLED, ANIMATOR SPEED {animator.speed}");
|
||||
#endif
|
||||
}
|
||||
if (!actionData.isReloadCancelled && actionData.isReloading)
|
||||
{
|
||||
actionData.invData.holdingEntity.MinEventContext.ItemActionData = actionData;
|
||||
actionData.invData.holdingEntity.FireEvent(MinEventTypes.onReloadUpdate, true);
|
||||
}
|
||||
}
|
||||
|
||||
private ItemActionRanged.ItemActionDataRanged actionData;
|
||||
private EntityAlive player;
|
||||
private AnimationReloadEvents eventBridge;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f156c87129f85044a3336ade4d1af2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
public class AnimationInspectFix : MonoBehaviour, IPlayableGraphRelated
|
||||
{
|
||||
[SerializeField]
|
||||
private string inspectName = "Inspect";
|
||||
[SerializeField]
|
||||
private int layer = 0;
|
||||
[SerializeField, Range(0, 1)]
|
||||
private float finishTime = 1;
|
||||
[SerializeField]
|
||||
private bool useStateTag = false;
|
||||
private static int inspectHash = Animator.StringToHash("weaponInspect");
|
||||
private IAnimatorWrapper wrapper;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (wrapper == null || !wrapper.IsValid)
|
||||
{
|
||||
var animator = GetComponent<Animator>();
|
||||
if (!animator)
|
||||
{
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
wrapper = animator.GetItemAnimatorWrapper();
|
||||
}
|
||||
if (useStateTag)
|
||||
{
|
||||
var stateInfo = wrapper.GetCurrentAnimatorStateInfo(layer);
|
||||
if (stateInfo.IsTag(inspectName) && stateInfo.normalizedTime < finishTime)
|
||||
{
|
||||
wrapper.ResetTrigger(inspectHash);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var transInfo = wrapper.GetAnimatorTransitionInfo(layer);
|
||||
if (transInfo.IsUserName(inspectName) && transInfo.normalizedTime < finishTime)
|
||||
{
|
||||
wrapper.ResetTrigger(inspectHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MonoBehaviour Init(Transform playerAnimatorTrans, bool isLocalPlayer)
|
||||
{
|
||||
enabled = false;
|
||||
var copy = isLocalPlayer ? playerAnimatorTrans.AddMissingComponent<AnimationInspectFix>() : null;
|
||||
if (copy)
|
||||
{
|
||||
copy.enabled = true;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void Disable(Transform playerAnimatorTrans)
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26c7436085cc1924a882f62d81f262a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib;
|
||||
using KFCommonUtilityLib.Scripts.StaticManagers;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationLockAction : StateMachineBehaviour
|
||||
{
|
||||
public bool lockReload = false;
|
||||
#if NotEditor
|
||||
private InventorySlotGurad slotGuard = new InventorySlotGurad();
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
var player = animator.GetComponentInParent<EntityAlive>();
|
||||
if (slotGuard.IsValid(player))
|
||||
{
|
||||
if (player.inventory.holdingItemData.actionData[MultiActionManager.GetActionIndexForEntity(player)] is IModuleContainerFor<ActionModuleAnimationLocked.AnimationLockedData> lockData)
|
||||
{
|
||||
lockData.Instance.isLocked = true;
|
||||
if (lockReload)
|
||||
{
|
||||
lockData.Instance.isReloadLocked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
var player = animator.GetComponentInParent<EntityAlive>();
|
||||
if (slotGuard.IsValid(player))
|
||||
{
|
||||
if (player.inventory.holdingItemData.actionData[MultiActionManager.GetActionIndexForEntity(player)] is IModuleContainerFor<ActionModuleAnimationLocked.AnimationLockedData> lockData)
|
||||
{
|
||||
lockData.Instance.isLocked = false;
|
||||
lockData.Instance.isReloadLocked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41af3d052f5a46a4c86c3ffbaf4c7918
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib.Scripts.StaticManagers;
|
||||
using UAI;
|
||||
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationMultiStageReloadState : StateMachineBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private bool speedUpOnCancel;
|
||||
[SerializeField]
|
||||
private bool immediateCancel;
|
||||
[SerializeField]
|
||||
private float ForceCancelReloadDelay = 1f;
|
||||
[SerializeField]
|
||||
private bool DoNotForceCancel = false;
|
||||
|
||||
private AnimationReloadEvents eventBridge;
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.SetWrappedBool(Animator.StringToHash("Reload"), false);
|
||||
if (eventBridge == null)
|
||||
{
|
||||
eventBridge = animator.GetComponent<AnimationReloadEvents>();
|
||||
}
|
||||
if (stateInfo.IsTag("ReloadStart"))
|
||||
{
|
||||
animator.speed = 1f;
|
||||
animator.SetWrappedBool(Animator.StringToHash("IsReloading"), true);
|
||||
#if NotEditor
|
||||
EntityAlive player = animator.GetComponentInParent<EntityAlive>();
|
||||
int actionIndex = MultiActionManager.GetActionIndexForEntity(player);
|
||||
eventBridge.OnReloadStart(actionIndex);
|
||||
#if DEBUG
|
||||
Log.Out($"start reload {actionIndex}");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
var actionData = eventBridge.actionData;
|
||||
if (actionData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionData.isReloadCancelled)
|
||||
{
|
||||
if (speedUpOnCancel)
|
||||
{
|
||||
Log.Out("Speed up animation!");
|
||||
animator.speed = 30;
|
||||
}
|
||||
|
||||
if (immediateCancel)
|
||||
{
|
||||
animator.SetBool("IsReloading", false);
|
||||
}
|
||||
|
||||
if (!DoNotForceCancel)
|
||||
{
|
||||
eventBridge.DelayForceCancelReload(ForceCancelReloadDelay);
|
||||
}
|
||||
}
|
||||
|
||||
if (actionData.isReloading && animator.GetBool("IsReloading"))
|
||||
{
|
||||
actionData.invData.holdingEntity.MinEventContext.ItemActionData = actionData;
|
||||
actionData.invData.holdingEntity.FireEvent(MinEventTypes.onReloadUpdate, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.speed = 1f;
|
||||
if (stateInfo.IsTag("ReloadEnd"))
|
||||
eventBridge?.OnReloadFinish();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a36e127f3f92d4f4a8c3e3fdabe6e1d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationRandomRecoilState : StateMachineBehaviour
|
||||
{
|
||||
[SerializeField] private Vector3 positionMultiplier = Vector3.one;
|
||||
[SerializeField] private Vector3 rotationMultiplier = Vector3.one;
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.GetComponent<AnimationProceduralRecoildAbs>()?.AddRecoil(positionMultiplier, rotationMultiplier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a853564a7472fea44b9ba42cbf3ae654
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimationResetRigWeightState : StateMachineBehaviour
|
||||
{
|
||||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
animator.GetComponent<RigWeightOverTime>()?.SetWeight(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cfcbf05cdb32514bab41d81a761cd4d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
public class AnimationRigLayerController : StateMachineBehaviour, ISerializationCallbackReceiver
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[Serializable]
|
||||
public struct State
|
||||
{
|
||||
public byte layer;
|
||||
public bool enable;
|
||||
}
|
||||
[SerializeField]
|
||||
public State[] layerStatesEditor;
|
||||
#endif
|
||||
[SerializeField, HideInInspector]
|
||||
private int[] layers;
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if(layerStatesEditor != null)
|
||||
{
|
||||
layers = new int[layerStatesEditor.Length];
|
||||
for (int i = 0; i < layerStatesEditor.Length; i++)
|
||||
{
|
||||
layers[i] = layerStatesEditor[i].layer | (layerStatesEditor[i].enable ? 0 : 0x8000);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
if (layers == null)
|
||||
return;
|
||||
|
||||
RigBuilder rigBuilder = animator.GetComponent<RigBuilder>();
|
||||
if (rigBuilder && rigBuilder.layers != null)
|
||||
{
|
||||
foreach (var layer in layers)
|
||||
{
|
||||
int realLayer = layer & 0x7fff;
|
||||
if (realLayer >= rigBuilder.layers.Count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
rigBuilder.layers[realLayer].active = (layer & 0x8000) <= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbb26fa6f1fef8f45b8eaf5702207898
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Utils/Animator Random Switch")]
|
||||
public class AnimatorRandomSwitch : StateMachineBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private string parameter;
|
||||
[SerializeField]
|
||||
private int stateCount;
|
||||
|
||||
private int[] stateHits;
|
||||
int totalHits;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
stateHits = new int[stateCount];
|
||||
for (int i = 0; i < stateCount; i++)
|
||||
{
|
||||
stateHits[i] = 1;
|
||||
}
|
||||
totalHits = stateCount;
|
||||
}
|
||||
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
int rand = Random.Range(0, totalHits);
|
||||
int cur = 0;
|
||||
bool found = false;
|
||||
for (int i = 0; i < stateHits.Length; i++)
|
||||
{
|
||||
cur += stateHits[i];
|
||||
if (cur > rand && !found)
|
||||
{
|
||||
animator.SetInteger(parameter, i);
|
||||
found = true;
|
||||
stateHits[i] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
stateHits[i] = 2;
|
||||
}
|
||||
}
|
||||
totalHits = stateCount * 2 - 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c083a728c43231842a2e50a3c04b4a11
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/FPSPack.meta
Normal file
8
KFAttached/FPSPack.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e3819a4a6a281d4bbdf89ab29424071
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/FPSPack/Demo.meta
Normal file
8
KFAttached/FPSPack/Demo.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b7fe40f86d8131479dac6a7eb9f7f66
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
KFAttached/FPSPack/Demo/FPSDemoGUI.cs
Normal file
68
KFAttached/FPSPack/Demo/FPSDemoGUI.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FPSDemoGUI : MonoBehaviour
|
||||
{
|
||||
public GameObject[] Prefabs;
|
||||
public Transform muzzleFlashPoint;
|
||||
public GameObject Gun;
|
||||
public float reactivateTime = 4;
|
||||
public Light Sun;
|
||||
|
||||
private int currentNomber;
|
||||
private GameObject currentInstance;
|
||||
private GUIStyle guiStyleHeader = new GUIStyle();
|
||||
private float sunIntensity;
|
||||
float dpiScale;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
if (Screen.dpi < 1) dpiScale = 1;
|
||||
if (Screen.dpi < 200) dpiScale = 1;
|
||||
else dpiScale = Screen.dpi / 200f;
|
||||
guiStyleHeader.fontSize = (int)(15f * dpiScale);
|
||||
guiStyleHeader.normal.textColor = new Color(0.15f, 0.15f, 0.15f);
|
||||
currentInstance = Instantiate(Prefabs[currentNomber], transform.position, transform.rotation) as GameObject;
|
||||
var reactivator = currentInstance.AddComponent<FPSDemoReactivator>();
|
||||
reactivator.TimeDelayToReactivate = reactivateTime;
|
||||
sunIntensity = Sun.intensity;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (GUI.Button(new Rect(10 * dpiScale, 15 * dpiScale, 135 * dpiScale, 37 * dpiScale), "PREVIOUS EFFECT"))
|
||||
{
|
||||
ChangeCurrent(-1);
|
||||
}
|
||||
if (GUI.Button(new Rect(160 * dpiScale, 15 * dpiScale, 135 * dpiScale, 37 * dpiScale), "NEXT EFFECT"))
|
||||
{
|
||||
ChangeCurrent(+1);
|
||||
}
|
||||
sunIntensity = GUI.HorizontalSlider(new Rect(10 * dpiScale, 70 * dpiScale, 285 * dpiScale, 15 * dpiScale), sunIntensity, 0, 0.6f);
|
||||
Sun.intensity = sunIntensity;
|
||||
GUI.Label(new Rect(300 * dpiScale, 70 * dpiScale, 30 * dpiScale, 30 * dpiScale), "SUN INTENSITY", guiStyleHeader);
|
||||
GUI.Label(new Rect(400 * dpiScale, 15 * dpiScale, 100 * dpiScale, 20 * dpiScale), "Prefab name is \"" + Prefabs[currentNomber].name + "\" \r\nHold any mouse button that would move the camera", guiStyleHeader);
|
||||
}
|
||||
// Update is called once per frame
|
||||
void ChangeCurrent(int delta)
|
||||
{
|
||||
currentNomber += delta;
|
||||
if (currentNomber > Prefabs.Length - 1)
|
||||
currentNomber = 0;
|
||||
else if (currentNomber < 0)
|
||||
currentNomber = Prefabs.Length - 1;
|
||||
if (currentInstance != null) Destroy(currentInstance);
|
||||
if (currentNomber < 10)
|
||||
{
|
||||
currentInstance = Instantiate(Prefabs[currentNomber], transform.position, transform.rotation) as GameObject;
|
||||
Gun.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentInstance = Instantiate(Prefabs[currentNomber], muzzleFlashPoint.position, muzzleFlashPoint.rotation) as GameObject;
|
||||
Gun.SetActive(true);
|
||||
}
|
||||
var reactivator = currentInstance.AddComponent<FPSDemoReactivator>();
|
||||
reactivator.TimeDelayToReactivate = reactivateTime;
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/Demo/FPSDemoGUI.cs.meta
Normal file
11
KFAttached/FPSPack/Demo/FPSDemoGUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f44a7ad42765c94b896425517325f1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
KFAttached/FPSPack/Demo/FPSDemoReactivator.cs
Normal file
19
KFAttached/FPSPack/Demo/FPSDemoReactivator.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FPSDemoReactivator : MonoBehaviour
|
||||
{
|
||||
|
||||
public float StartDelay = 0;
|
||||
public float TimeDelayToReactivate = 3;
|
||||
|
||||
void Start()
|
||||
{
|
||||
InvokeRepeating("Reactivate", StartDelay, TimeDelayToReactivate);
|
||||
}
|
||||
|
||||
void Reactivate()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/Demo/FPSDemoReactivator.cs.meta
Normal file
11
KFAttached/FPSPack/Demo/FPSDemoReactivator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77e369a1e74c2d84ead64ef026b1c433
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
KFAttached/FPSPack/Demo/FPSFireManager.cs
Normal file
49
KFAttached/FPSPack/Demo/FPSFireManager.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FPSFireManager : MonoBehaviour
|
||||
{
|
||||
public ImpactInfo[] ImpactElemets = new ImpactInfo[0];
|
||||
public float BulletDistance = 100;
|
||||
public GameObject ImpactEffect;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
RaycastHit hit;
|
||||
var ray = new Ray(transform.position, transform.forward);
|
||||
if (Physics.Raycast(ray, out hit, BulletDistance))
|
||||
{
|
||||
var effect = GetImpactEffect(hit.transform.gameObject);
|
||||
if (effect == null)
|
||||
return;
|
||||
var effectIstance = Instantiate(effect, hit.point, new Quaternion()) as GameObject;
|
||||
ImpactEffect.SetActive(false);
|
||||
ImpactEffect.SetActive(true);
|
||||
effectIstance.transform.LookAt(hit.point + hit.normal);
|
||||
Destroy(effectIstance, 4);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ImpactInfo
|
||||
{
|
||||
public MaterialType.MaterialTypeEnum MaterialType;
|
||||
public GameObject ImpactEffect;
|
||||
}
|
||||
|
||||
GameObject GetImpactEffect(GameObject impactedGameObject)
|
||||
{
|
||||
var materialType = impactedGameObject.GetComponent<MaterialType>();
|
||||
if (materialType == null)
|
||||
return null;
|
||||
foreach (var impactInfo in ImpactElemets)
|
||||
{
|
||||
if (impactInfo.MaterialType == materialType.TypeOfMaterial)
|
||||
return impactInfo.ImpactEffect;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/Demo/FPSFireManager.cs.meta
Normal file
11
KFAttached/FPSPack/Demo/FPSFireManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eabaea637d046b649916223ab9952a50
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
KFAttached/FPSPack/Demo/MouseLock.cs
Normal file
22
KFAttached/FPSPack/Demo/MouseLock.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MouseLock : MonoBehaviour
|
||||
{
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
|
||||
Screen.lockCursor = true;
|
||||
#else
|
||||
Cursor.visible = false;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/Demo/MouseLock.cs.meta
Normal file
11
KFAttached/FPSPack/Demo/MouseLock.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc19b6a3661472848bf60b7ac730c242
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
KFAttached/FPSPack/FPSLightCurves.cs
Normal file
47
KFAttached/FPSPack/FPSLightCurves.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FPSLightCurves : MonoBehaviour
|
||||
{
|
||||
public AnimationCurve LightCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
public float GraphTimeMultiplier = 1, GraphIntensityMultiplier = 1;
|
||||
|
||||
private bool canUpdate;
|
||||
private bool firstUpdate;
|
||||
private float startTime;
|
||||
private Light lightSource;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
lightSource = GetComponent<Light>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
lightSource.intensity = LightCurve.Evaluate(0);
|
||||
if (firstUpdate)
|
||||
{
|
||||
firstUpdate = false;
|
||||
return;
|
||||
}
|
||||
startTime = Time.time;
|
||||
canUpdate = true;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
firstUpdate = true;
|
||||
canUpdate = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var time = Time.time - startTime;
|
||||
if (canUpdate)
|
||||
{
|
||||
var eval = LightCurve.Evaluate(time / GraphTimeMultiplier) * GraphIntensityMultiplier;
|
||||
lightSource.intensity = eval;
|
||||
}
|
||||
if (time >= GraphTimeMultiplier)
|
||||
canUpdate = false;
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/FPSLightCurves.cs.meta
Normal file
11
KFAttached/FPSPack/FPSLightCurves.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22b1c2a9f789e3e47a7c58fa60e17e5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
KFAttached/FPSPack/FPSParticleSystemScaler.cs
Normal file
62
KFAttached/FPSPack/FPSParticleSystemScaler.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class FPSParticleSystemScaler : MonoBehaviour
|
||||
{
|
||||
public float particlesScale = 1.0f;
|
||||
|
||||
float oldScale;
|
||||
|
||||
void Start()
|
||||
{
|
||||
oldScale = particlesScale;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (Mathf.Abs(oldScale - particlesScale) > 0.0001f && particlesScale > 0)
|
||||
{
|
||||
transform.localScale = new Vector3(particlesScale, particlesScale, particlesScale);
|
||||
float scale = particlesScale / oldScale;
|
||||
var ps = this.GetComponentsInChildren<ParticleSystem>();
|
||||
|
||||
foreach (ParticleSystem particles in ps)
|
||||
{
|
||||
particles.startSize *= scale;
|
||||
particles.startSpeed *= scale;
|
||||
particles.gravityModifier *= scale;
|
||||
|
||||
SerializedObject serializedObject = new SerializedObject(particles);
|
||||
serializedObject.FindProperty("ClampVelocityModule.magnitude.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("ClampVelocityModule.x.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("ClampVelocityModule.y.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("ClampVelocityModule.z.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("VelocityModule.x.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("VelocityModule.y.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("VelocityModule.z.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("ColorBySpeedModule.range").vector2Value *= scale;
|
||||
serializedObject.FindProperty("RotationBySpeedModule.range").vector2Value *= scale;
|
||||
serializedObject.FindProperty("ForceModule.x.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("ForceModule.y.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("ForceModule.z.scalar").floatValue *= scale;
|
||||
serializedObject.FindProperty("SizeBySpeedModule.range").vector2Value *= scale;
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
var trails = this.GetComponentsInChildren<TrailRenderer>();
|
||||
foreach (TrailRenderer trail in trails)
|
||||
{
|
||||
trail.startWidth *= scale;
|
||||
trail.endWidth *= scale;
|
||||
}
|
||||
oldScale = particlesScale;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/FPSParticleSystemScaler.cs.meta
Normal file
11
KFAttached/FPSPack/FPSParticleSystemScaler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c035660ec1d9fd64da7beb32f35b7437
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
KFAttached/FPSPack/FPSRandomRotateAngle.cs
Normal file
29
KFAttached/FPSPack/FPSRandomRotateAngle.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FPSRandomRotateAngle : MonoBehaviour
|
||||
{
|
||||
public bool RotateX;
|
||||
public bool RotateY;
|
||||
public bool RotateZ = true;
|
||||
|
||||
private Transform t;
|
||||
|
||||
// Use this for initialization
|
||||
void Awake()
|
||||
{
|
||||
t = transform;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void OnEnable()
|
||||
{
|
||||
var rotateVector = Vector3.zero;
|
||||
if (RotateX)
|
||||
rotateVector.x = Random.Range(0, 360);
|
||||
if (RotateY)
|
||||
rotateVector.y = Random.Range(0, 360);
|
||||
if (RotateZ)
|
||||
rotateVector.z = Random.Range(0, 360);
|
||||
t.Rotate(rotateVector);
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/FPSRandomRotateAngle.cs.meta
Normal file
11
KFAttached/FPSPack/FPSRandomRotateAngle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7a83f50808621b43bd26cd127393a40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
KFAttached/FPSPack/FPSShaderColorGradient.cs
Normal file
61
KFAttached/FPSPack/FPSShaderColorGradient.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FPSShaderColorGradient : MonoBehaviour
|
||||
{
|
||||
public string ShaderProperty = "_TintColor";
|
||||
public int MaterialID = 0;
|
||||
public Gradient Color = new Gradient();
|
||||
public float TimeMultiplier = 1;
|
||||
|
||||
private bool canUpdate;
|
||||
private Material matInstance;
|
||||
private int propertyID;
|
||||
private float startTime;
|
||||
private Color oldColor;
|
||||
|
||||
// Use this for initialization
|
||||
private void Start()
|
||||
{
|
||||
var rend = GetComponent<Renderer>();
|
||||
if (rend != null)
|
||||
{
|
||||
var mats = rend.materials;
|
||||
if (MaterialID >= mats.Length)
|
||||
Debug.Log("ShaderColorGradient: Material ID more than shader materials count.");
|
||||
matInstance = mats[MaterialID];
|
||||
}
|
||||
else
|
||||
{
|
||||
var proj = GetComponent<Projector>();
|
||||
var projMat = proj.material;
|
||||
if (!projMat.name.EndsWith("(Instance)"))
|
||||
matInstance = new Material(projMat) { name = projMat.name + " (Instance)" };
|
||||
else
|
||||
matInstance = projMat;
|
||||
proj.material = matInstance;
|
||||
}
|
||||
|
||||
if (!matInstance.HasProperty(ShaderProperty))
|
||||
Debug.Log("ShaderColorGradient: Shader not have \"" + ShaderProperty + "\" property");
|
||||
propertyID = Shader.PropertyToID(ShaderProperty);
|
||||
oldColor = matInstance.GetColor(propertyID);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
startTime = Time.time;
|
||||
canUpdate = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var time = Time.time - startTime;
|
||||
if (canUpdate)
|
||||
{
|
||||
var eval = Color.Evaluate(time / TimeMultiplier);
|
||||
matInstance.SetColor(propertyID, eval * oldColor);
|
||||
}
|
||||
if (time >= TimeMultiplier)
|
||||
canUpdate = false;
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/FPSShaderColorGradient.cs.meta
Normal file
11
KFAttached/FPSPack/FPSShaderColorGradient.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f6f8e03260dedb45a05a2c5f5eea632
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
KFAttached/FPSPack/FPSShaderFloatCurves.cs
Normal file
57
KFAttached/FPSPack/FPSShaderFloatCurves.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FPSShaderFloatCurves : MonoBehaviour
|
||||
{
|
||||
public string ShaderProperty = "_BumpAmt";
|
||||
public int MaterialID = 0;
|
||||
public AnimationCurve FloatPropertyCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
public float GraphTimeMultiplier = 1, GraphScaleMultiplier = 1;
|
||||
|
||||
private bool canUpdate;
|
||||
private Material matInstance;
|
||||
private int propertyID;
|
||||
private float startTime;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var rend = GetComponent<Renderer>();
|
||||
if (rend != null)
|
||||
{
|
||||
var mats = rend.materials;
|
||||
if (MaterialID >= mats.Length)
|
||||
Debug.Log("ShaderColorGradient: Material ID more than shader materials count.");
|
||||
matInstance = mats[MaterialID];
|
||||
}
|
||||
else
|
||||
{
|
||||
var proj = GetComponent<Projector>();
|
||||
var projMat = proj.material;
|
||||
if (!projMat.name.EndsWith("(Instance)"))
|
||||
matInstance = new Material(projMat) { name = projMat.name + " (Instance)" };
|
||||
else
|
||||
matInstance = projMat;
|
||||
proj.material = matInstance;
|
||||
}
|
||||
if (!matInstance.HasProperty(ShaderProperty))
|
||||
Debug.Log("ShaderColorGradient: Shader not have \"" + ShaderProperty + "\" property");
|
||||
propertyID = Shader.PropertyToID(ShaderProperty);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
startTime = Time.time;
|
||||
canUpdate = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var time = Time.time - startTime;
|
||||
if (canUpdate)
|
||||
{
|
||||
var eval = FloatPropertyCurve.Evaluate(time / GraphTimeMultiplier) * GraphScaleMultiplier;
|
||||
matInstance.SetFloat(propertyID, eval);
|
||||
}
|
||||
if (time >= GraphTimeMultiplier)
|
||||
canUpdate = false;
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/FPSShaderFloatCurves.cs.meta
Normal file
11
KFAttached/FPSPack/FPSShaderFloatCurves.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91b9007bb8bdfdc4cb4e31998935a777
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
KFAttached/FPSPack/MaterialType.cs
Normal file
22
KFAttached/FPSPack/MaterialType.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MaterialType : MonoBehaviour
|
||||
{
|
||||
|
||||
public MaterialTypeEnum TypeOfMaterial = MaterialTypeEnum.Plaster;
|
||||
|
||||
[System.Serializable]
|
||||
public enum MaterialTypeEnum
|
||||
{
|
||||
Plaster,
|
||||
Metall,
|
||||
Folliage,
|
||||
Rock,
|
||||
Wood,
|
||||
Brick,
|
||||
Concrete,
|
||||
Dirt,
|
||||
Glass,
|
||||
Water
|
||||
}
|
||||
}
|
||||
11
KFAttached/FPSPack/MaterialType.cs.meta
Normal file
11
KFAttached/FPSPack/MaterialType.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e86c216f014d903439060cd429cb53a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/GG Camera Shake.meta
Normal file
8
KFAttached/GG Camera Shake.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1bfb6a4682934f44be265da6de48898
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/GG Camera Shake/Runtime.meta
Normal file
8
KFAttached/GG Camera Shake/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 721197a8e82a4304097f3e0991293e4e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
66
KFAttached/GG Camera Shake/Runtime/Attenuator.cs
Normal file
66
KFAttached/GG Camera Shake/Runtime/Attenuator.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains methods for changing strength and direction of shakes depending on their position.
|
||||
/// </summary>
|
||||
public static class Attenuator
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns multiplier for the strength of a shake, based on source and camera positions.
|
||||
/// </summary>
|
||||
public static float Strength(StrengthAttenuationParams pars, Vector3 sourcePosition, Vector3 cameraPosition)
|
||||
{
|
||||
Vector3 vec = cameraPosition - sourcePosition;
|
||||
float distance = Vector3.Scale(pars.axesMultiplier, vec).magnitude;
|
||||
float strength = Mathf.Clamp01(1 - (distance - pars.clippingDistance) / pars.falloffScale);
|
||||
|
||||
return Power.Evaluate(strength, pars.falloffDegree);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns displacement, opposite to the direction to the source in camera's local space.
|
||||
/// </summary>
|
||||
public static Displacement Direction(Vector3 sourcePosition, Vector3 cameraPosition, Quaternion cameraRotation)
|
||||
{
|
||||
Displacement direction = Displacement.Zero;
|
||||
direction.position = (cameraPosition - sourcePosition).normalized;
|
||||
direction.position = Quaternion.Inverse(cameraRotation) * direction.position;
|
||||
|
||||
direction.eulerAngles.x = direction.position.z;
|
||||
direction.eulerAngles.y = direction.position.x;
|
||||
direction.eulerAngles.z = -direction.position.x;
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class StrengthAttenuationParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Radius in which shake doesn't lose strength.
|
||||
/// </summary>
|
||||
[Tooltip("Radius in which shake doesn't lose strength.")]
|
||||
public float clippingDistance = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Defines how fast strength falls with distance.
|
||||
/// </summary>
|
||||
[Tooltip("How fast strength falls with distance.")]
|
||||
public float falloffScale = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Power of the falloff function.
|
||||
/// </summary>
|
||||
[Tooltip("Power of the falloff function.")]
|
||||
public Degree falloffDegree = Degree.Quadratic;
|
||||
|
||||
/// <summary>
|
||||
/// Contribution of each axis to distance. E. g. (1, 1, 0) for a 2D game in XY plane.
|
||||
/// </summary>
|
||||
[Tooltip("Contribution of each axis to distance. E. g. (1, 1, 0) for a 2D game in XY plane.")]
|
||||
public Vector3 axesMultiplier = Vector3.one;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/Attenuator.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/Attenuator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07aa6a8400d46274f9cbc5f3714e6a9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
133
KFAttached/GG Camera Shake/Runtime/BounceShake.cs
Normal file
133
KFAttached/GG Camera Shake/Runtime/BounceShake.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
public class BounceShake : ICameraShake
|
||||
{
|
||||
readonly Params pars;
|
||||
readonly AnimationCurve moveCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
readonly Vector3? sourcePosition = null;
|
||||
|
||||
float attenuation = 1;
|
||||
Displacement direction;
|
||||
Displacement previousWaypoint;
|
||||
Displacement currentWaypoint;
|
||||
int bounceIndex;
|
||||
float t;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of BounceShake.
|
||||
/// </summary>
|
||||
/// <param name="parameters">Parameters of the shake.</param>
|
||||
/// <param name="sourcePosition">World position of the source of the shake.</param>
|
||||
public BounceShake(Params parameters, Vector3? sourcePosition = null)
|
||||
{
|
||||
this.sourcePosition = sourcePosition;
|
||||
pars = parameters;
|
||||
Displacement rnd = Displacement.InsideUnitSpheres();
|
||||
direction = Displacement.Scale(rnd, pars.axesMultiplier).Normalized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of BounceShake.
|
||||
/// </summary>
|
||||
/// <param name="parameters">Parameters of the shake.</param>
|
||||
/// <param name="initialDirection">Initial direction of the shake motion.</param>
|
||||
/// <param name="sourcePosition">World position of the source of the shake.</param>
|
||||
public BounceShake(Params parameters, Displacement initialDirection, Vector3? sourcePosition = null)
|
||||
{
|
||||
this.sourcePosition = sourcePosition;
|
||||
pars = parameters;
|
||||
direction = Displacement.Scale(initialDirection, pars.axesMultiplier).Normalized;
|
||||
}
|
||||
|
||||
public Displacement CurrentDisplacement { get; private set; }
|
||||
public bool IsFinished { get; private set; }
|
||||
public void Initialize(Vector3 cameraPosition, Quaternion cameraRotation)
|
||||
{
|
||||
attenuation = sourcePosition == null ?
|
||||
1 : Attenuator.Strength(pars.attenuation, sourcePosition.Value, cameraPosition);
|
||||
currentWaypoint = attenuation * direction.ScaledBy(pars.positionStrength, pars.rotationStrength);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime, Vector3 cameraPosition, Quaternion cameraRotation)
|
||||
{
|
||||
if (t < 1)
|
||||
{
|
||||
|
||||
t += deltaTime * pars.freq;
|
||||
if (pars.freq == 0) t = 1;
|
||||
|
||||
CurrentDisplacement = Displacement.Lerp(previousWaypoint, currentWaypoint,
|
||||
moveCurve.Evaluate(t));
|
||||
}
|
||||
else
|
||||
{
|
||||
t = 0;
|
||||
CurrentDisplacement = currentWaypoint;
|
||||
previousWaypoint = currentWaypoint;
|
||||
bounceIndex++;
|
||||
if (bounceIndex > pars.numBounces)
|
||||
{
|
||||
IsFinished = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Displacement rnd = Displacement.InsideUnitSpheres();
|
||||
direction = -direction
|
||||
+ pars.randomness * Displacement.Scale(rnd, pars.axesMultiplier).Normalized;
|
||||
direction = direction.Normalized;
|
||||
float decayValue = 1 - (float)bounceIndex / pars.numBounces;
|
||||
currentWaypoint = decayValue * decayValue * attenuation
|
||||
* direction.ScaledBy(pars.positionStrength, pars.rotationStrength);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Params
|
||||
{
|
||||
/// <summary>
|
||||
/// Strength of the shake for positional axes.
|
||||
/// </summary>
|
||||
[Tooltip("Strength of the shake for positional axes.")]
|
||||
public float positionStrength = 0.05f;
|
||||
|
||||
/// <summary>
|
||||
/// Strength of the shake for rotational axes.
|
||||
/// </summary>
|
||||
[Tooltip("Strength of the shake for rotational axes.")]
|
||||
public float rotationStrength = 0.1f;
|
||||
|
||||
/// <summary>
|
||||
/// Preferred direction of shaking.
|
||||
/// </summary>
|
||||
[Tooltip("Preferred direction of shaking.")]
|
||||
public Displacement axesMultiplier = new Displacement(Vector2.one, Vector3.forward);
|
||||
|
||||
/// <summary>
|
||||
/// Frequency of shaking.
|
||||
/// </summary>
|
||||
[Tooltip("Frequency of shaking.")]
|
||||
public float freq = 25;
|
||||
|
||||
/// <summary>
|
||||
/// Number of vibrations before stop.
|
||||
/// </summary>
|
||||
[Tooltip("Number of vibrations before stop.")]
|
||||
public int numBounces = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Randomness of motion.
|
||||
/// </summary>
|
||||
[Range(0, 1)]
|
||||
[Tooltip("Randomness of motion.")]
|
||||
public float randomness = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// How strength falls with distance from the shake source.
|
||||
/// </summary>
|
||||
[Tooltip("How strength falls with distance from the shake source.")]
|
||||
public Attenuator.StrengthAttenuationParams attenuation;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/BounceShake.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/BounceShake.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a8a4f5340889954aa6de7013b117066
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
KFAttached/GG Camera Shake/Runtime/CameraShakePresets.cs
Normal file
113
KFAttached/GG Camera Shake/Runtime/CameraShakePresets.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains shorthands for creating common shake types.
|
||||
/// </summary>
|
||||
public class CameraShakePresets
|
||||
{
|
||||
readonly CameraShaker shaker;
|
||||
|
||||
public CameraShakePresets(CameraShaker shaker)
|
||||
{
|
||||
this.shaker = shaker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suitable for short and snappy shakes in 2D. Moves camera in X and Y axes and rotates it in Z axis.
|
||||
/// </summary>
|
||||
/// <param name="positionStrength">Strength of motion in X and Y axes.</param>
|
||||
/// <param name="rotationStrength">Strength of rotation in Z axis.</param>
|
||||
/// <param name="freq">Frequency of shaking.</param>
|
||||
/// <param name="numBounces">Number of vibrations before stop.</param>
|
||||
public void ShortShake2D(
|
||||
float positionStrength = 0.08f,
|
||||
float rotationStrength = 0.1f,
|
||||
float freq = 25,
|
||||
int numBounces = 5)
|
||||
{
|
||||
BounceShake.Params pars = new BounceShake.Params
|
||||
{
|
||||
positionStrength = positionStrength,
|
||||
rotationStrength = rotationStrength,
|
||||
freq = freq,
|
||||
numBounces = numBounces
|
||||
};
|
||||
shaker.RegisterShake(new BounceShake(pars));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suitable for longer and stronger shakes in 3D. Rotates camera in all three axes.
|
||||
/// </summary>
|
||||
/// <param name="strength">Strength of the shake.</param>
|
||||
/// <param name="freq">Frequency of shaking.</param>
|
||||
/// <param name="numBounces">Number of vibrations before stop.</param>
|
||||
public void ShortShake3D(
|
||||
float strength = 0.3f,
|
||||
float freq = 25,
|
||||
int numBounces = 5)
|
||||
{
|
||||
BounceShake.Params pars = new BounceShake.Params
|
||||
{
|
||||
axesMultiplier = new Displacement(Vector3.zero, new Vector3(1, 1, 0.4f)),
|
||||
rotationStrength = strength,
|
||||
freq = freq,
|
||||
numBounces = numBounces
|
||||
};
|
||||
shaker.RegisterShake(new BounceShake(pars));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suitable for longer and stronger shakes in 2D. Moves camera in X and Y axes and rotates it in Z axis.
|
||||
/// </summary>
|
||||
/// <param name="positionStrength">Strength of motion in X and Y axes.</param>
|
||||
/// <param name="rotationStrength">Strength of rotation in Z axis.</param>
|
||||
/// <param name="duration">Duration of the shake.</param>
|
||||
public void Explosion2D(
|
||||
float positionStrength = 1f,
|
||||
float rotationStrength = 3,
|
||||
float duration = 0.5f)
|
||||
{
|
||||
PerlinShake.NoiseMode[] modes =
|
||||
{
|
||||
new PerlinShake.NoiseMode(8, 1),
|
||||
new PerlinShake.NoiseMode(20, 0.3f)
|
||||
};
|
||||
Envelope.EnvelopeParams envelopePars = new Envelope.EnvelopeParams();
|
||||
envelopePars.decay = duration <= 0 ? 1 : 1 / duration;
|
||||
PerlinShake.Params pars = new PerlinShake.Params
|
||||
{
|
||||
strength = new Displacement(new Vector3(1, 1) * positionStrength, Vector3.forward * rotationStrength),
|
||||
noiseModes = modes,
|
||||
envelope = envelopePars,
|
||||
};
|
||||
shaker.RegisterShake(new PerlinShake(pars));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suitable for longer and stronger shakes in 3D. Rotates camera in all three axes.
|
||||
/// </summary>
|
||||
/// <param name="strength">Strength of the shake.</param>
|
||||
/// <param name="duration">Duration of the shake.</param>
|
||||
public void Explosion3D(
|
||||
float strength = 8f,
|
||||
float duration = 0.7f)
|
||||
{
|
||||
PerlinShake.NoiseMode[] modes =
|
||||
{
|
||||
new PerlinShake.NoiseMode(6, 1),
|
||||
new PerlinShake.NoiseMode(20, 0.2f)
|
||||
};
|
||||
Envelope.EnvelopeParams envelopePars = new Envelope.EnvelopeParams();
|
||||
envelopePars.decay = duration <= 0 ? 1 : 1 / duration;
|
||||
PerlinShake.Params pars = new PerlinShake.Params
|
||||
{
|
||||
strength = new Displacement(Vector3.zero, new Vector3(1, 1, 0.5f) * strength),
|
||||
noiseModes = modes,
|
||||
envelope = envelopePars,
|
||||
};
|
||||
shaker.RegisterShake(new PerlinShake(pars));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27cd455dd46fc6a47b7cc4f29f710304
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
KFAttached/GG Camera Shake/Runtime/CameraShaker.cs
Normal file
98
KFAttached/GG Camera Shake/Runtime/CameraShaker.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
/// <summary>
|
||||
/// Camera shaker component registeres new shakes, holds a list of active shakes, and applies them to the camera additively.
|
||||
/// </summary>
|
||||
public class CameraShaker : MonoBehaviour
|
||||
{
|
||||
public static CameraShaker Instance;
|
||||
public static CameraShakePresets Presets;
|
||||
|
||||
readonly List<ICameraShake> activeShakes = new List<ICameraShake>();
|
||||
|
||||
[Tooltip("Transform which will be affected by the shakes.\n\nCameraShaker will set this transform's local position and rotation.")]
|
||||
[SerializeField]
|
||||
Transform cameraTransform;
|
||||
|
||||
|
||||
[Tooltip("Scales the strength of all shakes.")]
|
||||
[Range(0, 1)]
|
||||
[SerializeField]
|
||||
public float StrengthMultiplier = 1;
|
||||
|
||||
public CameraShakePresets ShakePresets;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a shake to the list of active shakes.
|
||||
/// </summary>
|
||||
public static void Shake(ICameraShake shake)
|
||||
{
|
||||
if (IsInstanceNull()) return;
|
||||
Instance.RegisterShake(shake);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a shake to the list of active shakes.
|
||||
/// </summary>
|
||||
public void RegisterShake(ICameraShake shake)
|
||||
{
|
||||
shake.Initialize(cameraTransform.position,
|
||||
cameraTransform.rotation);
|
||||
activeShakes.Add(shake);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the transform which will be affected by the shakes.
|
||||
/// </summary>
|
||||
public void SetCameraTransform(Transform cameraTransform)
|
||||
{
|
||||
cameraTransform.localPosition = Vector3.zero;
|
||||
cameraTransform.localEulerAngles = Vector3.zero;
|
||||
this.cameraTransform = cameraTransform;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
ShakePresets = new CameraShakePresets(this);
|
||||
Presets = ShakePresets;
|
||||
if (cameraTransform == null)
|
||||
cameraTransform = transform;
|
||||
}
|
||||
|
||||
public void UpdateShake()
|
||||
{
|
||||
if (cameraTransform == null) return;
|
||||
|
||||
Displacement cameraDisplacement = Displacement.Zero;
|
||||
for (int i = activeShakes.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (activeShakes[i].IsFinished)
|
||||
{
|
||||
activeShakes.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
activeShakes[i].Update(Time.deltaTime, cameraTransform.position, cameraTransform.rotation);
|
||||
cameraDisplacement += activeShakes[i].CurrentDisplacement;
|
||||
}
|
||||
}
|
||||
cameraTransform.localPosition = transform.localPosition + StrengthMultiplier * cameraDisplacement.position;
|
||||
cameraTransform.localRotation *= Quaternion.Euler(StrengthMultiplier * cameraDisplacement.eulerAngles);
|
||||
}
|
||||
|
||||
private static bool IsInstanceNull()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Debug.LogError("CameraShaker Instance is missing!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/CameraShaker.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/CameraShaker.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a257897ce04dc64eb5ae266c62846be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
KFAttached/GG Camera Shake/Runtime/Displacement.cs
Normal file
98
KFAttached/GG Camera Shake/Runtime/Displacement.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
/// <summary>
|
||||
/// Representation of translation and rotation.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public struct Displacement
|
||||
{
|
||||
public Vector3 position;
|
||||
public Vector3 eulerAngles;
|
||||
|
||||
public Displacement(Vector3 position, Vector3 eulerAngles)
|
||||
{
|
||||
this.position = position;
|
||||
this.eulerAngles = eulerAngles;
|
||||
}
|
||||
|
||||
public Displacement(Vector3 position)
|
||||
{
|
||||
this.position = position;
|
||||
this.eulerAngles = Vector3.zero;
|
||||
}
|
||||
|
||||
public static Displacement Zero
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Displacement(Vector3.zero, Vector3.zero);
|
||||
}
|
||||
}
|
||||
|
||||
public static Displacement operator +(Displacement a, Displacement b)
|
||||
{
|
||||
return new Displacement(a.position + b.position,
|
||||
b.eulerAngles + a.eulerAngles);
|
||||
}
|
||||
|
||||
public static Displacement operator -(Displacement a, Displacement b)
|
||||
{
|
||||
return new Displacement(a.position - b.position,
|
||||
b.eulerAngles - a.eulerAngles);
|
||||
}
|
||||
|
||||
public static Displacement operator -(Displacement disp)
|
||||
{
|
||||
return new Displacement(-disp.position, -disp.eulerAngles);
|
||||
}
|
||||
|
||||
public static Displacement operator *(Displacement coords, float number)
|
||||
{
|
||||
return new Displacement(coords.position * number,
|
||||
coords.eulerAngles * number);
|
||||
}
|
||||
|
||||
public static Displacement operator *(float number, Displacement coords)
|
||||
{
|
||||
return coords * number;
|
||||
}
|
||||
|
||||
public static Displacement operator /(Displacement coords, float number)
|
||||
{
|
||||
return new Displacement(coords.position / number,
|
||||
coords.eulerAngles / number);
|
||||
}
|
||||
|
||||
public static Displacement Scale(Displacement a, Displacement b)
|
||||
{
|
||||
return new Displacement(Vector3.Scale(a.position, b.position),
|
||||
Vector3.Scale(b.eulerAngles, a.eulerAngles));
|
||||
}
|
||||
|
||||
public static Displacement Lerp(Displacement a, Displacement b, float t)
|
||||
{
|
||||
return new Displacement(Vector3.Lerp(a.position, b.position, t),
|
||||
Vector3.Lerp(a.eulerAngles, b.eulerAngles, t));
|
||||
}
|
||||
|
||||
public Displacement ScaledBy(float posScale, float rotScale)
|
||||
{
|
||||
return new Displacement(position * posScale, eulerAngles * rotScale);
|
||||
}
|
||||
|
||||
public Displacement Normalized
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Displacement(position.normalized, eulerAngles.normalized);
|
||||
}
|
||||
}
|
||||
|
||||
public static Displacement InsideUnitSpheres()
|
||||
{
|
||||
return new Displacement(Random.insideUnitSphere, Random.insideUnitSphere);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/Displacement.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/Displacement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22dc566280f4a704d958e931abdb9fc4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
168
KFAttached/GG Camera Shake/Runtime/Envelope.cs
Normal file
168
KFAttached/GG Camera Shake/Runtime/Envelope.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls strength of the shake over time.
|
||||
/// </summary>
|
||||
public class Envelope : IAmplitudeController
|
||||
{
|
||||
readonly EnvelopeParams pars;
|
||||
readonly EnvelopeControlMode controlMode;
|
||||
|
||||
float amplitude;
|
||||
float targetAmplitude;
|
||||
float sustainEndTime;
|
||||
bool finishWhenAmplitudeZero;
|
||||
bool finishImmediately;
|
||||
EnvelopeState state;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an Envelope instance.
|
||||
/// </summary>
|
||||
/// <param name="pars">Envelope parameters.</param>
|
||||
/// <param name="controlMode">Pass Auto for a single shake, or Manual for controlling strength manually.</param>
|
||||
public Envelope(EnvelopeParams pars, float initialTargetAmplitude, EnvelopeControlMode controlMode)
|
||||
{
|
||||
this.pars = pars;
|
||||
this.controlMode = controlMode;
|
||||
SetTarget(initialTargetAmplitude);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value by which you want to multiply shake displacement.
|
||||
/// </summary>
|
||||
public float Intensity { get; private set; }
|
||||
|
||||
public bool IsFinished
|
||||
{
|
||||
get
|
||||
{
|
||||
if (finishImmediately) return true;
|
||||
return (finishWhenAmplitudeZero || controlMode == EnvelopeControlMode.Auto)
|
||||
&& amplitude <= 0 && targetAmplitude <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void Finish()
|
||||
{
|
||||
finishWhenAmplitudeZero = true;
|
||||
SetTarget(0);
|
||||
}
|
||||
|
||||
public void FinishImmediately()
|
||||
{
|
||||
finishImmediately = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update is called every frame by the shake.
|
||||
/// </summary>
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (IsFinished) return;
|
||||
|
||||
if (state == EnvelopeState.Increase)
|
||||
{
|
||||
if (pars.attack > 0)
|
||||
amplitude += deltaTime * pars.attack;
|
||||
if (amplitude > targetAmplitude || pars.attack <= 0)
|
||||
{
|
||||
amplitude = targetAmplitude;
|
||||
state = EnvelopeState.Sustain;
|
||||
if (controlMode == EnvelopeControlMode.Auto)
|
||||
sustainEndTime = Time.time + pars.sustain;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state == EnvelopeState.Decrease)
|
||||
{
|
||||
|
||||
if (pars.decay > 0)
|
||||
amplitude -= deltaTime * pars.decay;
|
||||
if (amplitude < targetAmplitude || pars.decay <= 0)
|
||||
{
|
||||
amplitude = targetAmplitude;
|
||||
state = EnvelopeState.Sustain;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (controlMode == EnvelopeControlMode.Auto && Time.time > sustainEndTime)
|
||||
{
|
||||
SetTarget(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
amplitude = Mathf.Clamp01(amplitude);
|
||||
Intensity = Power.Evaluate(amplitude, pars.degree);
|
||||
}
|
||||
|
||||
public void SetTargetAmplitude(float value)
|
||||
{
|
||||
if (controlMode == EnvelopeControlMode.Manual && !finishWhenAmplitudeZero)
|
||||
{
|
||||
SetTarget(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTarget(float value)
|
||||
{
|
||||
targetAmplitude = Mathf.Clamp01(value);
|
||||
state = targetAmplitude > amplitude ? EnvelopeState.Increase : EnvelopeState.Decrease;
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class EnvelopeParams
|
||||
{
|
||||
/// <summary>
|
||||
/// How fast the amplitude rises.
|
||||
/// </summary>
|
||||
[Tooltip("How fast the amplitude increases.")]
|
||||
public float attack = 10;
|
||||
|
||||
/// <summary>
|
||||
/// How long in seconds the amplitude holds a maximum value.
|
||||
/// </summary>
|
||||
[Tooltip("How long in seconds the amplitude holds maximum value.")]
|
||||
public float sustain = 0;
|
||||
|
||||
/// <summary>
|
||||
/// How fast the amplitude falls.
|
||||
/// </summary>
|
||||
[Tooltip("How fast the amplitude decreases.")]
|
||||
public float decay = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// Power in which the amplitude is raised to get intensity.
|
||||
/// </summary>
|
||||
[Tooltip("Power in which the amplitude is raised to get intensity.")]
|
||||
public Degree degree = Degree.Cubic;
|
||||
}
|
||||
|
||||
public enum EnvelopeControlMode { Auto, Manual }
|
||||
|
||||
public enum EnvelopeState { Sustain, Increase, Decrease }
|
||||
}
|
||||
|
||||
public interface IAmplitudeController
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets value to which amplitude will move over time.
|
||||
/// </summary>
|
||||
void SetTargetAmplitude(float value);
|
||||
|
||||
/// <summary>
|
||||
/// Sets amplitude to zero and finishes the shake when zero is reached.
|
||||
/// </summary>
|
||||
void Finish();
|
||||
|
||||
/// <summary>
|
||||
/// Immediately finishes the shake.
|
||||
/// </summary>
|
||||
void FinishImmediately();
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/Envelope.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/Envelope.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13084b7de651ead408d3f5ef8c6837b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
KFAttached/GG Camera Shake/Runtime/ICameraShake.cs
Normal file
27
KFAttached/GG Camera Shake/Runtime/ICameraShake.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
public interface ICameraShake
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents current position and rotation of the camera according to the shake.
|
||||
/// </summary>
|
||||
Displacement CurrentDisplacement { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Shake system will dispose the shake on the first frame when this is true.
|
||||
/// </summary>
|
||||
bool IsFinished { get; }
|
||||
|
||||
/// <summary>
|
||||
/// CameraShaker calls this when the shake is added to the list of active shakes.
|
||||
/// </summary>
|
||||
void Initialize(Vector3 cameraPosition, Quaternion cameraRotation);
|
||||
|
||||
/// <summary>
|
||||
/// CameraShaker calls this every frame on active shakes.
|
||||
/// </summary>
|
||||
void Update(float deltaTime, Vector3 cameraPosition, Quaternion cameraRotation);
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/ICameraShake.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/ICameraShake.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a062a4046bad80b469554a84b9b30cab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
121
KFAttached/GG Camera Shake/Runtime/KickShake.cs
Normal file
121
KFAttached/GG Camera Shake/Runtime/KickShake.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
public class KickShake : ICameraShake
|
||||
{
|
||||
readonly Params pars;
|
||||
readonly Vector3? sourcePosition;
|
||||
readonly bool attenuateStrength;
|
||||
|
||||
Displacement direction;
|
||||
Displacement prevWaypoint;
|
||||
Displacement currentWaypoint;
|
||||
bool release;
|
||||
float t;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of KickShake in the direction from the source to the camera.
|
||||
/// </summary>
|
||||
/// <param name="parameters">Parameters of the shake.</param>
|
||||
/// <param name="sourcePosition">World position of the source of the shake.</param>
|
||||
/// <param name="attenuateStrength">Change strength depending on distance from the camera?</param>
|
||||
public KickShake(Params parameters, Vector3 sourcePosition, bool attenuateStrength)
|
||||
{
|
||||
pars = parameters;
|
||||
this.sourcePosition = sourcePosition;
|
||||
this.attenuateStrength = attenuateStrength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of KickShake.
|
||||
/// </summary>
|
||||
/// <param name="parameters">Parameters of the shake.</param>
|
||||
/// <param name="direction">Direction of the kick.</param>
|
||||
public KickShake(Params parameters, Displacement direction)
|
||||
{
|
||||
pars = parameters;
|
||||
this.direction = direction.Normalized;
|
||||
}
|
||||
|
||||
public Displacement CurrentDisplacement { get; private set; }
|
||||
public bool IsFinished { get; private set; }
|
||||
|
||||
|
||||
public void Initialize(Vector3 cameraPosition, Quaternion cameraRotation)
|
||||
{
|
||||
if (sourcePosition != null)
|
||||
{
|
||||
direction = Attenuator.Direction(sourcePosition.Value, cameraPosition, cameraRotation);
|
||||
if (attenuateStrength)
|
||||
direction *= Attenuator.Strength(pars.attenuation, sourcePosition.Value, cameraPosition);
|
||||
}
|
||||
currentWaypoint = Displacement.Scale(direction, pars.strength);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime, Vector3 cameraPosition, Quaternion cameraRotation)
|
||||
{
|
||||
if (t < 1)
|
||||
{
|
||||
Move(deltaTime,
|
||||
release ? pars.releaseTime : pars.attackTime,
|
||||
release ? pars.releaseCurve : pars.attackCurve);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentDisplacement = currentWaypoint;
|
||||
prevWaypoint = currentWaypoint;
|
||||
if (release)
|
||||
{
|
||||
IsFinished = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
release = true;
|
||||
t = 0;
|
||||
currentWaypoint = Displacement.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Move(float deltaTime, float duration, AnimationCurve curve)
|
||||
{
|
||||
if (duration > 0)
|
||||
t += deltaTime / duration;
|
||||
else
|
||||
t = 1;
|
||||
CurrentDisplacement = Displacement.Lerp(prevWaypoint, currentWaypoint, curve.Evaluate(t));
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Params
|
||||
{
|
||||
/// <summary>
|
||||
/// Strength of the shake for each axis.
|
||||
/// </summary>
|
||||
[Tooltip("Strength of the shake for each axis.")]
|
||||
public Displacement strength = new Displacement(Vector3.zero, Vector3.one);
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes to move forward.
|
||||
/// </summary>
|
||||
[Tooltip("How long it takes to move forward.")]
|
||||
public float attackTime = 0.05f;
|
||||
public AnimationCurve attackCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes to move back.
|
||||
/// </summary>
|
||||
[Tooltip("How long it takes to move back.")]
|
||||
public float releaseTime = 0.2f;
|
||||
public AnimationCurve releaseCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// How strength falls with distance from the shake source.
|
||||
/// </summary>
|
||||
[Tooltip("How strength falls with distance from the shake source.")]
|
||||
public Attenuator.StrengthAttenuationParams attenuation;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/KickShake.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/KickShake.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aacae9308ca14a04a8174bd35d85a1be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
144
KFAttached/GG Camera Shake/Runtime/PerlinShake.cs
Normal file
144
KFAttached/GG Camera Shake/Runtime/PerlinShake.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraShake
|
||||
{
|
||||
public class PerlinShake : ICameraShake
|
||||
{
|
||||
readonly Params pars;
|
||||
readonly Envelope envelope;
|
||||
|
||||
public IAmplitudeController AmplitudeController;
|
||||
|
||||
Vector2[] seeds;
|
||||
float time;
|
||||
Vector3? sourcePosition;
|
||||
float norm;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of PerlinShake.
|
||||
/// </summary>
|
||||
/// <param name="parameters">Parameters of the shake.</param>
|
||||
/// <param name="maxAmplitude">Maximum amplitude of the shake.</param>
|
||||
/// <param name="sourcePosition">World position of the source of the shake.</param>
|
||||
/// <param name="manualStrengthControl">Pass true if you want to control amplitude manually.</param>
|
||||
public PerlinShake(
|
||||
Params parameters,
|
||||
float maxAmplitude = 1,
|
||||
Vector3? sourcePosition = null,
|
||||
bool manualStrengthControl = false)
|
||||
{
|
||||
pars = parameters;
|
||||
envelope = new Envelope(pars.envelope, maxAmplitude,
|
||||
manualStrengthControl ?
|
||||
Envelope.EnvelopeControlMode.Manual : Envelope.EnvelopeControlMode.Auto);
|
||||
AmplitudeController = envelope;
|
||||
this.sourcePosition = sourcePosition;
|
||||
}
|
||||
|
||||
public Displacement CurrentDisplacement { get; private set; }
|
||||
public bool IsFinished { get; private set; }
|
||||
|
||||
public void Initialize(Vector3 cameraPosition, Quaternion cameraRotation)
|
||||
{
|
||||
seeds = new Vector2[pars.noiseModes.Length];
|
||||
norm = 0;
|
||||
for (int i = 0; i < seeds.Length; i++)
|
||||
{
|
||||
seeds[i] = Random.insideUnitCircle * 20;
|
||||
norm += pars.noiseModes[i].amplitude;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float deltaTime, Vector3 cameraPosition, Quaternion cameraRotation)
|
||||
{
|
||||
if (envelope.IsFinished)
|
||||
{
|
||||
IsFinished = true;
|
||||
return;
|
||||
}
|
||||
time += deltaTime;
|
||||
envelope.Update(deltaTime);
|
||||
|
||||
Displacement disp = Displacement.Zero;
|
||||
for (int i = 0; i < pars.noiseModes.Length; i++)
|
||||
{
|
||||
disp += pars.noiseModes[i].amplitude / norm *
|
||||
SampleNoise(seeds[i], pars.noiseModes[i].freq);
|
||||
}
|
||||
|
||||
CurrentDisplacement = envelope.Intensity * Displacement.Scale(disp, pars.strength);
|
||||
if (sourcePosition != null)
|
||||
CurrentDisplacement *= Attenuator.Strength(pars.attenuation, sourcePosition.Value, cameraPosition);
|
||||
}
|
||||
|
||||
private Displacement SampleNoise(Vector2 seed, float freq)
|
||||
{
|
||||
Vector3 position = new Vector3(
|
||||
Mathf.PerlinNoise(seed.x + time * freq, seed.y),
|
||||
Mathf.PerlinNoise(seed.x, seed.y + time * freq),
|
||||
Mathf.PerlinNoise(seed.x + time * freq, seed.y + time * freq));
|
||||
position -= Vector3.one * 0.5f;
|
||||
|
||||
Vector3 rotation = new Vector3(
|
||||
Mathf.PerlinNoise(-seed.x - time * freq, -seed.y),
|
||||
Mathf.PerlinNoise(-seed.x, -seed.y - time * freq),
|
||||
Mathf.PerlinNoise(-seed.x - time * freq, -seed.y - time * freq));
|
||||
rotation -= Vector3.one * 0.5f;
|
||||
|
||||
return new Displacement(position, rotation);
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class Params
|
||||
{
|
||||
/// <summary>
|
||||
/// Strength of the shake for each axis.
|
||||
/// </summary>
|
||||
[Tooltip("Strength of the shake for each axis.")]
|
||||
public Displacement strength = new Displacement(Vector3.zero, new Vector3(2, 2, 0.8f));
|
||||
|
||||
/// <summary>
|
||||
/// Layers of perlin noise with different frequencies.
|
||||
/// </summary>
|
||||
[Tooltip("Layers of perlin noise with different frequencies.")]
|
||||
public NoiseMode[] noiseModes = { new NoiseMode(12, 1) };
|
||||
|
||||
/// <summary>
|
||||
/// Strength over time.
|
||||
/// </summary>
|
||||
[Tooltip("Strength of the shake over time.")]
|
||||
public Envelope.EnvelopeParams envelope;
|
||||
|
||||
/// <summary>
|
||||
/// How strength falls with distance from the shake source.
|
||||
/// </summary>
|
||||
[Tooltip("How strength falls with distance from the shake source.")]
|
||||
public Attenuator.StrengthAttenuationParams attenuation;
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public struct NoiseMode
|
||||
{
|
||||
public NoiseMode(float freq, float amplitude)
|
||||
{
|
||||
this.freq = freq;
|
||||
this.amplitude = amplitude;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Frequency multiplier for the noise.
|
||||
/// </summary>
|
||||
[Tooltip("Frequency multiplier for the noise.")]
|
||||
public float freq;
|
||||
|
||||
/// <summary>
|
||||
/// Amplitude of the mode.
|
||||
/// </summary>
|
||||
[Tooltip("Amplitude of the mode.")]
|
||||
[Range(0, 1)]
|
||||
public float amplitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/PerlinShake.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/PerlinShake.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de97a9ba28783f34cae2c44c1d4446d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
KFAttached/GG Camera Shake/Runtime/Power.cs
Normal file
24
KFAttached/GG Camera Shake/Runtime/Power.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace CameraShake
|
||||
{
|
||||
public static class Power
|
||||
{
|
||||
public static float Evaluate(float value, Degree degree)
|
||||
{
|
||||
switch (degree)
|
||||
{
|
||||
case Degree.Linear:
|
||||
return value;
|
||||
case Degree.Quadratic:
|
||||
return value * value;
|
||||
case Degree.Cubic:
|
||||
return value * value * value;
|
||||
case Degree.Quadric:
|
||||
return value * value * value * value;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Degree { Linear, Quadratic, Cubic, Quadric }
|
||||
}
|
||||
11
KFAttached/GG Camera Shake/Runtime/Power.cs.meta
Normal file
11
KFAttached/GG Camera Shake/Runtime/Power.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae1c138ac39e5704daa47650c0a286d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
KFAttached/KFCommonUtilityLib.asmdef
Normal file
20
KFAttached/KFCommonUtilityLib.asmdef
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "KFCommonUtilityLib",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:7f7d1af65c2641843945d409d28f2e20",
|
||||
"GUID:2665a8d13d1b3f18800f46e256720795",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:d60799ab2a985554ea1a39cd38695018"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
KFAttached/KFCommonUtilityLib.asmdef.meta
Normal file
7
KFAttached/KFCommonUtilityLib.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63c0eca1c28248248af7caf2a72a6055
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/KFUtilAttached.meta
Normal file
8
KFAttached/KFUtilAttached.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72825f9e8d606284ba3dd8559d6e91fc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
154
KFAttached/KFUtilAttached/ApexWeaponHudControllerBase.cs
Normal file
154
KFAttached/KFUtilAttached/ApexWeaponHudControllerBase.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class ApexWeaponHudControllerBase : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
protected ComputeShader cptShader;
|
||||
[SerializeField, Range(0, 100)]
|
||||
protected int interPerc;
|
||||
[SerializeField]
|
||||
protected TMP_Text boundText;
|
||||
[SerializeField]
|
||||
protected TMP_Text[] miscText;
|
||||
[SerializeField]
|
||||
protected Renderer screenRenderer;
|
||||
[SerializeField]
|
||||
protected Texture maskTexture;
|
||||
[SerializeField]
|
||||
protected int matIndex;
|
||||
[SerializeField, Range(0, 32)]
|
||||
protected int depth = 0;
|
||||
[SerializeField]
|
||||
protected RenderTextureFormat renderTextureFormat = RenderTextureFormat.Default;
|
||||
[SerializeField]
|
||||
protected FilterMode filterMode = FilterMode.Point;
|
||||
[SerializeField]
|
||||
protected UnityEngine.Experimental.Rendering.GraphicsFormat graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_SRGB;
|
||||
[SerializeField]
|
||||
private string kernalName;
|
||||
[SerializeField, Range(0, 1)]
|
||||
protected float xScale = 1, yScale = 1;
|
||||
protected int kernalIndex = -1;
|
||||
protected Material mat;
|
||||
protected int xGroupCount, yGroupCount;
|
||||
protected CustomRenderTexture targetTexture;
|
||||
protected static bool shaderEnabled;
|
||||
protected static bool stateChecked = false;
|
||||
//max count, elem count, inter pixels, map size
|
||||
protected readonly int[] dataArray = new int[3];
|
||||
protected Color color = Color.white;
|
||||
|
||||
protected static readonly int id_color = Shader.PropertyToID("color");
|
||||
protected static readonly int id_dataArray = Shader.PropertyToID("dataArray");
|
||||
protected static readonly int id_Mask = Shader.PropertyToID("Mask");
|
||||
protected static readonly int id_EmissionMap = Shader.PropertyToID("EmissionMap");
|
||||
protected static readonly int id_EmissionColor = Shader.PropertyToID("_EmissionColor");
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (!stateChecked)
|
||||
{
|
||||
shaderEnabled = SystemInfo.supportsComputeShaders && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.Null && !Application.isBatchMode;
|
||||
stateChecked = true;
|
||||
Console.WriteLine("Compute shader support: " + shaderEnabled);
|
||||
}
|
||||
|
||||
dataArray[0] = 1;
|
||||
dataArray[1] = 0;
|
||||
dataArray[2] = interPerc;
|
||||
xGroupCount = (int)(maskTexture.width * xScale / 8);
|
||||
yGroupCount = (int)(maskTexture.height * yScale / 8);
|
||||
mat = screenRenderer.materials[matIndex];
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (!shaderEnabled)
|
||||
return;
|
||||
|
||||
if (targetTexture == null)
|
||||
{
|
||||
targetTexture = new CustomRenderTexture(maskTexture.width, maskTexture.height, renderTextureFormat)
|
||||
{
|
||||
enableRandomWrite = true,
|
||||
updateMode = CustomRenderTextureUpdateMode.OnDemand,
|
||||
depth = depth,
|
||||
useMipMap = false,
|
||||
autoGenerateMips = false,
|
||||
filterMode = filterMode,
|
||||
graphicsFormat = graphicsFormat,
|
||||
wrapMode = TextureWrapMode.Clamp
|
||||
};
|
||||
}
|
||||
|
||||
if (!targetTexture.IsCreated())
|
||||
targetTexture.Create();
|
||||
|
||||
mat.SetTexture("_EmissionMap", targetTexture);
|
||||
mat.SetColor(id_EmissionColor, Color.white);
|
||||
mat.EnableKeyword("_EMISSION");
|
||||
if (cptShader.HasKernel(kernalName))
|
||||
kernalIndex = cptShader.FindKernel(kernalName);
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
OnDisable();
|
||||
if (targetTexture != null)
|
||||
targetTexture.Release();
|
||||
}
|
||||
|
||||
public virtual void SetColor(Color color)
|
||||
{
|
||||
if (boundText != null)
|
||||
boundText.color = color;
|
||||
if (miscText != null)
|
||||
foreach (var t in miscText)
|
||||
t.color = color;
|
||||
|
||||
this.color = color;
|
||||
//mat.SetColor(id_EmissionColor, color);
|
||||
if (CanDispatch())
|
||||
Dispatch(dataArray);
|
||||
}
|
||||
|
||||
public virtual void SetText(string text)
|
||||
{
|
||||
if (text.StartsWith("#"))
|
||||
{
|
||||
dataArray[0] = Mathf.Max(int.Parse(text.Substring(1)), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (boundText != null)
|
||||
boundText.SetText(text);
|
||||
dataArray[1] = int.Parse(text);
|
||||
}
|
||||
|
||||
if (CanDispatch())
|
||||
Dispatch(dataArray);
|
||||
}
|
||||
|
||||
protected virtual bool CanDispatch()
|
||||
{
|
||||
return shaderEnabled && kernalIndex >= 0;
|
||||
}
|
||||
|
||||
protected virtual void Dispatch(int[] dataArray)
|
||||
{
|
||||
cptShader.SetInts(id_dataArray, dataArray);
|
||||
cptShader.SetVector(id_color, color);
|
||||
cptShader.SetTexture(kernalIndex, id_Mask, maskTexture);
|
||||
cptShader.SetTexture(kernalIndex, id_EmissionMap, targetTexture, 0);
|
||||
cptShader.Dispatch(kernalIndex, xGroupCount, yGroupCount, 1);
|
||||
//targetTexture.GenerateMips();
|
||||
//targetTexture.Update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0e18e2e55ec5014aad7a8808cd65efa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
KFAttached/KFUtilAttached/ChargeUpController.cs
Normal file
17
KFAttached/KFUtilAttached/ChargeUpController.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Weapon Display Controllers/Charge Up controller")]
|
||||
public class ChargeUpController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private WeaponLabelControllerChargeUp controller;
|
||||
private void OnEnable()
|
||||
{
|
||||
controller.StartChargeUp();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
controller.StopChargeUp();
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/ChargeUpController.cs.meta
Normal file
11
KFAttached/KFUtilAttached/ChargeUpController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccb8b18bea7ff8843a380b9e611799de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
KFAttached/KFUtilAttached/MuzzlePositionBinding.cs
Normal file
33
KFAttached/KFUtilAttached/MuzzlePositionBinding.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("Muzzle Position Binding")]
|
||||
public class MuzzlePositionBinding : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform muzzleTrans;
|
||||
[SerializeField]
|
||||
private Vector3 newMuzzlePosition;
|
||||
private Vector3 initialPosition;
|
||||
private void Awake()
|
||||
{
|
||||
if (muzzleTrans)
|
||||
initialPosition = transform.localPosition;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (muzzleTrans)
|
||||
muzzleTrans.localPosition = newMuzzlePosition;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (muzzleTrans)
|
||||
muzzleTrans.localPosition = initialPosition;
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/MuzzlePositionBinding.cs.meta
Normal file
11
KFAttached/KFUtilAttached/MuzzlePositionBinding.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d4b7e316af9faf4f9697b0d60f96793
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
69
KFAttached/KFUtilAttached/RigActivationBinding.cs
Normal file
69
KFAttached/KFUtilAttached/RigActivationBinding.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Binding Helpers/Rig Activation Binding")]
|
||||
public class RigActivationBinding : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private RigLayer[] bindings;
|
||||
[SerializeField]
|
||||
private RigLayer[] inverseBindings;
|
||||
[SerializeField]
|
||||
private RigLayer[] enableOnDisable;
|
||||
[SerializeField]
|
||||
private RigLayer[] disableOnEnable;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//Log.Out(gameObject.name + " OnEnable!");
|
||||
if (bindings != null)
|
||||
{
|
||||
foreach (RigLayer t in bindings)
|
||||
if (t != null)
|
||||
t.active = true;
|
||||
}
|
||||
if (inverseBindings != null)
|
||||
{
|
||||
foreach (RigLayer t in inverseBindings)
|
||||
{
|
||||
if (t != null)
|
||||
t.active = false;
|
||||
}
|
||||
}
|
||||
if (disableOnEnable != null)
|
||||
{
|
||||
foreach (RigLayer t in disableOnEnable)
|
||||
{
|
||||
if (t != null)
|
||||
t.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
//Log.Out(gameObject.name + " OnDisable!");
|
||||
if (bindings != null)
|
||||
{
|
||||
foreach (RigLayer t in bindings)
|
||||
if (t != null)
|
||||
t.active = false;
|
||||
}
|
||||
if (inverseBindings != null)
|
||||
{
|
||||
foreach (RigLayer t in inverseBindings)
|
||||
{
|
||||
if (t != null)
|
||||
t.active = true;
|
||||
}
|
||||
}
|
||||
if (enableOnDisable != null)
|
||||
{
|
||||
foreach (RigLayer t in enableOnDisable)
|
||||
{
|
||||
if (t != null)
|
||||
t.active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/RigActivationBinding.cs.meta
Normal file
11
KFAttached/KFUtilAttached/RigActivationBinding.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01778f8886cb5864c842e544741586b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
141
KFAttached/KFUtilAttached/TransformActivationBinding.cs
Normal file
141
KFAttached/KFUtilAttached/TransformActivationBinding.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Binding Helpers/Transform Activation Binding")]
|
||||
public class TransformActivationBinding : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
internal GameObject[] bindings;
|
||||
[SerializeField]
|
||||
private GameObject[] inverseBindings;
|
||||
[SerializeField]
|
||||
private GameObject[] enableOnDisable;
|
||||
[SerializeField]
|
||||
private GameObject[] disableOnEnable;
|
||||
[SerializeField]
|
||||
private GameObject[] enableOnEnable;
|
||||
[SerializeField]
|
||||
private GameObject[] disableOnDisable;
|
||||
[SerializeField]
|
||||
private string[] animatorParamBindings;
|
||||
internal AnimationTargetsAbs targets;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//Log.Out(gameObject.name + " OnEnable!");
|
||||
if (bindings != null)
|
||||
{
|
||||
foreach (GameObject t in bindings)
|
||||
{
|
||||
if (t)
|
||||
t.SetActive(true);
|
||||
}
|
||||
}
|
||||
if (inverseBindings != null)
|
||||
{
|
||||
foreach (GameObject t in inverseBindings)
|
||||
{
|
||||
if (t)
|
||||
t.SetActive(false);
|
||||
}
|
||||
}
|
||||
if (disableOnEnable != null)
|
||||
{
|
||||
foreach (GameObject t in disableOnEnable)
|
||||
{
|
||||
if (t)
|
||||
t.SetActive(false);
|
||||
}
|
||||
}
|
||||
if (enableOnEnable != null)
|
||||
{
|
||||
foreach (GameObject t in enableOnEnable)
|
||||
{
|
||||
if (t)
|
||||
t.SetActive(true);
|
||||
}
|
||||
}
|
||||
#if NotEditor
|
||||
ThreadManager.StartCoroutine(UpdateBool(true));
|
||||
#else
|
||||
UpdateBoolEditor(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
//Log.Out(gameObject.name + " OnDisable!");
|
||||
if (bindings != null)
|
||||
{
|
||||
foreach (GameObject t in bindings)
|
||||
if (t)
|
||||
t.SetActive(false);
|
||||
}
|
||||
if (inverseBindings != null)
|
||||
{
|
||||
foreach (GameObject t in inverseBindings)
|
||||
{
|
||||
if (t)
|
||||
t.SetActive(true);
|
||||
}
|
||||
}
|
||||
if (enableOnDisable != null)
|
||||
{
|
||||
foreach (GameObject t in enableOnDisable)
|
||||
{
|
||||
if (t)
|
||||
t.SetActive(true);
|
||||
}
|
||||
}
|
||||
if (disableOnDisable != null)
|
||||
{
|
||||
foreach (GameObject t in disableOnDisable)
|
||||
{
|
||||
if (t)
|
||||
t.SetActive(true);
|
||||
}
|
||||
}
|
||||
#if NotEditor
|
||||
ThreadManager.StartCoroutine(UpdateBool(false));
|
||||
#else
|
||||
UpdateBoolEditor(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
internal IEnumerator UpdateBool(bool enabled)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
if (animatorParamBindings != null && targets && targets.IsAnimationSet)
|
||||
{
|
||||
foreach (string str in animatorParamBindings)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
targets.GraphBuilder.Player.emodel.avatarController.UpdateBool(str, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
internal void UpdateBoolEditor(bool enabled)
|
||||
{
|
||||
if (animatorParamBindings != null && targets && targets.IsAnimationSet)
|
||||
{
|
||||
IAnimatorWrapper animator = targets.GraphBuilder.WeaponWrapper;
|
||||
if (animator == null || !animator.IsValid)
|
||||
{
|
||||
Log.Warning($"animator wrapper invalid!");
|
||||
return;
|
||||
}
|
||||
foreach (string str in animatorParamBindings)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
animator.SetBool(str, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/TransformActivationBinding.cs.meta
Normal file
11
KFAttached/KFUtilAttached/TransformActivationBinding.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f2bc8183b119f347a32259111b5d1f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
KFAttached/KFUtilAttached/WeaponColorController.cs
Normal file
16
KFAttached/KFUtilAttached/WeaponColorController.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Weapon Display Controllers/Weapon Color Controller")]
|
||||
public class WeaponColorController : WeaponColorControllerBase
|
||||
{
|
||||
[SerializeField]
|
||||
protected Renderer[] renderers;
|
||||
|
||||
public override bool setMaterialColor(int renderer_index, int material_index, int nameId, Color data)
|
||||
{
|
||||
if (renderers == null || renderers.Length <= renderer_index || !renderers[renderer_index].gameObject.activeInHierarchy || renderers[renderer_index].materials.Length <= material_index)
|
||||
return false;
|
||||
renderers[renderer_index].materials[material_index].SetColor(nameId, data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponColorController.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponColorController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcfafc95230152c408908547f15202e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6
KFAttached/KFUtilAttached/WeaponColorControllerBase.cs
Normal file
6
KFAttached/KFUtilAttached/WeaponColorControllerBase.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class WeaponColorControllerBase : MonoBehaviour
|
||||
{
|
||||
public abstract bool setMaterialColor(int renderer_index, int material_index, int nameId, Color data);
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponColorControllerBase.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponColorControllerBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fe7c9577b97dd8448e83857ceac21db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
KFAttached/KFUtilAttached/WeaponDataController.cs
Normal file
24
KFAttached/KFUtilAttached/WeaponDataController.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponDataController : WeaponLabelControllerBase
|
||||
{
|
||||
[SerializeField]
|
||||
private WeaponDataHandlerBase[] handlers;
|
||||
public override bool setLabelColor(int index, Color color)
|
||||
{
|
||||
if (handlers == null || index >= handlers.Length || index < 0 || !handlers[index] || !handlers[index].gameObject.activeSelf)
|
||||
return false;
|
||||
|
||||
handlers[index]?.SetColor(color);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool setLabelText(int index, string data)
|
||||
{
|
||||
if (handlers == null || index >= handlers.Length || index < 0 || !handlers[index] || !handlers[index].gameObject.activeSelf)
|
||||
return false;
|
||||
|
||||
handlers[index]?.SetText(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponDataController.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponDataController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f524ab568d21bf4d8f037fe0dee9c22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
KFAttached/KFUtilAttached/WeaponDataHandlerBase.cs
Normal file
7
KFAttached/KFUtilAttached/WeaponDataHandlerBase.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class WeaponDataHandlerBase : MonoBehaviour
|
||||
{
|
||||
public abstract void SetColor(Color color);
|
||||
public abstract void SetText(string text);
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponDataHandlerBase.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponDataHandlerBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3657194e2634c8a4a8aea7e7becd0581
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
KFAttached/KFUtilAttached/WeaponDataHandlerCanvasMask.cs
Normal file
51
KFAttached/KFUtilAttached/WeaponDataHandlerCanvasMask.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class WeaponDataHandlerCanvasMask : WeaponDataHandlerBase
|
||||
{
|
||||
[SerializeField]
|
||||
protected RectMask2D mask;
|
||||
[SerializeField]
|
||||
protected Image image;
|
||||
|
||||
protected float maxVal = 1, curVal = 1;
|
||||
//protected bool updated = true;
|
||||
|
||||
//protected virtual void OnEnable()
|
||||
//{
|
||||
// LayoutRebuilder.MarkLayoutForRebuild(mask.rectTransform);
|
||||
//}
|
||||
|
||||
public override void SetColor(Color color)
|
||||
{
|
||||
image.color = color;
|
||||
}
|
||||
|
||||
public override void SetText(string text)
|
||||
{
|
||||
if (text.StartsWith("#"))
|
||||
{
|
||||
maxVal = Mathf.Max(float.Parse(text.Substring(1)), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
curVal = Mathf.Max(float.Parse(text), 0);
|
||||
}
|
||||
if (curVal > maxVal)
|
||||
maxVal = curVal;
|
||||
float perc = curVal / maxVal;
|
||||
Vector4 padding = mask.padding;
|
||||
padding.w = mask.rectTransform.rect.height * Mathf.Clamp01(1 - perc);
|
||||
mask.padding = padding;
|
||||
//updated = true;
|
||||
}
|
||||
|
||||
//protected virtual void LateUpdate()
|
||||
//{
|
||||
// if (updated)
|
||||
// {
|
||||
// LayoutRebuilder.ForceRebuildLayoutImmediate(mask.rectTransform);
|
||||
// updated = false;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 013c89968af9af042960a4fec49cd708
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
KFAttached/KFUtilAttached/WeaponDataHandlerIndicator.cs
Normal file
71
KFAttached/KFUtilAttached/WeaponDataHandlerIndicator.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponDataHandlerIndicator : WeaponDataHandlerCanvasMask
|
||||
{
|
||||
[SerializeField]
|
||||
protected RectTransform indicator;
|
||||
[SerializeField]
|
||||
protected float offset;
|
||||
[SerializeField, ColorUsage(true, true)]
|
||||
protected Color normalColor;
|
||||
[SerializeField, ColorUsage(true, true)]
|
||||
protected Color warningColor;
|
||||
|
||||
protected float level = 0;
|
||||
|
||||
//private void Start()
|
||||
//{
|
||||
// LayoutRebuilder.MarkLayoutForRebuild(indicator.parent.GetComponent<RectTransform>());
|
||||
//}
|
||||
|
||||
//protected override void OnEnable()
|
||||
//{
|
||||
// base.OnEnable();
|
||||
// LayoutRebuilder.MarkLayoutForRebuild(indicator.parent.GetComponent<RectTransform>());
|
||||
//}
|
||||
|
||||
public override void SetText(string text)
|
||||
{
|
||||
if (text.StartsWith("$"))
|
||||
{
|
||||
level = Mathf.Clamp01(float.Parse(text.Substring(1)) / maxVal);
|
||||
SetIndicatorPos();
|
||||
//updated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
float prevMax = maxVal;
|
||||
base.SetText(text);
|
||||
if (prevMax != maxVal)
|
||||
{
|
||||
level = prevMax * level / maxVal;
|
||||
SetIndicatorPos();
|
||||
}
|
||||
}
|
||||
//Log.Out($"Setting text {text} max {maxVal} cur {curVal} level {level} indicator position {indicator.position.y} mask position {mask.padding.w}");
|
||||
if (curVal / maxVal < level)
|
||||
{
|
||||
SetColor(warningColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetColor(normalColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetIndicatorPos()
|
||||
{
|
||||
Vector3 pos = indicator.anchoredPosition;
|
||||
pos.y = mask.rectTransform.rect.height * level + offset;
|
||||
indicator.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
//protected override void LateUpdate()
|
||||
//{
|
||||
// if (updated)
|
||||
// {
|
||||
// LayoutRebuilder.ForceRebuildLayoutImmediate(indicator.parent.GetComponent<RectTransform>());
|
||||
// }
|
||||
// base.LateUpdate();
|
||||
//}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponDataHandlerIndicator.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponDataHandlerIndicator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e993a995fe33f8742bd17bf4b5cae305
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
KFAttached/KFUtilAttached/WeaponDataHandlerTMP.cs
Normal file
17
KFAttached/KFUtilAttached/WeaponDataHandlerTMP.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponDataHandlerTMP : WeaponDataHandlerBase
|
||||
{
|
||||
[SerializeField]
|
||||
private TMP_Text label;
|
||||
public override void SetColor(Color color)
|
||||
{
|
||||
label.color = color;
|
||||
}
|
||||
|
||||
public override void SetText(string text)
|
||||
{
|
||||
label.SetText(text);
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponDataHandlerTMP.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponDataHandlerTMP.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6ee4e451d350e048954e14bbccf6e6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
KFAttached/KFUtilAttached/WeaponLabelController.cs
Normal file
24
KFAttached/KFUtilAttached/WeaponLabelController.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Weapon Display Controllers/Weapon Label Controller TextMesh")]
|
||||
public class WeaponLabelController : WeaponLabelControllerBase
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMesh[] labels;
|
||||
|
||||
public override bool setLabelText(int index, string data)
|
||||
{
|
||||
if (labels == null || labels.Length <= index || !labels[index] || !labels[index].gameObject.activeSelf)
|
||||
return false;
|
||||
labels[index].text = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool setLabelColor(int index, Color color)
|
||||
{
|
||||
if (labels == null || labels.Length <= index || !labels[index] || !labels[index].gameObject.activeSelf)
|
||||
return false;
|
||||
labels[index].color = color;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponLabelController.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponLabelController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a067c009a9175a34db35886e48ce0129
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
KFAttached/KFUtilAttached/WeaponLabelControllerBase.cs
Normal file
7
KFAttached/KFUtilAttached/WeaponLabelControllerBase.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class WeaponLabelControllerBase : MonoBehaviour
|
||||
{
|
||||
public abstract bool setLabelText(int index, string data);
|
||||
public abstract bool setLabelColor(int index, Color color);
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponLabelControllerBase.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponLabelControllerBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc5547a942561564bb81d0ee893e4100
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
KFAttached/KFUtilAttached/WeaponLabelControllerBatch.cs
Normal file
36
KFAttached/KFUtilAttached/WeaponLabelControllerBatch.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace KFCommonUtilityLib.KFAttached.KFUtilAttached
|
||||
{
|
||||
public class WeaponLabelControllerBatch : WeaponLabelControllerBase
|
||||
{
|
||||
[SerializeField]
|
||||
private WeaponLabelControllerBase[] controllers;
|
||||
|
||||
public override bool setLabelColor(int index, Color color)
|
||||
{
|
||||
bool flag = false;
|
||||
foreach (var controller in controllers)
|
||||
{
|
||||
if (controller && controller.isActiveAndEnabled)
|
||||
{
|
||||
flag |= controller.setLabelColor(index, color);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public override bool setLabelText(int index, string data)
|
||||
{
|
||||
bool flag = false;
|
||||
foreach (var controller in controllers)
|
||||
{
|
||||
if (controller && controller.isActiveAndEnabled)
|
||||
{
|
||||
flag |= controller.setLabelText(index, data);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponLabelControllerBatch.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponLabelControllerBatch.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bdf1f2fdda9aae4c80dd6e0bdba81d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
KFAttached/KFUtilAttached/WeaponLabelControllerChargeUp.cs
Normal file
61
KFAttached/KFUtilAttached/WeaponLabelControllerChargeUp.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Weapon Display Controllers/Weapon Label Controller Charge Up")]
|
||||
public class WeaponLabelControllerChargeUp : ApexWeaponHudControllerBase
|
||||
{
|
||||
[SerializeField, Range(0.001f, 1f)]
|
||||
protected float tickTime;
|
||||
[SerializeField, Range(1, 1000)]
|
||||
protected int updateTicks = 1;
|
||||
protected Coroutine curChargeProc;
|
||||
protected bool isChargeRunning = false;
|
||||
internal void StartChargeUp()
|
||||
{
|
||||
if (shaderEnabled && (curChargeProc == null || !isChargeRunning))
|
||||
curChargeProc = StartCoroutine(ChargeUp());
|
||||
}
|
||||
|
||||
internal void StopChargeUp()
|
||||
{
|
||||
if (shaderEnabled && curChargeProc != null)
|
||||
{
|
||||
StopCoroutine(curChargeProc);
|
||||
curChargeProc = null;
|
||||
isChargeRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
StopChargeUp();
|
||||
}
|
||||
|
||||
private IEnumerator ChargeUp()
|
||||
{
|
||||
isChargeRunning = true;
|
||||
float chargeLeap = (float)dataArray[0] / updateTicks;
|
||||
int[] chargeArray = new int[4];
|
||||
float curChargeCount = 0;
|
||||
dataArray.CopyTo(chargeArray, 0);
|
||||
int max = dataArray[1];
|
||||
chargeArray[1] = (int)curChargeCount;
|
||||
while (chargeArray[1] <= max)
|
||||
{
|
||||
Dispatch(chargeArray);
|
||||
if (chargeArray[1] == max)
|
||||
break;
|
||||
yield return new WaitForSecondsRealtime(tickTime);
|
||||
max = dataArray[1];
|
||||
curChargeCount += chargeLeap;
|
||||
chargeArray[1] = Mathf.Min((int)curChargeCount, max);
|
||||
}
|
||||
isChargeRunning = false;
|
||||
yield break;
|
||||
}
|
||||
|
||||
protected override bool CanDispatch()
|
||||
{
|
||||
return base.CanDispatch() && !isChargeRunning;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24181b5d7224798438ea0bb73892de70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
KFAttached/KFUtilAttached/WeaponLabelControllerDevotion.cs
Normal file
25
KFAttached/KFUtilAttached/WeaponLabelControllerDevotion.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Weapon Display Controllers/Weapon Label Controller Devotion")]
|
||||
public class WeaponLabelControllerDevotion : WeaponLabelControllerBase
|
||||
{
|
||||
[SerializeField]
|
||||
private ApexWeaponHudControllerBase[] controllers;
|
||||
public override bool setLabelColor(int index, Color color)
|
||||
{
|
||||
if (controllers == null || index >= controllers.Length || !controllers[index] || !controllers[index].gameObject.activeSelf)
|
||||
return false;
|
||||
|
||||
controllers[index].SetColor(color);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool setLabelText(int index, string data)
|
||||
{
|
||||
if (controllers == null || index >= controllers.Length || !controllers[index] || !controllers[index].gameObject.activeSelf)
|
||||
return false;
|
||||
|
||||
controllers[index].SetText(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bc6e113f61659f489e67db4beb49b7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
KFAttached/KFUtilAttached/WeaponTextProController.cs
Normal file
25
KFAttached/KFUtilAttached/WeaponTextProController.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/Weapon Display Controllers/Weapon Text Controller TMP")]
|
||||
public class WeaponTextProController : WeaponLabelControllerBase
|
||||
{
|
||||
[SerializeField]
|
||||
private TMP_Text[] labels;
|
||||
|
||||
public override bool setLabelText(int index, string data)
|
||||
{
|
||||
if (labels == null || labels.Length <= index || !labels[index] || !labels[index].gameObject.activeSelf)
|
||||
return false;
|
||||
labels[index].SetText(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool setLabelColor(int index, Color color)
|
||||
{
|
||||
if (labels == null || labels.Length <= index || !labels[index] || !labels[index].gameObject.activeSelf)
|
||||
return false;
|
||||
labels[index].color = color;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
KFAttached/KFUtilAttached/WeaponTextProController.cs.meta
Normal file
11
KFAttached/KFUtilAttached/WeaponTextProController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93439c08074a2ef42b5c4da798001216
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/LeanTween.meta
Normal file
8
KFAttached/LeanTween.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e6a0fa47acf54892bbdae89028eaec3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/LeanTween/Framework.meta
Normal file
8
KFAttached/LeanTween/Framework.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3f23ec8eb7c24f0bbb1d41bf96c154f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
2695
KFAttached/LeanTween/Framework/LTDescr.cs
Normal file
2695
KFAttached/LeanTween/Framework/LTDescr.cs
Normal file
@@ -0,0 +1,2695 @@
|
||||
//namespace DentedPixel{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
/**
|
||||
* Internal Representation of a Tween<br>
|
||||
* <br>
|
||||
* This class represents all of the optional parameters you can pass to a method (it also represents the internal representation of the tween).<br><br>
|
||||
* <strong id='optional'>Optional Parameters</strong> are passed at the end of every method:<br>
|
||||
* <br>
|
||||
* <i>Example:</i><br>
|
||||
* LeanTween.moveX( gameObject, 1f, 1f).setEase( <a href="LeanTweenType.html">LeanTweenType</a>.easeInQuad ).setDelay(1f);<br>
|
||||
* <br>
|
||||
* You can pass the optional parameters in any order, and chain on as many as you wish.<br>
|
||||
* You can also <strong>pass parameters at a later time</strong> by saving a reference to what is returned.<br>
|
||||
* <br>
|
||||
* Retrieve a <strong>unique id</strong> for the tween by using the "id" property. You can pass this to LeanTween.pause, LeanTween.resume, LeanTween.cancel, LeanTween.isTweening methods<br>
|
||||
* <br>
|
||||
* <h4>Example:</h4>
|
||||
* int id = LeanTween.moveX(gameObject, 1f, 3f).id;<br>
|
||||
* <div style="color:gray"> // pause a specific tween</div>
|
||||
* LeanTween.pause(id);<br>
|
||||
* <div style="color:gray"> // resume later</div>
|
||||
* LeanTween.resume(id);<br>
|
||||
* <div style="color:gray"> // check if it is tweening before kicking of a new tween</div>
|
||||
* if( LeanTween.isTweening( id ) ){<br>
|
||||
* LeanTween.cancel( id );<br>
|
||||
* LeanTween.moveZ(gameObject, 10f, 3f);<br>
|
||||
* }<br>
|
||||
* @class LTDescr
|
||||
* @constructor
|
||||
*/
|
||||
public class LTDescr
|
||||
{
|
||||
public bool toggle;
|
||||
public bool useEstimatedTime;
|
||||
public bool useFrames;
|
||||
public bool useManualTime;
|
||||
public bool usesNormalDt;
|
||||
public bool hasInitiliazed;
|
||||
public bool hasExtraOnCompletes;
|
||||
public bool hasPhysics;
|
||||
public bool onCompleteOnRepeat;
|
||||
public bool onCompleteOnStart;
|
||||
public bool useRecursion;
|
||||
public float ratioPassed;
|
||||
public float passed;
|
||||
public float delay;
|
||||
public float time;
|
||||
public float speed;
|
||||
public float lastVal;
|
||||
private uint _id;
|
||||
public int loopCount;
|
||||
public uint counter = uint.MaxValue;
|
||||
public float direction;
|
||||
public float directionLast;
|
||||
public float overshoot;
|
||||
public float period;
|
||||
public float scale;
|
||||
public bool destroyOnComplete;
|
||||
public Transform trans;
|
||||
internal Vector3 fromInternal;
|
||||
public Vector3 from { get { return this.fromInternal; } set { this.fromInternal = value; } }
|
||||
internal Vector3 toInternal;
|
||||
public Vector3 to { get { return this.toInternal; } set { this.toInternal = value; } }
|
||||
internal Vector3 diff;
|
||||
internal Vector3 diffDiv2;
|
||||
public TweenAction type;
|
||||
private LeanTweenType easeType;
|
||||
public LeanTweenType loopType;
|
||||
|
||||
public bool hasUpdateCallback;
|
||||
|
||||
public EaseTypeDelegate easeMethod;
|
||||
public ActionMethodDelegate easeInternal { get; set; }
|
||||
public ActionMethodDelegate initInternal { get; set; }
|
||||
public delegate Vector3 EaseTypeDelegate();
|
||||
public delegate void ActionMethodDelegate();
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
public SpriteRenderer spriteRen;
|
||||
#endif
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
public RectTransform rectTransform;
|
||||
public UnityEngine.UI.Text uiText;
|
||||
public UnityEngine.UI.Image uiImage;
|
||||
public UnityEngine.UI.RawImage rawImage;
|
||||
public UnityEngine.Sprite[] sprites;
|
||||
#endif
|
||||
|
||||
// Convenience Getters
|
||||
public Transform toTrans
|
||||
{
|
||||
get
|
||||
{
|
||||
return optional.toTrans;
|
||||
}
|
||||
}
|
||||
|
||||
public LTDescrOptional _optional = new LTDescrOptional();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (trans != null ? "name:" + trans.gameObject.name : "gameObject:null") + " toggle:" + toggle + " passed:" + passed + " time:" + time + " delay:" + delay + " direction:" + direction + " from:" + from + " to:" + to + " diff:" + diff + " type:" + type + " ease:" + easeType + " useEstimatedTime:" + useEstimatedTime + " id:" + id + " hasInitiliazed:" + hasInitiliazed;
|
||||
}
|
||||
|
||||
public LTDescr()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[System.Obsolete("Use 'LeanTween.cancel( id )' instead")]
|
||||
public LTDescr cancel(GameObject gameObject)
|
||||
{
|
||||
// Debug.Log("canceling id:"+this._id+" this.uniqueId:"+this.uniqueId+" go:"+this.trans.gameObject);
|
||||
if (gameObject == this.trans.gameObject)
|
||||
LeanTween.removeTween((int)this._id, this.uniqueId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int uniqueId
|
||||
{
|
||||
get
|
||||
{
|
||||
uint toId = _id | counter << 16;
|
||||
|
||||
/*uint backId = toId & 0xFFFF;
|
||||
uint backCounter = toId >> 16;
|
||||
if(_id!=backId || backCounter!=counter){
|
||||
Debug.LogError("BAD CONVERSION toId:"+_id);
|
||||
}*/
|
||||
|
||||
return (int)toId;
|
||||
}
|
||||
}
|
||||
|
||||
public int id
|
||||
{
|
||||
get
|
||||
{
|
||||
return uniqueId;
|
||||
}
|
||||
}
|
||||
|
||||
public LTDescrOptional optional
|
||||
{
|
||||
get
|
||||
{
|
||||
return _optional;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._optional = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
this.toggle = this.useRecursion = this.usesNormalDt = true;
|
||||
this.trans = null;
|
||||
this.spriteRen = null;
|
||||
this.passed = this.delay = this.lastVal = 0.0f;
|
||||
this.hasUpdateCallback = this.useEstimatedTime = this.useFrames = this.hasInitiliazed = this.onCompleteOnRepeat = this.destroyOnComplete = this.onCompleteOnStart = this.useManualTime = this.hasExtraOnCompletes = false;
|
||||
this.easeType = LeanTweenType.linear;
|
||||
this.loopType = LeanTweenType.once;
|
||||
this.loopCount = 0;
|
||||
this.direction = this.directionLast = this.overshoot = this.scale = 1.0f;
|
||||
this.period = 0.3f;
|
||||
this.speed = -1f;
|
||||
this.easeMethod = this.easeLinear;
|
||||
this.from = this.to = Vector3.zero;
|
||||
this._optional.reset();
|
||||
}
|
||||
|
||||
// Initialize and Internal Methods
|
||||
|
||||
public LTDescr setFollow()
|
||||
{
|
||||
this.type = TweenAction.FOLLOW;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveX()
|
||||
{
|
||||
this.type = TweenAction.MOVE_X;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.position.x; };
|
||||
this.easeInternal = () => { trans.position = new Vector3(easeMethod().x, trans.position.y, trans.position.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveY()
|
||||
{
|
||||
this.type = TweenAction.MOVE_Y;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.position.y; };
|
||||
this.easeInternal = () => { trans.position = new Vector3(trans.position.x, easeMethod().x, trans.position.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveZ()
|
||||
{
|
||||
this.type = TweenAction.MOVE_Z;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.position.z; }; ;
|
||||
this.easeInternal = () => { trans.position = new Vector3(trans.position.x, trans.position.y, easeMethod().x); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveLocalX()
|
||||
{
|
||||
this.type = TweenAction.MOVE_LOCAL_X;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.localPosition.x; };
|
||||
this.easeInternal = () => { trans.localPosition = new Vector3(easeMethod().x, trans.localPosition.y, trans.localPosition.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveLocalY()
|
||||
{
|
||||
this.type = TweenAction.MOVE_LOCAL_Y;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.localPosition.y; };
|
||||
this.easeInternal = () => { trans.localPosition = new Vector3(trans.localPosition.x, easeMethod().x, trans.localPosition.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveLocalZ()
|
||||
{
|
||||
this.type = TweenAction.MOVE_LOCAL_Z;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.localPosition.z; };
|
||||
this.easeInternal = () => { trans.localPosition = new Vector3(trans.localPosition.x, trans.localPosition.y, easeMethod().x); };
|
||||
return this;
|
||||
}
|
||||
|
||||
private void initFromInternal() { this.fromInternal.x = 0; }
|
||||
|
||||
public LTDescr setOffset(Vector3 offset)
|
||||
{
|
||||
this.toInternal = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveCurved()
|
||||
{
|
||||
this.type = TweenAction.MOVE_CURVED;
|
||||
this.initInternal = this.initFromInternal;
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
if (this._optional.path.orientToPath)
|
||||
{
|
||||
if (this._optional.path.orientToPath2d)
|
||||
{
|
||||
this._optional.path.place2d(trans, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._optional.path.place(trans, val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trans.position = this._optional.path.point(val);
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveCurvedLocal()
|
||||
{
|
||||
this.type = TweenAction.MOVE_CURVED_LOCAL;
|
||||
this.initInternal = this.initFromInternal;
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
if (this._optional.path.orientToPath)
|
||||
{
|
||||
if (this._optional.path.orientToPath2d)
|
||||
{
|
||||
this._optional.path.placeLocal2d(trans, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._optional.path.placeLocal(trans, val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trans.localPosition = this._optional.path.point(val);
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveSpline()
|
||||
{
|
||||
this.type = TweenAction.MOVE_SPLINE;
|
||||
this.initInternal = this.initFromInternal;
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
if (this._optional.spline.orientToPath)
|
||||
{
|
||||
if (this._optional.spline.orientToPath2d)
|
||||
{
|
||||
this._optional.spline.place2d(trans, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._optional.spline.place(trans, val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trans.position = this._optional.spline.point(val);
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveSplineLocal()
|
||||
{
|
||||
this.type = TweenAction.MOVE_SPLINE_LOCAL;
|
||||
this.initInternal = this.initFromInternal;
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
if (this._optional.spline.orientToPath)
|
||||
{
|
||||
if (this._optional.spline.orientToPath2d)
|
||||
{
|
||||
this._optional.spline.placeLocal2d(trans, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._optional.spline.placeLocal(trans, val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trans.localPosition = this._optional.spline.point(val);
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setScaleX()
|
||||
{
|
||||
this.type = TweenAction.SCALE_X;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.localScale.x; };
|
||||
this.easeInternal = () => { trans.localScale = new Vector3(easeMethod().x, trans.localScale.y, trans.localScale.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setScaleY()
|
||||
{
|
||||
this.type = TweenAction.SCALE_Y;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.localScale.y; };
|
||||
this.easeInternal = () => { trans.localScale = new Vector3(trans.localScale.x, easeMethod().x, trans.localScale.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setScaleZ()
|
||||
{
|
||||
this.type = TweenAction.SCALE_Z;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.localScale.z; };
|
||||
this.easeInternal = () => { trans.localScale = new Vector3(trans.localScale.x, trans.localScale.y, easeMethod().x); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRotateX()
|
||||
{
|
||||
this.type = TweenAction.ROTATE_X;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.eulerAngles.x; this.toInternal.x = LeanTween.closestRot(this.fromInternal.x, this.toInternal.x); };
|
||||
this.easeInternal = () => { trans.eulerAngles = new Vector3(easeMethod().x, trans.eulerAngles.y, trans.eulerAngles.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRotateY()
|
||||
{
|
||||
this.type = TweenAction.ROTATE_Y;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.eulerAngles.y; this.toInternal.x = LeanTween.closestRot(this.fromInternal.x, this.toInternal.x); };
|
||||
this.easeInternal = () => { trans.eulerAngles = new Vector3(trans.eulerAngles.x, easeMethod().x, trans.eulerAngles.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRotateZ()
|
||||
{
|
||||
this.type = TweenAction.ROTATE_Z;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.fromInternal.x = trans.eulerAngles.z;
|
||||
this.toInternal.x = LeanTween.closestRot(this.fromInternal.x, this.toInternal.x);
|
||||
};
|
||||
this.easeInternal = () => { trans.eulerAngles = new Vector3(trans.eulerAngles.x, trans.eulerAngles.y, easeMethod().x); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRotateAround()
|
||||
{
|
||||
this.type = TweenAction.ROTATE_AROUND;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.fromInternal.x = 0f;
|
||||
this._optional.origRotation = trans.rotation;
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
Vector3 origPos = trans.localPosition;
|
||||
Vector3 rotateAroundPt = (Vector3)trans.TransformPoint(this._optional.point);
|
||||
// Debug.Log("this._optional.point:"+this._optional.point);
|
||||
trans.RotateAround(rotateAroundPt, this._optional.axis, -this._optional.lastVal);
|
||||
Vector3 diff = origPos - trans.localPosition;
|
||||
|
||||
trans.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
|
||||
trans.rotation = this._optional.origRotation;
|
||||
|
||||
rotateAroundPt = (Vector3)trans.TransformPoint(this._optional.point);
|
||||
trans.RotateAround(rotateAroundPt, this._optional.axis, val);
|
||||
|
||||
this._optional.lastVal = val;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRotateAroundLocal()
|
||||
{
|
||||
this.type = TweenAction.ROTATE_AROUND_LOCAL;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.fromInternal.x = 0f;
|
||||
this._optional.origRotation = trans.localRotation;
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
Vector3 origPos = trans.localPosition;
|
||||
trans.RotateAround((Vector3)trans.TransformPoint(this._optional.point), trans.TransformDirection(this._optional.axis), -this._optional.lastVal);
|
||||
Vector3 diff = origPos - trans.localPosition;
|
||||
|
||||
trans.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
|
||||
trans.localRotation = this._optional.origRotation;
|
||||
Vector3 rotateAroundPt = (Vector3)trans.TransformPoint(this._optional.point);
|
||||
trans.RotateAround(rotateAroundPt, trans.TransformDirection(this._optional.axis), val);
|
||||
|
||||
this._optional.lastVal = val;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setAlpha()
|
||||
{
|
||||
this.type = TweenAction.ALPHA;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
|
||||
if(trans.gameObject.renderer){ this.fromInternal.x = trans.gameObject.renderer.material.color.a; }else if(trans.childCount>0){ foreach (Transform child in trans) { if(child.gameObject.renderer!=null){ Color col = child.gameObject.renderer.material.color; this.fromInternal.x = col.a; break; }}}
|
||||
this.easeInternal = this.alpha;
|
||||
break;
|
||||
#else
|
||||
SpriteRenderer ren = trans.GetComponent<SpriteRenderer>();
|
||||
if (ren != null)
|
||||
{
|
||||
this.fromInternal.x = ren.color.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (trans.GetComponent<Renderer>() != null && trans.GetComponent<Renderer>().material.HasProperty("_Color"))
|
||||
{
|
||||
this.fromInternal.x = trans.GetComponent<Renderer>().material.color.a;
|
||||
}
|
||||
else if (trans.GetComponent<Renderer>() != null && trans.GetComponent<Renderer>().material.HasProperty("_TintColor"))
|
||||
{
|
||||
Color col = trans.GetComponent<Renderer>().material.GetColor("_TintColor");
|
||||
this.fromInternal.x = col.a;
|
||||
}
|
||||
else if (trans.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in trans)
|
||||
{
|
||||
if (child.gameObject.GetComponent<Renderer>() != null)
|
||||
{
|
||||
Color col = child.gameObject.GetComponent<Renderer>().material.color;
|
||||
this.fromInternal.x = col.a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
val = easeMethod().x;
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
|
||||
alphaRecursive(this.trans, val, this.useRecursion);
|
||||
#else
|
||||
if (this.spriteRen != null)
|
||||
{
|
||||
this.spriteRen.color = new Color(this.spriteRen.color.r, this.spriteRen.color.g, this.spriteRen.color.b, val);
|
||||
alphaRecursiveSprite(this.trans, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
alphaRecursive(this.trans, val, this.useRecursion);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
|
||||
alphaRecursive(this.trans, val, this.useRecursion);
|
||||
#else
|
||||
if (this.spriteRen != null)
|
||||
{
|
||||
this.spriteRen.color = new Color(this.spriteRen.color.r, this.spriteRen.color.g, this.spriteRen.color.b, val);
|
||||
alphaRecursiveSprite(this.trans, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
alphaRecursive(this.trans, val, this.useRecursion);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setTextAlpha()
|
||||
{
|
||||
this.type = TweenAction.TEXT_ALPHA;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.uiText = trans.GetComponent<UnityEngine.UI.Text>();
|
||||
this.fromInternal.x = this.uiText != null ? this.uiText.color.a : 1f;
|
||||
};
|
||||
this.easeInternal = () => { textAlphaRecursive(trans, easeMethod().x, this.useRecursion); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setAlphaVertex()
|
||||
{
|
||||
this.type = TweenAction.ALPHA_VERTEX;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.GetComponent<MeshFilter>().mesh.colors32[0].a; };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
Mesh mesh = trans.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
Color32[] colors = new Color32[vertices.Length];
|
||||
if (colors.Length == 0)
|
||||
{ //MaxFW fix: add vertex colors if the mesh doesn't have any
|
||||
Color32 transparentWhiteColor32 = new Color32(0xff, 0xff, 0xff, 0x00);
|
||||
colors = new Color32[mesh.vertices.Length];
|
||||
for (int k = 0; k < colors.Length; k++)
|
||||
colors[k] = transparentWhiteColor32;
|
||||
mesh.colors32 = colors;
|
||||
}// fix end
|
||||
Color32 c = mesh.colors32[0];
|
||||
c = new Color(c.r, c.g, c.b, val);
|
||||
for (int k = 0; k < vertices.Length; k++)
|
||||
colors[k] = c;
|
||||
mesh.colors32 = colors;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setColor()
|
||||
{
|
||||
this.type = TweenAction.COLOR;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
|
||||
if(trans.gameObject.renderer){
|
||||
this.setFromColor( trans.gameObject.renderer.material.color );
|
||||
}else if(trans.childCount>0){
|
||||
foreach (Transform child in trans) {
|
||||
if(child.gameObject.renderer!=null){
|
||||
this.setFromColor( child.gameObject.renderer.material.color );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
SpriteRenderer renColor = trans.GetComponent<SpriteRenderer>();
|
||||
if (renColor != null)
|
||||
{
|
||||
this.setFromColor(renColor.color);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (trans.GetComponent<Renderer>() != null && trans.GetComponent<Renderer>().material.HasProperty("_Color"))
|
||||
{
|
||||
Color col = trans.GetComponent<Renderer>().material.color;
|
||||
this.setFromColor(col);
|
||||
}
|
||||
else if (trans.GetComponent<Renderer>() != null && trans.GetComponent<Renderer>().material.HasProperty("_TintColor"))
|
||||
{
|
||||
Color col = trans.GetComponent<Renderer>().material.GetColor("_TintColor");
|
||||
this.setFromColor(col);
|
||||
}
|
||||
else if (trans.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in trans)
|
||||
{
|
||||
if (child.gameObject.GetComponent<Renderer>() != null)
|
||||
{
|
||||
Color col = child.gameObject.GetComponent<Renderer>().material.color;
|
||||
this.setFromColor(col);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
Color toColor = tweenColor(this, val);
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
|
||||
if (this.spriteRen != null)
|
||||
{
|
||||
this.spriteRen.color = toColor;
|
||||
colorRecursiveSprite(trans, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
// Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
|
||||
if (this.type == TweenAction.COLOR)
|
||||
colorRecursive(trans, toColor, this.useRecursion);
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
}
|
||||
#endif
|
||||
if (dt != 0f && this._optional.onUpdateColor != null)
|
||||
{
|
||||
this._optional.onUpdateColor(toColor);
|
||||
}
|
||||
else if (dt != 0f && this._optional.onUpdateColorObject != null)
|
||||
{
|
||||
this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCallbackColor()
|
||||
{
|
||||
this.type = TweenAction.CALLBACK_COLOR;
|
||||
this.initInternal = () => { this.diff = new Vector3(1.0f, 0.0f, 0.0f); };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
Color toColor = tweenColor(this, val);
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
if (this.spriteRen != null)
|
||||
{
|
||||
this.spriteRen.color = toColor;
|
||||
colorRecursiveSprite(trans, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
// Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
|
||||
if (this.type == TweenAction.COLOR)
|
||||
colorRecursive(trans, toColor, this.useRecursion);
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
}
|
||||
#endif
|
||||
if (dt != 0f && this._optional.onUpdateColor != null)
|
||||
{
|
||||
this._optional.onUpdateColor(toColor);
|
||||
}
|
||||
else if (dt != 0f && this._optional.onUpdateColorObject != null)
|
||||
{
|
||||
this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
|
||||
public LTDescr setTextColor()
|
||||
{
|
||||
this.type = TweenAction.TEXT_COLOR;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.uiText = trans.GetComponent<UnityEngine.UI.Text>();
|
||||
this.setFromColor(this.uiText != null ? this.uiText.color : Color.white);
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
Color toColor = tweenColor(this, val);
|
||||
this.uiText.color = toColor;
|
||||
if (dt != 0f && this._optional.onUpdateColor != null)
|
||||
this._optional.onUpdateColor(toColor);
|
||||
|
||||
if (this.useRecursion && trans.childCount > 0)
|
||||
textColorRecursive(this.trans, toColor);
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasAlpha()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_ALPHA;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.uiImage = trans.GetComponent<UnityEngine.UI.Image>();
|
||||
if (this.uiImage != null)
|
||||
{
|
||||
this.fromInternal.x = this.uiImage.color.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.rawImage = trans.GetComponent<UnityEngine.UI.RawImage>();
|
||||
if (this.rawImage != null)
|
||||
{
|
||||
this.fromInternal.x = this.rawImage.color.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.fromInternal.x = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
if (this.uiImage != null)
|
||||
{
|
||||
Color c = this.uiImage.color; c.a = val; this.uiImage.color = c;
|
||||
}
|
||||
else if (this.rawImage != null)
|
||||
{
|
||||
Color c = this.rawImage.color; c.a = val; this.rawImage.color = c;
|
||||
}
|
||||
if (this.useRecursion)
|
||||
{
|
||||
alphaRecursive(this.rectTransform, val, 0);
|
||||
textAlphaChildrenRecursive(this.rectTransform, val);
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasGroupAlpha()
|
||||
{
|
||||
this.type = TweenAction.CANVASGROUP_ALPHA;
|
||||
this.initInternal = () => { this.fromInternal.x = trans.GetComponent<CanvasGroup>().alpha; };
|
||||
this.easeInternal = () => { this.trans.GetComponent<CanvasGroup>().alpha = easeMethod().x; };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasColor()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_COLOR;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.uiImage = trans.GetComponent<UnityEngine.UI.Image>();
|
||||
if (this.uiImage == null)
|
||||
{
|
||||
this.rawImage = trans.GetComponent<UnityEngine.UI.RawImage>();
|
||||
this.setFromColor(this.rawImage != null ? this.rawImage.color : Color.white);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setFromColor(this.uiImage.color);
|
||||
}
|
||||
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
Color toColor = tweenColor(this, val);
|
||||
if (this.uiImage != null)
|
||||
{
|
||||
this.uiImage.color = toColor;
|
||||
}
|
||||
else if (this.rawImage != null)
|
||||
{
|
||||
this.rawImage.color = toColor;
|
||||
}
|
||||
|
||||
if (dt != 0f && this._optional.onUpdateColor != null)
|
||||
this._optional.onUpdateColor(toColor);
|
||||
|
||||
if (this.useRecursion)
|
||||
colorRecursive(this.rectTransform, toColor);
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasMoveX()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_MOVE_X;
|
||||
this.initInternal = () => { this.fromInternal.x = this.rectTransform.anchoredPosition3D.x; };
|
||||
this.easeInternal = () => { Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(easeMethod().x, c.y, c.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasMoveY()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_MOVE_Y;
|
||||
this.initInternal = () => { this.fromInternal.x = this.rectTransform.anchoredPosition3D.y; };
|
||||
this.easeInternal = () => { Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(c.x, easeMethod().x, c.z); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasMoveZ()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_MOVE_Z;
|
||||
this.initInternal = () => { this.fromInternal.x = this.rectTransform.anchoredPosition3D.z; };
|
||||
this.easeInternal = () => { Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(c.x, c.y, easeMethod().x); };
|
||||
return this;
|
||||
}
|
||||
|
||||
private void initCanvasRotateAround()
|
||||
{
|
||||
this.lastVal = 0.0f;
|
||||
this.fromInternal.x = 0.0f;
|
||||
this._optional.origRotation = this.rectTransform.rotation;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasRotateAround()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_ROTATEAROUND;
|
||||
this.initInternal = this.initCanvasRotateAround;
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
RectTransform rect = this.rectTransform;
|
||||
Vector3 origPos = rect.localPosition;
|
||||
rect.RotateAround((Vector3)rect.TransformPoint(this._optional.point), this._optional.axis, -val);
|
||||
Vector3 diff = origPos - rect.localPosition;
|
||||
|
||||
rect.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
|
||||
rect.rotation = this._optional.origRotation;
|
||||
rect.RotateAround((Vector3)rect.TransformPoint(this._optional.point), this._optional.axis, val);
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasRotateAroundLocal()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_ROTATEAROUND_LOCAL;
|
||||
this.initInternal = this.initCanvasRotateAround;
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
RectTransform rect = this.rectTransform;
|
||||
Vector3 origPos = rect.localPosition;
|
||||
rect.RotateAround((Vector3)rect.TransformPoint(this._optional.point), rect.TransformDirection(this._optional.axis), -val);
|
||||
Vector3 diff = origPos - rect.localPosition;
|
||||
|
||||
rect.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
|
||||
rect.rotation = this._optional.origRotation;
|
||||
rect.RotateAround((Vector3)rect.TransformPoint(this._optional.point), rect.TransformDirection(this._optional.axis), val);
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasPlaySprite()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_PLAYSPRITE;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
this.uiImage = trans.GetComponent<UnityEngine.UI.Image>();
|
||||
this.fromInternal.x = 0f;
|
||||
};
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
val = newVect.x;
|
||||
int frame = (int)Mathf.Round(val);
|
||||
this.uiImage.sprite = this.sprites[frame];
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasMove()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_MOVE;
|
||||
this.initInternal = () => { this.fromInternal = this.rectTransform.anchoredPosition3D; };
|
||||
this.easeInternal = () => { this.rectTransform.anchoredPosition3D = easeMethod(); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasScale()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_SCALE;
|
||||
this.initInternal = () => { this.from = this.rectTransform.localScale; };
|
||||
this.easeInternal = () => { this.rectTransform.localScale = easeMethod(); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setCanvasSizeDelta()
|
||||
{
|
||||
this.type = TweenAction.CANVAS_SIZEDELTA;
|
||||
this.initInternal = () => { this.from = this.rectTransform.sizeDelta; };
|
||||
this.easeInternal = () => { this.rectTransform.sizeDelta = easeMethod(); };
|
||||
return this;
|
||||
}
|
||||
#endif
|
||||
|
||||
private void callback() { newVect = easeMethod(); val = newVect.x; }
|
||||
|
||||
public LTDescr setCallback()
|
||||
{
|
||||
this.type = TweenAction.CALLBACK;
|
||||
this.initInternal = () => { };
|
||||
this.easeInternal = this.callback;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setValue3()
|
||||
{
|
||||
this.type = TweenAction.VALUE3;
|
||||
this.initInternal = () => { };
|
||||
this.easeInternal = this.callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMove()
|
||||
{
|
||||
this.type = TweenAction.MOVE;
|
||||
this.initInternal = () => { this.from = trans.position; };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
trans.position = newVect;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveLocal()
|
||||
{
|
||||
this.type = TweenAction.MOVE_LOCAL;
|
||||
this.initInternal = () => { this.from = trans.localPosition; };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
trans.localPosition = newVect;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setMoveToTransform()
|
||||
{
|
||||
this.type = TweenAction.MOVE_TO_TRANSFORM;
|
||||
this.initInternal = () => { this.from = trans.position; };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
this.to = this._optional.toTrans.position;
|
||||
this.diff = this.to - this.from;
|
||||
this.diffDiv2 = this.diff * 0.5f;
|
||||
|
||||
newVect = easeMethod();
|
||||
this.trans.position = newVect;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRotate()
|
||||
{
|
||||
this.type = TweenAction.ROTATE;
|
||||
this.initInternal = () => { this.from = trans.eulerAngles; this.to = new Vector3(LeanTween.closestRot(this.fromInternal.x, this.toInternal.x), LeanTween.closestRot(this.from.y, this.to.y), LeanTween.closestRot(this.from.z, this.to.z)); };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
trans.eulerAngles = newVect;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRotateLocal()
|
||||
{
|
||||
this.type = TweenAction.ROTATE_LOCAL;
|
||||
this.initInternal = () => { this.from = trans.localEulerAngles; this.to = new Vector3(LeanTween.closestRot(this.fromInternal.x, this.toInternal.x), LeanTween.closestRot(this.from.y, this.to.y), LeanTween.closestRot(this.from.z, this.to.z)); };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
trans.localEulerAngles = newVect;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setScale()
|
||||
{
|
||||
this.type = TweenAction.SCALE;
|
||||
this.initInternal = () => { this.from = trans.localScale; };
|
||||
this.easeInternal = () =>
|
||||
{
|
||||
newVect = easeMethod();
|
||||
trans.localScale = newVect;
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setGUIMove()
|
||||
{
|
||||
this.type = TweenAction.GUI_MOVE;
|
||||
this.initInternal = () => { this.from = new Vector3(this._optional.ltRect.rect.x, this._optional.ltRect.rect.y, 0); };
|
||||
this.easeInternal = () => { Vector3 v = easeMethod(); this._optional.ltRect.rect = new Rect(v.x, v.y, this._optional.ltRect.rect.width, this._optional.ltRect.rect.height); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setGUIMoveMargin()
|
||||
{
|
||||
this.type = TweenAction.GUI_MOVE_MARGIN;
|
||||
this.initInternal = () => { this.from = new Vector2(this._optional.ltRect.margin.x, this._optional.ltRect.margin.y); };
|
||||
this.easeInternal = () => { Vector3 v = easeMethod(); this._optional.ltRect.margin = new Vector2(v.x, v.y); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setGUIScale()
|
||||
{
|
||||
this.type = TweenAction.GUI_SCALE;
|
||||
this.initInternal = () => { this.from = new Vector3(this._optional.ltRect.rect.width, this._optional.ltRect.rect.height, 0); };
|
||||
this.easeInternal = () => { Vector3 v = easeMethod(); this._optional.ltRect.rect = new Rect(this._optional.ltRect.rect.x, this._optional.ltRect.rect.y, v.x, v.y); };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setGUIAlpha()
|
||||
{
|
||||
this.type = TweenAction.GUI_ALPHA;
|
||||
this.initInternal = () => { this.fromInternal.x = this._optional.ltRect.alpha; };
|
||||
this.easeInternal = () => { this._optional.ltRect.alpha = easeMethod().x; };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setGUIRotate()
|
||||
{
|
||||
this.type = TweenAction.GUI_ROTATE;
|
||||
this.initInternal = () =>
|
||||
{
|
||||
if (this._optional.ltRect.rotateEnabled == false)
|
||||
{
|
||||
this._optional.ltRect.rotateEnabled = true;
|
||||
this._optional.ltRect.resetForRotation();
|
||||
}
|
||||
|
||||
this.fromInternal.x = this._optional.ltRect.rotation;
|
||||
};
|
||||
this.easeInternal = () => { this._optional.ltRect.rotation = easeMethod().x; };
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setDelayedSound()
|
||||
{
|
||||
this.type = TweenAction.DELAYED_SOUND;
|
||||
this.initInternal = () => { this.hasExtraOnCompletes = true; };
|
||||
this.easeInternal = this.callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setTarget(Transform trans)
|
||||
{
|
||||
this.optional.toTrans = trans;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
this.hasInitiliazed = true;
|
||||
|
||||
usesNormalDt = !(useEstimatedTime || useManualTime || useFrames); // only set this to true if it uses non of the other timing modes
|
||||
|
||||
if (useFrames)
|
||||
this.optional.initFrameCount = Time.frameCount;
|
||||
|
||||
if (this.time <= 0f) // avoid dividing by zero
|
||||
this.time = Mathf.Epsilon;
|
||||
|
||||
if (this.initInternal != null)
|
||||
this.initInternal();
|
||||
|
||||
this.diff = this.to - this.from;
|
||||
this.diffDiv2 = this.diff * 0.5f;
|
||||
|
||||
if (this._optional.onStart != null)
|
||||
this._optional.onStart();
|
||||
|
||||
if (this.onCompleteOnStart)
|
||||
callOnCompletes();
|
||||
|
||||
if (this.speed >= 0)
|
||||
{
|
||||
initSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
private void initSpeed()
|
||||
{
|
||||
if (this.type == TweenAction.MOVE_CURVED || this.type == TweenAction.MOVE_CURVED_LOCAL)
|
||||
{
|
||||
this.time = this._optional.path.distance / this.speed;
|
||||
}
|
||||
else if (this.type == TweenAction.MOVE_SPLINE || this.type == TweenAction.MOVE_SPLINE_LOCAL)
|
||||
{
|
||||
this.time = this._optional.spline.distance / this.speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.time = (this.to - this.from).magnitude / this.speed;
|
||||
}
|
||||
}
|
||||
|
||||
public static float val;
|
||||
public static float dt;
|
||||
public static Vector3 newVect;
|
||||
|
||||
/**
|
||||
* If you need a tween to happen immediately instead of waiting for the next Update call, you can force it with this method
|
||||
*
|
||||
* @method updateNow
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 0f ).updateNow();
|
||||
*/
|
||||
public LTDescr updateNow()
|
||||
{
|
||||
updateInternal();
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool updateInternal()
|
||||
{
|
||||
|
||||
float directionLocal = this.direction;
|
||||
if (this.usesNormalDt)
|
||||
{
|
||||
dt = LeanTween.dtActual;
|
||||
}
|
||||
else if (this.useEstimatedTime)
|
||||
{
|
||||
dt = LeanTween.dtEstimated;
|
||||
}
|
||||
else if (this.useFrames)
|
||||
{
|
||||
dt = this.optional.initFrameCount == 0 ? 0 : 1;
|
||||
this.optional.initFrameCount = Time.frameCount;
|
||||
}
|
||||
else if (this.useManualTime)
|
||||
{
|
||||
dt = LeanTween.dtManual;
|
||||
}
|
||||
|
||||
// Debug.Log ("tween:" + this+ " dt:"+dt);
|
||||
if (this.delay <= 0f && directionLocal != 0f)
|
||||
{
|
||||
if (trans == null)
|
||||
return true;
|
||||
|
||||
// initialize if has not done so yet
|
||||
if (!this.hasInitiliazed)
|
||||
this.init();
|
||||
|
||||
dt = dt * directionLocal;
|
||||
this.passed += dt;
|
||||
|
||||
this.passed = Mathf.Clamp(this.passed, 0f, this.time);
|
||||
|
||||
this.ratioPassed = (this.passed / this.time); // need to clamp when finished so it will finish at the exact spot and not overshoot
|
||||
|
||||
this.easeInternal();
|
||||
|
||||
if (this.hasUpdateCallback)
|
||||
this._optional.callOnUpdate(val, this.ratioPassed);
|
||||
|
||||
bool isTweenFinished = directionLocal > 0f ? this.passed >= this.time : this.passed <= 0f;
|
||||
// Debug.Log("lt "+this+" dt:"+dt+" fin:"+isTweenFinished);
|
||||
if (isTweenFinished)
|
||||
{ // increment or flip tween
|
||||
this.loopCount--;
|
||||
if (this.loopType == LeanTweenType.pingPong)
|
||||
{
|
||||
this.direction = 0.0f - directionLocal;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.passed = Mathf.Epsilon;
|
||||
}
|
||||
|
||||
isTweenFinished = this.loopCount == 0 || this.loopType == LeanTweenType.once; // only return true if it is fully complete
|
||||
|
||||
if (isTweenFinished == false && this.onCompleteOnRepeat && this.hasExtraOnCompletes)
|
||||
callOnCompletes(); // this only gets called if onCompleteOnRepeat is set to true, otherwise LeanTween class takes care of calling it
|
||||
|
||||
return isTweenFinished;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.delay -= dt;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void callOnCompletes()
|
||||
{
|
||||
if (this.type == TweenAction.GUI_ROTATE)
|
||||
this._optional.ltRect.rotateFinished = true;
|
||||
|
||||
if (this.type == TweenAction.DELAYED_SOUND)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint((AudioClip)this._optional.onCompleteParam, this.to, this.from.x);
|
||||
}
|
||||
if (this._optional.onComplete != null)
|
||||
{
|
||||
this._optional.onComplete();
|
||||
}
|
||||
else if (this._optional.onCompleteObject != null)
|
||||
{
|
||||
this._optional.onCompleteObject(this._optional.onCompleteParam);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper Methods
|
||||
|
||||
public LTDescr setFromColor(Color col)
|
||||
{
|
||||
this.from = new Vector3(0.0f, col.a, 0.0f);
|
||||
this.diff = new Vector3(1.0f, 0.0f, 0.0f);
|
||||
this._optional.axis = new Vector3(col.r, col.g, col.b);
|
||||
return this;
|
||||
}
|
||||
|
||||
private static void alphaRecursive(Transform transform, float val, bool useRecursion = true)
|
||||
{
|
||||
Renderer renderer = transform.gameObject.GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
foreach (Material mat in renderer.materials)
|
||||
{
|
||||
if (mat.HasProperty("_Color"))
|
||||
{
|
||||
mat.color = new Color(mat.color.r, mat.color.g, mat.color.b, val);
|
||||
}
|
||||
else if (mat.HasProperty("_TintColor"))
|
||||
{
|
||||
Color col = mat.GetColor("_TintColor");
|
||||
mat.SetColor("_TintColor", new Color(col.r, col.g, col.b, val));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (useRecursion && transform.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
alphaRecursive(child, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void colorRecursive(Transform transform, Color toColor, bool useRecursion = true)
|
||||
{
|
||||
Renderer ren = transform.gameObject.GetComponent<Renderer>();
|
||||
if (ren != null)
|
||||
{
|
||||
foreach (Material mat in ren.materials)
|
||||
{
|
||||
mat.color = toColor;
|
||||
}
|
||||
}
|
||||
if (useRecursion && transform.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
colorRecursive(child, toColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
|
||||
private static void alphaRecursive(RectTransform rectTransform, float val, int recursiveLevel = 0)
|
||||
{
|
||||
if (rectTransform.childCount > 0)
|
||||
{
|
||||
foreach (RectTransform child in rectTransform)
|
||||
{
|
||||
UnityEngine.UI.MaskableGraphic uiImage = child.GetComponent<UnityEngine.UI.Image>();
|
||||
if (uiImage != null)
|
||||
{
|
||||
Color c = uiImage.color; c.a = val; uiImage.color = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
uiImage = child.GetComponent<UnityEngine.UI.RawImage>();
|
||||
if (uiImage != null)
|
||||
{
|
||||
Color c = uiImage.color; c.a = val; uiImage.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
alphaRecursive(child, val, recursiveLevel + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void alphaRecursiveSprite(Transform transform, float val)
|
||||
{
|
||||
if (transform.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
SpriteRenderer ren = child.GetComponent<SpriteRenderer>();
|
||||
if (ren != null)
|
||||
ren.color = new Color(ren.color.r, ren.color.g, ren.color.b, val);
|
||||
alphaRecursiveSprite(child, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void colorRecursiveSprite(Transform transform, Color toColor)
|
||||
{
|
||||
if (transform.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
SpriteRenderer ren = transform.gameObject.GetComponent<SpriteRenderer>();
|
||||
if (ren != null)
|
||||
ren.color = toColor;
|
||||
colorRecursiveSprite(child, toColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void colorRecursive(RectTransform rectTransform, Color toColor)
|
||||
{
|
||||
|
||||
if (rectTransform.childCount > 0)
|
||||
{
|
||||
foreach (RectTransform child in rectTransform)
|
||||
{
|
||||
UnityEngine.UI.MaskableGraphic uiImage = child.GetComponent<UnityEngine.UI.Image>();
|
||||
if (uiImage != null)
|
||||
{
|
||||
uiImage.color = toColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
uiImage = child.GetComponent<UnityEngine.UI.RawImage>();
|
||||
if (uiImage != null)
|
||||
uiImage.color = toColor;
|
||||
}
|
||||
colorRecursive(child, toColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void textAlphaChildrenRecursive(Transform trans, float val, bool useRecursion = true)
|
||||
{
|
||||
|
||||
if (useRecursion && trans.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in trans)
|
||||
{
|
||||
UnityEngine.UI.Text uiText = child.GetComponent<UnityEngine.UI.Text>();
|
||||
if (uiText != null)
|
||||
{
|
||||
Color c = uiText.color;
|
||||
c.a = val;
|
||||
uiText.color = c;
|
||||
}
|
||||
textAlphaChildrenRecursive(child, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void textAlphaRecursive(Transform trans, float val, bool useRecursion = true)
|
||||
{
|
||||
UnityEngine.UI.Text uiText = trans.GetComponent<UnityEngine.UI.Text>();
|
||||
if (uiText != null)
|
||||
{
|
||||
Color c = uiText.color;
|
||||
c.a = val;
|
||||
uiText.color = c;
|
||||
}
|
||||
if (useRecursion && trans.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in trans)
|
||||
{
|
||||
textAlphaRecursive(child, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void textColorRecursive(Transform trans, Color toColor)
|
||||
{
|
||||
if (trans.childCount > 0)
|
||||
{
|
||||
foreach (Transform child in trans)
|
||||
{
|
||||
UnityEngine.UI.Text uiText = child.GetComponent<UnityEngine.UI.Text>();
|
||||
if (uiText != null)
|
||||
{
|
||||
uiText.color = toColor;
|
||||
}
|
||||
textColorRecursive(child, toColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private static Color tweenColor(LTDescr tween, float val)
|
||||
{
|
||||
Vector3 diff3 = tween._optional.point - tween._optional.axis;
|
||||
float diffAlpha = tween.to.y - tween.from.y;
|
||||
return new Color(tween._optional.axis.x + diff3.x * val, tween._optional.axis.y + diff3.y * val, tween._optional.axis.z + diff3.z * val, tween.from.y + diffAlpha * val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause a tween
|
||||
*
|
||||
* @method pause
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public LTDescr pause()
|
||||
{
|
||||
if (this.direction != 0.0f)
|
||||
{ // check if tween is already paused
|
||||
this.directionLast = this.direction;
|
||||
this.direction = 0.0f;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume a paused tween
|
||||
*
|
||||
* @method resume
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public LTDescr resume()
|
||||
{
|
||||
this.direction = this.directionLast;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Axis optional axis for tweens where it is relevant
|
||||
*
|
||||
* @method setAxis
|
||||
* @param {Vector3} axis either the tween rotates around, or the direction it faces in the case of setOrientToPath
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);
|
||||
*/
|
||||
public LTDescr setAxis(Vector3 axis)
|
||||
{
|
||||
this._optional.axis = axis;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay the start of a tween
|
||||
*
|
||||
* @method setDelay
|
||||
* @param {float} float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setDelay( 1.5f );
|
||||
*/
|
||||
public LTDescr setDelay(float delay)
|
||||
{
|
||||
this.delay = delay;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of easing used for the tween. <br>
|
||||
* <ul><li><a href="LeanTweenType.html">List of all the ease types</a>.</li>
|
||||
* <li><a href="http://www.robertpenner.com/easing/easing_demo.html">This page helps visualize the different easing equations</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* @method setEase
|
||||
* @param {LeanTweenType} easeType:LeanTweenType the easing type to use
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce );
|
||||
*/
|
||||
public LTDescr setEase(LeanTweenType easeType)
|
||||
{
|
||||
|
||||
switch (easeType)
|
||||
{
|
||||
case LeanTweenType.linear:
|
||||
setEaseLinear(); break;
|
||||
case LeanTweenType.easeOutQuad:
|
||||
setEaseOutQuad(); break;
|
||||
case LeanTweenType.easeInQuad:
|
||||
setEaseInQuad(); break;
|
||||
case LeanTweenType.easeInOutQuad:
|
||||
setEaseInOutQuad(); break;
|
||||
case LeanTweenType.easeInCubic:
|
||||
setEaseInCubic(); break;
|
||||
case LeanTweenType.easeOutCubic:
|
||||
setEaseOutCubic(); break;
|
||||
case LeanTweenType.easeInOutCubic:
|
||||
setEaseInOutCubic(); break;
|
||||
case LeanTweenType.easeInQuart:
|
||||
setEaseInQuart(); break;
|
||||
case LeanTweenType.easeOutQuart:
|
||||
setEaseOutQuart(); break;
|
||||
case LeanTweenType.easeInOutQuart:
|
||||
setEaseInOutQuart(); break;
|
||||
case LeanTweenType.easeInQuint:
|
||||
setEaseInQuint(); break;
|
||||
case LeanTweenType.easeOutQuint:
|
||||
setEaseOutQuint(); break;
|
||||
case LeanTweenType.easeInOutQuint:
|
||||
setEaseInOutQuint(); break;
|
||||
case LeanTweenType.easeInSine:
|
||||
setEaseInSine(); break;
|
||||
case LeanTweenType.easeOutSine:
|
||||
setEaseOutSine(); break;
|
||||
case LeanTweenType.easeInOutSine:
|
||||
setEaseInOutSine(); break;
|
||||
case LeanTweenType.easeInExpo:
|
||||
setEaseInExpo(); break;
|
||||
case LeanTweenType.easeOutExpo:
|
||||
setEaseOutExpo(); break;
|
||||
case LeanTweenType.easeInOutExpo:
|
||||
setEaseInOutExpo(); break;
|
||||
case LeanTweenType.easeInCirc:
|
||||
setEaseInCirc(); break;
|
||||
case LeanTweenType.easeOutCirc:
|
||||
setEaseOutCirc(); break;
|
||||
case LeanTweenType.easeInOutCirc:
|
||||
setEaseInOutCirc(); break;
|
||||
case LeanTweenType.easeInBounce:
|
||||
setEaseInBounce(); break;
|
||||
case LeanTweenType.easeOutBounce:
|
||||
setEaseOutBounce(); break;
|
||||
case LeanTweenType.easeInOutBounce:
|
||||
setEaseInOutBounce(); break;
|
||||
case LeanTweenType.easeInBack:
|
||||
setEaseInBack(); break;
|
||||
case LeanTweenType.easeOutBack:
|
||||
setEaseOutBack(); break;
|
||||
case LeanTweenType.easeInOutBack:
|
||||
setEaseInOutBack(); break;
|
||||
case LeanTweenType.easeInElastic:
|
||||
setEaseInElastic(); break;
|
||||
case LeanTweenType.easeOutElastic:
|
||||
setEaseOutElastic(); break;
|
||||
case LeanTweenType.easeInOutElastic:
|
||||
setEaseInOutElastic(); break;
|
||||
case LeanTweenType.punch:
|
||||
setEasePunch(); break;
|
||||
case LeanTweenType.easeShake:
|
||||
setEaseShake(); break;
|
||||
case LeanTweenType.easeSpring:
|
||||
setEaseSpring(); break;
|
||||
default:
|
||||
setEaseLinear(); break;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setEaseLinear() { this.easeType = LeanTweenType.linear; this.easeMethod = this.easeLinear; return this; }
|
||||
|
||||
public LTDescr setEaseSpring() { this.easeType = LeanTweenType.easeSpring; this.easeMethod = this.easeSpring; return this; }
|
||||
|
||||
public LTDescr setEaseInQuad() { this.easeType = LeanTweenType.easeInQuad; this.easeMethod = this.easeInQuad; return this; }
|
||||
|
||||
public LTDescr setEaseOutQuad() { this.easeType = LeanTweenType.easeOutQuad; this.easeMethod = this.easeOutQuad; return this; }
|
||||
|
||||
public LTDescr setEaseInOutQuad() { this.easeType = LeanTweenType.easeInOutQuad; this.easeMethod = this.easeInOutQuad; return this; }
|
||||
|
||||
public LTDescr setEaseInCubic() { this.easeType = LeanTweenType.easeInCubic; this.easeMethod = this.easeInCubic; return this; }
|
||||
|
||||
public LTDescr setEaseOutCubic() { this.easeType = LeanTweenType.easeOutCubic; this.easeMethod = this.easeOutCubic; return this; }
|
||||
|
||||
public LTDescr setEaseInOutCubic() { this.easeType = LeanTweenType.easeInOutCubic; this.easeMethod = this.easeInOutCubic; return this; }
|
||||
|
||||
public LTDescr setEaseInQuart() { this.easeType = LeanTweenType.easeInQuart; this.easeMethod = this.easeInQuart; return this; }
|
||||
|
||||
public LTDescr setEaseOutQuart() { this.easeType = LeanTweenType.easeOutQuart; this.easeMethod = this.easeOutQuart; return this; }
|
||||
|
||||
public LTDescr setEaseInOutQuart() { this.easeType = LeanTweenType.easeInOutQuart; this.easeMethod = this.easeInOutQuart; return this; }
|
||||
|
||||
public LTDescr setEaseInQuint() { this.easeType = LeanTweenType.easeInQuint; this.easeMethod = this.easeInQuint; return this; }
|
||||
|
||||
public LTDescr setEaseOutQuint() { this.easeType = LeanTweenType.easeOutQuint; this.easeMethod = this.easeOutQuint; return this; }
|
||||
|
||||
public LTDescr setEaseInOutQuint() { this.easeType = LeanTweenType.easeInOutQuint; this.easeMethod = this.easeInOutQuint; return this; }
|
||||
|
||||
public LTDescr setEaseInSine() { this.easeType = LeanTweenType.easeInSine; this.easeMethod = this.easeInSine; return this; }
|
||||
|
||||
public LTDescr setEaseOutSine() { this.easeType = LeanTweenType.easeOutSine; this.easeMethod = this.easeOutSine; return this; }
|
||||
|
||||
public LTDescr setEaseInOutSine() { this.easeType = LeanTweenType.easeInOutSine; this.easeMethod = this.easeInOutSine; return this; }
|
||||
|
||||
public LTDescr setEaseInExpo() { this.easeType = LeanTweenType.easeInExpo; this.easeMethod = this.easeInExpo; return this; }
|
||||
|
||||
public LTDescr setEaseOutExpo() { this.easeType = LeanTweenType.easeOutExpo; this.easeMethod = this.easeOutExpo; return this; }
|
||||
|
||||
public LTDescr setEaseInOutExpo() { this.easeType = LeanTweenType.easeInOutExpo; this.easeMethod = this.easeInOutExpo; return this; }
|
||||
|
||||
public LTDescr setEaseInCirc() { this.easeType = LeanTweenType.easeInCirc; this.easeMethod = this.easeInCirc; return this; }
|
||||
|
||||
public LTDescr setEaseOutCirc() { this.easeType = LeanTweenType.easeOutCirc; this.easeMethod = this.easeOutCirc; return this; }
|
||||
|
||||
public LTDescr setEaseInOutCirc() { this.easeType = LeanTweenType.easeInOutCirc; this.easeMethod = this.easeInOutCirc; return this; }
|
||||
|
||||
public LTDescr setEaseInBounce() { this.easeType = LeanTweenType.easeInBounce; this.easeMethod = this.easeInBounce; return this; }
|
||||
|
||||
public LTDescr setEaseOutBounce() { this.easeType = LeanTweenType.easeOutBounce; this.easeMethod = this.easeOutBounce; return this; }
|
||||
|
||||
public LTDescr setEaseInOutBounce() { this.easeType = LeanTweenType.easeInOutBounce; this.easeMethod = this.easeInOutBounce; return this; }
|
||||
|
||||
public LTDescr setEaseInBack() { this.easeType = LeanTweenType.easeInBack; this.easeMethod = this.easeInBack; return this; }
|
||||
|
||||
public LTDescr setEaseOutBack() { this.easeType = LeanTweenType.easeOutBack; this.easeMethod = this.easeOutBack; return this; }
|
||||
|
||||
public LTDescr setEaseInOutBack() { this.easeType = LeanTweenType.easeInOutBack; this.easeMethod = this.easeInOutBack; return this; }
|
||||
|
||||
public LTDescr setEaseInElastic() { this.easeType = LeanTweenType.easeInElastic; this.easeMethod = this.easeInElastic; return this; }
|
||||
|
||||
public LTDescr setEaseOutElastic() { this.easeType = LeanTweenType.easeOutElastic; this.easeMethod = this.easeOutElastic; return this; }
|
||||
|
||||
public LTDescr setEaseInOutElastic() { this.easeType = LeanTweenType.easeInOutElastic; this.easeMethod = this.easeInOutElastic; return this; }
|
||||
|
||||
public LTDescr setEasePunch() { this._optional.animationCurve = LeanTween.punch; this.toInternal.x = this.from.x + this.to.x; this.easeMethod = this.tweenOnCurve; return this; }
|
||||
|
||||
public LTDescr setEaseShake() { this._optional.animationCurve = LeanTween.shake; this.toInternal.x = this.from.x + this.to.x; this.easeMethod = this.tweenOnCurve; return this; }
|
||||
|
||||
private Vector3 tweenOnCurve()
|
||||
{
|
||||
return new Vector3(this.from.x + (this.diff.x) * this._optional.animationCurve.Evaluate(ratioPassed),
|
||||
this.from.y + (this.diff.y) * this._optional.animationCurve.Evaluate(ratioPassed),
|
||||
this.from.z + (this.diff.z) * this._optional.animationCurve.Evaluate(ratioPassed));
|
||||
}
|
||||
|
||||
// Vector3 Ease Methods
|
||||
|
||||
private Vector3 easeInOutQuad()
|
||||
{
|
||||
val = this.ratioPassed * 2f;
|
||||
|
||||
if (val < 1f)
|
||||
{
|
||||
val = val * val;
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
val = (1f - val) * (val - 3f) + 1f;
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInQuad()
|
||||
{
|
||||
val = ratioPassed * ratioPassed;
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeOutQuad()
|
||||
{
|
||||
val = this.ratioPassed;
|
||||
val = -val * (val - 2f);
|
||||
return (this.diff * val + this.from);
|
||||
}
|
||||
|
||||
private Vector3 easeLinear()
|
||||
{
|
||||
val = this.ratioPassed;
|
||||
return new Vector3(this.from.x + this.diff.x * val, this.from.y + this.diff.y * val, this.from.z + this.diff.z * val);
|
||||
}
|
||||
|
||||
private Vector3 easeSpring()
|
||||
{
|
||||
val = Mathf.Clamp01(this.ratioPassed);
|
||||
val = (Mathf.Sin(val * Mathf.PI * (0.2f + 2.5f * val * val * val)) * Mathf.Pow(1f - val, 2.2f) + val) * (1f + (1.2f * (1f - val)));
|
||||
return this.from + this.diff * val;
|
||||
}
|
||||
|
||||
private Vector3 easeInCubic()
|
||||
{
|
||||
val = this.ratioPassed * this.ratioPassed * this.ratioPassed;
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeOutCubic()
|
||||
{
|
||||
val = this.ratioPassed - 1f;
|
||||
val = (val * val * val + 1);
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInOutCubic()
|
||||
{
|
||||
val = this.ratioPassed * 2f;
|
||||
if (val < 1f)
|
||||
{
|
||||
val = val * val * val;
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
val -= 2f;
|
||||
val = val * val * val + 2f;
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInQuart()
|
||||
{
|
||||
val = this.ratioPassed * this.ratioPassed * this.ratioPassed * this.ratioPassed;
|
||||
return diff * val + this.from;
|
||||
}
|
||||
|
||||
private Vector3 easeOutQuart()
|
||||
{
|
||||
val = this.ratioPassed - 1f;
|
||||
val = -(val * val * val * val - 1);
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInOutQuart()
|
||||
{
|
||||
val = this.ratioPassed * 2f;
|
||||
if (val < 1f)
|
||||
{
|
||||
val = val * val * val * val;
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
val -= 2f;
|
||||
// val = (val * val * val * val - 2f);
|
||||
return -this.diffDiv2 * (val * val * val * val - 2f) + this.from;
|
||||
}
|
||||
|
||||
private Vector3 easeInQuint()
|
||||
{
|
||||
val = this.ratioPassed;
|
||||
val = val * val * val * val * val;
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeOutQuint()
|
||||
{
|
||||
val = this.ratioPassed - 1f;
|
||||
val = (val * val * val * val * val + 1f);
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInOutQuint()
|
||||
{
|
||||
val = this.ratioPassed * 2f;
|
||||
if (val < 1f)
|
||||
{
|
||||
val = val * val * val * val * val;
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
val -= 2f;
|
||||
val = (val * val * val * val * val + 2f);
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInSine()
|
||||
{
|
||||
val = -Mathf.Cos(this.ratioPassed * LeanTween.PI_DIV2);
|
||||
return new Vector3(this.diff.x * val + this.diff.x + this.from.x, this.diff.y * val + this.diff.y + this.from.y, this.diff.z * val + this.diff.z + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeOutSine()
|
||||
{
|
||||
val = Mathf.Sin(this.ratioPassed * LeanTween.PI_DIV2);
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInOutSine()
|
||||
{
|
||||
val = -(Mathf.Cos(Mathf.PI * this.ratioPassed) - 1f);
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInExpo()
|
||||
{
|
||||
val = Mathf.Pow(2f, 10f * (this.ratioPassed - 1f));
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeOutExpo()
|
||||
{
|
||||
val = (-Mathf.Pow(2f, -10f * this.ratioPassed) + 1f);
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInOutExpo()
|
||||
{
|
||||
val = this.ratioPassed * 2f;
|
||||
if (val < 1) return this.diffDiv2 * Mathf.Pow(2, 10 * (val - 1)) + this.from;
|
||||
val--;
|
||||
return this.diffDiv2 * (-Mathf.Pow(2, -10 * val) + 2) + this.from;
|
||||
}
|
||||
|
||||
private Vector3 easeInCirc()
|
||||
{
|
||||
val = -(Mathf.Sqrt(1f - this.ratioPassed * this.ratioPassed) - 1f);
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeOutCirc()
|
||||
{
|
||||
val = this.ratioPassed - 1f;
|
||||
val = Mathf.Sqrt(1f - val * val);
|
||||
|
||||
return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInOutCirc()
|
||||
{
|
||||
val = this.ratioPassed * 2f;
|
||||
if (val < 1f)
|
||||
{
|
||||
val = -(Mathf.Sqrt(1f - val * val) - 1f);
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
val -= 2f;
|
||||
val = (Mathf.Sqrt(1f - val * val) + 1f);
|
||||
return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeInBounce()
|
||||
{
|
||||
val = this.ratioPassed;
|
||||
val = 1f - val;
|
||||
return new Vector3(this.diff.x - LeanTween.easeOutBounce(0, this.diff.x, val) + this.from.x,
|
||||
this.diff.y - LeanTween.easeOutBounce(0, this.diff.y, val) + this.from.y,
|
||||
this.diff.z - LeanTween.easeOutBounce(0, this.diff.z, val) + this.from.z);
|
||||
}
|
||||
|
||||
private Vector3 easeOutBounce()
|
||||
{
|
||||
val = ratioPassed;
|
||||
float valM, valN; // bounce values
|
||||
if (val < (valM = 1 - 1.75f * this.overshoot / 2.75f))
|
||||
{
|
||||
val = 1 / valM / valM * val * val;
|
||||
}
|
||||
else if (val < (valN = 1 - .75f * this.overshoot / 2.75f))
|
||||
{
|
||||
val -= (valM + valN) / 2;
|
||||
// first bounce, height: 1/4
|
||||
val = 7.5625f * val * val + 1 - .25f * this.overshoot * this.overshoot;
|
||||
}
|
||||
else if (val < (valM = 1 - .25f * this.overshoot / 2.75f))
|
||||
{
|
||||
val -= (valM + valN) / 2;
|
||||
// second bounce, height: 1/16
|
||||
val = 7.5625f * val * val + 1 - .0625f * this.overshoot * this.overshoot;
|
||||
}
|
||||
else
|
||||
{ // valN = 1
|
||||
val -= (valM + 1) / 2;
|
||||
// third bounce, height: 1/64
|
||||
val = 7.5625f * val * val + 1 - .015625f * this.overshoot * this.overshoot;
|
||||
}
|
||||
return this.diff * val + this.from;
|
||||
}
|
||||
|
||||
private Vector3 easeInOutBounce()
|
||||
{
|
||||
val = this.ratioPassed * 2f;
|
||||
if (val < 1f)
|
||||
{
|
||||
return new Vector3(LeanTween.easeInBounce(0, this.diff.x, val) * 0.5f + this.from.x,
|
||||
LeanTween.easeInBounce(0, this.diff.y, val) * 0.5f + this.from.y,
|
||||
LeanTween.easeInBounce(0, this.diff.z, val) * 0.5f + this.from.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = val - 1f;
|
||||
return new Vector3(LeanTween.easeOutBounce(0, this.diff.x, val) * 0.5f + this.diffDiv2.x + this.from.x,
|
||||
LeanTween.easeOutBounce(0, this.diff.y, val) * 0.5f + this.diffDiv2.y + this.from.y,
|
||||
LeanTween.easeOutBounce(0, this.diff.z, val) * 0.5f + this.diffDiv2.z + this.from.z);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 easeInBack()
|
||||
{
|
||||
val = this.ratioPassed;
|
||||
val /= 1;
|
||||
float s = 1.70158f * this.overshoot;
|
||||
return this.diff * (val) * val * ((s + 1) * val - s) + this.from;
|
||||
}
|
||||
|
||||
private Vector3 easeOutBack()
|
||||
{
|
||||
float s = 1.70158f * this.overshoot;
|
||||
val = (this.ratioPassed / 1) - 1;
|
||||
val = ((val) * val * ((s + 1) * val + s) + 1);
|
||||
return this.diff * val + this.from;
|
||||
}
|
||||
|
||||
private Vector3 easeInOutBack()
|
||||
{
|
||||
float s = 1.70158f * this.overshoot;
|
||||
val = this.ratioPassed * 2f;
|
||||
if ((val) < 1)
|
||||
{
|
||||
s *= (1.525f) * overshoot;
|
||||
return this.diffDiv2 * (val * val * (((s) + 1) * val - s)) + this.from;
|
||||
}
|
||||
val -= 2;
|
||||
s *= (1.525f) * overshoot;
|
||||
val = ((val) * val * (((s) + 1) * val + s) + 2);
|
||||
return this.diffDiv2 * val + this.from;
|
||||
}
|
||||
|
||||
private Vector3 easeInElastic()
|
||||
{
|
||||
return new Vector3(LeanTween.easeInElastic(this.from.x, this.to.x, this.ratioPassed, this.overshoot, this.period),
|
||||
LeanTween.easeInElastic(this.from.y, this.to.y, this.ratioPassed, this.overshoot, this.period),
|
||||
LeanTween.easeInElastic(this.from.z, this.to.z, this.ratioPassed, this.overshoot, this.period));
|
||||
}
|
||||
|
||||
private Vector3 easeOutElastic()
|
||||
{
|
||||
return new Vector3(LeanTween.easeOutElastic(this.from.x, this.to.x, this.ratioPassed, this.overshoot, this.period),
|
||||
LeanTween.easeOutElastic(this.from.y, this.to.y, this.ratioPassed, this.overshoot, this.period),
|
||||
LeanTween.easeOutElastic(this.from.z, this.to.z, this.ratioPassed, this.overshoot, this.period));
|
||||
}
|
||||
|
||||
private Vector3 easeInOutElastic()
|
||||
{
|
||||
return new Vector3(LeanTween.easeInOutElastic(this.from.x, this.to.x, this.ratioPassed, this.overshoot, this.period),
|
||||
LeanTween.easeInOutElastic(this.from.y, this.to.y, this.ratioPassed, this.overshoot, this.period),
|
||||
LeanTween.easeInOutElastic(this.from.z, this.to.z, this.ratioPassed, this.overshoot, this.period));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how far past a tween will overshoot for certain ease types (compatible: easeInBack, easeInOutBack, easeOutBack, easeOutElastic, easeInElastic, easeInOutElastic). <br>
|
||||
* @method setOvershoot
|
||||
* @param {float} overshoot:float how far past the destination it will go before settling in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutBack ).setOvershoot(2f);
|
||||
*/
|
||||
public LTDescr setOvershoot(float overshoot)
|
||||
{
|
||||
this.overshoot = overshoot;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how short the iterations are for certain ease types (compatible: easeOutElastic, easeInElastic, easeInOutElastic). <br>
|
||||
* @method setPeriod
|
||||
* @param {float} period:float how short the iterations are that the tween will animate at (default 0.3f)
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutElastic ).setPeriod(0.3f);
|
||||
*/
|
||||
public LTDescr setPeriod(float period)
|
||||
{
|
||||
this.period = period;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how large the effect is for certain ease types (compatible: punch, shake, animation curves). <br>
|
||||
* @method setScale
|
||||
* @param {float} scale:float how much the ease will be multiplied by (default 1f)
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.punch ).setScale(2f);
|
||||
*/
|
||||
public LTDescr setScale(float scale)
|
||||
{
|
||||
this.scale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of easing used for the tween with a custom curve. <br>
|
||||
* @method setEase (AnimationCurve)
|
||||
* @param {AnimationCurve} easeDefinition:AnimationCurve an <a href="http://docs.unity3d.com/Documentation/ScriptReference/AnimationCurve.html" target="_blank">AnimationCure</a> that describes the type of easing you want, this is great for when you want a unique type of movement
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce );
|
||||
*/
|
||||
public LTDescr setEase(AnimationCurve easeCurve)
|
||||
{
|
||||
this._optional.animationCurve = easeCurve;
|
||||
this.easeMethod = this.tweenOnCurve;
|
||||
this.easeType = LeanTweenType.animationCurve;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the end that the GameObject is tweening towards
|
||||
* @method setTo
|
||||
* @param {Vector3} to:Vector3 point at which you want the tween to reach
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LTDescr descr = LeanTween.move( cube, Vector3.up, new Vector3(1f,3f,0f), 1.0f ).setEase( LeanTweenType.easeInOutBounce );<br>
|
||||
* // Later your want to change your destination or your destiation is constantly moving<br>
|
||||
* descr.setTo( new Vector3(5f,10f,3f) );<br>
|
||||
*/
|
||||
public LTDescr setTo(Vector3 to)
|
||||
{
|
||||
if (this.hasInitiliazed)
|
||||
{
|
||||
this.to = to;
|
||||
this.diff = to - this.from;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setTo(Transform to)
|
||||
{
|
||||
this._optional.toTrans = to;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the beginning of the tween
|
||||
* @method setFrom
|
||||
* @param {Vector3} from:Vector3 the point you would like the tween to start at
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LTDescr descr = LeanTween.move( cube, Vector3.up, new Vector3(1f,3f,0f), 1.0f ).setFrom( new Vector3(5f,10f,3f) );<br>
|
||||
*/
|
||||
public LTDescr setFrom(Vector3 from)
|
||||
{
|
||||
if (this.trans)
|
||||
{
|
||||
this.init();
|
||||
}
|
||||
this.from = from;
|
||||
// this.hasInitiliazed = true; // this is set, so that the "from" value isn't overwritten later on when the tween starts
|
||||
this.diff = this.to - this.from;
|
||||
this.diffDiv2 = this.diff * 0.5f;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setFrom(float from)
|
||||
{
|
||||
return setFrom(new Vector3(from, 0f, 0f));
|
||||
}
|
||||
|
||||
public LTDescr setDiff(Vector3 diff)
|
||||
{
|
||||
this.diff = diff;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setHasInitialized(bool has)
|
||||
{
|
||||
this.hasInitiliazed = has;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setId(uint id, uint global_counter)
|
||||
{
|
||||
this._id = id;
|
||||
this.counter = global_counter;
|
||||
// Debug.Log("Global counter:"+global_counter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the point of time the tween will start in
|
||||
* @method setPassed
|
||||
* @param {float} passedTime:float the length of time in seconds the tween will start in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* int tweenId = LeanTween.moveX(gameObject, 5f, 2.0f ).id;<br>
|
||||
* // Later<br>
|
||||
* LTDescr descr = description( tweenId );<br>
|
||||
* descr.setPassed( 1f );<br>
|
||||
*/
|
||||
public LTDescr setPassed(float passed)
|
||||
{
|
||||
this.passed = passed;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the finish time of the tween
|
||||
* @method setTime
|
||||
* @param {float} finishTime:float the length of time in seconds you wish the tween to complete in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* int tweenId = LeanTween.moveX(gameObject, 5f, 2.0f ).id;<br>
|
||||
* // Later<br>
|
||||
* LTDescr descr = description( tweenId );<br>
|
||||
* descr.setTime( 1f );<br>
|
||||
*/
|
||||
public LTDescr setTime(float time)
|
||||
{
|
||||
float passedTimeRatio = this.passed / this.time;
|
||||
this.passed = time * passedTimeRatio;
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the finish time of the tween
|
||||
* @method setSpeed
|
||||
* @param {float} speed:float the speed in unity units per second you wish the object to travel (overrides the given time)
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveLocalZ( gameObject, 10f, 1f).setSpeed(0.2f) // the given time is ignored when speed is set<br>
|
||||
*/
|
||||
public LTDescr setSpeed(float speed)
|
||||
{
|
||||
this.speed = speed;
|
||||
if (this.hasInitiliazed)
|
||||
initSpeed();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tween to repeat a number of times.
|
||||
* @method setRepeat
|
||||
* @param {int} repeatNum:int the number of times to repeat the tween. -1 to repeat infinite times
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 10 ).setLoopPingPong();
|
||||
*/
|
||||
public LTDescr setRepeat(int repeat)
|
||||
{
|
||||
this.loopCount = repeat;
|
||||
if ((repeat > 1 && this.loopType == LeanTweenType.once) || (repeat < 0 && this.loopType == LeanTweenType.once))
|
||||
{
|
||||
this.loopType = LeanTweenType.clamp;
|
||||
}
|
||||
if (this.type == TweenAction.CALLBACK || this.type == TweenAction.CALLBACK_COLOR)
|
||||
{
|
||||
this.setOnCompleteOnRepeat(true);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setLoopType(LeanTweenType loopType)
|
||||
{
|
||||
this.loopType = loopType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setUseEstimatedTime(bool useEstimatedTime)
|
||||
{
|
||||
this.useEstimatedTime = useEstimatedTime;
|
||||
this.usesNormalDt = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ignore time scale when tweening an object when you want the animation to be time-scale independent (ignores the Time.timeScale value). Great for pause screens, when you want all other action to be stopped (or slowed down)
|
||||
* @method setIgnoreTimeScale
|
||||
* @param {bool} useUnScaledTime:bool whether to use the unscaled time or not
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setIgnoreTimeScale( true );
|
||||
*/
|
||||
public LTDescr setIgnoreTimeScale(bool useUnScaledTime)
|
||||
{
|
||||
this.useEstimatedTime = useUnScaledTime;
|
||||
this.usesNormalDt = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use frames when tweening an object, when you don't want the animation to be time-frame independent...
|
||||
* @method setUseFrames
|
||||
* @param {bool} useFrames:bool whether to use estimated time or not
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseFrames( true );
|
||||
*/
|
||||
public LTDescr setUseFrames(bool useFrames)
|
||||
{
|
||||
this.useFrames = useFrames;
|
||||
this.usesNormalDt = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setUseManualTime(bool useManualTime)
|
||||
{
|
||||
this.useManualTime = useManualTime;
|
||||
this.usesNormalDt = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setLoopCount(int loopCount)
|
||||
{
|
||||
this.loopType = LeanTweenType.clamp;
|
||||
this.loopCount = loopCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* No looping involved, just run once (the default)
|
||||
* @method setLoopOnce
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopOnce();
|
||||
*/
|
||||
public LTDescr setLoopOnce() { this.loopType = LeanTweenType.once; return this; }
|
||||
|
||||
/**
|
||||
* When the animation gets to the end it starts back at where it began
|
||||
* @method setLoopClamp
|
||||
* @param {int} loops:int (defaults to -1) how many times you want the loop to happen (-1 for an infinite number of times)
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopClamp( 2 );
|
||||
*/
|
||||
public LTDescr setLoopClamp()
|
||||
{
|
||||
this.loopType = LeanTweenType.clamp;
|
||||
if (this.loopCount == 0)
|
||||
this.loopCount = -1;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setLoopClamp(int loops)
|
||||
{
|
||||
this.loopCount = loops;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* When the animation gets to the end it then tweens back to where it started (and on, and on)
|
||||
* @method setLoopPingPong
|
||||
* @param {int} loops:int (defaults to -1) how many times you want the loop to happen in both directions (-1 for an infinite number of times). Passing a value of 1 will cause the object to go towards and back from it's destination once.
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopPingPong( 2 );
|
||||
*/
|
||||
public LTDescr setLoopPingPong()
|
||||
{
|
||||
this.loopType = LeanTweenType.pingPong;
|
||||
if (this.loopCount == 0)
|
||||
this.loopCount = -1;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setLoopPingPong(int loops)
|
||||
{
|
||||
this.loopType = LeanTweenType.pingPong;
|
||||
this.loopCount = loops == -1 ? loops : loops * 2;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Have a method called when the tween finishes
|
||||
* @method setOnComplete
|
||||
* @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished(){ }
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished );
|
||||
*/
|
||||
public LTDescr setOnComplete(Action onComplete)
|
||||
{
|
||||
this._optional.onComplete = onComplete;
|
||||
this.hasExtraOnCompletes = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Have a method called when the tween finishes
|
||||
* @method setOnComplete (object)
|
||||
* @param {Action<object>} onComplete:Action<object> the method that should be called when the tween is finished ex: tweenFinished( object myObj ){ }
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* object tweenFinishedObj = "hi" as object;
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished, tweenFinishedObj );
|
||||
*/
|
||||
public LTDescr setOnComplete(Action<object> onComplete)
|
||||
{
|
||||
this._optional.onCompleteObject = onComplete;
|
||||
this.hasExtraOnCompletes = true;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setOnComplete(Action<object> onComplete, object onCompleteParam)
|
||||
{
|
||||
this._optional.onCompleteObject = onComplete;
|
||||
this.hasExtraOnCompletes = true;
|
||||
if (onCompleteParam != null)
|
||||
this._optional.onCompleteParam = onCompleteParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass an object to along with the onComplete Function
|
||||
* @method setOnCompleteParam
|
||||
* @param {object} onComplete:object an object that
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.delayedCall(1.5f, enterMiniGameStart).setOnCompleteParam( new object[]{""+5} );<br><br>
|
||||
* void enterMiniGameStart( object val ){<br>
|
||||
* object[] arr = (object [])val;<br>
|
||||
* int lvl = int.Parse((string)arr[0]);<br>
|
||||
* }<br>
|
||||
*/
|
||||
public LTDescr setOnCompleteParam(object onCompleteParam)
|
||||
{
|
||||
this._optional.onCompleteParam = onCompleteParam;
|
||||
this.hasExtraOnCompletes = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Have a method called on each frame that the tween is being animated (passes a float value)
|
||||
* @method setOnUpdate
|
||||
* @param {Action<float>} onUpdate:Action<float> a method that will be called on every frame with the float value of the tweened object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );<br>
|
||||
* <br>
|
||||
* void tweenMoved( float val ){ }<br>
|
||||
*/
|
||||
public LTDescr setOnUpdate(Action<float> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateFloat = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setOnUpdateRatio(Action<float, float> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateFloatRatio = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setOnUpdateObject(Action<float, object> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateFloatObject = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setOnUpdateVector2(Action<Vector2> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateVector2 = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setOnUpdateVector3(Action<Vector3> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateVector3 = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setOnUpdateColor(Action<Color> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateColor = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
public LTDescr setOnUpdateColor(Action<Color, object> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateColorObject = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
#if !UNITY_FLASH
|
||||
|
||||
public LTDescr setOnUpdate(Action<Color> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateColor = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setOnUpdate(Action<Color, object> onUpdate)
|
||||
{
|
||||
this._optional.onUpdateColorObject = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Have a method called on each frame that the tween is being animated (passes a float value and a object)
|
||||
* @method setOnUpdate (object)
|
||||
* @param {Action<float,object>} onUpdate:Action<float,object> a method that will be called on every frame with the float value of the tweened object, and an object of the person's choosing
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );<br>
|
||||
* <br>
|
||||
* void tweenMoved( float val, object obj ){ }<br>
|
||||
*/
|
||||
public LTDescr setOnUpdate(Action<float, object> onUpdate, object onUpdateParam = null)
|
||||
{
|
||||
this._optional.onUpdateFloatObject = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
if (onUpdateParam != null)
|
||||
this._optional.onUpdateParam = onUpdateParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setOnUpdate(Action<Vector3, object> onUpdate, object onUpdateParam = null)
|
||||
{
|
||||
this._optional.onUpdateVector3Object = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
if (onUpdateParam != null)
|
||||
this._optional.onUpdateParam = onUpdateParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setOnUpdate(Action<Vector2> onUpdate, object onUpdateParam = null)
|
||||
{
|
||||
this._optional.onUpdateVector2 = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
if (onUpdateParam != null)
|
||||
this._optional.onUpdateParam = onUpdateParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Have a method called on each frame that the tween is being animated (passes a float value)
|
||||
* @method setOnUpdate (Vector3)
|
||||
* @param {Action<Vector3>} onUpdate:Action<Vector3> a method that will be called on every frame with the float value of the tweened object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );<br>
|
||||
* <br>
|
||||
* void tweenMoved( Vector3 val ){ }<br>
|
||||
*/
|
||||
public LTDescr setOnUpdate(Action<Vector3> onUpdate, object onUpdateParam = null)
|
||||
{
|
||||
this._optional.onUpdateVector3 = onUpdate;
|
||||
this.hasUpdateCallback = true;
|
||||
if (onUpdateParam != null)
|
||||
this._optional.onUpdateParam = onUpdateParam;
|
||||
return this;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Have an object passed along with the onUpdate method
|
||||
* @method setOnUpdateParam
|
||||
* @param {object} onUpdateParam:object an object that will be passed along with the onUpdate method
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );<br>
|
||||
* <br>
|
||||
* void tweenMoved( float val, object obj ){ }<br>
|
||||
*/
|
||||
public LTDescr setOnUpdateParam(object onUpdateParam)
|
||||
{
|
||||
this._optional.onUpdateParam = onUpdateParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon
|
||||
* @method setOrientToPath
|
||||
* @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);<br>
|
||||
*/
|
||||
public LTDescr setOrientToPath(bool doesOrient)
|
||||
{
|
||||
if (this.type == TweenAction.MOVE_CURVED || this.type == TweenAction.MOVE_CURVED_LOCAL)
|
||||
{
|
||||
if (this._optional.path == null)
|
||||
this._optional.path = new LTBezierPath();
|
||||
this._optional.path.orientToPath = doesOrient;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._optional.spline.orientToPath = doesOrient;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon
|
||||
* @method setOrientToPath2d
|
||||
* @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath2d(true).setAxis(Vector3.forward);<br>
|
||||
*/
|
||||
public LTDescr setOrientToPath2d(bool doesOrient2d)
|
||||
{
|
||||
setOrientToPath(doesOrient2d);
|
||||
if (this.type == TweenAction.MOVE_CURVED || this.type == TweenAction.MOVE_CURVED_LOCAL)
|
||||
{
|
||||
this._optional.path.orientToPath2d = doesOrient2d;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._optional.spline.orientToPath2d = doesOrient2d;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRect(LTRect rect)
|
||||
{
|
||||
this._optional.ltRect = rect;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setRect(Rect rect)
|
||||
{
|
||||
this._optional.ltRect = new LTRect(rect);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setPath(LTBezierPath path)
|
||||
{
|
||||
this._optional.path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the point at which the GameObject will be rotated around
|
||||
* @method setPoint
|
||||
* @param {Vector3} point:Vector3 point at which you want the object to rotate around (local space)
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.rotateAround( cube, Vector3.up, 360.0f, 1.0f ) .setPoint( new Vector3(1f,0f,0f) ) .setEase( LeanTweenType.easeInOutBounce );<br>
|
||||
*/
|
||||
public LTDescr setPoint(Vector3 point)
|
||||
{
|
||||
this._optional.point = point;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setDestroyOnComplete(bool doesDestroy)
|
||||
{
|
||||
this.destroyOnComplete = doesDestroy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setAudio(object audio)
|
||||
{
|
||||
this._optional.onCompleteParam = audio;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the onComplete method to be called at the end of every loop cycle (also applies to the delayedCall method)
|
||||
* @method setOnCompleteOnRepeat
|
||||
* @param {bool} isOn:bool does call onComplete on every loop cycle
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.delayedCall(gameObject,0.3f, delayedMethod).setRepeat(4).setOnCompleteOnRepeat(true);
|
||||
*/
|
||||
public LTDescr setOnCompleteOnRepeat(bool isOn)
|
||||
{
|
||||
this.onCompleteOnRepeat = isOn;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the onComplete method to be called at the beginning of the tween (it will still be called when it is completed as well)
|
||||
* @method setOnCompleteOnStart
|
||||
* @param {bool} isOn:bool does call onComplete at the start of the tween
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.delayedCall(gameObject, 2f, ()=>{<br> // Flash an object 5 times
|
||||
* LeanTween.alpha(gameObject, 0f, 1f);<br>
|
||||
* LeanTween.alpha(gameObject, 1f, 0f).setDelay(1f);<br>
|
||||
* }).setOnCompleteOnStart(true).setRepeat(5);<br>
|
||||
*/
|
||||
public LTDescr setOnCompleteOnStart(bool isOn)
|
||||
{
|
||||
this.onCompleteOnStart = isOn;
|
||||
return this;
|
||||
}
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
public LTDescr setRect(RectTransform rect)
|
||||
{
|
||||
this.rectTransform = rect;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setSprites(UnityEngine.Sprite[] sprites)
|
||||
{
|
||||
this.sprites = sprites;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTDescr setFrameRate(float frameRate)
|
||||
{
|
||||
this.time = this.sprites.Length / frameRate;
|
||||
return this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Have a method called when the tween starts
|
||||
* @method setOnStart
|
||||
* @param {Action<>} onStart:Action<> the method that should be called when the tween is starting ex: tweenStarted( ){ }
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>C#:</i><br>
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( ()=>{ Debug.Log("I started!"); });
|
||||
* <i>Javascript:</i><br>
|
||||
* LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( function(){ Debug.Log("I started!"); } );
|
||||
*/
|
||||
public LTDescr setOnStart(Action onStart)
|
||||
{
|
||||
this._optional.onStart = onStart;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the direction of a tween -1f for backwards 1f for forwards (currently only bezier and spline paths are supported)
|
||||
* @method setDirection
|
||||
* @param {float} direction:float the direction that the tween should run, -1f for backwards 1f for forwards
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setDirection(-1f);<br>
|
||||
*/
|
||||
|
||||
public LTDescr setDirection(float direction)
|
||||
{
|
||||
if (this.direction != -1f && this.direction != 1f)
|
||||
{
|
||||
Debug.LogWarning("You have passed an incorrect direction of '" + direction + "', direction must be -1f or 1f");
|
||||
return this;
|
||||
}
|
||||
|
||||
if (this.direction != direction)
|
||||
{
|
||||
// Debug.Log("reverse path:"+this.path+" spline:"+this._optional.spline+" hasInitiliazed:"+this.hasInitiliazed);
|
||||
if (this.hasInitiliazed)
|
||||
{
|
||||
this.direction = direction;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._optional.path != null)
|
||||
{
|
||||
this._optional.path = new LTBezierPath(LTUtility.reverse(this._optional.path.pts));
|
||||
}
|
||||
else if (this._optional.spline != null)
|
||||
{
|
||||
this._optional.spline = new LTSpline(LTUtility.reverse(this._optional.spline.pts));
|
||||
}
|
||||
// this.passed = this.time - this.passed;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the tween will recursively effect an objects children in the hierarchy
|
||||
* @method setRecursive
|
||||
* @param {bool} useRecursion:bool whether the tween will recursively effect an objects children in the hierarchy
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.alpha(gameObject, 0f, 1f).setRecursive(true);<br>
|
||||
*/
|
||||
|
||||
public LTDescr setRecursive(bool useRecursion)
|
||||
{
|
||||
this.useRecursion = useRecursion;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
11
KFAttached/LeanTween/Framework/LTDescr.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LTDescr.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 381c8d6fb1acdc348870a7147bc98723
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
99
KFAttached/LeanTween/Framework/LTDescrOptional.cs
Normal file
99
KFAttached/LeanTween/Framework/LTDescrOptional.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
//namespace DentedPixel{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class LTDescrOptional
|
||||
{
|
||||
|
||||
public Transform toTrans { get; set; }
|
||||
public Vector3 point { get; set; }
|
||||
public Vector3 axis { get; set; }
|
||||
public float lastVal { get; set; }
|
||||
public Quaternion origRotation { get; set; }
|
||||
public LTBezierPath path { get; set; }
|
||||
public LTSpline spline { get; set; }
|
||||
public AnimationCurve animationCurve;
|
||||
public int initFrameCount;
|
||||
public Color color;
|
||||
|
||||
public LTRect ltRect { get; set; } // maybe get rid of this eventually
|
||||
|
||||
public Action<float> onUpdateFloat { get; set; }
|
||||
public Action<float, float> onUpdateFloatRatio { get; set; }
|
||||
public Action<float, object> onUpdateFloatObject { get; set; }
|
||||
public Action<Vector2> onUpdateVector2 { get; set; }
|
||||
public Action<Vector3> onUpdateVector3 { get; set; }
|
||||
public Action<Vector3, object> onUpdateVector3Object { get; set; }
|
||||
public Action<Color> onUpdateColor { get; set; }
|
||||
public Action<Color, object> onUpdateColorObject { get; set; }
|
||||
public Action onComplete { get; set; }
|
||||
public Action<object> onCompleteObject { get; set; }
|
||||
public object onCompleteParam { get; set; }
|
||||
public object onUpdateParam { get; set; }
|
||||
public Action onStart { get; set; }
|
||||
|
||||
|
||||
// #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
// public SpriteRenderer spriteRen { get; set; }
|
||||
// #endif
|
||||
//
|
||||
// #if LEANTWEEN_1
|
||||
// public Hashtable optional;
|
||||
// #endif
|
||||
// #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
// public RectTransform rectTransform;
|
||||
// public UnityEngine.UI.Text uiText;
|
||||
// public UnityEngine.UI.Image uiImage;
|
||||
// public UnityEngine.Sprite[] sprites;
|
||||
// #endif
|
||||
|
||||
|
||||
public void reset()
|
||||
{
|
||||
animationCurve = null;
|
||||
|
||||
this.onUpdateFloat = null;
|
||||
this.onUpdateFloatRatio = null;
|
||||
this.onUpdateVector2 = null;
|
||||
this.onUpdateVector3 = null;
|
||||
this.onUpdateFloatObject = null;
|
||||
this.onUpdateVector3Object = null;
|
||||
this.onUpdateColor = null;
|
||||
this.onComplete = null;
|
||||
this.onCompleteObject = null;
|
||||
this.onCompleteParam = null;
|
||||
this.onStart = null;
|
||||
|
||||
this.point = Vector3.zero;
|
||||
this.initFrameCount = 0;
|
||||
}
|
||||
|
||||
public void callOnUpdate(float val, float ratioPassed)
|
||||
{
|
||||
if (this.onUpdateFloat != null)
|
||||
this.onUpdateFloat(val);
|
||||
|
||||
if (this.onUpdateFloatRatio != null)
|
||||
{
|
||||
this.onUpdateFloatRatio(val, ratioPassed);
|
||||
}
|
||||
else if (this.onUpdateFloatObject != null)
|
||||
{
|
||||
this.onUpdateFloatObject(val, this.onUpdateParam);
|
||||
}
|
||||
else if (this.onUpdateVector3Object != null)
|
||||
{
|
||||
this.onUpdateVector3Object(LTDescr.newVect, this.onUpdateParam);
|
||||
}
|
||||
else if (this.onUpdateVector3 != null)
|
||||
{
|
||||
this.onUpdateVector3(LTDescr.newVect);
|
||||
}
|
||||
else if (this.onUpdateVector2 != null)
|
||||
{
|
||||
this.onUpdateVector2(new Vector2(LTDescr.newVect.x, LTDescr.newVect.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
11
KFAttached/LeanTween/Framework/LTDescrOptional.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LTDescrOptional.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1ba8f1ef97134cb39b52ae26678db63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
243
KFAttached/LeanTween/Framework/LTSeq.cs
Normal file
243
KFAttached/LeanTween/Framework/LTSeq.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using UnityEngine;
|
||||
|
||||
/**
|
||||
* Internal Representation of a Sequence<br>
|
||||
* <br>
|
||||
* <h4>Example:</h4>
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append(1f); <span style="color:gray">// delay everything one second</span><br>
|
||||
* seq.append( () => { <span style="color:gray">// fire an event before start</span><br>
|
||||
* Debug.Log("I have started");<br>
|
||||
* });<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); <span style="color:gray">// do a tween</span><br>
|
||||
* seq.append( (object obj) => { <span style="color:gray">// fire event after tween</span><br>
|
||||
* var dict = obj as Dictionary<string,string>;<br>
|
||||
* Debug.Log("We are done now obj value:"+dict["hi"]);<br>
|
||||
* }, new Dictionary<string,string>(){ {"hi","sup"} } );<br>
|
||||
* @class LTSeq
|
||||
* @constructor
|
||||
*/
|
||||
public class LTSeq
|
||||
{
|
||||
|
||||
public LTSeq previous;
|
||||
|
||||
public LTSeq current;
|
||||
|
||||
public LTDescr tween;
|
||||
|
||||
public float totalDelay;
|
||||
|
||||
public float timeScale;
|
||||
|
||||
private int debugIter;
|
||||
|
||||
public uint counter;
|
||||
|
||||
public bool toggle = false;
|
||||
|
||||
private uint _id;
|
||||
|
||||
public int id
|
||||
{
|
||||
get
|
||||
{
|
||||
uint toId = _id | counter << 16;
|
||||
|
||||
/*uint backId = toId & 0xFFFF;
|
||||
uint backCounter = toId >> 16;
|
||||
if(_id!=backId || backCounter!=counter){
|
||||
Debug.LogError("BAD CONVERSION toId:"+_id);
|
||||
}*/
|
||||
|
||||
return (int)toId;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
previous = null;
|
||||
tween = null;
|
||||
totalDelay = 0f;
|
||||
}
|
||||
|
||||
public void init(uint id, uint global_counter)
|
||||
{
|
||||
reset();
|
||||
_id = id;
|
||||
|
||||
counter = global_counter;
|
||||
|
||||
this.current = this;
|
||||
}
|
||||
|
||||
private LTSeq addOn()
|
||||
{
|
||||
this.current.toggle = true;
|
||||
LTSeq lastCurrent = this.current;
|
||||
this.current = LeanTween.sequence(true);
|
||||
// Debug.Log("this.current:" + this.current.id + " lastCurrent:" + lastCurrent.id);
|
||||
this.current.previous = lastCurrent;
|
||||
lastCurrent.toggle = false;
|
||||
this.current.totalDelay = lastCurrent.totalDelay;
|
||||
this.current.debugIter = lastCurrent.debugIter + 1;
|
||||
return current;
|
||||
}
|
||||
|
||||
private float addPreviousDelays()
|
||||
{
|
||||
// Debug.Log("delay:"+delay+" count:"+this.current.count+" this.current.totalDelay:"+this.current.totalDelay);
|
||||
|
||||
LTSeq prev = this.current.previous;
|
||||
|
||||
if (prev != null && prev.tween != null)
|
||||
{
|
||||
return this.current.totalDelay + prev.tween.time;
|
||||
}
|
||||
return this.current.totalDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a time delay to the sequence
|
||||
* @method append (delay)
|
||||
* @param {float} delay:float amount of time to add to the sequence
|
||||
* @return {LTSeq} LTDescr an object that distinguishes the tween
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append(1f); // delay everything one second<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br>
|
||||
*/
|
||||
public LTSeq append(float delay)
|
||||
{
|
||||
this.current.totalDelay += delay;
|
||||
|
||||
return this.current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a time delay to the sequence
|
||||
* @method append (method)
|
||||
* @param {System.Action} callback:System.Action method you want to be called
|
||||
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
|
||||
* @example
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append( () => { // fire an event before start<br>
|
||||
* Debug.Log("I have started");<br>
|
||||
* });<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br>
|
||||
* seq.append( () => { // fire event after tween<br>
|
||||
* Debug.Log("We are done now");<br>
|
||||
* });;<br>
|
||||
*/
|
||||
public LTSeq append(System.Action callback)
|
||||
{
|
||||
LTDescr newTween = LeanTween.delayedCall(0f, callback);
|
||||
// Debug.Log("newTween:" + newTween);
|
||||
return append(newTween);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a time delay to the sequence
|
||||
* @method add (method(object))
|
||||
* @param {System.Action} callback:System.Action method you want to be called
|
||||
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
|
||||
* @example
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append( () => { // fire an event before start<br>
|
||||
* Debug.Log("I have started");<br>
|
||||
* });<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br>
|
||||
* seq.append((object obj) => { // fire event after tween
|
||||
* var dict = obj as Dictionary<string,string>;
|
||||
* Debug.Log("We are done now obj value:"+dict["hi"]);
|
||||
* }, new Dictionary<string,string>(){ {"hi","sup"} } );
|
||||
*/
|
||||
public LTSeq append(System.Action<object> callback, object obj)
|
||||
{
|
||||
append(LeanTween.delayedCall(0f, callback).setOnCompleteParam(obj));
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
public LTSeq append(GameObject gameObject, System.Action callback)
|
||||
{
|
||||
append(LeanTween.delayedCall(gameObject, 0f, callback));
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
public LTSeq append(GameObject gameObject, System.Action<object> callback, object obj)
|
||||
{
|
||||
append(LeanTween.delayedCall(gameObject, 0f, callback).setOnCompleteParam(obj));
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a sequencer object where you can easily chain together tweens and methods one after another
|
||||
*
|
||||
* @method add (tween)
|
||||
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
|
||||
* @example
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a move tween<br>
|
||||
* seq.append( LeanTween.rotateAround( avatar1, Vector3.forward, 360f, 1f ) ); // then do a rotate tween<br>
|
||||
*/
|
||||
public LTSeq append(LTDescr tween)
|
||||
{
|
||||
this.current.tween = tween;
|
||||
|
||||
// Debug.Log("tween:" + tween + " delay:" + this.current.totalDelay);
|
||||
|
||||
this.current.totalDelay = addPreviousDelays();
|
||||
|
||||
tween.setDelay(this.current.totalDelay);
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
public LTSeq insert(LTDescr tween)
|
||||
{
|
||||
this.current.tween = tween;
|
||||
|
||||
tween.setDelay(addPreviousDelays());
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
|
||||
public LTSeq setScale(float timeScale)
|
||||
{
|
||||
// Debug.Log("this.current:" + this.current.previous.debugIter+" tween:"+this.current.previous.tween);
|
||||
setScaleRecursive(this.current, timeScale, 500);
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
private void setScaleRecursive(LTSeq seq, float timeScale, int count)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
this.timeScale = timeScale;
|
||||
|
||||
// Debug.Log("seq.count:" + count + " seq.tween:" + seq.tween);
|
||||
seq.totalDelay *= timeScale;
|
||||
if (seq.tween != null)
|
||||
{
|
||||
// Debug.Log("seq.tween.time * timeScale:" + seq.tween.time * timeScale + " seq.totalDelay:"+seq.totalDelay +" time:"+seq.tween.time+" seq.tween.delay:"+seq.tween.delay);
|
||||
if (seq.tween.time != 0f)
|
||||
seq.tween.setTime(seq.tween.time * timeScale);
|
||||
seq.tween.setDelay(seq.tween.delay * timeScale);
|
||||
}
|
||||
|
||||
if (seq.previous != null)
|
||||
setScaleRecursive(seq.previous, timeScale, count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public LTSeq reverse()
|
||||
{
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
}
|
||||
11
KFAttached/LeanTween/Framework/LTSeq.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LTSeq.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c88dbe4cdd9944f198e9796ee394c86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
471
KFAttached/LeanTween/Framework/LeanAudio.cs
Normal file
471
KFAttached/LeanTween/Framework/LeanAudio.cs
Normal file
@@ -0,0 +1,471 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class LeanAudioStream
|
||||
{
|
||||
|
||||
public int position = 0;
|
||||
|
||||
public AudioClip audioClip;
|
||||
public float[] audioArr;
|
||||
|
||||
public LeanAudioStream(float[] audioArr)
|
||||
{
|
||||
this.audioArr = audioArr;
|
||||
}
|
||||
|
||||
public void OnAudioRead(float[] data)
|
||||
{
|
||||
int count = 0;
|
||||
while (count < data.Length)
|
||||
{
|
||||
data[count] = audioArr[this.position];
|
||||
position++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAudioSetPosition(int newPosition)
|
||||
{
|
||||
this.position = newPosition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Audio dynamically and easily playback
|
||||
*
|
||||
* @class LeanAudio
|
||||
* @constructor
|
||||
*/
|
||||
public class LeanAudio : object
|
||||
{
|
||||
|
||||
public static float MIN_FREQEUNCY_PERIOD = 0.000115f;
|
||||
public static int PROCESSING_ITERATIONS_MAX = 50000;
|
||||
public static float[] generatedWaveDistances;
|
||||
public static int generatedWaveDistancesCount = 0;
|
||||
|
||||
private static float[] longList;
|
||||
|
||||
public static LeanAudioOptions options()
|
||||
{
|
||||
if (generatedWaveDistances == null)
|
||||
{
|
||||
generatedWaveDistances = new float[PROCESSING_ITERATIONS_MAX];
|
||||
longList = new float[PROCESSING_ITERATIONS_MAX];
|
||||
}
|
||||
return new LeanAudioOptions();
|
||||
}
|
||||
|
||||
public static LeanAudioStream createAudioStream(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null)
|
||||
{
|
||||
if (options == null)
|
||||
options = new LeanAudioOptions();
|
||||
|
||||
options.useSetData = false;
|
||||
|
||||
int generatedWavePtsLength = createAudioWave(volume, frequency, options);
|
||||
createAudioFromWave(generatedWavePtsLength, options);
|
||||
|
||||
return options.stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create dynamic audio from a set of Animation Curves and other options.
|
||||
*
|
||||
* @method createAudio
|
||||
* @param {AnimationCurve} volumeCurve:AnimationCurve describing the shape of the audios volume (from 0-1). The length of the audio is dicated by the end value here.
|
||||
* @param {AnimationCurve} frequencyCurve:AnimationCurve describing the width of the oscillations between the sound waves in seconds. Large numbers mean a lower note, while higher numbers mean a tighter frequency and therefor a higher note. Values are usually between 0.01 and 0.000001 (or smaller)
|
||||
* @param {LeanAudioOptions} options:LeanAudioOptions You can pass any other values in here like vibrato or the frequency you would like the sound to be encoded at. See <a href="LeanAudioOptions.html">LeanAudioOptions</a> for more details.
|
||||
* @return {AudioClip} AudioClip of the procedurally generated audio
|
||||
* @example
|
||||
* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
|
||||
* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
|
||||
* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ));<br>
|
||||
*/
|
||||
public static AudioClip createAudio(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null)
|
||||
{
|
||||
if (options == null)
|
||||
options = new LeanAudioOptions();
|
||||
|
||||
int generatedWavePtsLength = createAudioWave(volume, frequency, options);
|
||||
// Debug.Log("generatedWavePtsLength:"+generatedWavePtsLength);
|
||||
return createAudioFromWave(generatedWavePtsLength, options);
|
||||
}
|
||||
|
||||
private static int createAudioWave(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options)
|
||||
{
|
||||
float time = volume[volume.length - 1].time;
|
||||
int listLength = 0;
|
||||
// List<float> list = new List<float>();
|
||||
|
||||
// generatedWaveDistances = new List<float>();
|
||||
// float[] vibratoValues = new float[ vibrato.Length ];
|
||||
float passed = 0f;
|
||||
for (int i = 0; i < PROCESSING_ITERATIONS_MAX; i++)
|
||||
{
|
||||
float f = frequency.Evaluate(passed);
|
||||
if (f < MIN_FREQEUNCY_PERIOD)
|
||||
f = MIN_FREQEUNCY_PERIOD;
|
||||
float height = volume.Evaluate(passed + 0.5f * f);
|
||||
if (options.vibrato != null)
|
||||
{
|
||||
for (int j = 0; j < options.vibrato.Length; j++)
|
||||
{
|
||||
float peakMulti = Mathf.Abs(Mathf.Sin(1.5708f + passed * (1f / options.vibrato[j][0]) * Mathf.PI));
|
||||
float diff = (1f - options.vibrato[j][1]);
|
||||
peakMulti = options.vibrato[j][1] + diff * peakMulti;
|
||||
height *= peakMulti;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debug.Log("i:"+i+" f:"+f+" passed:"+passed+" height:"+height+" time:"+time);
|
||||
if (passed + 0.5f * f >= time)
|
||||
break;
|
||||
if (listLength >= PROCESSING_ITERATIONS_MAX - 1)
|
||||
{
|
||||
Debug.LogError("LeanAudio has reached it's processing cap. To avoid this error increase the number of iterations ex: LeanAudio.PROCESSING_ITERATIONS_MAX = " + (PROCESSING_ITERATIONS_MAX * 2));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
int distPoint = listLength / 2;
|
||||
|
||||
//generatedWaveDistances.Add( f );
|
||||
passed += f;
|
||||
|
||||
generatedWaveDistances[distPoint] = passed;
|
||||
//Debug.Log("distPoint:"+distPoint+" passed:"+passed);
|
||||
|
||||
//list.Add( passed );
|
||||
//list.Add( i%2==0 ? -height : height );
|
||||
|
||||
longList[listLength] = passed;
|
||||
longList[listLength + 1] = i % 2 == 0 ? -height : height;
|
||||
}
|
||||
|
||||
|
||||
|
||||
listLength += 2;
|
||||
|
||||
}
|
||||
|
||||
listLength += -2;
|
||||
generatedWaveDistancesCount = listLength / 2;
|
||||
|
||||
/*float[] wave = new float[ listLength ];
|
||||
for(int i = 0; i < wave.Length; i++){
|
||||
wave[i] = longList[i];
|
||||
}*/
|
||||
return listLength;
|
||||
}
|
||||
|
||||
private static AudioClip createAudioFromWave(int waveLength, LeanAudioOptions options)
|
||||
{
|
||||
float time = longList[waveLength - 2];
|
||||
float[] audioArr = new float[(int)(options.frequencyRate * time)];
|
||||
|
||||
int waveIter = 0;
|
||||
float subWaveDiff = longList[waveIter];
|
||||
float subWaveTimeLast = 0f;
|
||||
float subWaveTime = longList[waveIter];
|
||||
float waveHeight = longList[waveIter + 1];
|
||||
for (int i = 0; i < audioArr.Length; i++)
|
||||
{
|
||||
float passedTime = (float)i / (float)options.frequencyRate;
|
||||
if (passedTime > longList[waveIter])
|
||||
{
|
||||
subWaveTimeLast = longList[waveIter];
|
||||
waveIter += 2;
|
||||
subWaveDiff = longList[waveIter] - longList[waveIter - 2];
|
||||
waveHeight = longList[waveIter + 1];
|
||||
// Debug.Log("passed wave i:"+i);
|
||||
}
|
||||
subWaveTime = passedTime - subWaveTimeLast;
|
||||
float ratioElapsed = subWaveTime / subWaveDiff;
|
||||
|
||||
float value = Mathf.Sin(ratioElapsed * Mathf.PI);
|
||||
|
||||
if (options.waveStyle == LeanAudioOptions.LeanAudioWaveStyle.Square)
|
||||
{
|
||||
if (value > 0f)
|
||||
value = 1f;
|
||||
if (value < 0f)
|
||||
value = -1f;
|
||||
}
|
||||
else if (options.waveStyle == LeanAudioOptions.LeanAudioWaveStyle.Sawtooth)
|
||||
{
|
||||
float sign = value > 0f ? 1f : -1f;
|
||||
if (ratioElapsed < 0.5f)
|
||||
{
|
||||
value = (ratioElapsed * 2f) * sign;
|
||||
}
|
||||
else
|
||||
{ // 0.5f - 1f
|
||||
value = (1f - ratioElapsed) * 2f * sign;
|
||||
}
|
||||
}
|
||||
else if (options.waveStyle == LeanAudioOptions.LeanAudioWaveStyle.Noise)
|
||||
{
|
||||
float peakMulti = (1f - options.waveNoiseInfluence) + Mathf.PerlinNoise(0f, passedTime * options.waveNoiseScale) * options.waveNoiseInfluence;
|
||||
|
||||
/*if(i<25){
|
||||
Debug.Log("passedTime:"+passedTime+" peakMulti:"+peakMulti+" infl:"+options.waveNoiseInfluence);
|
||||
}*/
|
||||
|
||||
value *= peakMulti;
|
||||
}
|
||||
|
||||
//if(i<25)
|
||||
// Debug.Log("passedTime:"+passedTime+" value:"+value+" ratioElapsed:"+ratioElapsed+" subWaveTime:"+subWaveTime+" subWaveDiff:"+subWaveDiff);
|
||||
|
||||
value *= waveHeight;
|
||||
|
||||
|
||||
if (options.modulation != null)
|
||||
{
|
||||
for (int k = 0; k < options.modulation.Length; k++)
|
||||
{
|
||||
float peakMulti = Mathf.Abs(Mathf.Sin(1.5708f + passedTime * (1f / options.modulation[k][0]) * Mathf.PI));
|
||||
float diff = (1f - options.modulation[k][1]);
|
||||
peakMulti = options.modulation[k][1] + diff * peakMulti;
|
||||
// if(k<10){
|
||||
// Debug.Log("k:"+k+" peakMulti:"+peakMulti+" value:"+value+" after:"+(value*peakMulti));
|
||||
// }
|
||||
value *= peakMulti;
|
||||
}
|
||||
}
|
||||
|
||||
audioArr[i] = value;
|
||||
// Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
|
||||
}
|
||||
|
||||
|
||||
int lengthSamples = audioArr.Length;
|
||||
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
bool is3dSound = false;
|
||||
AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, is3dSound, false);
|
||||
#else
|
||||
AudioClip audioClip = null;
|
||||
if (options.useSetData)
|
||||
{
|
||||
audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, null, OnAudioSetPosition);
|
||||
audioClip.SetData(audioArr, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
options.stream = new LeanAudioStream(audioArr);
|
||||
// Debug.Log("len:"+audioArr.Length+" lengthSamples:"+lengthSamples+" freqRate:"+options.frequencyRate);
|
||||
audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, options.stream.OnAudioRead, options.stream.OnAudioSetPosition);
|
||||
options.stream.audioClip = audioClip;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return audioClip;
|
||||
}
|
||||
|
||||
private static void OnAudioSetPosition(int newPosition)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static AudioClip generateAudioFromCurve(AnimationCurve curve, int frequencyRate = 44100)
|
||||
{
|
||||
float curveTime = curve[curve.length - 1].time;
|
||||
float time = curveTime;
|
||||
float[] audioArr = new float[(int)(frequencyRate * time)];
|
||||
|
||||
// Debug.Log("curveTime:"+curveTime+" AudioSettings.outputSampleRate:"+AudioSettings.outputSampleRate);
|
||||
for (int i = 0; i < audioArr.Length; i++)
|
||||
{
|
||||
float pt = (float)i / (float)frequencyRate;
|
||||
audioArr[i] = curve.Evaluate(pt);
|
||||
// Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
|
||||
}
|
||||
|
||||
int lengthSamples = audioArr.Length;//(int)( (float)frequencyRate * curveTime );
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
bool is3dSound = false;
|
||||
AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, frequencyRate, is3dSound, false);
|
||||
#else
|
||||
AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, frequencyRate, false);
|
||||
#endif
|
||||
audioClip.SetData(audioArr, 0);
|
||||
|
||||
return audioClip;
|
||||
}
|
||||
|
||||
public static AudioSource play(AudioClip audio, float volume)
|
||||
{
|
||||
AudioSource audioSource = playClipAt(audio, Vector3.zero);
|
||||
audioSource.volume = volume;
|
||||
return audioSource;
|
||||
}
|
||||
|
||||
public static AudioSource play(AudioClip audio)
|
||||
{
|
||||
return playClipAt(audio, Vector3.zero);
|
||||
}
|
||||
|
||||
public static AudioSource play(AudioClip audio, Vector3 pos)
|
||||
{
|
||||
return playClipAt(audio, pos);
|
||||
}
|
||||
|
||||
public static AudioSource play(AudioClip audio, Vector3 pos, float volume)
|
||||
{
|
||||
// Debug.Log("audio length:"+audio.length);
|
||||
AudioSource audioSource = playClipAt(audio, pos);
|
||||
audioSource.minDistance = 1f;
|
||||
//audioSource.pitch = pitch;
|
||||
audioSource.volume = volume;
|
||||
|
||||
return audioSource;
|
||||
}
|
||||
|
||||
public static AudioSource playClipAt(AudioClip clip, Vector3 pos)
|
||||
{
|
||||
GameObject tempGO = new GameObject(); // create the temp object
|
||||
tempGO.transform.position = pos; // set its position
|
||||
AudioSource aSource = tempGO.AddComponent<AudioSource>(); // add an audio source
|
||||
aSource.clip = clip; // define the clip
|
||||
aSource.Play(); // start the sound
|
||||
GameObject.Destroy(tempGO, clip.length); // destroy object after clip duration
|
||||
return aSource; // return the AudioSource reference
|
||||
}
|
||||
|
||||
public static void printOutAudioClip(AudioClip audioClip, ref AnimationCurve curve, float scaleX = 1f)
|
||||
{
|
||||
// Debug.Log("Audio channels:"+audioClip.channels+" frequency:"+audioClip.frequency+" length:"+audioClip.length+" samples:"+audioClip.samples);
|
||||
float[] samples = new float[audioClip.samples * audioClip.channels];
|
||||
audioClip.GetData(samples, 0);
|
||||
int i = 0;
|
||||
|
||||
Keyframe[] frames = new Keyframe[samples.Length];
|
||||
while (i < samples.Length)
|
||||
{
|
||||
frames[i] = new Keyframe((float)i * scaleX, samples[i]);
|
||||
++i;
|
||||
}
|
||||
curve = new AnimationCurve(frames);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pass in options to LeanAudio
|
||||
*
|
||||
* @class LeanAudioOptions
|
||||
* @constructor
|
||||
*/
|
||||
public class LeanAudioOptions : object
|
||||
{
|
||||
|
||||
public enum LeanAudioWaveStyle
|
||||
{
|
||||
Sine,
|
||||
Square,
|
||||
Sawtooth,
|
||||
Noise
|
||||
}
|
||||
|
||||
public LeanAudioWaveStyle waveStyle = LeanAudioWaveStyle.Sine;
|
||||
public Vector3[] vibrato;
|
||||
public Vector3[] modulation;
|
||||
public int frequencyRate = 44100;
|
||||
public float waveNoiseScale = 1000;
|
||||
public float waveNoiseInfluence = 1f;
|
||||
|
||||
public bool useSetData = true;
|
||||
public LeanAudioStream stream;
|
||||
|
||||
public LeanAudioOptions() { }
|
||||
|
||||
/**
|
||||
* Set the frequency for the audio is encoded. 44100 is CD quality, but you can usually get away with much lower (or use a lower amount to get a more 8-bit sound).
|
||||
*
|
||||
* @method setFrequency
|
||||
* @param {int} frequencyRate:int of the frequency you wish to encode the AudioClip at
|
||||
* @return {LeanAudioOptions} LeanAudioOptions describing optional values
|
||||
* @example
|
||||
* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
|
||||
* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
|
||||
* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ).setFrequency(12100) );<br>
|
||||
*/
|
||||
public LeanAudioOptions setFrequency(int frequencyRate)
|
||||
{
|
||||
this.frequencyRate = frequencyRate;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set details about the shape of the curve by adding vibrato modulations through it (alters the peak values giving it a wah-wah effect). You can add as many as you want to sculpt out more detail in the sound wave.
|
||||
*
|
||||
* @method setVibrato
|
||||
* @param {Vector3[]} vibratoArray:Vector3[] The first value is the period in seconds that you wish to have the vibrato wave fluctuate at. The second value is the minimum height you wish the vibrato wave to dip down to (default is zero). The third is reserved for future effects.
|
||||
* @return {LeanAudioOptions} LeanAudioOptions describing optional values
|
||||
* @example
|
||||
* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
|
||||
* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
|
||||
* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0.3f,0f)} ).setFrequency(12100) );<br>
|
||||
*/
|
||||
public LeanAudioOptions setVibrato(Vector3[] vibrato)
|
||||
{
|
||||
this.vibrato = vibrato;
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
public LeanAudioOptions setModulation( Vector3[] modulation ){
|
||||
this.modulation = modulation;
|
||||
return this;
|
||||
}*/
|
||||
|
||||
public LeanAudioOptions setWaveSine()
|
||||
{
|
||||
this.waveStyle = LeanAudioWaveStyle.Sine;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveSquare()
|
||||
{
|
||||
this.waveStyle = LeanAudioWaveStyle.Square;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveSawtooth()
|
||||
{
|
||||
this.waveStyle = LeanAudioWaveStyle.Sawtooth;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveNoise()
|
||||
{
|
||||
this.waveStyle = LeanAudioWaveStyle.Noise;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveStyle(LeanAudioWaveStyle style)
|
||||
{
|
||||
this.waveStyle = style;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public LeanAudioOptions setWaveNoiseScale(float waveScale)
|
||||
{
|
||||
this.waveNoiseScale = waveScale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveNoiseInfluence(float influence)
|
||||
{
|
||||
this.waveNoiseInfluence = influence;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
KFAttached/LeanTween/Framework/LeanAudio.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LeanAudio.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52e41e970d9353942b27458440bec9eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
363
KFAttached/LeanTween/Framework/LeanSmooth.cs
Normal file
363
KFAttached/LeanTween/Framework/LeanSmooth.cs
Normal file
@@ -0,0 +1,363 @@
|
||||
using UnityEngine;
|
||||
|
||||
/**
|
||||
* Use these smooth methods to move one value towards another<br /><br />
|
||||
* <strong>Example: </strong><br />fromY = LeanSmooth.spring(fromY, followArrow.localPosition.y, ref velocityY, 1.1f);<br />
|
||||
* fromVec3 = LeanSmooth.damp(fromVec3, dude5Title.localPosition, ref velocityVec3, 1.1f);<br />
|
||||
* fromColor = LeanSmooth.damp(fromColor, dude5Title.GetComponent<Renderer>().material.color, ref velocityColor, 1.1f);<br />
|
||||
* Debug.Log("Smoothed y:" + fromY + " vec3:" + fromVec3 + " color:" + fromColor);<br />
|
||||
*
|
||||
* @class LeanSmooth
|
||||
*/
|
||||
|
||||
public class LeanSmooth
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (eases in and out to destination with no overshoot)</summary>
|
||||
*
|
||||
* @method LeanSmooth.damp (float)
|
||||
* @param {float} current:float the current value
|
||||
* @param {float} target:float the value we are trying to reach
|
||||
* @param {float} currentVelocity:float the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @example
|
||||
* followVar = LeanSmooth.damp(followVar, destinationVar, ref followVelocity, 1.1f);\n
|
||||
* Debug.Log("current:"+followVar);
|
||||
*/
|
||||
public static float damp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f)
|
||||
{
|
||||
if (deltaTime < 0f)
|
||||
deltaTime = Time.deltaTime;
|
||||
|
||||
smoothTime = Mathf.Max(0.0001f, smoothTime);
|
||||
float num = 2f / smoothTime;
|
||||
float num2 = num * deltaTime;
|
||||
float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);
|
||||
float num4 = current - target;
|
||||
float num5 = target;
|
||||
if (maxSpeed > 0f)
|
||||
{
|
||||
float num6 = maxSpeed * smoothTime;
|
||||
num4 = Mathf.Clamp(num4, -num6, num6);
|
||||
}
|
||||
target = current - num4;
|
||||
float num7 = (currentVelocity + num * num4) * deltaTime;
|
||||
currentVelocity = (currentVelocity - num * num7) * num3;
|
||||
float num8 = target + (num4 + num7) * num3;
|
||||
if (num5 - current > 0f == num8 > num5)
|
||||
{
|
||||
num8 = num5;
|
||||
currentVelocity = (num8 - num5) / deltaTime;
|
||||
}
|
||||
return num8;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (eases in and out to destination with no overshoot)</summary>
|
||||
*
|
||||
* @method LeanSmooth.damp (Vector3)
|
||||
* @param {float} current:Vector3 the current value
|
||||
* @param {float} target:Vector3 the value we are trying to reach
|
||||
* @param {float} currentVelocity:Vector3 the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @example
|
||||
* transform.position = LeanSmooth.damp(transform.position, destTrans.position, ref followVelocity, 1.1f);\n
|
||||
* Debug.Log("current:"+transform.position);
|
||||
*/
|
||||
public static Vector3 damp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f)
|
||||
{
|
||||
float x = damp(current.x, target.x, ref currentVelocity.x, smoothTime, maxSpeed, deltaTime);
|
||||
float y = damp(current.y, target.y, ref currentVelocity.y, smoothTime, maxSpeed, deltaTime);
|
||||
float z = damp(current.z, target.z, ref currentVelocity.z, smoothTime, maxSpeed, deltaTime);
|
||||
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one color value towards another color (eases in and out to destination with no overshoot)</summary>
|
||||
*
|
||||
* @method LeanSmooth.damp (Color)
|
||||
* @param {float} current:Color the current value
|
||||
* @param {float} target:Color the value we are trying to reach
|
||||
* @param {float} currentVelocity:Color the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @example
|
||||
* fromColor = LeanSmooth.damp(fromColor, transform.GetComponent<Renderer>().material.color, ref velocityColor, 1.1f);\n
|
||||
* Debug.Log("current:"+fromColor);
|
||||
*/
|
||||
public static Color damp(Color current, Color target, ref Color currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f)
|
||||
{
|
||||
float r = damp(current.r, target.r, ref currentVelocity.r, smoothTime, maxSpeed, deltaTime);
|
||||
float g = damp(current.g, target.g, ref currentVelocity.g, smoothTime, maxSpeed, deltaTime);
|
||||
float b = damp(current.b, target.b, ref currentVelocity.b, smoothTime, maxSpeed, deltaTime);
|
||||
float a = damp(current.a, target.a, ref currentVelocity.a, smoothTime, maxSpeed, deltaTime);
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (eases in and out to destination with possible overshoot bounciness)</summary>
|
||||
*
|
||||
* @method LeanSmooth.spring (float)
|
||||
* @param {float} current:float the current value
|
||||
* @param {float} target:float the value we are trying to reach
|
||||
* @param {float} currentVelocity:float the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @example
|
||||
* followVar = LeanSmooth.spring(followVar, destinationVar, ref followVelocity, 1.1f);\n
|
||||
* Debug.Log("current:"+followVar);
|
||||
*/
|
||||
public static float spring(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f, float friction = 2f, float accelRate = 0.5f)
|
||||
{
|
||||
if (deltaTime < 0f)
|
||||
deltaTime = Time.deltaTime;
|
||||
|
||||
float diff = target - current;
|
||||
|
||||
currentVelocity += deltaTime / smoothTime * accelRate * diff;
|
||||
|
||||
currentVelocity *= (1f - deltaTime * friction);
|
||||
|
||||
if (maxSpeed > 0f && maxSpeed < Mathf.Abs(currentVelocity))
|
||||
currentVelocity = maxSpeed * Mathf.Sign(currentVelocity);
|
||||
|
||||
float returned = current + currentVelocity;
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (eases in and out to destination with possible overshoot bounciness)</summary>
|
||||
*
|
||||
* @method LeanSmooth.spring (Vector3)
|
||||
* @param {Vector3} current:float the current value
|
||||
* @param {Vector3} target:float the value we are trying to reach
|
||||
* @param {Vector3} currentVelocity:float the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @example
|
||||
* transform.position = LeanSmooth.spring(transform.position, destTrans.position, ref followVelocity, 1.1f);\n
|
||||
* Debug.Log("current:"+transform.position);
|
||||
*/
|
||||
public static Vector3 spring(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f, float friction = 2f, float accelRate = 0.5f)
|
||||
{
|
||||
float x = spring(current.x, target.x, ref currentVelocity.x, smoothTime, maxSpeed, deltaTime, friction, accelRate);
|
||||
float y = spring(current.y, target.y, ref currentVelocity.y, smoothTime, maxSpeed, deltaTime, friction, accelRate);
|
||||
float z = spring(current.z, target.z, ref currentVelocity.z, smoothTime, maxSpeed, deltaTime, friction, accelRate);
|
||||
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one color towards another (eases in and out to destination with possible overshoot bounciness)</summary>
|
||||
*
|
||||
* @method LeanSmooth.spring (Color)
|
||||
* @param {Color} current:float the current value
|
||||
* @param {Color} target:float the value we are trying to reach
|
||||
* @param {Color} currentVelocity:float the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @example
|
||||
* fromColor = LeanSmooth.spring(fromColor, transform.GetComponent<Renderer>().material.color, ref velocityColor, 1.1f);\n
|
||||
* Debug.Log("current:"+fromColor);
|
||||
*/
|
||||
public static Color spring(Color current, Color target, ref Color currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f, float friction = 2f, float accelRate = 0.5f)
|
||||
{
|
||||
float r = spring(current.r, target.r, ref currentVelocity.r, smoothTime, maxSpeed, deltaTime, friction, accelRate);
|
||||
float g = spring(current.g, target.g, ref currentVelocity.g, smoothTime, maxSpeed, deltaTime, friction, accelRate);
|
||||
float b = spring(current.b, target.b, ref currentVelocity.b, smoothTime, maxSpeed, deltaTime, friction, accelRate);
|
||||
float a = spring(current.a, target.a, ref currentVelocity.a, smoothTime, maxSpeed, deltaTime, friction, accelRate);
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (at a constant speed)</summary>
|
||||
*
|
||||
* @method LeanSmooth.linear (float)
|
||||
* @param {float} current:float the current value
|
||||
* @param {float} target:float the value we are trying to reach
|
||||
* @param {float} moveSpeed:float the speed at which to move towards the target
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @example
|
||||
* followVar = LeanSmooth.linear(followVar, destinationVar, 50f);\n
|
||||
* Debug.Log("current:"+followVar);
|
||||
*/
|
||||
public static float linear(float current, float target, float moveSpeed, float deltaTime = -1f)
|
||||
{
|
||||
if (deltaTime < 0f)
|
||||
deltaTime = Time.deltaTime;
|
||||
|
||||
bool targetGreater = (target > current);
|
||||
|
||||
float currentVelocity = deltaTime * moveSpeed * (targetGreater ? 1f : -1f);
|
||||
|
||||
float returned = current + currentVelocity;
|
||||
|
||||
float returnPassed = returned - target;
|
||||
if ((targetGreater && returnPassed > 0) || !targetGreater && returnPassed < 0)
|
||||
{ // Has passed point, return target
|
||||
return target;
|
||||
}
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (at a constant speed)</summary>
|
||||
*
|
||||
* @method LeanSmooth.linear (Vector3)
|
||||
* @param {Vector3} current:float the current value
|
||||
* @param {Vector3} target:float the value we are trying to reach
|
||||
* @param {float} moveSpeed:float the speed at which to move towards the target
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @example
|
||||
* transform.position = LeanSmooth.linear(transform.position, followTrans.position, 50f);\n
|
||||
* Debug.Log("current:"+transform.position);
|
||||
*/
|
||||
public static Vector3 linear(Vector3 current, Vector3 target, float moveSpeed, float deltaTime = -1f)
|
||||
{
|
||||
float x = linear(current.x, target.x, moveSpeed, deltaTime);
|
||||
float y = linear(current.y, target.y, moveSpeed, deltaTime);
|
||||
float z = linear(current.z, target.z, moveSpeed, deltaTime);
|
||||
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one color towards another (at a constant speed)</summary>
|
||||
*
|
||||
* @method LeanSmooth.linear (Color)
|
||||
* @param {Color} current:float the current value
|
||||
* @param {Color} target:float the value we are trying to reach
|
||||
* @param {float} moveSpeed:float the speed at which to move towards the target
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @example
|
||||
* fromColor = LeanSmooth.linear(fromColor, transform.GetComponent<Renderer>().material.color, 50f);\n
|
||||
* Debug.Log("current:"+fromColor);
|
||||
*/
|
||||
public static Color linear(Color current, Color target, float moveSpeed)
|
||||
{
|
||||
float r = linear(current.r, target.r, moveSpeed);
|
||||
float g = linear(current.g, target.g, moveSpeed);
|
||||
float b = linear(current.b, target.b, moveSpeed);
|
||||
float a = linear(current.a, target.a, moveSpeed);
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (with an ease that bounces back some when it reaches it's destination)</summary>
|
||||
*
|
||||
* @method LeanSmooth.bounceOut (float)
|
||||
* @param {float} current:float the current value
|
||||
* @param {float} target:float the value we are trying to reach
|
||||
* @param {float} currentVelocity:float the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @param {float} [hitDamping]:float the rate at which to dampen the bounciness of when it reaches it's destination
|
||||
* @example
|
||||
* followVar = LeanSmooth.bounceOut(followVar, destinationVar, ref followVelocity, 1.1f);\n
|
||||
* Debug.Log("current:"+followVar);
|
||||
*/
|
||||
public static float bounceOut(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f, float friction = 2f, float accelRate = 0.5f, float hitDamping = 0.9f)
|
||||
{
|
||||
if (deltaTime < 0f)
|
||||
deltaTime = Time.deltaTime;
|
||||
|
||||
float diff = target - current;
|
||||
|
||||
currentVelocity += deltaTime / smoothTime * accelRate * diff;
|
||||
|
||||
currentVelocity *= (1f - deltaTime * friction);
|
||||
|
||||
if (maxSpeed > 0f && maxSpeed < Mathf.Abs(currentVelocity))
|
||||
currentVelocity = maxSpeed * Mathf.Sign(currentVelocity);
|
||||
|
||||
float returned = current + currentVelocity;
|
||||
|
||||
bool targetGreater = (target > current);
|
||||
float returnPassed = returned - target;
|
||||
if ((targetGreater && returnPassed > 0) || !targetGreater && returnPassed < 0)
|
||||
{ // Start a bounce
|
||||
currentVelocity = -currentVelocity * hitDamping;
|
||||
returned = current + currentVelocity;
|
||||
}
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one value towards another (with an ease that bounces back some when it reaches it's destination)</summary>
|
||||
*
|
||||
* @method LeanSmooth.bounceOut (Vector3)
|
||||
* @param {Vector3} current:float the current value
|
||||
* @param {Vector3} target:float the value we are trying to reach
|
||||
* @param {Vector3} currentVelocity:float the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @param {float} [hitDamping]:float the rate at which to dampen the bounciness of when it reaches it's destination
|
||||
* @example
|
||||
* transform.position = LeanSmooth.bounceOut(transform.position, followTrans.position, ref followVelocity, 1.1f);\n
|
||||
* Debug.Log("current:"+transform.position);
|
||||
*/
|
||||
public static Vector3 bounceOut(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f, float friction = 2f, float accelRate = 0.5f, float hitDamping = 0.9f)
|
||||
{
|
||||
float x = bounceOut(current.x, target.x, ref currentVelocity.x, smoothTime, maxSpeed, deltaTime, friction, accelRate, hitDamping);
|
||||
float y = bounceOut(current.y, target.y, ref currentVelocity.y, smoothTime, maxSpeed, deltaTime, friction, accelRate, hitDamping);
|
||||
float z = bounceOut(current.z, target.z, ref currentVelocity.z, smoothTime, maxSpeed, deltaTime, friction, accelRate, hitDamping);
|
||||
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Moves one color towards another (with an ease that bounces back some when it reaches it's destination)</summary>
|
||||
*
|
||||
* @method LeanSmooth.bounceOut (Color)
|
||||
* @param {Color} current:float the current value
|
||||
* @param {Color} target:float the value we are trying to reach
|
||||
* @param {Color} currentVelocity:float the current velocity of the value
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} maxSpeed:float the top speed you want the value to move at (defaults to unlimited -1f)
|
||||
* @param {float} deltaTime:float the difference in time since the method was called (defaults to Time.deltaTime)
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @param {float} [hitDamping]:float the rate at which to dampen the bounciness of when it reaches it's destination
|
||||
* @example
|
||||
* fromColor = LeanSmooth.bounceOut(fromColor, transform.GetComponent<Renderer>().material.color, ref followVelocity, 1.1f);\n
|
||||
* Debug.Log("current:" + fromColor);
|
||||
*/
|
||||
public static Color bounceOut(Color current, Color target, ref Color currentVelocity, float smoothTime, float maxSpeed = -1f, float deltaTime = -1f, float friction = 2f, float accelRate = 0.5f, float hitDamping = 0.9f)
|
||||
{
|
||||
float r = bounceOut(current.r, target.r, ref currentVelocity.r, smoothTime, maxSpeed, deltaTime, friction, accelRate, hitDamping);
|
||||
float g = bounceOut(current.g, target.g, ref currentVelocity.g, smoothTime, maxSpeed, deltaTime, friction, accelRate, hitDamping);
|
||||
float b = bounceOut(current.b, target.b, ref currentVelocity.b, smoothTime, maxSpeed, deltaTime, friction, accelRate, hitDamping);
|
||||
float a = bounceOut(current.a, target.a, ref currentVelocity.a, smoothTime, maxSpeed, deltaTime, friction, accelRate, hitDamping);
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
}
|
||||
11
KFAttached/LeanTween/Framework/LeanSmooth.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LeanSmooth.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ca0f285af8dd4270bd759978223faad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
146
KFAttached/LeanTween/Framework/LeanTest.cs
Normal file
146
KFAttached/LeanTween/Framework/LeanTest.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class LeanTester : MonoBehaviour
|
||||
{
|
||||
public float timeout = 15f;
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
public void Start()
|
||||
{
|
||||
StartCoroutine(timeoutCheck());
|
||||
}
|
||||
|
||||
IEnumerator timeoutCheck()
|
||||
{
|
||||
float pauseEndTime = Time.realtimeSinceStartup + timeout;
|
||||
while (Time.realtimeSinceStartup < pauseEndTime)
|
||||
{
|
||||
yield return 0;
|
||||
}
|
||||
if (LeanTest.testsFinished == false)
|
||||
{
|
||||
Debug.Log(LeanTest.formatB("Tests timed out!"));
|
||||
LeanTest.overview();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public class LeanTest : object
|
||||
{
|
||||
public static int expected = 0;
|
||||
private static int tests = 0;
|
||||
private static int passes = 0;
|
||||
|
||||
public static float timeout = 15f;
|
||||
public static bool timeoutStarted = false;
|
||||
public static bool testsFinished = false;
|
||||
|
||||
public static void debug(string name, bool didPass, string failExplaination = null)
|
||||
{
|
||||
expect(didPass, name, failExplaination);
|
||||
}
|
||||
|
||||
public static void expect(bool didPass, string definition, string failExplaination = null)
|
||||
{
|
||||
float len = printOutLength(definition);
|
||||
int paddingLen = 40 - (int)(len * 1.05f);
|
||||
#if UNITY_FLASH
|
||||
string padding = padRight(paddingLen);
|
||||
#else
|
||||
string padding = "".PadRight(paddingLen, "_"[0]);
|
||||
#endif
|
||||
string logName = formatB(definition) + " " + padding + " [ " + (didPass ? formatC("pass", "green") : formatC("fail", "red")) + " ]";
|
||||
if (didPass == false && failExplaination != null)
|
||||
logName += " - " + failExplaination;
|
||||
Debug.Log(logName);
|
||||
if (didPass)
|
||||
passes++;
|
||||
tests++;
|
||||
|
||||
// Debug.Log("tests:"+tests+" expected:"+expected);
|
||||
if (tests == expected && testsFinished == false)
|
||||
{
|
||||
overview();
|
||||
}
|
||||
else if (tests > expected)
|
||||
{
|
||||
Debug.Log(formatB("Too many tests for a final report!") + " set LeanTest.expected = " + tests);
|
||||
}
|
||||
|
||||
if (timeoutStarted == false)
|
||||
{
|
||||
timeoutStarted = true;
|
||||
GameObject tester = new GameObject();
|
||||
tester.name = "~LeanTest";
|
||||
LeanTester test = tester.AddComponent(typeof(LeanTester)) as LeanTester;
|
||||
test.timeout = timeout;
|
||||
#if !UNITY_EDITOR
|
||||
tester.hideFlags = HideFlags.HideAndDontSave;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static string padRight(int len)
|
||||
{
|
||||
string str = "";
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
str += "_";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static float printOutLength(string str)
|
||||
{
|
||||
float len = 0.0f;
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (str[i] == "I"[0])
|
||||
{
|
||||
len += 0.5f;
|
||||
}
|
||||
else if (str[i] == "J"[0])
|
||||
{
|
||||
len += 0.85f;
|
||||
}
|
||||
else
|
||||
{
|
||||
len += 1.0f;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
public static string formatBC(string str, string color)
|
||||
{
|
||||
return formatC(formatB(str), color);
|
||||
}
|
||||
|
||||
public static string formatB(string str)
|
||||
{
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
|
||||
return str;
|
||||
#else
|
||||
return "<b>" + str + "</b>";
|
||||
#endif
|
||||
}
|
||||
|
||||
public static string formatC(string str, string color)
|
||||
{
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
|
||||
return str;
|
||||
#else
|
||||
return "<color=" + color + ">" + str + "</color>";
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void overview()
|
||||
{
|
||||
testsFinished = true;
|
||||
int failedCnt = (expected - passes);
|
||||
string failedStr = failedCnt > 0 ? formatBC("" + failedCnt, "red") : "" + failedCnt;
|
||||
Debug.Log(formatB("Final Report:") + " _____________________ PASSED: " + formatBC("" + passes, "green") + " FAILED: " + failedStr + " ");
|
||||
}
|
||||
}
|
||||
11
KFAttached/LeanTween/Framework/LeanTest.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LeanTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82464f26ca2ba284a8f92f51248c574a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
4581
KFAttached/LeanTween/Framework/LeanTween.cs
Normal file
4581
KFAttached/LeanTween/Framework/LeanTween.cs
Normal file
@@ -0,0 +1,4581 @@
|
||||
//namespace DentedPixel{
|
||||
|
||||
// LeanTween version 2.50 - http://dentedpixel.com/developer-diary/
|
||||
//
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2017 Russell Savage - Dented Pixel
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
|
||||
|
||||
/*
|
||||
TERMS OF USE - EASING EQUATIONS#
|
||||
Open source under the BSD License.
|
||||
Copyright (c)2001 Robert Penner
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pass this to the "ease" parameter, to get a different easing behavior<br /><br />
|
||||
* <strong>Example: </strong><br />LeanTween.rotateX(gameObject, 270.0f, 1.5f).setEase(LeanTweenType.easeInBack);
|
||||
*
|
||||
* @class LeanTweenType
|
||||
*/
|
||||
|
||||
/**
|
||||
* @property {integer} linear
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutQuad
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInQuad
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutQuad
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInCubic
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutCubic
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutCubic
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInQuart
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutQuart
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutQuart
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInQuint
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutQuint
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutQuint
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInSine
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutSine
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutSine
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInExpo
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutExpo
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutExpo
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInCirc
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutCirc
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutCirc
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInBounce
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutBounce
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutBounce
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInBack
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutBack
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutBack
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInElastic
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeOutElastic
|
||||
*/
|
||||
/**
|
||||
* @property {integer} easeInOutElastic
|
||||
*/
|
||||
/**
|
||||
* @property {integer} punch
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum TweenAction
|
||||
{
|
||||
MOVE_X,
|
||||
MOVE_Y,
|
||||
MOVE_Z,
|
||||
MOVE_LOCAL_X,
|
||||
MOVE_LOCAL_Y,
|
||||
MOVE_LOCAL_Z,
|
||||
MOVE_CURVED,
|
||||
MOVE_CURVED_LOCAL,
|
||||
MOVE_SPLINE,
|
||||
MOVE_SPLINE_LOCAL,
|
||||
SCALE_X,
|
||||
SCALE_Y,
|
||||
SCALE_Z,
|
||||
ROTATE_X,
|
||||
ROTATE_Y,
|
||||
ROTATE_Z,
|
||||
ROTATE_AROUND,
|
||||
ROTATE_AROUND_LOCAL,
|
||||
CANVAS_ROTATEAROUND,
|
||||
CANVAS_ROTATEAROUND_LOCAL,
|
||||
CANVAS_PLAYSPRITE,
|
||||
ALPHA,
|
||||
TEXT_ALPHA,
|
||||
CANVAS_ALPHA,
|
||||
CANVASGROUP_ALPHA,
|
||||
ALPHA_VERTEX,
|
||||
COLOR,
|
||||
CALLBACK_COLOR,
|
||||
TEXT_COLOR,
|
||||
CANVAS_COLOR,
|
||||
CANVAS_MOVE_X,
|
||||
CANVAS_MOVE_Y,
|
||||
CANVAS_MOVE_Z,
|
||||
CALLBACK,
|
||||
MOVE,
|
||||
MOVE_LOCAL,
|
||||
MOVE_TO_TRANSFORM,
|
||||
ROTATE,
|
||||
ROTATE_LOCAL,
|
||||
SCALE,
|
||||
VALUE3,
|
||||
GUI_MOVE,
|
||||
GUI_MOVE_MARGIN,
|
||||
GUI_SCALE,
|
||||
GUI_ALPHA,
|
||||
GUI_ROTATE,
|
||||
DELAYED_SOUND,
|
||||
CANVAS_MOVE,
|
||||
CANVAS_SCALE,
|
||||
CANVAS_SIZEDELTA,
|
||||
FOLLOW,
|
||||
|
||||
}
|
||||
|
||||
public enum LeanTweenType
|
||||
{
|
||||
notUsed, linear, easeOutQuad, easeInQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart,
|
||||
easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc,
|
||||
easeInBounce, easeOutBounce, easeInOutBounce, easeInBack, easeOutBack, easeInOutBack, easeInElastic, easeOutElastic, easeInOutElastic, easeSpring, easeShake, punch, once, clamp, pingPong, animationCurve
|
||||
}
|
||||
|
||||
public enum LeanProp
|
||||
{
|
||||
position,
|
||||
localPosition,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
localX,
|
||||
localY,
|
||||
localZ,
|
||||
scale,
|
||||
color
|
||||
}
|
||||
|
||||
/**
|
||||
* LeanTween is an efficient tweening engine for Unity3d<br /><br />
|
||||
* <a href="#index">Index of All Methods</a> | <a href="LTDescr.html">Optional Paramaters that can be passed</a><br /><br />
|
||||
* <strong id='optional'>Optional Parameters</strong> are passed at the end of every method<br />
|
||||
* <br />
|
||||
* <i>Example:</i><br />
|
||||
* LeanTween.moveX( gameObject, 1f, 1f).setEase( <a href="LeanTweenType.html">LeanTweenType</a>.easeInQuad ).setDelay(1f);<br />
|
||||
* <br />
|
||||
* You can pass the optional parameters in any order, and chain on as many as you wish!<br /><br />
|
||||
* You can also modify this tween later, just save the unique id of the tween.<br />
|
||||
* <h4>Example:</h4>
|
||||
* int id = LeanTween.moveX(gameObject, 1f, 1f).id;<br />
|
||||
* <a href="LTDescr.html">LTDescr</a> d = LeanTween.<a href="#method_LeanTween.descr">descr</a>( id );<br /><br />
|
||||
* if(d!=null){ <span style="color:gray">// if the tween has already finished it will return null</span><br />
|
||||
* <span style="color:gray">   // change some parameters</span><br />
|
||||
*    d.setOnComplete( onCompleteFunc ).setEase( <a href="LeanTweenType.html">LeanTweenType</a>.easeInOutBack );<br />
|
||||
* }
|
||||
*
|
||||
* @class LeanTween
|
||||
*/
|
||||
|
||||
public class LeanTween : MonoBehaviour
|
||||
{
|
||||
|
||||
public static bool throwErrors = true;
|
||||
public static float tau = Mathf.PI * 2.0f;
|
||||
public static float PI_DIV2 = Mathf.PI / 2.0f;
|
||||
|
||||
private static LTSeq[] sequences;
|
||||
|
||||
private static LTDescr[] tweens;
|
||||
private static int[] tweensFinished;
|
||||
private static int[] tweensFinishedIds;
|
||||
private static LTDescr tween;
|
||||
private static int tweenMaxSearch = -1;
|
||||
private static int maxTweens = 400;
|
||||
private static int maxSequences = 400;
|
||||
private static int frameRendered = -1;
|
||||
private static GameObject _tweenEmpty;
|
||||
public static float dtEstimated = -1f;
|
||||
public static float dtManual;
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
|
||||
private static float previousRealTime;
|
||||
#endif
|
||||
public static float dtActual;
|
||||
private static uint global_counter = 0;
|
||||
private static int i;
|
||||
private static int j;
|
||||
private static int finishedCnt;
|
||||
public static AnimationCurve punch = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(0.112586f, 0.9976035f), new Keyframe(0.3120486f, -0.1720615f), new Keyframe(0.4316337f, 0.07030682f), new Keyframe(0.5524869f, -0.03141804f), new Keyframe(0.6549395f, 0.003909959f), new Keyframe(0.770987f, -0.009817753f), new Keyframe(0.8838775f, 0.001939224f), new Keyframe(1.0f, 0.0f));
|
||||
public static AnimationCurve shake = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(0.75f, -1f), new Keyframe(1f, 0f));
|
||||
|
||||
public static void init()
|
||||
{
|
||||
init(maxTweens);
|
||||
}
|
||||
|
||||
public static int maxSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
return tweenMaxSearch;
|
||||
}
|
||||
}
|
||||
|
||||
public static int maxSimulataneousTweens
|
||||
{
|
||||
get
|
||||
{
|
||||
return maxTweens;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Find out how many tweens you have animating at a given time</summary>
|
||||
*
|
||||
* @method LeanTween.tweensRunning
|
||||
* @example
|
||||
* Debug.Log("I have "+LeanTween.tweensRunning+" animating!");
|
||||
*/
|
||||
public static int tweensRunning
|
||||
{
|
||||
get
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].toggle)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This line is optional. Here you can specify the maximum number of tweens you will use (the default is 400). This must be called before any use of LeanTween is made for it to be effective. <summary>This line is optional. Here you can specify the maximum number of tweens you will use (the default is 400). This must be called before any use of LeanTween is made for it to be effective. </summary>
|
||||
*
|
||||
* @method LeanTween.init
|
||||
* @param {integer} maxSimultaneousTweens:int The maximum number of tweens you will use, make sure you don't go over this limit, otherwise the code will throw an error
|
||||
* @example
|
||||
* LeanTween.init( 800 );
|
||||
*/
|
||||
public static void init(int maxSimultaneousTweens)
|
||||
{
|
||||
init(maxSimultaneousTweens, maxSequences);
|
||||
}
|
||||
|
||||
public static void init(int maxSimultaneousTweens, int maxSimultaneousSequences)
|
||||
{
|
||||
if (tweens == null)
|
||||
{
|
||||
maxTweens = maxSimultaneousTweens;
|
||||
tweens = new LTDescr[maxTweens];
|
||||
tweensFinished = new int[maxTweens];
|
||||
tweensFinishedIds = new int[maxTweens];
|
||||
_tweenEmpty = new GameObject();
|
||||
_tweenEmpty.name = "~LeanTween";
|
||||
_tweenEmpty.AddComponent(typeof(LeanTween));
|
||||
_tweenEmpty.isStatic = true;
|
||||
#if !UNITY_EDITOR
|
||||
_tweenEmpty.hideFlags = HideFlags.HideAndDontSave;
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
if(Application.isPlaying)
|
||||
DontDestroyOnLoad( _tweenEmpty );
|
||||
#else
|
||||
DontDestroyOnLoad(_tweenEmpty);
|
||||
#endif
|
||||
for (int i = 0; i < maxTweens; i++)
|
||||
{
|
||||
tweens[i] = new LTDescr();
|
||||
}
|
||||
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
UnityEngine.SceneManagement.SceneManager.sceneLoaded += onLevelWasLoaded54;
|
||||
#endif
|
||||
|
||||
sequences = new LTSeq[maxSimultaneousSequences];
|
||||
|
||||
for (int i = 0; i < maxSimultaneousSequences; i++)
|
||||
{
|
||||
sequences[i] = new LTSeq();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset()
|
||||
{
|
||||
if (tweens != null)
|
||||
{
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i] != null)
|
||||
tweens[i].toggle = false;
|
||||
}
|
||||
}
|
||||
tweens = null;
|
||||
Destroy(_tweenEmpty);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
LeanTween.update();
|
||||
}
|
||||
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
private static void onLevelWasLoaded54( UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode ){ internalOnLevelWasLoaded( scene.buildIndex ); }
|
||||
#else
|
||||
public void OnLevelWasLoaded(int lvl) { internalOnLevelWasLoaded(lvl); }
|
||||
#endif
|
||||
|
||||
private static void internalOnLevelWasLoaded(int lvl)
|
||||
{
|
||||
// Debug.Log("reseting gui");
|
||||
LTGUI.reset();
|
||||
}
|
||||
|
||||
private static int maxTweenReached;
|
||||
|
||||
public static void update()
|
||||
{
|
||||
if (frameRendered != Time.frameCount)
|
||||
{ // make sure update is only called once per frame
|
||||
init();
|
||||
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
|
||||
dtEstimated = Time.realtimeSinceStartup - previousRealTime;
|
||||
if(dtEstimated>0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large
|
||||
dtEstimated = 0.2f;
|
||||
previousRealTime = Time.realtimeSinceStartup;
|
||||
#else
|
||||
|
||||
dtEstimated = dtEstimated < 0f ? 0f : dtEstimated = Time.unscaledDeltaTime;
|
||||
|
||||
// Debug.Log("Time.unscaledDeltaTime:"+Time.unscaledDeltaTime);
|
||||
#endif
|
||||
|
||||
dtActual = Time.deltaTime;
|
||||
maxTweenReached = 0;
|
||||
finishedCnt = 0;
|
||||
// if(tweenMaxSearch>1500)
|
||||
// Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens);
|
||||
for (int i = 0; i <= tweenMaxSearch && i < maxTweens; i++)
|
||||
{
|
||||
tween = tweens[i];
|
||||
// if(i==0 && tweens[i].toggle)
|
||||
// Debug.Log("tweens["+i+"]"+tweens[i]);
|
||||
if (tween.toggle)
|
||||
{
|
||||
maxTweenReached = i;
|
||||
|
||||
if (tween.updateInternal())
|
||||
{ // returns true if the tween is finished with it's loop
|
||||
tweensFinished[finishedCnt] = i;
|
||||
tweensFinishedIds[finishedCnt] = tweens[i].id;
|
||||
finishedCnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Debug.Log("maxTweenReached:"+maxTweenReached);
|
||||
tweenMaxSearch = maxTweenReached;
|
||||
frameRendered = Time.frameCount;
|
||||
|
||||
for (int i = 0; i < finishedCnt; i++)
|
||||
{
|
||||
j = tweensFinished[i];
|
||||
tween = tweens[j];
|
||||
|
||||
if (tween.id == tweensFinishedIds[i])
|
||||
{
|
||||
// Debug.Log("removing tween:"+tween);
|
||||
removeTween(j);
|
||||
if (tween.hasExtraOnCompletes && tween.trans != null)
|
||||
tween.callOnCompletes();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void removeTween(int i, int uniqueId)
|
||||
{ // Only removes the tween if the unique id matches <summary>Move a GameObject to a certain location</summary>
|
||||
if (tweens[i].uniqueId == uniqueId)
|
||||
{
|
||||
removeTween(i);
|
||||
}
|
||||
}
|
||||
|
||||
// This method is only used internally! Do not call this from your scripts. To cancel a tween use LeanTween.cancel
|
||||
public static void removeTween(int i)
|
||||
{
|
||||
if (tweens[i].toggle)
|
||||
{
|
||||
tweens[i].toggle = false;
|
||||
tweens[i].counter = uint.MaxValue;
|
||||
//logError("Removing tween["+i+"]:"+tweens[i]);
|
||||
if (tweens[i].destroyOnComplete)
|
||||
{
|
||||
// Debug.Log("destroying tween.type:"+tween.type+" ltRect"+(tweens[i]._optional.ltRect==null));
|
||||
if (tweens[i]._optional.ltRect != null)
|
||||
{
|
||||
// Debug.Log("destroy i:"+i+" id:"+tweens[i].ltRect.id);
|
||||
LTGUI.destroy(tweens[i]._optional.ltRect.id);
|
||||
}
|
||||
else
|
||||
{ // check if equal to tweenEmpty
|
||||
if (tweens[i].trans != null && tweens[i].trans.gameObject != _tweenEmpty)
|
||||
{
|
||||
Destroy(tweens[i].trans.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
//tweens[i].optional = null;
|
||||
startSearch = i;
|
||||
//Debug.Log("start search reset:"+startSearch + " i:"+i+" tweenMaxSearch:"+tweenMaxSearch);
|
||||
if (i + 1 >= tweenMaxSearch)
|
||||
{
|
||||
//Debug.Log("reset to zero");
|
||||
startSearch = 0;
|
||||
//tweenMaxSearch--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3[] add(Vector3[] a, Vector3 b)
|
||||
{
|
||||
Vector3[] c = new Vector3[a.Length];
|
||||
for (i = 0; i < a.Length; i++)
|
||||
{
|
||||
c[i] = a[i] + b;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static float closestRot(float from, float to)
|
||||
{
|
||||
float minusWhole = 0 - (360 - to);
|
||||
float plusWhole = 360 + to;
|
||||
float toDiffAbs = Mathf.Abs(to - from);
|
||||
float minusDiff = Mathf.Abs(minusWhole - from);
|
||||
float plusDiff = Mathf.Abs(plusWhole - from);
|
||||
if (toDiffAbs < minusDiff && toDiffAbs < plusDiff)
|
||||
{
|
||||
return to;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (minusDiff < plusDiff)
|
||||
{
|
||||
return minusWhole;
|
||||
}
|
||||
else
|
||||
{
|
||||
return plusWhole;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Cancels all tweens</summary>
|
||||
*
|
||||
* @method LeanTween.cancelAll
|
||||
* @param {bool} callComplete:bool (optional) if true, then the all onCompletes will run before canceling
|
||||
* @example LeanTween.cancelAll(true); <br />
|
||||
*/
|
||||
public static void cancelAll()
|
||||
{
|
||||
cancelAll(false);
|
||||
}
|
||||
public static void cancelAll(bool callComplete)
|
||||
{
|
||||
init();
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].trans != null)
|
||||
{
|
||||
if (callComplete && tweens[i].optional.onComplete != null)
|
||||
tweens[i].optional.onComplete();
|
||||
removeTween(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Cancel all tweens that are currently targeting the gameObject</summary>
|
||||
*
|
||||
* @method LeanTween.cancel
|
||||
* @param {GameObject} gameObject:GameObject gameObject whose tweens you wish to cancel
|
||||
* @param {bool} callOnComplete:bool (optional) whether to call the onComplete method before canceling
|
||||
* @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f); <br />
|
||||
* LeanTween.cancel( gameObject );
|
||||
*/
|
||||
public static void cancel(GameObject gameObject)
|
||||
{
|
||||
cancel(gameObject, false);
|
||||
}
|
||||
public static void cancel(GameObject gameObject, bool callOnComplete)
|
||||
{
|
||||
init();
|
||||
Transform trans = gameObject.transform;
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
LTDescr tween = tweens[i];
|
||||
if (tween != null && tween.toggle && tween.trans == trans)
|
||||
{
|
||||
if (callOnComplete && tween.optional.onComplete != null)
|
||||
tween.optional.onComplete();
|
||||
removeTween(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void cancel(RectTransform rect)
|
||||
{
|
||||
cancel(rect.gameObject, false);
|
||||
}
|
||||
|
||||
// public static void cancel( GameObject gameObject, int uniqueId ){
|
||||
// if(uniqueId>=0){
|
||||
// init();
|
||||
// int backId = uniqueId & 0xFFFF;
|
||||
// int backCounter = uniqueId >> 16;
|
||||
// // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tweens[backId].counter + " tweens[id].type:"+tweens[backId].type);
|
||||
// if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter))
|
||||
// removeTween((int)backId);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void cancel(GameObject gameObject, int uniqueId, bool callOnComplete = false)
|
||||
{
|
||||
if (uniqueId >= 0)
|
||||
{
|
||||
init();
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
// Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tw eens[backId].counter + " tweens[id].type:"+tweens[backId].type);
|
||||
if (tweens[backId].trans == null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter == backCounter))
|
||||
{
|
||||
if (callOnComplete && tweens[backId].optional.onComplete != null)
|
||||
tweens[backId].optional.onComplete();
|
||||
removeTween((int)backId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void cancel(LTRect ltRect, int uniqueId)
|
||||
{
|
||||
if (uniqueId >= 0)
|
||||
{
|
||||
init();
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
// Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type);
|
||||
if (tweens[backId]._optional.ltRect == ltRect && tweens[backId].counter == backCounter)
|
||||
removeTween((int)backId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Cancel a specific tween with the provided id</summary>
|
||||
*
|
||||
* @method LeanTween.cancel
|
||||
* @param {int} id:int unique id that represents that tween
|
||||
* @param {bool} callOnComplete:bool (optional) whether to call the onComplete method before canceling
|
||||
* @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).id; <br />
|
||||
* LeanTween.cancel( id );
|
||||
*/
|
||||
public static void cancel(int uniqueId)
|
||||
{
|
||||
cancel(uniqueId, false);
|
||||
}
|
||||
public static void cancel(int uniqueId, bool callOnComplete)
|
||||
{
|
||||
if (uniqueId >= 0)
|
||||
{
|
||||
init();
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
if (backId > tweens.Length - 1)
|
||||
{ // sequence
|
||||
int sequenceId = backId - tweens.Length;
|
||||
LTSeq seq = sequences[sequenceId];
|
||||
// Debug.Log("sequenceId:" + sequenceId+" maxSequences:"+maxSequences+" prev:"+seq.previous);
|
||||
|
||||
for (int i = 0; i < maxSequences; i++)
|
||||
{
|
||||
if (seq.current.tween != null)
|
||||
{
|
||||
int tweenId = seq.current.tween.uniqueId;
|
||||
int tweenIndex = tweenId & 0xFFFF;
|
||||
removeTween(tweenIndex);
|
||||
}
|
||||
if (seq.current.previous == null)
|
||||
break;
|
||||
seq.current = seq.current.previous;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // tween
|
||||
// Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type);
|
||||
if (tweens[backId].counter == backCounter)
|
||||
{
|
||||
if (callOnComplete && tweens[backId].optional.onComplete != null)
|
||||
tweens[backId].optional.onComplete();
|
||||
removeTween((int)backId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Retrieve a tweens LTDescr object to modify</summary>
|
||||
*
|
||||
* @method LeanTween.descr
|
||||
* @param {int} id:int unique id that represents that tween
|
||||
* @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod ).id; <br /><br />
|
||||
* <div style="color:gray">// later I want decide I want to change onComplete method </div>
|
||||
* LTDescr descr = LeanTween.descr( id );<br />
|
||||
* if(descr!=null) <span style="color:gray">// if the tween has already finished it will come back null</span><br />
|
||||
*   descr.setOnComplete( newMethod );<br />
|
||||
*/
|
||||
public static LTDescr descr(int uniqueId)
|
||||
{
|
||||
init();
|
||||
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
|
||||
// Debug.Log("backId:" + backId+" backCounter:"+backCounter);
|
||||
if (tweens[backId] != null && tweens[backId].uniqueId == uniqueId && tweens[backId].counter == backCounter)
|
||||
{
|
||||
// Debug.Log("tween count:" + tweens[backId].counter);
|
||||
return tweens[backId];
|
||||
}
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].uniqueId == uniqueId && tweens[i].counter == backCounter)
|
||||
{
|
||||
return tweens[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LTDescr description(int uniqueId)
|
||||
{
|
||||
return descr(uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Retrieve a tweens LTDescr object(s) to modify</summary>
|
||||
*
|
||||
* @method LeanTween.descriptions
|
||||
* @param {GameObject} id:GameObject object whose tween descriptions you want to retrieve
|
||||
* @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod ); <br /><br />
|
||||
* <div style="color:gray">// later I want decide I want to change onComplete method </div>
|
||||
* LTDescr[] descr = LeanTween.descriptions( gameObject );<br />
|
||||
* if(descr.Length>0) <span style="color:gray">// make sure there is a valid description for this target</span><br />
|
||||
*   descr[0].setOnComplete( newMethod );<span style="color:gray">// in this case we only ever expect there to be one tween on this object</span><br />
|
||||
*/
|
||||
public static LTDescr[] descriptions(GameObject gameObject = null)
|
||||
{
|
||||
if (gameObject == null) return null;
|
||||
|
||||
List<LTDescr> descrs = new List<LTDescr>();
|
||||
Transform trans = gameObject.transform;
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].toggle && tweens[i].trans == trans)
|
||||
descrs.Add(tweens[i]);
|
||||
}
|
||||
return descrs.ToArray();
|
||||
}
|
||||
|
||||
[System.Obsolete("Use 'pause( id )' instead")]
|
||||
public static void pause(GameObject gameObject, int uniqueId)
|
||||
{
|
||||
pause(uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Pause all tweens for a GameObject</summary>
|
||||
*
|
||||
* @method LeanTween.pause
|
||||
* @param {int} id:int Id of the tween you want to pause
|
||||
* @example
|
||||
* int id = LeanTween.moveX(gameObject, 5, 1.0).id<br />
|
||||
* LeanTween.pause( id );<br />
|
||||
* // Later....<br />
|
||||
* LeanTween.resume( id );
|
||||
*/
|
||||
public static void pause(int uniqueId)
|
||||
{
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
if (tweens[backId].counter == backCounter)
|
||||
{
|
||||
tweens[backId].pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Pause all tweens for a GameObject</summary>
|
||||
*
|
||||
* @method LeanTween.pause
|
||||
* @param {GameObject} gameObject:GameObject GameObject whose tweens you want to pause
|
||||
*/
|
||||
public static void pause(GameObject gameObject)
|
||||
{
|
||||
Transform trans = gameObject.transform;
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].trans == trans)
|
||||
{
|
||||
tweens[i].pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Pause all active tweens</summary>
|
||||
*
|
||||
* @method LeanTween.pauseAll
|
||||
*/
|
||||
public static void pauseAll()
|
||||
{
|
||||
init();
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
tweens[i].pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Resume all active tweens</summary>
|
||||
*
|
||||
* @method LeanTween.resumeAll
|
||||
*/
|
||||
public static void resumeAll()
|
||||
{
|
||||
init();
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
tweens[i].resume();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Obsolete("Use 'resume( id )' instead")]
|
||||
public static void resume(GameObject gameObject, int uniqueId)
|
||||
{
|
||||
resume(uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Resume a specific tween</summary>
|
||||
*
|
||||
* @method LeanTween.resume
|
||||
* @param {int} id:int Id of the tween you want to resume
|
||||
* @example
|
||||
* int id = LeanTween.moveX(gameObject, 5, 1.0).id<br />
|
||||
* LeanTween.pause( id );<br />
|
||||
* // Later....<br />
|
||||
* LeanTween.resume( id );
|
||||
*/
|
||||
public static void resume(int uniqueId)
|
||||
{
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
if (tweens[backId].counter == backCounter)
|
||||
{
|
||||
tweens[backId].resume();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Resume all the tweens on a GameObject</summary>
|
||||
*
|
||||
* @method LeanTween.resume
|
||||
* @param {GameObject} gameObject:GameObject GameObject whose tweens you want to resume
|
||||
*/
|
||||
public static void resume(GameObject gameObject)
|
||||
{
|
||||
Transform trans = gameObject.transform;
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].trans == trans)
|
||||
tweens[i].resume();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Test whether or not a tween is paused on a GameObject</summary>
|
||||
*
|
||||
* @method LeanTween.isPaused
|
||||
* @param {GameObject} gameObject:GameObject GameObject that you want to test if it is paused
|
||||
*/
|
||||
public static bool isPaused(GameObject gameObject = null)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (Mathf.Equals(tweens[i].direction, 0f))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Transform trans = gameObject.transform;
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (Mathf.Equals(tweens[i].direction, 0f) && tweens[i].trans == trans)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool isPaused(RectTransform rect)
|
||||
{
|
||||
return isTweening(rect.gameObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Test whether or not a tween is paused or not</summary>
|
||||
*
|
||||
* @method LeanTween.isPaused
|
||||
* @param {GameObject} id:int id of the tween that you want to test if it is paused
|
||||
* @example
|
||||
* int id = LeanTween.moveX(gameObject, 1f, 3f).id;<br />
|
||||
* LeanTween.pause(gameObject);<br />
|
||||
* if(LeanTween.isPaused( id ))<br />
|
||||
*      Debug.Log("I am paused!");<br />
|
||||
*/
|
||||
public static bool isPaused(int uniqueId)
|
||||
{
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
if (backId < 0 || backId >= maxTweens) return false;
|
||||
// Debug.Log("tweens[backId].counter:"+tweens[backId].counter+" backCounter:"+backCounter +" toggle:"+tweens[backId].toggle);
|
||||
if (tweens[backId].counter == backCounter && Mathf.Equals(tweens[i].direction, 0f))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Test whether or not a tween is active on a GameObject</summary>
|
||||
*
|
||||
* @method LeanTween.isTweening
|
||||
* @param {GameObject} gameObject:GameObject GameObject that you want to test if it is tweening
|
||||
*/
|
||||
public static bool isTweening(GameObject gameObject = null)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].toggle)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Transform trans = gameObject.transform;
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].toggle && tweens[i].trans == trans)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool isTweening(RectTransform rect)
|
||||
{
|
||||
return isTweening(rect.gameObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Test whether or not a tween is active or not</summary>
|
||||
*
|
||||
* @method LeanTween.isTweening
|
||||
* @param {GameObject} id:int id of the tween that you want to test if it is tweening
|
||||
* @example
|
||||
* int id = LeanTween.moveX(gameObject, 1f, 3f).id;<br />
|
||||
* if(LeanTween.isTweening( id ))<br />
|
||||
*      Debug.Log("I am tweening!");<br />
|
||||
*/
|
||||
public static bool isTweening(int uniqueId)
|
||||
{
|
||||
int backId = uniqueId & 0xFFFF;
|
||||
int backCounter = uniqueId >> 16;
|
||||
if (backId < 0 || backId >= maxTweens) return false;
|
||||
// Debug.Log("tweens[backId].counter:"+tweens[backId].counter+" backCounter:"+backCounter +" toggle:"+tweens[backId].toggle);
|
||||
if (tweens[backId].counter == backCounter && tweens[backId].toggle)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool isTweening(LTRect ltRect)
|
||||
{
|
||||
for (int i = 0; i <= tweenMaxSearch; i++)
|
||||
{
|
||||
if (tweens[i].toggle && tweens[i]._optional.ltRect == ltRect)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void drawBezierPath(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float arrowSize = 0.0f, Transform arrowTransform = null)
|
||||
{
|
||||
Vector3 last = a;
|
||||
Vector3 p;
|
||||
Vector3 aa = (-a + 3 * (b - c) + d);
|
||||
Vector3 bb = 3 * (a + c) - 6 * b;
|
||||
Vector3 cc = 3 * (b - a);
|
||||
|
||||
float t;
|
||||
|
||||
if (arrowSize > 0.0f)
|
||||
{
|
||||
Vector3 beforePos = arrowTransform.position;
|
||||
Quaternion beforeQ = arrowTransform.rotation;
|
||||
float distanceTravelled = 0f;
|
||||
|
||||
for (float k = 1.0f; k <= 120.0f; k++)
|
||||
{
|
||||
t = k / 120.0f;
|
||||
p = ((aa * t + (bb)) * t + cc) * t + a;
|
||||
Gizmos.DrawLine(last, p);
|
||||
distanceTravelled += (p - last).magnitude;
|
||||
if (distanceTravelled > 1f)
|
||||
{
|
||||
distanceTravelled = distanceTravelled - 1f;
|
||||
/*float deltaY = p.y - last.y;
|
||||
float deltaX = p.x - last.x;
|
||||
float ang = Mathf.Atan(deltaY / deltaX);
|
||||
Vector3 arrow = p + new Vector3( Mathf.Cos(ang+2.5f), Mathf.Sin(ang+2.5f), 0f)*0.5f;
|
||||
Gizmos.DrawLine(p, arrow);
|
||||
arrow = p + new Vector3( Mathf.Cos(ang+-2.5f), Mathf.Sin(ang+-2.5f), 0f)*0.5f;
|
||||
Gizmos.DrawLine(p, arrow);*/
|
||||
|
||||
arrowTransform.position = p;
|
||||
arrowTransform.LookAt(last, Vector3.forward);
|
||||
Vector3 to = arrowTransform.TransformDirection(Vector3.right);
|
||||
// Debug.Log("to:"+to+" tweenEmpty.transform.position:"+arrowTransform.position);
|
||||
Vector3 back = (last - p);
|
||||
back = back.normalized;
|
||||
Gizmos.DrawLine(p, p + (to + back) * arrowSize);
|
||||
to = arrowTransform.TransformDirection(-Vector3.right);
|
||||
Gizmos.DrawLine(p, p + (to + back) * arrowSize);
|
||||
}
|
||||
last = p;
|
||||
}
|
||||
|
||||
arrowTransform.position = beforePos;
|
||||
arrowTransform.rotation = beforeQ;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (float k = 1.0f; k <= 30.0f; k++)
|
||||
{
|
||||
t = k / 30.0f;
|
||||
p = ((aa * t + (bb)) * t + cc) * t + a;
|
||||
Gizmos.DrawLine(last, p);
|
||||
last = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static object logError(string error)
|
||||
{
|
||||
if (throwErrors) Debug.LogError(error); else Debug.Log(error);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LTDescr options(LTDescr seed) { Debug.LogError("error this function is no longer used"); return null; }
|
||||
public static LTDescr options()
|
||||
{
|
||||
init();
|
||||
|
||||
bool found = false;
|
||||
// Debug.Log("Search start");
|
||||
for (j = 0, i = startSearch; j <= maxTweens; i++)
|
||||
{
|
||||
if (j >= maxTweens)
|
||||
return logError("LeanTween - You have run out of available spaces for tweening. To avoid this error increase the number of spaces to available for tweening when you initialize the LeanTween class ex: LeanTween.init( " + (maxTweens * 2) + " );") as LTDescr;
|
||||
if (i >= maxTweens)
|
||||
i = 0;
|
||||
// Debug.Log("searching i:"+i);
|
||||
if (tweens[i].toggle == false)
|
||||
{
|
||||
if (i + 1 > tweenMaxSearch && i + 1 < maxTweens)
|
||||
tweenMaxSearch = i + 1;
|
||||
startSearch = i + 1;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
j++;
|
||||
}
|
||||
if (found == false)
|
||||
logError("no available tween found!");
|
||||
|
||||
// Debug.Log("new tween with i:"+i+" counter:"+tweens[i].counter+" tweenMaxSearch:"+tweenMaxSearch+" tween:"+tweens[i]);
|
||||
tweens[i].reset();
|
||||
|
||||
global_counter++;
|
||||
if (global_counter > 0x8000)
|
||||
global_counter = 0;
|
||||
|
||||
tweens[i].setId((uint)i, global_counter);
|
||||
|
||||
return tweens[i];
|
||||
}
|
||||
|
||||
|
||||
public static GameObject tweenEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
init(maxTweens);
|
||||
return _tweenEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
public static int startSearch = 0;
|
||||
public static LTDescr d;
|
||||
|
||||
private static LTDescr pushNewTween(GameObject gameObject, Vector3 to, float time, LTDescr tween)
|
||||
{
|
||||
init(maxTweens);
|
||||
if (gameObject == null || tween == null)
|
||||
return null;
|
||||
|
||||
tween.trans = gameObject.transform;
|
||||
tween.to = to;
|
||||
tween.time = time;
|
||||
|
||||
if (tween.time <= 0f)
|
||||
tween.updateInternal();
|
||||
//tween.hasPhysics = gameObject.rigidbody!=null;
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
/**
|
||||
* <summary>Play a sequence of images on a Unity UI Object</summary>
|
||||
*
|
||||
* @method LeanTween.play
|
||||
* @param {RectTransform} rectTransform:RectTransform RectTransform that you want to play the sequence of sprites on
|
||||
* @param {Sprite[]} sprites:Sprite[] Sequence of sprites to be played
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween <br />
|
||||
* @example
|
||||
* LeanTween.play(gameObject.GetComponent<RectTransform>(), sprites).setLoopPingPong();
|
||||
*/
|
||||
public static LTDescr play(RectTransform rectTransform, UnityEngine.Sprite[] sprites)
|
||||
{
|
||||
float defaultFrameRate = 0.25f;
|
||||
float time = defaultFrameRate * sprites.Length;
|
||||
return pushNewTween(rectTransform.gameObject, new Vector3((float)sprites.Length - 1.0f, 0, 0), time, options().setCanvasPlaySprite().setSprites(sprites).setRepeat(-1));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* <summary>Retrieve a sequencer object where you can easily chain together tweens and methods one after another</summary>
|
||||
*
|
||||
* @method LeanTween.sequence
|
||||
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
|
||||
* @example
|
||||
* var seq = LeanTween.sequence();<br />
|
||||
* seq.add(1f); // delay everything one second<br />
|
||||
* seq.add( () => { // fire an event before start<br />
|
||||
*  Debug.Log("I have started");<br />
|
||||
* });<br />
|
||||
* seq.add( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br />
|
||||
* seq.add( () => { // fire event after tween<br />
|
||||
*  Debug.Log("We are done now");<br />
|
||||
* });;<br />
|
||||
*/
|
||||
public static LTSeq sequence(bool initSequence = true)
|
||||
{
|
||||
init(maxTweens);
|
||||
// Loop through and find available sequence
|
||||
for (int i = 0; i < sequences.Length; i++)
|
||||
{
|
||||
// Debug.Log("i:" + i + " sequences[i]:" + sequences[i]);
|
||||
if (sequences[i].tween == null || sequences[i].tween.toggle == false)
|
||||
{
|
||||
if (sequences[i].toggle == false)
|
||||
{
|
||||
LTSeq seq = sequences[i];
|
||||
if (initSequence)
|
||||
{
|
||||
seq.init((uint)(i + tweens.Length), global_counter);
|
||||
|
||||
global_counter++;
|
||||
if (global_counter > 0x8000)
|
||||
global_counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
seq.reset();
|
||||
}
|
||||
|
||||
return seq;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Fade a gameobject's material to a certain alpha value.</summary>
|
||||
*
|
||||
* @method LeanTween.alpha
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to fade
|
||||
* @param {float} to:float the final alpha value (0-1)
|
||||
* @param {float} time:float The time with which to fade the object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.alpha(gameObject, 1f, 1f) .setDelay(1f);
|
||||
*/
|
||||
public static LTDescr alpha(GameObject gameObject, float to, float time)
|
||||
{
|
||||
LTDescr lt = pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setAlpha());
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
SpriteRenderer ren = gameObject.GetComponent<SpriteRenderer>();
|
||||
lt.spriteRen = ren;
|
||||
#endif
|
||||
return lt;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Fade a GUI Object</summary>
|
||||
*
|
||||
* @method LeanTween.alpha
|
||||
* @param {LTRect} ltRect:LTRect LTRect that you wish to fade
|
||||
* @param {float} to:float the final alpha value (0-1)
|
||||
* @param {float} time:float The time with which to fade the object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.alpha(ltRect, 1f, 1f) .setEase(LeanTweenType.easeInCirc);
|
||||
*/
|
||||
public static LTDescr alpha(LTRect ltRect, float to, float time)
|
||||
{
|
||||
ltRect.alphaEnabled = true;
|
||||
return pushNewTween(tweenEmpty, new Vector3(to, 0f, 0f), time, options().setGUIAlpha().setRect(ltRect));
|
||||
}
|
||||
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
/**
|
||||
* <summary>Fade a Unity UI Object</summary>
|
||||
*
|
||||
* @method LeanTween.alphaText
|
||||
* @param {RectTransform} rectTransform:RectTransform RectTransform associated with the Text Component you wish to fade
|
||||
* @param {float} to:float the final alpha value (0-1)
|
||||
* @param {float} time:float The time with which to fade the object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.alphaText(gameObject.GetComponent<RectTransform>(), 1f, 1f) .setEase(LeanTweenType.easeInCirc);
|
||||
*/
|
||||
public static LTDescr textAlpha(RectTransform rectTransform, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTransform.gameObject, new Vector3(to, 0, 0), time, options().setTextAlpha());
|
||||
}
|
||||
public static LTDescr alphaText(RectTransform rectTransform, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTransform.gameObject, new Vector3(to, 0, 0), time, options().setTextAlpha());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Fade a Unity UI Canvas Group</summary>
|
||||
*
|
||||
* @method LeanTween.alphaCanvas
|
||||
* @param {RectTransform} rectTransform:RectTransform RectTransform that the CanvasGroup is attached to
|
||||
* @param {float} to:float the final alpha value (0-1)
|
||||
* @param {float} time:float The time with which to fade the object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.alphaCanvas(gameObject.GetComponent<RectTransform>(), 0f, 1f) .setLoopPingPong();
|
||||
*/
|
||||
public static LTDescr alphaCanvas(CanvasGroup canvasGroup, float to, float time)
|
||||
{
|
||||
return pushNewTween(canvasGroup.gameObject, new Vector3(to, 0, 0), time, options().setCanvasGroupAlpha());
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* <summary>This works by tweening the vertex colors directly</summary>
|
||||
<br />
|
||||
Vertex-based coloring is useful because you avoid making a copy of your
|
||||
object's material for each instance that needs a different color.<br />
|
||||
<br />
|
||||
A shader that supports vertex colors is required for it to work
|
||||
(for example the shaders in Mobile/Particles/)
|
||||
*
|
||||
* @method LeanTween.alphaVertex
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to alpha
|
||||
* @param {float} to:float The alpha value you wish to tween to
|
||||
* @param {float} time:float The time with which to delay before calling the function
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr alphaVertex(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0f, 0f), time, options().setAlphaVertex());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Change a gameobject's material to a certain color value</summary>
|
||||
*
|
||||
* @method LeanTween.color
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to change the color
|
||||
* @param {Color} to:Color the final color value ex: Color.Red, new Color(1.0f,1.0f,0.0f,0.8f)
|
||||
* @param {float} time:float The time with which to fade the object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.color(gameObject, Color.yellow, 1f) .setDelay(1f);
|
||||
*/
|
||||
public static LTDescr color(GameObject gameObject, Color to, float time)
|
||||
{
|
||||
LTDescr lt = pushNewTween(gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setColor().setPoint(new Vector3(to.r, to.g, to.b)));
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
SpriteRenderer ren = gameObject.GetComponent<SpriteRenderer>();
|
||||
lt.spriteRen = ren;
|
||||
#endif
|
||||
return lt;
|
||||
}
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
/**
|
||||
* <summary>Change the color a Unity UI Object</summary>
|
||||
*
|
||||
* @method LeanTween.colorText
|
||||
* @param {RectTransform} rectTransform:RectTransform RectTransform attached to the Text Component whose color you want to change
|
||||
* @param {Color} to:Color the final alpha value ex: Color.Red, new Color(1.0f,1.0f,0.0f,0.8f)
|
||||
* @param {float} time:float The time with which to fade the object
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* LeanTween.colorText(gameObject.GetComponent<RectTransform>(), Color.yellow, 1f) .setDelay(1f);
|
||||
*/
|
||||
public static LTDescr textColor(RectTransform rectTransform, Color to, float time)
|
||||
{
|
||||
return pushNewTween(rectTransform.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setTextColor().setPoint(new Vector3(to.r, to.g, to.b)));
|
||||
}
|
||||
public static LTDescr colorText(RectTransform rectTransform, Color to, float time)
|
||||
{
|
||||
return pushNewTween(rectTransform.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setTextColor().setPoint(new Vector3(to.r, to.g, to.b)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* <summary>Call a method after a specified amount of time</summary>
|
||||
*
|
||||
* @method LeanTween.delayedCall
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to associate with this delayed call
|
||||
* @param {float} time:float delay The time you wish to pass before the method is called
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.delayedCall(gameObject, 1f, ()=>{ <br />Debug.Log("I am called one second later!");<br /> }));
|
||||
*/
|
||||
public static LTDescr delayedCall(float delayTime, Action callback)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback));
|
||||
}
|
||||
|
||||
public static LTDescr delayedCall(float delayTime, Action<object> callback)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback));
|
||||
}
|
||||
|
||||
public static LTDescr delayedCall(GameObject gameObject, float delayTime, Action callback)
|
||||
{
|
||||
return pushNewTween(gameObject, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback));
|
||||
}
|
||||
|
||||
public static LTDescr delayedCall(GameObject gameObject, float delayTime, Action<object> callback)
|
||||
{
|
||||
return pushNewTween(gameObject, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback));
|
||||
}
|
||||
|
||||
public static LTDescr destroyAfter(LTRect rect, float delayTime)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, Vector3.zero, delayTime, options().setCallback().setRect(rect).setDestroyOnComplete(true));
|
||||
}
|
||||
|
||||
/*public static LTDescr delayedCall(GameObject gameObject, float delayTime, string callback){
|
||||
return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete( callback ) );
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject to a certain location</summary>
|
||||
*
|
||||
* @method LeanTween.move
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
|
||||
* @param {Vector3} vec:Vector3 to The final positin with which to move to
|
||||
* @param {float} time:float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.move(gameObject, new Vector3(0f,-3f,5f), 2.0f) .setEase( LeanTweenType.easeOutQuad );
|
||||
*/
|
||||
public static LTDescr move(GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, to, time, options().setMove());
|
||||
}
|
||||
public static LTDescr move(GameObject gameObject, Vector2 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to.x, to.y, gameObject.transform.position.z), time, options().setMove());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject along a set of bezier curves</summary>
|
||||
*
|
||||
* @method LeanTween.move
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
|
||||
* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle2,Handle1,Point2,...
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Javascript:</i><br />
|
||||
* LeanTween.move(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
|
||||
* <i>C#:</i><br />
|
||||
* LeanTween.move(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);;<br />
|
||||
*/
|
||||
public static LTDescr move(GameObject gameObject, Vector3[] to, float time)
|
||||
{
|
||||
d = options().setMoveCurved();
|
||||
if (d.optional.path == null)
|
||||
d.optional.path = new LTBezierPath(to);
|
||||
else
|
||||
d.optional.path.setPoints(to);
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
public static LTDescr move(GameObject gameObject, LTBezierPath to, float time)
|
||||
{
|
||||
d = options().setMoveCurved();
|
||||
d.optional.path = to;
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
public static LTDescr move(GameObject gameObject, LTSpline to, float time)
|
||||
{
|
||||
d = options().setMoveSpline();
|
||||
d.optional.spline = to;
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject through a set of points</summary>
|
||||
*
|
||||
* @method LeanTween.moveSpline
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
|
||||
* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd<br />Note: The first and last item just define the angle of the end points, they are not actually used in the spline path itself. If you do not care about the angle you can jus set the first two items and last two items as the same value.
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Javascript:</i><br />
|
||||
* LeanTween.moveSpline(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
|
||||
* <i>C#:</i><br />
|
||||
* LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
|
||||
*/
|
||||
public static LTDescr moveSpline(GameObject gameObject, Vector3[] to, float time)
|
||||
{
|
||||
d = options().setMoveSpline();
|
||||
d.optional.spline = new LTSpline(to);
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject through a set of points</summary>
|
||||
*
|
||||
* @method LeanTween.moveSpline
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
|
||||
* @param {LTSpline} spline:LTSpline pass a pre-existing LTSpline for the object to move along
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Javascript:</i><br />
|
||||
* LeanTween.moveSpline(gameObject, ltSpline, 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
|
||||
* <i>C#:</i><br />
|
||||
* LeanTween.moveSpline(gameObject, ltSpline, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
|
||||
*/
|
||||
public static LTDescr moveSpline(GameObject gameObject, LTSpline to, float time)
|
||||
{
|
||||
d = options().setMoveSpline();
|
||||
d.optional.spline = to;
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject through a set of points, in local space</summary>
|
||||
*
|
||||
* @method LeanTween.moveSplineLocal
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
|
||||
* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Javascript:</i><br />
|
||||
* LeanTween.moveSpline(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
|
||||
* <i>C#:</i><br />
|
||||
* LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
|
||||
*/
|
||||
public static LTDescr moveSplineLocal(GameObject gameObject, Vector3[] to, float time)
|
||||
{
|
||||
d = options().setMoveSplineLocal();
|
||||
d.optional.spline = new LTSpline(to);
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GUI Element to a certain location</summary>
|
||||
*
|
||||
* @method LeanTween.move (GUI)
|
||||
* @param {LTRect} ltRect:LTRect ltRect LTRect object that you wish to move
|
||||
* @param {Vector2} vec:Vector2 to The final position with which to move to (pixel coordinates)
|
||||
* @param {float} time:float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr move(LTRect ltRect, Vector2 to, float time)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, to, time, options().setGUIMove().setRect(ltRect));
|
||||
}
|
||||
|
||||
public static LTDescr moveMargin(LTRect ltRect, Vector2 to, float time)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, to, time, options().setGUIMoveMargin().setRect(ltRect));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject along the x-axis</summary>
|
||||
*
|
||||
* @method LeanTween.moveX
|
||||
* @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to move
|
||||
* @param {float} to:float to The final position with which to move to
|
||||
* @param {float} time:float time The time to complete the move in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr moveX(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setMoveX());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject along the y-axis</summary>
|
||||
*
|
||||
* @method LeanTween.moveY
|
||||
* @param {GameObject} GameObject gameObject Gameobject that you wish to move
|
||||
* @param {float} float to The final position with which to move to
|
||||
* @param {float} float time The time to complete the move in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr moveY(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setMoveY());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject along the z-axis</summary>
|
||||
*
|
||||
* @method LeanTween.moveZ
|
||||
* @param {GameObject} GameObject gameObject Gameobject that you wish to move
|
||||
* @param {float} float to The final position with which to move to
|
||||
* @param {float} float time The time to complete the move in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr moveZ(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setMoveZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject to a certain location relative to the parent transform.</summary>
|
||||
*
|
||||
* @method LeanTween.moveLocal
|
||||
* @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
|
||||
* @param {Vector3} Vector3 to The final positin with which to move to
|
||||
* @param {float} float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr moveLocal(GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, to, time, options().setMoveLocal());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject along a set of bezier curves, in local space</summary>
|
||||
*
|
||||
* @method LeanTween.moveLocal
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
|
||||
* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle1,Handle2,Point2,...
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Javascript:</i><br />
|
||||
* LeanTween.moveLocal(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
|
||||
* <i>C#:</i><br />
|
||||
* LeanTween.moveLocal(gameObject, new Vector3[]{Vector3(0f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,1f)}).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
|
||||
*/
|
||||
public static LTDescr moveLocal(GameObject gameObject, Vector3[] to, float time)
|
||||
{
|
||||
d = options().setMoveCurvedLocal();
|
||||
if (d.optional.path == null)
|
||||
d.optional.path = new LTBezierPath(to);
|
||||
else
|
||||
d.optional.path.setPoints(to);
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
public static LTDescr moveLocalX(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setMoveLocalX());
|
||||
}
|
||||
|
||||
public static LTDescr moveLocalY(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setMoveLocalY());
|
||||
}
|
||||
|
||||
public static LTDescr moveLocalZ(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setMoveLocalZ());
|
||||
}
|
||||
|
||||
public static LTDescr moveLocal(GameObject gameObject, LTBezierPath to, float time)
|
||||
{
|
||||
d = options().setMoveCurvedLocal();
|
||||
d.optional.path = to;
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time)
|
||||
{
|
||||
d = options().setMoveSplineLocal();
|
||||
d.optional.spline = to;
|
||||
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a GameObject to another transform</summary>
|
||||
*
|
||||
* @method LeanTween.move
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
|
||||
* @param {Transform} destination:Transform Transform whose position the tween will finally end on
|
||||
* @param {float} time:float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.move(gameObject, anotherTransform, 2.0f) .setEase( LeanTweenType.easeOutQuad );
|
||||
*/
|
||||
public static LTDescr move(GameObject gameObject, Transform to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, Vector3.zero, time, options().setTo(to).setMoveToTransform());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a GameObject, to values are in passed in degrees</summary>
|
||||
*
|
||||
* @method LeanTween.rotate
|
||||
* @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
|
||||
* @param {Vector3} Vector3 to The final rotation with which to rotate to
|
||||
* @param {float} float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.rotate(cube, new Vector3(180f,30f,0f), 1.5f);
|
||||
*/
|
||||
|
||||
public static LTDescr rotate(GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, to, time, options().setRotate());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a GUI element (using an LTRect object), to a value that is in degrees</summary>
|
||||
*
|
||||
* @method LeanTween.rotate
|
||||
* @param {LTRect} ltRect:LTRect LTRect that you wish to rotate
|
||||
* @param {float} to:float The final rotation with which to rotate to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @param {Array} optional:Array Object Array where you can pass <a href="#optional">optional items</a>.
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* if(GUI.Button(buttonRect.rect, "Rotate"))<br />
|
||||
* LeanTween.rotate( buttonRect4, 150.0f, 1.0f).setEase(LeanTweenType.easeOutElastic);<br />
|
||||
* GUI.matrix = Matrix4x4.identity;<br />
|
||||
*/
|
||||
public static LTDescr rotate(LTRect ltRect, float to, float time)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, new Vector3(to, 0f, 0f), time, options().setGUIRotate().setRect(ltRect));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a GameObject in the objects local space (on the transforms localEulerAngles object)</summary>
|
||||
*
|
||||
* @method LeanTween.rotateLocal
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
|
||||
* @param {Vector3} to:Vector3 The final rotation with which to rotate to
|
||||
* @param {float} time:float The time to complete the rotation in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr rotateLocal(GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, to, time, options().setRotateLocal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate a GameObject only on the X axis <summary>Rotate a GameObject only on the X axis</summary>
|
||||
*
|
||||
* @method LeanTween.rotateX
|
||||
* @param {GameObject} GameObject Gameobject that you wish to rotate
|
||||
* @param {float} to:float The final x-axis rotation with which to rotate
|
||||
* @param {float} time:float The time to complete the rotation in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr rotateX(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setRotateX());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a GameObject only on the Y axis</summary>
|
||||
*
|
||||
* @method LeanTween.rotateY
|
||||
* @param {GameObject} GameObject Gameobject that you wish to rotate
|
||||
* @param {float} to:float The final y-axis rotation with which to rotate
|
||||
* @param {float} time:float The time to complete the rotation in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr rotateY(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setRotateY());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a GameObject only on the Z axis</summary>
|
||||
*
|
||||
* @method LeanTween.rotateZ
|
||||
* @param {GameObject} GameObject Gameobject that you wish to rotate
|
||||
* @param {float} to:float The final z-axis rotation with which to rotate
|
||||
* @param {float} time:float The time to complete the rotation in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr rotateZ(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setRotateZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a GameObject around a certain Axis (the best method to use when you want to rotate beyond 180 degrees)</summary>
|
||||
*
|
||||
* @method LeanTween.rotateAround
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
|
||||
* @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
|
||||
* @param {float} degrees:float the degrees in which to rotate
|
||||
* @param {float} time:float time The time to complete the rotation in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example:</i><br />
|
||||
* LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
|
||||
*/
|
||||
public static LTDescr rotateAround(GameObject gameObject, Vector3 axis, float add, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(add, 0f, 0f), time, options().setAxis(axis).setRotateAround());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a GameObject around a certain Axis in Local Space (the best method to use when you want to rotate beyond 180 degrees) </summary>
|
||||
*
|
||||
* @method LeanTween.rotateAroundLocal
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
|
||||
* @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
|
||||
* @param {float} degrees:float the degrees in which to rotate
|
||||
* @param {float} time:float time The time to complete the rotation in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example:</i><br />
|
||||
* LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
|
||||
*/
|
||||
public static LTDescr rotateAroundLocal(GameObject gameObject, Vector3 axis, float add, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(add, 0f, 0f), time, options().setRotateAroundLocal().setAxis(axis));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Scale a GameObject to a certain size</summary>
|
||||
*
|
||||
* @method LeanTween.scale
|
||||
* @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to scale
|
||||
* @param {Vector3} vec:Vector3 to The size with which to tween to
|
||||
* @param {float} time:float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr scale(GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, to, time, options().setScale());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Scale a GUI Element to a certain width and height</summary>
|
||||
*
|
||||
* @method LeanTween.scale (GUI)
|
||||
* @param {LTRect} LTRect ltRect LTRect object that you wish to move
|
||||
* @param {Vector2} Vector2 to The final width and height to scale to (pixel based)
|
||||
* @param {float} float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* var bRect:LTRect = new LTRect( 0, 0, 100, 50 );<br />
|
||||
* LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 ).setEase(LeanTweenType.easeOutBounce);<br />
|
||||
* function OnGUI(){<br />
|
||||
*   if(GUI.Button(bRect.rect, "Scale")){ }<br />
|
||||
* }<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );<br />
|
||||
* LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f ).setEase(LeanTweenType.easeOutBounce);<br />
|
||||
* void OnGUI(){<br />
|
||||
*   if(GUI.Button(bRect.rect, "Scale")){ }<br />
|
||||
* }<br />
|
||||
*/
|
||||
public static LTDescr scale(LTRect ltRect, Vector2 to, float time)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, to, time, options().setGUIScale().setRect(ltRect));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Scale a GameObject to a certain size along the x-axis only</summary>
|
||||
*
|
||||
* @method LeanTween.scaleX
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
|
||||
* @param {float} scaleTo:float the size with which to scale to
|
||||
* @param {float} time:float the time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr scaleX(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setScaleX());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Scale a GameObject to a certain size along the y-axis only</summary>
|
||||
*
|
||||
* @method LeanTween.scaleY
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
|
||||
* @param {float} scaleTo:float the size with which to scale to
|
||||
* @param {float} time:float the time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr scaleY(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setScaleY());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Scale a GameObject to a certain size along the z-axis only</summary>
|
||||
*
|
||||
* @method LeanTween.scaleZ
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
|
||||
* @param {float} scaleTo:float the size with which to scale to
|
||||
* @param {float} time:float the time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr scaleZ(GameObject gameObject, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setScaleZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween any particular value (float)</summary>
|
||||
*
|
||||
* @method LeanTween.value (float)
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
|
||||
* @param {float} from:float The original value to start the tween from
|
||||
* @param {Vector3} to:float The final float with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( function( val:float ){ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( (float val)=>{ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
*/
|
||||
public static LTDescr value(GameObject gameObject, float from, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setCallback().setFrom(new Vector3(from, 0, 0)));
|
||||
}
|
||||
public static LTDescr value(float from, float to, float time)
|
||||
{
|
||||
return pushNewTween(tweenEmpty, new Vector3(to, 0, 0), time, options().setCallback().setFrom(new Vector3(from, 0, 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween any particular value (Vector2)</summary>
|
||||
*
|
||||
* @method LeanTween.value (Vector2)
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
|
||||
* @param {Vector2} from:Vector2 The original value to start the tween from
|
||||
* @param {Vector3} to:Vector2 The final Vector2 with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* LeanTween.value( gameObject, new Vector2(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( function( val:Vector2 ){ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LeanTween.value( gameObject, new Vector3(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( (Vector2 val)=>{ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
*/
|
||||
public static LTDescr value(GameObject gameObject, Vector2 from, Vector2 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to.x, to.y, 0), time, options().setValue3().setTo(new Vector3(to.x, to.y, 0f)).setFrom(new Vector3(from.x, from.y, 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween any particular value (Vector3)</summary>
|
||||
*
|
||||
* @method LeanTween.value (Vector3)
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
|
||||
* @param {Vector3} from:Vector3 The original value to start the tween from
|
||||
* @param {Vector3} to:Vector3 The final Vector3 with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( function( val:Vector3 ){ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( (Vector3 val)=>{ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
*/
|
||||
public static LTDescr value(GameObject gameObject, Vector3 from, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, to, time, options().setValue3().setFrom(from));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tween any particular value (Color)<summary></summary>
|
||||
*
|
||||
* @method LeanTween.value (Color)
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
|
||||
* @param {Color} from:Color The original value to start the tween from
|
||||
* @param {Color} to:Color The final Color with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( function( val:Color ){ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( (Color val)=>{ <br />
|
||||
*  Debug.Log("tweened val:"+val);<br />
|
||||
* } );<br />
|
||||
*/
|
||||
public static LTDescr value(GameObject gameObject, Color from, Color to, float time)
|
||||
{
|
||||
LTDescr lt = pushNewTween(gameObject, new Vector3(1f, to.a, 0f), time, options().setCallbackColor().setPoint(new Vector3(to.r, to.g, to.b))
|
||||
.setFromColor(from).setHasInitialized(false));
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
SpriteRenderer ren = gameObject.GetComponent<SpriteRenderer>();
|
||||
lt.spriteRen = ren;
|
||||
#endif
|
||||
return lt;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween any particular value, it does not need to be tied to any particular type or GameObject</summary>
|
||||
*
|
||||
* @method LeanTween.value (float)
|
||||
* @param {GameObject} GameObject gameObject GameObject with which to tie the tweening with. This is only used when you need to cancel this tween, it does not actually perform any operations on this gameObject
|
||||
* @param {Action<float>} callOnUpdate:Action<float> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( float val ){ }
|
||||
* @param {float} float from The original value to start the tween from
|
||||
* @param {float} float to The value to end the tween on
|
||||
* @param {float} float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
|
||||
* function updateValueExampleCallback( val:float ){<br />
|
||||
*   Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");<br />
|
||||
* }<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
|
||||
* void updateValueExampleCallback( float val ){<br />
|
||||
*   Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");<br />
|
||||
* }<br />
|
||||
*/
|
||||
|
||||
public static LTDescr value(GameObject gameObject, Action<float> callOnUpdate, float from, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setCallback().setTo(new Vector3(to, 0, 0)).setFrom(new Vector3(from, 0, 0)).setOnUpdate(callOnUpdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tweens any float value, it does not need to be tied to any particular type or GameObject</summary>
|
||||
*
|
||||
* @method LeanTween.value (float)
|
||||
* @param {GameObject} GameObject gameObject GameObject with which to tie the tweening with. This is only used when you need to cancel this tween, it does not actually perform any operations on this gameObject
|
||||
* @param {Action<float, float>} callOnUpdateRatio:Action<float,float> Function that's called every Update frame. It must accept two float values ex: function updateValue( float val, float ratio){ }
|
||||
* @param {float} float from The original value to start the tween from
|
||||
* @param {float} float to The value to end the tween on
|
||||
* @param {float} float time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
|
||||
* function updateValueExampleCallback( val:float, ratio:float ){<br />
|
||||
*   Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);<br />
|
||||
* }<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
|
||||
* void updateValueExampleCallback( float val, float ratio ){<br />
|
||||
*   Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);<br />
|
||||
* }<br />
|
||||
*/
|
||||
|
||||
public static LTDescr value(GameObject gameObject, Action<float, float> callOnUpdateRatio, float from, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setCallback().setTo(new Vector3(to, 0, 0)).setFrom(new Vector3(from, 0, 0)).setOnUpdateRatio(callOnUpdateRatio));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween from one color to another</summary>
|
||||
*
|
||||
* @method LeanTween.value (Color)
|
||||
* @param {GameObject} GameObject gameObject GameObject with which to tie the tweening with. This is only used when you need to cancel this tween, it does not actually perform any operations on this gameObject
|
||||
* @param {Action<Color>} callOnUpdate:Action<Color> The function that is called on every Update frame, this function needs to accept a color value ex: function updateValue( Color val ){ }
|
||||
* @param {Color} Color from The original value to start the tween from
|
||||
* @param {Color} Color to The value to end the tween on
|
||||
* @param {Color} Color time The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example
|
||||
* <i>Example Javascript: </i><br />
|
||||
* LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);<br />
|
||||
* function updateValueExampleCallback( val:Color ){<br />
|
||||
*   Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");<br />
|
||||
* }<br />
|
||||
* <br />
|
||||
* <i>Example C#: </i> <br />
|
||||
* LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);<br />
|
||||
* void updateValueExampleCallback( Color val ){<br />
|
||||
*   Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");<br />
|
||||
* }<br />
|
||||
*/
|
||||
|
||||
public static LTDescr value(GameObject gameObject, Action<Color> callOnUpdate, Color from, Color to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setCallbackColor().setPoint(new Vector3(to.r, to.g, to.b))
|
||||
.setAxis(new Vector3(from.r, from.g, from.b)).setFrom(new Vector3(0.0f, from.a, 0.0f)).setHasInitialized(false).setOnUpdateColor(callOnUpdate));
|
||||
}
|
||||
public static LTDescr value(GameObject gameObject, Action<Color, object> callOnUpdate, Color from, Color to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setCallbackColor().setPoint(new Vector3(to.r, to.g, to.b))
|
||||
.setAxis(new Vector3(from.r, from.g, from.b)).setFrom(new Vector3(0.0f, from.a, 0.0f)).setHasInitialized(false).setOnUpdateColor(callOnUpdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween any particular value (Vector2), this could be used to tween an arbitrary value like offset property</summary>
|
||||
*
|
||||
* @method LeanTween.value (Vector2)
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
|
||||
* @param {Action<Vector2>} callOnUpdate:Action<Vector2> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
|
||||
* @param {float} from:Vector2 The original value to start the tween from
|
||||
* @param {Vector2} to:Vector2 The final Vector3 with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr value(GameObject gameObject, Action<Vector2> callOnUpdate, Vector2 from, Vector2 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to.x, to.y, 0f), time, options().setValue3().setTo(new Vector3(to.x, to.y, 0f)).setFrom(new Vector3(from.x, from.y, 0f)).setOnUpdateVector2(callOnUpdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween any particular value (Vector3), this could be used to tween an arbitrary property that uses a Vector</summary>
|
||||
*
|
||||
* @method LeanTween.value (Vector3)
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
|
||||
* @param {Action<Vector3>} callOnUpdate:Action<Vector3> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
|
||||
* @param {float} from:Vector3 The original value to start the tween from
|
||||
* @param {Vector3} to:Vector3 The final Vector3 with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr value(GameObject gameObject, Action<Vector3> callOnUpdate, Vector3 from, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, to, time, options().setValue3().setTo(to).setFrom(from).setOnUpdateVector3(callOnUpdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Tween any particular value (float)</summary>
|
||||
*
|
||||
* @method LeanTween.value (float,object)
|
||||
* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
|
||||
* @param {Action<float,object>} callOnUpdate:Action<float,object> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val, object obj ){ }
|
||||
* @param {float} from:float The original value to start the tween from
|
||||
* @param {Vector3} to:float The final Vector3 with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
*/
|
||||
public static LTDescr value(GameObject gameObject, Action<float, object> callOnUpdate, float from, float to, float time)
|
||||
{
|
||||
return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setCallback().setTo(new Vector3(to, 0, 0)).setFrom(new Vector3(from, 0, 0)).setOnUpdate(callOnUpdate, gameObject));
|
||||
}
|
||||
|
||||
public static LTDescr delayedSound(AudioClip audio, Vector3 pos, float volume)
|
||||
{
|
||||
//Debug.LogError("Delay sound??");
|
||||
return pushNewTween(tweenEmpty, pos, 0f, options().setDelayedSound().setTo(pos).setFrom(new Vector3(volume, 0, 0)).setAudio(audio));
|
||||
}
|
||||
|
||||
public static LTDescr delayedSound(GameObject gameObject, AudioClip audio, Vector3 pos, float volume)
|
||||
{
|
||||
//Debug.LogError("Delay sound??");
|
||||
return pushNewTween(gameObject, pos, 0f, options().setDelayedSound().setTo(pos).setFrom(new Vector3(volume, 0, 0)).setAudio(audio));
|
||||
}
|
||||
|
||||
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
|
||||
/**
|
||||
* <summary>Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.move (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {Vector3} to:Vector3 The final Vector3 with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.move(gameObject.GetComponent<RectTransform>(), new Vector3(200f,-100f,0f), 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr move(RectTransform rectTrans, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, to, time, options().setCanvasMove().setRect(rectTrans));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a RectTransform object affecting x-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.moveX (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {float} to:float The final x location with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.moveX(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr moveX(RectTransform rectTrans, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasMoveX().setRect(rectTrans));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a RectTransform object affecting y-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.moveY (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {float} to:float The final y location with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.moveY(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr moveY(RectTransform rectTrans, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasMoveY().setRect(rectTrans));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Move a RectTransform object affecting z-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)n</summary>
|
||||
*
|
||||
* @method LeanTween.moveZ (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {float} to:float The final x location with which to tween to
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.moveZ(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr moveZ(RectTransform rectTrans, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasMoveZ().setRect(rectTrans));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.rotate (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {float} to:float The degree with which to rotate the RectTransform
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.rotate(gameObject.GetComponent<RectTransform>(), 90f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr rotate(RectTransform rectTrans, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasRotateAround().setRect(rectTrans).setAxis(Vector3.forward));
|
||||
}
|
||||
|
||||
public static LTDescr rotate(RectTransform rectTrans, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, to, time, options().setCanvasRotateAround().setRect(rectTrans).setAxis(Vector3.forward));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.rotateAround (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {Vector3} axis:Vector3 The axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
|
||||
* @param {float} to:float The degree with which to rotate the RectTransform
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.rotateAround(gameObject.GetComponent<RectTransform>(), Vector3.forward, 90f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr rotateAround(RectTransform rectTrans, Vector3 axis, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasRotateAround().setRect(rectTrans).setAxis(axis));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Rotate a RectTransform object around it's local axis (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.rotateAroundLocal (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {Vector3} axis:Vector3 The local axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
|
||||
* @param {float} to:float The degree with which to rotate the RectTransform
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.rotateAroundLocal(gameObject.GetComponent<RectTransform>(), Vector3.forward, 90f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr rotateAroundLocal(RectTransform rectTrans, Vector3 axis, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasRotateAroundLocal().setRect(rectTrans).setAxis(axis));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Scale a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.scale (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {Vector3} to:Vector3 The final Vector3 with which to tween to (localScale)
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.scale(gameObject.GetComponent<RectTransform>(), gameObject.GetComponent<RectTransform>().localScale*2f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr scale(RectTransform rectTrans, Vector3 to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, to, time, options().setCanvasScale().setRect(rectTrans));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Change the sizeDelta of a RectTransform object (used in Unity Canvas, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.size (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {Vector2} to:Vector2 The final Vector2 the tween will end at for sizeDelta property
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.size(gameObject.GetComponent<RectTransform>(), gameObject.GetComponent<RectTransform>().sizeDelta*2f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr size(RectTransform rectTrans, Vector2 to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, to, time, options().setCanvasSizeDelta().setRect(rectTrans));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Alpha an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.alpha (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {float} to:float The final Vector3 with which to tween to (localScale)
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.alpha(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr alpha(RectTransform rectTrans, float to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasAlpha().setRect(rectTrans));
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Change the Color of an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
|
||||
*
|
||||
* @method LeanTween.alpha (RectTransform)
|
||||
* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
|
||||
* @param {float} to:float The final Vector3 with which to tween to (localScale)
|
||||
* @param {float} time:float The time to complete the tween in
|
||||
* @return {LTDescr} LTDescr an object that distinguishes the tween
|
||||
* @example LeanTween.color(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f);
|
||||
*/
|
||||
public static LTDescr color(RectTransform rectTrans, Color to, float time)
|
||||
{
|
||||
return pushNewTween(rectTrans.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setCanvasColor().setRect(rectTrans).setPoint(new Vector3(to.r, to.g, to.b)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Tweening Functions - Thanks to Robert Penner and GFX47
|
||||
|
||||
public static float tweenOnCurve(LTDescr tweenDescr, float ratioPassed)
|
||||
{
|
||||
// Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed));
|
||||
return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed);
|
||||
}
|
||||
|
||||
public static Vector3 tweenOnCurveVector(LTDescr tweenDescr, float ratioPassed)
|
||||
{
|
||||
return new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed),
|
||||
tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed),
|
||||
tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed));
|
||||
}
|
||||
|
||||
public static float easeOutQuadOpt(float start, float diff, float ratioPassed)
|
||||
{
|
||||
return -diff * ratioPassed * (ratioPassed - 2) + start;
|
||||
}
|
||||
|
||||
public static float easeInQuadOpt(float start, float diff, float ratioPassed)
|
||||
{
|
||||
return diff * ratioPassed * ratioPassed + start;
|
||||
}
|
||||
|
||||
public static float easeInOutQuadOpt(float start, float diff, float ratioPassed)
|
||||
{
|
||||
ratioPassed /= .5f;
|
||||
if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start;
|
||||
ratioPassed--;
|
||||
return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start;
|
||||
}
|
||||
|
||||
public static Vector3 easeInOutQuadOpt(Vector3 start, Vector3 diff, float ratioPassed)
|
||||
{
|
||||
ratioPassed /= .5f;
|
||||
if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start;
|
||||
ratioPassed--;
|
||||
return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start;
|
||||
}
|
||||
|
||||
public static float linear(float start, float end, float val)
|
||||
{
|
||||
return Mathf.Lerp(start, end, val);
|
||||
}
|
||||
|
||||
public static float clerp(float start, float end, float val)
|
||||
{
|
||||
float min = 0.0f;
|
||||
float max = 360.0f;
|
||||
float half = Mathf.Abs((max - min) / 2.0f);
|
||||
float retval = 0.0f;
|
||||
float diff = 0.0f;
|
||||
if ((end - start) < -half)
|
||||
{
|
||||
diff = ((max - start) + end) * val;
|
||||
retval = start + diff;
|
||||
}
|
||||
else if ((end - start) > half)
|
||||
{
|
||||
diff = -((max - end) + start) * val;
|
||||
retval = start + diff;
|
||||
}
|
||||
else retval = start + (end - start) * val;
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static float spring(float start, float end, float val)
|
||||
{
|
||||
val = Mathf.Clamp01(val);
|
||||
val = (Mathf.Sin(val * Mathf.PI * (0.2f + 2.5f * val * val * val)) * Mathf.Pow(1f - val, 2.2f) + val) * (1f + (1.2f * (1f - val)));
|
||||
return start + (end - start) * val;
|
||||
}
|
||||
|
||||
public static float easeInQuad(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return end * val * val + start;
|
||||
}
|
||||
|
||||
public static float easeOutQuad(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return -end * val * (val - 2) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutQuad(float start, float end, float val)
|
||||
{
|
||||
val /= .5f;
|
||||
end -= start;
|
||||
if (val < 1) return end / 2 * val * val + start;
|
||||
val--;
|
||||
return -end / 2 * (val * (val - 2) - 1) + start;
|
||||
}
|
||||
|
||||
|
||||
public static float easeInOutQuadOpt2(float start, float diffBy2, float val, float val2)
|
||||
{
|
||||
val /= .5f;
|
||||
if (val < 1) return diffBy2 * val2 + start;
|
||||
val--;
|
||||
return -diffBy2 * ((val2 - 2) - 1f) + start;
|
||||
}
|
||||
|
||||
public static float easeInCubic(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return end * val * val * val + start;
|
||||
}
|
||||
|
||||
public static float easeOutCubic(float start, float end, float val)
|
||||
{
|
||||
val--;
|
||||
end -= start;
|
||||
return end * (val * val * val + 1) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutCubic(float start, float end, float val)
|
||||
{
|
||||
val /= .5f;
|
||||
end -= start;
|
||||
if (val < 1) return end / 2 * val * val * val + start;
|
||||
val -= 2;
|
||||
return end / 2 * (val * val * val + 2) + start;
|
||||
}
|
||||
|
||||
public static float easeInQuart(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return end * val * val * val * val + start;
|
||||
}
|
||||
|
||||
public static float easeOutQuart(float start, float end, float val)
|
||||
{
|
||||
val--;
|
||||
end -= start;
|
||||
return -end * (val * val * val * val - 1) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutQuart(float start, float end, float val)
|
||||
{
|
||||
val /= .5f;
|
||||
end -= start;
|
||||
if (val < 1) return end / 2 * val * val * val * val + start;
|
||||
val -= 2;
|
||||
return -end / 2 * (val * val * val * val - 2) + start;
|
||||
}
|
||||
|
||||
public static float easeInQuint(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return end * val * val * val * val * val + start;
|
||||
}
|
||||
|
||||
public static float easeOutQuint(float start, float end, float val)
|
||||
{
|
||||
val--;
|
||||
end -= start;
|
||||
return end * (val * val * val * val * val + 1) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutQuint(float start, float end, float val)
|
||||
{
|
||||
val /= .5f;
|
||||
end -= start;
|
||||
if (val < 1) return end / 2 * val * val * val * val * val + start;
|
||||
val -= 2;
|
||||
return end / 2 * (val * val * val * val * val + 2) + start;
|
||||
}
|
||||
|
||||
public static float easeInSine(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return -end * Mathf.Cos(val / 1 * (Mathf.PI / 2)) + end + start;
|
||||
}
|
||||
|
||||
public static float easeOutSine(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return end * Mathf.Sin(val / 1 * (Mathf.PI / 2)) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutSine(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return -end / 2 * (Mathf.Cos(Mathf.PI * val / 1) - 1) + start;
|
||||
}
|
||||
|
||||
public static float easeInExpo(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return end * Mathf.Pow(2, 10 * (val / 1 - 1)) + start;
|
||||
}
|
||||
|
||||
public static float easeOutExpo(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return end * (-Mathf.Pow(2, -10 * val / 1) + 1) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutExpo(float start, float end, float val)
|
||||
{
|
||||
val /= .5f;
|
||||
end -= start;
|
||||
if (val < 1) return end / 2 * Mathf.Pow(2, 10 * (val - 1)) + start;
|
||||
val--;
|
||||
return end / 2 * (-Mathf.Pow(2, -10 * val) + 2) + start;
|
||||
}
|
||||
|
||||
public static float easeInCirc(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
return -end * (Mathf.Sqrt(1 - val * val) - 1) + start;
|
||||
}
|
||||
|
||||
public static float easeOutCirc(float start, float end, float val)
|
||||
{
|
||||
val--;
|
||||
end -= start;
|
||||
return end * Mathf.Sqrt(1 - val * val) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutCirc(float start, float end, float val)
|
||||
{
|
||||
val /= .5f;
|
||||
end -= start;
|
||||
if (val < 1) return -end / 2 * (Mathf.Sqrt(1 - val * val) - 1) + start;
|
||||
val -= 2;
|
||||
return end / 2 * (Mathf.Sqrt(1 - val * val) + 1) + start;
|
||||
}
|
||||
|
||||
public static float easeInBounce(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
float d = 1f;
|
||||
return end - easeOutBounce(0, end, d - val) + start;
|
||||
}
|
||||
|
||||
public static float easeOutBounce(float start, float end, float val)
|
||||
{
|
||||
val /= 1f;
|
||||
end -= start;
|
||||
if (val < (1 / 2.75f))
|
||||
{
|
||||
return end * (7.5625f * val * val) + start;
|
||||
}
|
||||
else if (val < (2 / 2.75f))
|
||||
{
|
||||
val -= (1.5f / 2.75f);
|
||||
return end * (7.5625f * (val) * val + .75f) + start;
|
||||
}
|
||||
else if (val < (2.5 / 2.75))
|
||||
{
|
||||
val -= (2.25f / 2.75f);
|
||||
return end * (7.5625f * (val) * val + .9375f) + start;
|
||||
}
|
||||
else
|
||||
{
|
||||
val -= (2.625f / 2.75f);
|
||||
return end * (7.5625f * (val) * val + .984375f) + start;
|
||||
}
|
||||
}
|
||||
|
||||
public static float easeInOutBounce(float start, float end, float val)
|
||||
{
|
||||
end -= start;
|
||||
float d = 1f;
|
||||
if (val < d / 2) return easeInBounce(0, end, val * 2) * 0.5f + start;
|
||||
else return easeOutBounce(0, end, val * 2 - d) * 0.5f + end * 0.5f + start;
|
||||
}
|
||||
|
||||
public static float easeInBack(float start, float end, float val, float overshoot = 1.0f)
|
||||
{
|
||||
end -= start;
|
||||
val /= 1;
|
||||
float s = 1.70158f * overshoot;
|
||||
return end * (val) * val * ((s + 1) * val - s) + start;
|
||||
}
|
||||
|
||||
public static float easeOutBack(float start, float end, float val, float overshoot = 1.0f)
|
||||
{
|
||||
float s = 1.70158f * overshoot;
|
||||
end -= start;
|
||||
val = (val / 1) - 1;
|
||||
return end * ((val) * val * ((s + 1) * val + s) + 1) + start;
|
||||
}
|
||||
|
||||
public static float easeInOutBack(float start, float end, float val, float overshoot = 1.0f)
|
||||
{
|
||||
float s = 1.70158f * overshoot;
|
||||
end -= start;
|
||||
val /= .5f;
|
||||
if ((val) < 1)
|
||||
{
|
||||
s *= (1.525f) * overshoot;
|
||||
return end / 2 * (val * val * (((s) + 1) * val - s)) + start;
|
||||
}
|
||||
val -= 2;
|
||||
s *= (1.525f) * overshoot;
|
||||
return end / 2 * ((val) * val * (((s) + 1) * val + s) + 2) + start;
|
||||
}
|
||||
|
||||
public static float easeInElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f)
|
||||
{
|
||||
end -= start;
|
||||
|
||||
float p = period;
|
||||
float s = 0f;
|
||||
float a = 0f;
|
||||
|
||||
if (val == 0f) return start;
|
||||
|
||||
if (val == 1f) return start + end;
|
||||
|
||||
if (a == 0f || a < Mathf.Abs(end))
|
||||
{
|
||||
a = end;
|
||||
s = p / 4f;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
|
||||
}
|
||||
|
||||
if (overshoot > 1f && val > 0.6f)
|
||||
overshoot = 1f + ((1f - val) / 0.4f * (overshoot - 1f));
|
||||
// Debug.Log("ease in elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
|
||||
|
||||
val = val - 1f;
|
||||
return start - (a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
|
||||
}
|
||||
|
||||
public static float easeOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f)
|
||||
{
|
||||
end -= start;
|
||||
|
||||
float p = period;
|
||||
float s = 0f;
|
||||
float a = 0f;
|
||||
|
||||
if (val == 0f) return start;
|
||||
|
||||
// Debug.Log("ease out elastic val:"+val+" a:"+a);
|
||||
if (val == 1f) return start + end;
|
||||
|
||||
if (a == 0f || a < Mathf.Abs(end))
|
||||
{
|
||||
a = end;
|
||||
s = p / 4f;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
|
||||
}
|
||||
if (overshoot > 1f && val < 0.4f)
|
||||
overshoot = 1f + (val / 0.4f * (overshoot - 1f));
|
||||
// Debug.Log("ease out elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
|
||||
|
||||
return start + end + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * overshoot;
|
||||
}
|
||||
|
||||
public static float easeInOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f)
|
||||
{
|
||||
end -= start;
|
||||
|
||||
float p = period;
|
||||
float s = 0f;
|
||||
float a = 0f;
|
||||
|
||||
if (val == 0f) return start;
|
||||
|
||||
val = val / (1f / 2f);
|
||||
if (val == 2f) return start + end;
|
||||
|
||||
if (a == 0f || a < Mathf.Abs(end))
|
||||
{
|
||||
a = end;
|
||||
s = p / 4f;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
|
||||
}
|
||||
|
||||
if (overshoot > 1f)
|
||||
{
|
||||
if (val < 0.2f)
|
||||
{
|
||||
overshoot = 1f + (val / 0.2f * (overshoot - 1f));
|
||||
}
|
||||
else if (val > 0.8f)
|
||||
{
|
||||
overshoot = 1f + ((1f - val) / 0.2f * (overshoot - 1f));
|
||||
}
|
||||
}
|
||||
|
||||
if (val < 1f)
|
||||
{
|
||||
val = val - 1f;
|
||||
return start - 0.5f * (a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
|
||||
}
|
||||
val = val - 1f;
|
||||
return end + start + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * 0.5f * overshoot;
|
||||
}
|
||||
|
||||
// Mark: LeanTween Following
|
||||
|
||||
/**
|
||||
* <summary>Follow another transforms position/scale/color with a damp transition (eases in and out to destination with no overshoot)</summary>
|
||||
*
|
||||
* @method LeanTween.followDamp
|
||||
* @param {Transform} transform:Transform the transform you wish to be the follower
|
||||
* @param {Transform} transform:Transform the transform you wish to follow
|
||||
* @param {LeanProp} leanProp:LeanProp enum of the type of following you wish to do position, scale, color, etc.
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} [maxSpeed]:float maximum speed at which it moves towards the destination
|
||||
* @example
|
||||
* LeanTween.followDamp(transform, followTransform, LeanProp.localY, 1.1f);
|
||||
*/
|
||||
public static LTDescr followDamp(Transform trans, Transform target, LeanProp prop, float smoothTime, float maxSpeed = -1f)
|
||||
{
|
||||
var d = pushNewTween(trans.gameObject, Vector3.zero, float.MaxValue, options().setFollow().setTarget(target));
|
||||
|
||||
switch (prop)
|
||||
{
|
||||
case LeanProp.localPosition:
|
||||
d.optional.axis = d.trans.localPosition;
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.optional.axis = LeanSmooth.damp(d.optional.axis, d.toTrans.localPosition, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime);
|
||||
d.trans.localPosition = d.optional.axis + d.toInternal;
|
||||
}; break;
|
||||
case LeanProp.position:
|
||||
d.diff = d.trans.position;
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.optional.axis = LeanSmooth.damp(d.optional.axis, d.toTrans.position, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime);
|
||||
d.trans.position = d.optional.axis + d.toInternal;
|
||||
}; break;
|
||||
case LeanProp.localX:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosX(LeanSmooth.damp(d.trans.localPosition.x, d.toTrans.localPosition.x, ref d.fromInternal.x, smoothTime, maxSpeed, Time.deltaTime));
|
||||
}; break;
|
||||
case LeanProp.localY:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosY(LeanSmooth.damp(d.trans.localPosition.y, d.toTrans.localPosition.y, ref d.fromInternal.y, smoothTime, maxSpeed, Time.deltaTime));
|
||||
}; break;
|
||||
case LeanProp.localZ:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosZ(LeanSmooth.damp(d.trans.localPosition.z, d.toTrans.localPosition.z, ref d.fromInternal.z, smoothTime, maxSpeed, Time.deltaTime));
|
||||
}; break;
|
||||
case LeanProp.x:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosX(LeanSmooth.damp(d.trans.position.x, d.toTrans.position.x, ref d.fromInternal.x, smoothTime, maxSpeed, Time.deltaTime));
|
||||
}; break;
|
||||
case LeanProp.y:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosY(LeanSmooth.damp(d.trans.position.y, d.toTrans.position.y, ref d.fromInternal.y, smoothTime, maxSpeed, Time.deltaTime));
|
||||
}; break;
|
||||
case LeanProp.z:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosZ(LeanSmooth.damp(d.trans.position.z, d.toTrans.position.z, ref d.fromInternal.z, smoothTime, maxSpeed, Time.deltaTime));
|
||||
}; break;
|
||||
case LeanProp.scale:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.localScale = LeanSmooth.damp(d.trans.localScale, d.toTrans.localScale, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime);
|
||||
}; break;
|
||||
case LeanProp.color:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
var col = LeanSmooth.damp(d.trans.LeanColor(), d.toTrans.LeanColor(), ref d.optional.color, smoothTime, maxSpeed, Time.deltaTime);
|
||||
d.trans.GetComponent<Renderer>().material.color = col;
|
||||
}; break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Follow another transforms position/scale/color with a springy transition (eases in and out to destination with possible overshoot bounciness)</summary>
|
||||
*
|
||||
* @method LeanTween.followSpring
|
||||
* @param {Transform} transform:Transform the transform you wish to be the follower
|
||||
* @param {Transform} transform:Transform the transform you wish to follow
|
||||
* @param {LeanProp} leanProp:LeanProp enum of the type of following you wish to do position, scale, color, etc.
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} [maxSpeed]:float maximum speed at which it moves towards the destination
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @example
|
||||
* LeanTween.followSpring(transform, followTransform, LeanProp.localY);
|
||||
*/
|
||||
public static LTDescr followSpring(Transform trans, Transform target, LeanProp prop, float smoothTime, float maxSpeed = -1f, float friction = 2f, float accelRate = 0.5f)
|
||||
{
|
||||
var d = pushNewTween(trans.gameObject, Vector3.zero, float.MaxValue, options().setFollow().setTarget(target));
|
||||
switch (prop)
|
||||
{
|
||||
case LeanProp.localPosition:
|
||||
d.optional.axis = d.trans.localPosition;
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.optional.axis = LeanSmooth.spring(d.optional.axis, d.toTrans.localPosition, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate);
|
||||
d.trans.localPosition = d.optional.axis + d.toInternal;
|
||||
}; break;
|
||||
case LeanProp.position:
|
||||
d.diff = d.trans.position;
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.diff = LeanSmooth.spring(d.diff, d.toTrans.position, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate);
|
||||
d.trans.position = d.diff;// + d.toInternal;
|
||||
}; break;
|
||||
case LeanProp.localX:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosX(LeanSmooth.spring(d.trans.localPosition.x, d.toTrans.localPosition.x, ref d.fromInternal.x, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate));
|
||||
}; break;
|
||||
case LeanProp.localY:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosY(LeanSmooth.spring(d.trans.localPosition.y, d.toTrans.localPosition.y, ref d.fromInternal.y, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate));
|
||||
}; break;
|
||||
case LeanProp.localZ:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosZ(LeanSmooth.spring(d.trans.localPosition.z, d.toTrans.localPosition.z, ref d.fromInternal.z, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate));
|
||||
}; break;
|
||||
case LeanProp.x:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosX(LeanSmooth.spring(d.trans.position.x, d.toTrans.position.x, ref d.fromInternal.x, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate));
|
||||
}; break;
|
||||
case LeanProp.y:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosY(LeanSmooth.spring(d.trans.position.y, d.toTrans.position.y, ref d.fromInternal.y, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate));
|
||||
}; break;
|
||||
case LeanProp.z:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosZ(LeanSmooth.spring(d.trans.position.z, d.toTrans.position.z, ref d.fromInternal.z, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate));
|
||||
}; break;
|
||||
case LeanProp.scale:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.localScale = LeanSmooth.spring(d.trans.localScale, d.toTrans.localScale, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate);
|
||||
}; break;
|
||||
case LeanProp.color:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
var col = LeanSmooth.spring(d.trans.LeanColor(), d.toTrans.LeanColor(), ref d.optional.color, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate);
|
||||
d.trans.GetComponent<Renderer>().material.color = col;
|
||||
}; break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Follow another transforms position/scale/color (with an ease that bounces back some when it reaches it's destination)</summary>
|
||||
*
|
||||
* @method LeanTween.followBounceOut
|
||||
* @param {Transform} transform:Transform the transform you wish to be the follower
|
||||
* @param {Transform} transform:Transform the transform you wish to follow
|
||||
* @param {LeanProp} leanProp:LeanProp enum of the type of following you wish to do position, scale, color, etc.
|
||||
* @param {float} smoothTime:float roughly the time it takes to reach the destination
|
||||
* @param {float} [maxSpeed]:float maximum speed at which it moves towards the destination
|
||||
* @param {float} [friction]:float rate at which the spring is slowed down once it reaches it's destination
|
||||
* @param {float} [accelRate]:float the rate it accelerates from it's initial position
|
||||
* @param {float} [hitDamp]:float the rate at which to dampen the bounciness of when it reaches it's destination
|
||||
* @example
|
||||
* LeanTween.followBounceOut(transform, followTransform, LeanProp.localY, 1.1f);
|
||||
*/
|
||||
public static LTDescr followBounceOut(Transform trans, Transform target, LeanProp prop, float smoothTime, float maxSpeed = -1f, float friction = 2f, float accelRate = 0.5f, float hitDamping = 0.9f)
|
||||
{
|
||||
var d = pushNewTween(trans.gameObject, Vector3.zero, float.MaxValue, options().setFollow().setTarget(target));
|
||||
switch (prop)
|
||||
{
|
||||
case LeanProp.localPosition:
|
||||
d.optional.axis = d.trans.localPosition;
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.optional.axis = LeanSmooth.bounceOut(d.optional.axis, d.toTrans.localPosition, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping);
|
||||
d.trans.localPosition = d.optional.axis + d.toInternal;
|
||||
}; break;
|
||||
case LeanProp.position:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.optional.axis = LeanSmooth.bounceOut(d.optional.axis, d.toTrans.position, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping);
|
||||
d.trans.position = d.optional.axis + d.toInternal;
|
||||
}; break;
|
||||
case LeanProp.localX:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosX(LeanSmooth.bounceOut(d.trans.localPosition.x, d.toTrans.localPosition.x, ref d.fromInternal.x, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping));
|
||||
}; break;
|
||||
case LeanProp.localY:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosY(LeanSmooth.bounceOut(d.trans.localPosition.y, d.toTrans.localPosition.y, ref d.fromInternal.y, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping));
|
||||
}; break;
|
||||
case LeanProp.localZ:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosZ(LeanSmooth.bounceOut(d.trans.localPosition.z, d.toTrans.localPosition.z, ref d.fromInternal.z, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping));
|
||||
}; break;
|
||||
case LeanProp.x:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosX(LeanSmooth.bounceOut(d.trans.position.x, d.toTrans.position.x, ref d.fromInternal.x, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping));
|
||||
}; break;
|
||||
case LeanProp.y:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosY(LeanSmooth.bounceOut(d.trans.position.y, d.toTrans.position.y, ref d.fromInternal.y, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping));
|
||||
}; break;
|
||||
case LeanProp.z:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosZ(LeanSmooth.bounceOut(d.trans.position.z, d.toTrans.position.z, ref d.fromInternal.z, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping));
|
||||
}; break;
|
||||
case LeanProp.scale:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.localScale = LeanSmooth.bounceOut(d.trans.localScale, d.toTrans.localScale, ref d.fromInternal, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping);
|
||||
}; break;
|
||||
case LeanProp.color:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
var col = LeanSmooth.bounceOut(d.trans.LeanColor(), d.toTrans.LeanColor(), ref d.optional.color, smoothTime, maxSpeed, Time.deltaTime, friction, accelRate, hitDamping);
|
||||
d.trans.GetComponent<Renderer>().material.color = col;
|
||||
}; break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Follow another transforms position/scale/color with a constant speed</summary>
|
||||
*
|
||||
* @method LeanTween.followLinear
|
||||
* @param {Transform} transform:Transform the transform you wish to be the follower
|
||||
* @param {Transform} transform:Transform the transform you wish to follow
|
||||
* @param {LeanProp} leanProp:LeanProp enum of the type of following you wish to do position, scale, color, etc.
|
||||
* @param {float} moveSpeed:float roughly the time it takes to reach the destination
|
||||
* @example
|
||||
* LeanTween.followLinear(transform, followTransform, LeanProp.localY, 50f);
|
||||
*/
|
||||
public static LTDescr followLinear(Transform trans, Transform target, LeanProp prop, float moveSpeed)
|
||||
{
|
||||
var d = pushNewTween(trans.gameObject, Vector3.zero, float.MaxValue, options().setFollow().setTarget(target));
|
||||
switch (prop)
|
||||
{
|
||||
case LeanProp.localPosition:
|
||||
d.optional.axis = d.trans.localPosition;
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.optional.axis = LeanSmooth.linear(d.optional.axis, d.toTrans.localPosition, moveSpeed);
|
||||
d.trans.localPosition = d.optional.axis + d.toInternal;
|
||||
}; break;
|
||||
case LeanProp.position:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.position = LeanSmooth.linear(d.trans.position, d.toTrans.position, moveSpeed);
|
||||
}; break;
|
||||
case LeanProp.localX:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosX(LeanSmooth.linear(d.trans.localPosition.x, d.toTrans.localPosition.x, moveSpeed));
|
||||
}; break;
|
||||
case LeanProp.localY:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosY(LeanSmooth.linear(d.trans.localPosition.y, d.toTrans.localPosition.y, moveSpeed));
|
||||
}; break;
|
||||
case LeanProp.localZ:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetLocalPosZ(LeanSmooth.linear(d.trans.localPosition.z, d.toTrans.localPosition.z, moveSpeed));
|
||||
}; break;
|
||||
case LeanProp.x:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosX(LeanSmooth.linear(d.trans.position.x, d.toTrans.position.x, moveSpeed));
|
||||
}; break;
|
||||
case LeanProp.y:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosY(LeanSmooth.linear(d.trans.position.y, d.toTrans.position.y, moveSpeed));
|
||||
}; break;
|
||||
case LeanProp.z:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.LeanSetPosZ(LeanSmooth.linear(d.trans.position.z, d.toTrans.position.z, moveSpeed));
|
||||
}; break;
|
||||
case LeanProp.scale:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
d.trans.localScale = LeanSmooth.linear(d.trans.localScale, d.toTrans.localScale, moveSpeed);
|
||||
}; break;
|
||||
case LeanProp.color:
|
||||
d.easeInternal = () =>
|
||||
{
|
||||
var col = LeanSmooth.linear(d.trans.LeanColor(), d.toTrans.LeanColor(), moveSpeed);
|
||||
d.trans.GetComponent<Renderer>().material.color = col;
|
||||
}; break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
// LeanTween Listening/Dispatch
|
||||
|
||||
private static System.Action<LTEvent>[] eventListeners;
|
||||
private static GameObject[] goListeners;
|
||||
private static int eventsMaxSearch = 0;
|
||||
public static int EVENTS_MAX = 10;
|
||||
public static int LISTENERS_MAX = 10;
|
||||
private static int INIT_LISTENERS_MAX = LISTENERS_MAX;
|
||||
|
||||
public static void addListener(int eventId, System.Action<LTEvent> callback)
|
||||
{
|
||||
addListener(tweenEmpty, eventId, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener method to be called when the appropriate LeanTween.dispatchEvent is called
|
||||
*
|
||||
* @method LeanTween.addListener
|
||||
* @param {GameObject} caller:GameObject the gameObject the listener is attached to
|
||||
* @param {int} eventId:int a unique int that describes the event (best to use an enum)
|
||||
* @param {System.Action<LTEvent>} callback:System.Action<LTEvent> the method to call when the event has been dispatched
|
||||
* @example
|
||||
* LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp);<br />
|
||||
* <br />
|
||||
* void jumpUp( LTEvent e ){ Debug.Log("jump!"); }<br />
|
||||
*/
|
||||
public static void addListener(GameObject caller, int eventId, System.Action<LTEvent> callback)
|
||||
{
|
||||
if (eventListeners == null)
|
||||
{
|
||||
INIT_LISTENERS_MAX = LISTENERS_MAX;
|
||||
eventListeners = new System.Action<LTEvent>[EVENTS_MAX * LISTENERS_MAX];
|
||||
goListeners = new GameObject[EVENTS_MAX * LISTENERS_MAX];
|
||||
}
|
||||
// Debug.Log("searching for an empty space for:"+caller + " eventid:"+event);
|
||||
for (i = 0; i < INIT_LISTENERS_MAX; i++)
|
||||
{
|
||||
int point = eventId * INIT_LISTENERS_MAX + i;
|
||||
if (goListeners[point] == null || eventListeners[point] == null)
|
||||
{
|
||||
eventListeners[point] = callback;
|
||||
goListeners[point] = caller;
|
||||
if (i >= eventsMaxSearch)
|
||||
eventsMaxSearch = i + 1;
|
||||
// Debug.Log("adding event for:"+caller.name);
|
||||
|
||||
return;
|
||||
}
|
||||
#if UNITY_FLASH
|
||||
if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback)){
|
||||
// Debug.Log("This event is already being listened for.");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (goListeners[point] == caller && System.Object.Equals(eventListeners[point], callback))
|
||||
{
|
||||
// Debug.Log("This event is already being listened for.");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Debug.LogError("You ran out of areas to add listeners, consider increasing LISTENERS_MAX, ex: LeanTween.LISTENERS_MAX = " + (LISTENERS_MAX * 2));
|
||||
}
|
||||
|
||||
public static bool removeListener(int eventId, System.Action<LTEvent> callback)
|
||||
{
|
||||
return removeListener(tweenEmpty, eventId, callback);
|
||||
}
|
||||
|
||||
public static bool removeListener(int eventId)
|
||||
{
|
||||
int point = eventId * INIT_LISTENERS_MAX + i;
|
||||
eventListeners[point] = null;
|
||||
goListeners[point] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an event listener you have added
|
||||
* @method LeanTween.removeListener
|
||||
* @param {GameObject} caller:GameObject the gameObject the listener is attached to
|
||||
* @param {int} eventId:int a unique int that describes the event (best to use an enum)
|
||||
* @param {System.Action<LTEvent>} callback:System.Action<LTEvent> the method that was specified to call when the event has been dispatched
|
||||
* @example
|
||||
* LeanTween.removeListener(gameObject, (int)MyEvents.JUMP, jumpUp);<br />
|
||||
* <br />
|
||||
* void jumpUp( LTEvent e ){ }<br />
|
||||
*/
|
||||
public static bool removeListener(GameObject caller, int eventId, System.Action<LTEvent> callback)
|
||||
{
|
||||
for (i = 0; i < eventsMaxSearch; i++)
|
||||
{
|
||||
int point = eventId * INIT_LISTENERS_MAX + i;
|
||||
#if UNITY_FLASH
|
||||
if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback) ){
|
||||
#else
|
||||
if (goListeners[point] == caller && System.Object.Equals(eventListeners[point], callback))
|
||||
{
|
||||
#endif
|
||||
eventListeners[point] = null;
|
||||
goListeners[point] = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the added listeners that you are dispatching the event
|
||||
* @method LeanTween.dispatchEvent
|
||||
* @param {int} eventId:int a unique int that describes the event (best to use an enum)
|
||||
* @example
|
||||
* LeanTween.dispatchEvent( (int)MyEvents.JUMP );<br />
|
||||
*/
|
||||
public static void dispatchEvent(int eventId)
|
||||
{
|
||||
dispatchEvent(eventId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the added listeners that you are dispatching the event
|
||||
* @method LeanTween.dispatchEvent
|
||||
* @param {int} eventId:int a unique int that describes the event (best to use an enum)
|
||||
* @param {object} data:object Pass data to the listener, access it from the listener with *.data on the LTEvent object
|
||||
* @example
|
||||
* LeanTween.dispatchEvent( (int)MyEvents.JUMP, transform );<br />
|
||||
* <br />
|
||||
* void jumpUp( LTEvent e ){<br />
|
||||
*   Transform tran = (Transform)e.data;<br />
|
||||
* }<br />
|
||||
*/
|
||||
public static void dispatchEvent(int eventId, object data)
|
||||
{
|
||||
for (int k = 0; k < eventsMaxSearch; k++)
|
||||
{
|
||||
int point = eventId * INIT_LISTENERS_MAX + k;
|
||||
if (eventListeners[point] != null)
|
||||
{
|
||||
if (goListeners[point])
|
||||
{
|
||||
eventListeners[point](new LTEvent(eventId, data));
|
||||
}
|
||||
else
|
||||
{
|
||||
eventListeners[point] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // End LeanTween class
|
||||
|
||||
public class LTUtility
|
||||
{
|
||||
|
||||
public static Vector3[] reverse(Vector3[] arr)
|
||||
{
|
||||
int length = arr.Length;
|
||||
int left = 0;
|
||||
int right = length - 1;
|
||||
|
||||
for (; left < right; left += 1, right -= 1)
|
||||
{
|
||||
Vector3 temporary = arr[left];
|
||||
arr[left] = arr[right];
|
||||
arr[right] = temporary;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
|
||||
public class LTBezier
|
||||
{
|
||||
public float length;
|
||||
|
||||
private Vector3 a;
|
||||
private Vector3 aa;
|
||||
private Vector3 bb;
|
||||
private Vector3 cc;
|
||||
private float len;
|
||||
private float[] arcLengths;
|
||||
|
||||
public LTBezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float precision)
|
||||
{
|
||||
this.a = a;
|
||||
aa = (-a + 3 * (b - c) + d);
|
||||
bb = 3 * (a + c) - 6 * b;
|
||||
cc = 3 * (b - a);
|
||||
|
||||
this.len = 1.0f / precision;
|
||||
arcLengths = new float[(int)this.len + (int)1];
|
||||
arcLengths[0] = 0;
|
||||
|
||||
Vector3 ov = a;
|
||||
Vector3 v;
|
||||
float clen = 0.0f;
|
||||
for (int i = 1; i <= this.len; i++)
|
||||
{
|
||||
v = bezierPoint(i * precision);
|
||||
clen += (ov - v).magnitude;
|
||||
this.arcLengths[i] = clen;
|
||||
ov = v;
|
||||
}
|
||||
this.length = clen;
|
||||
}
|
||||
|
||||
private float map(float u)
|
||||
{
|
||||
float targetLength = u * this.arcLengths[(int)this.len];
|
||||
int low = 0;
|
||||
int high = (int)this.len;
|
||||
int index = 0;
|
||||
while (low < high)
|
||||
{
|
||||
index = low + ((int)((high - low) / 2.0f) | 0);
|
||||
if (this.arcLengths[index] < targetLength)
|
||||
{
|
||||
low = index + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
high = index;
|
||||
}
|
||||
}
|
||||
if (this.arcLengths[index] > targetLength)
|
||||
index--;
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
|
||||
return (index + (targetLength - arcLengths[index]) / (arcLengths[index + 1] - arcLengths[index])) / this.len;
|
||||
}
|
||||
|
||||
private Vector3 bezierPoint(float t)
|
||||
{
|
||||
return ((aa * t + (bb)) * t + cc) * t + a;
|
||||
}
|
||||
|
||||
public Vector3 point(float t)
|
||||
{
|
||||
return bezierPoint(map(t));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually animate along a bezier path with this class
|
||||
* @class LTBezierPath
|
||||
* @constructor
|
||||
* @param {Vector3 Array} pts A set of points that define one or many bezier paths (the paths should be passed in multiples of 4, which correspond to each individual bezier curve)<br />
|
||||
* It goes in the order: <strong>startPoint</strong>,endControl,startControl,<strong>endPoint</strong> - <strong>Note:</strong> the control for the end and start are reversed! This is just a *quirk* of the API.<br />
|
||||
* <img src="http://dentedpixel.com/assets/LTBezierExplanation.gif" width="413" height="196" style="margin-top:10px" />
|
||||
* @example
|
||||
* LTBezierPath ltPath = new LTBezierPath( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(1f,0f,0f), new Vector3(1f,0f,0f), new Vector3(1f,1f,0f)} );<br /><br />
|
||||
* LeanTween.move(lt, ltPath.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate <br />
|
||||
* Vector3 pt = ltPath.point( 0.6f ); // retrieve a point along the path
|
||||
*/
|
||||
public class LTBezierPath
|
||||
{
|
||||
public Vector3[] pts;
|
||||
public float length;
|
||||
public bool orientToPath;
|
||||
public bool orientToPath2d;
|
||||
|
||||
private LTBezier[] beziers;
|
||||
private float[] lengthRatio;
|
||||
private int currentBezier = 0, previousBezier = 0;
|
||||
|
||||
public LTBezierPath() { }
|
||||
public LTBezierPath(Vector3[] pts_)
|
||||
{
|
||||
setPoints(pts_);
|
||||
}
|
||||
|
||||
public void setPoints(Vector3[] pts_)
|
||||
{
|
||||
if (pts_.Length < 4)
|
||||
LeanTween.logError("LeanTween - When passing values for a vector path, you must pass four or more values!");
|
||||
if (pts_.Length % 4 != 0)
|
||||
LeanTween.logError("LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2...");
|
||||
|
||||
pts = pts_;
|
||||
|
||||
int k = 0;
|
||||
beziers = new LTBezier[pts.Length / 4];
|
||||
lengthRatio = new float[beziers.Length];
|
||||
int i;
|
||||
length = 0;
|
||||
for (i = 0; i < pts.Length; i += 4)
|
||||
{
|
||||
beziers[k] = new LTBezier(pts[i + 0], pts[i + 2], pts[i + 1], pts[i + 3], 0.05f);
|
||||
length += beziers[k].length;
|
||||
k++;
|
||||
}
|
||||
// Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers);
|
||||
for (i = 0; i < beziers.Length; i++)
|
||||
{
|
||||
lengthRatio[i] = beziers[i].length / length;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {float} distance distance of the path (in unity units)
|
||||
*/
|
||||
public float distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Retrieve a point along a path</summary>
|
||||
*
|
||||
* @method point
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @return {Vector3} Vector3 position of the point along the path
|
||||
* @example
|
||||
* transform.position = ltPath.point( 0.6f );
|
||||
*/
|
||||
public Vector3 point(float ratio)
|
||||
{
|
||||
float added = 0.0f;
|
||||
for (int i = 0; i < lengthRatio.Length; i++)
|
||||
{
|
||||
added += lengthRatio[i];
|
||||
if (added >= ratio)
|
||||
return beziers[i].point((ratio - (added - lengthRatio[i])) / lengthRatio[i]);
|
||||
}
|
||||
return beziers[lengthRatio.Length - 1].point(1.0f);
|
||||
}
|
||||
|
||||
public void place2d(Transform transform, float ratio)
|
||||
{
|
||||
transform.position = point(ratio);
|
||||
ratio += 0.001f;
|
||||
if (ratio <= 1.0f)
|
||||
{
|
||||
Vector3 v3Dir = point(ratio) - transform.position;
|
||||
float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
|
||||
transform.eulerAngles = new Vector3(0, 0, angle);
|
||||
}
|
||||
}
|
||||
|
||||
public void placeLocal2d(Transform transform, float ratio)
|
||||
{
|
||||
transform.localPosition = point(ratio);
|
||||
ratio += 0.001f;
|
||||
if (ratio <= 1.0f)
|
||||
{
|
||||
Vector3 v3Dir = point(ratio) - transform.localPosition;
|
||||
float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
|
||||
transform.localEulerAngles = new Vector3(0, 0, angle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Place an object along a certain point on the path (facing the direction perpendicular to the path)</summary>
|
||||
*
|
||||
* @method place
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @example
|
||||
* ltPath.place( transform, 0.6f );
|
||||
*/
|
||||
public void place(Transform transform, float ratio)
|
||||
{
|
||||
place(transform, ratio, Vector3.up);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path</summary>
|
||||
*
|
||||
* @method place
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
|
||||
* @example
|
||||
* ltPath.place( transform, 0.6f, Vector3.left );
|
||||
*/
|
||||
public void place(Transform transform, float ratio, Vector3 worldUp)
|
||||
{
|
||||
transform.position = point(ratio);
|
||||
ratio += 0.001f;
|
||||
if (ratio <= 1.0f)
|
||||
transform.LookAt(point(ratio), worldUp);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space</summary>
|
||||
*
|
||||
* @method placeLocal
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @example
|
||||
* ltPath.placeLocal( transform, 0.6f );
|
||||
*/
|
||||
public void placeLocal(Transform transform, float ratio)
|
||||
{
|
||||
placeLocal(transform, ratio, Vector3.up);
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space</summary>
|
||||
*
|
||||
* @method placeLocal
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
|
||||
* @example
|
||||
* ltPath.placeLocal( transform, 0.6f, Vector3.left );
|
||||
*/
|
||||
public void placeLocal(Transform transform, float ratio, Vector3 worldUp)
|
||||
{
|
||||
// Debug.Log("place ratio:" + ratio + " greater:"+(ratio>1f));
|
||||
ratio = Mathf.Clamp01(ratio);
|
||||
transform.localPosition = point(ratio);
|
||||
// Debug.Log("ratio:" + ratio + " +:" + (ratio + 0.001f));
|
||||
ratio = Mathf.Clamp01(ratio + 0.001f);
|
||||
|
||||
if (ratio <= 1.0f)
|
||||
transform.LookAt(transform.parent.TransformPoint(point(ratio)), worldUp);
|
||||
}
|
||||
|
||||
public void gizmoDraw(float t = -1.0f)
|
||||
{
|
||||
Vector3 prevPt = point(0);
|
||||
|
||||
for (int i = 1; i <= 120; i++)
|
||||
{
|
||||
float pm = (float)i / 120f;
|
||||
Vector3 currPt2 = point(pm);
|
||||
//Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
|
||||
Gizmos.color = (previousBezier == currentBezier) ? Color.magenta : Color.grey;
|
||||
Gizmos.DrawLine(currPt2, prevPt);
|
||||
prevPt = currPt2;
|
||||
previousBezier = currentBezier;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Retrieve the closest ratio near the point</summary>
|
||||
*
|
||||
* @method ratioAtPoint
|
||||
* @param {Vector3} point:Vector3 given a current location it makes the best approximiation of where it is along the path ratio-wise (0-1)
|
||||
* @return {float} float of ratio along the path
|
||||
* @example
|
||||
* ratioIter = ltBezier.ratioAtPoint( transform.position );
|
||||
*/
|
||||
public float ratioAtPoint(Vector3 pt, float precision = 0.01f)
|
||||
{
|
||||
float closestDist = float.MaxValue;
|
||||
int closestI = 0;
|
||||
int maxIndex = Mathf.RoundToInt(1f / precision);
|
||||
for (int i = 0; i < maxIndex; i++)
|
||||
{
|
||||
float ratio = (float)i / (float)maxIndex;
|
||||
float dist = Vector3.Distance(pt, point(ratio));
|
||||
// Debug.Log("i:"+i+" dist:"+dist);
|
||||
if (dist < closestDist)
|
||||
{
|
||||
closestDist = dist;
|
||||
closestI = i;
|
||||
}
|
||||
}
|
||||
//Debug.Log("closestI:"+closestI+" maxIndex:"+maxIndex);
|
||||
return (float)closestI / (float)(maxIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate along a set of points that need to be in the format: controlPoint, point1, point2.... pointLast, endControlPoint <summary>Move a GameObject to a certain location</summary>
|
||||
* @class LTSpline
|
||||
* @constructor
|
||||
* @param {Vector3 Array} pts A set of points that define the points the path will pass through (starting with starting control point, and ending with a control point)<br />
|
||||
<i><strong>Note:</strong> The first and last item just define the angle of the end points, they are not actually used in the spline path itself. If you do not care about the angle you can jus set the first two items and last two items as the same value.</i>
|
||||
* @example
|
||||
* LTSpline ltSpline = new LTSpline( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(0f,0f,0f), new Vector3(0f,0.5f,0f), new Vector3(1f,1f,0f), new Vector3(1f,1f,0f)} );<br /><br />
|
||||
* LeanTween.moveSpline(lt, ltSpline.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate <br />
|
||||
* Vector3 pt = ltSpline.point( 0.6f ); // retrieve a point along the path
|
||||
*/
|
||||
[System.Serializable]
|
||||
public class LTSpline
|
||||
{
|
||||
public static int DISTANCE_COUNT = 3; // increase for a more accurate constant speed
|
||||
public static int SUBLINE_COUNT = 20; // increase for a more accurate smoothing of the curves into lines
|
||||
|
||||
/**
|
||||
* @property {float} distance distance of the spline (in unity units)
|
||||
*/
|
||||
public float distance = 0f;
|
||||
|
||||
public bool constantSpeed = true;
|
||||
|
||||
public Vector3[] pts;
|
||||
[System.NonSerialized]
|
||||
public Vector3[] ptsAdj;
|
||||
public int ptsAdjLength;
|
||||
public bool orientToPath;
|
||||
public bool orientToPath2d;
|
||||
private int numSections;
|
||||
private int currPt;
|
||||
|
||||
public LTSpline(Vector3[] pts)
|
||||
{
|
||||
init(pts, true);
|
||||
}
|
||||
|
||||
public LTSpline(Vector3[] pts, bool constantSpeed)
|
||||
{
|
||||
this.constantSpeed = constantSpeed;
|
||||
init(pts, constantSpeed);
|
||||
}
|
||||
|
||||
private void init(Vector3[] pts, bool constantSpeed)
|
||||
{
|
||||
if (pts.Length < 4)
|
||||
{
|
||||
LeanTween.logError("LeanTween - When passing values for a spline path, you must pass four or more values!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.pts = new Vector3[pts.Length];
|
||||
System.Array.Copy(pts, this.pts, pts.Length);
|
||||
|
||||
numSections = pts.Length - 3;
|
||||
|
||||
float minSegment = float.PositiveInfinity;
|
||||
Vector3 earlierPoint = this.pts[1];
|
||||
float totalDistance = 0f;
|
||||
for (int i = 1; i < this.pts.Length - 1; i++)
|
||||
{
|
||||
// float pointDistance = (this.pts[i]-earlierPoint).sqrMagnitude;
|
||||
float pointDistance = Vector3.Distance(this.pts[i], earlierPoint);
|
||||
//Debug.Log("pointDist:"+pointDistance);
|
||||
if (pointDistance < minSegment)
|
||||
{
|
||||
minSegment = pointDistance;
|
||||
}
|
||||
|
||||
totalDistance += pointDistance;
|
||||
}
|
||||
|
||||
if (constantSpeed)
|
||||
{
|
||||
minSegment = totalDistance / (numSections * SUBLINE_COUNT);
|
||||
//Debug.Log("minSegment:"+minSegment+" numSections:"+numSections);
|
||||
|
||||
float minPrecision = minSegment / SUBLINE_COUNT; // number of subdivisions in each segment
|
||||
int precision = (int)Mathf.Ceil(totalDistance / minPrecision) * DISTANCE_COUNT;
|
||||
// Debug.Log("precision:"+precision);
|
||||
if (precision <= 1) // precision has to be greater than one
|
||||
precision = 2;
|
||||
|
||||
ptsAdj = new Vector3[precision];
|
||||
earlierPoint = interp(0f);
|
||||
int num = 1;
|
||||
ptsAdj[0] = earlierPoint;
|
||||
distance = 0f;
|
||||
for (int i = 0; i < precision + 1; i++)
|
||||
{
|
||||
float fract = ((float)(i)) / precision;
|
||||
// Debug.Log("fract:"+fract);
|
||||
Vector3 point = interp(fract);
|
||||
float dist = Vector3.Distance(point, earlierPoint);
|
||||
|
||||
// float dist = (point-earlierPoint).sqrMagnitude;
|
||||
if (dist >= minPrecision || fract >= 1.0f)
|
||||
{
|
||||
ptsAdj[num] = point;
|
||||
distance += dist; // only add it to the total distance once we know we are adding it as an adjusted point
|
||||
|
||||
earlierPoint = point;
|
||||
// Debug.Log("fract:"+fract+" point:"+point);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
// make sure there is a point at the very end
|
||||
/*num++;
|
||||
Vector3 endPoint = interp( 1f );
|
||||
ptsAdj[num] = endPoint;*/
|
||||
// Debug.Log("fract 1f endPoint:"+endPoint);
|
||||
|
||||
ptsAdjLength = num;
|
||||
}
|
||||
// Debug.Log("map 1f:"+map(1f)+" end:"+ptsAdj[ ptsAdjLength-1 ]);
|
||||
|
||||
// Debug.Log("ptsAdjLength:"+ptsAdjLength+" minPrecision:"+minPrecision+" precision:"+precision);
|
||||
}
|
||||
|
||||
public Vector3 map(float u)
|
||||
{
|
||||
if (u >= 1f)
|
||||
return pts[pts.Length - 2];
|
||||
float t = u * (ptsAdjLength - 1);
|
||||
int first = (int)Mathf.Floor(t);
|
||||
int next = (int)Mathf.Ceil(t);
|
||||
|
||||
if (first < 0)
|
||||
first = 0;
|
||||
|
||||
Vector3 val = ptsAdj[first];
|
||||
|
||||
|
||||
Vector3 nextVal = ptsAdj[next];
|
||||
float diff = t - first;
|
||||
|
||||
// Debug.Log("u:"+u+" val:"+val +" nextVal:"+nextVal+" diff:"+diff+" first:"+first+" next:"+next);
|
||||
|
||||
val = val + (nextVal - val) * diff;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public Vector3 interp(float t)
|
||||
{
|
||||
currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections), numSections - 1);
|
||||
float u = t * (float)numSections - (float)currPt;
|
||||
|
||||
//Debug.Log("currPt:"+currPt+" numSections:"+numSections+" pts.Length :"+pts.Length );
|
||||
Vector3 a = pts[currPt];
|
||||
Vector3 b = pts[currPt + 1];
|
||||
Vector3 c = pts[currPt + 2];
|
||||
Vector3 d = pts[currPt + 3];
|
||||
|
||||
Vector3 val = (.5f * (
|
||||
(-a + 3f * b - 3f * c + d) * (u * u * u)
|
||||
+ (2f * a - 5f * b + 4f * c - d) * (u * u)
|
||||
+ (-a + c) * u
|
||||
+ 2f * b));
|
||||
// Debug.Log("currPt:"+currPt+" t:"+t+" val.x"+val.x+" y:"+val.y+" z:"+val.z);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a point along a path <summary>Move a GameObject to a certain location</summary>
|
||||
*
|
||||
* @method ratioAtPoint
|
||||
* @param {Vector3} point:Vector3 given a current location it makes the best approximiation of where it is along the path ratio-wise (0-1)
|
||||
* @return {float} float of ratio along the path
|
||||
* @example
|
||||
* ratioIter = ltSpline.ratioAtPoint( transform.position );
|
||||
*/
|
||||
public float ratioAtPoint(Vector3 pt)
|
||||
{
|
||||
float closestDist = float.MaxValue;
|
||||
int closestI = 0;
|
||||
for (int i = 0; i < ptsAdjLength; i++)
|
||||
{
|
||||
float dist = Vector3.Distance(pt, ptsAdj[i]);
|
||||
// Debug.Log("i:"+i+" dist:"+dist);
|
||||
if (dist < closestDist)
|
||||
{
|
||||
closestDist = dist;
|
||||
closestI = i;
|
||||
}
|
||||
}
|
||||
// Debug.Log("closestI:"+closestI+" ptsAdjLength:"+ptsAdjLength);
|
||||
return (float)closestI / (float)(ptsAdjLength - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a point along a path <summary>Move a GameObject to a certain location</summary>
|
||||
*
|
||||
* @method point
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @return {Vector3} Vector3 position of the point along the path
|
||||
* @example
|
||||
* transform.position = ltSpline.point( 0.6f );
|
||||
*/
|
||||
public Vector3 point(float ratio)
|
||||
{
|
||||
float t = ratio > 1f ? 1f : ratio;
|
||||
return constantSpeed ? map(t) : interp(t);
|
||||
}
|
||||
|
||||
public void place2d(Transform transform, float ratio)
|
||||
{
|
||||
transform.position = point(ratio);
|
||||
ratio += 0.001f;
|
||||
if (ratio <= 1.0f)
|
||||
{
|
||||
Vector3 v3Dir = point(ratio) - transform.position;
|
||||
float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
|
||||
transform.eulerAngles = new Vector3(0, 0, angle);
|
||||
}
|
||||
}
|
||||
|
||||
public void placeLocal2d(Transform transform, float ratio)
|
||||
{
|
||||
Transform trans = transform.parent;
|
||||
if (trans == null)
|
||||
{ // this has no parent, just do a regular transform
|
||||
place2d(transform, ratio);
|
||||
return;
|
||||
}
|
||||
transform.localPosition = point(ratio);
|
||||
ratio += 0.001f;
|
||||
if (ratio <= 1.0f)
|
||||
{
|
||||
Vector3 ptAhead = point(ratio);//trans.TransformPoint( );
|
||||
Vector3 v3Dir = ptAhead - transform.localPosition;
|
||||
float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
|
||||
transform.localEulerAngles = new Vector3(0, 0, angle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Place an object along a certain point on the path (facing the direction perpendicular to the path) <summary>Move a GameObject to a certain location</summary>
|
||||
*
|
||||
* @method place
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @example
|
||||
* ltPath.place( transform, 0.6f );
|
||||
*/
|
||||
public void place(Transform transform, float ratio)
|
||||
{
|
||||
place(transform, ratio, Vector3.up);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path <summary>Move a GameObject to a certain location</summary>
|
||||
*
|
||||
* @method place
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
|
||||
* @example
|
||||
* ltPath.place( transform, 0.6f, Vector3.left );
|
||||
*/
|
||||
public void place(Transform transform, float ratio, Vector3 worldUp)
|
||||
{
|
||||
// ratio = Mathf.Repeat(ratio, 1.0f); // make sure ratio is always between 0-1
|
||||
transform.position = point(ratio);
|
||||
ratio += 0.001f;
|
||||
if (ratio <= 1.0f)
|
||||
transform.LookAt(point(ratio), worldUp);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space <summary>Move a GameObject to a certain location</summary>
|
||||
*
|
||||
* @method placeLocal
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @example
|
||||
* ltPath.placeLocal( transform, 0.6f );
|
||||
*/
|
||||
public void placeLocal(Transform transform, float ratio)
|
||||
{
|
||||
placeLocal(transform, ratio, Vector3.up);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space <summary>Move a GameObject to a certain location</summary>
|
||||
*
|
||||
* @method placeLocal
|
||||
* @param {Transform} transform:Transform the transform of the object you wish to place along the path
|
||||
* @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
|
||||
* @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
|
||||
* @example
|
||||
* ltPath.placeLocal( transform, 0.6f, Vector3.left );
|
||||
*/
|
||||
public void placeLocal(Transform transform, float ratio, Vector3 worldUp)
|
||||
{
|
||||
transform.localPosition = point(ratio);
|
||||
ratio += 0.001f;
|
||||
if (ratio <= 1.0f)
|
||||
transform.LookAt(transform.parent.TransformPoint(point(ratio)), worldUp);
|
||||
}
|
||||
|
||||
public void gizmoDraw(float t = -1.0f)
|
||||
{
|
||||
if (ptsAdj == null || ptsAdj.Length <= 0)
|
||||
return;
|
||||
|
||||
Vector3 prevPt = ptsAdj[0];
|
||||
|
||||
for (int i = 0; i < ptsAdjLength; i++)
|
||||
{
|
||||
Vector3 currPt2 = ptsAdj[i];
|
||||
// Debug.Log("currPt2:"+currPt2);
|
||||
//Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
|
||||
Gizmos.DrawLine(prevPt, currPt2);
|
||||
prevPt = currPt2;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawGizmo(Color color)
|
||||
{
|
||||
if (this.ptsAdjLength >= 4)
|
||||
{
|
||||
|
||||
Vector3 prevPt = this.ptsAdj[0];
|
||||
|
||||
Color colorBefore = Gizmos.color;
|
||||
Gizmos.color = color;
|
||||
for (int i = 0; i < this.ptsAdjLength; i++)
|
||||
{
|
||||
Vector3 currPt2 = this.ptsAdj[i];
|
||||
// Debug.Log("currPt2:"+currPt2);
|
||||
|
||||
Gizmos.DrawLine(prevPt, currPt2);
|
||||
prevPt = currPt2;
|
||||
}
|
||||
Gizmos.color = colorBefore;
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawGizmo(Transform[] arr, Color color)
|
||||
{
|
||||
if (arr.Length >= 4)
|
||||
{
|
||||
Vector3[] vec3s = new Vector3[arr.Length];
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
vec3s[i] = arr[i].position;
|
||||
}
|
||||
LTSpline spline = new LTSpline(vec3s);
|
||||
Vector3 prevPt = spline.ptsAdj[0];
|
||||
|
||||
Color colorBefore = Gizmos.color;
|
||||
Gizmos.color = color;
|
||||
for (int i = 0; i < spline.ptsAdjLength; i++)
|
||||
{
|
||||
Vector3 currPt2 = spline.ptsAdj[i];
|
||||
// Debug.Log("currPt2:"+currPt2);
|
||||
|
||||
Gizmos.DrawLine(prevPt, currPt2);
|
||||
prevPt = currPt2;
|
||||
}
|
||||
Gizmos.color = colorBefore;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void drawLine(Transform[] arr, float width, Color color)
|
||||
{
|
||||
if (arr.Length >= 4)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*public Vector3 Velocity(float t) {
|
||||
t = map( t );
|
||||
|
||||
int numSections = pts.Length - 3;
|
||||
int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
|
||||
float u = t * (float) numSections - (float) currPt;
|
||||
|
||||
Vector3 a = pts[currPt];
|
||||
Vector3 b = pts[currPt + 1];
|
||||
Vector3 c = pts[currPt + 2];
|
||||
Vector3 d = pts[currPt + 3];
|
||||
|
||||
return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u)
|
||||
+ (2f * a -5f * b + 4f * c - d) * u
|
||||
+ .5f * c - .5f * a;
|
||||
}*/
|
||||
|
||||
public void drawLinesGLLines(Material outlineMaterial, Color color, float width)
|
||||
{
|
||||
GL.PushMatrix();
|
||||
outlineMaterial.SetPass(0);
|
||||
GL.LoadPixelMatrix();
|
||||
GL.Begin(GL.LINES);
|
||||
GL.Color(color);
|
||||
|
||||
if (constantSpeed)
|
||||
{
|
||||
if (this.ptsAdjLength >= 4)
|
||||
{
|
||||
|
||||
Vector3 prevPt = this.ptsAdj[0];
|
||||
|
||||
for (int i = 0; i < this.ptsAdjLength; i++)
|
||||
{
|
||||
Vector3 currPt2 = this.ptsAdj[i];
|
||||
GL.Vertex(prevPt);
|
||||
GL.Vertex(currPt2);
|
||||
|
||||
prevPt = currPt2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.pts.Length >= 4)
|
||||
{
|
||||
|
||||
Vector3 prevPt = this.pts[0];
|
||||
|
||||
float split = 1f / ((float)this.pts.Length * 10f);
|
||||
|
||||
float iter = 0f;
|
||||
while (iter < 1f)
|
||||
{
|
||||
float at = iter / 1f;
|
||||
Vector3 currPt2 = interp(at);
|
||||
// Debug.Log("currPt2:"+currPt2);
|
||||
|
||||
GL.Vertex(prevPt);
|
||||
GL.Vertex(currPt2);
|
||||
|
||||
prevPt = currPt2;
|
||||
|
||||
iter += split;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GL.End();
|
||||
GL.PopMatrix();
|
||||
|
||||
}
|
||||
|
||||
public Vector3[] generateVectors()
|
||||
{
|
||||
if (this.pts.Length >= 4)
|
||||
{
|
||||
List<Vector3> meshPoints = new List<Vector3>();
|
||||
Vector3 prevPt = this.pts[0];
|
||||
meshPoints.Add(prevPt);
|
||||
|
||||
float split = 1f / ((float)this.pts.Length * 10f);
|
||||
|
||||
float iter = 0f;
|
||||
while (iter < 1f)
|
||||
{
|
||||
float at = iter / 1f;
|
||||
Vector3 currPt2 = interp(at);
|
||||
// Debug.Log("currPt2:"+currPt2);
|
||||
|
||||
// GL.Vertex(prevPt);
|
||||
// GL.Vertex(currPt2);
|
||||
meshPoints.Add(currPt2);
|
||||
|
||||
// prevPt = currPt2;
|
||||
|
||||
iter += split;
|
||||
}
|
||||
|
||||
meshPoints.ToArray();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate GUI Elements by creating this object and passing the *.rect variable to the GUI method<br /><br />
|
||||
* <strong>Example Javascript: </strong><br />var bRect:LTRect = new LTRect( 0, 0, 100, 50 );<br />
|
||||
* LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );<br />
|
||||
* function OnGUI(){<br />
|
||||
*   if(GUI.Button(bRect.rect, "Scale")){ }<br />
|
||||
* }<br />
|
||||
* <br />
|
||||
* <strong>Example C#: </strong> <br />
|
||||
* LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );<br />
|
||||
* LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f );<br />
|
||||
* void OnGUI(){<br />
|
||||
*   if(GUI.Button(bRect.rect, "Scale")){ }<br />
|
||||
* }<br />
|
||||
*
|
||||
* @class LTRect
|
||||
* @constructor
|
||||
* @param {float} x:float X location
|
||||
* @param {float} y:float Y location
|
||||
* @param {float} width:float Width
|
||||
* @param {float} height:float Height
|
||||
* @param {float} alpha:float (Optional) initial alpha amount (0-1)
|
||||
* @param {float} rotation:float (Optional) initial rotation in degrees (0-360)
|
||||
*/
|
||||
|
||||
[System.Serializable]
|
||||
public class LTRect : System.Object
|
||||
{
|
||||
/**
|
||||
* Pass this value to the GUI Methods
|
||||
*
|
||||
* @property rect
|
||||
* @type {Rect} rect:Rect Rect object that controls the positioning and size
|
||||
*/
|
||||
public Rect _rect;
|
||||
public float alpha = 1f;
|
||||
public float rotation;
|
||||
public Vector2 pivot;
|
||||
public Vector2 margin;
|
||||
public Rect relativeRect = new Rect(0f, 0f, float.PositiveInfinity, float.PositiveInfinity);
|
||||
|
||||
public bool rotateEnabled;
|
||||
[HideInInspector]
|
||||
public bool rotateFinished;
|
||||
public bool alphaEnabled;
|
||||
public string labelStr;
|
||||
public LTGUI.Element_Type type;
|
||||
public GUIStyle style;
|
||||
public bool useColor = false;
|
||||
public Color color = Color.white;
|
||||
public bool fontScaleToFit;
|
||||
public bool useSimpleScale;
|
||||
public bool sizeByHeight;
|
||||
|
||||
public Texture texture;
|
||||
|
||||
private int _id = -1;
|
||||
[HideInInspector]
|
||||
public int counter;
|
||||
|
||||
public static bool colorTouched;
|
||||
|
||||
public LTRect()
|
||||
{
|
||||
reset();
|
||||
this.rotateEnabled = this.alphaEnabled = true;
|
||||
_rect = new Rect(0f, 0f, 1f, 1f);
|
||||
}
|
||||
|
||||
public LTRect(Rect rect)
|
||||
{
|
||||
_rect = rect;
|
||||
reset();
|
||||
}
|
||||
|
||||
public LTRect(float x, float y, float width, float height)
|
||||
{
|
||||
_rect = new Rect(x, y, width, height);
|
||||
this.alpha = 1.0f;
|
||||
this.rotation = 0.0f;
|
||||
this.rotateEnabled = this.alphaEnabled = false;
|
||||
}
|
||||
|
||||
public LTRect(float x, float y, float width, float height, float alpha)
|
||||
{
|
||||
_rect = new Rect(x, y, width, height);
|
||||
this.alpha = alpha;
|
||||
this.rotation = 0.0f;
|
||||
this.rotateEnabled = this.alphaEnabled = false;
|
||||
}
|
||||
|
||||
public LTRect(float x, float y, float width, float height, float alpha, float rotation)
|
||||
{
|
||||
_rect = new Rect(x, y, width, height);
|
||||
this.alpha = alpha;
|
||||
this.rotation = rotation;
|
||||
this.rotateEnabled = this.alphaEnabled = false;
|
||||
if (rotation != 0.0f)
|
||||
{
|
||||
this.rotateEnabled = true;
|
||||
resetForRotation();
|
||||
}
|
||||
}
|
||||
|
||||
public bool hasInitiliazed
|
||||
{
|
||||
get
|
||||
{
|
||||
return _id != -1;
|
||||
}
|
||||
}
|
||||
|
||||
public int id
|
||||
{
|
||||
get
|
||||
{
|
||||
int toId = _id | counter << 16;
|
||||
|
||||
/*uint backId = toId & 0xFFFF;
|
||||
uint backCounter = toId >> 16;
|
||||
if(_id!=backId || backCounter!=counter){
|
||||
Debug.LogError("BAD CONVERSION toId:"+_id);
|
||||
}*/
|
||||
|
||||
return toId;
|
||||
}
|
||||
}
|
||||
|
||||
public void setId(int id, int counter)
|
||||
{
|
||||
this._id = id;
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
this.alpha = 1.0f;
|
||||
this.rotation = 0.0f;
|
||||
this.rotateEnabled = this.alphaEnabled = false;
|
||||
this.margin = Vector2.zero;
|
||||
this.sizeByHeight = false;
|
||||
this.useColor = false;
|
||||
}
|
||||
|
||||
public void resetForRotation()
|
||||
{
|
||||
Vector3 scale = new Vector3(GUI.matrix[0, 0], GUI.matrix[1, 1], GUI.matrix[2, 2]);
|
||||
if (pivot == Vector2.zero)
|
||||
{
|
||||
pivot = new Vector2((_rect.x + ((_rect.width) * 0.5f)) * scale.x + GUI.matrix[0, 3], (_rect.y + ((_rect.height) * 0.5f)) * scale.y + GUI.matrix[1, 3]);
|
||||
}
|
||||
}
|
||||
|
||||
public float x
|
||||
{
|
||||
get { return _rect.x; }
|
||||
set { _rect.x = value; }
|
||||
}
|
||||
|
||||
public float y
|
||||
{
|
||||
get { return _rect.y; }
|
||||
set { _rect.y = value; }
|
||||
}
|
||||
|
||||
public float width
|
||||
{
|
||||
get { return _rect.width; }
|
||||
set { _rect.width = value; }
|
||||
}
|
||||
|
||||
public float height
|
||||
{
|
||||
get { return _rect.height; }
|
||||
set { _rect.height = value; }
|
||||
}
|
||||
|
||||
public Rect rect
|
||||
{
|
||||
|
||||
get
|
||||
{
|
||||
if (colorTouched)
|
||||
{
|
||||
colorTouched = false;
|
||||
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 1.0f);
|
||||
}
|
||||
if (rotateEnabled)
|
||||
{
|
||||
if (rotateFinished)
|
||||
{
|
||||
rotateFinished = false;
|
||||
rotateEnabled = false;
|
||||
//this.rotation = 0.0f;
|
||||
pivot = Vector2.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUIUtility.RotateAroundPivot(rotation, pivot);
|
||||
}
|
||||
}
|
||||
if (alphaEnabled)
|
||||
{
|
||||
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);
|
||||
colorTouched = true;
|
||||
}
|
||||
if (fontScaleToFit)
|
||||
{
|
||||
if (this.useSimpleScale)
|
||||
{
|
||||
style.fontSize = (int)(_rect.height * this.relativeRect.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
style.fontSize = (int)_rect.height;
|
||||
}
|
||||
}
|
||||
return _rect;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_rect = value;
|
||||
}
|
||||
}
|
||||
|
||||
public LTRect setStyle(GUIStyle style)
|
||||
{
|
||||
this.style = style;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTRect setFontScaleToFit(bool fontScaleToFit)
|
||||
{
|
||||
this.fontScaleToFit = fontScaleToFit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTRect setColor(Color color)
|
||||
{
|
||||
this.color = color;
|
||||
this.useColor = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTRect setAlpha(float alpha)
|
||||
{
|
||||
this.alpha = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTRect setLabel(String str)
|
||||
{
|
||||
this.labelStr = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTRect setUseSimpleScale(bool useSimpleScale, Rect relativeRect)
|
||||
{
|
||||
this.useSimpleScale = useSimpleScale;
|
||||
this.relativeRect = relativeRect;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTRect setUseSimpleScale(bool useSimpleScale)
|
||||
{
|
||||
this.useSimpleScale = useSimpleScale;
|
||||
this.relativeRect = new Rect(0f, 0f, Screen.width, Screen.height);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LTRect setSizeByHeight(bool sizeByHeight)
|
||||
{
|
||||
this.sizeByHeight = sizeByHeight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "x:" + _rect.x + " y:" + _rect.y + " width:" + _rect.width + " height:" + _rect.height;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Object that describes the event to an event listener
|
||||
* @class LTEvent
|
||||
* @constructor
|
||||
* @param {object} data:object Data that has been passed from the dispatchEvent method
|
||||
*/
|
||||
public class LTEvent
|
||||
{
|
||||
public int id;
|
||||
public object data;
|
||||
|
||||
public LTEvent(int id, object data)
|
||||
{
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
public class LTGUI
|
||||
{
|
||||
public static int RECT_LEVELS = 5;
|
||||
public static int RECTS_PER_LEVEL = 10;
|
||||
public static int BUTTONS_MAX = 24;
|
||||
|
||||
private static LTRect[] levels;
|
||||
private static int[] levelDepths;
|
||||
private static Rect[] buttons;
|
||||
private static int[] buttonLevels;
|
||||
private static int[] buttonLastFrame;
|
||||
private static LTRect r;
|
||||
private static Color color = Color.white;
|
||||
private static bool isGUIEnabled = false;
|
||||
private static int global_counter = 0;
|
||||
|
||||
public enum Element_Type
|
||||
{
|
||||
Texture,
|
||||
Label
|
||||
}
|
||||
|
||||
public static void init()
|
||||
{
|
||||
if (levels == null)
|
||||
{
|
||||
levels = new LTRect[RECT_LEVELS * RECTS_PER_LEVEL];
|
||||
levelDepths = new int[RECT_LEVELS];
|
||||
}
|
||||
}
|
||||
|
||||
public static void initRectCheck()
|
||||
{
|
||||
if (buttons == null)
|
||||
{
|
||||
buttons = new Rect[BUTTONS_MAX];
|
||||
buttonLevels = new int[BUTTONS_MAX];
|
||||
buttonLastFrame = new int[BUTTONS_MAX];
|
||||
for (int i = 0; i < buttonLevels.Length; i++)
|
||||
{
|
||||
buttonLevels[i] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset()
|
||||
{
|
||||
if (isGUIEnabled)
|
||||
{
|
||||
isGUIEnabled = false;
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
{
|
||||
levels[i] = null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < levelDepths.Length; i++)
|
||||
{
|
||||
levelDepths[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(int updateLevel)
|
||||
{
|
||||
if (isGUIEnabled)
|
||||
{
|
||||
init();
|
||||
if (levelDepths[updateLevel] > 0)
|
||||
{
|
||||
color = GUI.color;
|
||||
int baseI = updateLevel * RECTS_PER_LEVEL;
|
||||
int maxLoop = baseI + levelDepths[updateLevel];// RECTS_PER_LEVEL;//;
|
||||
|
||||
for (int i = baseI; i < maxLoop; i++)
|
||||
{
|
||||
r = levels[i];
|
||||
// Debug.Log("r:"+r+" i:"+i);
|
||||
if (r != null /*&& checkOnScreen(r.rect)*/)
|
||||
{
|
||||
//Debug.Log("label:"+r.labelStr+" textColor:"+r.style.normal.textColor);
|
||||
if (r.useColor)
|
||||
GUI.color = r.color;
|
||||
if (r.type == Element_Type.Label)
|
||||
{
|
||||
if (r.style != null)
|
||||
GUI.skin.label = r.style;
|
||||
if (r.useSimpleScale)
|
||||
{
|
||||
GUI.Label(new Rect((r.rect.x + r.margin.x + r.relativeRect.x) * r.relativeRect.width, (r.rect.y + r.margin.y + r.relativeRect.y) * r.relativeRect.height, r.rect.width * r.relativeRect.width, r.rect.height * r.relativeRect.height), r.labelStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.Label(new Rect(r.rect.x + r.margin.x, r.rect.y + r.margin.y, r.rect.width, r.rect.height), r.labelStr);
|
||||
}
|
||||
}
|
||||
else if (r.type == Element_Type.Texture && r.texture != null)
|
||||
{
|
||||
Vector2 size = r.useSimpleScale ? new Vector2(0f, r.rect.height * r.relativeRect.height) : new Vector2(r.rect.width, r.rect.height);
|
||||
if (r.sizeByHeight)
|
||||
{
|
||||
size.x = (float)r.texture.width / (float)r.texture.height * size.y;
|
||||
}
|
||||
if (r.useSimpleScale)
|
||||
{
|
||||
GUI.DrawTexture(new Rect((r.rect.x + r.margin.x + r.relativeRect.x) * r.relativeRect.width, (r.rect.y + r.margin.y + r.relativeRect.y) * r.relativeRect.height, size.x, size.y), r.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.DrawTexture(new Rect(r.rect.x + r.margin.x, r.rect.y + r.margin.y, size.x, size.y), r.texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GUI.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool checkOnScreen(Rect rect)
|
||||
{
|
||||
bool offLeft = rect.x + rect.width < 0f;
|
||||
bool offRight = rect.x > Screen.width;
|
||||
bool offBottom = rect.y > Screen.height;
|
||||
bool offTop = rect.y + rect.height < 0f;
|
||||
|
||||
return !(offLeft || offRight || offBottom || offTop);
|
||||
}
|
||||
|
||||
public static void destroy(int id)
|
||||
{
|
||||
int backId = id & 0xFFFF;
|
||||
int backCounter = id >> 16;
|
||||
if (id >= 0 && levels[backId] != null && levels[backId].hasInitiliazed && levels[backId].counter == backCounter)
|
||||
levels[backId] = null;
|
||||
}
|
||||
|
||||
public static void destroyAll(int depth)
|
||||
{ // clears all gui elements on depth
|
||||
int maxLoop = depth * RECTS_PER_LEVEL + RECTS_PER_LEVEL;
|
||||
for (int i = depth * RECTS_PER_LEVEL; levels != null && i < maxLoop; i++)
|
||||
{
|
||||
levels[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static LTRect label(Rect rect, string label, int depth)
|
||||
{
|
||||
return LTGUI.label(new LTRect(rect), label, depth);
|
||||
}
|
||||
|
||||
public static LTRect label(LTRect rect, string label, int depth)
|
||||
{
|
||||
rect.type = Element_Type.Label;
|
||||
rect.labelStr = label;
|
||||
return element(rect, depth);
|
||||
}
|
||||
|
||||
public static LTRect texture(Rect rect, Texture texture, int depth)
|
||||
{
|
||||
return LTGUI.texture(new LTRect(rect), texture, depth);
|
||||
}
|
||||
|
||||
public static LTRect texture(LTRect rect, Texture texture, int depth)
|
||||
{
|
||||
rect.type = Element_Type.Texture;
|
||||
rect.texture = texture;
|
||||
return element(rect, depth);
|
||||
}
|
||||
|
||||
public static LTRect element(LTRect rect, int depth)
|
||||
{
|
||||
isGUIEnabled = true;
|
||||
init();
|
||||
int maxLoop = depth * RECTS_PER_LEVEL + RECTS_PER_LEVEL;
|
||||
int k = 0;
|
||||
if (rect != null)
|
||||
{
|
||||
destroy(rect.id);
|
||||
}
|
||||
if (rect.type == LTGUI.Element_Type.Label && rect.style != null)
|
||||
{
|
||||
if (rect.style.normal.textColor.a <= 0f)
|
||||
{
|
||||
Debug.LogWarning("Your GUI normal color has an alpha of zero, and will not be rendered.");
|
||||
}
|
||||
}
|
||||
if (rect.relativeRect.width == float.PositiveInfinity)
|
||||
{
|
||||
rect.relativeRect = new Rect(0f, 0f, Screen.width, Screen.height);
|
||||
}
|
||||
for (int i = depth * RECTS_PER_LEVEL; i < maxLoop; i++)
|
||||
{
|
||||
r = levels[i];
|
||||
if (r == null)
|
||||
{
|
||||
r = rect;
|
||||
r.rotateEnabled = true;
|
||||
r.alphaEnabled = true;
|
||||
r.setId(i, global_counter);
|
||||
levels[i] = r;
|
||||
// Debug.Log("k:"+k+ " maxDepth:"+levelDepths[depth]);
|
||||
if (k >= levelDepths[depth])
|
||||
{
|
||||
levelDepths[depth] = k + 1;
|
||||
}
|
||||
global_counter++;
|
||||
return r;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
Debug.LogError("You ran out of GUI Element spaces");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool hasNoOverlap(Rect rect, int depth)
|
||||
{
|
||||
initRectCheck();
|
||||
bool hasNoOverlap = true;
|
||||
bool wasAddedToList = false;
|
||||
for (int i = 0; i < buttonLevels.Length; i++)
|
||||
{
|
||||
// Debug.Log("buttonLastFrame["+i+"]:"+buttonLastFrame[i]);
|
||||
//Debug.Log("buttonLevels["+i+"]:"+buttonLevels[i]);
|
||||
if (buttonLevels[i] >= 0)
|
||||
{
|
||||
//Debug.Log("buttonLastFrame["+i+"]:"+buttonLastFrame[i]+" Time.frameCount:"+Time.frameCount);
|
||||
if (buttonLastFrame[i] + 1 < Time.frameCount)
|
||||
{ // It has to have been visible within the current, or
|
||||
buttonLevels[i] = -1;
|
||||
// Debug.Log("resetting i:"+i);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if(buttonLevels[i]>=0)
|
||||
// Debug.Log("buttonLevels["+i+"]:"+buttonLevels[i]);
|
||||
if (buttonLevels[i] > depth)
|
||||
{
|
||||
/*if(firstTouch().x > 0){
|
||||
Debug.Log("buttons["+i+"]:"+buttons[i] + " firstTouch:");
|
||||
Debug.Log(firstTouch());
|
||||
Debug.Log(buttonLevels[i]);
|
||||
}*/
|
||||
if (pressedWithinRect(buttons[i]))
|
||||
{
|
||||
hasNoOverlap = false; // there is an overlapping button that is higher
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wasAddedToList == false && buttonLevels[i] < 0)
|
||||
{
|
||||
wasAddedToList = true;
|
||||
buttonLevels[i] = depth;
|
||||
buttons[i] = rect;
|
||||
buttonLastFrame[i] = Time.frameCount;
|
||||
}
|
||||
}
|
||||
|
||||
return hasNoOverlap;
|
||||
}
|
||||
|
||||
public static bool pressedWithinRect(Rect rect)
|
||||
{
|
||||
Vector2 vec2 = firstTouch();
|
||||
if (vec2.x < 0f)
|
||||
return false;
|
||||
float vecY = Screen.height - vec2.y;
|
||||
return (vec2.x > rect.x && vec2.x < rect.x + rect.width && vecY > rect.y && vecY < rect.y + rect.height);
|
||||
}
|
||||
|
||||
public static bool checkWithinRect(Vector2 vec2, Rect rect)
|
||||
{
|
||||
vec2.y = Screen.height - vec2.y;
|
||||
return (vec2.x > rect.x && vec2.x < rect.x + rect.width && vec2.y > rect.y && vec2.y < rect.y + rect.height);
|
||||
}
|
||||
|
||||
public static Vector2 firstTouch()
|
||||
{
|
||||
if (Input.touchCount > 0)
|
||||
{
|
||||
return Input.touches[0].position;
|
||||
}
|
||||
else if (Input.GetMouseButton(0))
|
||||
{
|
||||
return Input.mousePosition;
|
||||
}
|
||||
|
||||
return new Vector2(Mathf.NegativeInfinity, Mathf.NegativeInfinity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace DentedPixel { public class LeanDummy { } }
|
||||
//}
|
||||
11
KFAttached/LeanTween/Framework/LeanTween.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LeanTween.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c2f4b27196f84954b44753aaac214bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
188
KFAttached/LeanTween/Framework/LeanTweenExt.cs
Normal file
188
KFAttached/LeanTween/Framework/LeanTweenExt.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public static class LeanTweenExt
|
||||
{
|
||||
//LeanTween.addListener
|
||||
//LeanTween.alpha
|
||||
public static LTDescr LeanAlpha(this GameObject gameObject, float to, float time) { return LeanTween.alpha(gameObject, to, time); }
|
||||
//LeanTween.alphaCanvas
|
||||
public static LTDescr LeanAlphaVertex(this GameObject gameObject, float to, float time) { return LeanTween.alphaVertex(gameObject, to, time); }
|
||||
//LeanTween.alpha (RectTransform)
|
||||
public static LTDescr LeanAlpha(this RectTransform rectTransform, float to, float time) { return LeanTween.alpha(rectTransform, to, time); }
|
||||
//LeanTween.alphaCanvas
|
||||
public static LTDescr LeanAlpha(this CanvasGroup canvas, float to, float time) { return LeanTween.alphaCanvas(canvas, to, time); }
|
||||
//LeanTween.alphaText
|
||||
public static LTDescr LeanAlphaText(this RectTransform rectTransform, float to, float time) { return LeanTween.alphaText(rectTransform, to, time); }
|
||||
//LeanTween.cancel
|
||||
public static void LeanCancel(this GameObject gameObject) { LeanTween.cancel(gameObject); }
|
||||
public static void LeanCancel(this GameObject gameObject, bool callOnComplete) { LeanTween.cancel(gameObject, callOnComplete); }
|
||||
public static void LeanCancel(this GameObject gameObject, int uniqueId, bool callOnComplete = false) { LeanTween.cancel(gameObject, uniqueId, callOnComplete); }
|
||||
//LeanTween.cancel
|
||||
public static void LeanCancel(this RectTransform rectTransform) { LeanTween.cancel(rectTransform); }
|
||||
//LeanTween.cancelAll
|
||||
//LeanTween.color
|
||||
public static LTDescr LeanColor(this GameObject gameObject, Color to, float time) { return LeanTween.color(gameObject, to, time); }
|
||||
//LeanTween.colorText
|
||||
public static LTDescr LeanColorText(this RectTransform rectTransform, Color to, float time) { return LeanTween.colorText(rectTransform, to, time); }
|
||||
//LeanTween.delayedCall
|
||||
public static LTDescr LeanDelayedCall(this GameObject gameObject, float delayTime, System.Action callback) { return LeanTween.delayedCall(gameObject, delayTime, callback); }
|
||||
public static LTDescr LeanDelayedCall(this GameObject gameObject, float delayTime, System.Action<object> callback) { return LeanTween.delayedCall(gameObject, delayTime, callback); }
|
||||
|
||||
//LeanTween.isPaused
|
||||
public static bool LeanIsPaused(this GameObject gameObject) { return LeanTween.isPaused(gameObject); }
|
||||
public static bool LeanIsPaused(this RectTransform rectTransform) { return LeanTween.isPaused(rectTransform); }
|
||||
|
||||
//LeanTween.isTweening
|
||||
public static bool LeanIsTweening(this GameObject gameObject) { return LeanTween.isTweening(gameObject); }
|
||||
//LeanTween.isTweening
|
||||
//LeanTween.move
|
||||
public static LTDescr LeanMove(this GameObject gameObject, Vector3 to, float time) { return LeanTween.move(gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this Transform transform, Vector3 to, float time) { return LeanTween.move(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this RectTransform rectTransform, Vector3 to, float time) { return LeanTween.move(rectTransform, to, time); }
|
||||
//LeanTween.move
|
||||
public static LTDescr LeanMove(this GameObject gameObject, Vector2 to, float time) { return LeanTween.move(gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this Transform transform, Vector2 to, float time) { return LeanTween.move(transform.gameObject, to, time); }
|
||||
//LeanTween.move
|
||||
public static LTDescr LeanMove(this GameObject gameObject, Vector3[] to, float time) { return LeanTween.move(gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this GameObject gameObject, LTBezierPath to, float time) { return LeanTween.move(gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this GameObject gameObject, LTSpline to, float time) { return LeanTween.move(gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this Transform transform, Vector3[] to, float time) { return LeanTween.move(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this Transform transform, LTBezierPath to, float time) { return LeanTween.move(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMove(this Transform transform, LTSpline to, float time) { return LeanTween.move(transform.gameObject, to, time); }
|
||||
//LeanTween.moveLocal
|
||||
public static LTDescr LeanMoveLocal(this GameObject gameObject, Vector3 to, float time) { return LeanTween.moveLocal(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocal(this GameObject gameObject, LTBezierPath to, float time) { return LeanTween.moveLocal(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocal(this GameObject gameObject, LTSpline to, float time) { return LeanTween.moveLocal(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocal(this Transform transform, Vector3 to, float time) { return LeanTween.moveLocal(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocal(this Transform transform, LTBezierPath to, float time) { return LeanTween.moveLocal(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocal(this Transform transform, LTSpline to, float time) { return LeanTween.moveLocal(transform.gameObject, to, time); }
|
||||
//LeanTween.moveLocal
|
||||
public static LTDescr LeanMoveLocalX(this GameObject gameObject, float to, float time) { return LeanTween.moveLocalX(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocalY(this GameObject gameObject, float to, float time) { return LeanTween.moveLocalY(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocalZ(this GameObject gameObject, float to, float time) { return LeanTween.moveLocalZ(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocalX(this Transform transform, float to, float time) { return LeanTween.moveLocalX(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocalY(this Transform transform, float to, float time) { return LeanTween.moveLocalY(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMoveLocalZ(this Transform transform, float to, float time) { return LeanTween.moveLocalZ(transform.gameObject, to, time); }
|
||||
//LeanTween.moveSpline
|
||||
public static LTDescr LeanMoveSpline(this GameObject gameObject, Vector3[] to, float time) { return LeanTween.moveSpline(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveSpline(this GameObject gameObject, LTSpline to, float time) { return LeanTween.moveSpline(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveSpline(this Transform transform, Vector3[] to, float time) { return LeanTween.moveSpline(transform.gameObject, to, time); }
|
||||
public static LTDescr LeanMoveSpline(this Transform transform, LTSpline to, float time) { return LeanTween.moveSpline(transform.gameObject, to, time); }
|
||||
//LeanTween.moveSplineLocal
|
||||
public static LTDescr LeanMoveSplineLocal(this GameObject gameObject, Vector3[] to, float time) { return LeanTween.moveSplineLocal(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveSplineLocal(this Transform transform, Vector3[] to, float time) { return LeanTween.moveSplineLocal(transform.gameObject, to, time); }
|
||||
//LeanTween.moveX
|
||||
public static LTDescr LeanMoveX(this GameObject gameObject, float to, float time) { return LeanTween.moveX(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveX(this Transform transform, float to, float time) { return LeanTween.moveX(transform.gameObject, to, time); }
|
||||
//LeanTween.moveX (RectTransform)
|
||||
public static LTDescr LeanMoveX(this RectTransform rectTransform, float to, float time) { return LeanTween.moveX(rectTransform, to, time); }
|
||||
//LeanTween.moveY
|
||||
public static LTDescr LeanMoveY(this GameObject gameObject, float to, float time) { return LeanTween.moveY(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveY(this Transform transform, float to, float time) { return LeanTween.moveY(transform.gameObject, to, time); }
|
||||
//LeanTween.moveY (RectTransform)
|
||||
public static LTDescr LeanMoveY(this RectTransform rectTransform, float to, float time) { return LeanTween.moveY(rectTransform, to, time); }
|
||||
//LeanTween.moveZ
|
||||
public static LTDescr LeanMoveZ(this GameObject gameObject, float to, float time) { return LeanTween.moveZ(gameObject, to, time); }
|
||||
public static LTDescr LeanMoveZ(this Transform transform, float to, float time) { return LeanTween.moveZ(transform.gameObject, to, time); }
|
||||
//LeanTween.moveZ (RectTransform)
|
||||
public static LTDescr LeanMoveZ(this RectTransform rectTransform, float to, float time) { return LeanTween.moveZ(rectTransform, to, time); }
|
||||
//LeanTween.pause
|
||||
public static void LeanPause(this GameObject gameObject) { LeanTween.pause(gameObject); }
|
||||
//LeanTween.play
|
||||
public static LTDescr LeanPlay(this RectTransform rectTransform, UnityEngine.Sprite[] sprites) { return LeanTween.play(rectTransform, sprites); }
|
||||
//LeanTween.removeListener
|
||||
//LeanTween.resume
|
||||
public static void LeanResume(this GameObject gameObject) { LeanTween.resume(gameObject); }
|
||||
//LeanTween.resumeAll
|
||||
//LeanTween.rotate
|
||||
public static LTDescr LeanRotate(this GameObject gameObject, Vector3 to, float time) { return LeanTween.rotate(gameObject, to, time); }
|
||||
public static LTDescr LeanRotate(this Transform transform, Vector3 to, float time) { return LeanTween.rotate(transform.gameObject, to, time); }
|
||||
//LeanTween.rotate
|
||||
//LeanTween.rotate (RectTransform)
|
||||
public static LTDescr LeanRotate(this RectTransform rectTransform, Vector3 to, float time) { return LeanTween.rotate(rectTransform, to, time); }
|
||||
//LeanTween.rotateAround
|
||||
public static LTDescr LeanRotateAround(this GameObject gameObject, Vector3 axis, float add, float time) { return LeanTween.rotateAround(gameObject, axis, add, time); }
|
||||
public static LTDescr LeanRotateAround(this Transform transform, Vector3 axis, float add, float time) { return LeanTween.rotateAround(transform.gameObject, axis, add, time); }
|
||||
//LeanTween.rotateAround (RectTransform)
|
||||
public static LTDescr LeanRotateAround(this RectTransform rectTransform, Vector3 axis, float add, float time) { return LeanTween.rotateAround(rectTransform, axis, add, time); }
|
||||
//LeanTween.rotateAroundLocal
|
||||
public static LTDescr LeanRotateAroundLocal(this GameObject gameObject, Vector3 axis, float add, float time) { return LeanTween.rotateAroundLocal(gameObject, axis, add, time); }
|
||||
public static LTDescr LeanRotateAroundLocal(this Transform transform, Vector3 axis, float add, float time) { return LeanTween.rotateAroundLocal(transform.gameObject, axis, add, time); }
|
||||
//LeanTween.rotateAround (RectTransform)
|
||||
public static LTDescr LeanRotateAroundLocal(this RectTransform rectTransform, Vector3 axis, float add, float time) { return LeanTween.rotateAroundLocal(rectTransform, axis, add, time); }
|
||||
//LeanTween.rotateLocal
|
||||
//LeanTween.rotateX
|
||||
public static LTDescr LeanRotateX(this GameObject gameObject, float to, float time) { return LeanTween.rotateX(gameObject, to, time); }
|
||||
public static LTDescr LeanRotateX(this Transform transform, float to, float time) { return LeanTween.rotateX(transform.gameObject, to, time); }
|
||||
//LeanTween.rotateY
|
||||
public static LTDescr LeanRotateY(this GameObject gameObject, float to, float time) { return LeanTween.rotateY(gameObject, to, time); }
|
||||
public static LTDescr LeanRotateY(this Transform transform, float to, float time) { return LeanTween.rotateY(transform.gameObject, to, time); }
|
||||
//LeanTween.rotateZ
|
||||
public static LTDescr LeanRotateZ(this GameObject gameObject, float to, float time) { return LeanTween.rotateZ(gameObject, to, time); }
|
||||
public static LTDescr LeanRotateZ(this Transform transform, float to, float time) { return LeanTween.rotateZ(transform.gameObject, to, time); }
|
||||
//LeanTween.scale
|
||||
public static LTDescr LeanScale(this GameObject gameObject, Vector3 to, float time) { return LeanTween.scale(gameObject, to, time); }
|
||||
public static LTDescr LeanScale(this Transform transform, Vector3 to, float time) { return LeanTween.scale(transform.gameObject, to, time); }
|
||||
//LeanTween.scale (GUI)
|
||||
//LeanTween.scale (RectTransform)
|
||||
public static LTDescr LeanScale(this RectTransform rectTransform, Vector3 to, float time) { return LeanTween.scale(rectTransform, to, time); }
|
||||
//LeanTween.scaleX
|
||||
public static LTDescr LeanScaleX(this GameObject gameObject, float to, float time) { return LeanTween.scaleX(gameObject, to, time); }
|
||||
public static LTDescr LeanScaleX(this Transform transform, float to, float time) { return LeanTween.scaleX(transform.gameObject, to, time); }
|
||||
//LeanTween.scaleY
|
||||
public static LTDescr LeanScaleY(this GameObject gameObject, float to, float time) { return LeanTween.scaleY(gameObject, to, time); }
|
||||
public static LTDescr LeanScaleY(this Transform transform, float to, float time) { return LeanTween.scaleY(transform.gameObject, to, time); }
|
||||
//LeanTween.scaleZ
|
||||
public static LTDescr LeanScaleZ(this GameObject gameObject, float to, float time) { return LeanTween.scaleZ(gameObject, to, time); }
|
||||
public static LTDescr LeanScaleZ(this Transform transform, float to, float time) { return LeanTween.scaleZ(transform.gameObject, to, time); }
|
||||
//LeanTween.sequence
|
||||
//LeanTween.size (RectTransform)
|
||||
public static LTDescr LeanSize(this RectTransform rectTransform, Vector2 to, float time) { return LeanTween.size(rectTransform, to, time); }
|
||||
//LeanTween.tweensRunning
|
||||
//LeanTween.value (Color)
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Color from, Color to, float time) { return LeanTween.value(gameObject, from, to, time); }
|
||||
//LeanTween.value (Color)
|
||||
//LeanTween.value (float)
|
||||
public static LTDescr LeanValue(this GameObject gameObject, float from, float to, float time) { return LeanTween.value(gameObject, from, to, time); }
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Vector2 from, Vector2 to, float time) { return LeanTween.value(gameObject, from, to, time); }
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Vector3 from, Vector3 to, float time) { return LeanTween.value(gameObject, from, to, time); }
|
||||
//LeanTween.value (float)
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<float> callOnUpdate, float from, float to, float time) { return LeanTween.value(gameObject, callOnUpdate, from, to, time); }
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<float, float> callOnUpdate, float from, float to, float time) { return LeanTween.value(gameObject, callOnUpdate, from, to, time); }
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<float, object> callOnUpdate, float from, float to, float time) { return LeanTween.value(gameObject, callOnUpdate, from, to, time); }
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<Color> callOnUpdate, Color from, Color to, float time) { return LeanTween.value(gameObject, callOnUpdate, from, to, time); }
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<Vector2> callOnUpdate, Vector2 from, Vector2 to, float time) { return LeanTween.value(gameObject, callOnUpdate, from, to, time); }
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<Vector3> callOnUpdate, Vector3 from, Vector3 to, float time) { return LeanTween.value(gameObject, callOnUpdate, from, to, time); }
|
||||
|
||||
public static void LeanSetPosX(this Transform transform, float val)
|
||||
{
|
||||
transform.position = new Vector3(val, transform.position.y, transform.position.z);
|
||||
}
|
||||
public static void LeanSetPosY(this Transform transform, float val)
|
||||
{
|
||||
transform.position = new Vector3(transform.position.x, val, transform.position.z);
|
||||
}
|
||||
public static void LeanSetPosZ(this Transform transform, float val)
|
||||
{
|
||||
transform.position = new Vector3(transform.position.x, transform.position.y, val);
|
||||
}
|
||||
|
||||
public static void LeanSetLocalPosX(this Transform transform, float val)
|
||||
{
|
||||
transform.localPosition = new Vector3(val, transform.localPosition.y, transform.localPosition.z);
|
||||
}
|
||||
public static void LeanSetLocalPosY(this Transform transform, float val)
|
||||
{
|
||||
transform.localPosition = new Vector3(transform.localPosition.x, val, transform.localPosition.z);
|
||||
}
|
||||
public static void LeanSetLocalPosZ(this Transform transform, float val)
|
||||
{
|
||||
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, val);
|
||||
}
|
||||
|
||||
public static Color LeanColor(this Transform transform)
|
||||
{
|
||||
return transform.GetComponent<Renderer>().material.color;
|
||||
}
|
||||
}
|
||||
11
KFAttached/LeanTween/Framework/LeanTweenExt.cs.meta
Normal file
11
KFAttached/LeanTween/Framework/LeanTweenExt.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dbe851e9c0814f1d8f514ecf70f675d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
KFAttached/LeanTween/License.txt
Normal file
31
KFAttached/LeanTween/License.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Russell Savage - Dented Pixel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
TERMS OF USE - EASING EQUATIONS
|
||||
Open source under the BSD License.
|
||||
Copyright (c)2001 Robert Penner
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
7
KFAttached/LeanTween/License.txt.meta
Normal file
7
KFAttached/LeanTween/License.txt.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e389e9bcd4f944c338327697bd209cad
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/Misc.meta
Normal file
8
KFAttached/Misc.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e90139dce980d4840bf4b20c1114b015
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
KFAttached/Misc/AimReference.cs
Normal file
49
KFAttached/Misc/AimReference.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class AimReference : MonoBehaviour
|
||||
{
|
||||
[NonSerialized]
|
||||
public Vector3 positionOffset;
|
||||
[NonSerialized]
|
||||
public Quaternion rotationOffset;
|
||||
[NonSerialized]
|
||||
public AimReferenceGroup group;
|
||||
[NonSerialized]
|
||||
public int index = -1;
|
||||
[NonSerialized]
|
||||
public ScopeBase scopeBase;
|
||||
[SerializeField]
|
||||
private GameObject scopeBindingObject;
|
||||
public bool asReference;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (!group)
|
||||
{
|
||||
return;
|
||||
}
|
||||
scopeBase = GetComponentInParent<ScopeBase>();
|
||||
Transform refTrans = scopeBase ? scopeBase.transform : transform.parent;
|
||||
rotationOffset = Quaternion.Inverse(refTrans.rotation) * transform.rotation;
|
||||
positionOffset = refTrans.InverseTransformDirection(transform.position - refTrans.position);
|
||||
group.UpdateEnableStates();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (!group)
|
||||
{
|
||||
return;
|
||||
}
|
||||
group.UpdateEnableStates();
|
||||
}
|
||||
|
||||
public void UpdateEnableState(bool state)
|
||||
{
|
||||
if (scopeBindingObject)
|
||||
{
|
||||
scopeBindingObject.SetActive(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/Misc/AimReference.cs.meta
Normal file
11
KFAttached/Misc/AimReference.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53a21d5a88ab0034c8b0db6ea40e7d85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
KFAttached/Misc/AimReferenceGroup.cs
Normal file
62
KFAttached/Misc/AimReferenceGroup.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
public class AimReferenceGroup : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public AimReference[] aimReferences;
|
||||
private bool registered;
|
||||
|
||||
#if NotEditor
|
||||
private ActionModuleProceduralAiming.ProceduralAimingData data;
|
||||
private void Awake()
|
||||
{
|
||||
if (aimReferences != null)
|
||||
{
|
||||
foreach (var reference in aimReferences)
|
||||
{
|
||||
reference.group = this;
|
||||
}
|
||||
}
|
||||
|
||||
EntityPlayerLocal player = GetComponentInParent<EntityPlayerLocal>();
|
||||
if (aimReferences == null || aimReferences.Length == 0 || !player || player.inventory?.holdingItemData?.actionData?[1] is not IModuleContainerFor<ActionModuleProceduralAiming.ProceduralAimingData> module)
|
||||
{
|
||||
Destroy(this);
|
||||
if (aimReferences != null)
|
||||
{
|
||||
foreach (var reference in aimReferences)
|
||||
{
|
||||
Destroy(reference);
|
||||
}
|
||||
aimReferences = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
data = module.Instance;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (registered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
registered = data.RegisterGroup(aimReferences, gameObject.name);
|
||||
}
|
||||
#endif
|
||||
|
||||
internal void UpdateEnableStates()
|
||||
{
|
||||
#if NotEditor
|
||||
if (!registered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
data.UpdateCurrentReference();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
11
KFAttached/Misc/AimReferenceGroup.cs.meta
Normal file
11
KFAttached/Misc/AimReferenceGroup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93cdda222d3f0e24aa2b48c9b9fd7b81
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
KFAttached/Misc/AttachmentReference.cs
Normal file
7
KFAttached/Misc/AttachmentReference.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class AttachmentReference : MonoBehaviour
|
||||
{
|
||||
public Transform attachmentReference;
|
||||
}
|
||||
11
KFAttached/Misc/AttachmentReference.cs.meta
Normal file
11
KFAttached/Misc/AttachmentReference.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ade2782c6b27f6448984f3d9d0ef550
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
45
KFAttached/Misc/AttachmentReferenceAppended.cs
Normal file
45
KFAttached/Misc/AttachmentReferenceAppended.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AttachmentReferenceAppended : AttachmentReference
|
||||
{
|
||||
private Transform[] bindings;
|
||||
public void Merge(AnimationTargetsAbs targets)
|
||||
{
|
||||
if (attachmentReference && targets)
|
||||
{
|
||||
foreach (var bindings in attachmentReference.GetComponentsInChildren<TransformActivationBinding>(true))
|
||||
{
|
||||
bindings.targets = targets;
|
||||
}
|
||||
bindings = new Transform[attachmentReference.childCount];
|
||||
for (int i = 0; i < attachmentReference.childCount; i++)
|
||||
{
|
||||
bindings[i] = attachmentReference.GetChild(i);
|
||||
bindings[i].SetParent(targets.AttachmentRef, false);
|
||||
}
|
||||
Destroy(attachmentReference.gameObject);
|
||||
attachmentReference = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
if (bindings != null)
|
||||
{
|
||||
foreach (var binding in bindings)
|
||||
{
|
||||
if (binding)
|
||||
{
|
||||
binding.SetParent(null, false);
|
||||
Destroy(binding.gameObject);
|
||||
}
|
||||
}
|
||||
bindings = null;
|
||||
}
|
||||
if (attachmentReference)
|
||||
{
|
||||
Destroy(attachmentReference.gameObject);
|
||||
attachmentReference = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/Misc/AttachmentReferenceAppended.cs.meta
Normal file
11
KFAttached/Misc/AttachmentReferenceAppended.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2f4680216a56a6479d51c0c8a9f51a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
KFAttached/Misc/AudioSourceGroup.cs
Normal file
15
KFAttached/Misc/AudioSourceGroup.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class AudioSourceGroup
|
||||
{
|
||||
[SerializeField]
|
||||
public string groupName;
|
||||
[SerializeField]
|
||||
public AudioClip[] clips = new AudioClip[0];
|
||||
[SerializeField]
|
||||
public AudioSource source;
|
||||
|
||||
public bool IsValid => source != null && clips != null && clips.Length > 0 && source != null;
|
||||
}
|
||||
11
KFAttached/Misc/AudioSourceGroup.cs.meta
Normal file
11
KFAttached/Misc/AudioSourceGroup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8d5d39385ea6d348b03c7cdf161c572
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6
KFAttached/Misc/IgnoreTint.cs
Normal file
6
KFAttached/Misc/IgnoreTint.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class IgnoreTint : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
11
KFAttached/Misc/IgnoreTint.cs.meta
Normal file
11
KFAttached/Misc/IgnoreTint.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 122c053de47e8a14aa2aa57287456e86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
KFAttached/Misc/ItemAnimatorUpdate.cs
Normal file
31
KFAttached/Misc/ItemAnimatorUpdate.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
[DisallowMultipleComponent]
|
||||
internal class ItemAnimatorUpdate : MonoBehaviour
|
||||
{
|
||||
private Animator animator;
|
||||
private RigBuilder weaponRB;
|
||||
internal PlayableGraph graph;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
TryGetComponent<RigBuilder>(out weaponRB);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//animator.playableGraph.Evaluate(Time.deltaTime);
|
||||
animator.Update(Time.deltaTime);
|
||||
//graph.Evaluate(Time.deltaTime);
|
||||
//weaponRB?.Evaluate(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
11
KFAttached/Misc/ItemAnimatorUpdate.cs.meta
Normal file
11
KFAttached/Misc/ItemAnimatorUpdate.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b9545ce69a57b542aef2de6d8093b73
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
KFAttached/Misc/PlayerRigLateUpdate.cs
Normal file
34
KFAttached/Misc/PlayerRigLateUpdate.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[Obsolete]
|
||||
[AddComponentMenu("")]
|
||||
public class PlayerRigLateUpdate : MonoBehaviour
|
||||
{
|
||||
#if NotEditor
|
||||
//private Animator animator;
|
||||
//private RigBuilder rigBuilder;
|
||||
//private void Awake()
|
||||
//{
|
||||
// animator = GetComponent<Animator>();
|
||||
// rigBuilder = GetComponent<RigBuilder>();
|
||||
//}
|
||||
|
||||
//private void OnAnimatorMove()
|
||||
//{
|
||||
// if (rigBuilder.enabled)
|
||||
// ForceToManualUpdate();
|
||||
//}
|
||||
|
||||
//private void LateUpdate()
|
||||
//{
|
||||
// rigBuilder.Evaluate(Time.deltaTime);
|
||||
//}
|
||||
|
||||
//private void ForceToManualUpdate()
|
||||
//{
|
||||
// RigTargets.RebuildRig(animator, rigBuilder);
|
||||
//}
|
||||
#endif
|
||||
}
|
||||
11
KFAttached/Misc/PlayerRigLateUpdate.cs.meta
Normal file
11
KFAttached/Misc/PlayerRigLateUpdate.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f95fdfaecc53e6146a222aa23dd93ae2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
5
KFAttached/Misc/ScopeBase.cs
Normal file
5
KFAttached/Misc/ScopeBase.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ScopeBase : MonoBehaviour
|
||||
{
|
||||
}
|
||||
11
KFAttached/Misc/ScopeBase.cs.meta
Normal file
11
KFAttached/Misc/ScopeBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22006be69eab7844e8873de3daedd07c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
KFAttached/Misc/WeaponCameraFollow.cs
Normal file
62
KFAttached/Misc/WeaponCameraFollow.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class WeaponCameraFollow : MonoBehaviour
|
||||
{
|
||||
public RenderTexture targetTexture;
|
||||
#if NotEditor
|
||||
public ActionModuleDynamicSensitivity.DynamicSensitivityData dynamicSensitivityData;
|
||||
public EntityPlayerLocal player;
|
||||
#endif
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
#if NotEditor
|
||||
OcclusionManager.Instance.SetMultipleCameras(true);
|
||||
if (dynamicSensitivityData != null)
|
||||
{
|
||||
dynamicSensitivityData.activated = true;
|
||||
}
|
||||
//UpdateAntialiasing();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
#if NotEditor
|
||||
OcclusionManager.Instance.SetMultipleCameras(false);
|
||||
if (dynamicSensitivityData != null)
|
||||
{
|
||||
dynamicSensitivityData.activated = false;
|
||||
}
|
||||
#endif
|
||||
if (!targetTexture || !targetTexture.IsCreated())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var cmd = new CommandBuffer();
|
||||
cmd.SetRenderTarget(targetTexture);
|
||||
cmd.ClearRenderTarget(true, true, Color.black);
|
||||
Graphics.ExecuteCommandBuffer(cmd);
|
||||
cmd.Dispose();
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
public void UpdateAntialiasing()
|
||||
{
|
||||
var pipCamera = GetComponent<Camera>();
|
||||
var layer = GetComponent<PostProcessLayer>();
|
||||
var prevFsr = player.renderManager.fsr;
|
||||
int num = player.renderManager.dlssEnabled ? 0 : GamePrefs.GetInt(EnumGamePrefs.OptionsGfxAA);
|
||||
float @float = GamePrefs.GetFloat(EnumGamePrefs.OptionsGfxAASharpness);
|
||||
player.renderManager.FSRInit(layer.superResolution);
|
||||
player.renderManager.SetAntialiasing(num, @float, layer);
|
||||
Rect rect = pipCamera.rect;
|
||||
rect.x = ((layer.antialiasingMode == PostProcessLayer.Antialiasing.SuperResolution) ? 1E-07f : 0f);
|
||||
pipCamera.rect = rect;
|
||||
player.renderManager.fsr = prevFsr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
11
KFAttached/Misc/WeaponCameraFollow.cs.meta
Normal file
11
KFAttached/Misc/WeaponCameraFollow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9ea69da20db0064282418fbfd9a57c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/Render.meta
Normal file
8
KFAttached/Render.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e92eb85b5d313f248a46263f550fcc0f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
KFAttached/Render/BokehBlurTargetRef.cs
Normal file
12
KFAttached/Render/BokehBlurTargetRef.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace KFCommonUtilityLib.KFAttached.Render
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class BokehBlurTargetRef : MonoBehaviour
|
||||
{
|
||||
#if NotEditor
|
||||
internal MagnifyScope target;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
KFAttached/Render/BokehBlurTargetRef.cs.meta
Normal file
11
KFAttached/Render/BokehBlurTargetRef.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16ae170c638bd434dbe48e1b9e46ac99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
405
KFAttached/Render/MagnifyScope.cs
Normal file
405
KFAttached/Render/MagnifyScope.cs
Normal file
@@ -0,0 +1,405 @@
|
||||
#if NotEditor
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
namespace KFCommonUtilityLib.KFAttached.Render
|
||||
{
|
||||
[AddComponentMenu("KFAttachments/Render Utils/Magnify Scope")]
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class MagnifyScope : MonoBehaviour
|
||||
{
|
||||
#if NotEditor
|
||||
private static Shader newShader;
|
||||
private static FieldInfo fieldResources = AccessTools.Field(typeof(PostProcessLayer), "m_Resources");
|
||||
#endif
|
||||
private RenderTexture targetTexture;
|
||||
private Renderer renderTarget;
|
||||
|
||||
private Camera pipCamera;
|
||||
[Header("Core")]
|
||||
[SerializeField]
|
||||
private bool manualControl = false;
|
||||
[SerializeField]
|
||||
private Transform cameraJoint;
|
||||
[SerializeField]
|
||||
private float aspectRatio = 1.0f;
|
||||
[SerializeField]
|
||||
private bool hideFpvModelInScope = false;
|
||||
[SerializeField]
|
||||
private bool variableZoom = false;
|
||||
[Header("Reticle Scaling")]
|
||||
[SerializeField]
|
||||
private bool scaleReticle = false;
|
||||
[SerializeField]
|
||||
private Vector2 reticleSizeRange = new Vector2(1, 1);
|
||||
//[SerializeField]
|
||||
//private bool scaleDownReticle = false;
|
||||
//[SerializeField]
|
||||
//private float reticleScaleRatio = 1.0f;
|
||||
[Header("Camera Texture Size And Procedural Aiming")]
|
||||
[SerializeField]
|
||||
private Transform aimRef;
|
||||
[SerializeField]
|
||||
private float lensSizeFull;
|
||||
[SerializeField]
|
||||
private float lensSizeValid;
|
||||
|
||||
private float initialReticleScale = 1f;
|
||||
private float initialFov = 55f;
|
||||
private float textureHeight = Screen.height;
|
||||
|
||||
#if NotEditor
|
||||
private EntityPlayerLocal player;
|
||||
private int itemSlot = -1;
|
||||
private ItemActionZoom.ItemActionDataZoom zoomActionData;
|
||||
private bool IsVariableZoom => variableZoom && variableZoomData != null;
|
||||
private ActionModuleVariableZoom.VariableZoomData variableZoomData;
|
||||
private float targetStep = 0;
|
||||
private float currentStep = 0;
|
||||
private float stepVelocity = 0;
|
||||
#else
|
||||
[Header("Editor Debug")]
|
||||
public Camera debugCamera;
|
||||
public float debugScale = 2f;
|
||||
#endif
|
||||
private void Awake()
|
||||
{
|
||||
renderTarget = GetComponent<Renderer>();
|
||||
if (!renderTarget)
|
||||
{
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
#if NotEditor
|
||||
|
||||
if (newShader == null)
|
||||
{
|
||||
newShader = LoadManager.LoadAsset<Shader>("#@modfolder(CommonUtilityLib):Resources/PIPScope.unity3d?PIPScope.shadergraph", null, null, false, true).Asset;
|
||||
}
|
||||
if (renderTarget.material.shader.name == "Shader Graphs/MagnifyScope" || renderTarget.material.shader.name == "Shader Graphs/PIPScopeNew")
|
||||
{
|
||||
renderTarget.material.shader = newShader;
|
||||
}
|
||||
initialReticleScale = renderTarget.material.GetFloat("_ReticleScale");
|
||||
#else
|
||||
if(debugCamera == null)
|
||||
{
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
//if (!player.playerCamera.TryGetComponent<BokehBlurTargetRef>(out var bokeh))
|
||||
//{
|
||||
// bokeh = player.playerCamera.gameObject.AddComponent<BokehBlurTargetRef>();
|
||||
//}
|
||||
//bokeh.target = this;
|
||||
// Precompute rotations
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
private void Start()
|
||||
{
|
||||
var entity = GetComponentInParent<EntityPlayerLocal>();
|
||||
if (!entity)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
player = entity;
|
||||
itemSlot = player.inventory.holdingItemIdx;
|
||||
OnEnable();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
float targetFov;
|
||||
#if NotEditor
|
||||
if (!player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CalcInitialFov();
|
||||
//inventory holding item is not set when creating model, this might be an issue for items with base scope that has this script attached
|
||||
//workaround taken from alternative action module, which keeps a reference to the ItemValue being set until its custom data is created
|
||||
//afterwards it's set to null so we still need to access holding item when this method is triggered by mods
|
||||
if (itemSlot != player.inventory.holdingItemIdx)
|
||||
{
|
||||
Log.Out($"Scope shader script: Expecting holding item idx {itemSlot} but getting {player.inventory.holdingItemIdx}!");
|
||||
return;
|
||||
}
|
||||
var zoomAction = (ItemActionZoom)((ActionModuleAlternative.InventorySetItemTemp?.ItemClass ?? player.inventory.holdingItem).Actions[1]);
|
||||
zoomActionData = (ItemActionZoom.ItemActionDataZoom)player.inventory.holdingItemData.actionData[1];
|
||||
variableZoomData = (zoomActionData as IModuleContainerFor<ActionModuleVariableZoom.VariableZoomData>)?.Instance;
|
||||
if (variableZoomData != null && (variableZoom || variableZoomData.forceFov))
|
||||
{
|
||||
if (variableZoom)
|
||||
{
|
||||
variableZoomData.shouldUpdate = false;
|
||||
targetStep = currentStep = variableZoomData.curStep;
|
||||
stepVelocity = 0f;
|
||||
targetFov = CalcCurrentFov();
|
||||
}
|
||||
else
|
||||
{
|
||||
targetFov = variableZoomData.fovRange.min;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string originalRatio = zoomAction.Properties.GetString("ZoomRatio");
|
||||
if (string.IsNullOrEmpty(originalRatio))
|
||||
{
|
||||
originalRatio = "0";
|
||||
}
|
||||
targetFov = StringParsers.ParseFloat(player.inventory.holdingItemItemValue.GetPropertyOverride("ZoomRatio", originalRatio));
|
||||
targetFov = ScaleToFov(targetFov);
|
||||
}
|
||||
|
||||
#else
|
||||
if(debugCamera == null)
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
targetFov = Mathf.Rad2Deg * 2 * Mathf.Atan(Mathf.Tan(Mathf.Deg2Rad * 27.5f) / Mathf.Sqrt(debugScale));
|
||||
#endif
|
||||
CreateCamera();
|
||||
UpdateFOV(targetFov);
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
private void Update()
|
||||
{
|
||||
if (IsVariableZoom)
|
||||
{
|
||||
if (variableZoomData.shouldUpdate)
|
||||
{
|
||||
variableZoomData.shouldUpdate = false;
|
||||
targetStep = variableZoomData.curStep;
|
||||
}
|
||||
if (currentStep != targetStep)
|
||||
{
|
||||
if (variableZoomData.isToggleOnly)
|
||||
{
|
||||
currentStep = targetStep;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentStep = Mathf.SmoothDamp(currentStep, targetStep, ref stepVelocity, 0.05f);
|
||||
}
|
||||
UpdateFOV(CalcCurrentFov());
|
||||
}
|
||||
}
|
||||
|
||||
if (!manualControl && zoomActionData != null)
|
||||
{
|
||||
if (player.bFirstPersonView)
|
||||
{
|
||||
bool aimingGun = player.AimingGun;
|
||||
if (aimingGun && !pipCamera.gameObject.activeSelf)
|
||||
{
|
||||
pipCamera.gameObject.SetActive(true);
|
||||
}
|
||||
else if (!aimingGun && !zoomActionData.bZoomInProgress && pipCamera.gameObject.activeSelf)
|
||||
{
|
||||
pipCamera.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
else if (pipCamera.gameObject.activeSelf)
|
||||
{
|
||||
pipCamera.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
DestroyCamera();
|
||||
#if NotEditor
|
||||
currentStep = targetStep = stepVelocity = 0f;
|
||||
#else
|
||||
if(debugCamera == null)
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private float ScaleToFov(float scale)
|
||||
{
|
||||
return Mathf.Rad2Deg * 2 * Mathf.Atan(Mathf.Tan(Mathf.Deg2Rad * initialFov * 0.5f) / scale);
|
||||
}
|
||||
|
||||
private float FovToScale(float fov)
|
||||
{
|
||||
return Mathf.Tan(Mathf.Deg2Rad * initialFov * 0.5f) / Mathf.Tan(Mathf.Deg2Rad * fov * 0.5f);
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
private void CalcInitialFov()
|
||||
{
|
||||
if (aimRef)
|
||||
{
|
||||
var distance = Mathf.Abs(Vector3.Dot(renderTarget.bounds.center - aimRef.position, aimRef.forward));
|
||||
var scaleFov = lensSizeValid / (2 * distance * Mathf.Tan(Mathf.Deg2Rad * 27.5f));
|
||||
var scaleTexture = lensSizeFull / (2 * distance * Mathf.Tan(Mathf.Deg2Rad * 27.5f));
|
||||
textureHeight = scaleTexture * Screen.height;
|
||||
//textureHeight = Mathf.Abs(player.playerCamera.WorldToScreenPoint(player.playerCamera.transform.forward * distance + player.playerCamera.transform.up * height).y -
|
||||
// player.playerCamera.WorldToScreenPoint(player.playerCamera.transform.forward * distance - player.playerCamera.transform.up * height).y);
|
||||
initialFov = Mathf.Rad2Deg * 2 * Mathf.Atan(Mathf.Tan(Mathf.Deg2Rad * 27.5f) * scaleFov);
|
||||
Log.Out($"distance {distance}, scale fov {scaleFov}, scale texture {scaleTexture} texture height {textureHeight} initial fov {initialFov}");
|
||||
return;
|
||||
}
|
||||
textureHeight = Screen.height * 0.5f;
|
||||
initialFov = 15;
|
||||
}
|
||||
|
||||
private static float CalcFovStep(float t, float fovMin, float fovMax)
|
||||
{
|
||||
return 2f * Mathf.Rad2Deg * Mathf.Atan(Mathf.Lerp(Mathf.Tan(fovMax * 0.5f * Mathf.Deg2Rad), Mathf.Tan(fovMin * 0.5f * Mathf.Deg2Rad), t));
|
||||
}
|
||||
|
||||
private float CalcCurrentFov()
|
||||
{
|
||||
if (!IsVariableZoom)
|
||||
{
|
||||
throw new Exception("Variable Zoom is not set!");
|
||||
}
|
||||
float targetFov;
|
||||
if (variableZoomData.forceFov)
|
||||
{
|
||||
targetFov = CalcFovStep(currentStep, variableZoomData.fovRange.min, variableZoomData.fovRange.max);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetFov = ScaleToFov(Mathf.Lerp(variableZoomData.minScale, variableZoomData.maxScale, currentStep));
|
||||
}
|
||||
return targetFov;
|
||||
}
|
||||
#endif
|
||||
|
||||
private void DestroyCamera()
|
||||
{
|
||||
if (targetTexture && targetTexture.IsCreated())
|
||||
{
|
||||
targetTexture.Release();
|
||||
Destroy(targetTexture);
|
||||
}
|
||||
if (pipCamera)
|
||||
{
|
||||
Destroy(pipCamera.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFOV(float targetFov)
|
||||
{
|
||||
if (targetFov > 0)
|
||||
{
|
||||
pipCamera.fieldOfView = targetFov;
|
||||
#if NotEditor
|
||||
if (scaleReticle && IsVariableZoom)
|
||||
{
|
||||
renderTarget.material.SetFloat("_ReticleScale", Mathf.Lerp(reticleSizeRange.x, reticleSizeRange.y, currentStep));
|
||||
//if (variableZoomData.maxScale > variableZoomData.minScale)
|
||||
//{
|
||||
// float minScale;
|
||||
// if (reticleScaleRatio >= 1)
|
||||
// {
|
||||
// minScale = scaleDownReticle ? 1 - (variableZoomData.maxScale * reticleScaleRatio - variableZoomData.minScale) / (variableZoomData.maxScale * reticleScaleRatio) : 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// minScale = scaleDownReticle ? 1 - reticleScaleRatio * (variableZoomData.maxScale - variableZoomData.minScale) / variableZoomData.maxScale : 1;
|
||||
// }
|
||||
// float maxScale;
|
||||
// if (reticleScaleRatio >= 1)
|
||||
// {
|
||||
// maxScale = scaleDownReticle ? 1 : variableZoomData.maxScale * reticleScaleRatio / variableZoomData.minScale;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// maxScale = scaleDownReticle ? 1 : 1 + reticleScaleRatio * (variableZoomData.maxScale - variableZoomData.minScale) / variableZoomData.minScale;
|
||||
// }
|
||||
// float reticleScale = Mathf.Lerp(minScale, maxScale, variableZoomData.curStep);
|
||||
// renderTarget.material.SetFloat("_ReticleScale", initialReticleScale / reticleScale);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// renderTarget.material.SetFloat("_ReticleScale", initialReticleScale);
|
||||
//}
|
||||
}
|
||||
//Log.Out($"target fov {targetFov} target scale {targetScale}");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateCamera()
|
||||
{
|
||||
const float texScale = 1f;
|
||||
targetTexture = new RenderTexture((int)(textureHeight * aspectRatio), (int)(textureHeight), 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear)
|
||||
{
|
||||
filterMode = FilterMode.Bilinear,
|
||||
wrapMode = TextureWrapMode.Clamp
|
||||
};
|
||||
renderTarget.material.mainTexture = targetTexture;
|
||||
GameObject cameraGO = new GameObject("KFPiPCam");
|
||||
if (cameraJoint != null)
|
||||
{
|
||||
cameraGO.transform.parent = cameraJoint.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
cameraGO.transform.parent = transform;
|
||||
}
|
||||
|
||||
pipCamera = cameraGO.AddComponent<Camera>();
|
||||
pipCamera.targetTexture = targetTexture;
|
||||
pipCamera.depth = -2;
|
||||
pipCamera.fieldOfView = 55;
|
||||
pipCamera.nearClipPlane = 0.05f;
|
||||
pipCamera.farClipPlane = 5000;
|
||||
pipCamera.aspect = aspectRatio;
|
||||
pipCamera.rect = new Rect(0, 0, texScale, texScale);
|
||||
#if NotEditor
|
||||
//pipCamera.CopyFrom(player.playerCamera);
|
||||
pipCamera.cullingMask = player.playerCamera.cullingMask;
|
||||
//renderTarget.material.SetFloat("_AspectMain", player.playerCamera.aspect);
|
||||
//renderTarget.material.SetFloat("_AspectScope", pipCamera.aspect);
|
||||
#else
|
||||
pipCamera.CopyFrom(debugCamera);
|
||||
#endif
|
||||
if (cameraJoint == null || hideFpvModelInScope)
|
||||
{
|
||||
pipCamera.cullingMask &= ~(1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
pipCamera.cullingMask |= 1024;
|
||||
}
|
||||
cameraGO.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
cameraGO.transform.localScale = Vector3.one;
|
||||
|
||||
#if NotEditor
|
||||
WeaponCameraFollow weaponCameraFollow = cameraGO.AddComponent<WeaponCameraFollow>();
|
||||
weaponCameraFollow.targetTexture = targetTexture;
|
||||
weaponCameraFollow.dynamicSensitivityData = (zoomActionData as IModuleContainerFor<ActionModuleDynamicSensitivity.DynamicSensitivityData>)?.Instance;
|
||||
weaponCameraFollow.player = player;
|
||||
var old = player.playerCamera.GetComponent<PostProcessLayer>();
|
||||
var layer = pipCamera.gameObject.GetOrAddComponent<PostProcessLayer>();
|
||||
//layer.antialiasingMode = old.antialiasingMode;
|
||||
//layer.superResolution = (SuperResolution)old.superResolution.GetType().CreateInstance();
|
||||
layer.Init(fieldResources.GetValue(old) as PostProcessResources);
|
||||
//weaponCameraFollow.UpdateAntialiasing();
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void RenderImageCallback(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/Render/MagnifyScope.cs.meta
Normal file
11
KFAttached/Render/MagnifyScope.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54496e2804e57d84da57d0241db8bdf6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
KFAttached/Render/MagnifyScopeTargetRef.cs
Normal file
38
KFAttached/Render/MagnifyScopeTargetRef.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KFCommonUtilityLib.KFAttached.Render
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
internal class MagnifyScopeTargetRef : MonoBehaviour
|
||||
{
|
||||
private HashSet<MagnifyScope> targets = new HashSet<MagnifyScope>();
|
||||
|
||||
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
foreach (var target in targets)
|
||||
{
|
||||
target.RenderImageCallback(source, destination);
|
||||
}
|
||||
Graphics.Blit(source, destination);
|
||||
}
|
||||
|
||||
internal void AddTarget(MagnifyScope target)
|
||||
{
|
||||
if (targets.Count == 0)
|
||||
{
|
||||
enabled = true;
|
||||
}
|
||||
targets.Add(target);
|
||||
}
|
||||
|
||||
internal void RemoveTarget(MagnifyScope target)
|
||||
{
|
||||
targets.Remove(target);
|
||||
if(targets.Count == 0 )
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/Render/MagnifyScopeTargetRef.cs.meta
Normal file
11
KFAttached/Render/MagnifyScopeTargetRef.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b65f1de3a5df39443a8af191b067c5d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/RigAdaptors.meta
Normal file
8
KFAttached/RigAdaptors.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fabd6babec972349939cbd377f41ba1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/RigAdaptors/Adaptors.meta
Normal file
8
KFAttached/RigAdaptors/Adaptors.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cecc0dfc3c12e4f4dab5bbe3f4ba7c1d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
KFAttached/RigAdaptors/Adaptors/BlendConstraintAdaptor.cs
Normal file
56
KFAttached/RigAdaptors/Adaptors/BlendConstraintAdaptor.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class BlendConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private Transform m_SourceA;
|
||||
[SerializeField]
|
||||
private Transform m_SourceB;
|
||||
[SerializeField]
|
||||
private bool m_BlendPosition;
|
||||
[SerializeField]
|
||||
private bool m_BlendRotation;
|
||||
[SerializeField]
|
||||
private float m_PositionWeight;
|
||||
[SerializeField]
|
||||
private float m_RotationWeight;
|
||||
[SerializeField]
|
||||
private bool m_MaintainPositionOffsets;
|
||||
[SerializeField]
|
||||
private bool m_MaintainRotationOffsets;
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<BlendConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject?.name;
|
||||
m_SourceA = constraint.data.sourceObjectA;
|
||||
m_SourceB = constraint.data.sourceObjectB;
|
||||
m_BlendPosition = constraint.data.blendPosition;
|
||||
m_BlendRotation = constraint.data.blendRotation;
|
||||
m_PositionWeight = constraint.data.positionWeight;
|
||||
m_RotationWeight = constraint.data.rotationWeight;
|
||||
m_MaintainPositionOffsets = constraint.data.maintainPositionOffsets;
|
||||
m_MaintainRotationOffsets = constraint.data.maintainRotationOffsets;
|
||||
}
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<BlendConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = targetRoot.FindInAllChildren(m_ConstrainedObject);
|
||||
constraint.data.sourceObjectA = m_SourceA;
|
||||
constraint.data.sourceObjectB = m_SourceB;
|
||||
constraint.data.blendPosition = m_BlendPosition;
|
||||
constraint.data.blendRotation = m_BlendRotation;
|
||||
constraint.data.positionWeight = m_PositionWeight;
|
||||
constraint.data.rotationWeight = m_RotationWeight;
|
||||
constraint.data.maintainPositionOffsets = m_MaintainPositionOffsets;
|
||||
constraint.data.maintainRotationOffsets = m_MaintainRotationOffsets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2ca56f5a0b464646817033fcff9f693
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
KFAttached/RigAdaptors/Adaptors/ChainIKConstraintAdaptor.cs
Normal file
56
KFAttached/RigAdaptors/Adaptors/ChainIKConstraintAdaptor.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class ChainIKConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_Root;
|
||||
[SerializeField]
|
||||
private string m_Tip;
|
||||
[SerializeField]
|
||||
private Transform m_Target;
|
||||
[SerializeField]
|
||||
private float m_ChainRotationWeight;
|
||||
[SerializeField]
|
||||
private float m_TipRotationWeight;
|
||||
[SerializeField]
|
||||
private int m_MaxIterations;
|
||||
[SerializeField]
|
||||
private float m_Tolerance;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetPositionOffset;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetRotationOffset;
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<ChainIKConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Root = constraint.data.root?.name;
|
||||
m_Tip = constraint.data.tip?.name;
|
||||
m_Target = constraint.data.target;
|
||||
m_ChainRotationWeight = constraint.data.chainRotationWeight;
|
||||
m_TipRotationWeight = constraint.data.tipRotationWeight;
|
||||
m_MaxIterations = constraint.data.maxIterations;
|
||||
m_Tolerance = constraint.data.tolerance;
|
||||
m_MaintainTargetPositionOffset = constraint.data.maintainTargetPositionOffset;
|
||||
m_MaintainTargetRotationOffset = constraint.data.maintainTargetRotationOffset;
|
||||
}
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<ChainIKConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.root = targetRoot.FindInAllChildren(m_Root);
|
||||
constraint.data.tip = targetRoot.FindInAllChildren(m_Tip);
|
||||
constraint.data.target = m_Target;
|
||||
constraint.data.chainRotationWeight = m_ChainRotationWeight;
|
||||
constraint.data.tipRotationWeight = m_TipRotationWeight;
|
||||
constraint.data.maxIterations = m_MaxIterations;
|
||||
constraint.data.tolerance = m_Tolerance;
|
||||
constraint.data.maintainTargetPositionOffset = m_MaintainTargetPositionOffset;
|
||||
constraint.data.maintainTargetRotationOffset = m_MaintainTargetRotationOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b4dd415747e268478ef7e27093e78a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
KFAttached/RigAdaptors/Adaptors/DampedTransformAdaptor.cs
Normal file
38
KFAttached/RigAdaptors/Adaptors/DampedTransformAdaptor.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class DampedTransformAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private Transform m_Source;
|
||||
[SerializeField]
|
||||
private float m_DampPosition;
|
||||
[SerializeField]
|
||||
private float m_DampRotation;
|
||||
[SerializeField]
|
||||
private bool m_MaintainAim;
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<DampedTransform>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject?.name;
|
||||
m_Source = constraint.data.sourceObject;
|
||||
m_DampPosition = constraint.data.dampPosition;
|
||||
m_DampRotation = constraint.data.dampRotation;
|
||||
m_MaintainAim = constraint.data.maintainAim;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<DampedTransform>();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = targetRoot.FindInAllChildren(m_ConstrainedObject);
|
||||
constraint.data.sourceObject = m_Source;
|
||||
constraint.data.dampPosition = m_DampPosition;
|
||||
constraint.data.dampRotation = m_DampRotation;
|
||||
constraint.data.maintainAim = m_MaintainAim;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7eae293f02f20ea4e83de9504d5a5f93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/RigAdaptors/Adaptors/Data.meta
Normal file
8
KFAttached/RigAdaptors/Adaptors/Data.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28f7c996c8fc946498369133083c03d9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
KFAttached/RigAdaptors/Adaptors/Data/TwistNode.cs
Normal file
22
KFAttached/RigAdaptors/Adaptors/Data/TwistNode.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KFCommonUtilityLib.RigAdaptors.Adaptors.Data
|
||||
{
|
||||
[Serializable]
|
||||
public class TwistNode
|
||||
{
|
||||
[SerializeField]
|
||||
public string name;
|
||||
[SerializeField]
|
||||
public float weight;
|
||||
|
||||
public TwistNode() { }
|
||||
|
||||
public TwistNode(string name, float weight)
|
||||
{
|
||||
this.name = name;
|
||||
this.weight = weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/RigAdaptors/Adaptors/Data/TwistNode.cs.meta
Normal file
11
KFAttached/RigAdaptors/Adaptors/Data/TwistNode.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce4dc6aaaa5e6564d8f5975388620f86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
KFAttached/RigAdaptors/Adaptors/MultiAimConstraintAdaptor.cs
Normal file
68
KFAttached/RigAdaptors/Adaptors/MultiAimConstraintAdaptor.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiAimConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private WeightedTransformArray m_SourceObjects;
|
||||
[SerializeField]
|
||||
private Vector3 m_Offset;
|
||||
[SerializeField]
|
||||
private Vector2 m_limits;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.Axis m_AimAxis;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.Axis m_UpAxis;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.WorldUpType m_WorldUpType;
|
||||
[SerializeField]
|
||||
private string m_WorldUpObject;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.Axis m_WorldUpAxis;
|
||||
[SerializeField]
|
||||
private bool m_MaintainOffset;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedAxes;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiAimConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = targetRoot.FindInAllChildren(m_ConstrainedObject);
|
||||
constraint.data.sourceObjects = m_SourceObjects;
|
||||
constraint.data.offset = m_Offset;
|
||||
constraint.data.limits = m_limits;
|
||||
constraint.data.aimAxis = m_AimAxis;
|
||||
constraint.data.upAxis = m_UpAxis;
|
||||
constraint.data.worldUpType = m_WorldUpType;
|
||||
if (!string.IsNullOrEmpty(m_WorldUpObject))
|
||||
constraint.data.worldUpObject = targetRoot.FindInAllChildren(m_WorldUpObject);
|
||||
constraint.data.worldUpAxis = m_WorldUpAxis;
|
||||
constraint.data.maintainOffset = m_MaintainOffset;
|
||||
constraint.data.constrainedXAxis = m_ConstrainedAxes.x;
|
||||
constraint.data.constrainedYAxis = m_ConstrainedAxes.y;
|
||||
constraint.data.constrainedZAxis = m_ConstrainedAxes.z;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiAimConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject?.name;
|
||||
m_SourceObjects = constraint.data.sourceObjects;
|
||||
m_Offset = constraint.data.offset;
|
||||
m_limits = constraint.data.limits;
|
||||
m_AimAxis = constraint.data.aimAxis;
|
||||
m_UpAxis = constraint.data.upAxis;
|
||||
m_WorldUpType = constraint.data.worldUpType;
|
||||
if ((m_WorldUpType == MultiAimConstraintData.WorldUpType.ObjectUp || m_WorldUpType == MultiAimConstraintData.WorldUpType.ObjectRotationUp) && constraint.data.worldUpObject)
|
||||
m_WorldUpObject = constraint.data.worldUpObject.name;
|
||||
m_WorldUpAxis = constraint.data.worldUpAxis;
|
||||
m_MaintainOffset = constraint.data.maintainOffset;
|
||||
m_ConstrainedAxes = new Vector3Bool(constraint.data.constrainedXAxis, constraint.data.constrainedYAxis, constraint.data.constrainedZAxis);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80b6e2441c0c1ab46a65e9ff120057de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiParentConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private WeightedTransformArray m_SourceObjects;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedPositionAxes;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedRotationAxes;
|
||||
[SerializeField]
|
||||
private bool m_MaintainPositionOffset;
|
||||
[SerializeField]
|
||||
private bool m_MaintainRotationOffset;
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiParentConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = targetRoot.FindInAllChildren(m_ConstrainedObject);
|
||||
constraint.data.sourceObjects = m_SourceObjects;
|
||||
constraint.data.constrainedPositionXAxis = m_ConstrainedPositionAxes.x;
|
||||
constraint.data.constrainedPositionYAxis = m_ConstrainedPositionAxes.y;
|
||||
constraint.data.constrainedPositionZAxis = m_ConstrainedPositionAxes.z;
|
||||
constraint.data.constrainedRotationXAxis = m_ConstrainedRotationAxes.x;
|
||||
constraint.data.constrainedRotationYAxis = m_ConstrainedRotationAxes.y;
|
||||
constraint.data.constrainedRotationZAxis = m_ConstrainedRotationAxes.z;
|
||||
constraint.data.maintainPositionOffset = m_MaintainPositionOffset;
|
||||
constraint.data.maintainRotationOffset = m_MaintainRotationOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiParentConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject?.name;
|
||||
m_SourceObjects = constraint.data.sourceObjects;
|
||||
m_ConstrainedPositionAxes = new Vector3Bool(constraint.data.constrainedPositionXAxis, constraint.data.constrainedPositionYAxis, constraint.data.constrainedPositionZAxis);
|
||||
m_ConstrainedRotationAxes = new Vector3Bool(constraint.data.constrainedRotationXAxis, constraint.data.constrainedRotationYAxis, constraint.data.constrainedRotationZAxis);
|
||||
m_MaintainPositionOffset = constraint.data.maintainPositionOffset;
|
||||
m_MaintainRotationOffset = constraint.data.maintainRotationOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1efc37cc0b8c5d748832a228eef2373c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiPositionConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private WeightedTransformArray m_SourceObjects;
|
||||
[SerializeField]
|
||||
private Vector3 m_Offset;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedAxes;
|
||||
[SerializeField]
|
||||
private bool m_MaintainOffset;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiPositionConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = targetRoot.FindInAllChildren(m_ConstrainedObject);
|
||||
constraint.data.sourceObjects = m_SourceObjects;
|
||||
constraint.data.offset = m_Offset;
|
||||
constraint.data.constrainedXAxis = m_ConstrainedAxes.x;
|
||||
constraint.data.constrainedYAxis = m_ConstrainedAxes.y;
|
||||
constraint.data.constrainedZAxis = m_ConstrainedAxes.z;
|
||||
constraint.data.maintainOffset = m_MaintainOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiPositionConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject?.name;
|
||||
m_SourceObjects = constraint.data.sourceObjects;
|
||||
m_Offset = constraint.data.offset;
|
||||
m_ConstrainedAxes = new Vector3Bool(constraint.data.constrainedXAxis, constraint.data.constrainedYAxis, constraint.data.constrainedZAxis);
|
||||
m_MaintainOffset = constraint.data.maintainOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d705cece31c4abd4495c5fdf8203afe5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiReferentialConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private int m_Driver;
|
||||
[SerializeField]
|
||||
private List<Transform> m_SourceObjects;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiReferentialConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.driver = m_Driver;
|
||||
constraint.data.sourceObjects = m_SourceObjects;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiReferentialConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Driver = constraint.data.driver;
|
||||
m_SourceObjects = constraint.data.sourceObjects;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e103ecfa73363f14a90b16031c25e8b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiRotationConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private WeightedTransformArray m_SourceObjects;
|
||||
[SerializeField]
|
||||
private Vector3 m_Offset;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedAxes;
|
||||
[SerializeField]
|
||||
private bool m_MaintainOffset;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiRotationConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = targetRoot.FindInAllChildren(m_ConstrainedObject);
|
||||
constraint.data.sourceObjects = m_SourceObjects;
|
||||
constraint.data.offset = m_Offset;
|
||||
constraint.data.constrainedXAxis = m_ConstrainedAxes.x;
|
||||
constraint.data.constrainedYAxis = m_ConstrainedAxes.y;
|
||||
constraint.data.constrainedZAxis = m_ConstrainedAxes.z;
|
||||
constraint.data.maintainOffset = m_MaintainOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiRotationConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject?.name;
|
||||
m_SourceObjects = constraint.data.sourceObjects;
|
||||
m_Offset = constraint.data.offset;
|
||||
m_ConstrainedAxes = new Vector3Bool(constraint.data.constrainedXAxis, constraint.data.constrainedYAxis, constraint.data.constrainedZAxis);
|
||||
m_MaintainOffset = constraint.data.maintainOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de8f43467d976b544b7967ab5425d23b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
KFAttached/RigAdaptors/Adaptors/OverrideTransformAdaptor.cs
Normal file
48
KFAttached/RigAdaptors/Adaptors/OverrideTransformAdaptor.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class OverrideTransformAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private Transform m_OverrideSource;
|
||||
[SerializeField]
|
||||
private Vector3 m_OverridePosition;
|
||||
[SerializeField]
|
||||
private Vector3 m_OverrideRotation;
|
||||
[SerializeField]
|
||||
private float m_PositionWeight;
|
||||
[SerializeField]
|
||||
private float m_RotationWeight;
|
||||
[SerializeField]
|
||||
private OverrideTransformData.Space m_Space;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<OverrideTransform>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = targetRoot.FindInAllChildren(m_ConstrainedObject);
|
||||
constraint.data.sourceObject = m_OverrideSource;
|
||||
constraint.data.position = m_OverridePosition;
|
||||
constraint.data.rotation = m_OverrideRotation;
|
||||
constraint.data.positionWeight = m_PositionWeight;
|
||||
constraint.data.rotationWeight = m_RotationWeight;
|
||||
constraint.data.space = m_Space;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<OverrideTransform>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject?.name;
|
||||
m_OverrideSource = constraint.data.sourceObject;
|
||||
m_OverridePosition = constraint.data.position;
|
||||
m_OverrideRotation = constraint.data.rotation;
|
||||
m_PositionWeight = constraint.data.positionWeight;
|
||||
m_RotationWeight = constraint.data.rotationWeight;
|
||||
m_Space = constraint.data.space;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b059f9f28d4d2e46a30530eeede98a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
KFAttached/RigAdaptors/Adaptors/RigAdaptorAbs.cs
Normal file
34
KFAttached/RigAdaptors/Adaptors/RigAdaptorAbs.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
public abstract class RigAdaptorAbs : MonoBehaviour
|
||||
{
|
||||
[NonSerialized]
|
||||
public Transform targetRoot;
|
||||
[SerializeField]
|
||||
protected float weight = 1f;
|
||||
public abstract void ReadRigData();
|
||||
public abstract void FindRigTargets();
|
||||
|
||||
protected void WeightedTransformArrayToAdaptor(WeightedTransformArray array, out string[] transforms, out float[] weights)
|
||||
{
|
||||
transforms = new string[array.Count];
|
||||
weights = new float[array.Count];
|
||||
for (int i = 0; i < array.Count; i++)
|
||||
{
|
||||
transforms[i] = array[i].transform?.name;
|
||||
weights[i] = array[i].weight;
|
||||
}
|
||||
}
|
||||
|
||||
protected WeightedTransformArray WeightedTransformArrayFromAdaptor(Transform targetRoot, string[] transforms, float[] weights)
|
||||
{
|
||||
WeightedTransformArray array = new WeightedTransformArray();
|
||||
for (int i = 0; i < transforms.Length; i++)
|
||||
{
|
||||
array.Add(new WeightedTransform(targetRoot.FindInAllChildren(transforms[i]), weights[i]));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
11
KFAttached/RigAdaptors/Adaptors/RigAdaptorAbs.cs.meta
Normal file
11
KFAttached/RigAdaptors/Adaptors/RigAdaptorAbs.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a19d5243587a11344927b47b3a9240fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class TwistChainConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_Root;
|
||||
[SerializeField]
|
||||
private string m_Tip;
|
||||
[SerializeField]
|
||||
private Transform m_RootTarget;
|
||||
[SerializeField]
|
||||
private Transform m_TipTarget;
|
||||
[SerializeField]
|
||||
private AnimationCurve m_Curve;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<TwistChainConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.root = targetRoot.FindInAllChildren(m_Root);
|
||||
constraint.data.tip = targetRoot.FindInAllChildren(m_Tip);
|
||||
constraint.data.rootTarget = m_RootTarget;
|
||||
constraint.data.tipTarget = m_TipTarget;
|
||||
constraint.data.curve = m_Curve;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<TwistChainConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Root = constraint.data.root?.name;
|
||||
m_Tip = constraint.data.tip?.name;
|
||||
m_RootTarget = constraint.data.rootTarget;
|
||||
m_TipTarget = constraint.data.tipTarget;
|
||||
m_Curve = constraint.data.curve;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e71b15efb8d89b9428eaee7b14e80f8d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
KFAttached/RigAdaptors/Adaptors/TwistCorrectionAdaptor.cs
Normal file
50
KFAttached/RigAdaptors/Adaptors/TwistCorrectionAdaptor.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class TwistCorrectionAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_Source;
|
||||
[SerializeField]
|
||||
private TwistCorrectionData.Axis m_TwistAxis;
|
||||
[SerializeField]
|
||||
private string[] m_TwistNodes;
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<TwistCorrection>();
|
||||
if (m_TwistNodes == null)
|
||||
{
|
||||
Log.Error("twist nodes array not serialized!");
|
||||
Component.Destroy(constraint);
|
||||
Component.Destroy(this);
|
||||
return;
|
||||
}
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.sourceObject = targetRoot.FindInAllChildren(m_Source);
|
||||
constraint.data.twistAxis = m_TwistAxis;
|
||||
var twistNodes = new WeightedTransformArray(m_TwistNodes.Length);
|
||||
for (int i = 0; i < m_TwistNodes.Length; i++)
|
||||
{
|
||||
string[] node = m_TwistNodes[i].Split(';');
|
||||
if (node.Length == 2)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(node[0]))
|
||||
twistNodes.SetTransform(i, targetRoot.FindInAllChildren(node[0]));
|
||||
twistNodes.SetWeight(i, float.Parse(node[1]));
|
||||
}
|
||||
}
|
||||
constraint.data.twistNodes = twistNodes;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<TwistCorrection>();
|
||||
weight = constraint.weight;
|
||||
m_Source = constraint.data.sourceObject.name;
|
||||
m_TwistAxis = constraint.data.twistAxis;
|
||||
m_TwistNodes = constraint.data.twistNodes.Select(n => (n.transform.gameObject?.name ?? "") + ';' + n.weight.ToString()).ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0de395249ff56c646ab5045a6b20568a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class TwoBoneIKConstraintAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_Root;
|
||||
[SerializeField]
|
||||
private string m_Mid;
|
||||
[SerializeField]
|
||||
private string m_Tip;
|
||||
[SerializeField]
|
||||
private Transform m_Target;
|
||||
[SerializeField]
|
||||
private Transform m_Hint;
|
||||
[SerializeField]
|
||||
private float m_TargetPositionWeight;
|
||||
[SerializeField]
|
||||
private float m_TargetRotationWeight;
|
||||
[SerializeField]
|
||||
private float m_HintWeight;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetPositionOffset;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetRotationOffset;
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<TwoBoneIKConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.root = targetRoot.FindInAllChildren(m_Root);
|
||||
constraint.data.mid = targetRoot.FindInAllChildren(m_Mid);
|
||||
constraint.data.tip = targetRoot.FindInAllChildren(m_Tip);
|
||||
constraint.data.target = m_Target;
|
||||
constraint.data.hint = m_Hint;
|
||||
constraint.data.targetPositionWeight = m_TargetPositionWeight;
|
||||
constraint.data.targetRotationWeight = m_TargetRotationWeight;
|
||||
constraint.data.hintWeight = m_HintWeight;
|
||||
constraint.data.maintainTargetPositionOffset = m_MaintainTargetPositionOffset;
|
||||
constraint.data.maintainTargetRotationOffset = m_MaintainTargetRotationOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<TwoBoneIKConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Root = constraint.data.root?.name;
|
||||
m_Mid = constraint.data.mid?.name;
|
||||
m_Tip = constraint.data.tip?.name;
|
||||
m_Target = constraint.data.target;
|
||||
m_Hint = constraint.data.hint;
|
||||
m_TargetPositionWeight = constraint.data.targetPositionWeight;
|
||||
m_TargetRotationWeight = constraint.data.targetRotationWeight;
|
||||
m_HintWeight = constraint.data.hintWeight;
|
||||
m_MaintainTargetPositionOffset = constraint.data.maintainTargetPositionOffset;
|
||||
m_MaintainTargetRotationOffset = constraint.data.maintainTargetRotationOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 917124d705d34eb4bb6e982c423de951
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
542
KFAttached/RigAdaptors/AnimationTargetsAbs.cs
Normal file
542
KFAttached/RigAdaptors/AnimationTargetsAbs.cs
Normal file
@@ -0,0 +1,542 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib.Scripts.StaticManagers;
|
||||
using UniLinq;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public abstract class AnimationTargetsAbs : MonoBehaviour
|
||||
{
|
||||
protected enum ParentName
|
||||
{
|
||||
Spine3,
|
||||
LeftHand,
|
||||
RightHand,
|
||||
}
|
||||
protected static readonly string[] ParentNames = { "Spine3", "LeftHand", "RightHand" };
|
||||
protected static string GetParentName(ParentName name) => ParentNames[(int)name];
|
||||
[Header("TPV Fields")]
|
||||
[SerializeField]
|
||||
protected Transform itemTpv;
|
||||
[SerializeField]
|
||||
protected RuntimeAnimatorController weaponRuntimeControllerTpv;
|
||||
[SerializeField]
|
||||
protected AvatarMask weaponRigMaskTpv;
|
||||
[SerializeField]
|
||||
protected ParentName parentNameTpv;
|
||||
|
||||
private Rig[] rigTpv;
|
||||
private RigLayer[] rigLayerTpv;
|
||||
protected Animator itemAnimatorTpv;
|
||||
protected bool fpvSet = false;
|
||||
protected bool tpvSet = false;
|
||||
private Dictionary<string, GameObject> dict_attachments = new Dictionary<string, GameObject>();
|
||||
|
||||
public abstract Transform ItemFpv { get; protected set; }
|
||||
public abstract Transform AttachmentRef { get; protected set; }
|
||||
public Transform ItemTpv { get => itemTpv; protected set => itemTpv = value; }
|
||||
public Transform ItemTpvOrSelf => itemTpv ? itemTpv : transform;
|
||||
public bool IsFpv { get; set; }
|
||||
public bool IsAnimationSet => (IsFpv && fpvSet) || (!IsFpv && tpvSet);
|
||||
public bool Destroyed { get; protected set; }
|
||||
public Transform PlayerAnimatorTrans { get; private set; }
|
||||
public Animator ItemAnimator => IsFpv ? ItemAnimatorFpv : ItemAnimatorTpv;
|
||||
public Transform ItemCurrent => IsFpv ? ItemFpv : ItemTpv;
|
||||
public Transform ItemCurrentOrDefault => IsFpv ? ItemFpv : ItemTpvOrSelf;
|
||||
public AnimationGraphBuilder GraphBuilder { get; private set; }
|
||||
|
||||
protected abstract Animator ItemAnimatorFpv { get; }
|
||||
protected virtual Animator ItemAnimatorTpv => itemAnimatorTpv;
|
||||
|
||||
private Transform spine1, spine2, spine3;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
foreach (var bindings in GetComponentsInChildren<TransformActivationBinding>(true))
|
||||
{
|
||||
bindings.targets = this;
|
||||
}
|
||||
#if NotEditor
|
||||
gameObject.GetOrAddComponent<AttachmentReference>().attachmentReference = AttachmentRef;
|
||||
#endif
|
||||
if (itemTpv)
|
||||
{
|
||||
rigTpv = itemTpv.GetComponentsInChildren<Rig>(true);
|
||||
#if NotEditor
|
||||
if (rigTpv.Length > 0)
|
||||
{
|
||||
int uid = TypeBasedUID<AnimationTargetsAbs>.UID;
|
||||
foreach (var rig in rigTpv)
|
||||
{
|
||||
rig.gameObject.name += $"_UID_{uid}";
|
||||
AnimationRiggingManager.AddRigExcludeName(rig.gameObject.name);
|
||||
}
|
||||
}
|
||||
rigLayerTpv = new RigLayer[rigTpv.Length];
|
||||
#endif
|
||||
itemTpv.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
//attaching the same prefab multiple times is not allowed!
|
||||
public void AttachPrefab(GameObject prefab)
|
||||
{
|
||||
if (!Destroyed && dict_attachments != null && prefab.TryGetComponent<AttachmentReferenceAppended>(out var appended))
|
||||
{
|
||||
appended.Merge(this);
|
||||
dict_attachments[prefab.name] = prefab.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject GetPrefab(string name)
|
||||
{
|
||||
if (Destroyed || dict_attachments == null || !dict_attachments.TryGetValue(name, out var prefab))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return prefab;
|
||||
}
|
||||
|
||||
public void Init(Transform playerAnimatorTrans, bool isFpv)
|
||||
{
|
||||
if (Destroyed || (isFpv && fpvSet) || (!isFpv && tpvSet))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!playerAnimatorTrans)
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
var animator = playerAnimatorTrans.GetComponentInChildren<Animator>(true);
|
||||
if (!animator)
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
fpvSet = false;
|
||||
tpvSet = false;
|
||||
playerAnimatorTrans = animator.transform;
|
||||
PlayerAnimatorTrans = playerAnimatorTrans;
|
||||
GraphBuilder = playerAnimatorTrans.AddMissingComponent<AnimationGraphBuilder>();
|
||||
IsFpv = isFpv;
|
||||
if (!isFpv)
|
||||
{
|
||||
itemAnimatorTpv = animator;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemAnimatorTpv = null;
|
||||
}
|
||||
spine1 = PlayerAnimatorTrans.FindInAllChildren("Spine1");
|
||||
spine2 = spine1.Find("Spine2");
|
||||
spine3 = spine2.Find("Spine3");
|
||||
|
||||
#if NotEditor
|
||||
Utils.SetLayerRecursively(gameObject, 24, Utils.ExcludeLayerZoom);
|
||||
if (ItemFpv)
|
||||
{
|
||||
Utils.SetLayerRecursively(ItemFpv.gameObject, 10, Utils.ExcludeLayerZoom);
|
||||
}
|
||||
if (ItemTpv)
|
||||
{
|
||||
Utils.SetLayerRecursively(ItemTpv.gameObject, 24, Utils.ExcludeLayerZoom);
|
||||
}
|
||||
#endif
|
||||
if (ItemTpv)
|
||||
{
|
||||
ItemTpv.parent = isFpv ? playerAnimatorTrans.parent : playerAnimatorTrans;
|
||||
ItemTpv.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
ItemTpv.localScale = Vector3.one;
|
||||
}
|
||||
if (!Destroyed)
|
||||
{
|
||||
Init();
|
||||
SetEnabled(false);
|
||||
//Log.Out($"Init rig\n{StackTraceUtility.ExtractStackTrace()}");
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Init()
|
||||
{
|
||||
if (!itemTpv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
itemTpv.SetParent(PlayerAnimatorTrans.parent);
|
||||
itemTpv.position = Vector3.zero;
|
||||
itemTpv.localPosition = Vector3.zero;
|
||||
itemTpv.localRotation = Quaternion.identity;
|
||||
if (!IsFpv)
|
||||
{
|
||||
itemAnimatorTpv = PlayerAnimatorTrans.GetComponent<Animator>();
|
||||
if (rigTpv.Length > 0)
|
||||
{
|
||||
foreach (var rig in rigTpv)
|
||||
{
|
||||
if (rig.TryGetComponent<RigConverter>(out var rc))
|
||||
{
|
||||
rc.targetRoot = PlayerAnimatorTrans;
|
||||
rc.Rebind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
itemAnimatorTpv = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
if (!PlayerAnimatorTrans)
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
if (IsFpv && ItemFpv && !fpvSet)
|
||||
{
|
||||
fpvSet = SetupFpv();
|
||||
}
|
||||
else if (!IsFpv && ItemTpv && !tpvSet)
|
||||
{
|
||||
tpvSet = SetupTpv();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract bool SetupFpv();
|
||||
|
||||
protected virtual bool SetupTpv()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
itemTpv.SetParent(itemAnimatorTpv.transform.FindInAllChildren(GetParentName(parentNameTpv)));
|
||||
itemTpv.position = Vector3.zero;
|
||||
itemTpv.localPosition = Vector3.zero;
|
||||
itemTpv.localRotation = Quaternion.identity;
|
||||
|
||||
GraphBuilder.InitWeapon(ItemTpv, weaponRuntimeControllerTpv, weaponRigMaskTpv);
|
||||
|
||||
var rigBuilder = PlayerAnimatorTrans.AddMissingComponent<RigBuilder>();
|
||||
#if NotEditor
|
||||
foreach (var layer in rigBuilder.layers)
|
||||
{
|
||||
if (layer.name == SDCSUtils.IKRIG)
|
||||
{
|
||||
layer.active = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (rigTpv.Length > 0)
|
||||
{
|
||||
rigBuilder.layers.RemoveAll(r => rigLayerTpv.Any(layer => layer?.name == r.name));
|
||||
for (int i = 0; i < rigTpv.Length; i++)
|
||||
{
|
||||
rigBuilder.layers.Insert(i, rigLayerTpv[i] = new RigLayer(rigTpv[i], true));
|
||||
}
|
||||
}
|
||||
BuildRig(PlayerAnimatorTrans.GetComponent<Animator>(), rigBuilder);
|
||||
|
||||
sw.Stop();
|
||||
string info = $"setup tpv animation graph took {sw.ElapsedMilliseconds} ms";
|
||||
//info += $"\n{StackTraceUtility.ExtractStackTrace()}";
|
||||
Log.Out(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
if (!PlayerAnimatorTrans)
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
if (IsFpv && ItemFpv && fpvSet)
|
||||
{
|
||||
RemoveFpv();
|
||||
fpvSet = false;
|
||||
}
|
||||
else if (!IsFpv && ItemTpv && tpvSet)
|
||||
{
|
||||
RemoveTpv();
|
||||
tpvSet = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void RemoveFpv();
|
||||
|
||||
protected virtual void RemoveTpv()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
itemTpv.SetParent(PlayerAnimatorTrans.parent);
|
||||
itemTpv.position = Vector3.zero;
|
||||
itemTpv.localPosition = Vector3.zero;
|
||||
itemTpv.localRotation = Quaternion.identity;
|
||||
|
||||
var rigBuilder = PlayerAnimatorTrans.AddMissingComponent<RigBuilder>();
|
||||
#if NotEditor
|
||||
foreach (var layer in rigBuilder.layers)
|
||||
{
|
||||
if (layer.name == SDCSUtils.IKRIG)
|
||||
{
|
||||
layer.active = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (rigTpv.Length > 0)
|
||||
{
|
||||
rigBuilder.layers.RemoveAll(r => rigLayerTpv.Any(layer => layer?.name == r.name));
|
||||
Array.Clear(rigLayerTpv, 0, rigLayerTpv.Length);
|
||||
|
||||
//rigTpv.transform.SetParent(transform, false);
|
||||
//rigTpv.gameObject.SetActive(false);
|
||||
}
|
||||
BuildRig(PlayerAnimatorTrans.GetComponent<Animator>(), rigBuilder);
|
||||
|
||||
sw.Stop();
|
||||
string info = $"destroy tpv animation graph took {sw.ElapsedMilliseconds} ms";
|
||||
//info += $"\n{StackTraceUtility.ExtractStackTrace()}";
|
||||
Log.Out(info);
|
||||
}
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
|
||||
if (AttachmentRef)
|
||||
{
|
||||
AttachmentRef.parent = transform;
|
||||
AttachmentRef = null;
|
||||
}
|
||||
|
||||
DestroyFpv();
|
||||
DestroyTpv();
|
||||
#if NotEditor
|
||||
Destroyed = true;
|
||||
#endif
|
||||
PlayerAnimatorTrans = null;
|
||||
dict_attachments = null;
|
||||
|
||||
Component.DestroyImmediate(this);
|
||||
//Log.Out(StackTraceUtility.ExtractStackTrace());
|
||||
}
|
||||
|
||||
public virtual void DestroyFpv()
|
||||
{
|
||||
if (ItemFpv)
|
||||
{
|
||||
if (IsFpv && fpvSet && PlayerAnimatorTrans)
|
||||
{
|
||||
GraphBuilder.SetCurrentTarget(null);
|
||||
}
|
||||
ItemFpv.parent = null;
|
||||
GameObject.DestroyImmediate(ItemFpv.gameObject);
|
||||
}
|
||||
fpvSet = false;
|
||||
ItemFpv = null;
|
||||
Log.Out("destroy fpv");
|
||||
}
|
||||
|
||||
public virtual void DestroyTpv()
|
||||
{
|
||||
if (ItemTpv)
|
||||
{
|
||||
if (!IsFpv && tpvSet && PlayerAnimatorTrans)
|
||||
{
|
||||
GraphBuilder.SetCurrentTarget(null);
|
||||
}
|
||||
ItemTpv.parent = null;
|
||||
GameObject.DestroyImmediate(ItemTpv.gameObject);
|
||||
}
|
||||
tpvSet = false;
|
||||
ItemTpv = null;
|
||||
Log.Out("destroy tpv");
|
||||
}
|
||||
|
||||
public virtual void SetEnabled(bool enabled)
|
||||
{
|
||||
if (Destroyed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (AttachmentRef)
|
||||
{
|
||||
AttachmentRef.parent = enabled ? (IsFpv ? ItemFpv : ItemTpvOrSelf) : transform;
|
||||
}
|
||||
if (enabled)
|
||||
{
|
||||
if (ItemFpv)
|
||||
{
|
||||
ItemFpv.gameObject.SetActive(IsFpv);
|
||||
}
|
||||
if (ItemTpv)
|
||||
{
|
||||
ItemTpv.gameObject.SetActive(!IsFpv);
|
||||
}
|
||||
Setup();
|
||||
}
|
||||
else
|
||||
{
|
||||
Remove();
|
||||
if (ItemFpv)
|
||||
{
|
||||
ItemFpv.gameObject.SetActive(false);
|
||||
}
|
||||
if (ItemTpv)
|
||||
{
|
||||
ItemTpv.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
if (ItemTpv)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.SetActive(!IsFpv);
|
||||
}
|
||||
}
|
||||
|
||||
protected void BuildRig(Animator animator, RigBuilder rb)
|
||||
{
|
||||
animator.UnbindAllStreamHandles();
|
||||
animator.UnbindAllSceneHandles();
|
||||
rb.Build();
|
||||
animator.Rebind();
|
||||
}
|
||||
|
||||
private readonly static int[] resetHashes = new int[]
|
||||
{
|
||||
Animator.StringToHash("Reload"),
|
||||
Animator.StringToHash("PowerAttack"),
|
||||
Animator.StringToHash("UseItem"),
|
||||
Animator.StringToHash("ItemUse"),
|
||||
Animator.StringToHash("WeaponFire")
|
||||
};
|
||||
|
||||
#if NotEditor
|
||||
//VRoid switch view workaround
|
||||
public void OnEnable()
|
||||
{
|
||||
var player = GetComponentInParent<EntityPlayerLocal>();
|
||||
if ((player && player.bFirstPersonView) || ItemTpv)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void UpdatePlayerAvatar(AvatarController avatarController, bool rigWeaponChanged)
|
||||
{
|
||||
//var itemCurrent = ItemCurrent;
|
||||
//if (itemCurrent && !itemCurrent.gameObject.activeSelf)
|
||||
//{
|
||||
// Log.Out("Rigged weapon not active, enabling it...");
|
||||
// SetEnabled(true);
|
||||
//}
|
||||
if (IsAnimationSet)
|
||||
{
|
||||
foreach (var hash in resetHashes)
|
||||
{
|
||||
var role = GraphBuilder.GetWrapperRoleByParamHash(hash);
|
||||
if (role == AnimationGraphBuilder.ParamInWrapper.Vanilla || role == AnimationGraphBuilder.ParamInWrapper.Both)
|
||||
{
|
||||
GraphBuilder.VanillaWrapper.ResetTrigger(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IsFpv && fpvSet)
|
||||
{
|
||||
GraphBuilder.VanillaWrapper.Play("idle", 0, 0f);
|
||||
avatarController.UpdateInt(AvatarController.weaponHoldTypeHash, -1, false);
|
||||
}
|
||||
else if (!IsFpv && tpvSet)
|
||||
{
|
||||
//avatarController.UpdateInt(AvatarController.weaponHoldTypeHash, 0, false);
|
||||
//GraphBuilder.VanillaWrapper.Play("Unarmed", GraphBuilder.VanillaWrapper.GetLayerIndex("StandingIdleTurn"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("RightHandHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("RangedRightHandHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("AdditiveOffsetHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("RightArmHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("BothArmsHoldPoses"), 0);
|
||||
//GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("AdditiveAimPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("UpperBodyAttack"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("BowDrawAndFire"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("UpperBodyUseAndReload"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("AdditiveRangedAttack"), 0);
|
||||
}
|
||||
}
|
||||
|
||||
//public void UpdateTpvSpineRotation(EntityPlayer player)
|
||||
//{
|
||||
// if (!IsFpv && tpvSet && player && !player.IsDead())
|
||||
// {
|
||||
// float xOffset = player.rotation.x / 3f;
|
||||
// float yOffset = 0f;
|
||||
// if (player.IsCrouching)
|
||||
// {
|
||||
// xOffset += 10f;
|
||||
// yOffset += 5f;
|
||||
// }
|
||||
// if (player.MovementState > 0)
|
||||
// {
|
||||
// xOffset += player.speedForward;
|
||||
// }
|
||||
// if (Time.timeScale > 0.001f)
|
||||
// {
|
||||
// spine1.transform.localEulerAngles = new Vector3(spine1.transform.localEulerAngles.x - xOffset, spine1.transform.localEulerAngles.y - yOffset, spine1.transform.localEulerAngles.z);
|
||||
// spine2.transform.localEulerAngles = new Vector3(spine2.transform.localEulerAngles.x - xOffset, spine2.transform.localEulerAngles.y - yOffset, spine2.transform.localEulerAngles.z);
|
||||
// spine3.transform.localEulerAngles = new Vector3(spine3.transform.localEulerAngles.x - xOffset, spine3.transform.localEulerAngles.y - yOffset, spine3.transform.localEulerAngles.z);
|
||||
// return;
|
||||
// }
|
||||
// spine1.transform.localEulerAngles = new Vector3(-xOffset, spine1.transform.localEulerAngles.y - yOffset, spine1.transform.localEulerAngles.z);
|
||||
// spine2.transform.localEulerAngles = new Vector3(-xOffset, spine2.transform.localEulerAngles.y - yOffset, spine2.transform.localEulerAngles.z);
|
||||
// spine3.transform.localEulerAngles = new Vector3(-xOffset, spine3.transform.localEulerAngles.y - yOffset, spine3.transform.localEulerAngles.z);
|
||||
// }
|
||||
//}
|
||||
|
||||
#else
|
||||
public void Update()
|
||||
{
|
||||
if (IsAnimationSet)
|
||||
{
|
||||
foreach (var hash in resetHashes)
|
||||
{
|
||||
var role = GraphBuilder.GetWrapperRoleByParamHash(hash);
|
||||
if (role == AnimationGraphBuilder.ParamInWrapper.Vanilla || role == AnimationGraphBuilder.ParamInWrapper.Both)
|
||||
{
|
||||
GraphBuilder.VanillaWrapper.ResetTrigger(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IsFpv && fpvSet)
|
||||
{
|
||||
GraphBuilder.VanillaWrapper.Play("idle", 0, 0f);
|
||||
}
|
||||
else if (!IsFpv && tpvSet)
|
||||
{
|
||||
//GraphBuilder.VanillaWrapper.Play("Unarmed", GraphBuilder.VanillaWrapper.GetLayerIndex("StandingIdleTurn"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("RightHandHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("RangedRightHandHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("AdditiveOffsetHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("RightArmHoldPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("BothArmsHoldPoses"), 0);
|
||||
//GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("AdditiveAimPoses"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("UpperBodyAttack"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("BowDrawAndFire"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("UpperBodyUseAndReload"), 0);
|
||||
GraphBuilder.VanillaWrapper.Play("Empty", GraphBuilder.VanillaWrapper.GetLayerIndex("AdditiveRangedAttack"), 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
11
KFAttached/RigAdaptors/AnimationTargetsAbs.cs.meta
Normal file
11
KFAttached/RigAdaptors/AnimationTargetsAbs.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9257aed4b0cc243458e5209dd3fb523d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
165
KFAttached/RigAdaptors/PlayGraphTargets.cs
Normal file
165
KFAttached/RigAdaptors/PlayGraphTargets.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib.Scripts.StaticManagers;
|
||||
using UniLinq;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
using System;
|
||||
|
||||
[AddComponentMenu("KFAttachments/RigAdaptors/PlayGraph Targets")]
|
||||
public class PlayGraphTargets : AnimationTargetsAbs
|
||||
{
|
||||
[Header("FPV Fields")]
|
||||
[SerializeField]
|
||||
public Transform itemFpv;
|
||||
[SerializeField]
|
||||
public Transform attachmentReference;
|
||||
[SerializeField]
|
||||
private RuntimeAnimatorController weaponRuntimeControllerFpv;
|
||||
[SerializeField]
|
||||
private ParentName parentNameFpv;
|
||||
|
||||
private Rig[] rigFpv;
|
||||
private RigLayer[] rigLayerFpv;
|
||||
private Animator itemAnimatorFpv;
|
||||
public override Transform ItemFpv { get => itemFpv; protected set => itemFpv = value; }
|
||||
|
||||
public override Transform AttachmentRef { get => attachmentReference; protected set => attachmentReference = value; }
|
||||
|
||||
protected override Animator ItemAnimatorFpv => itemAnimatorFpv;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
if (!itemFpv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rigFpv = itemFpv.GetComponentsInChildren<Rig>();
|
||||
#if NotEditor
|
||||
if (rigFpv.Length > 0)
|
||||
{
|
||||
int uid = TypeBasedUID<AnimationTargetsAbs>.UID;
|
||||
foreach (var rig in rigFpv)
|
||||
{
|
||||
rig.gameObject.name += $"_UID_{uid}";
|
||||
AnimationRiggingManager.AddRigExcludeName(rig.gameObject.name);
|
||||
}
|
||||
}
|
||||
rigLayerFpv = new RigLayer[rigFpv.Length];
|
||||
#endif
|
||||
itemFpv.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
if (!itemFpv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
itemFpv.SetParent(PlayerAnimatorTrans.parent);
|
||||
itemFpv.position = Vector3.zero;
|
||||
itemFpv.localPosition = Vector3.zero;
|
||||
itemFpv.localRotation = Quaternion.identity;
|
||||
|
||||
if (IsFpv)
|
||||
{
|
||||
itemAnimatorFpv = PlayerAnimatorTrans.GetComponent<Animator>();
|
||||
if (rigFpv.Length > 0)
|
||||
{
|
||||
foreach (var rig in rigFpv)
|
||||
{
|
||||
if (rig.TryGetComponent<RigConverter>(out var rc))
|
||||
{
|
||||
rc.targetRoot = PlayerAnimatorTrans;
|
||||
rc.Rebind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
itemAnimatorFpv = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool SetupFpv()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
itemFpv.SetParent(itemAnimatorFpv.transform.FindInAllChildren(GetParentName(parentNameFpv)));
|
||||
itemFpv.position = Vector3.zero;
|
||||
itemFpv.localPosition = Vector3.zero;
|
||||
itemFpv.localRotation = Quaternion.identity;
|
||||
|
||||
GraphBuilder.InitWeapon(itemFpv, weaponRuntimeControllerFpv, null);
|
||||
var rigBuilder = PlayerAnimatorTrans.AddMissingComponent<RigBuilder>();
|
||||
#if NotEditor
|
||||
foreach (var layer in rigBuilder.layers)
|
||||
{
|
||||
if (layer.name == SDCSUtils.IKRIG)
|
||||
{
|
||||
layer.active = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (rigFpv.Length > 0)
|
||||
{
|
||||
rigBuilder.layers.RemoveAll(r => rigLayerFpv.Any(layer => layer?.name == r.name));
|
||||
for (int i = 0; i < rigFpv.Length; i++)
|
||||
{
|
||||
rigBuilder.layers.Insert(i, rigLayerFpv[i] = new RigLayer(rigFpv[i], true));
|
||||
}
|
||||
}
|
||||
BuildRig(PlayerAnimatorTrans.GetComponent<Animator>(), rigBuilder);
|
||||
|
||||
sw.Stop();
|
||||
string info = $"setup fpv animation graph took {sw.ElapsedMilliseconds} ms";
|
||||
//info += $"\n{StackTraceUtility.ExtractStackTrace()}";
|
||||
Log.Out(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void RemoveFpv()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
itemFpv.SetParent(PlayerAnimatorTrans.parent);
|
||||
itemFpv.position = Vector3.zero;
|
||||
itemFpv.localPosition = Vector3.zero;
|
||||
itemFpv.localRotation = Quaternion.identity;
|
||||
|
||||
var rigBuilder = PlayerAnimatorTrans.AddMissingComponent<RigBuilder>();
|
||||
#if NotEditor
|
||||
foreach (var layer in rigBuilder.layers)
|
||||
{
|
||||
if (layer.name == SDCSUtils.IKRIG)
|
||||
{
|
||||
layer.active = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (rigFpv.Length > 0)
|
||||
{
|
||||
rigBuilder.layers.RemoveAll(r => rigLayerFpv.Any(layer => layer?.name == r.name));
|
||||
Array.Clear(rigLayerFpv, 0, rigLayerFpv.Length);
|
||||
|
||||
//rigFpv.transform.SetParent(transform, false);
|
||||
//rigFpv.gameObject.SetActive(false);
|
||||
}
|
||||
BuildRig(PlayerAnimatorTrans.GetComponent<Animator>(), rigBuilder);
|
||||
|
||||
sw.Stop();
|
||||
string info = $"destroy fpv animation graph took {sw.ElapsedMilliseconds} ms";
|
||||
//info += $"\n{StackTraceUtility.ExtractStackTrace()}";
|
||||
Log.Out(info);
|
||||
}
|
||||
}
|
||||
11
KFAttached/RigAdaptors/PlayGraphTargets.cs.meta
Normal file
11
KFAttached/RigAdaptors/PlayGraphTargets.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cdb3ae68f5838c49a4ee601f977eb76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/RigAdaptors/ReverseAdaptors.meta
Normal file
8
KFAttached/RigAdaptors/ReverseAdaptors.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c37be1fa2e9bdc4eae9a203d5cf95c4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class BlendConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private string m_SourceA;
|
||||
[SerializeField]
|
||||
private string m_SourceB;
|
||||
[SerializeField]
|
||||
private bool m_BlendPosition;
|
||||
[SerializeField]
|
||||
private bool m_BlendRotation;
|
||||
[SerializeField]
|
||||
private float m_PositionWeight;
|
||||
[SerializeField]
|
||||
private float m_RotationWeight;
|
||||
[SerializeField]
|
||||
private bool m_MaintainPositionOffsets;
|
||||
[SerializeField]
|
||||
private bool m_MaintainRotationOffsets;
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<BlendConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject;
|
||||
m_SourceA = constraint.data.sourceObjectA?.name;
|
||||
m_SourceB = constraint.data.sourceObjectB?.name;
|
||||
m_BlendPosition = constraint.data.blendPosition;
|
||||
m_BlendRotation = constraint.data.blendRotation;
|
||||
m_PositionWeight = constraint.data.positionWeight;
|
||||
m_RotationWeight = constraint.data.rotationWeight;
|
||||
m_MaintainPositionOffsets = constraint.data.maintainPositionOffsets;
|
||||
m_MaintainRotationOffsets = constraint.data.maintainRotationOffsets;
|
||||
}
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<BlendConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = m_ConstrainedObject;
|
||||
constraint.data.sourceObjectA = targetRoot.FindInAllChildren(m_SourceA);
|
||||
constraint.data.sourceObjectB = targetRoot.FindInAllChildren(m_SourceB);
|
||||
constraint.data.blendPosition = m_BlendPosition;
|
||||
constraint.data.blendRotation = m_BlendRotation;
|
||||
constraint.data.positionWeight = m_PositionWeight;
|
||||
constraint.data.rotationWeight = m_RotationWeight;
|
||||
constraint.data.maintainPositionOffsets = m_MaintainPositionOffsets;
|
||||
constraint.data.maintainRotationOffsets = m_MaintainRotationOffsets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98945ef0fc0d660459661507c533176e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class ChainIKConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_Root;
|
||||
[SerializeField]
|
||||
private Transform m_Tip;
|
||||
[SerializeField]
|
||||
private string m_Target;
|
||||
[SerializeField]
|
||||
private float m_ChainRotationWeight;
|
||||
[SerializeField]
|
||||
private float m_TipRotationWeight;
|
||||
[SerializeField]
|
||||
private int m_MaxIterations;
|
||||
[SerializeField]
|
||||
private float m_Tolerance;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetPositionOffset;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetRotationOffset;
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<ChainIKConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Root = constraint.data.root;
|
||||
m_Tip = constraint.data.tip;
|
||||
m_Target = constraint.data.target?.name;
|
||||
m_ChainRotationWeight = constraint.data.chainRotationWeight;
|
||||
m_TipRotationWeight = constraint.data.tipRotationWeight;
|
||||
m_MaxIterations = constraint.data.maxIterations;
|
||||
m_Tolerance = constraint.data.tolerance;
|
||||
m_MaintainTargetPositionOffset = constraint.data.maintainTargetPositionOffset;
|
||||
m_MaintainTargetRotationOffset = constraint.data.maintainTargetRotationOffset;
|
||||
}
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<ChainIKConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.root = m_Root;
|
||||
constraint.data.tip = m_Tip;
|
||||
constraint.data.target = targetRoot.FindInAllChildren(m_Target);
|
||||
constraint.data.chainRotationWeight = m_ChainRotationWeight;
|
||||
constraint.data.tipRotationWeight = m_TipRotationWeight;
|
||||
constraint.data.maxIterations = m_MaxIterations;
|
||||
constraint.data.tolerance = m_Tolerance;
|
||||
constraint.data.maintainTargetPositionOffset = m_MaintainTargetPositionOffset;
|
||||
constraint.data.maintainTargetRotationOffset = m_MaintainTargetRotationOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d07f318626844d943a83719329ef46e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class DampedTransformReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private string m_Source;
|
||||
[SerializeField]
|
||||
private float m_DampPosition;
|
||||
[SerializeField]
|
||||
private float m_DampRotation;
|
||||
[SerializeField]
|
||||
private bool m_MaintainAim;
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<DampedTransform>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject;
|
||||
m_Source = constraint.data.sourceObject?.name;
|
||||
m_DampPosition = constraint.data.dampPosition;
|
||||
m_DampRotation = constraint.data.dampRotation;
|
||||
m_MaintainAim = constraint.data.maintainAim;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<DampedTransform>();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = m_ConstrainedObject;
|
||||
constraint.data.sourceObject = targetRoot.FindInAllChildren(m_Source);
|
||||
constraint.data.dampPosition = m_DampPosition;
|
||||
constraint.data.dampRotation = m_DampRotation;
|
||||
constraint.data.maintainAim = m_MaintainAim;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 024d749c0fd809c4ba3d82d3a3618415
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiAimConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private string[] m_SourceObjectNames;
|
||||
[SerializeField]
|
||||
private float[] m_SourceObjectWeights;
|
||||
[SerializeField]
|
||||
private Vector3 m_Offset;
|
||||
[SerializeField]
|
||||
private Vector2 m_limits;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.Axis m_AimAxis;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.Axis m_UpAxis;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.WorldUpType m_WorldUpType;
|
||||
[SerializeField]
|
||||
private Transform m_WorldUpObject;
|
||||
[SerializeField]
|
||||
private MultiAimConstraintData.Axis m_WorldUpAxis;
|
||||
[SerializeField]
|
||||
private bool m_MaintainOffset;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedAxes;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiAimConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = m_ConstrainedObject;
|
||||
constraint.data.sourceObjects = WeightedTransformArrayFromAdaptor(targetRoot, m_SourceObjectNames, m_SourceObjectWeights);
|
||||
constraint.data.offset = m_Offset;
|
||||
constraint.data.limits = m_limits;
|
||||
constraint.data.aimAxis = m_AimAxis;
|
||||
constraint.data.upAxis = m_UpAxis;
|
||||
constraint.data.worldUpType = m_WorldUpType;
|
||||
constraint.data.worldUpObject = m_WorldUpObject;
|
||||
constraint.data.worldUpAxis = m_WorldUpAxis;
|
||||
constraint.data.maintainOffset = m_MaintainOffset;
|
||||
constraint.data.constrainedXAxis = m_ConstrainedAxes.x;
|
||||
constraint.data.constrainedYAxis = m_ConstrainedAxes.y;
|
||||
constraint.data.constrainedZAxis = m_ConstrainedAxes.z;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiAimConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject;
|
||||
WeightedTransformArrayToAdaptor(constraint.data.sourceObjects, out m_SourceObjectNames, out m_SourceObjectWeights);
|
||||
m_Offset = constraint.data.offset;
|
||||
m_limits = constraint.data.limits;
|
||||
m_AimAxis = constraint.data.aimAxis;
|
||||
m_UpAxis = constraint.data.upAxis;
|
||||
m_WorldUpType = constraint.data.worldUpType;
|
||||
if ((m_WorldUpType == MultiAimConstraintData.WorldUpType.ObjectUp || m_WorldUpType == MultiAimConstraintData.WorldUpType.ObjectRotationUp) && constraint.data.worldUpObject)
|
||||
m_WorldUpObject = constraint.data.worldUpObject;
|
||||
m_WorldUpAxis = constraint.data.worldUpAxis;
|
||||
m_MaintainOffset = constraint.data.maintainOffset;
|
||||
m_ConstrainedAxes = new Vector3Bool(constraint.data.constrainedXAxis, constraint.data.constrainedYAxis, constraint.data.constrainedZAxis);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57060a9b209c4cb489b39a7405f25bcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiParentConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private string[] m_SourceObjectNames;
|
||||
[SerializeField]
|
||||
private float[] m_SourceObjectWeights;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedPositionAxes;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedRotationAxes;
|
||||
[SerializeField]
|
||||
private bool m_MaintainPositionOffset;
|
||||
[SerializeField]
|
||||
private bool m_MaintainRotationOffset;
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiParentConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = m_ConstrainedObject;
|
||||
constraint.data.sourceObjects = WeightedTransformArrayFromAdaptor(targetRoot, m_SourceObjectNames, m_SourceObjectWeights);
|
||||
constraint.data.constrainedPositionXAxis = m_ConstrainedPositionAxes.x;
|
||||
constraint.data.constrainedPositionYAxis = m_ConstrainedPositionAxes.y;
|
||||
constraint.data.constrainedPositionZAxis = m_ConstrainedPositionAxes.z;
|
||||
constraint.data.constrainedRotationXAxis = m_ConstrainedRotationAxes.x;
|
||||
constraint.data.constrainedRotationYAxis = m_ConstrainedRotationAxes.y;
|
||||
constraint.data.constrainedRotationZAxis = m_ConstrainedRotationAxes.z;
|
||||
constraint.data.maintainPositionOffset = m_MaintainPositionOffset;
|
||||
constraint.data.maintainRotationOffset = m_MaintainRotationOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiParentConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject;
|
||||
WeightedTransformArrayToAdaptor(constraint.data.sourceObjects, out m_SourceObjectNames, out m_SourceObjectWeights);
|
||||
m_ConstrainedPositionAxes = new Vector3Bool(constraint.data.constrainedPositionXAxis, constraint.data.constrainedPositionYAxis, constraint.data.constrainedPositionZAxis);
|
||||
m_ConstrainedRotationAxes = new Vector3Bool(constraint.data.constrainedRotationXAxis, constraint.data.constrainedRotationYAxis, constraint.data.constrainedRotationZAxis);
|
||||
m_MaintainPositionOffset = constraint.data.maintainPositionOffset;
|
||||
m_MaintainRotationOffset = constraint.data.maintainRotationOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4720f809bab89e4bab5459297567d0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiPositionConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private string[] m_SourceObjectNames;
|
||||
[SerializeField]
|
||||
private float[] m_SourceObjectWeights;
|
||||
[SerializeField]
|
||||
private Vector3 m_Offset;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedAxes;
|
||||
[SerializeField]
|
||||
private bool m_MaintainOffset;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiPositionConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = m_ConstrainedObject;
|
||||
constraint.data.sourceObjects = WeightedTransformArrayFromAdaptor(targetRoot, m_SourceObjectNames, m_SourceObjectWeights);
|
||||
constraint.data.offset = m_Offset;
|
||||
constraint.data.constrainedXAxis = m_ConstrainedAxes.x;
|
||||
constraint.data.constrainedYAxis = m_ConstrainedAxes.y;
|
||||
constraint.data.constrainedZAxis = m_ConstrainedAxes.z;
|
||||
constraint.data.maintainOffset = m_MaintainOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiPositionConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject;
|
||||
WeightedTransformArrayToAdaptor(constraint.data.sourceObjects, out m_SourceObjectNames, out m_SourceObjectWeights);
|
||||
m_Offset = constraint.data.offset;
|
||||
m_ConstrainedAxes = new Vector3Bool(constraint.data.constrainedXAxis, constraint.data.constrainedYAxis, constraint.data.constrainedZAxis);
|
||||
m_MaintainOffset = constraint.data.maintainOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 700d88da068a59848930b99154a10879
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiReferentialConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private int m_Driver;
|
||||
[SerializeField]
|
||||
private List<string> m_SourceObjects;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiReferentialConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.driver = m_Driver;
|
||||
constraint.data.sourceObjects = new List<Transform>();
|
||||
foreach(var sourceObject in m_SourceObjects)
|
||||
{
|
||||
constraint.data.sourceObjects.Add(targetRoot.FindInAllChildren(sourceObject));
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiReferentialConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Driver = constraint.data.driver;
|
||||
m_SourceObjects = new List<string>();
|
||||
foreach (var sourceObject in constraint.data.sourceObjects)
|
||||
{
|
||||
m_SourceObjects.Add(sourceObject?.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c564e8b8f4881e6498f344db3bbd63b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class MultiRotationConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private string[] m_SourceObjectNames;
|
||||
[SerializeField]
|
||||
private float[] m_SourceObjectWeights;
|
||||
[SerializeField]
|
||||
private Vector3 m_Offset;
|
||||
[SerializeField]
|
||||
private Vector3Bool m_ConstrainedAxes;
|
||||
[SerializeField]
|
||||
private bool m_MaintainOffset;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<MultiRotationConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = m_ConstrainedObject;
|
||||
constraint.data.sourceObjects = WeightedTransformArrayFromAdaptor(targetRoot, m_SourceObjectNames, m_SourceObjectWeights);
|
||||
constraint.data.offset = m_Offset;
|
||||
constraint.data.constrainedXAxis = m_ConstrainedAxes.x;
|
||||
constraint.data.constrainedYAxis = m_ConstrainedAxes.y;
|
||||
constraint.data.constrainedZAxis = m_ConstrainedAxes.z;
|
||||
constraint.data.maintainOffset = m_MaintainOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<MultiRotationConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject;
|
||||
WeightedTransformArrayToAdaptor(constraint.data.sourceObjects, out m_SourceObjectNames, out m_SourceObjectWeights);
|
||||
m_Offset = constraint.data.offset;
|
||||
m_ConstrainedAxes = new Vector3Bool(constraint.data.constrainedXAxis, constraint.data.constrainedYAxis, constraint.data.constrainedZAxis);
|
||||
m_MaintainOffset = constraint.data.maintainOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b08d9d6ae2d5244b83a65aacd535ab8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class OverrideTransformReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_ConstrainedObject;
|
||||
[SerializeField]
|
||||
private string m_OverrideSource;
|
||||
[SerializeField]
|
||||
private Vector3 m_OverridePosition;
|
||||
[SerializeField]
|
||||
private Vector3 m_OverrideRotation;
|
||||
[SerializeField]
|
||||
private float m_PositionWeight;
|
||||
[SerializeField]
|
||||
private float m_RotationWeight;
|
||||
[SerializeField]
|
||||
private OverrideTransformData.Space m_Space;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<OverrideTransform>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.constrainedObject = m_ConstrainedObject;
|
||||
constraint.data.sourceObject = targetRoot.FindInAllChildren(m_OverrideSource);
|
||||
constraint.data.position = m_OverridePosition;
|
||||
constraint.data.rotation = m_OverrideRotation;
|
||||
constraint.data.positionWeight = m_PositionWeight;
|
||||
constraint.data.rotationWeight = m_RotationWeight;
|
||||
constraint.data.space = m_Space;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<OverrideTransform>();
|
||||
weight = constraint.weight;
|
||||
m_ConstrainedObject = constraint.data.constrainedObject;
|
||||
m_OverrideSource = constraint.data.sourceObject?.name;
|
||||
m_OverridePosition = constraint.data.position;
|
||||
m_OverrideRotation = constraint.data.rotation;
|
||||
m_PositionWeight = constraint.data.positionWeight;
|
||||
m_RotationWeight = constraint.data.rotationWeight;
|
||||
m_Space = constraint.data.space;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6971ec144ef3f84b8c6ce116c7ea3de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class TwistChainConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_Root;
|
||||
[SerializeField]
|
||||
private Transform m_Tip;
|
||||
[SerializeField]
|
||||
private string m_RootTarget;
|
||||
[SerializeField]
|
||||
private string m_TipTarget;
|
||||
[SerializeField]
|
||||
private AnimationCurve m_Curve;
|
||||
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<TwistChainConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.root = m_Root;
|
||||
constraint.data.tip = m_Tip;
|
||||
constraint.data.rootTarget = targetRoot.FindInAllChildren(m_RootTarget);
|
||||
constraint.data.tipTarget = targetRoot.FindInAllChildren(m_TipTarget);
|
||||
constraint.data.curve = m_Curve;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<TwistChainConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Root = constraint.data.root;
|
||||
m_Tip = constraint.data.tip;
|
||||
m_RootTarget = constraint.data.rootTarget?.name;
|
||||
m_TipTarget = constraint.data.tipTarget?.name;
|
||||
m_Curve = constraint.data.curve;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 769f53150f7d575498374023f393136c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class TwistCorrectionReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a25e34cfebf5e5e45a0be99dad327b64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("")]
|
||||
public class TwoBoneIKConstraintReverseAdaptor : RigAdaptorAbs
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform m_Root;
|
||||
[SerializeField]
|
||||
private Transform m_Mid;
|
||||
[SerializeField]
|
||||
private Transform m_Tip;
|
||||
[SerializeField]
|
||||
private string m_Target;
|
||||
[SerializeField]
|
||||
private string m_Hint;
|
||||
[SerializeField]
|
||||
private float m_TargetPositionWeight;
|
||||
[SerializeField]
|
||||
private float m_TargetRotationWeight;
|
||||
[SerializeField]
|
||||
private float m_HintWeight;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetPositionOffset;
|
||||
[SerializeField]
|
||||
private bool m_MaintainTargetRotationOffset;
|
||||
public override void FindRigTargets()
|
||||
{
|
||||
var constraint = GetComponent<TwoBoneIKConstraint>();
|
||||
constraint.Reset();
|
||||
constraint.weight = weight;
|
||||
constraint.data.root = m_Root;
|
||||
constraint.data.mid = m_Mid;
|
||||
constraint.data.tip = m_Tip;
|
||||
constraint.data.target = targetRoot.FindInAllChildren(m_Target);
|
||||
constraint.data.hint = targetRoot.FindInAllChildren(m_Hint);
|
||||
constraint.data.targetPositionWeight = m_TargetPositionWeight;
|
||||
constraint.data.targetRotationWeight = m_TargetRotationWeight;
|
||||
constraint.data.hintWeight = m_HintWeight;
|
||||
constraint.data.maintainTargetPositionOffset = m_MaintainTargetPositionOffset;
|
||||
constraint.data.maintainTargetRotationOffset = m_MaintainTargetRotationOffset;
|
||||
}
|
||||
|
||||
public override void ReadRigData()
|
||||
{
|
||||
var constraint = GetComponent<TwoBoneIKConstraint>();
|
||||
weight = constraint.weight;
|
||||
m_Root = constraint.data.root;
|
||||
m_Mid = constraint.data.mid;
|
||||
m_Tip = constraint.data.tip;
|
||||
m_Target = constraint.data.target?.name;
|
||||
m_Hint = constraint.data.hint?.name;
|
||||
m_TargetPositionWeight = constraint.data.targetPositionWeight;
|
||||
m_TargetRotationWeight = constraint.data.targetRotationWeight;
|
||||
m_HintWeight = constraint.data.hintWeight;
|
||||
m_MaintainTargetPositionOffset = constraint.data.maintainTargetPositionOffset;
|
||||
m_MaintainTargetRotationOffset = constraint.data.maintainTargetRotationOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9347c9017333b794d8117c27ec493d06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
309
KFAttached/RigAdaptors/RigConverter.cs
Normal file
309
KFAttached/RigAdaptors/RigConverter.cs
Normal file
@@ -0,0 +1,309 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
[AddComponentMenu("KFAttachments/RigAdaptors/Rig Converter")]
|
||||
public class RigConverter : MonoBehaviour
|
||||
{
|
||||
public Transform targetRoot;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[ContextMenu("Convert Rig Constraints to Adaptors")]
|
||||
private void Convert()
|
||||
{
|
||||
foreach (var constraint in GetComponentsInChildren<IRigConstraint>(true))
|
||||
{
|
||||
if (constraint.component.TryGetComponent<RigConverterRole>(out var role) && role.role == RigConverterRole.Role.Ignore)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var adaptorName = constraint.GetType().Name;
|
||||
if (role && role.role == RigConverterRole.Role.Reverse)
|
||||
{
|
||||
adaptorName += "Reverse";
|
||||
}
|
||||
adaptorName += "Adaptor,KFCommonUtilityLib";
|
||||
var adaptorType = Type.GetType(adaptorName);
|
||||
var adaptor = (RigAdaptorAbs)constraint.component.transform.AddMissingComponent(adaptorType);
|
||||
adaptor.ReadRigData();
|
||||
adaptor.hideFlags = HideFlags.NotEditable;
|
||||
EditorUtility.SetDirty(adaptor);
|
||||
}
|
||||
Save();
|
||||
}
|
||||
|
||||
[ContextMenu("Read Adaptor Value to Constraints")]
|
||||
private void Read()
|
||||
{
|
||||
Rebind();
|
||||
Save();
|
||||
}
|
||||
|
||||
[ContextMenu("Remove All Adaptors")]
|
||||
private void RemoveAll()
|
||||
{
|
||||
var constraints = GetComponentsInChildren<RigAdaptorAbs>(true);
|
||||
foreach (var constraint in constraints)
|
||||
{
|
||||
DestroyImmediate(constraint);
|
||||
}
|
||||
Save();
|
||||
}
|
||||
|
||||
[ContextMenu("Fix A22 Constraints")]
|
||||
private void Fix()
|
||||
{
|
||||
Rebind();
|
||||
foreach (var constraint in GetComponentsInChildren<IRigConstraint>())
|
||||
{
|
||||
string name = constraint.component.transform.name;
|
||||
if (char.IsDigit(name[^1]))
|
||||
{
|
||||
if (name.Contains("ArmRollCorrections") && constraint.component is MultiRotationConstraint mrcArm)
|
||||
{
|
||||
int index = int.Parse(name.Substring(name.Length - 1, 1));
|
||||
var source = mrcArm.data.sourceObjects;
|
||||
source.SetWeight(0, index * 0.25f);
|
||||
mrcArm.data.sourceObjects = source;
|
||||
mrcArm.data.constrainedXAxis = true;
|
||||
mrcArm.data.constrainedYAxis = false;
|
||||
mrcArm.data.constrainedZAxis = false;
|
||||
}
|
||||
else if (name.Contains("FingerTarget") && name.Length == 13 && constraint.component is TwoBoneIKConstraint tbc)
|
||||
{
|
||||
int index = int.Parse(name.Substring(name.Length - 1, 1));
|
||||
string targetNameBase = tbc.data.root.transform.name[..^1];
|
||||
tbc.data.root = targetRoot.FindInAllChildren($"{targetNameBase}1");
|
||||
tbc.data.mid = targetRoot.FindInAllChildren($"{targetNameBase}{(index == 5 ? 3 : 2)}");
|
||||
tbc.data.tip = targetRoot.FindInAllChildren($"{targetNameBase}4");
|
||||
}
|
||||
else if (name.Contains("FingerTargetRollCorrection") && constraint.component is MultiRotationConstraint mrcFinger)
|
||||
{
|
||||
int index = int.Parse(name.Substring(name.Length - 1, 1));
|
||||
mrcFinger.data.constrainedXAxis = true;
|
||||
mrcFinger.data.constrainedYAxis = false;
|
||||
mrcFinger.data.constrainedZAxis = index == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Convert();
|
||||
}
|
||||
|
||||
[ContextMenu("Convert To New Rig Setup")]
|
||||
private void Renew()
|
||||
{
|
||||
Rebind();
|
||||
string leftHandTransName = null, rightHandTransName = null;
|
||||
foreach (var tbik in GetComponentsInChildren<TwoBoneIKConstraint>())
|
||||
{
|
||||
if(tbik.data.tip.name.Contains("hand", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Transform target = tbik.data.target;
|
||||
if(target.name.Contains("target", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
target = target.parent;
|
||||
}
|
||||
if (tbik.data.tip.name.StartsWith("Left", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
leftHandTransName = target.name;
|
||||
}
|
||||
else
|
||||
{
|
||||
rightHandTransName = target.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(leftHandTransName == null || rightHandTransName == null)
|
||||
{
|
||||
Log.Error("Left/Right hand transform not found on weapon skeleton!");
|
||||
return;
|
||||
}
|
||||
foreach (var constraint in GetComponentsInChildren<IRigConstraint>())
|
||||
{
|
||||
Transform trans = constraint.component.transform;
|
||||
string name = trans.name;
|
||||
if (char.IsDigit(name[^1]) && name.StartsWith("FingerTarget") && !trans.parent.name.StartsWith("FingerTarget") && constraint is TwoBoneIKConstraint tbik)
|
||||
{
|
||||
int index = int.Parse(name.Substring(name.Length - 1, 1));
|
||||
if(index > 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
GameObject newConstraint = new(name);
|
||||
newConstraint.transform.SetParent(trans, true);
|
||||
newConstraint.transform.SetAsFirstSibling();
|
||||
newConstraint.transform.position = trans.position;
|
||||
EditorUtility.CopySerialized(tbik, newConstraint.AddComponent<TwoBoneIKConstraint>());
|
||||
DestroyImmediate(tbik);
|
||||
if (trans.GetComponent<TwoBoneIKConstraintAdaptor>() is TwoBoneIKConstraintAdaptor adaptor)
|
||||
{
|
||||
DestroyImmediate(adaptor);
|
||||
}
|
||||
|
||||
string targetNameBase = tbik.data.root.transform.name[..^1];
|
||||
bool isLeft = targetNameBase.StartsWith("Left");
|
||||
GameObject metacarpal = new($"MetacarpalAiming{index}");
|
||||
var aimConstraint = metacarpal.AddComponent<MultiAimConstraint>();
|
||||
aimConstraint.data.constrainedObject = targetRoot.FindInAllChildren($"{targetNameBase}0");
|
||||
aimConstraint.data.aimAxis = isLeft ? MultiAimConstraintData.Axis.X_NEG : MultiAimConstraintData.Axis.X;
|
||||
aimConstraint.data.upAxis = isLeft ? MultiAimConstraintData.Axis.Y : MultiAimConstraintData.Axis.Y_NEG;
|
||||
aimConstraint.data.worldUpType = MultiAimConstraintData.WorldUpType.None;
|
||||
aimConstraint.data.constrainedXAxis = false;
|
||||
aimConstraint.data.constrainedYAxis = false;
|
||||
aimConstraint.data.constrainedZAxis = true;
|
||||
Transform curSource = tbik.data.target;
|
||||
while(((isLeft && curSource.parent.parent.name != leftHandTransName) || (!isLeft && curSource.parent.parent.name != rightHandTransName)) && !curSource.parent.name.Contains("1"))
|
||||
{
|
||||
curSource = curSource.parent;
|
||||
}
|
||||
var sourceArr = aimConstraint.data.sourceObjects;
|
||||
var source = new WeightedTransform(curSource.parent.name.Contains("1") ? curSource.parent : curSource, 1);
|
||||
sourceArr.Add(source);
|
||||
aimConstraint.data.sourceObjects = sourceArr;
|
||||
metacarpal.transform.SetParent(trans.transform);
|
||||
metacarpal.transform.SetAsFirstSibling();
|
||||
}
|
||||
}
|
||||
Convert();
|
||||
}
|
||||
|
||||
public void CreateEmpty()
|
||||
{
|
||||
CreateEmptyForSide("Left");
|
||||
CreateEmptyForSide("Right");
|
||||
}
|
||||
|
||||
private static string[] PhalangeBoneNames = new[]
|
||||
{
|
||||
"Thumb",
|
||||
"Index",
|
||||
"Middle",
|
||||
"Pinky",
|
||||
"Ring"
|
||||
};
|
||||
|
||||
private void CreateEmptyForSide(string side)
|
||||
{
|
||||
WeightedTransformArray sourceObjects = new();
|
||||
|
||||
Transform shoulderReposition = new GameObject($"{side}ShoulderReposition").transform;
|
||||
shoulderReposition.parent = transform;
|
||||
MultiPositionConstraint shoulderRepositionConstraint = shoulderReposition.gameObject.AddComponent<MultiPositionConstraint>();
|
||||
shoulderRepositionConstraint.data.constrainedObject = targetRoot.FindInAllChildren($"{side}Shoulder");
|
||||
shoulderRepositionConstraint.data.constrainedXAxis = shoulderRepositionConstraint.data.constrainedYAxis = shoulderRepositionConstraint.data.constrainedZAxis = true;
|
||||
|
||||
Transform armRollCorrection = new GameObject($"{side}ArmRollCorrections").transform;
|
||||
armRollCorrection.parent = transform;
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
Transform child = new GameObject($"{armRollCorrection.name}{i}").transform;
|
||||
child.parent = armRollCorrection;
|
||||
MultiRotationConstraint armRollCorrectionConstraint = child.gameObject.AddComponent<MultiRotationConstraint>();
|
||||
armRollCorrectionConstraint.data.constrainedObject = targetRoot.FindInAllChildren($"{side}ForeArmRoll{i}");
|
||||
armRollCorrectionConstraint.data.constrainedXAxis = true;
|
||||
armRollCorrectionConstraint.data.constrainedYAxis = false;
|
||||
armRollCorrectionConstraint.data.constrainedZAxis = false;
|
||||
sourceObjects.Add(new WeightedTransform(null, i * .25f));
|
||||
armRollCorrectionConstraint.data.sourceObjects = sourceObjects;
|
||||
sourceObjects.Clear();
|
||||
}
|
||||
|
||||
Transform armTarget = new GameObject($"{side}ArmTarget").transform;
|
||||
armTarget.parent = transform;
|
||||
TwoBoneIKConstraint armTargetConstraint = armTarget.gameObject.AddComponent<TwoBoneIKConstraint>();
|
||||
armTargetConstraint.data.root = targetRoot.FindInAllChildren($"{side}Arm");
|
||||
armTargetConstraint.data.mid = targetRoot.FindInAllChildren($"{side}ForeArm");
|
||||
armTargetConstraint.data.tip = targetRoot.FindInAllChildren($"{side}Hand");
|
||||
|
||||
bool isLeft = side == "Left";
|
||||
Transform handTargets = new GameObject($"{side}HandTargets").transform;
|
||||
handTargets.parent = transform;
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
string fingerTargetName = $"FingerTarget{i}";
|
||||
Transform fingerTargetParent = new GameObject(fingerTargetName).transform;
|
||||
fingerTargetParent.parent = handTargets;
|
||||
|
||||
Transform metacarpalAiming = new GameObject($"MetacarpalAiming{i}").transform;
|
||||
metacarpalAiming.parent = fingerTargetParent;
|
||||
MultiAimConstraint metacarpalAimingConstraint = metacarpalAiming.gameObject.AddComponent<MultiAimConstraint>();
|
||||
metacarpalAimingConstraint.data.constrainedObject = targetRoot.FindInAllChildren($"{side}Hand{PhalangeBoneNames[i]}0");
|
||||
metacarpalAimingConstraint.data.aimAxis = isLeft ? MultiAimConstraintData.Axis.X_NEG : MultiAimConstraintData.Axis.X;
|
||||
metacarpalAimingConstraint.data.upAxis = isLeft ? MultiAimConstraintData.Axis.Y : MultiAimConstraintData.Axis.Y_NEG;
|
||||
metacarpalAimingConstraint.data.worldUpType = MultiAimConstraintData.WorldUpType.None;
|
||||
metacarpalAimingConstraint.data.constrainedXAxis = false;
|
||||
metacarpalAimingConstraint.data.constrainedYAxis = false;
|
||||
metacarpalAimingConstraint.data.constrainedZAxis = true;
|
||||
|
||||
Transform fingerTarget = new GameObject(fingerTargetName).transform;
|
||||
fingerTarget.parent = fingerTargetParent;
|
||||
TwoBoneIKConstraint fingerTargetConstraint = fingerTarget.gameObject.AddComponent<TwoBoneIKConstraint>();
|
||||
fingerTargetConstraint.data.root = targetRoot.FindInAllChildren($"{side}Hand{PhalangeBoneNames[i]}1");
|
||||
fingerTargetConstraint.data.mid = targetRoot.FindInAllChildren($"{side}Hand{PhalangeBoneNames[i]}2");
|
||||
fingerTargetConstraint.data.tip = targetRoot.FindInAllChildren($"{side}Hand{PhalangeBoneNames[i]}4");
|
||||
}
|
||||
|
||||
Transform thumbTargetParent = new GameObject("FingerTarget5").transform;
|
||||
thumbTargetParent.parent = handTargets;
|
||||
|
||||
Transform thumbTargetRollCorrection1 = new GameObject("FingerTargetRollCorrection1").transform;
|
||||
thumbTargetRollCorrection1.parent = thumbTargetParent;
|
||||
MultiRotationConstraint thumbTargetRollCorrectionConstraint = thumbTargetRollCorrection1.gameObject.AddComponent<MultiRotationConstraint>();
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedObject = targetRoot.FindInAllChildren($"{side}HandThumb1");
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedXAxis = thumbTargetRollCorrectionConstraint.data.constrainedYAxis = thumbTargetRollCorrectionConstraint.data.constrainedZAxis = true;
|
||||
sourceObjects.Add(new WeightedTransform(null, .5f));
|
||||
thumbTargetRollCorrectionConstraint.data.sourceObjects = sourceObjects;
|
||||
sourceObjects.Clear();
|
||||
|
||||
Transform thumbTargetRollCorrection2 = new GameObject("FingerTargetRollCorrection2").transform;
|
||||
thumbTargetRollCorrection2.parent = thumbTargetParent;
|
||||
thumbTargetRollCorrectionConstraint = thumbTargetRollCorrection2.gameObject.AddComponent<MultiRotationConstraint>();
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedObject = targetRoot.FindInAllChildren($"{side}HandThumb2");
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedXAxis = true;
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedYAxis = false;
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedZAxis = false;
|
||||
sourceObjects.Add(new WeightedTransform(null, .3f));
|
||||
thumbTargetRollCorrectionConstraint.data.sourceObjects = sourceObjects;
|
||||
sourceObjects.Clear();
|
||||
|
||||
Transform thumbTargetRollCorrection3 = new GameObject("FingerTargetRollCorrection3").transform;
|
||||
thumbTargetRollCorrection3.parent = thumbTargetParent;
|
||||
thumbTargetRollCorrectionConstraint = thumbTargetRollCorrection3.gameObject.AddComponent<MultiRotationConstraint>();
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedObject = targetRoot.FindInAllChildren($"{side}HandThumb3");
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedXAxis = true;
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedYAxis = false;
|
||||
thumbTargetRollCorrectionConstraint.data.constrainedZAxis = false;
|
||||
sourceObjects.Add(new WeightedTransform(null, .2f));
|
||||
thumbTargetRollCorrectionConstraint.data.sourceObjects = sourceObjects;
|
||||
sourceObjects.Clear();
|
||||
|
||||
Transform thumbTarget = new GameObject("FingerTarget5").transform;
|
||||
thumbTarget.parent = thumbTargetParent;
|
||||
TwoBoneIKConstraint thumbTargetConstraint = thumbTarget.gameObject.AddComponent<TwoBoneIKConstraint>();
|
||||
thumbTargetConstraint.data.root = targetRoot.FindInAllChildren($"{side}HandThumb1");
|
||||
thumbTargetConstraint.data.mid = targetRoot.FindInAllChildren($"{side}HandThumb3");
|
||||
thumbTargetConstraint.data.tip = targetRoot.FindInAllChildren($"{side}HandThumb4");
|
||||
thumbTargetConstraint.data.targetRotationWeight = 0;
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
var root = GetComponentInParent<RigTargets>(true).gameObject;
|
||||
if(PrefabUtility.IsOutermostPrefabInstanceRoot(root))
|
||||
PrefabUtility.ApplyPrefabInstance(root, InteractionMode.AutomatedAction);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Rebind()
|
||||
{
|
||||
foreach (var adaptor in GetComponentsInChildren<RigAdaptorAbs>(true))
|
||||
{
|
||||
adaptor.targetRoot = targetRoot;
|
||||
adaptor.FindRigTargets();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/RigAdaptors/RigConverter.cs.meta
Normal file
11
KFAttached/RigAdaptors/RigConverter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3d68c3fc2fae4143b22cdc25d70652e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
KFAttached/RigAdaptors/RigConverterRole.cs
Normal file
14
KFAttached/RigAdaptors/RigConverterRole.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("KFAttachments/RigAdaptors/Rig Converter Ignore")]
|
||||
public class RigConverterRole : MonoBehaviour
|
||||
{
|
||||
public enum Role
|
||||
{
|
||||
Normal,
|
||||
Reverse,
|
||||
Ignore
|
||||
}
|
||||
|
||||
public Role role;
|
||||
}
|
||||
11
KFAttached/RigAdaptors/RigConverterRole.cs.meta
Normal file
11
KFAttached/RigAdaptors/RigConverterRole.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0ab4e79948fd2844a1e3857e46066dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
183
KFAttached/RigAdaptors/RigTargets.cs
Normal file
183
KFAttached/RigAdaptors/RigTargets.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
#if NotEditor
|
||||
using KFCommonUtilityLib.Scripts.StaticManagers;
|
||||
using UniLinq;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
[AddComponentMenu("KFAttachments/RigAdaptors/Rig Targets")]
|
||||
public class RigTargets : AnimationTargetsAbs
|
||||
{
|
||||
[Header("Fpv Fields")]
|
||||
[SerializeField]
|
||||
public Transform itemFpv;
|
||||
[SerializeField]
|
||||
public Rig rig;
|
||||
[SerializeField]
|
||||
public Transform attachmentReference;
|
||||
|
||||
private RigLayer rigLayerFpv;
|
||||
|
||||
private Animator itemAnimator;
|
||||
|
||||
public override Transform ItemFpv { get => itemFpv; protected set => itemFpv = value; }
|
||||
public override Transform AttachmentRef { get => attachmentReference; protected set => attachmentReference = value; }
|
||||
protected override Animator ItemAnimatorFpv => itemAnimator;
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
if (!itemFpv)
|
||||
return;
|
||||
itemAnimator = itemFpv.GetComponentInChildren<Animator>(true);
|
||||
#if NotEditor
|
||||
itemAnimator.writeDefaultValuesOnDisable = true;
|
||||
#endif
|
||||
#if NotEditor
|
||||
rig.gameObject.name += $"_UID_{TypeBasedUID<AnimationTargetsAbs>.UID}";
|
||||
AnimationRiggingManager.AddRigExcludeName(rig.gameObject.name);
|
||||
|
||||
itemFpv.gameObject.SetActive(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
if (!itemFpv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsFpv)
|
||||
{
|
||||
if (ItemAnimatorFpv.TryGetComponent<AnimationDelayRender>(out var delayRenderer))
|
||||
{
|
||||
Destroy(delayRenderer);
|
||||
}
|
||||
itemFpv.SetParent(PlayerAnimatorTrans.parent, false);
|
||||
itemFpv.SetAsFirstSibling();
|
||||
itemFpv.position = Vector3.zero;
|
||||
itemFpv.localPosition = Vector3.zero;
|
||||
itemFpv.localRotation = Quaternion.identity;
|
||||
var rc = rig.GetComponent<RigConverter>();
|
||||
rc.targetRoot = PlayerAnimatorTrans;
|
||||
rc.Rebind();
|
||||
}
|
||||
else
|
||||
{
|
||||
itemFpv.SetParent(PlayerAnimatorTrans.parent);
|
||||
itemFpv.position = Vector3.zero;
|
||||
itemFpv.localPosition = Vector3.zero;
|
||||
itemFpv.localRotation = Quaternion.identity;
|
||||
}
|
||||
//Log.Out($"set parent to {PlayerAnimatorTrans.parent.parent.name}/{PlayerAnimatorTrans.parent.name}\n{StackTraceUtility.ExtractStackTrace()}");
|
||||
|
||||
//#if NotEditor
|
||||
// Utils.SetLayerRecursively(itemFpv.gameObject, 10, Utils.ExcludeLayerZoom);
|
||||
// Utils.SetLayerRecursively(gameObject, 24, Utils.ExcludeLayerZoom);
|
||||
//#endif
|
||||
//LogInfo(itemFpv.localPosition.ToString() + " / " + itemFpv.localEulerAngles.ToString());
|
||||
}
|
||||
|
||||
protected override bool SetupFpv()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
rig.transform.SetParent(PlayerAnimatorTrans, false);
|
||||
rig.transform.position = Vector3.zero;
|
||||
rig.transform.localPosition = Vector3.zero;
|
||||
rig.transform.localRotation = Quaternion.identity;
|
||||
|
||||
var rigBuilder = PlayerAnimatorTrans.AddMissingComponent<RigBuilder>();
|
||||
rigBuilder.layers.Insert(0, rigLayerFpv = new RigLayer(rig, true));
|
||||
#if NotEditor
|
||||
foreach (var layer in rigBuilder.layers)
|
||||
{
|
||||
if (layer.name == SDCSUtils.IKRIG)
|
||||
{
|
||||
layer.active = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
BuildRig(rigBuilder.GetComponent<Animator>(), rigBuilder);
|
||||
sw.Stop();
|
||||
string info = $"setup animation rig took {sw.ElapsedMilliseconds} ms";
|
||||
//info += $"\n{StackTraceUtility.ExtractStackTrace()}";
|
||||
Log.Out(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void RemoveFpv()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
var rigBuilder = PlayerAnimatorTrans.AddMissingComponent<RigBuilder>();
|
||||
int removed = rigBuilder.layers.RemoveAll(r => r.name == rigLayerFpv.name);
|
||||
//#if NotEditor
|
||||
// Log.Out($"Removed {removed} layers, remaining:\n{string.Join("\n", rigBuilder.layers.Select(layer => layer.name))}");
|
||||
//#endif
|
||||
rig.transform.SetParent(transform, false);
|
||||
rig.gameObject.SetActive(false);
|
||||
rigLayerFpv = null;
|
||||
#if NotEditor
|
||||
foreach (var layer in rigBuilder.layers)
|
||||
{
|
||||
if (layer.name == SDCSUtils.IKRIG)
|
||||
{
|
||||
layer.active = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
BuildRig(rigBuilder.GetComponent<Animator>(), rigBuilder);
|
||||
sw.Stop();
|
||||
string info = $"destroy animation rig took {sw.ElapsedMilliseconds} ms";
|
||||
//info += $"\n{StackTraceUtility.ExtractStackTrace()}";
|
||||
Log.Out(info);
|
||||
}
|
||||
|
||||
public override void DestroyFpv()
|
||||
{
|
||||
#if NotEditor
|
||||
if (rig)
|
||||
{
|
||||
AnimationRiggingManager.RemoveRigExcludeName(rig.gameObject.name);
|
||||
}
|
||||
#endif
|
||||
base.DestroyFpv();
|
||||
if (rig)
|
||||
{
|
||||
rig.transform.parent = null;
|
||||
GameObject.DestroyImmediate(rig.gameObject);
|
||||
}
|
||||
rig = null;
|
||||
}
|
||||
|
||||
public override void SetEnabled(bool enabled)
|
||||
{
|
||||
//var t = new StackTrace();
|
||||
|
||||
//LogInfo($"set enabled {isFPV} stack trace:\n{t.ToString()}");
|
||||
if (itemFpv)
|
||||
{
|
||||
itemFpv.localPosition = enabled ? Vector3.zero : new Vector3(0, -100, 0);
|
||||
}
|
||||
base.SetEnabled(enabled);
|
||||
#if NotEditor
|
||||
if (enabled && IsFpv && ItemAnimatorFpv && !ItemAnimatorFpv.TryGetComponent<AnimationDelayRender>(out var delayRenderer))
|
||||
{
|
||||
delayRenderer = ItemAnimatorFpv.gameObject.AddComponent<AnimationDelayRender>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NotEditor
|
||||
public override void UpdatePlayerAvatar(AvatarController avatarController, bool rigWeaponChanged)
|
||||
{
|
||||
base.UpdatePlayerAvatar(avatarController, rigWeaponChanged);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
11
KFAttached/RigAdaptors/RigTargets.cs.meta
Normal file
11
KFAttached/RigAdaptors/RigTargets.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b5aed79c0403ae438dd1f929cc1391e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
KFAttached/RigAdaptors/Utils.meta
Normal file
8
KFAttached/RigAdaptors/Utils.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfcfb8cce097e304f91fab84a5e76ed8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
KFAttached/RigAdaptors/Utils/InventorySlotGurad.cs
Normal file
25
KFAttached/RigAdaptors/Utils/InventorySlotGurad.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
public class InventorySlotGurad
|
||||
{
|
||||
public int Slot { get; private set; } = -1;
|
||||
|
||||
#if NotEditor
|
||||
public bool IsValid(EntityAlive entity)
|
||||
{
|
||||
if (entity && entity.inventory != null)
|
||||
{
|
||||
if (Slot < 0)
|
||||
{
|
||||
Slot = entity.inventory.holdingItemIdx;
|
||||
return true;
|
||||
}
|
||||
if (Slot != entity.inventory.holdingItemIdx)
|
||||
{
|
||||
Log.Warning($"trying to set ammo for slot {Slot} while holding slot {entity.inventory.holdingItemIdx} on entity {entity.entityId}!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
11
KFAttached/RigAdaptors/Utils/InventorySlotGurad.cs.meta
Normal file
11
KFAttached/RigAdaptors/Utils/InventorySlotGurad.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cf53ce461844eb4eb8f418707f838d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
431
KFAttached/RigAdaptors/Utils/KFExtensions.cs
Normal file
431
KFAttached/RigAdaptors/Utils/KFExtensions.cs
Normal file
@@ -0,0 +1,431 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public static class KFExtensions
|
||||
{
|
||||
public static Transform FindInAllChildren(this Transform target, string name, bool onlyActive = false)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!onlyActive || (onlyActive && (bool)target.gameObject && target.gameObject.activeSelf))
|
||||
{
|
||||
if (target.name == name)
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
for (int i = 0; i < target.childCount; i++)
|
||||
{
|
||||
Transform transform = target.GetChild(i).FindInAllChildren(name, onlyActive);
|
||||
if (transform != null)
|
||||
{
|
||||
return transform;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static T AddMissingComponent<T>(this Transform transform) where T : Component
|
||||
{
|
||||
if (!transform.TryGetComponent<T>(out var val))
|
||||
{
|
||||
val = transform.gameObject.AddComponent<T>();
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
public static Component AddMissingComponent(this Transform transform, Type type)
|
||||
{
|
||||
if (!transform.TryGetComponent(type, out var val))
|
||||
{
|
||||
val = transform.gameObject.AddComponent(type);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
public static void RotateAroundPivot(this Transform self, Transform pivot, Vector3 angles)
|
||||
{
|
||||
Vector3 dir = self.InverseTransformVector(self.position - pivot.position); // get point direction relative to pivot
|
||||
Quaternion rot = Quaternion.Euler(angles);
|
||||
dir = rot * dir; // rotate it
|
||||
self.localPosition = dir + self.InverseTransformPoint(pivot.position); // calculate rotated point
|
||||
self.localRotation = rot;
|
||||
}
|
||||
|
||||
public static void RotateAroundPivot(this Transform self, Transform pivot, Quaternion rotation)
|
||||
{
|
||||
Vector3 dir = self.InverseTransformVector(self.position - pivot.position); // get point direction relative to pivot
|
||||
dir = rotation * dir; // rotate it
|
||||
self.localPosition = dir + self.InverseTransformPoint(pivot.position); // calculate rotated point
|
||||
self.localRotation = rotation;
|
||||
}
|
||||
|
||||
public static Vector3 Random(Vector3 min, Vector3 max)
|
||||
{
|
||||
return new Vector3(UnityEngine.Random.Range(min.x, max.x), UnityEngine.Random.Range(min.y, max.y), UnityEngine.Random.Range(min.z, max.z));
|
||||
}
|
||||
|
||||
public static Vector3 Clamp(Vector3 val, Vector3 min, Vector3 max)
|
||||
{
|
||||
return new Vector3(Mathf.Clamp(val.x, min.x, max.x), Mathf.Clamp(val.y, min.y, max.y), Mathf.Clamp(val.z, min.z, max.z));
|
||||
}
|
||||
|
||||
public static Vector3 SmoothStep(Vector3 from, Vector3 to, float t)
|
||||
{
|
||||
return new Vector3(Mathf.SmoothStep(from.x, to.x, t), Mathf.SmoothStep(from.y, to.y, t), Mathf.SmoothStep(from.z, to.z, t));
|
||||
}
|
||||
|
||||
public static float AngleToInferior(float angle)
|
||||
{
|
||||
angle %= 360;
|
||||
angle = angle > 180 ? angle - 360 : angle;
|
||||
return angle;
|
||||
}
|
||||
|
||||
public static Vector3 AngleToInferior(Vector3 angle)
|
||||
{
|
||||
return new Vector3(AngleToInferior(angle.x), AngleToInferior(angle.y), AngleToInferior(angle.z));
|
||||
}
|
||||
|
||||
public static IAnimatorWrapper GetWrapperForParam(this Animator self, AnimatorControllerParameter param, bool prefVanilla = false)
|
||||
{
|
||||
if (!self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
return AnimationGraphBuilder.DummyWrapper;
|
||||
switch (builder.GetWrapperRoleByParam(param))
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
if (prefVanilla)
|
||||
{
|
||||
return builder.VanillaWrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
return builder.WeaponWrapper;
|
||||
}
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
return builder.VanillaWrapper;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
return builder.WeaponWrapper;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Attachments:
|
||||
return builder.AttachmentWrapper;
|
||||
default:
|
||||
return AnimationGraphBuilder.DummyWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
public static IAnimatorWrapper GetWrapperForParamHash(this Animator self, int nameHash, bool prefVanilla = false)
|
||||
{
|
||||
if (!self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
return AnimationGraphBuilder.DummyWrapper;
|
||||
switch (builder.GetWrapperRoleByParamHash(nameHash))
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
if (prefVanilla)
|
||||
{
|
||||
return builder.VanillaWrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
return builder.WeaponWrapper;
|
||||
}
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
return builder.VanillaWrapper;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
return builder.WeaponWrapper;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Attachments:
|
||||
return builder.AttachmentWrapper;
|
||||
default:
|
||||
return AnimationGraphBuilder.DummyWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
public static IAnimatorWrapper GetWrapperForParamName(this Animator self, string name, bool prefVanilla = false)
|
||||
{
|
||||
if (!self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
return AnimationGraphBuilder.DummyWrapper;
|
||||
switch (builder.GetWrapperRoleByParamName(name))
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
if (prefVanilla)
|
||||
{
|
||||
return builder.VanillaWrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
return builder.WeaponWrapper;
|
||||
}
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
return builder.VanillaWrapper;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
return builder.WeaponWrapper;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Attachments:
|
||||
return builder.AttachmentWrapper;
|
||||
default:
|
||||
return AnimationGraphBuilder.DummyWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetWrappedBool(this Animator self, int _propertyHash)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
var wrapper = self.GetWrapperForParamHash(_propertyHash);
|
||||
if (wrapper != null && wrapper.IsValid)
|
||||
{
|
||||
return wrapper.GetBool(_propertyHash);
|
||||
}
|
||||
return self.GetBool(_propertyHash);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int GetWrappedInt(this Animator self, int _propertyHash)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
var wrapper = self.GetWrapperForParamHash(_propertyHash);
|
||||
if (wrapper != null && wrapper.IsValid)
|
||||
{
|
||||
return wrapper.GetInteger(_propertyHash);
|
||||
}
|
||||
return self.GetInteger(_propertyHash);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static float GetWrappedFloat(this Animator self, int _propertyHash)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
var wrapper = self.GetWrapperForParamHash(_propertyHash);
|
||||
if (wrapper != null && wrapper.IsValid)
|
||||
{
|
||||
return wrapper.GetFloat(_propertyHash);
|
||||
}
|
||||
return self.GetFloat(_propertyHash);
|
||||
}
|
||||
return float.NaN;
|
||||
}
|
||||
|
||||
public static void SetWrappedTrigger(this Animator self, int _propertyHash)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
var role = builder.GetWrapperRoleByParamHash(_propertyHash);
|
||||
switch(role)
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
builder.VanillaWrapper.SetTrigger(_propertyHash);
|
||||
builder.WeaponWrapper.SetTrigger(_propertyHash);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
builder.VanillaWrapper.SetTrigger(_propertyHash);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
builder.WeaponWrapper.SetTrigger(_propertyHash);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
builder.SetChildTrigger(_propertyHash);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.SetTrigger(_propertyHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetWrappedTrigger(this Animator self, int _propertyHash)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
var role = builder.GetWrapperRoleByParamHash(_propertyHash);
|
||||
switch (role)
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
builder.VanillaWrapper.ResetTrigger(_propertyHash);
|
||||
builder.WeaponWrapper.ResetTrigger(_propertyHash);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
builder.VanillaWrapper.ResetTrigger(_propertyHash);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
builder.WeaponWrapper.ResetTrigger(_propertyHash);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
builder.ResetChildTrigger(_propertyHash);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.ResetTrigger(_propertyHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetWrappedBool(this Animator self, int _propertyHash, bool _value)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
var role = builder.GetWrapperRoleByParamHash(_propertyHash);
|
||||
switch (role)
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
builder.VanillaWrapper.SetBool(_propertyHash, _value);
|
||||
builder.WeaponWrapper.SetBool(_propertyHash, _value);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
builder.VanillaWrapper.SetBool(_propertyHash, _value);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
builder.WeaponWrapper.SetBool(_propertyHash, _value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
builder.SetChildBool(_propertyHash, _value);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.SetBool(_propertyHash, _value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetWrappedInt(this Animator self, int _propertyHash, int _value)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
var role = builder.GetWrapperRoleByParamHash(_propertyHash);
|
||||
switch (role)
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
builder.VanillaWrapper.SetInteger(_propertyHash, _value);
|
||||
builder.WeaponWrapper.SetInteger(_propertyHash, _value);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
builder.VanillaWrapper.SetInteger(_propertyHash, _value);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
builder.WeaponWrapper.SetInteger(_propertyHash, _value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
builder.SetChildInteger(_propertyHash, _value);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.SetInteger(_propertyHash, _value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetWrappedFloat(this Animator self, int _propertyHash, float _value)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
var role = builder.GetWrapperRoleByParamHash(_propertyHash);
|
||||
switch (role)
|
||||
{
|
||||
case AnimationGraphBuilder.ParamInWrapper.Both:
|
||||
builder.VanillaWrapper.SetFloat(_propertyHash, _value);
|
||||
builder.WeaponWrapper.SetFloat(_propertyHash, _value);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Vanilla:
|
||||
builder.VanillaWrapper.SetFloat(_propertyHash, _value);
|
||||
break;
|
||||
case AnimationGraphBuilder.ParamInWrapper.Weapon:
|
||||
builder.WeaponWrapper.SetFloat(_propertyHash, _value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
builder.SetChildFloat(_propertyHash, _value);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.SetFloat(_propertyHash, _value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static AnimatorControllerParameter[] GetWrappedParameters(this Animator self)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder) && builder.HasWeaponOverride)
|
||||
{
|
||||
return builder.Parameters;
|
||||
}
|
||||
return self.parameters;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IAnimatorWrapper GetItemAnimatorWrapper(this Animator self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
return builder.WeaponWrapper;
|
||||
return new AnimatorWrapper(self);
|
||||
}
|
||||
|
||||
public static bool IsVanillaInTransition(this Animator self, int layerIndex)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
return builder.VanillaWrapper.IsInTransition(layerIndex);
|
||||
}
|
||||
return self.IsInTransition(layerIndex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static AnimatorStateInfo GetCurrentVanillaStateInfo(this Animator self, int layerIndex)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
return builder.VanillaWrapper.GetCurrentAnimatorStateInfo(layerIndex);
|
||||
}
|
||||
return self.GetCurrentAnimatorStateInfo(layerIndex);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public static void SetVanillaLayerWeight(this Animator self, int layerIndex, float weight)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
if (self.TryGetComponent<AnimationGraphBuilder>(out var builder))
|
||||
{
|
||||
builder.VanillaWrapper.SetLayerWeight(layerIndex, weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.SetLayerWeight(layerIndex, weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
KFAttached/RigAdaptors/Utils/KFExtensions.cs.meta
Normal file
11
KFAttached/RigAdaptors/Utils/KFExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4347de315a685e4482f8ad79c488d19
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
64
KFAttached/RigAdaptors/Utils/QuaternionUtil.cs
Normal file
64
KFAttached/RigAdaptors/Utils/QuaternionUtil.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
|
||||
/*
|
||||
Copyright 2016 Max Kaufmann (max.kaufmann@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public static class QuaternionUtil {
|
||||
|
||||
public static Quaternion AngVelToDeriv(Quaternion Current, Vector3 AngVel) {
|
||||
var Spin = new Quaternion(AngVel.x, AngVel.y, AngVel.z, 0f);
|
||||
var Result = Spin * Current;
|
||||
return new Quaternion(0.5f * Result.x, 0.5f * Result.y, 0.5f * Result.z, 0.5f * Result.w);
|
||||
}
|
||||
|
||||
public static Vector3 DerivToAngVel(Quaternion Current, Quaternion Deriv) {
|
||||
var Result = Deriv * Quaternion.Inverse(Current);
|
||||
return new Vector3(2f * Result.x, 2f * Result.y, 2f * Result.z);
|
||||
}
|
||||
|
||||
public static Quaternion IntegrateRotation(Quaternion Rotation, Vector3 AngularVelocity, float DeltaTime) {
|
||||
if (DeltaTime < Mathf.Epsilon) return Rotation;
|
||||
var Deriv = AngVelToDeriv(Rotation, AngularVelocity);
|
||||
var Pred = new Vector4(
|
||||
Rotation.x + Deriv.x * DeltaTime,
|
||||
Rotation.y + Deriv.y * DeltaTime,
|
||||
Rotation.z + Deriv.z * DeltaTime,
|
||||
Rotation.w + Deriv.w * DeltaTime
|
||||
).normalized;
|
||||
return new Quaternion(Pred.x, Pred.y, Pred.z, Pred.w);
|
||||
}
|
||||
|
||||
public static Quaternion SmoothDamp(Quaternion rot, Quaternion target, ref Quaternion deriv, float time) {
|
||||
if (Time.deltaTime < Mathf.Epsilon) return rot;
|
||||
// account for double-cover
|
||||
var Dot = Quaternion.Dot(rot, target);
|
||||
var Multi = Dot > 0f ? 1f : -1f;
|
||||
target.x *= Multi;
|
||||
target.y *= Multi;
|
||||
target.z *= Multi;
|
||||
target.w *= Multi;
|
||||
// smooth damp (nlerp approx)
|
||||
var Result = new Vector4(
|
||||
Mathf.SmoothDamp(rot.x, target.x, ref deriv.x, time),
|
||||
Mathf.SmoothDamp(rot.y, target.y, ref deriv.y, time),
|
||||
Mathf.SmoothDamp(rot.z, target.z, ref deriv.z, time),
|
||||
Mathf.SmoothDamp(rot.w, target.w, ref deriv.w, time)
|
||||
).normalized;
|
||||
|
||||
// ensure deriv is tangent
|
||||
var derivError = Vector4.Project(new Vector4(deriv.x, deriv.y, deriv.z, deriv.w), Result);
|
||||
deriv.x -= derivError.x;
|
||||
deriv.y -= derivError.y;
|
||||
deriv.z -= derivError.z;
|
||||
deriv.w -= derivError.w;
|
||||
|
||||
return new Quaternion(Result.x, Result.y, Result.z, Result.w);
|
||||
}
|
||||
}
|
||||
11
KFAttached/RigAdaptors/Utils/QuaternionUtil.cs.meta
Normal file
11
KFAttached/RigAdaptors/Utils/QuaternionUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52358614fb4cc7645abfdec7b22f0dc8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user