コード例 #1
0
    public TouchObject _GetTouch(int id)
    {
        #if UNITY_IPHONE || UNITY_ANDROID && !UNITY_EDITOR
        Touch touch = Input.GetTouch(id);

        if (id >= _bufferTouchObjes.Count)
        {
            Debug.LogError("EROOR too many touch count: " + id);
            return(null);
        }
        TouchObject touchObj = _bufferTouchObjes[id];
        // copy to TouchObject
        touchObj.deltaPosition = touch.deltaPosition;
        touchObj.deltaTime     = touch.deltaTime;
        touchObj.fingerId      = touch.fingerId;
        touchObj.phase         = touch.phase;
        touchObj.position      = touch.position;
        touchObj.tapCount      = touch.tapCount;

        return(touchObj);
        #else
        if (id >= _touchCount)
        {
            return(null);
        }
        return(_bufferTouchObjes[id]);
        #endif
    }
コード例 #2
0
    void Start() //Called when start
    {
        if (description == "")
        {
            description = "";
        }
        if (scriptInteract != null)
        {
            intObj = new InteractObject(scriptInteract);
        }

        if (scriptTouch != null)
        {
            touObj = new TouchObject(scriptTouch);
        }

        if (showName) //Create floatingLabel
        {
            canvas = GameObject.Find("PopupUI");
            var popupText = Resources.Load("Prefabs/PopUpObject");
            floatingLabel = (GameObject)Instantiate(popupText);
            floatingLabel.transform.SetParent(canvas.transform);
            floatingLabel.transform.GetComponent <UnityEngine.UI.Text>().text = this.name;
        }
    }
コード例 #3
0
    public void OnPointerUp(PointerEventData eventData)
    {
        TouchObject canceled = _touches[eventData.pointerId];

        TouchRemoved(canceled);
        _touches.Remove(eventData.pointerId);
    }
コード例 #4
0
    // Adds a new touch to the list every time the screen is touched
    public void AddTouch(Touch touch, RectTransform rect)
    {
        TouchObject newTouch = new TouchObject(touch, rect);

        mTouches[touch.fingerId] = newTouch;
        CheckHitNote(newTouch, rect);
    }
コード例 #5
0
    public void OnPointerDown(PointerEventData eventData)
    {
        eventData.pointerId = _idProvider++;
        TouchObject t = new TouchObject(eventData, eventData.pointerId);

        _touches.Add(eventData.pointerId, t);
        TouchAdded(t);
    }
コード例 #6
0
ファイル: ItemController.cs プロジェクト: androosha/Bag
 void OnTapEvent(TouchObject touch)
 {
     Debug.Log(name + " tap");
     if (onTapEvent != null)
     {
         onTapEvent.Invoke(this);
     }
 }
コード例 #7
0
ファイル: NoOrderTouchGoal.cs プロジェクト: SoundGuy/GGJ2018
    private void SubGoalTouched(TouchObject to)
    {
        GoalsSet.Remove(to);

        if (GoalsSet.Count == 0)
        {
            CompleteGoal();
            Debug.Log("NoOrderGoalComplete");
        }
    }
コード例 #8
0
 // Use this for initialization
 void Start()
 {
     if (touchObejct == null)
     {
         TouchObject parent = gameObject.GetComponentInParent <TouchObject>();
         if (parent != null)
         {
             touchObejct = parent;
         }
     }
 }
コード例 #9
0
    // Update is called once per frame
    void Update()
    {
        #if UNITY_IPHONE || UNITY_ANDROID && !UNITY_EDITOR
        _touchCount = Input.touchCount;
        #else
        _touchCount = 0;

        if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
        {
            TouchObject touch = _bufferTouchObjes[0];
            touch.deltaPosition = Vector2.zero;
            touch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        }

        if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
        {
            _touchCount++;

            TouchObject touch    = _bufferTouchObjes[0];
            Vector2     inputPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            touch.deltaPosition = inputPos - touch.position;
            touch.position      = inputPos;

            // copy point
            bool isRot  = Input.GetKey(KeyCode.LeftAlt);
            bool isPan  = Input.GetKey(KeyCode.LeftShift);
            bool isPanY = Input.GetKey(KeyCode.LeftControl);
            if (isRot || isPan || isPanY)
            {
                _touchCount++;

                TouchObject touchCopy = _bufferTouchObjes[1];
                Vector2     copyPos   = Vector2.zero;
                if (isRot)
                {
                    copyPos = new Vector2(Screen.width - touch.position.x, Screen.height - touch.position.y);
                }
                else
                {
                    if (isPan)
                    {
                        copyPos = new Vector2(touch.position.x + 30, Screen.height - touch.position.y);
                    }
                    else
                    {
                        copyPos = new Vector2(Screen.width - touch.position.x, touch.position.y);
                    }
                }
                touchCopy.position = copyPos;
            }
        }
        #endif
    }
コード例 #10
0
 // Same as above, but is typically only called when TouchObject is first created
 private void CheckHitNote(TouchObject touch, RectTransform rect)
 {
     if (RectTransformUtility.RectangleContainsScreenPoint(rect, touch.mTouch.position))
     {
         char lane = rect.gameObject.GetComponent <NoteHit>().mLaneColor;
         if (CheckIfNoteIsClose(lane))
         {
             HitNextNote(lane, touch);
         }
         return;
     }
 }
コード例 #11
0
    // Decides which type of note hit function to call
    private void HitNextNote(char lane, TouchObject touch)
    {
        switch (RhythmManager.instance.mSpawnedNotes[lane].Peek().GetComponent <NoteScript>().mType)
        {
        case 'R':
            HitRegularNote(lane, touch);
            break;

        case 'L':
            HitLongNote(lane);
            break;
        }
    }
コード例 #12
0
 // Checks if the given touch is close to the next note in its lane
 private void CheckHitNote(TouchObject touch)
 {
     foreach (KeyValuePair <char, RectTransform> pair in mButtons)
     {
         if (RectTransformUtility.RectangleContainsScreenPoint(pair.Value, touch.mTouch.position))
         {
             if (CheckIfNoteIsClose(pair.Key))
             {
                 HitNextNote(pair.Key, touch);
             }
             continue;
         }
     }
 }
コード例 #13
0
    private void SubGoalTouched(TouchObject to)
    {
        bool complete = true;

        for (int i = 0; i < SubGoals.Length && complete; i++)
        {
            complete &= SubGoals[i].IsTouched;
        }
        if (complete)
        {
            CompleteGoal();
            Debug.Log("SimGoalComplete");
        }
    }
コード例 #14
0
 TouchObjectState GetTouchedPrev(TouchObject touchObject)
 {
     if (touchedPrev != null)
     {
         foreach (var t in touchedPrev)
         {
             if (t.touchObject == touchObject)
             {
                 return(t);
             }
         }
     }
     return(null);
 }
コード例 #15
0
    private void Awake()
    {
        if (_instance != null)
        {
            Destroy(this);
            return;
        }

        _instance                       = this;
        _spriteRenderer                 = GetComponent <SpriteRenderer>();
        _soulKeeper                     = transform.Find("SoulKeeper").GetComponent <SoulKeeper>();
        _secondChanceClickArea          = GetComponent <TouchObject>();
        _secondChanceClickArea.IsActive = false;
        _secondChanceClickArea.OnClick.AddListener(OnSecondChanceAreaClick);
    }
コード例 #16
0
    void OnGUI()
    {
        if (!debug)
        {
            return;
        }
        float w = 20;
        float h = 20;

        for (int i = 0; i < _touchCount; i++)
        {
            TouchObject touch = _bufferTouchObjes[i];
            Rect        rect  = new Rect(touch.position.x - w / 2, Screen.height - touch.position.y - w / 2, w, h);
            GUI.Label(rect, "X");
        }
    }
