열차 목업의 내부 확인용 프로젝트
smchoi
2024-07-23 891576775c982322c685f6bedae3460ed1116011
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;
using UnityEngine;
using UnityEngine.EventSystems;
 
namespace UnityStandardAssets.CrossPlatformInput
{
    public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    {
        // designed to work in a pair with another axis touch button
        // (typically with one having -1 and one having 1 axisValues)
        public string axisName = "Horizontal"; // The name of the axis
        public float axisValue = 1; // The axis that the value has
        public float responseSpeed = 3; // The speed at which the axis touch button responds
        public float returnToCentreSpeed = 3; // The speed at which the button will return to its centre
 
        AxisTouchButton m_PairedWith; // Which button this one is paired with
        CrossPlatformInputManager.VirtualAxis m_Axis; // A reference to the virtual axis as it is in the cross platform input
 
        void OnEnable()
        {
            if (!CrossPlatformInputManager.AxisExists(axisName))
            {
                // if the axis doesnt exist create a new one in cross platform input
                m_Axis = new CrossPlatformInputManager.VirtualAxis(axisName);
                CrossPlatformInputManager.RegisterVirtualAxis(m_Axis);
            }
            else
            {
                m_Axis = CrossPlatformInputManager.VirtualAxisReference(axisName);
            }
            FindPairedButton();
        }
 
        void FindPairedButton()
        {
            // find the other button witch which this button should be paired
            // (it should have the same axisName)
            var otherAxisButtons = FindObjectsOfType(typeof(AxisTouchButton)) as AxisTouchButton[];
 
            if (otherAxisButtons != null)
            {
                for (int i = 0; i < otherAxisButtons.Length; i++)
                {
                    if (otherAxisButtons[i].axisName == axisName && otherAxisButtons[i] != this)
                    {
                        m_PairedWith = otherAxisButtons[i];
                    }
                }
            }
        }
 
        void OnDisable()
        {
            // The object is disabled so remove it from the cross platform input system
            m_Axis.Remove();
        }
 
 
        public void OnPointerDown(PointerEventData data)
        {
            if (m_PairedWith == null)
            {
                FindPairedButton();
            }
            // update the axis and record that the button has been pressed this frame
            m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, axisValue, responseSpeed * Time.deltaTime));
        }
 
 
        public void OnPointerUp(PointerEventData data)
        {
            m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, 0, responseSpeed * Time.deltaTime));
        }
    }
}