Example #1
0
        public static RfidBinding checkBindings(JSONNode JSONatt, touchType smartTouchType)
        {
            //Debug.LogError ("Checking rfid bindings that contains attributes...");
            RfidBinding rfidObject = null;

            for (int i = 0; i < bindedObjects.Count; i++)
            {
                RfidBinding temp = bindedObjects [i];
                for (int k = 0; k < JSONatt.Count; k++)
                {
                    string tempAttribute = JSONatt [k].Value;
                    if (temp.attribute.Contains(tempAttribute))
                    {
                        i = bindedObjects.Count;
                        k = JSONatt.Count;
                        //Debug.LogError ("Attributes found!...'" + tempAttribute + "', checking if binding is enabled and functions exists!");
                        if (temp.enableBinding &&
                            ((smartTouchType == touchType.smartTouchStart && temp.smartTouchStart != null) ||
                             (smartTouchType == touchType.smartTouchEnd && temp.smartTouchEnd != null)))
                        {
                            rfidObject = temp;
                        }
                    }
                    else
                    {
                        //Debug.LogError ("No bindings exists with attributes, " + tempAttribute);
                        rfidObject = null;                         //object exits, but not enabled or does not contain executable function
                    }
                }
            }
            return(rfidObject);
        }
Example #2
0
        public static RfidBinding checkBindings(JSONNode JSONatt, touchType smartTouchType)
        {
            //Debug.LogError ("Checking rfid bindings that contains attributes...");
            RfidBinding rfidObject = null;
            for (int i = 0; i < bindedObjects.Count; i++) {
                RfidBinding temp = bindedObjects [i];
                for (int k = 0; k<JSONatt.Count; k++) {
                    string tempAttribute = JSONatt [k].Value;
                    if (temp.attribute.Contains (tempAttribute)) {
                        i = bindedObjects.Count;
                        k = JSONatt.Count;
                        //Debug.LogError ("Attributes found!...'" + tempAttribute + "', checking if binding is enabled and functions exists!");
                        if(temp.enableBinding &&
                            ((smartTouchType == touchType.smartTouchStart && temp.smartTouchStart != null) ||
                         (smartTouchType == touchType.smartTouchEnd && temp.smartTouchEnd != null))){
                            rfidObject = temp;
                        }

                    } else {
                        //Debug.LogError ("No bindings exists with attributes, " + tempAttribute);
                        rfidObject = null; //object exits, but not enabled or does not contain executable function
                    }
                }
            }
            return rfidObject;
        }
