2017年1月14日 星期六

[WPF] 抓取網頁資料

Step 1: 工具 > NuGet封裝管理員 > 管理方案的NuGet套件

Step 2: 瀏覽 > 搜尋HtmlAgilityPack > 安裝HtmlAgilityPack

*xpath是使用HAPXPathFinder v0.9軟體來尋找出來的,範例檔有提供

Step 3: Coding
using HtmlAgilityPack;
using System.Net;
using System.IO;

string url = "http://www.just-the-word.com/main.pl?word=hello";
string xpath = "/html[1]/body[1]/div[1]/div[3]/div[1]";  //xpath是使用HAPXPathFinder v0.9軟體來尋找出來的

HttpWebRequest httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
try
{
    HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;

     Stream stream = httpWebResponse.GetResponseStream();
     StreamReader reader = new StreamReader(stream, Encoding.UTF8);
     string s = reader.ReadToEnd();
     reader.Close();
     stream.Close();
     httpWebResponse.Close();

     HtmlDocument htmlDoc = new HtmlDocument();

     htmlDoc.LoadHtml(s);
     //16GB 32GB 64GB 的運送時間XPATH
     HtmlNode anchors = htmlDoc.DocumentNode.SelectSingleNode(xpath);
     //HtmlNode anchors32 = htmlDoc.DocumentNode.SelectSingleNode("/html/body/div[2]/div[3]/div/div[2]/div[2]/div[3]/ul/li[2]/label/span/span[3]/span");
     //HtmlNode anchors64 = htmlDoc.DocumentNode.SelectSingleNode("/html/body/div[2]/div[3]/div/div[2]/div[2]/div[3]/ul/li[3]/label/span/span[3]/span");

     //output
     //set RichTextBox
     richTextBox.Document.Blocks.Add(new Paragraph(new Run(anchors.InnerText)));
     //get RichTextBox
     //string richText = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd).Text;
}
catch (WebException web)
{
     //error message
}

完成

參考資料:
http://www.just-the-word.com/main.pl?word=walk&mode=combinations#N N*

範例檔下載

2017年1月9日 星期一

[Unity 3D] Text放大不失焦和調整AR拍攝距離

Text放大不失焦

調整AR拍攝距離
AR Camera > Camera > 調整屬性Field of View的數值

[Unity 3D] Image元件和Toggle按鈕(複選題)

從屬性欄位設定Image Source,顯示圖片
Step 1:

Step 2:

Toggle按鈕(複選題)
Step 1:
Step 2:
Step 3:

[Unity 3D] Keeping the object on the screen even when the target is lost


讓AR Camera 偵測到目標物後,產生的虛擬物件不會消失的方法有兩種:

The first one : 設定屬性
Step 1 : 要把ImageTarget 放到 ARCamera階層下.
Step 2 : Enable Extended Tracking 的選項打勾.

The Second one : 修改腳本
The script that handles what happens when tracking is lost is called DefaultTrackableEventHandler.cs and is found in Assets > Vuforia > Scripts. 
In that file you will find a function OnTrackingLost() This function disables all the renderComponents and colliderComponents for each of the children of the ImageTarget. If you want your object to stay visible comment out the following foreach loops like so:
private void OnTrackingLost()  //當目標物遺失就執行這方法
{
    Renderer[] rendererComponents = GetComponentsInChildren(true);
    Collider[] colliderComponents = GetComponentsInChildren(true);
    /*
    // Disable rendering:
    foreach (Renderer component in rendererComponents)
    {
        component.enabled = false;  //把false改成true,當目標物遺失虛擬物件不會跟著消失
    }

    // Disable colliders:
    foreach (Collider component in colliderComponents)
    {
        component.enabled = false;   //把false改成true,當目標物遺失虛擬物件不會跟著消失

    }
    */
    Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
}