public void InitContent(ARDocument doc) { ResultTitle.text = doc.title; ResultAuthors.text = string.Join(", ", doc.authors); ResultSource.text = string.Format("<i>{0} - {1}</i>", doc.year, doc.source); BtnPDF.gameObject.SetActive(true); pdfLink = doc.pdfLink; BtnPDF.interactable = pdfLink.Length > 0; //Debug.Log("Init Content:" + ResultTitle.text + ResultTitle.font); }
public void InitTagContent(ARDocument doc, string words, GameObject cam) { TextTitle.text = doc.title; TextAuthors.text = string.Join(", ", doc.authors); TextSource.text = string.Format("{0} - {1}", doc.year, doc.source); TextExtraInfo.text = string.Format("Tag: <i>{0}</i>", words); hololensCamera = cam; rootObject = null; if (PageOrganizer.DictPrintedDocObjects.ContainsKey(doc.filename)) { rootObject = PageOrganizer.DictPrintedDocObjects[doc.filename]; } }
public void PreloadTags(string newDoc) { // Not yet prepared if (!Doc2Tags.ContainsKey(newDoc) && PageOrganizer.DictDocuments.ContainsKey(newDoc)) { ARDocument newARDoc = PageOrganizer.DictDocuments[newDoc]; Doc2Tags.Add(newDoc, new List <string>()); // Add all authors foreach (string author in newARDoc.authors) { AddNewTag(author, newDoc); } // Add source and year AddNewTag(newARDoc.source, newDoc); AddNewTag(newARDoc.year.ToString(), newDoc); } }
public void TagPointerClick(GameObject tagObj) { string tagName = tagObj.GetComponentInChildren <Text>().text; Debug.Log("Click on Tag:" + tagName); if (tagName != currClickedTag) { // Clear old ones and open new one foreach (var obj in tagResultObjList) { Destroy(obj); } tagResultObjList.Clear(); if (Tag2Docs.ContainsKey(tagName)) { var docs = Tag2Docs[tagName]; Debug.Log("Tag2Docs:" + string.Join(", ", docs)); foreach (var doc in docs) { // No need to create for current document if (doc != PageOrg.CurrDocStr && PageOrganizer.DictDocuments.ContainsKey(doc)) { ARDocument currDoc = PageOrganizer.DictDocuments[doc]; GameObject tagResultObj = Instantiate(Resources.Load("LocalSearchResult")) as GameObject; tagResultObj.SetActive(true); var tagResultHandler = tagResultObj.GetComponent <LocalSearchResultCanvas>(); tagResultHandler.InitTagContent(currDoc, tagName, PageOrg.hololensCamera); tagResultObjList.Add(tagResultObj); } else if (doc != PageOrg.CurrDocStr) { Debug.Log("Tag Clicked: cannot find target document from DictDocuments:" + doc); } } currClickedTag = tagName; } else { Debug.Log("Tag Clicked: cannot find target tag from Tag2Docs: " + tagName); } } }
private static List <ARDocument> ParseLocalDocuments(string word) { string cleanedWord = word.Trim(new char[] { ' ', ',', '.', ':', '\'', '\"', '-', '?', '[', ']', '{', '}', '<', '>', ';', '*' }).ToLower(); List <ARDocument> resultList = new List <ARDocument>(); if (!wordRecords.Dict.ContainsKey(cleanedWord)) { return(resultList); } List <Tuple <string, int> > resultZip = wordRecords.Files.Zip(wordRecords.Dict[cleanedWord].ToArray(), (first, second) => new Tuple <string, int>(first, second)).ToList(); resultZip.Sort((x, y) => y.Item2.CompareTo(x.Item2)); foreach (var pair in resultZip) { Debug.Log("[Ordered Result] FileName:" + pair.Item1 + ", Hit:" + pair.Item2); if (PageOrganizer.DictDocuments.ContainsKey(pair.Item1)) { if (pair.Item2 > 0) { ARDocument arDoc = PageOrganizer.DictDocuments[pair.Item1]; arDoc.extraInfo = pair.Item2.ToString(); // Add to list (to be displayed on window) resultList.Add(arDoc); } else { Debug.Log("Word didn't appear in target document:" + pair.Item1); } } else { Debug.Log("FileName from local records not exist in PageOrganizer.DictDocument: " + pair.Item1); } } return(resultList); }
/// <summary> /// The title meta-data (brief info)'s position / size is controled by the parent canvas. /// In this animator, only transparency is controlled. /// </summary> /// <param name="status"></param> /// <returns></returns> private IEnumerator TitleMetaDataFade(ChildObjFadeStatus status, ARDocument currDoc = null) { if (status == ChildObjFadeStatus.CLOSE || status == ChildObjFadeStatus.CLOSE_AND_OPEN) { for (float i = CANVAS_CLOSE_TIME; i >= 0; i -= Time.deltaTime) { float percentage = i / CANVAS_CLOSE_TIME; bkgMetaData.alpha = percentage; yield return(null); } MetaDataObj.SetActive(false); } if (status == ChildObjFadeStatus.OPEN || status == ChildObjFadeStatus.CLOSE_AND_OPEN) { MetaDataObj.SetActive(true); if (currDoc != null) { TextMetaDataTitle.text = currDoc.title; TextMetaDataAuthors.text = string.Join(", ", currDoc.authors); TextMetaDataSource.text = string.Format("{0} - {1}", currDoc.year, currDoc.source); } else { Debug.LogError("Title Fade Error: Fail to update Title Meta-data"); } //titleBriefText.text = sourceText; for (float i = 0; i <= CANVAS_OPEN_TIME; i += Time.deltaTime) { float percentage = i / CANVAS_OPEN_TIME; bkgMetaData.alpha = percentage; yield return(null); } } }
/// <summary> /// /// </summary> /// <param name="newDoc"></param> /// <param name="newRef"></param> /// <param name="normPosX">Normalized position X</param> /// <param name="normPosY">Normalized position Y</param> /// <param name="newRefType"></param> public void UpdateRefEvent(RefEventStatus newRefEvent, string newDoc = "", string newRef = "", float normPosX = 0, float normPosY = 0) { refAnimationCounter++; bool docDiff = (newDoc.Length > 0); bool refDiff = false; if (newRef.Length > 0 && newRef != refFileName) { refFileName = newRef; refDiff = true; if (PageOrganizer.DictDocuments.ContainsKey(refFileName)) { refDoc = PageOrganizer.DictDocuments[refFileName]; } else { refDoc = null; } } // Should update the canvas if the ref changed. bool shouldUpdate = docDiff || refDiff; Debug.Log(string.Format("parsing the events, name:{0}, current status:{1}, new status:{2}", refFileName, RefFlag, newRefEvent)); // Same Ref *Diff Type: if from OFF: open canvas, open new content, else: clear old, keep canvas, and open new content // Diff Ref *Diff Type: if from OFF: open canvas, open new content, else: clear old, modify canvas, open new // Diff Ref Same Type: modify canvas, close&open new // Check the level info from the pen, and update the _refFlag switch (newRefEvent) { case RefEventStatus.OFF: if (RefFlag != RefEventStatus.OFF) { ClearReferenceObjects(RefFlag); // Close (ON -> OFF) StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.CLOSE, RefFlag, refAnimationCounter)); RefFlag = RefEventStatus.OFF; } break; case RefEventStatus.META_DATA: if (RefFlag != RefEventStatus.META_DATA) { if (RefFlag == RefEventStatus.OFF) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.OPEN, newRefEvent, refAnimationCounter, normPosX, normPosY)); } else { ClearReferenceObjects(RefFlag); if (shouldUpdate) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); } } StartCoroutine(ReferenceMetaDataFade(ChildObjFadeStatus.OPEN)); } else if (shouldUpdate) { // level didn't change, but contents changed StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); StartCoroutine(ReferenceMetaDataFade(ChildObjFadeStatus.CLOSE_AND_OPEN)); } RefFlag = RefEventStatus.META_DATA; break; case RefEventStatus.PREVIEW: if (RefFlag != RefEventStatus.PREVIEW) { if (RefFlag == RefEventStatus.OFF) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.OPEN, newRefEvent, refAnimationCounter, normPosX, normPosY)); } else { ClearReferenceObjects(RefFlag); if (shouldUpdate) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); } } StartCoroutine(ReferencePreviewFade(ChildObjFadeStatus.OPEN)); } else if (shouldUpdate) { // level didn't change, but contents changed StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); StartCoroutine(ReferencePreviewFade(ChildObjFadeStatus.CLOSE_AND_OPEN)); } RefFlag = RefEventStatus.PREVIEW; break; case RefEventStatus.FULL_PAPER: if (RefFlag != RefEventStatus.FULL_PAPER) { if (RefFlag == RefEventStatus.OFF) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.OPEN, newRefEvent, refAnimationCounter, normPosX, normPosY)); } else { ClearReferenceObjects(RefFlag); if (shouldUpdate) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); } } StartCoroutine(ReferenceFullPaperFade(ChildObjFadeStatus.OPEN)); } else if (shouldUpdate) { // level didn't change, but contents changed StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); StartCoroutine(ReferenceFullPaperFade(ChildObjFadeStatus.CLOSE_AND_OPEN)); } RefFlag = RefEventStatus.FULL_PAPER; break; case RefEventStatus.VIDEO: if (RefFlag != RefEventStatus.VIDEO) { if (RefFlag == RefEventStatus.OFF) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.OPEN, newRefEvent, refAnimationCounter, normPosX, normPosY)); } else { ClearReferenceObjects(RefFlag); if (shouldUpdate) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); } } if (refDoc != null && refDoc.videoLink.Length > 0) { StartCoroutine(PageOrg.VideoFade(VideoObj, ChildObjFadeStatus.OPEN, refDoc.videoLink)); } } else if (shouldUpdate) { if (refDoc != null && refDoc.videoLink.Length > 0) { StartCoroutine(ReferenceCanvasFade(CanvasFadeStatus.MODIFY, newRefEvent, refAnimationCounter, normPosX, normPosY)); StartCoroutine(PageOrg.VideoFade(VideoObj, ChildObjFadeStatus.CLOSE_AND_OPEN, refDoc.videoLink)); } } RefFlag = RefEventStatus.VIDEO; break; default: // negative values Debug.Log("UpdateRef: negative values: " + newRefEvent); break; } }
/// <summary> /// The reference event animations use morph effect because they are closer. /// For the title event, since we explicitly switch context, we just shrink and re-open the new one. /// </summary> /// <param name="flag"></param> /// <returns></returns> private IEnumerator ReferenceMetaDataFade(ChildObjFadeStatus flag)//, float posX=0, float posY=0) { if (flag == ChildObjFadeStatus.CLOSE) { // Handle the fade in/out effect of the [current] printed reference on the desk, if available CanvasGroup prevPrintedGroup = null; if (refPrintedObj) { prevPrintedGroup = refPrintedObj.GetComponent <CanvasGroup>(); } // ON -> OFF: Fade out the title alpha for (float i = CANVAS_CLOSE_TIME; i >= 0; i -= Time.deltaTime) { float percentage = i / CANVAS_CLOSE_TIME; bkgMetaData.alpha = percentage; if (prevPrintedGroup) { prevPrintedGroup.alpha = percentage; refPrintedMaterial.color = new Color(refPrintedMaterial.color.r, refPrintedMaterial.color.g, refPrintedMaterial.color.b, percentage); } yield return(null); } MetaDataObj.SetActive(false); if (refPrintedObj) { // Finally, hide and clear the printed reference object refPrintedObj.SetActive(false); refPrintedObj = null; } Debug.Log("Ref: Title closed."); } else if (flag == ChildObjFadeStatus.OPEN) { MetaDataObj.SetActive(true); CanvasGroup currPrintedGroup = null; // Update new reference's printed object (AR Tag) if (PageOrganizer.DictPrintedDocObjects.ContainsKey(refFileName)) { refPrintedObj = PageOrganizer.DictPrintedDocObjects[refFileName]; refPrintedObj.SetActive(true); currPrintedGroup = refPrintedObj.GetComponent <CanvasGroup>(); } // Note the (x,y) of the 2D document maps to X and -Z axis of Unity3D if (PageOrganizer.DictDocuments.ContainsKey(refFileName)) { ARDocument refDoc = PageOrganizer.DictDocuments[refFileName]; MetaDataTitle.text = refDoc.title; MetaDataAuthors.text = string.Join(", ", refDoc.authors); MetaDataSource.text = string.Format("{0} - {1}", refDoc.year, refDoc.source); } else { Debug.LogError("Error: reference name not found in documents dict:" + refFileName); } for (float i = 0; i <= CANVAS_OPEN_TIME; i += Time.deltaTime) { float percentage = i / CANVAS_OPEN_TIME; bkgMetaData.alpha = percentage; if (currPrintedGroup) { currPrintedGroup.alpha = percentage; refPrintedMaterial.color = new Color(refPrintedMaterial.color.r, refPrintedMaterial.color.g, refPrintedMaterial.color.b, percentage); } yield return(null); } } else if (flag == ChildObjFadeStatus.CLOSE_AND_OPEN) { if (PageOrganizer.DictDocuments.ContainsKey(refFileName)) { ARDocument refDoc = PageOrganizer.DictDocuments[refFileName]; Debug.Log("Update Ref Title: " + refDoc.title); // Create new panel GameObject newMetaDataObj = Instantiate(MetaDataObj, gameObject.transform); Canvas newMetaDataCanvas = newMetaDataObj.GetComponent <Canvas>(); newMetaDataCanvas.overrideSorting = true; newMetaDataCanvas.sortingOrder = 0; Text[] texts = newMetaDataObj.GetComponentsInChildren <Text>(); // Handle the fade in/out effect of the [current] printed reference on the desk, if available CanvasGroup prevPrintedGroup = null; if (refPrintedObj) { prevPrintedGroup = refPrintedObj.GetComponent <CanvasGroup>(); } CanvasGroup currPrintedGroup = null; GameObject currPrintedObj = null; // Update new reference's printed object (AR Tag) if (PageOrganizer.DictPrintedDocObjects.ContainsKey(refFileName)) { currPrintedObj = PageOrganizer.DictPrintedDocObjects[refFileName]; currPrintedObj.SetActive(true); currPrintedGroup = currPrintedObj.GetComponent <CanvasGroup>(); } foreach (Text text in texts) { if (text.name.Contains("Title")) { text.text = "<b>" + refDoc.title + "</b>"; MetaDataTitle = text; } else if (text.name.Contains("Authors")) { text.text = string.Join(", ", refDoc.authors); MetaDataAuthors = text; } else if (text.name.Contains("Source")) { text.text = string.Format("<i>{0} - {1}</i>", refDoc.year, refDoc.source); MetaDataSource = text; } } CanvasGroup newGroup = newMetaDataObj.GetComponent <CanvasGroup>(); // hand-made Morph effect: fade in/out at the same time. for (float i = 0; i <= CANVAS_OPEN_TIME; i += Time.deltaTime) { float percentage = i / CANVAS_OPEN_TIME; // Fading out bkgMetaData.alpha = 1 - percentage; if (prevPrintedGroup) { prevPrintedGroup.alpha = 1 - percentage; } // Fading in newGroup.alpha = percentage; if (currPrintedGroup) { currPrintedGroup.alpha = percentage; } yield return(null); } if (refPrintedObj) { // Finally, hide and clear the printed reference object refPrintedObj.SetActive(false); refPrintedObj = null; } if (currPrintedObj) { // Update the printed reference object refPrintedObj = currPrintedObj; } newGroup.alpha = 1; // Update the variables MetaDataObj.SetActive(false); MetaDataObj = newMetaDataObj; bkgMetaData = newGroup; Debug.Log("Ref: New title has replaced the old one:" + MetaDataObj.name); } else { Debug.LogError("Error: reference name not found in documents dict:" + refFileName); } } }
/// <summary> /// Helper function: parse the json string and turn it into ARDocument List. /// Note: this is slow, and the caller needs to put it into a separate Task. /// </summary> /// <param name="jsonResult"></param> /// <returns></returns> //private IEnumerator ParseJSONResults(string jsonResult) public void ParseJSONResults(string jsonResult) { parsingStatus = PARSING_STATUS.PENDING; List <ARDocument> parsedResults = new List <ARDocument>(); //academicResult.Clear(); // Parse to output the result. var result = JsonConvert.DeserializeObject <JSONAcademic.RootObject>(jsonResult); int counter = 0; string title = ""; var authorNames = new List <string>(); string majorLastName = ""; int year = 0; string source = ""; string pdfUrl = ""; //yield return null; foreach (var entity in result.entities) { //Debug.Log(string.Format("----------{0}----------", counter)); var dict = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(entity.E); //yield return null; // Names in "E" is well-organized. But they are not guranteed. title = ""; authorNames.Clear(); majorLastName = ""; year = entity.Y; source = ""; pdfUrl = ""; if (dict.ContainsKey("DN")) { title = dict["DN"]; } else { //Debug.LogWarning("DisplayName not exist. Have to manulay create them."); var titleWords = entity.Ti.Split(' '); foreach (var tw in titleWords) { title += tw[0].ToString().ToUpper() + tw.Substring(1) + " "; } } //Debug.Log("Title: " + title); if (dict.ContainsKey("ANF")) { dynamic authors = dict["ANF"]; majorLastName = authors[0]["LN"]; foreach (var author in authors) { // FN, LN, S authorNames.Add(string.Format("{0} {1}", author["FN"], author["LN"])); } } else { //Debug.LogWarning("ANF not exist. Have to manulay create them."); foreach (var author in entity.AA) { string lowerName = author.AuN; var authorWords = lowerName.Split(' '); var currAuthorName = ""; foreach (var aw in authorWords) { currAuthorName += aw[0].ToString().ToUpper() + aw.Substring(1) + " "; } authorNames.Add(currAuthorName); } majorLastName = authorNames[0].Split(' ').Last(); var titleWords = entity.Ti.Split(' '); foreach (var tw in titleWords) { title += tw[0].ToString().ToUpper() + tw.Substring(1) + " "; } } //Debug.Log("Authors: " + string.Join(" ", authorNames)); if (dict.ContainsKey("VSN") && dict["VSN"].Length > 0) { // short conf/journal name source = dict["VSN"]; } else if (dict.ContainsKey("PB") && dict["PB"].Length > 0) { // short journal name source = dict["PB"]; } else if (entity.C != null && entity.C.CN.Length > 0) { source = entity.C.CN.ToUpper(); } else if (entity.J != null && entity.J.JN.Length > 0) { source = entity.J.JN.ToUpper(); } else if (dict.ContainsKey("VFN") && dict["VFN"].Length > 0) { // full conf name source = dict["VFN"]; } else if (dict.ContainsKey("BV") && dict["BV"].Length > 0) { // full journal name source = dict["BV"]; } else { //Debug.LogWarning("Source not available."); } // Cut string idea from Stack overflow: https://stackoverflow.com/a/16236570/4762924 if (source.Length == 0) { source = "N/A"; } else if (source.Length >= 50) { // Try to cut at space int pos = source.LastIndexOf(" ", 40); // No space to space is too soon, just cut without thinking. if (pos <= 40) { pos = 50; } source = source.Substring(0, pos) + "..."; } //Debug.Log(string.Format("Source: {0}-({1})", source, year)); // S.Ty Source Type(1:HTML, 2:Text, 3:PDF, 4:DOC, 5:PPT, 6:XLS, 7:PS) // Sometimes I found type 0 also points to pdf link if (dict.ContainsKey("S")) { foreach (var urlDict in dict["S"]) { int urlType = urlDict["Ty"]; string urlContent = urlDict["U"]; if (urlType == 3) { pdfUrl = urlContent; break; } else if (urlType == 0 && urlContent.Contains("pdf")) { pdfUrl = urlContent; } else { //Debug.Log(string.Format("----{0}; {1}", urlType, urlContent)); } } } if (pdfUrl.Length > 0) { //Debug.Log("PDF available:" + pdfUrl); } // Last name of first author + last two digits of year string fileName = string.Format("{0}{1}", majorLastName, (year % 100).ToString("D2")); //Debug.Log("Named as:" + fileName); ARDocument doc = new ARDocument(fileName, title, authorNames.ToArray(), source, year, pdfUrl); parsedResults.Add(doc); ++counter; } Debug.Log(string.Format("Got {0} new results. Old results: {1}.", parsedResults.Count, currResults.Count)); currResults.AddRange(parsedResults); parsingStatus = PARSING_STATUS.DONE; }