void Awake() { touchable = gameObject.GetComponent <Touchable>(); boxcollider = gameObject.GetComponent <BoxCollider>(); rigidbody = gameObject.GetComponent <Rigidbody>(); default_storage_scale = storage.transform.localScale.x; //could grab any dimension storage_ghost = storage.GetComponent <Ghost>(); storage_touchable = storage.GetComponent <Touchable>(); storage_available = storage_ghost.available; storage_available_meshrenderer = storage_available.GetComponent <MeshRenderer>(); storage_snap = storage_ghost.snap; storage_snap_meshrenderer = storage_snap.GetComponent <MeshRenderer>(); active_ghost = active.GetComponent <Ghost>(); active_touchable = active.GetComponent <Touchable>(); active_available = active_ghost.available; active_available_meshrenderer = active_available.GetComponent <MeshRenderer>(); active_snap = active_ghost.snap; active_snap_meshrenderer = active_snap.GetComponent <MeshRenderer>(); dial_dial = dial.GetComponent <Dial>(); dial_touchable = dial.GetComponent <Touchable>(); textv_tmpro = textv.GetComponent <TextMeshPro>(); textv_meshrenderer = textv.GetComponent <MeshRenderer>(); textl_tmpro = textl.GetComponent <TextMeshPro>(); textl_meshrenderer = textl.GetComponent <MeshRenderer>(); text_fadable = GetComponent <Fadable>(); disabled = false; }
void onButton (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { float rawPos = Mathf.Clamp ((_eventData.position.x - (Screen.width / 2f)) - (filler.anchoredPosition.x + component.anchoredPosition.x), 0f, 400f); filler.sizeDelta = new Vector2(rawPos, 15f); currentValue = Mathf.Clamp01(rawPos / 400f); updateText (); }
void OnButtonLevel (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { buttonLevel.Interactable = false; buttonOptions.Interactable = false; buttonCredits.Interactable = false; StartCoroutine("StartLevel"); }
void OnButtonQuit (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { #if UNITY_EDITOR EditorApplication.ExecuteMenuItem("Edit/Play"); #else Application.Quit(); #endif }
private void touchDown(RaycastHit2D hit, int index) { Touchable touchedObject = hit.collider?.gameObject.GetComponent <Touchable>(); touchedObjects[index] = touchedObject; touchedObject?.Touched(hit.point); }
void Awake() { touchable = gameObject.GetComponent <Touchable>(); rigidbody = gameObject.GetComponent <Rigidbody>(); og_transform = gameObject.transform; og_localPosition = gameObject.transform.localPosition; og_localRotation = gameObject.transform.localRotation; }
public void ForceTouchToEnd() { if (!_touchedObject) { return; } _touchedObject.InvokeIfActive(_touchedObject.onTouchEnd); _touchedObject = null; }
private void OnCollisionEnter2D(Collision2D collision) { Touchable obj = collision.gameObject.GetComponent <Touchable>(); if (obj != null) { obj.OnTouchPlayer(this); } }
public void Delegate(Touchable from, Touchable to) { for (int i = 0; i < MaxTouchCount; i++) { if (touchedObjects[i] == from) { touchedObjects[i] = to; return; } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.forward); touchDown(hit, 0); } else if (Input.GetMouseButtonUp(0)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); touchUp(hit.point, 0); } else if (Input.GetMouseButton(0)) { touchMove(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0); } if (Input.GetMouseButtonDown(1)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); specialTouchObject = hit.collider?.gameObject.GetComponent <Touchable>(); specialTouchObject?.SpecialTouched(hit.point); } else if (Input.GetMouseButtonUp(1)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); specialTouchObject?.SpecialReleased(hit.point); specialTouchObject = null; } for (int index = 0; index < Input.touchCount; index++) { Touch touch = Input.GetTouch(index); RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(touch.position), Vector2.zero); switch (touch.phase) { case TouchPhase.Began: touchDown(hit, index); break; case TouchPhase.Moved: touchMove(hit.point, index); break; default: touchUp(hit.point, index); break; } } }
void OnTriggerExit2D(Collider2D other) { // Check for a touchable Touchable touchable = other.GetComponent <Touchable>(); if (!touchable) { return; } touchable.OnHoverExit(); }
void Awake() { _touchable = GetComponent <Touchable>(); _touchable.SetOnSwipe((args) => { //inspect swipe args fields for more information, you can always ask Barkin Debug.Log($"On swipe {args.lastPosition}"); foreach (Transform child in transform) { child.transform.position += new Vector3(args.delta.x, args.delta.y, 0); } }); }
private Touchable GetGameObject() { if (clicked == null) { RaycastHit2D hit = Physics2D.Raycast(touch.position, Vector2.zero, 0f); if (hit) { Debug.Log("touched[" + touch.fingerId + "]: " + hit.transform.name); clicked = hit.transform.gameObject.GetComponent <Touchable>(); } } return(clicked); }
void Start() { touchPrevious = GameObject.Find("Previous").GetComponent<Touchable>(); touchNext = GameObject.Find("Next").GetComponent<Touchable>(); etapes = new GameObject[3]; etapes[0] = GameObject.Find("Etape1"); etapes[1] = GameObject.Find("Etape2"); etapes[2] = GameObject.Find("Etape3"); etapes[0].SetActive(true); etapes[1].SetActive(false); etapes[2].SetActive(false); }
void Awake() { _touchable = GetComponent <Touchable>(); _touchable.SetOnTouchDown((args) => { Debug.Log($"Button touch down {args.position}"); //return true to block other touch events return(false); }); _touchable.SetOnTouchUp((args) => { Debug.Log($"Button touch up {args.position}"); }); }
// Update is called once per frame void Update() { if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Began)) { //Debug.Log("Touch detected!"); RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero); //Debug.Log("can touch? " + touchEnabled); if (touchEnabled && hit.collider && hit.collider.CompareTag("Touchable")) { Debug.Log("Hit it! " + hit.collider.gameObject.name); Touchable touched = hit.collider.GetComponent <Touchable>(); touched.OnTouch(); } } }
public void OnControllerColliderHit(ControllerColliderHit _hit) { Rigidbody _otherBody = _hit.collider.attachedRigidbody; if (_otherBody == null || _otherBody.isKinematic) { return; } if (_hit.moveDirection.y < -0.3F) { return; } Vector3 pushDir = new Vector3(_hit.moveDirection.x, 0, _hit.moveDirection.z); _otherBody.velocity = pushDir * currentWalkSpeed * pushingSpeedReduction; //Color Issue // Debug.Log(localCharacter.velocity.magnitude); Touchable _mov = _otherBody.GetComponent <Touchable>(); int _id = 0; if (_mov != null) { if (_mov.localIC != null) { _id = _mov.localIC.localID; } } _mov.normalizeTimer = 1.0F; Debug.Log(_id); if (localCharacter.velocity.magnitude > 0.4F) { _mov.target_Color = Helper.instance.Interaction_Colors[_id].color_States[2]; _mov.fade_Time = 5.0F; } else { _mov.target_Color = Helper.instance.Interaction_Colors[_id].color_States[0]; _mov.fade_Time = 0.8F; } }
private void Update() { if (!IsTouching()) { return; } #if UNITY_EDITOR _touchPos = shouldUseMouse ? GetScreenToWorld(Input.mousePosition) : GetScreenToWorld(Input.GetTouch(0).position); #else _touchPos = GetScreenToWorld(Input.GetTouch(0).position); #endif if (TouchStarted()) { RaycastHit2D hit = Physics2D.CircleCast(_touchPos, 1f, Vector2.zero, 1, 1 << 8, -10, 10); if (!hit) { _touchedObject = null; return; } _touchedObject = hit.rigidbody.gameObject.GetComponent <Touchable>(); _touchedObject.InvokeIfActive(_touchedObject.onTouchStart); Debug.Log("Touched object: " + _touchedObject); } else if (TouchEnded() && _touchedObject != null) { _touchedObject.InvokeIfActive(_touchedObject.onTouchEnd); _touchedObject = null; } else if (_touchedObject) { Vector3 delta = _touchPos - _touchedObject.Position;; if (delta.magnitude > minDragDistance) { _touchedObject.InvokeIfActive(_touchedObject.onDragged); } else { _touchedObject.InvokeIfActive(_touchedObject.onHeld); } } }
// Update is called once per frame void Update() { if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Began) || Input.GetMouseButtonDown(0)) { Vector2 pos = Input.touchCount > 0 ? Input.GetTouch(0).position : new Vector2(Input.mousePosition.x, Input.mousePosition.y); Ray raycast = Camera.main.ScreenPointToRay(pos); RaycastHit raycastHit; if (Physics.Raycast(raycast, out raycastHit)) { Debug.Log("Something Hit"); Touchable touchableVideo = raycastHit.collider.GetComponent <Touchable> (); if (touchableVideo != null) { touchableVideo.Touch(); } } } }
// Update is called once per frame void Update() { timer += Time.deltaTime; if (Input.touchCount > 0) { //store touches Touch[] touches = Input.touches; t1 = touches[0]; Touch myTouch = Input.GetTouch(0); //for (int i = 0; i < Input.touchCount; i++){} startPos = t1.position; r = Camera.main.ScreenPointToRay(t1.position); Debug.DrawRay(r.origin, 100 * r.direction); bool hasHitItem = (Physics.Raycast(r, out rayCastHitInfo)); Touchable possibleItem; if (hasHitItem) { possibleItem = rayCastHitInfo.collider.gameObject.GetComponent <Touchable>(); } else { possibleItem = null; } if (t1.phase == TouchPhase.Began) { #region Tap timer = 0; moved = false; #endregion #region Drag distanceToSelectedObject = Vector3.Distance(possibleItem.transform.position, Camera.main.transform.position); #endregion #region Scale if (Input.touchCount == 2 && currentlySelectedObject) { t1 = touches[0]; t2 = touches[1]; startingDis = Vector3.Distance(t1.position, t2.position); objectIntialSize = currentlySelectedObject.transform.localScale; } #endregion #region Rotate #endregion #region Camera Pinch to Zoom //Reference for Pinch to Zoom: https://www.youtube.com/watch?v=ae6CyngEG-U&ab_channel=Holistic3d //There is a Seperate Script on the Main Camera for this called "PinchToZoom" that works. if (Input.touchCount == 2 && !currentlySelectedObject) { //Calibrate Distance previousDistance = Vector2.Distance(t1.position, t2.position); } #endregion } if (t1.phase == TouchPhase.Moved) { moved = true; #region Drag if (possibleItem != currentlySelectedObject) { currentlySelectedObject.DeSelect(); currentlySelectedObject = possibleItem; currentlySelectedObject.Select(); } currentlySelectedObject.transform.position = r.origin + distanceToSelectedObject * r.direction; #endregion #region Scale if (Input.touchCount == 2 && currentlySelectedObject) { t1 = touches[0]; t2 = touches[1]; float currentDis = Vector3.Distance(t1.position, t2.position); currentlySelectedObject.transform.localScale = objectIntialSize * currentDis / startingDis; } #endregion #region Rotate if (Input.touchCount == 1 && currentlySelectedObject) { t1 = touches[0]; //distAngle = thetaNew - thetaStart; //float distAngle; //float startingRotation = currentlySelectedObject.transform.rotation.eulerAngles.x; //currentlySelectedObject.transform.rotation = startingRotation * Quaternion.RotateTowards(Camera.forward,distAngle); } #endregion #region Camera Pinch to Zoom //Reference for Pinch to Zoom: https://www.youtube.com/watch?v=ae6CyngEG-U&ab_channel=Holistic3d //There is a Seperate Script on the Main Camera for this called "PinchToZoom" that works. if (Input.touchCount == 2 && !currentlySelectedObject) { t1 = touches[0]; t2 = touches[1]; float distance = Vector3.Distance(t1.position, t2.position); //Camera based on Pinch/Zoom float pinchAmount = (previousDistance - distance) * zoomSpeed * Time.deltaTime; Camera.main.transform.Translate(0, 0, pinchAmount); previousDistance = distance; } #endregion } if ((t1.phase == TouchPhase.Ended) && !moved && wasShort()) { #region Currently Selected Object if (currentlySelectedObject) { currentlySelectedObject.DeSelect(); currentlySelectedObject = null; } if (Physics.Raycast(r, out rayCastHitInfo)) { currentlySelectedObject = rayCastHitInfo.collider.gameObject.GetComponent <Touchable>(); if (currentlySelectedObject) { currentlySelectedObject.Select(); } } #endregion } } #region Accelerometer //Accelerometer Tutorial https://www.youtube.com/watch?v=XZWNXsjIvrE float speed = 0.1f; currentlySelectedObject.transform.Translate(Input.acceleration.x * speed, 0, -Input.acceleration.z * speed); #endregion }
void Start() { touchOnePlayer = GameObject.Find("1Player").GetComponent<Touchable>(); touchTwoPlayer = GameObject.Find("2Players").GetComponent<Touchable>(); touchPuzzle = GameObject.Find("Puzzle").GetComponent<Touchable>(); touchTutoriel = GameObject.Find("btnTutorial").GetComponent<Touchable>(); touchEasy = GameObject.Find("btnEasy").GetComponent<Touchable>(); touchNormal = GameObject.Find("btnNormal").GetComponent<Touchable>(); touchDifficult = GameObject.Find("btnDifficult").GetComponent<Touchable>(); sprite1j = GameObject.Find("1j").GetComponent<SpriteRenderer>(); sprite2j = GameObject.Find("2j").GetComponent<SpriteRenderer>(); spritePuzzle = GameObject.Find("puzzle").GetComponent<SpriteRenderer>(); spriteTutoriel = GameObject.Find("tutoral").GetComponent<SpriteRenderer>(); spriteTruck1 = GameObject.Find("truck1").GetComponent<SpriteRenderer>(); spriteTruck2 = GameObject.Find("truck2").GetComponent<SpriteRenderer>(); spriteEasy = GameObject.Find("facile").GetComponent<SpriteRenderer>(); spriteNormal = GameObject.Find("moyen").GetComponent<SpriteRenderer>(); spriteDifficult = GameObject.Find("difficile").GetComponent<SpriteRenderer>(); initialPosTruck1 = spriteTruck1.transform.position; initialPosTruck2 = spriteTruck2.transform.position; CreateLerps(); CreateStateMachine(); }
void OnGraphicsButton (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { MenuCamera.instance.prepare ("options", "graphics"); ScreenManager.Instance.SetScreen("ScreenGraphics"); }
void OnButtonOptions (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { door_options.SetBool("Open", true); MenuCamera.instance.prepare("Menu", "Options"); ScreenManager.Instance.SetScreen("ScreenOptions"); }
/* * This function seems to handle all possible interactions between the hand and other objects. * Honestly, I haven't quite got a full understanding of this ~200-line behemoth. */ //"left_hand": true -> left, false -> right void TryHand(bool left_hand, float htrigger_val, float itrigger_val, float x_val, float y_val, Vector3 hand_vel, ref bool ref_htrigger, ref bool ref_itrigger, ref int ref_htrigger_delta, ref int ref_itrigger_delta, ref float ref_x, ref float ref_y, ref GameObject ref_hand, ref GameObject ref_grabbed, ref GameObject ref_ohand, ref GameObject ref_ograbbed) { float htrigger_threshhold = 0.1f; float itrigger_threshhold = 0.1f; //find deltas ref_htrigger_delta = 0; if (!ref_htrigger && htrigger_val > htrigger_threshhold) { ref_htrigger_delta = 1; ref_htrigger = true; } else if (ref_htrigger && htrigger_val <= htrigger_threshhold) { ref_htrigger_delta = -1; ref_htrigger = false; } ref_itrigger_delta = 0; if (!ref_itrigger && itrigger_val > itrigger_threshhold) { ref_itrigger_delta = 1; ref_itrigger = true; ref_x = x_val; ref_y = y_val; } else if (ref_itrigger && itrigger_val <= itrigger_threshhold) { ref_itrigger_delta = -1; ref_itrigger = false; } //find new grabs if (ref_grabbed == null && ref_htrigger_delta == 1) { //first try movables for (int i = 0; ref_grabbed == null && i < movables.Count; i++) { if ( //object newly grabbed (left_hand && movables[i].ltouch) || (!left_hand && movables[i].rtouch) ) { ref_grabbed = movables[i].gameObject; ref_grabbed.transform.SetParent(ref_hand.transform); if (ref_grabbed == ref_ograbbed) { ref_ograbbed = null; } movables[i].grabbed = true; Tool t = ref_grabbed.GetComponent <Tool>(); if (t) //newly grabbed object is a tool { t.engaged = false; t.stored = false; ref_grabbed.transform.localScale = new Vector3(1f, 1f, 1f); t.text.transform.localScale = new Vector3(1f, 1f, 1f); t.rigidbody.isKinematic = true; t.boxcollider.isTrigger = false; UpdateApplyTool(t); } VisAid v = ref_grabbed.GetComponent <VisAid>(); if (v) //newly grabbed object is a visaid { v.stored = false; v.rigidbody.isKinematic = true; } } } //then dials if (ref_grabbed == null) { for (int i = 0; i < tools.Count; i++) { if ( //dial newly grabbed (left_hand && tools[i].dial_touchable.ltouch) || (!left_hand && tools[i].dial_touchable.rtouch) ) { ref_grabbed = tools[i].dial; tools[i].dial_touchable.grabbed = true; if (ref_grabbed == ref_ograbbed) { ref_ograbbed = null; } } } } //then extraaneous if (ref_grabbed == null) //still not holding anything { Touchable g = handle_workspace_touchable; if ( //handle newly grabbed (left_hand && g.ltouch) || (!left_hand && g.rtouch) ) { ref_grabbed = handle_workspace; g.grabbed = true; if (ref_grabbed == ref_ograbbed) { ref_ograbbed = null; } } } if (ref_grabbed == null) //still not holding anything { Touchable g = halfer_touchable; if ( //halfing button newly grabbed (left_hand && g.ltouch) || (!left_hand && g.rtouch) ) { ref_grabbed = halfer; g.touch = true; if (ref_grabbed == ref_ograbbed) { ref_ograbbed = null; } SetAllHalfed(!halfed); } } if (ref_grabbed == null) //still not holding anything { Touchable g = reset_touchable; if ( //reset button newly grabbed (left_hand && g.ltouch) || (!left_hand && g.rtouch) ) { ref_grabbed = reset; g.touch = true; if (ref_grabbed == ref_ograbbed) { ref_ograbbed = null; } thermo.Reset(); } } if (ref_grabbed != null) //something newly grabbed { Halfable h = ref_grabbed.GetComponent <Halfable>(); if (h != null) { h.setHalf(false); //nothing should be halfed while being grabbed } } } //find new releases else if (ref_grabbed && ref_htrigger_delta == -1) //something newly released { Tool t = ref_grabbed.GetComponent <Tool>(); if (t) //tool newly released { if (t.active_ghost.tintersect) //tool released making it active { ActivateTool(t); } else if (t.storage_ghost.tintersect) //tool released making it stored { StoreTool(t); } else //tool released nowhere special { DetachTool(t, hand_vel); } } else //newly released object is NOT a tool { ref_grabbed.transform.SetParent(ref_grabbed.GetComponent <Touchable>().og_parent); //ok to do, even with a dial VisAid v = ref_grabbed.GetComponent <VisAid>(); if (v) //visaid newly released { v.rigidbody.isKinematic = false; v.rigidbody.velocity = hand_vel; } } ref_grabbed.GetComponent <Touchable>().grabbed = false; ref_grabbed = null; } if (ref_grabbed) { TryInteractable(ref_grabbed, x_val, y_val, ref ref_x, ref ref_y); } ref_x = x_val; ref_y = y_val; //centerer if (vrcenter_fingertoggleable.finger) //finger hitting vrcenter object { if ( //we're currently checking the correct hand (left_hand && vrcenter_fingertoggleable.lfinger) || (!left_hand && vrcenter_fingertoggleable.rfinger) ) { //reset center position vrcenter_backing_meshrenderer.material = tab_hisel; UnityEngine.XR.InputTracking.Recenter(); OVRManager.display.RecenterPose(); Vector3 pos = cam_offset.transform.localPosition - (cam_offset.transform.localPosition + ceye.transform.localPosition); pos.y = 0f; cam_offset.transform.localPosition = pos; } else { vrcenter_backing_meshrenderer.material = tab_hi; } } else { vrcenter_backing_meshrenderer.material = tab_default; } }
// Start is called before the first frame update void Start() { // All this code does, at end of day, is find all the objects to manage, // and set initial values and such as needed. thermo = GameObject.Find("Oracle").GetComponent <ThermoState>(); cam_offset = GameObject.Find("CamOffset"); ceye = GameObject.Find("CenterEyeAnchor"); hand_emptys = new Material[] { hand_empty }; hand_touchings = new Material[] { hand_touching }; hand_grabbings = new Material[] { hand_grabbing }; lhand = GameObject.Find("LeftControllerAnchor"); lactualhand = lhand.transform.GetChild(0).gameObject; lhand_pos = lhand.transform.position; lhand_vel = new Vector3(0f, 0f, 0f); lhand_meshrenderer = GameObject.Find("hands:Lhand").GetComponent <SkinnedMeshRenderer>(); rhand = GameObject.Find("RightControllerAnchor"); ractualhand = rhand.transform.GetChild(0).gameObject; rhand_pos = rhand.transform.position; rhand_vel = new Vector3(0f, 0f, 0f); rhand_meshrenderer = GameObject.Find("hands:Rhand").GetComponent <SkinnedMeshRenderer>(); lhand_meshrenderer.materials = hand_emptys; rhand_meshrenderer.materials = hand_emptys; // As we grab them, set ranges on tool dials (sliders). Tool t; tools = new List <Tool>(); t = GameObject.Find("Tool_Insulator").GetComponent <Tool>(); tool_insulator = t; tools.Add(t); t.dial_dial.min_map = 0f; t.dial_dial.max_map = 1f; t.dial_dial.unit = "n"; t = GameObject.Find("Tool_Clamp").GetComponent <Tool>(); tool_clamp = t; tools.Add(t); t.dial_dial.min_map = 0f; t.dial_dial.max_map = 1f; t.dial_dial.unit = "h"; t = GameObject.Find("Tool_Burner").GetComponent <Tool>(); tool_burner = t; tools.Add(t); t.dial_dial.min_map = 1f; t.dial_dial.max_map = 1000f * 100f; t.dial_dial.unit = "J/s"; t = GameObject.Find("Tool_Coil").GetComponent <Tool>(); tool_coil = t; tools.Add(t); t.dial_dial.min_map = -1f; t.dial_dial.max_map = -1000f * 100f; t.dial_dial.unit = "J/s"; double kg_corresponding_to_10mpa = thermo.surfacearea_insqr * (10 * 1453.8 /*MPa->psi*/) * 0.453592 /*lb->kg*/; double kg_corresponding_to_2mpa = thermo.surfacearea_insqr * (2 * 1453.8 /*MPa->psi*/) * 0.453592 /*lb->kg*/; // 10 MPa seems way too big, sooooo... we'll just do 2 MPa. t = GameObject.Find("Tool_Weight").GetComponent <Tool>(); tool_weight = t; tools.Add(t); t.dial_dial.min_map = 0f; t.dial_dial.max_map = (float)kg_corresponding_to_10mpa; t.dial_dial.unit = "kg"; t = GameObject.Find("Tool_Balloon").GetComponent <Tool>(); tool_balloon = t; tools.Add(t); t.dial_dial.min_map = 0f; t.dial_dial.max_map = -(float)kg_corresponding_to_10mpa; t.dial_dial.unit = "kg"; flame = GameObject.Find("Flame").GetComponent <ParticleSystem>(); workspace = GameObject.Find("Workspace"); handle_workspace = GameObject.Find("Handle_Workspace"); handle_workspace_touchable = handle_workspace.GetComponent <Touchable>(); // set initial states of meshrenderers and transforms for our tools. for (int i = 0; i < tools.Count; i++) { t = tools[i]; t.active_available_meshrenderer.enabled = false; t.active_snap_meshrenderer.enabled = false; t.storage_available_meshrenderer.enabled = false; t.storage_snap_meshrenderer.enabled = false; GameObject g = t.gameObject; g.transform.SetParent(t.storage.gameObject.transform); t.stored = true; g.transform.localPosition = new Vector3(0f, 0f, 0f); g.transform.localScale = new Vector3(1f, 1f, 1f); g.transform.localRotation = Quaternion.identity; float v = t.storage.transform.localScale.x; //can grab any dimension Vector3 invscale = new Vector3(1f / v, 1f / v, 1f / v); t.text.transform.localScale = invscale; t.textv_tmpro.SetText("{0:3}" + t.dial_dial.unit, (float)t.dial_dial.map); } vessel = GameObject.Find("Vessel"); graph = GameObject.Find("Graph"); state_dot = GameObject.Find("gstate"); challenge_dot = GameObject.Find("cstate"); clipboard = GameObject.Find("Clipboard"); challenge_ball_collide = challenge_dot.GetComponent <ChallengeBall>(); vrcenter = GameObject.Find("VRCenter"); vrcenter_fingertoggleable = vrcenter.GetComponent <FingerToggleable>(); vrcenter_backing_meshrenderer = vrcenter.transform.GetChild(1).GetComponent <MeshRenderer>(); movables = new List <Touchable>(); for (int i = 0; i < tools.Count; i++) { movables.Add(tools[i].touchable); //important that tools take priority, so they can be grabbed and removed } movables.Add(graph.GetComponent <Touchable>()); movables.Add(clipboard.GetComponent <Touchable>()); halfer = GameObject.Find("Halfer"); halfer_touchable = halfer.GetComponent <Touchable>(); reset = GameObject.Find("Reset"); reset_touchable = reset.GetComponent <Touchable>(); halfables = new List <Halfable>(); halfables.Add(GameObject.Find("Container").GetComponent <Halfable>()); halfables.Add(GameObject.Find("Tool_Insulator").GetComponent <Halfable>()); halfables.Add(GameObject.Find("Tool_Coil").GetComponent <Halfable>()); // A bunch of stuff related to initializing clipboard. instructions_parent = GameObject.Find("Instructions"); challenge_parent = GameObject.Find("Challenge"); quiz_parent = GameObject.Find("Quiz"); mode_tabs = new List <Tab>(); mode_tabs.Add(GameObject.Find("ModeInstructions").GetComponent <Tab>()); mode_tabs.Add(GameObject.Find("ModeChallenge").GetComponent <Tab>()); mode_tabs.Add(GameObject.Find("ModeQuiz").GetComponent <Tab>()); questions = new List <string>(); options = new List <string>(); answers = new List <int>(); //the correct answer givens = new List <int>(); //the recorded answer given by the user (default -1) questions.Add("Here is an example question- in what region is the water?"); options.Add("A. Solid"); options.Add("B. Liquid"); options.Add("C. Vapor"); options.Add("D. Two Phase"); answers.Add(2); givens.Add(-1); questions.Add("Here is an example question- in what region is the water?"); options.Add("A. Solid"); options.Add("B. Liquid"); options.Add("C. Vapor"); options.Add("D. Two Phase"); answers.Add(2); givens.Add(-1); questions.Add("Here is an example question- in what region is the water?"); options.Add("A. Solid"); options.Add("B. Liquid"); options.Add("C. Vapor"); options.Add("D. Two Phase"); answers.Add(2); givens.Add(-1); questions.Add("Here is an example question- in what region is the water?"); options.Add("A. Solid"); options.Add("B. Liquid"); options.Add("C. Vapor"); options.Add("D. Two Phase"); answers.Add(2); givens.Add(-1); questions.Add("Here is an example question- in what region is the water?"); options.Add("A. Solid"); options.Add("B. Liquid"); options.Add("C. Vapor"); options.Add("D. Two Phase"); answers.Add(2); givens.Add(-1); option_tabs = new List <Tab>(); option_tabs.Add(GameObject.Find("QA").GetComponent <Tab>()); option_tabs.Add(GameObject.Find("QB").GetComponent <Tab>()); option_tabs.Add(GameObject.Find("QC").GetComponent <Tab>()); option_tabs.Add(GameObject.Find("QD").GetComponent <Tab>()); qconfirm_tab = GameObject.Find("QConfirm").GetComponent <Tab>(); board = GameObject.Find("Board"); qtext_tmp = GameObject.Find("Qtext").GetComponent <TextMeshPro>(); SetQuizText(); SetChallengeBall(); SetAllHalfed(true); }
/* * Function to update object materials/appearance in response to a "grab" event. */ void UpdateGrabVis() { for (int i = 0; i < tools.Count; i++) { Tool t = tools[i]; GameObject g = t.gameObject; if (lgrabbed == g || rgrabbed == g) { //active if (t.active_ghost.tintersect) { t.active_available_meshrenderer.enabled = false; t.active_snap_meshrenderer.enabled = true; } else { t.active_available_meshrenderer.enabled = true; t.active_snap_meshrenderer.enabled = false; } //storage if (t.storage_ghost.tintersect) { t.storage_available_meshrenderer.enabled = false; t.storage_snap_meshrenderer.enabled = true; } else { t.storage_available_meshrenderer.enabled = true; t.storage_snap_meshrenderer.enabled = false; } } else { t.active_snap_meshrenderer.enabled = false; t.active_available_meshrenderer.enabled = false; t.storage_snap_meshrenderer.enabled = false; t.storage_available_meshrenderer.enabled = false; } } Touchable gr; bool ltouch = false; bool rtouch = false; for (int i = 0; i < movables.Count; i++) { gr = movables[i]; if (gr.ltouch) { ltouch = true; } if (gr.rtouch) { rtouch = true; } } for (int i = 0; i < tools.Count; i++) { gr = tools[i].dial_touchable; if (gr.ltouch) { ltouch = true; } if (gr.rtouch) { rtouch = true; } } gr = handle_workspace_touchable; if (gr.ltouch) { ltouch = true; } if (gr.rtouch) { rtouch = true; } Touchable press_gr = halfer_touchable; if (press_gr.ltouch) { ltouch = true; } if (press_gr.rtouch) { rtouch = true; } press_gr = reset_touchable; if (press_gr.ltouch) { ltouch = true; } if (press_gr.rtouch) { rtouch = true; } if (lgrabbed) { lhand_meshrenderer.materials = hand_grabbings; } else if (ltouch) { lhand_meshrenderer.materials = hand_touchings; } else { lhand_meshrenderer.materials = hand_emptys; } if (rgrabbed) { rhand_meshrenderer.materials = hand_grabbings; } else if (rtouch) { rhand_meshrenderer.materials = hand_touchings; } else { rhand_meshrenderer.materials = hand_emptys; } }
internal void AddTouchable(Touchable touchable) { this.ListTouchableRectangles.Add(touchable); }
/// <summary> /// Determines how touch events are distributed to this element. Default is {@link Touchable#enabled}. /// </summary> /// <param name="touchable">Touchable.</param> public void SetTouchable(Touchable touchable) => this.touchable = touchable;
/// <summary> /// Determines how touch events are distributed to this element. Default is {@link Touchable#enabled}. /// </summary> /// <param name="touchable">Touchable.</param> public void setTouchable( Touchable touchable ) { this.touchable = touchable; }
/// <summary> /// Determines how touch events are distributed to this element. Default is {@link Touchable#enabled}. /// </summary> /// <param name="touchable">Touchable.</param> public void setTouchable(Touchable touchable) { this.touchable = touchable; }
void OnEasterButton (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { door_easter.SetBool("Open", true); MenuCamera.instance.prepare("Credits", "Easter"); ScreenManager.Instance.SetScreen("ScreenEasteregg"); }
// Update is called once per frame private void Update() { Transform pointer = Pointer; if (pointer == null || _laserPointerRenderer == null) { return; } Ray pointerRay = new Ray(pointer.position, pointer.forward); _laserPointerRenderer.SetPosition(0, pointerRay.origin); RaycastHit hitInfo; // なにかに当たっているとき if (Physics.Raycast(pointerRay, out hitInfo, _maxDistance)) { _laserPointerRenderer.SetPosition(1, hitInfo.point); GameObject target = hitInfo.collider.gameObject; Touchable touchable = target.GetComponent <Touchable>(); Grabbable grabbable = target.GetComponent <Grabbable>(); // 何かを掴んでいるとき if (_isGrabbing) { if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger)) { _grabTarget.transform.SetParent(_parentOfGrabTarget); _parentOfGrabTarget = null; _grabTarget = null; _isGrabbing = false; } if (OVRInput.Get(OVRInput.Touch.PrimaryTouchpad)) { Vector3 direction = pointer.forward * OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad).y; if (_grabTarget != null) { _grabTarget.transform.Translate(direction * 0.1f, Space.World); } } } // 何も掴んでいないとき else { // Touchableに当たっているとき if (touchable != null) { _touchTarget = touchable.gameObject; touchable.TouchBegin(this); if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger)) { // if (_touchTarget.transform.parent != null) Debug.Log("self Debug.Log: TouchTrigger : " + _touchTarget.transform.parent.gameObject.name); touchable.TouchTrigger(this); } } else { ReleaseTouchTarget(); // Grabbableに当たっているとき if (grabbable != null) { // ボタンを押すとcontrollerに追従するようにする if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger)) { _grabTarget = target; _parentOfGrabTarget = _grabTarget.transform.parent; _grabTarget.transform.SetParent(pointer); _isGrabbing = true; } } } } } // どこにも当たっていないとき else { _laserPointerRenderer.SetPosition(1, pointerRay.origin + pointerRay.direction * _maxDistance); ReleaseTouchTarget(); } }
void Update() { if (!isInputEnabled) { return; } #region PC Debugging // Only for debugging on pc // Should be disabled by default as it will deny touch input if (testingOnComputer) { Ray ray; RaycastHit hit; if (Input.GetMouseButtonDown(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); timeStamp = Time.time; if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (hit.collider.gameObject.tag == "Touchable") { Touchable obj = hit.collider.gameObject.GetComponent <Touchable>(); obj.Interact(hit); } } } if (Input.GetMouseButton(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (hit.collider.gameObject.tag == "Holdable") { Holdable obj = hit.collider.gameObject.GetComponent <Holdable>(); obj.Interact(hit, timeStamp); } if (hit.collider.gameObject.tag == "Touchable") { Touchable obj = hit.collider.gameObject.GetComponent <Touchable>(); obj.Interact(hit); } } } if (Input.GetMouseButtonUp(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (hit.collider.gameObject.tag == "Holdable") { Holdable obj = hit.collider.gameObject.GetComponent <Holdable>(); obj.TouchEnded(); } } } } #endregion // Touch input else { int touchCount = Input.touchCount; if (touchCount == 0) { return; } else { // Loops through all touch inputs (1 per finger) for (int i = 0; i < touchCount; i++) { Touch touch = Input.GetTouch(i); Ray ray; RaycastHit hit; // A Unity Touch goes through several phases through its lifetime // TouchPhase.Began - On touch beginning // TouchPhase.Stationaty - Finger has not moved since last check // TouchPhase.Moved - Finger moved since last check // TouchPhase.Ended - On touch end switch (touch.phase) { // If the touch input started this frame case TouchPhase.Began: touchTimes.Add(Time.time); ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0)); if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (hit.collider.gameObject.tag == "Touchable") { Touchable obj = hit.collider.gameObject.GetComponent <Touchable>(); obj.Interact(hit); } } break; // If the touch input did not move since last frame case TouchPhase.Stationary: break; // If the touch input did move since last frame case TouchPhase.Moved: touchTimes[i] = Time.time; ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0)); if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (hit.collider.gameObject.tag == "Holdable") { // Check that the touch input is still hitting the same holdable object Holdable obj = hit.collider.gameObject.GetComponent <Holdable>(); if (obj != lastHoldable && lastHoldable != null) { lastHoldable.TouchEnded(); } } else if (lastHoldable != null) { lastHoldable.TouchEnded(); } } break; // If the touch input ended this frame case TouchPhase.Ended: ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0)); if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (hit.collider.gameObject.tag == "Holdable") { Holdable obj = hit.collider.gameObject.GetComponent <Holdable>(); obj.TouchEnded(); } } touchTimes.RemoveAt(i); break; } // This was added to check raycast between touch phases, whether the touch is moving or not. // This could possibly be removed and implemented into the Switch Case. if (touch.phase != TouchPhase.Ended) { bool done = false; ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0)); if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (hit.collider.gameObject.tag == "Holdable") { Holdable obj = hit.collider.gameObject.GetComponent <Holdable>(); done = obj.Interact(hit, touchTimes[i]); lastHoldable = obj; } } /*if (done) - This line created errors since an entry could end up triggering two removes, thus triggering an "Array Index is Out of Bounds" error. * { * touchTimes.RemoveAt(i); * }*/ } } } } }
void onEnter (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { top.color = new Color32(128, 128, 128, 255); bottom.color = new Color32(128, 128, 128, 255); text.color = new Color32(128, 128, 128, 255); }
void OnBackButton (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { door_credits.SetBool("Open", false); MenuCamera.instance.prepare("Credits", "Menu"); ScreenManager.Instance.SetScreen("ScreenMainMenu"); }
void onExit (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { top.color = new Color32(0, 0, 0, 0); bottom.color = new Color32(0, 0, 0, 0); text.color = new Color32(255, 255, 255, 255); }
void OnBackButton (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { MenuCamera.instance.prepare("Controls", "Options"); ScreenManager.Instance.SetScreen("ScreenOptions"); }
void OnBackButton (Touchable _sender, UnityEngine.EventSystems.PointerEventData _eventData) { ScreenManager.Instance.SetScreen("ScreenCredits"); }