열차 목업의 내부 확인용 프로젝트
smchoi
2024-06-14 23cbbc76b6204691dd06f93f2108993f9ca79020
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections.Generic;
 
namespace UnityEngine.XR.Interaction.Toolkit.Samples.Hands
{
    /// <summary>
    /// Provides the ability to reset specified objects if they fall below a certain position - designated by this transform's height.
    /// </summary>
    public class ObjectResetPlane : MonoBehaviour
    {
        [SerializeField]
        [Tooltip("Which objects to reset if falling out of range.")]
        List<Transform> m_ObjectsToReset = new List<Transform>();
 
        [SerializeField]
        [Tooltip("How often to check if objects should be reset.")]
        float m_CheckDuration = 2f;
 
        readonly List<Pose> m_OriginalPositions = new List<Pose>();
 
        float m_CheckTimer;
 
        /// <summary>
        /// See <see cref="MonoBehaviour"/>.
        /// </summary>
        protected void Start()
        {
            foreach (var currentTransform in m_ObjectsToReset)
            {
                if (currentTransform != null)
                {
                    m_OriginalPositions.Add(new Pose(currentTransform.position, currentTransform.rotation));
                }
                else
                {
                    Debug.LogWarning("Objects To Reset contained a null element. Update the reference or delete the array element of the missing object.", this);
                    m_OriginalPositions.Add(new Pose());
                }
            }
        }
 
        /// <summary>
        /// See <see cref="MonoBehaviour"/>.
        /// </summary>
        protected void Update()
        {
            m_CheckTimer -= Time.deltaTime;
 
            if (m_CheckTimer > 0)
                return;
 
            m_CheckTimer = m_CheckDuration;
 
            var resetPlane = transform.position.y;
 
            for (var transformIndex = 0; transformIndex < m_ObjectsToReset.Count; transformIndex++)
            {
                var currentTransform = m_ObjectsToReset[transformIndex];
                if (currentTransform == null)
                    continue;
 
                if (currentTransform.position.y < resetPlane)
                {
                    currentTransform.SetPositionAndRotation(m_OriginalPositions[transformIndex].position, m_OriginalPositions[transformIndex].rotation);
 
                    var rigidBody = currentTransform.GetComponentInChildren<Rigidbody>();
                    if (rigidBody != null)
                    {
                        rigidBody.velocity = Vector3.zero;
                        rigidBody.angularVelocity = Vector3.zero;
                    }
                }
            }
        }
    }
}