示例#1
0
    //private void checkCornerGameObjects()
    //{
    //    // Check the GO exist
    //    if (topLeftObj == null && PageOrg.DictBarcodeFileNames.ContainsKey(MarkerTopLeftID))
    //    {
    //        string tempName = PageOrg.DictBarcodeFileNames[MarkerTopLeftID];
    //        if (PageOrganizer.DictPrintedDocObjects.ContainsKey(tempName))
    //            topLeftObj = PageOrganizer.DictPrintedDocObjects[tempName];
    //    }
    //    if (botRightObj == null && PageOrg.DictBarcodeFileNames.ContainsKey(MarkerBotRightID))
    //    {
    //        string tempName = PageOrg.DictBarcodeFileNames[MarkerBotRightID];
    //        if (PageOrganizer.DictPrintedDocObjects.ContainsKey(tempName))
    //            botRightObj = PageOrganizer.DictPrintedDocObjects[tempName];
    //    }
    //}
    #endregion

    #region Public Interfaces
    /// <summary>
    /// Update the noteboard with given document info and cropped region coordinates.
    /// </summary>
    /// <param name="targetDoc"></param>
    /// <param name="page"></param>
    /// <param name="normTLX">Normalized Top-Left X</param>
    /// <param name="normTLY">Normalized Top-Left Y</param>
    /// <param name="normBRX">Normalized Bottom-Right X</param>
    /// <param name="normBRY">Normalized Bottom-Right Y</param>
    public void UpdateNoteBoard(string targetDoc, int page, float normTLX, float normTLY, float normBRX, float normBRY, string source = "")
    {
        // Note: some of them has leading zero. make sure to clean the Resources name format.
        string _fullName = string.Format("{0}/{1}-{2}", targetDoc, targetDoc, page.ToString("D2"));
        //string _fullName = "Norrie03/Norrie03-01";
        Sprite tempBoardSprite = PageOrg.FindSprite(_fullName);

        if (tempBoardSprite == null)
        {
            _fullName       = string.Format("{0}/{1}-{2}", targetDoc, targetDoc, page);
            tempBoardSprite = PageOrg.FindSprite(_fullName);
        }
        if (tempBoardSprite == null)
        {
            Debug.Log("UpdateNoteBoard Error: target sprite not found:" + _fullName);
            return;
        }

        GameObject        tempObj = Instantiate(Resources.Load("CustomNotes")) as GameObject;
        CustomNotesObject noteObj = tempObj.GetComponent <CustomNotesObject>();

        noteObj.fullImage.sprite = tempBoardSprite;

        noteObj.SetMask(normTLX - CropSafeEdge, 1 - normTLY + CropSafeEdge, normBRX, 1 - normBRY - CropSafeEdge);
        noteObj.SetNoteInfo(targetDoc, page, noteObjList.Count, source, DateTime.Today.ToString("d"));
        // Move to fader
        tempObj.transform.SetParent(panelBoardObj.transform);
        tempObj.transform.localEulerAngles = Vector3.zero;

        float newX = 0, newY = 0;

        if (CurrSortMethod == SortingMethods.TIME)
        {
            // Default: put them one-by-one based on when they were created.
            //if (nextNoteX + noteObj.width / 2 > currBoardWidth / 2 || (currTag.Length > 0 && currTag != noteObj.CreateDate))
            if (nextNoteX + noteObj.width / 2 > currBoardWidth || (currTag.Length > 0 && currTag != noteObj.CreateDate))
            {
                // Move to the new line.
                nextNoteX  = notePadding;// -currBoardWidth / 2;
                nextNoteY -= avgNoteHeight;
            }
            if (currTag == "" || currTag != noteObj.CreateDate)
            {
                currTag = noteObj.CreateDate;
                AddTag(currTag, dateTagDict);
            }

            newX = nextNoteX + noteObj.width / 2;
            newY = nextNoteY - noteObj.height / 2;

            nextNoteX += noteObj.width + notePadding;
        }
        else if (CurrSortMethod == SortingMethods.NAME)
        {
            bool adjustFlag = false;
            int  insertedID = -1;
            if (nameNoteDict.ContainsKey(targetDoc))
            {
                // make it grow to the next line
                var lastObj = nameNoteDict[targetDoc][nameNoteDict[targetDoc].Count - 1];
                nextNoteX = lastObj.gameObject.transform.localPosition.x + lastObj.width / 2 + notePadding;
                nextNoteY = lastObj.gameObject.transform.localPosition.y + lastObj.height / 2;

                //if (nextNoteX + noteObj.width / 2 > currBoardWidth / 2)
                if (nextNoteX + noteObj.width / 2 > currBoardWidth)
                {
                    // Move to the new line.
                    nextNoteX  = notePadding;// -currBoardWidth / 2;
                    nextNoteY -= avgNoteHeight;
                    adjustFlag = true;
                    insertedID = nameNoteDict.IndexOfKey(targetDoc);
                }
            }
            else
            {
                nameNoteDict[targetDoc] = new List <CustomNotesObject>();
                insertedID = nameNoteDict.IndexOfKey(targetDoc);
                nextNoteX  = notePadding;// -currBoardWidth / 2;
                //newX = -currBoardWidth / 2 + noteObj.width / 2;
                if (insertedID == 0)
                {
                    nextNoteY = -notePadding;// currBoardHeight / 2;
                }
                else
                {
                    // Find last note y pos
                    var prevObj = nameNoteDict[nameNoteDict.Keys[insertedID - 1]][nameNoteDict[nameNoteDict.Keys[insertedID - 1]].Count - 1];
                    nextNoteY = prevObj.gameObject.transform.localPosition.y + prevObj.height / 2 - avgNoteHeight;
                }
                // Add a new tag, which will also change the nextNoteX/Y
                AddTag(targetDoc, nameTagDict);
                adjustFlag = true;
            }
            newX = nextNoteX + noteObj.width / 2;
            newY = nextNoteY - noteObj.height / 2;

            if (adjustFlag)
            {
                // Adjust the stuff under this line (affected)
                for (int i = insertedID + 1; i < nameNoteDict.Keys.Count; ++i)
                {
                    foreach (var obj in nameNoteDict[nameNoteDict.Keys[i]])
                    {
                        Vector3 src = obj.gameObject.transform.position;
                        obj.gameObject.transform.localPosition += new Vector3(0, -avgNoteHeight, 0);
                        StartCoroutine(obj.SlowMove(src, obj.gameObject.transform.position));
                    }
                }
            }
        }
        else if (CurrSortMethod == SortingMethods.SOURCE)
        {
            bool adjustFlag = false;
            int  insertedID = -1;
            if (sourceNoteDict.ContainsKey(source))
            {
                var lastObj = sourceNoteDict[source][sourceNoteDict[source].Count - 1];
                nextNoteX = lastObj.gameObject.transform.localPosition.x + lastObj.width / 2 + notePadding;
                nextNoteY = lastObj.gameObject.transform.localPosition.y + lastObj.height / 2;

                //if (nextNoteX + noteObj.width / 2 > currBoardWidth / 2)
                if (nextNoteX + noteObj.width / 2 > currBoardWidth)
                {
                    // Move to the new line.
                    nextNoteX  = notePadding;// -currBoardWidth / 2;
                    nextNoteY -= avgNoteHeight;
                    adjustFlag = true;
                    insertedID = sourceNoteDict.IndexOfKey(source);
                }
            }
            else
            {
                sourceNoteDict[source] = new List <CustomNotesObject>();
                insertedID             = sourceNoteDict.IndexOfKey(source);
                nextNoteX = notePadding;// -currBoardWidth / 2;
                //newX = -currBoardWidth / 2 + noteObj.width / 2;
                if (insertedID == 0)
                {
                    nextNoteY = -notePadding;// currBoardHeight / 2;
                }
                else
                {
                    // Find last note y pos
                    var prevObj = sourceNoteDict[sourceNoteDict.Keys[insertedID - 1]][sourceNoteDict[sourceNoteDict.Keys[insertedID - 1]].Count - 1];
                    nextNoteY = prevObj.gameObject.transform.localPosition.y + prevObj.height / 2 - avgNoteHeight;
                }
                // Add a new tag, which will also change the nextNoteX/Y
                AddTag(source, sourceTagDict);
                adjustFlag = true;
            }
            newX = nextNoteX + noteObj.width / 2;
            newY = nextNoteY - noteObj.height / 2;

            if (adjustFlag)
            {
                // Adjust the stuff under this line (affected)
                for (int i = insertedID + 1; i < sourceNoteDict.Keys.Count; ++i)
                {
                    foreach (var obj in sourceNoteDict[sourceNoteDict.Keys[i]])
                    {
                        Vector3 src = obj.gameObject.transform.position;
                        obj.gameObject.transform.localPosition += new Vector3(0, -avgNoteHeight, 0);
                        StartCoroutine(obj.SlowMove(src, obj.gameObject.transform.position));
                    }
                }
            }
        }

        Vector3 srcPos = PageOrg.hololensCamera.transform.position + PageOrg.hololensCamera.transform.forward * 0.8f + PageOrg.hololensCamera.transform.up * (-0.05f);

        //DEBUG:         //newX = newY = 0;
        noteObj.currTransform.localPosition = new Vector3(newX, newY, -0.01f);
        Vector3 destPos = noteObj.currTransform.position;

        Debug.Log("SlowMove:" + srcPos + ", " + destPos);
        StartCoroutine(noteObj.SlowMove(srcPos, destPos));

        // Add to the list and update the dictionary
        noteObjList.Add(noteObj);

        if (!nameNoteDict.ContainsKey(targetDoc))
        {
            nameNoteDict[targetDoc] = new List <CustomNotesObject>();
        }
        nameNoteDict[targetDoc].Add(noteObj);

        if (source.Length > 0)
        {
            if (!sourceNoteDict.ContainsKey(source))
            {
                sourceNoteDict[source] = new List <CustomNotesObject>();
            }
            sourceNoteDict[source].Add(noteObj);
        }

        //tempObj.transform.localPosition = new Vector3(newX, newY, 0);

        Debug.Log(string.Format("Update note board; Load sprite:{0}, At ({1}, {2})", _fullName, newX, newY));
    }
