Skip to content
Draft

Dev3 #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ ExportedObj/
*.booproj
*.svd


# Unity3D generated meta files
*.pidb.meta

Expand Down Expand Up @@ -370,3 +369,9 @@ captures/
*.app

.idea

TextMesh Pro/
Library/
ProjectSettings/
UserSettings/
Temp/
1 change: 1 addition & 0 deletions system_Example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/output
/Assets/AssetStoreTools*
/ProjectSettings
*.meta

# Autogenerated VS/MD solution and project files
ExportedObj/
Expand Down
52 changes: 33 additions & 19 deletions system_Example/Assets/system_exam/thread_exam1/thread_exam1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,61 @@
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)
{
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);
}


}
Binary file modified system_Example/Assets/system_exam/thread_exam1/thread_exam1.unity
Binary file not shown.
9 changes: 9 additions & 0 deletions system_Example/Assets/system_exam/thread_exam2.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions system_Example/Assets/system_exam/thread_exam2/main.cs
Original file line number Diff line number Diff line change
@@ -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);




}

}

}
12 changes: 12 additions & 0 deletions system_Example/Assets/system_exam/thread_exam2/main.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.