コード例 #17
0
 private void Update()
 {
     if (TouchObject.IsTouchObject(blockTab, uiCamera))
     {
         selectTab = blockTab;
         subject.OnNext(selectTab);
     }
     else if (TouchObject.IsTouchObject(Player1SkinTab, uiCamera))
     {
         selectTab = Player1SkinTab;
         subject.OnNext(selectTab);
     }
     else if (TouchObject.IsTouchObject(Player2SkinTab, uiCamera))
     {
         selectTab = Player2SkinTab;
         subject.OnNext(selectTab);
     }
 }
コード例 #18
0
        void Update()
        {
            if (TouchInput.Instance.TouchCount > 0)
            {
                this.TouchObj1 = TouchInput.Instance.GetTouch(0);

                var rTouchPos = this.TouchObj1.position;
                if (rTouchPos.x < Screen.width * 0.3f)
                {
                    if (this.TouchObj1.phase == TouchPhase.Began)
                    {
                        this.JoystickRootTrans.anchoredPosition = this.TouchObj1.position;
                        Joystick.Instance.Reset();
                    }
                    else if (this.TouchObj1.phase == TouchPhase.Moved)
                    {
                        this.JoystickFrontTrans.anchoredPosition += this.TouchObj1.deltaPosition;

                        Vector2 rDir = this.TouchObj1.position - this.JoystickRootTrans.anchoredPosition;
                        if (rDir.sqrMagnitude > this.JoystickMaxDistance * this.JoystickMaxDistance)
                        {
                            this.JoystickFrontTrans.anchoredPosition = rDir.normalized * this.JoystickMaxDistance;
                        }
                        Joystick.Instance.Set(this.JoystickFrontTrans.anchoredPosition.x / this.JoystickMaxDistance,
                                              this.JoystickFrontTrans.anchoredPosition.y / this.JoystickMaxDistance);
                    }
                    else if (this.TouchObj1.phase == TouchPhase.Ended)
                    {
                        this.JoystickRootTrans.anchoredPosition  = this.JoystickInitPos;
                        this.JoystickFrontTrans.anchoredPosition = Vector2.zero;
                        Joystick.Instance.Reset();
                    }
                }
            }
            else
            {
                this.JoystickRootTrans.anchoredPosition  = this.JoystickInitPos;
                this.JoystickFrontTrans.anchoredPosition = Vector2.zero;
                Joystick.Instance.Reset();
            }
        }
コード例 #19
0
        // ----------------------
        // Events
        // ----------------------


        // --------------------
        public void OnTouchStart(Vector2 startPos, Vector2 curPos, float timeElapsed, TouchObject touchObj)
        {
            this.OnTouchStart(startPos, curPos, timeElapsed, touchObj.IsMouse(), touchObj.IsPressureSensitive(), touchObj.GetPressure());
        }
コード例 #20
0
 // Simple note hit. Destroys the note and activates the appropriate lane's cruncher's animation/particle effect
 private void HitRegularNote(char lane, TouchObject touch)
 {
     mButtons[lane].gameObject.GetComponent <NoteHit>().HitNote();
     Destroy(RhythmManager.instance.mSpawnedNotes[lane].Dequeue());
 }
