private void HandleTouchpad(IDualShock4Extension ds4) { for (int index = this.touches.Count - 1; index >= 0; --index) { DualShock4SpecialFeaturesExample.Touch touch = this.touches[index]; if (!ds4.IsTouchingByTouchId(touch.touchId)) { touch.go.SetActive(false); this.unusedTouches.Enqueue(touch); this.touches.RemoveAt(index); } } for (int index = 0; index < ds4.get_maxTouches(); ++index) { if (ds4.IsTouching(index)) { int touchId = ds4.GetTouchId(index); DualShock4SpecialFeaturesExample.Touch touch = this.touches.Find((Predicate <DualShock4SpecialFeaturesExample.Touch>)(x => x.touchId == touchId)); if (touch == null) { touch = this.unusedTouches.Dequeue(); this.touches.Add(touch); } touch.touchId = touchId; touch.go.SetActive(true); Vector2 vector2; ds4.GetTouchPosition(index, ref vector2); touch.go.get_transform().set_localPosition(new Vector3((float)(vector2.x - 0.5), (float)(0.5 + touch.go.get_transform().get_localScale().y * 0.5), (float)(vector2.y - 0.5))); } } }
private void InitializeTouchObjects() { this.touches = new List <DualShock4SpecialFeaturesExample.Touch>(2); this.unusedTouches = new Queue <DualShock4SpecialFeaturesExample.Touch>(2); for (int index = 0; index < 2; ++index) { DualShock4SpecialFeaturesExample.Touch touch = new DualShock4SpecialFeaturesExample.Touch(); touch.go = GameObject.CreatePrimitive((PrimitiveType)0); touch.go.get_transform().set_localScale(new Vector3(0.1f, 0.1f, 0.1f)); touch.go.get_transform().SetParent(this.touchpadTransform, true); ((Renderer)touch.go.GetComponent <MeshRenderer>()).get_material().set_color(index != 0 ? Color.get_green() : Color.get_red()); touch.go.SetActive(false); this.unusedTouches.Enqueue(touch); } }