Example #3
0
        public static bool compareJSON(string ID, touchType ST, Vector3 location, out RfidBinding rfidObject)
        {
            ////Debug.LogError ("Comparing socket input with JSON file and RfidBindings");
            JSONNode attributes = findTagInJSON(ID, location);

            rfidObject = BindManager.checkBindings(attributes, ST);
            if (attributes != null && rfidObject != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
    static float staticSize = 0.2f; //判断为长按的最大偏移半径
    /// <summary>
    /// Touchs the event.
    /// </summary>
    /// <returns>The event.</returns>
    /// <param name="t">T.</param>
    /// <param name="presstime">Presstime.</param>
    static public touchType tEvent(Touch t, ref float presstime)
    {
        if (Mathf.Abs(t.deltaPosition.x) > staticSize && Mathf.Abs(t.deltaPosition.y) > staticSize)
        {
            if (drop)
            {
//				拖动状态
                tP = touchType.drop;
            }
            else
            {
//				移动状态
                tP   = touchType.move;
                move = true;
            }
        }
        if (Mathf.Abs(t.deltaPosition.x) < staticSize && Mathf.Abs(t.deltaPosition.y) < staticSize && move == false && drop == false)
        {
//			按压时间大于0.3秒的时候进入长按状态
            presstime += Time.deltaTime;
            if (presstime > longPressTime)
            {
                tP   = touchType.longpress;
                drop = true;
            }
        }
        if (t.phase == TouchPhase.Ended)
        {
//			松手时候如果按压时间少于长按时间就是单击
            if (presstime < longPressTime)
            {
                tP = touchType.relase;
            }
            else
            {
//				否则就是结束触摸
                tP = touchType.touchend;
            }
//			重置状态
            drop      = false;
            move      = false;
            presstime = 0.0f;
        }
        return(tP);
    }
Example #5
0
        public static void rfidDetected(string ID, touchType ST, Vector3 location)
        {
            RfidBinding rfidObject;

            if (checkJSON.compareJSON(ID, ST, location, out rfidObject))
            {
                if (ST == touchType.smartTouchEnd)
                {
                    rfidObject.smartTouchEnd(ID, location);
                }
                else if (ST == touchType.smartTouchStart)
                {
                    rfidObject.smartTouchStart(ID, location);
                }
            }
            else
            {
                Debug.LogError("Unregistered RFID: " + ID);
            }
        }
Example #6
0
        public void RFIDEventManager(string ID, touchType ST, Vector3 location)
        {
            List <string> otherID    = new List <string> ();
            List <string> components = new List <string> ();
            Dictionary <string, string> properties = new Dictionary <string, string> ();

            checkJSON.findTagInfo(j, ID, out otherID, out components, out properties);
            bindedObject rfReadyObject = new bindedObject(ID, otherID, location, components, properties);

            if (components != null & properties != null)               //entry MUST contain some components and properties
            {
                if (ST == touchType.smartTouchStart)
                {
                    Debug.Log("Starting smarttouch start event");
                    smartTouchStart(rfReadyObject);
                }
                else if (ST == touchType.smartTouchEnd)
                {
                    smartTouchEnd(rfReadyObject);
                }
            }
        }
Example #7
0
 public static bool compareJSON(string ID, touchType ST, Vector3 location, out RfidBinding rfidObject)
 {
     ////Debug.LogError ("Comparing socket input with JSON file and RfidBindings");
     JSONNode attributes = findTagInJSON (ID, location);
     rfidObject = BindManager.checkBindings (attributes, ST);
     if (attributes != null && rfidObject != null){
         return true;
     } else
         return false;
 }
Example #8
0
 public static void rfidDetected(string ID, touchType ST, Vector3 location)
 {
     RfidBinding rfidObject;
     if (checkJSON.compareJSON (ID, ST, location, out rfidObject)) {
         if (ST == touchType.smartTouchEnd) {
             rfidObject.smartTouchEnd (ID, location);
         } else if (ST == touchType.smartTouchStart) {
             rfidObject.smartTouchStart (ID, location);
         }
     } else
         Debug.LogError ("Unregistered RFID: " + ID);
 }
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            touchMoved = false;
            Ray ourRay = Camera.main.ScreenPointToRay(Input.touches[0].position);
            Debug.DrawRay(ourRay.origin, 30 * ourRay.direction);

            RaycastHit[] hits;
            hits = Physics.RaycastAll(ourRay);

            RaycastHit info;

            for (int i = 0; i < hits.Length; i++)
            {
                RaycastHit hit   = hits[i];
                Collider   hitGO = hit.transform.GetComponent <Collider>();

                if (hitGO)
                {
                    if (hitGO.transform.parent.name == "Objects for Collision")
                    {
                        objectHit = hits[i];
                        Debug.Log("Ray Hitting Object");
                    }

                    if (hitGO.transform.GetComponent <IControllable>() != null && Input.touches[0].phase == TouchPhase.Began)
                    {
                        if (selectedObject != null && selectedObject == object_hit)
                        {
                            selectedObject.youveBeenUnselected();
                            selectedObject = null;
                        }

                        else
                        {
                            object_hit = hitGO.transform.GetComponent <IControllable>();
                            object_hit.youveBeenSelected();
                            selectedObject = object_hit;
                            starting_distance_to_selected_object = Vector3.Distance(Camera.main.transform.position, hitGO.transform.position);
                        }
                    }
                }
            }

            if (Input.touches.Length == 1)
            {
                switch (Input.touches[0].phase)
                {
                case TouchPhase.Began:
                    timeTouched = Time.time;

                    posTouch1Started = Input.touches[0].position;

                    break;

                case TouchPhase.Moved:
                    touchMoved = true;

                    touchValue = touchType.drag;
                    break;

                case TouchPhase.Stationary:
                    touchLength = Time.time - timeTouched;
                    if (touchLength > 0.3f)
                    {
                        //Debug.Log("Long Tap");
                        touchValue = touchType.long_tap;
                    }
                    break;

                case TouchPhase.Ended:
                    touchLength = Time.time - timeTouched;

                    if (touchLength < 0.3f && !touchMoved)
                    {
                        //Debug.Log("Tap!");
                        touchValue = touchType.tap;
                    }
                    break;
                }
            }

            else if (Input.touches.Length == 2)
            {
                switch (Input.touches[0].phase)
                {
                case TouchPhase.Began:
                    posTouch1Started = Input.touches[0].position;
                    break;

                case TouchPhase.Moved:
                    posTouch1Moved = Input.touches[0].position;
                    break;
                }

                switch (Input.touches[1].phase)
                {
                case TouchPhase.Began:
                    posTouch2Started = Input.touches[1].position;

                    initScaleDistance = Vector2.Distance(posTouch1Started, posTouch2Started);

                    break;

                case TouchPhase.Moved:

                    //Debug.Log("Touch 1 movement rotation" + Input.touches[0].deltaPosition.magnitude);

                    if (Input.touches[0].deltaPosition.magnitude < wiggleRoom)//rotate
                    {
                        initAngle = Vector2.Angle(Input.touches[0].position, Input.touches[1].position);
                        newAngle  = Vector2.Angle(Input.touches[0].position - Input.touches[0].deltaPosition, Input.touches[1].position - Input.touches[1].deltaPosition);

                        angleDelta = Mathf.DeltaAngle(newAngle, initAngle);

                        touchValue = touchType.rotate;
                    }

                    else//scale
                    {
                        posTouch2Moved = Input.touches[1].position;

                        newScaleDistanceDelta = Vector2.Distance(posTouch1Moved - Input.touches[0].deltaPosition, posTouch2Moved - Input.touches[1].deltaPosition);


                        if (newScaleDistanceDelta > 300)
                        {
                            newScaleDistance = Vector2.Distance(posTouch1Moved, posTouch2Moved);
                            scaleAmount      = newScaleDistance / initScaleDistance;
                            touchValue       = touchType.scale;
                        }

                        else
                        {
                            touchValue = touchType.drag;
                        }
                    }
                    break;
                }
            }

            switch (touchValue)
            {
            case touchType.tap:
                Debug.Log("Tap");

                if (Physics.Raycast(ourRay, out info))
                {
                    IControllable object_hit = info.transform.GetComponent <IControllable>();
                    if (object_hit != null)
                    {
                        object_hit.youveBeenTapped();
                    }
                }
                break;

            case touchType.long_tap:
                Debug.Log("Long Tap");

                if (Physics.Raycast(ourRay, out info))
                {
                    IControllable object_hit = info.transform.GetComponent <IControllable>();
                    if (object_hit != null)
                    {
                        object_hit.youveBeenLongTapped();
                    }
                }

                break;

            case touchType.drag:
                Debug.Log("Drag");

                if (selectedObject != null)   //Drag object
                {
                    //Drag Code
                    //Strategy 1
                    //Keep same distance from camera to selected object
                    //Ray new_position_ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
                    //selectedObject.moveTo(new_position_ray.GetPoint(starting_distance_to_selected_object));

                    //Stragey 2
                    //Theoretical Plane, move to plane - Screen to world point
                    //Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(Input.touches[0].position.x, Input.touches[0].position.y, 10f));
                    //selectedObject.moveTo(point);

                    //Stategy 3
                    //Move on oblique surface(floor) - Raycast
                    //Vector3 point = new Vector3(objectHit.point.x, objectHit.point.y+0.5f, objectHit.point.z);
                    //selectedObject.moveTo(point);

                    //Strategy 4
                    //General Surface(Collider)


                    selectedObject.moveTo(Input.touches[0].position, objectHit, starting_distance_to_selected_object);
                }

                else if (Input.touches.Length == 1)   //Strafe camera
                {
                    Camera.main.transform.Translate(-Input.touches[0].deltaPosition.x * cameraStrafeSpeed * Time.deltaTime, 0, 0);
                }

                else if (selectedObject == null && Input.touches.Length == 2)   //rotate camera up/down, left/right
                {
                    Debug.Log("drag camera");
                    //Camera.main.transform.rotation = Quaternion.Euler(angleY, angleX, 0.0f);
                    Camera.main.transform.Rotate(Input.touches[0].deltaPosition.y * cameraRotateSpeed * Time.deltaTime, -Input.touches[0].deltaPosition.x * cameraRotateSpeed * Time.deltaTime, 0);
                }

                break;

            case touchType.scale:

                if (selectedObject != null)
                {
                    Debug.Log("Scale - Object");

                    selectedObject.scaleBy(scaleAmount, scaleSpeed);
                }

                else
                {
                    Debug.Log("Scale - Zoom");

                    if (Camera.main.transform.position.y <= 0)
                    {
                        Debug.Log("Camera cannot move below floor (y is trying to go below 0)");
                        Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y + 0.1f, Camera.main.transform.position.z);
                    }

                    else if (Camera.main.transform.position.y >= 15)
                    {
                        Debug.Log("Camera cannot go too high (y is trying to go above 15)");
                        Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y - 0.1f, Camera.main.transform.position.z);
                    }

                    else if (Camera.main.transform.position.x <= -15)

                    {
                        Debug.Log("Camera cannot move outside bounds of floor (X is trying to go below -15)");
                        Camera.main.transform.position = new Vector3(Camera.main.transform.position.x + 0.1f, Camera.main.transform.position.y, Camera.main.transform.position.z);
                    }

                    else if (Camera.main.transform.position.x >= 15)
                    {
                        Debug.Log("Camera cannot move outside bounds of floor (X is trying to go above 15)");
                        Camera.main.transform.position = new Vector3(Camera.main.transform.position.x - 0.1f, Camera.main.transform.position.y, Camera.main.transform.position.z);
                    }

                    else if (Camera.main.transform.position.z <= -15)
                    {
                        Debug.Log("Camera cannot move outside bounds of floor (Z is trying to go below -15)");
                        Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, Camera.main.transform.position.z + 0.1f);
                    }

                    else if (Camera.main.transform.position.z >= 15)
                    {
                        Debug.Log("Camera cannot move outside bounds of floor (Z is trying to go above 15)");
                        Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, Camera.main.transform.position.z - 0.1f);
                    }

                    else
                    {
                        if (scaleAmount > 1)
                        {
                            //Camera.main.transform.position += (scaleAmount*scaleSensitivity) * transform.forward;
                            Camera.main.transform.Translate(Vector3.forward * (scaleAmount * scaleSensitivity));
                        }

                        else
                        {
                            //Camera.main.transform.position += (-scaleAmount*scaleSensitivity) * transform.forward;
                            Camera.main.transform.Translate(Vector3.forward * (-scaleAmount * scaleSensitivity));
                        }
                    }
                }

                break;

            case touchType.rotate:

                // Vector3 v = Input.touches[1].position - Input.touches[0].position;

                // float theta = Mathf.Atan(v.y/v.x);

                // Quaternion rotation = Quaternion.AngleAxis(theta, Camera.main.transform.forward);

                rotateAmount = new Vector3(0, 0, -angleDelta);

                if (selectedObject != null)
                {
                    Debug.Log("Rotate - Object");

                    selectedObject.rotateBy(Quaternion.Euler(rotateAmount));
                }

                else
                {
                    Debug.Log("Rotate - Camera");

                    Camera.main.transform.rotation *= Quaternion.Euler(rotateAmount);
                }

                break;

            case touchType.determining:
                Debug.Log("Determining");
                break;
            }
        }

        else//accelerometer/gyroscope
        {
            if (selectedObject != null)
            {
                if (touchValue == touchType.tap && accelerometer)//acceleromter move
                {
                    Vector3 dir = Vector3.zero;

                    dir.x = Input.acceleration.x;
                    dir.z = Input.acceleration.y;

                    if (dir.sqrMagnitude > 1)
                    {
                        dir.Normalize();
                    }

                    dir *= Time.deltaTime;

                    selectedObject.moveToAccel(dir);
                }

                else if (touchValue == touchType.long_tap && gyroscope)//gyroscope rotate
                {
                    selectedObject.rotateByGyro(new Quaternion(Input.gyro.attitude.x, -Input.gyro.attitude.y, -Input.gyro.attitude.w, -Input.gyro.attitude.z));
                }
            }
        }
    }
