Skip to content
Open
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
Binary file added Lab 12 Report.docx
Binary file not shown.
24 changes: 24 additions & 0 deletions threads/Assets/HealthVooDoo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

/// <summary>
/// Author: Matt Gipson
/// Contact: Deadwynn@gmail.com
/// Domain: www.livingvalkyrie.com
///
/// Description: HealthVooDoo
/// </summary>
public class HealthVooDoo : MonoBehaviour {
#region Fields

public int health = 5;
public Text healthText;

#endregion

void Update() {
healthText.text = "health: " + health;
}

}
12 changes: 12 additions & 0 deletions threads/Assets/HealthVooDoo.cs.meta

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

60 changes: 60 additions & 0 deletions threads/Assets/Lab11Thread.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using UnityEngine;
using System.Collections;
using System.Threading;

/// <summary>
/// Author: Matt Gipson
/// Contact: Deadwynn@gmail.com
/// Domain: www.livingvalkyrie.com
///
/// Description: Lab11Thread
/// </summary>
public class Lab11Thread : MonoBehaviour {
#region Fields

bool _stopThreads = false;
string _threadOutput = "";

#endregion

void Start() {
ThreadStart firstThread = new ThreadStart(DisplayThread1);
ThreadStart secondThread = new ThreadStart( DisplayThread2 );

Thread thread1 = new Thread(firstThread);
Thread thread2 = new Thread(secondThread);

thread1.Start();
thread2.Start();

Invoke("StopThreads", 10);

}

void DisplayThread1() {
lock (this) {
while (_stopThreads == false) {
print("display thread 1");
_threadOutput = "hello thread 1";
Thread.Sleep(1000);
print("thread 1 output --> " + _threadOutput);
}
}
}

void DisplayThread2() {
lock (this) {
while (_stopThreads == false) {
print("display thread 2");
_threadOutput = "hello thread 2";
Thread.Sleep(1000);
print("thread 2 output --> " + _threadOutput);
}
}
}

void StopThreads() {
_stopThreads = true;
}

}
12 changes: 12 additions & 0 deletions threads/Assets/Lab11Thread.cs.meta

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

84 changes: 84 additions & 0 deletions threads/Assets/Lab12ThreadVooDoo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using UnityEngine;
using System.Collections;
using System.Threading;

/// <summary>
/// Author: Matt Gipson
/// Contact: Deadwynn@gmail.com
/// Domain: www.livingvalkyrie.com
///
/// Description: Lab12ThreadVooDoo
/// </summary>
public class Lab12ThreadVooDoo : MonoBehaviour {
#region Fields

#endregion

void Start() {
Start7();
}

void Start7() {
string text = "t1";
Thread t1 = new Thread(() => print(text));

text = "t2";
Thread t2 = new Thread(() => print(text));

t1.Start();
t2.Start();
}

void Start6() {

Thread worker = new Thread(Go);
print("is worker background? " + worker.IsBackground);
worker.IsBackground = true;
print("is worker background? " + worker.IsBackground);
worker.Start();
}

void Start5() {
Thread.CurrentThread.Name = "main";
Thread worker = new Thread(Go);
worker.Name = "worker";
worker.Start();
Go();
}

void Go() {
print("hello from " + Thread.CurrentThread.Name);
}

void Start4() {
for (int i = 0; i < 10; i++) {
int temp = i;
new Thread(() => print(temp)).Start();
}
}

void Start3() {
for (int i = 0; i < 10; i++) {
new Thread(() => Debug.Log(i)).Start();
}
}

void Start2() {
new Thread(() => {
print("Im running from another thread");
print("this is so cool!");
}).Start();
}

void Start1() {
Thread thread = new Thread(() => DisplayMessage("Hello from the thread!"));
thread.Start();
}

void DisplayMessage(string toPrint) {
print(toPrint);
}

void Update() {}

}
12 changes: 12 additions & 0 deletions threads/Assets/Lab12ThreadVooDoo.cs.meta

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

60 changes: 60 additions & 0 deletions threads/Assets/MovementVooDoo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using UnityEngine;
using System.Collections;
using System.Threading;
using JetBrains.Annotations;

/// <summary>
/// Author: Matt Gipson
/// Contact: Deadwynn@gmail.com
/// Domain: www.livingvalkyrie.com
///
/// Description: MovementVooDoo
/// </summary>
public class MovementVooDoo : MonoBehaviour {
#region Fields

public Vector3 moveDirection;
public Vector3 translatingVector = Vector3.left;
public Vector3 currPos;
public float speed;
public float delta;
Thread thread;

#endregion

void Start() {
thread = new Thread(Move);
//initialize thread
//start thread
thread.Start();
//start invoke repeating
InvokeRepeating("ChangeDirection", 5, 5);
}

void Move() {
while (translatingVector != currPos) {
//print("thread running");
translatingVector = Vector3.Lerp(translatingVector, moveDirection, delta * speed);
}
}

void ChangeDirection() {
print("called");
moveDirection = new Vector3(Random.Range(0,5), Random.Range(0,5), Random.Range(0,5));
}

void Update() {
transform.Translate(translatingVector);
currPos = transform.position;
delta = Time.deltaTime;
}

void OnTriggerEnter(Collider other) {
//print("triggered by " + other.name);
if (other.tag == "Enemy" ) {
//print("in if block");
HealthVooDoo health = GetComponent<HealthVooDoo>();
health.health--;
}
}
}
12 changes: 12 additions & 0 deletions threads/Assets/MovementVooDoo.cs.meta

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

9 changes: 9 additions & 0 deletions threads/Assets/UnityVS.meta

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

9 changes: 9 additions & 0 deletions threads/Assets/UnityVS/Editor.meta

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

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guid: 38d405c119fcc7c4e83d4a478a40ff2f
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guid: 4ad02dc83da735c4e8d945332b9202f6
Binary file not shown.
20 changes: 20 additions & 0 deletions threads/Assets/UnityVS/Editor/UnityVS.VersionSpecific.dll.meta

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

Binary file added threads/Assets/test.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions threads/Assets/test.unity.meta

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

Binary file added threads/ProjectSettings/AudioManager.asset
Binary file not shown.
Binary file added threads/ProjectSettings/DynamicsManager.asset
Binary file not shown.
Binary file added threads/ProjectSettings/EditorBuildSettings.asset
Binary file not shown.
Binary file added threads/ProjectSettings/EditorSettings.asset
Binary file not shown.
Binary file added threads/ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file added threads/ProjectSettings/InputManager.asset
Binary file not shown.
Binary file added threads/ProjectSettings/NavMeshAreas.asset
Binary file not shown.
Binary file added threads/ProjectSettings/NetworkManager.asset
Binary file not shown.
Binary file added threads/ProjectSettings/Physics2DSettings.asset
Binary file not shown.
Binary file added threads/ProjectSettings/ProjectSettings.asset
Binary file not shown.
2 changes: 2 additions & 0 deletions threads/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m_EditorVersion: 5.1.2f1
m_StandardAssetsVersion: 0
Binary file added threads/ProjectSettings/QualitySettings.asset
Binary file not shown.
Binary file added threads/ProjectSettings/TagManager.asset
Binary file not shown.
Binary file added threads/ProjectSettings/TimeManager.asset
Binary file not shown.