Example #1
0
    private void Update()
    {
        //Check if the left mouse button was used to click
        if (Input.GetMouseButtonUp(0) && _isActive)
        {
            //Finds the correct link based on the mouse position and the text field
            TextMeshProUGUI textMesh  = hpv.pages.Peek().GetComponentInChildren <TextMeshProUGUI>();
            int             linkIndex = TMP_TextUtilities.FindIntersectingLink(textMesh, Input.mousePosition, _mainCamera);
            if (linkIndex != -1)
            {
                int linkId = int.Parse(textMesh.textInfo.linkInfo[linkIndex].GetLinkID());
                HelpStickyObject currentObj = objectListByID[linkId];
                // reference it against the sticky list to see if it should get stickied or it should get un-stickied
                if (currentObj.isStickied)
                {
                    // un-sticky it
                    currentObj.stickyNote.SetActive(false);
                    currentObj.isStickied = false;
                }
                else
                {
                    soundUnderline.SoundPencilUnderline();
                    // sticky it
                    if (currentObj.stickyNote != null)
                    {
                        currentObj.stickyNote.SetActive(true);
                        currentObj.isStickied = true;
                    }
                    else
                    { // create a new sticky
                        if (_currentSticky == 10)
                        {
                            _currentSticky = 0;
                        }

                        foreach (var obje in objectListByID)
                        {
                            if (obje.stickyID == _currentSticky)
                            {
                                Destroy(obje.stickyNote);
                                obje.stickyID = -1;
                            }
                        }
                        currentObj.stickyNote = Instantiate(_stickyPrefab, stickyPositions[_currentSticky]);
                        currentObj.stickyNote.GetComponentInChildren <TextMeshProUGUI>().text = currentObj.stickyText;
                        currentObj.stickyID = _currentSticky;
                        _currentSticky++;
                        currentObj.isStickied = true;
                        if (TutorialManager.Instance._doTutorial && TutorialManager.Instance.currentState ==
                            TutorialManager.TutorialState.HelpfolderThree)
                        {
                            TutorialManager.Instance.AdvanceTutorial();
                        }
                    }
                }

                if (currentObj.isStickied)
                {
                    _underLiner.CreateLines(CreateUnderlineCoords(linkId), hpv.CurrentPageNumber(), linkId);
                }
                else
                {
                    _underLiner.DestroyLine(linkId);
                }
            }
        }
    }