-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJune.cs
More file actions
93 lines (66 loc) · 2.18 KB
/
June.cs
File metadata and controls
93 lines (66 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* See the copyright information at https://github.com/srfoster/June/blob/master/COPYRIGHT */
using UnityEngine;
using System.Collections;
using System;
using System.Threading;
using System.Diagnostics;
public class June {
protected GameObject game_object;
protected string game_object_name;
protected string java_file_name;
protected Process java_process;
protected Thread java_thread;
public delegate void GameObjectCallback(GameObject obj);
protected GameObjectCallback callback = null;
protected bool is_stopped = false;
public June(GameObject game_object, string java_file_name)
{
this.game_object = game_object;
this.game_object_name = game_object.name;
this.java_file_name = java_file_name;
}
public void Start() {
java_thread = (new Thread(javaCompileAndRun));
java_thread.Start();
}
public bool isStopped()
{
return is_stopped;
}
public void Stop() {
if(is_stopped)
return;
//is_stopped = true;
UnityEngine.Debug.Log("Trying to kill");
try{
//Work-around because Unity is being stupid
java_process.GetType().GetMethod( "Kill" ).Invoke( java_process, new object[]{} );
}catch(Exception e){
UnityEngine.Debug.Log(e);
}
}
public string getFileName()
{
return java_file_name;
}
virtual public void javaCompileAndRun()
{
try{
string class_name = java_file_name.Split('.')[0];
Shell.shell("javac", "-classpath '" + JuneConfig.june_files_path + "' "+JuneConfig.java_files_path+"/"+java_file_name);
java_process = Shell.shell_no_start("java", "-classpath '" + JuneConfig.june_files_path + ":" + JuneConfig.java_files_path+"' "+class_name+" " + game_object_name);
java_process.Start();
Boolean has_exited = Convert.ToBoolean(java_process.GetType().GetProperty( "HasExited" ).GetValue(java_process, new object[]{}));
while(!has_exited)
{
UnityEngine.Debug.Log("Waiting for Java process to exit: ");
Thread.Sleep(500);
has_exited = Convert.ToBoolean(java_process.GetType().GetProperty( "HasExited" ).GetValue(java_process, new object[]{}));
}
UnityEngine.Debug.Log("I'm here.");
is_stopped = true;
}catch(Exception e){
UnityEngine.Debug.Log(e);
}
}
}