Exemple #1
0
 void Awake()
 {
     this.mTarget = this.GetComponent <InputTarget>();
     this.mTarget.onPress.Attach(touch => this.onPress.Invoke(touch));
     this.mTarget.onRelease.Attach(touch => this.onRelease.Invoke(touch));
     this.mTarget.onClick.Attach(touch => this.onClick.Invoke(touch));
     this.mTarget.onMove.Attach(touch => this.onMove.Invoke(touch));
 }
Exemple #2
0
        void Awake()
        {
            statistics = new DragStatistics(dragStatisticTime);

            inputTarget = this.GetComponent <InputTarget>();
            inputTarget.onPress.Attach(this.OnPress);
            InputDetection.instance.onReleaseAnyWhere.Attach(this.OnReleaseAnywhere);

            if (adjustedOffestOnScreen)
            {
                offsetOnScreen *= Screen.height / 768.0f;
            }
        }
Exemple #3
0
        public void UseAlternativeTarget(InputTarget alternativeTarget)
        {
            if (alternativeTarget == null)
            {
                return;
            }

            inputTarget.onPress.Detach(this.OnPress);

            inputTarget = alternativeTarget;
            inputTarget.GetComponent <Collider>().enabled = true;
            inputTarget.onPress.Attach(this.OnPress);
        }
        public bool Cast(Vector3 position, out Ray ray, out RaycastHit hitInfo, out InputTarget hitTarget, bool checkTarget = true, bool ignoreTrigger = false)
        {
            ray       = default(Ray);
            hitInfo   = default(RaycastHit);
            hitTarget = null;
            if (!this.camera)
            {
                return(false);
            }

            ray = this.camera.ScreenPointToRay(position);

            int maskToUse = this.mask != -1 ? this.mask : this.camera.cullingMask;

            if (checkTarget)
            {
                RaycastHit[] hits = Physics.RaycastAll(ray, float.MaxValue, maskToUse);
                System.Array.Sort(hits, (h1, h2) => h1.distance.CompareTo(h2.distance));
                for (int j = 0; j < hits.Length; j++)
                {
                    RaycastHit h = hits[j];
                    if (ignoreTrigger && h.collider.isTrigger)
                    {
                        continue;
                    }
                    InputTarget target = h.collider.GetComponentInParent <InputTarget>();
                    if (target == null || !target.enabled)
                    {
                        continue;
                    }
                    hitInfo   = h;
                    hitTarget = target;
                    Debug.DrawLine(this.transform.position, h.point, Color.green, 0.5f);
                    return(true);
                }
            }
            else
            {
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, maskToUse))
                {
                    InputTarget target = hit.collider.GetComponentInParent <InputTarget>();
                    hitInfo   = hit;
                    hitTarget = target != null && target.enabled ? target : null;
                    Debug.DrawLine(this.transform.position, hit.point, Color.red, 0.5f);
                    return(true);
                }
            }

            return(false);
        }
Exemple #5
0
        private bool Raycast(Vector3 position, out Ray ray, out RaycastHit hitInfo, out InputCaster hitCaster, out InputTarget hitTarget)
        {
            ray       = default(Ray);
            hitInfo   = default(RaycastHit);
            hitCaster = null;
            hitTarget = null;

            for (int i = 0; i < casters.Count; i++)
            {
                var caster = casters[i];
                if (!caster.enabled)
                {
                    continue;
                }

                hitCaster = caster;

                if (caster.Cast(position,
                                out ray,
                                out hitInfo,
                                out hitTarget,
                                this.checkTarget, this.ignoreTrigger))
                {
                    return(true);
                }
            }

            return(false);
        }