diff --git a/.gitignore b/.gitignore index 3c555204..27e19b65 100644 --- a/.gitignore +++ b/.gitignore @@ -242,7 +242,6 @@ ExportedObj/ *.booproj *.svd - # Unity3D generated meta files *.pidb.meta @@ -370,3 +369,9 @@ captures/ *.app .idea + +TextMesh Pro/ +Library/ +ProjectSettings/ +UserSettings/ +Temp/ \ No newline at end of file diff --git a/system_Example/.gitignore b/system_Example/.gitignore index c413c614..15c2db32 100644 --- a/system_Example/.gitignore +++ b/system_Example/.gitignore @@ -7,6 +7,7 @@ /output /Assets/AssetStoreTools* /ProjectSettings +*.meta # Autogenerated VS/MD solution and project files ExportedObj/ diff --git a/system_Example/Assets/system_exam/thread_exam1/thread_exam1.cs b/system_Example/Assets/system_exam/thread_exam1/thread_exam1.cs index e837c416..8ecf7f51 100644 --- a/system_Example/Assets/system_exam/thread_exam1/thread_exam1.cs +++ b/system_Example/Assets/system_exam/thread_exam1/thread_exam1.cs @@ -11,40 +11,27 @@ using UniRx.Triggers; using UnityEngine.UI; + public class thread_exam1 : MonoBehaviour { // receiving Thread Thread receiveThread; + bool m_isRun; - // Use this for initialization - void Start () { - - Debug.Log("start udp Thread"); - receiveThread = new Thread( - new ThreadStart(ReceiveData)); - receiveThread.IsBackground = true; - receiveThread.Start(); - - - } - - // Update is called once per frame - void Update () { - - } - + [SerializeField] Button m_btnEndThread; // receive thread private void ReceiveData() { //client = new UdpClient(portLocal); - while (true) + int nCount = 1; + while (m_isRun) { try { Thread.Sleep(1000); - Debug.Log("tick :"); + Debug.Log("tick :" + nCount++); } catch (Exception err) @@ -52,6 +39,33 @@ private void ReceiveData() print(err.ToString()); } } + + Debug.Log ("thread end"); + } + // Use this for initialization + void Start () { + + m_isRun = true; + + Debug.Log("start udp Thread"); + receiveThread = new Thread( + new ThreadStart(ReceiveData)); + receiveThread.IsBackground = true; + receiveThread.Start(); + + m_btnEndThread.OnClickAsObservable () + .Subscribe (_ => { + m_isRun = false; + }); + + Observable.OnceApplicationQuit () + .Subscribe (_ => { + Debug.Log("OnceApplicationQuit"); + m_isRun = false; + }).AddTo(this); + } + + } diff --git a/system_Example/Assets/system_exam/thread_exam1/thread_exam1.unity b/system_Example/Assets/system_exam/thread_exam1/thread_exam1.unity index c9c05944..feb08b98 100644 Binary files a/system_Example/Assets/system_exam/thread_exam1/thread_exam1.unity and b/system_Example/Assets/system_exam/thread_exam1/thread_exam1.unity differ diff --git a/system_Example/Assets/system_exam/thread_exam2.meta b/system_Example/Assets/system_exam/thread_exam2.meta new file mode 100644 index 00000000..78fc85ac --- /dev/null +++ b/system_Example/Assets/system_exam/thread_exam2.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 7c5d6da35898c4cc685f9098d265b603 +folderAsset: yes +timeCreated: 1487310267 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/system_Example/Assets/system_exam/thread_exam2/main.cs b/system_Example/Assets/system_exam/thread_exam2/main.cs new file mode 100644 index 00000000..b3eab2a3 --- /dev/null +++ b/system_Example/Assets/system_exam/thread_exam2/main.cs @@ -0,0 +1,77 @@ +using UnityEngine; +using System.Collections; + +using System; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.Threading; + +using UniRx; +using UniRx.Triggers; +using UnityEngine.UI; + +using LitJson; + + +namespace thread_exam_2 +{ + + public class main : MonoBehaviour + { + bool m_isAppQuitting; + [SerializeField] Button m_BtnEnd; + + public System.IDisposable _udpSequence; + + // Use this for initialization + void Start () + { + m_isAppQuitting = false; + _udpSequence = Observable.Create < JsonData > ( observer => + { + int nCount=1; + + while (! m_isAppQuitting ) + { + Thread.Sleep(1000); + Debug.Log("tick "); + JsonData test_json = new JsonData(); + test_json["count"] = nCount++; + observer . OnNext (test_json); + } + Debug.Log("thread finish"); + observer . OnCompleted (); + return null ; + }) + . SubscribeOn ( Scheduler . ThreadPool ) + . Publish () + . RefCount () + . ObserveOnMainThread () + . Subscribe ( x => { + Debug.Log ( x.ToJson() ); + }) + . AddTo ( this ); + + m_BtnEnd.onClick.AsObservable().Subscribe (_ => { + Debug.Log("dispose thread"); + _udpSequence.Dispose (); + + }); + + + Observable.OnceApplicationQuit ().Subscribe (_ => { + + Debug.Log("app quit"); + _udpSequence.Dispose (); + + }).AddTo(this); + + + + + } + + } + +} diff --git a/system_Example/Assets/system_exam/thread_exam2/main.cs.meta b/system_Example/Assets/system_exam/thread_exam2/main.cs.meta new file mode 100644 index 00000000..eba25771 --- /dev/null +++ b/system_Example/Assets/system_exam/thread_exam2/main.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 85abba496c6ef455abd8ef07cf7986cc +timeCreated: 1487310597 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/system_Example/Assets/system_exam/thread_exam2/scene.unity b/system_Example/Assets/system_exam/thread_exam2/scene.unity new file mode 100644 index 00000000..70769afd Binary files /dev/null and b/system_Example/Assets/system_exam/thread_exam2/scene.unity differ diff --git a/system_Example/Assets/system_exam/thread_exam2/scene.unity.meta b/system_Example/Assets/system_exam/thread_exam2/scene.unity.meta new file mode 100644 index 00000000..e6781fa8 --- /dev/null +++ b/system_Example/Assets/system_exam/thread_exam2/scene.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f14b460f401d945d59a266871b4d4c8c +timeCreated: 1487310544 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: