From fc6de82e75310b4c007d80753a5f58e6692f4855 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 13 Oct 2020 10:33:05 +0800 Subject: +misc --- Assets/Scripts/Test/AimTest.cs | 32 +++---- Assets/Scripts/Test/CentreTest.cs | 44 ++++----- Assets/Scripts/Test/FootIKTest.cs | 136 +++++++++++++-------------- Assets/Scripts/Test/HitBoxTest.cs | 72 +++++++------- Assets/Scripts/Test/IKTest.cs | 66 ++++++------- Assets/Scripts/Test/PhysicsWorldTest.cs | 18 ++++ Assets/Scripts/Test/PhysicsWorldTest.cs.meta | 11 +++ Assets/Scripts/Test/RootConstainTest.cs | 70 +++++++------- Assets/Scripts/Test/SaionjiScript.cs | 50 +++++----- 9 files changed, 264 insertions(+), 235 deletions(-) create mode 100644 Assets/Scripts/Test/PhysicsWorldTest.cs create mode 100644 Assets/Scripts/Test/PhysicsWorldTest.cs.meta (limited to 'Assets/Scripts/Test') diff --git a/Assets/Scripts/Test/AimTest.cs b/Assets/Scripts/Test/AimTest.cs index ad33221b..d69c4a41 100644 --- a/Assets/Scripts/Test/AimTest.cs +++ b/Assets/Scripts/Test/AimTest.cs @@ -1,16 +1,16 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class AimTest : MonoBehaviour -{ - public GameObject Go_ConstainObj; - - public GameObject Go_AimTarget; - - public void LateUpdate() - { - Go_ConstainObj.transform.LookAt(Go_AimTarget.transform); - } - -} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class AimTest : MonoBehaviour +{ + public GameObject Go_ConstainObj; + + public GameObject Go_AimTarget; + + public void LateUpdate() + { + Go_ConstainObj.transform.LookAt(Go_AimTarget.transform); + } + +} diff --git a/Assets/Scripts/Test/CentreTest.cs b/Assets/Scripts/Test/CentreTest.cs index 1338067d..b921cc59 100644 --- a/Assets/Scripts/Test/CentreTest.cs +++ b/Assets/Scripts/Test/CentreTest.cs @@ -1,22 +1,22 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class CentreTest : MonoBehaviour -{ - - public Transform Trans_Saionji_Left; - public Transform Trans_Saionji_Right; - - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - transform.position = (Trans_Saionji_Left.position + Trans_Saionji_Right.position ) / 2; - } -} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CentreTest : MonoBehaviour +{ + + public Transform Trans_Saionji_Left; + public Transform Trans_Saionji_Right; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + transform.position = (Trans_Saionji_Left.position + Trans_Saionji_Right.position ) / 2; + } +} diff --git a/Assets/Scripts/Test/FootIKTest.cs b/Assets/Scripts/Test/FootIKTest.cs index f1711ade..5b939619 100644 --- a/Assets/Scripts/Test/FootIKTest.cs +++ b/Assets/Scripts/Test/FootIKTest.cs @@ -1,69 +1,69 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class FootIKTest : MonoBehaviour -{ - - Animator anim; - - public LayerMask layerMask; - - [Range(0, 1f)] - public float DistanceToGround; - - private void Start() - { - - anim = GetComponent(); - - } - - private void OnAnimatorIK(int layerIndex) - { - - if (anim) - { - - anim.SetIKPositionWeight(AvatarIKGoal.LeftFoot, anim.GetFloat("IKLeftFootWeight")); - anim.SetIKRotationWeight(AvatarIKGoal.LeftFoot, anim.GetFloat("IKLeftFootWeight")); - anim.SetIKPositionWeight(AvatarIKGoal.RightFoot, anim.GetFloat("IKRightFootWeight")); - anim.SetIKRotationWeight(AvatarIKGoal.RightFoot, anim.GetFloat("IKRightFootWeight")); - - // Left Foot - RaycastHit hit; - Ray ray = new Ray(anim.GetIKPosition(AvatarIKGoal.LeftFoot) + Vector3.up, Vector3.down); - if (Physics.Raycast(ray, out hit, DistanceToGround + 1f, layerMask)) - { - if (hit.transform.tag == "Walkable") - { - Vector3 footOriginForward = anim.GetBoneTransform(HumanBodyBones.LeftFoot).forward; - Vector3 footPosition = hit.point; - footPosition.y += DistanceToGround; - anim.SetIKPosition(AvatarIKGoal.LeftFoot, footPosition); - anim.SetIKRotation(AvatarIKGoal.LeftFoot, Quaternion.LookRotation(footOriginForward - Vector3.Dot(footOriginForward, hit.normal) *(hit.normal), hit.normal)); - } - } - - // Right Foot - ray = new Ray(anim.GetIKPosition(AvatarIKGoal.RightFoot) + Vector3.up, Vector3.down); - if (Physics.Raycast(ray, out hit, DistanceToGround + 1f, layerMask)) - { - - if (hit.transform.tag == "Walkable") - { - Vector3 footOriginForward = anim.GetBoneTransform(HumanBodyBones.RightFoot).forward; - Vector3 footPosition = hit.point; - footPosition.y += DistanceToGround; - anim.SetIKPosition(AvatarIKGoal.RightFoot, footPosition); - anim.SetIKRotation(AvatarIKGoal.RightFoot, Quaternion.LookRotation(footOriginForward - Vector3.Dot(footOriginForward, hit.normal) * (hit.normal), hit.normal)); - } - - } - - - } - - } - +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FootIKTest : MonoBehaviour +{ + + Animator anim; + + public LayerMask layerMask; + + [Range(0, 1f)] + public float DistanceToGround; + + private void Start() + { + + anim = GetComponent(); + + } + + private void OnAnimatorIK(int layerIndex) + { + + if (anim) + { + + anim.SetIKPositionWeight(AvatarIKGoal.LeftFoot, anim.GetFloat("IKLeftFootWeight")); + anim.SetIKRotationWeight(AvatarIKGoal.LeftFoot, anim.GetFloat("IKLeftFootWeight")); + anim.SetIKPositionWeight(AvatarIKGoal.RightFoot, anim.GetFloat("IKRightFootWeight")); + anim.SetIKRotationWeight(AvatarIKGoal.RightFoot, anim.GetFloat("IKRightFootWeight")); + + // Left Foot + RaycastHit hit; + Ray ray = new Ray(anim.GetIKPosition(AvatarIKGoal.LeftFoot) + Vector3.up, Vector3.down); + if (Physics.Raycast(ray, out hit, DistanceToGround + 1f, layerMask)) + { + if (hit.transform.tag == "Walkable") + { + Vector3 footOriginForward = anim.GetBoneTransform(HumanBodyBones.LeftFoot).forward; + Vector3 footPosition = hit.point; + footPosition.y += DistanceToGround; + anim.SetIKPosition(AvatarIKGoal.LeftFoot, footPosition); + anim.SetIKRotation(AvatarIKGoal.LeftFoot, Quaternion.LookRotation(footOriginForward - Vector3.Dot(footOriginForward, hit.normal) *(hit.normal), hit.normal)); + } + } + + // Right Foot + ray = new Ray(anim.GetIKPosition(AvatarIKGoal.RightFoot) + Vector3.up, Vector3.down); + if (Physics.Raycast(ray, out hit, DistanceToGround + 1f, layerMask)) + { + + if (hit.transform.tag == "Walkable") + { + Vector3 footOriginForward = anim.GetBoneTransform(HumanBodyBones.RightFoot).forward; + Vector3 footPosition = hit.point; + footPosition.y += DistanceToGround; + anim.SetIKPosition(AvatarIKGoal.RightFoot, footPosition); + anim.SetIKRotation(AvatarIKGoal.RightFoot, Quaternion.LookRotation(footOriginForward - Vector3.Dot(footOriginForward, hit.normal) * (hit.normal), hit.normal)); + } + + } + + + } + + } + } \ No newline at end of file diff --git a/Assets/Scripts/Test/HitBoxTest.cs b/Assets/Scripts/Test/HitBoxTest.cs index 57b0d1af..139ec287 100644 --- a/Assets/Scripts/Test/HitBoxTest.cs +++ b/Assets/Scripts/Test/HitBoxTest.cs @@ -1,36 +1,36 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -// AABB hitbox -public class HitBoxTest : MonoBehaviour -{ - public bool DrawGizmo; - - [SerializeField] - private bool m_IsActive; - - [SerializeField] - private Vector3 m_TopLeft, m_RightBottom; - - private void OnDrawGizmos() - { - if (!DrawGizmo) return; - Gizmos.color = Color.green; - Vector3 topleft = transform.position + m_TopLeft; - Vector3 rightbottom = transform.position + m_RightBottom; - Gizmos.DrawCube((topleft + rightbottom) / 2, rightbottom - topleft); - } - - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// AABB hitbox +public class HitBoxTest : MonoBehaviour +{ + public bool DrawGizmo; + + [SerializeField] + private bool m_IsActive; + + [SerializeField] + private Vector3 m_TopLeft, m_RightBottom; + + private void OnDrawGizmos() + { + if (!DrawGizmo) return; + Gizmos.color = Color.green; + Vector3 topleft = transform.position + m_TopLeft; + Vector3 rightbottom = transform.position + m_RightBottom; + Gizmos.DrawCube((topleft + rightbottom) / 2, rightbottom - topleft); + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Test/IKTest.cs b/Assets/Scripts/Test/IKTest.cs index 4e203be9..fdc5c2a3 100644 --- a/Assets/Scripts/Test/IKTest.cs +++ b/Assets/Scripts/Test/IKTest.cs @@ -1,33 +1,33 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class IKTest : MonoBehaviour -{ - public GameObject Go_FootIK; - [Range(0,1)] - public float IKWeight; - - private Animator animator; - - private void Start() - { - - } - - private void OnAnimatorIK(int layerIndex) - { - if(animator == null) - { - animator = GetComponent(); - } - - animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, IKWeight); - animator.SetIKPosition(AvatarIKGoal.LeftFoot, Go_FootIK.transform.position); - - animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, IKWeight); - animator.SetIKRotation(AvatarIKGoal.LeftFoot, Go_FootIK.transform.rotation); - - } - -} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class IKTest : MonoBehaviour +{ + public GameObject Go_FootIK; + [Range(0,1)] + public float IKWeight; + + private Animator animator; + + private void Start() + { + + } + + private void OnAnimatorIK(int layerIndex) + { + if(animator == null) + { + animator = GetComponent(); + } + + animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, IKWeight); + animator.SetIKPosition(AvatarIKGoal.LeftFoot, Go_FootIK.transform.position); + + animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, IKWeight); + animator.SetIKRotation(AvatarIKGoal.LeftFoot, Go_FootIK.transform.rotation); + + } + +} diff --git a/Assets/Scripts/Test/PhysicsWorldTest.cs b/Assets/Scripts/Test/PhysicsWorldTest.cs new file mode 100644 index 00000000..7c177213 --- /dev/null +++ b/Assets/Scripts/Test/PhysicsWorldTest.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PhysicsWorldTest : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Test/PhysicsWorldTest.cs.meta b/Assets/Scripts/Test/PhysicsWorldTest.cs.meta new file mode 100644 index 00000000..6e113c78 --- /dev/null +++ b/Assets/Scripts/Test/PhysicsWorldTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bef3db5279f15c347a57f806171eaa33 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Test/RootConstainTest.cs b/Assets/Scripts/Test/RootConstainTest.cs index 43c22b67..3de174ee 100644 --- a/Assets/Scripts/Test/RootConstainTest.cs +++ b/Assets/Scripts/Test/RootConstainTest.cs @@ -1,35 +1,35 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class RootConstainTest : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } - - private void OnAnimatorMove() - { - Animator animator = GetComponent(); - - // 约束z=0 - if (animator) - { - //animator.ApplyBuiltinRootMotion(); - transform.position += new Vector3(animator.deltaPosition.x, animator.deltaPosition.y, 0); - transform.forward = animator.deltaRotation * transform.forward; - Vector3 euler = animator.deltaRotation.ToEuler(); - euler.x = euler.z = euler.y = 0; - transform.rotation *= Quaternion.Euler(euler); - } - } - -} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RootConstainTest : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + private void OnAnimatorMove() + { + Animator animator = GetComponent(); + + // 约束z=0 + if (animator) + { + //animator.ApplyBuiltinRootMotion(); + transform.position += new Vector3(animator.deltaPosition.x, animator.deltaPosition.y, 0); + transform.forward = animator.deltaRotation * transform.forward; + Vector3 euler = animator.deltaRotation.ToEuler(); + euler.x = euler.z = euler.y = 0; + transform.rotation *= Quaternion.Euler(euler); + } + } + +} diff --git a/Assets/Scripts/Test/SaionjiScript.cs b/Assets/Scripts/Test/SaionjiScript.cs index be2fdd59..67a042bd 100644 --- a/Assets/Scripts/Test/SaionjiScript.cs +++ b/Assets/Scripts/Test/SaionjiScript.cs @@ -1,25 +1,25 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class SaionjiScript : MonoBehaviour -{ - - - // Start is called before the first frame update - void Start() - { - - } - - private void OnCollisionEnter(Collision collision) - { - Debug.Log("OnCollisionEnter()"); - } - - private void OnTriggerEnter(Collider other) - { - Debug.Log("OnTriggerEnter()"); - } - -} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SaionjiScript : MonoBehaviour +{ + HitBoxTest hitbox; + + // Start is called before the first frame update + void Start() + { + + } + + private void OnCollisionEnter(Collision collision) + { + Debug.Log("OnCollisionEnter()"); + } + + private void OnTriggerEnter(Collider other) + { + Debug.Log("OnTriggerEnter()"); + } + +} -- cgit v1.1-26-g67d0