コード例 #21
0
    void SimulateAR()
    {
        if (Input.GetMouseButton(0))
        {
            bool       touchedObject = false;
            Ray        ray           = CameraSingleton.Instance.GetActiveCamera().ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                TouchObject o = hit.collider.gameObject.GetComponent <TouchObject>();
                if (o)
                {
                    o.OnTouch();
                    touchedObject = true;
                }
            }

            if (!touchedObject)
            {
                RaycastHit tHit;
                Vector3    rotatedForward = Quaternion.Euler(Random.Range(-6f, 6f), Random.Range(-6f, 6f), 0f) * ray.direction;
                Ray        rotatedRay     = new Ray(ray.origin, rotatedForward);
                bool       cancelOut      = false;
                // Randomly select an item to spawn from the list
                SpawnItem item = WeightedSelection.RandomItem <SpawnItem>(spawnPrefabs, FindWeight);
                if (Physics.Raycast(rotatedRay, out tHit))
                {
                    for (int i = 0; i < spawnedObjects.Count; i++)
                    {
                        if (spawnedObjects[i] != null)
                        {
                            float d       = Vector3.Distance(tHit.point, spawnedObjects[i].obj.transform.position);
                            float padding = item.positionPadding + spawnedObjects[i].positionPadding;
                            if (d < padding)
                            {
                                cancelOut = true;
                                break;
                            }
                        }
                        else
                        {
                            randomGrassLocation.text = "Found a null grass object! Removing";
                            spawnedObjects.Remove(spawnedObjects[i]);
                        }
                    }

#if TESTING
                    if (Time.timeSinceLevelLoad > lastSample + 1f)
                    {
                        hitPointText.text      = "Hit point: " + tHit.Point.ToString();
                        closestGrassText.text  = "No longer calculating";
                        grassObjectsCount.text = "Grass count: " + spawnedObjects.Count.ToString();
                        if (spawnedObjects.Count > 0)
                        {
                            randomGrassLocation.text = spawnedObjects[Random.Range(0, spawnedObjects.Count)].transform.position.ToString();
                        }
                        lastSample = Time.timeSinceLevelLoad;
                    }
#endif

                    if (cancelOut)
                    {
                        return;
                    }

                    GameObject  newObj  = item.DoSetup(tHit.point, GameObject.Find("TestingArea").transform);
                    SpawnedItem newItem = new SpawnedItem();
                    newItem.obj = newObj; newItem.positionPadding = item.positionPadding;
                    spawnedObjects.Add(newItem);

                    newObj.transform.rotation = Quaternion.Euler(0.0f,
                                                                 Random.Range(-360f, 360f), 0f);
                }
            }
        }
    }
