Upload from upload_mods.ps1
This commit is contained in:
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