//constructor public AndroidTiltPedalsAndSteeringWheel() { canvas = GameObject.Find("ControlCanvas"); if (canvas == null) { canvas = new GameObject(); canvas.AddComponent <Canvas>(); } AccelPad = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefabs/AccelSlide"), Vector3.zero, Quaternion.identity, canvas.transform); _accelPedal = AccelPad.transform.Find("Pedal"); GameObject.Destroy(AccelPad.GetComponentInChildren <InputSlidePedal>()); BrakePad = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefabs/BrakeSlide"), Vector3.zero, Quaternion.identity, canvas.transform); _brakePedal = BrakePad.transform.Find("Pedal"); GameObject.Destroy(BrakePad.GetComponentInChildren <InputSlidePedal>()); SteerPad = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefabs/SteeringWheelPad"), Vector3.zero, Quaternion.identity, canvas.transform); SteerPadController = SteerPad.GetComponent <SteeringWheelPadController>(); BrakePad.GetComponent <RectTransform>().anchoredPosition = new Vector2(Settings.Instance.BrakePos, 0); AccelPad.GetComponent <RectTransform>().anchoredPosition = new Vector2(Settings.Instance.AccelPos, 0); SteerPad.GetComponent <RectTransform>().anchoredPosition = new Vector2(Settings.Instance.SteeringPosX, Settings.Instance.SteeringPosY); _restAngle = -Mathf.Atan2(Input.acceleration.y, Input.acceleration.z) * Mathf.Rad2Deg; //Main.Instance.PopupMsg(_restAngle.ToString()); //125 degrees rest = 2.18rad //150 is full accel = 2.62rad = rest + 0.436 //100 is full brake = 1.75rad = rest - 0.436 //<100 is reverse }
//constructor public AndroidPressPedalsAndSteeringWheel() { canvas = GameObject.Find("ControlCanvas"); if (canvas == null) { canvas = new GameObject(); canvas.AddComponent <Canvas>(); } AccelPad = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefabs/AccelPress"), Vector3.zero, Quaternion.identity, canvas.transform); _accelPedal = AccelPad.transform.Find("Pedal"); AccelPadController = AccelPad.GetComponentInChildren <InputPressPedal>(); BrakePad = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefabs/BrakePress"), Vector3.zero, Quaternion.identity, canvas.transform); _brakePedal = BrakePad.transform.Find("Pedal"); BrakePadController = BrakePad.GetComponentInChildren <InputPressPedal>(); SteerPad = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefabs/SteeringWheelPad"), Vector3.zero, Quaternion.identity, canvas.transform); SteerPadController = SteerPad.GetComponent <SteeringWheelPadController>(); AccelPadController.SteeringColl = SteerPad.GetComponent <BoxCollider2D>(); BrakePadController.SteeringColl = SteerPad.GetComponent <BoxCollider2D>(); BrakePad.GetComponent <RectTransform>().anchoredPosition = new Vector2(Settings.Instance.BrakePos, 0); AccelPad.GetComponent <RectTransform>().anchoredPosition = new Vector2(Settings.Instance.AccelPos, 0); SteerPad.GetComponent <RectTransform>().anchoredPosition = new Vector2(Settings.Instance.SteeringPosX, Settings.Instance.SteeringPosY); BoxCollider2D BrakeColl = BrakePadController.GetComponent <BoxCollider2D>(); BoxCollider2D AccelColl = AccelPadController.GetComponent <BoxCollider2D>(); float MidPt = (Settings.Instance.BrakePos + Settings.Instance.AccelPos) / 2; if (Settings.Instance.BrakePos < Settings.Instance.AccelPos) { BrakeColl.size = new Vector2(MidPt + 400, BrakeColl.size.y); BrakeColl.offset = new Vector2((MidPt - 400) / 2 - Settings.Instance.BrakePos, 200); AccelColl.size = new Vector2((400 - MidPt), AccelColl.size.y); AccelColl.offset = new Vector2((400 + MidPt) / 2 - Settings.Instance.AccelPos, 200); } else { AccelColl.size = new Vector2(MidPt + 400, AccelColl.size.y); AccelColl.offset = new Vector2((MidPt - 400) / 2 - Settings.Instance.AccelPos, 200); BrakeColl.size = new Vector2((400 - MidPt), BrakeColl.size.y); BrakeColl.offset = new Vector2((400 + MidPt) / 2 - Settings.Instance.BrakePos, 200); } }