Example #10
0
    void Update()
    {
        if (Input.touchCount > 0)
        {
            touchPoint   = Input.GetTouch(0);
            getTouchType = TouchEvent.tEvent(touchPoint, ref pressTime);
            switch (getTouchType)
            {
                #region drop
            case touchType.drop:
                MenuTitle.text = "drop";
                if (iconMoveT < 1 && iconMoveT > 0)
                {
                    hotBoxIconMove = true;    //允许插值;
                }

                if (SelectionIcon != null)
                {
                    SelectionIcon.rectTransform.localScale = oneScale;
                }

                hotBoxTagPosition = hotboxTarget.rectTransform.anchoredPosition = screenScale.V2Multi(touchPoint.position - Halfscreen);

                HotBoxDistanceList.Sort
                (
                    (HotBoxIconData i1, HotBoxIconData i2) =>
                {
                    return(Vector2.Distance(i1.position, hotBoxTagPosition).CompareTo(Vector2.Distance(i2.position, hotBoxTagPosition)));
                }
                );                                                                                                      //根据每个图标距离手指位置排序
                SelectionIcon = NowHotBoxIconList.Find((Image i) => { return(i.name == HotBoxDistanceList[0].name); }); //找出排序后在列表上第一个的对象

                if (SelectionIcon != null)
                {
                    SelectionIcon.rectTransform.localScale = oneFiveScale;         //放大图标
                }

                break;

                #endregion
                #region longpress
            case touchType.longpress:
                MenuTitle.text = "longpress";
                isHotMenuClose = false;     //设置热盒菜单为未关闭状态
                if (HotBoxDistanceList.Count > 0)
                {
                    HotBoxDistanceList.Clear();
                }

                for (int i = 0; i < NowHotBoxIconList.Count; i++)       //激活全部菜单图标
                {
                    NowHotBoxIconList[i].gameObject.SetActive(true);
                }

                hotBoxTagPosition = hotBoxCenterPosition = screenScale.V2Multi(touchPoint.rawPosition - Halfscreen); //设置中心点位置
                hotboxCenter.rectTransform.anchoredPosition = hotBoxCenterPosition;                                  //将中心点摆到对应位置

                if (hotBoxCenterPosition.x > 0)                                                                      //判断左右
                {
                    isRight = true;
                }
                else
                {
                    isRight = false;
                }

                setNowHotBoxList(ProgramData.instance.NowPage, hotBoxTagPosition, isRight); //设置当前页面的热盒图标位置

                for (int i = 0; i < NowHotBoxIconList.Count; i++)                           //把当前每一个图标的名字与位置数据存入列表用于比较
                {
                    HotBoxDistanceList.Add(new HotBoxIconData(NowHotBoxIconList[i].name, NowHotBoxIconTargetPositionList[i]));
                }

                hotBoxIconMove = true; //允许插值;
                isOut          = true; //设置为向外运动

                break;
                #endregion

                #region move
            case touchType.move:
                MenuTitle.text = "Move";
                //if (dropAction != null)
                //{
                //    dropAction();
                //}

                break;
                #endregion

                #region relase
            case touchType.relase:
                MenuTitle.text = "Relase";
                break;

            case touchType.touchend:
                MenuTitle.text = "touchEnd";
                hotboxTarget.rectTransform.anchoredPosition = notUseIconPosition;
                hotboxCenter.rectTransform.anchoredPosition = notUseIconPosition;

                if (SelectionIcon != null)
                {
                    if (SelectionIcon == Icon_Back)
                    {
                        MenuTitle.text = "back";
                    }
                    else
                    {
                        pageType pt = pageType.HotToday;
                        if (SelectionIcon == Icon_HotToday)
                        {
                            pt = pageType.HotToday;
                        }
                        else if (SelectionIcon == Icon_TheNew)
                        {
                            pt = pageType.TheNew;
                        }
                        else if (SelectionIcon == Icon_HotNew)
                        {
                            pt = pageType.HotNew;
                        }
                        else if (SelectionIcon == Icon_WeekList)
                        {
                            pt = pageType.WeekList;
                        }
                        else if (SelectionIcon == Icon_Seach)
                        {
                            pt = pageType.Seach;
                        }
                        ProgramData.instance.NowPage = pt;
                        MenuTitle.text = pt.ToString();
                    }
                }


                hotBoxIconMove = true;  //允许插值;
                isOut          = false; //设置图标状态为收回
                if (HotBoxDistanceList.Count > 0)
                {
                    HotBoxDistanceList.Clear();
                }
                break;
                #endregion
            }
        }
        if (hotBoxIconMove)
        {                                        //当允许被插值的时候则插值
            lerpToPosition(hotBoxTagPosition, ref iconMoveT, isOut);
        }

        //if (iconMoveT <= 0 && isHotMenuClose == false && SelectionIcon != null)//当菜单图标全部被收起同时热盒菜单处于打开状态同时有选中对象的时候
        //{
        //    SelectionIcon.rectTransform.localScale = oneScale;
        //    SelectionIcon.rectTransform.anchoredPosition = notUseIconPosition;
        //    SelectionIcon = null;
        //    isHotMenuClose = true;
        //}
    }