//ping phong 运动
using UnityEngine; public class AutoMove : MonoBehaviour { public float Speed = 1.0f; public Transform PointStart; public Transform PointEnd; void Start () { transform.position = PointStart.position; } void Update () { float deltaTime = Mathf.PingPong(Time.time*Speed, 1); transform.position = Vector3.Lerp( PointStart.position, PointEnd.position, deltaTime ); } }//tilt window(四元数的用法)
public class TiltWindowCustom : MonoBehaviour { [Tooltip("以角度为单位")] public Vector2 range = new Vector2(5f, 3f); Transform mTrans; Quaternion mStart; Vector2 mRot = Vector2.zero; void Start() { mTrans = transform; mStart = mTrans.localRotation; } void Update() { Vector3 pos = Input.mousePosition; float halfWidth = Screen.width * 0.5f; float halfHeight = Screen.height * 0.5f; //屏幕鼠标位置为中心点的时候为0 float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f); float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f); mRot = Vector2.Lerp(mRot, new Vector2(x, y), Time.deltaTime * 5f); mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y * range.y, mRot.x * range.x, 0f); } }//到达某一状态后执行操作。
IEnumerator DisablePanelDeleyed(Animator anim) { bool closedStateReached = false;//一开始状态没有到达 bool wantToClose = true; while (!closedStateReached && wantToClose) { if (!anim.IsInTransition(0))//没有处于过渡状态的,0表示Layer索引下标 closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(k_ClosedStateName); yield return new WaitForEndOfFrame(); } //到达close状态后隐藏当前obj if (wantToClose) anim.gameObject.SetActive(false); }//gpu instance
internal void ObjInstancing(int num) { TransInfos = new Matrix4x4[num]; for (int i = 0; i < num; i++) { SpecificAttributes sa = new SpecificAttributes(); TransInfos[i] = sa.TransMatrix; } Graphics.DrawMeshInstanced(mSharedMesh, 0, mSharedMaterial, TransInfos); } public SpecificAttributes() { mPos = UnityEngine.Random.insideUnitSphere * 10; mRot = Quaternion.LookRotation(UnityEngine.Random.insideUnitSphere); mScale = Vector3.one * UnityEngine.Random.Range(1, 3); TransMatrix = Matrix4x4.TRS(mPos, mRot, mScale); } //MARKER CAMERA SHAKE SHAKE private void ShakeCamera() { if (shakeAmplitude > 0) { shakeActive = new Vector3(Random.Range(-shakeAmplitude, shakeAmplitude), Random.Range(-shakeAmplitude, shakeAmplitude), 0); shakeAmplitude -= Time.deltaTime; } else { shakeActive = Vector3.zero; } transform.position += shakeActive; }