コード例 #22
0
    void Update()
    {
#if UNITY_EDITOR
        SimulateAR();
        return;
#endif

        _QuitOnConnectionErrors();

        // The tracking state must be FrameTrackingState.Tracking in order to access the Frame.
        if (Frame.TrackingState != FrameTrackingState.Tracking)
        {
            const int LOST_TRACKING_SLEEP_TIMEOUT = 15;
            Screen.sleepTimeout = LOST_TRACKING_SLEEP_TIMEOUT;
            return;
        }

        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        Frame.GetNewPlanes(ref m_newPlanes);

        // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
        for (int i = 0; i < m_newPlanes.Count; i++)
        {
            // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
            // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
            // coordinates.
            GameObject planeObject = Instantiate(m_trackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                 transform);
            planeObject.GetComponent <TrackedPlaneVisualizer>().SetTrackedPlane(m_newPlanes[i]);
            planeObject.GetComponent <Renderer>().material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f));
        }

        // Disable the snackbar UI when no planes are valid.
        bool showSearchingUI = true;
        Frame.GetAllPlanes(ref m_allPlanes);
        for (int i = 0; i < m_allPlanes.Count; i++)
        {
            if (m_allPlanes[i].IsValid)
            {
                showSearchingUI = false;
                break;
            }
        }

        m_searchingForPlaneUI.SetActive(showSearchingUI);

        if (Input.touches.Length > 0)
        {
            TouchPhase t = Input.touches[0].phase; //just look at first touch until we decide how to handle multitouch

            if (t == TouchPhase.Ended)
            {
                tapMode = false;
            }

            Ray        ray = CameraSingleton.Instance.GetActiveCamera().ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (t == TouchPhase.Began)
                {
                    TouchObject o = hit.collider.gameObject.GetComponent <TouchObject>();
                    if (o)
                    {
                        o.OnTouch();
                        tapMode = true;
                    }
                }
            }

            if (!tapMode && t != TouchPhase.Ended)
            {
                TrackableHit     tHit;
                TrackableHitFlag raycastFilter  = TrackableHitFlag.PlaneWithinBounds | TrackableHitFlag.PlaneWithinPolygon;
                Vector3          rotatedForward = Quaternion.Euler(Random.Range(-6f, 6f), Random.Range(-6f, 6f), 0f) * ray.direction;
                Ray  rotatedRay = new Ray(ray.origin, rotatedForward);
                bool cancelOut  = false;
                // Randomly select an item to spawn from the list
                SpawnItem item = WeightedSelection.RandomItem <SpawnItem>(spawnPrefabs, FindWeight);
                if (Session.Raycast(rotatedRay, raycastFilter, out tHit))
                {
                    for (int i = 0; i < spawnedObjects.Count; i++)
                    {
                        if (spawnedObjects[i] != null)
                        {
                            float d       = Vector3.Distance(tHit.Point, spawnedObjects[i].obj.transform.position);
                            float padding = item.positionPadding + spawnedObjects[i].positionPadding;
                            if (d < padding)
                            {
                                cancelOut = true;
                                break;
                            }
                        }
                        else
                        {
                            randomGrassLocation.text = "Found a null grass object! Removing";
                            spawnedObjects.Remove(spawnedObjects[i]);
                        }
                    }

#if TESTING
                    if (Time.timeSinceLevelLoad > lastSample + 1f)
                    {
                        hitPointText.text      = "Hit point: " + tHit.Point.ToString();
                        closestGrassText.text  = "No longer calculating";
                        grassObjectsCount.text = "Grass count: " + spawnedObjects.Count.ToString();
                        if (spawnedObjects.Count > 0)
                        {
                            randomGrassLocation.text = spawnedObjects[Random.Range(0, spawnedObjects.Count)].transform.position.ToString();
                        }
                        lastSample = Time.timeSinceLevelLoad;
                    }
#endif

                    if (cancelOut)
                    {
                        return;
                    }

                    // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                    // world evolves.
                    var anchor = Session.CreateAnchor(tHit.Point, Quaternion.identity);

                    GameObject  newObj  = item.DoSetup(tHit.Point, anchor.transform);
                    SpawnedItem newItem = new SpawnedItem();
                    newItem.obj = newObj; newItem.positionPadding = item.positionPadding;
                    spawnedObjects.Add(newItem);

                    newObj.transform.rotation = Quaternion.Euler(0.0f,
                                                                 Random.Range(-360f, 360f), 0f);

                    // Use a plane attachment component to maintain y-offset from the plane (occurs after anchor updates).
                    newObj.GetComponent <PlaneAttachment>().Attach(tHit.Plane);
                }
            }
        }
    }
コード例 #23
0
    void HandRayCast()
    {
        //Debug.DrawRay(transform.position, transform.forward*5,Color.blue, 1f);
        if (Physics.Raycast(transform.position, transform.forward, out _hitInfo, 1))
        {
            if (_hitInfo.transform.gameObject.CompareTag("Grabable"))
            {
                if (_hitInfo.transform.gameObject.GetComponent <ObjectGrab>().GetIsGrabable())
                {
                    ObjectGrab objGrab = _hitInfo.transform.gameObject.GetComponent <ObjectGrab>();
                    if (Input.GetMouseButtonDown(0))
                    {
                        objGrab.objrigid.isKinematic = true;
                        objGrab.transform.parent     = transform;
                        objGrab.isGrabed             = true;
                    }

                    if (Input.GetMouseButtonUp(0))
                    {
                        objGrab.objrigid.isKinematic = false;
                        objGrab.transform.parent     = null;
                        objGrab.isGrabed             = false;
                    }
                    if (Input.GetKeyDown(KeyCode.F))
                    {
                        objGrab.objrigid.isKinematic = false;
                        objGrab.isGrabed             = false;
                        objGrab.transform.parent     = null;
                        objGrab.isShoot = true;
                        objGrab.objrigid.AddForce(transform.forward * throwForce, ForceMode.Impulse);
                    }
                }
            }
            else if (_hitInfo.transform.gameObject.CompareTag("Touchable"))
            {
                if (_hitInfo.transform.gameObject.GetComponent <TouchObject>().GetTouchable())
                {
                    TouchObject touchObj = _hitInfo.transform.gameObject.GetComponent <TouchObject>();
                    if (Input.GetMouseButtonDown(0))
                    {
                        Debug.Log("Touch");
                        touchObj.SetIsTouched();
                    }
                }
            }
            else if (_hitInfo.transform.gameObject.CompareTag("Eatable"))
            {
                if (_hitInfo.transform.gameObject.GetComponent <Consumer>().GetIsTouchable())
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        Debug.Log("Touch");
                        _hitInfo.transform.gameObject.GetComponent <Consumer>().Consume();
                        ui.HungryBar.value += 25f;

                        //여기에 배고픔 4분의1씩 차는거 구현하심됩니다.
                    }
                }
            }
        }
    }
コード例 #24
0
 private void Removed(TouchObject t)
 {
     this.t = null;
     Debug.Log("-");
 }
コード例 #25
0
 private void Added(TouchObject t)
 {
     this.t = t;
     Debug.Log("+");
 }
コード例 #26
0
    //TODO: リファクタリング
    void MultiTouchUpdate()
    {
        if (DeviceInputManager.touchCount >= 2)
        {
            TouchObject touch1 = DeviceInputManager.GetTouch(0);
            TouchObject touch2 = DeviceInputManager.GetTouch(1);

            if (!isStartTowFinger)
            {
                // Start Two Finger;
                isStartTowFinger = true;

                zoomDeltaList.Clear();
                centerDeltaList.Clear();

                preCenter = (touch1.position + touch2.position) / 2.0f;
            }

            // Find out how the touches have moved relative to eachother:
            Vector2 curDist  = touch1.position - touch2.position;
            Vector2 prevDist = (touch1.position - touch1.deltaPosition) - (touch2.position - touch2.deltaPosition);

            Vector2 center      = (touch1.position + touch2.position) / 2.0f;
            Vector2 centerDelta = center - preCenter;
            preCenter = center;

            float   zoomDelta = (curDist.magnitude - prevDist.magnitude) * 0.01f;
            Vector2 panDelta  = (curDist - prevDist) * 0.01f;

            // avg
            zoomDeltaList.Add(Mathf.Abs(zoomDelta));
            if (zoomDeltaList.Count > avgBufferNum)
            {
                zoomDeltaList.RemoveAt(0);
            }

            float avgZoomDelta = 0;
            for (int i = 0; i < zoomDeltaList.Count; i++)
            {
                avgZoomDelta += zoomDeltaList [i];
            }
            avgZoomDelta /= zoomDeltaList.Count;
            //
            centerDeltaList.Add(Mathf.Abs(centerDelta.magnitude));
            if (centerDeltaList.Count > avgBufferNum)
            {
                centerDeltaList.RemoveAt(0);
            }

            float avgCenterDelta = 0;
            for (int i = 0; i < centerDeltaList.Count; i++)
            {
                avgCenterDelta += centerDeltaList [i];
            }
            avgCenterDelta /= centerDeltaList.Count;
            //

            if (avgZoomDelta > 0.05f)
            {
                zoomDistance += zoomDelta;
            }
            if (avgCenterDelta > 2.0f)
            {
                panDistance += -centerDelta * 0.01f;
            }
        }
        else
        {
            isStartTowFinger = false;
        }
    }