示例#2
0
    private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs hand)
    {
        if (audioSource != null && !audioSource.isPlaying)
        {
            audioSource.Play();

            if (GazeManager.Instance != null && GazeManager.Instance.Hit)
            {
                GameObject focusedObject = GazeManager.Instance.HitInfo.collider.gameObject;

                // I found that the Unity will create something like "CustomNotes(Clone)"
                if (focusedObject.name.Contains("CustomNotes"))
                {
                    // Notes (pieces of cropped content) being clicked
                    CustomNotesObject notesObject = focusedObject.GetComponent <CustomNotesObject>();
                    Debug.Log(string.Format("Tap on:{0}, page #{1}", notesObject.FileName, notesObject.Page));
                    pageOrganizer.NotePage.UpdateContextDocument(notesObject.FileName, notesObject.Page);
                }
                else if (focusedObject.name.Contains("BoardTag"))
                {
                    // The board tag being clicked
                    pageOrganizer.NotePage.TapOnBoardTag();
                }
                else if (focusedObject.name.Contains("CanvasBoard"))
                {
                    // The blank whiteboard being clicked
                    pageOrganizer.NotePage.TapOnBoard();
                }
                else if (focusedObject.name.Contains("Btn"))
                {
                    Button btn = focusedObject.GetComponent <Button>();
                    btn.onClick.Invoke();
                    //focusedObject.SendMessage("OnSelect", focusedObject, SendMessageOptions.DontRequireReceiver);
                }
                else if (focusedObject.name.Contains("Toggle"))
                {
                    Toggle tg = focusedObject.GetComponent <Toggle>();
                    tg.isOn = !tg.isOn;
                }
                else if (focusedObject.name.Contains("Pie"))
                {
                    PieMenu pieMenu = focusedObject.GetComponent <PieMenu>();
                    PageConstants.RefEventStatus prevRefFlag = pageOrganizer.RefPage.RefFlag;
                    // Invoke on current cursor position
                    int tryTap = pieMenu.MousePressed(true, Vector2.zero);
                    //pieMenu.MousePressed(new Vector2(GazeManager.Instance.Position.x - focusedObject.transform.position.x, GazeManager.Instance.Position.y - focusedObject.transform.position.y), true);
                    // Previously in Full Paper mode (manipulation mode) and now changed
                    if (prevRefFlag == PageConstants.RefEventStatus.FULL_PAPER && tryTap >= 0)
                    {
                        GazeGestureManager.Instance.ResetGestureRecognizers();
                    }
                }
                else if (focusedObject.name.Contains("PanelTag"))
                {
                    pageOrganizer.TitlePage.TagPointerClick(focusedObject);
                }
                else if (focusedObject.name.Contains("ThumbnailItem"))
                {
                    // Item in PDF Viewer
                    Button btn = focusedObject.GetComponent <Button>();
                    btn.onClick.Invoke();
                }

                Debug.Log("Tap:" + focusedObject.name + " parent: " + focusedObject.transform.parent.gameObject.name + ", pos: " + GazeManager.Instance.Position);
            }
        }

        //if (InteractibleManager.Instance.FocusedGameObject != null)
        //{
        //    // Play a select sound if we have an audio source and are not targeting an asset with a select sound.
        //    if (audioSource != null && !audioSource.isPlaying &&
        //        (InteractibleManager.Instance.FocusedGameObject.GetComponent<Interactible>() != null &&
        //        InteractibleManager.Instance.FocusedGameObject.GetComponent<Interactible>().TargetFeedbackSound == null))
        //    {
        //        audioSource.Play();
        //    }

        //    // Cache InteractibleManager's FocusedGameObject in FocusedGameObject.
        //    FocusedGameObject = InteractibleManager.Instance.FocusedGameObject;
        //}
    }