123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
- public class HandEvent : MonoBehaviour
- {
- private List<GameObject> dynamicEvents;
- private List<GameObject> staticEvents;
- public Material outlineL;
- public Material outlineR;
- public Material outlineRB;
- public Material outlineRL;
- public Material outlineRR;
- // Start is called before the first frame update
- void Start()
- {
- InputDeviceHandPartEventBase.eventDelegate += HandEventDelegate;
- dynamicEvents = GameObject.Find("DynamicEvent").GetAllChildren();
- staticEvents = GameObject.Find("StaticEvent").GetAllChildren();
- }
- // Update is called once per frame
- void Update()
- {
- }
- void OnDestroy()
- {
- InputDeviceHandPartEventBase.eventDelegate -= HandEventDelegate;
- }
- void HandEventDelegate(InputDeviceHandPart inputDeviceHandPart, HandEventType eventType, float EventPercent)
- {
- if (inputDeviceHandPart.PartType == SC.XR.Unity.Module_InputSystem.InputDevicePartType.HandLeft)
- {
- if (eventType == HandEventType.Static_Fist)
- {
- staticEvents[0].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 0);
- }
- else if (eventType == HandEventType.Static_Point)
- {
- staticEvents[1].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 1);
- }
- else if (eventType == HandEventType.Static_Peace)
- {
- staticEvents[2].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 2);
- }
- else if (eventType == HandEventType.Static_Three)
- {
- staticEvents[3].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 3);
- }
- else if (eventType == HandEventType.Static_Four)
- {
- staticEvents[4].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 4);
- }
- else if (eventType == HandEventType.Static_Five)
- {
- staticEvents[5].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 5);
- }
- else if (eventType == HandEventType.Static_Phone)
- {
- staticEvents[6].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 6);
- }
- else if (eventType == HandEventType.Static_Damn)
- {
- staticEvents[7].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 7);
- }
- else if (eventType == HandEventType.Static_Gun)
- {
- staticEvents[8].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 8);
- }
- else if (eventType == HandEventType.Static_Like)
- {
- staticEvents[9].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 9);
- }
- else if (eventType == HandEventType.Static_No_Like)
- {
- staticEvents[10].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 10);
- }
- else if (eventType == HandEventType.Static_OK)
- {
- staticEvents[11].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 11);
- }
- else if (eventType == HandEventType.Static_RockAndRoll)
- {
- staticEvents[12].GetComponent<Image>().material = outlineL;
- StartCoroutine("SetToOrigin", 12);
- }
- else if (eventType == HandEventType.Dynamic_Click_Down ||
- eventType == HandEventType.Dynamic_Click_Hold)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
- }
- }
- else if (eventType == HandEventType.Dynamic_Click)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
- }
- StartCoroutine("SetAboutClick", 0);
- }
- else if (eventType == HandEventType.Dynamic_Click_Up)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- }
- else if (eventType == HandEventType.Dynamic_Open)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- dynamicEvents[1].GetComponent<RawImage>().material = outlineRL;
- StartCoroutine("SetToOrigin", 21);
- }
- else if (eventType == HandEventType.Dynamic_Flip)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- dynamicEvents[2].GetComponent<RawImage>().material = outlineRL;
- StartCoroutine("SetToOrigin", 22);
- }
- else if (eventType == HandEventType.Null)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- }
- }
- else if (inputDeviceHandPart.PartType == SC.XR.Unity.Module_InputSystem.InputDevicePartType.HandRight)
- {
- if (eventType == HandEventType.Static_Fist)
- {
- staticEvents[0].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 0);
- }
- else if (eventType == HandEventType.Static_Point)
- {
- staticEvents[1].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 1);
- }
- else if (eventType == HandEventType.Static_Peace)
- {
- staticEvents[2].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 2);
- }
- else if (eventType == HandEventType.Static_Three)
- {
- staticEvents[3].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 3);
- }
- else if (eventType == HandEventType.Static_Four)
- {
- staticEvents[4].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 4);
- }
- else if (eventType == HandEventType.Static_Five)
- {
- staticEvents[5].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 5);
- }
- else if (eventType == HandEventType.Static_Phone)
- {
- staticEvents[6].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 6);
- }
- else if (eventType == HandEventType.Static_Damn)
- {
- staticEvents[7].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 7);
- }
- else if (eventType == HandEventType.Static_Gun)
- {
- staticEvents[8].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 8);
- }
- else if (eventType == HandEventType.Static_Like)
- {
- staticEvents[9].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 9);
- }
- else if (eventType == HandEventType.Static_No_Like)
- {
- staticEvents[10].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 10);
- }
- else if (eventType == HandEventType.Static_OK)
- {
- staticEvents[11].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 11);
- }
- else if (eventType == HandEventType.Static_RockAndRoll)
- {
- staticEvents[12].GetComponent<Image>().material = outlineR;
- StartCoroutine("SetToOrigin", 12);
- }
- else if (eventType == HandEventType.Dynamic_Click_Down ||
- eventType == HandEventType.Dynamic_Click_Hold)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
- }
- }
- else if (eventType == HandEventType.Dynamic_Click)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
- }
- StartCoroutine("SetAboutClick", 1);
- }
- else if (eventType == HandEventType.Dynamic_Click_Up)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- }
- else if (eventType == HandEventType.Dynamic_Open)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- dynamicEvents[1].GetComponent<RawImage>().material = outlineRR;
- StartCoroutine("SetToOrigin", 21);
- }
- else if (eventType == HandEventType.Dynamic_Flip)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
- dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
- }
- else
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- dynamicEvents[2].GetComponent<RawImage>().material = outlineRR;
- StartCoroutine("SetToOrigin", 22);
- }
- else if (eventType == HandEventType.Null)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- }
- }
- }
- private IEnumerator SetToOrigin(int keynumber)
- {
- yield return new WaitForSeconds(1);
- if (keynumber < 20)
- {
- staticEvents[keynumber].GetComponent<Image>().material = null;
- }
- else
- {
- keynumber -= 20;
- dynamicEvents[keynumber].GetComponent<RawImage>().material = null;
- }
- }
- private IEnumerator SetAboutClick(int lr)
- {
- yield return new WaitForSeconds(1);
- if (lr == 0)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- else if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
- }
- }
- else if (lr == 1)
- {
- if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = null;
- }
- else if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
- {
- dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
- }
- }
- }
- }
|