-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathGameObjectExamples.cs
More file actions
61 lines (52 loc) · 1.89 KB
/
GameObjectExamples.cs
File metadata and controls
61 lines (52 loc) · 1.89 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
using UnityEngine;
using System.Collections.Generic;
using System.Reflection;
using System.Net;
/**
* Example console commands for getting information about GameObjects
*/
public static class GameObjectCommands {
[CUDLR.Command("object list", "lists all the game objects in the scene")]
public static void ListGameObjects() {
UnityEngine.Object[] objects = UnityEngine.Object.FindObjectsOfType(typeof(GameObject));
foreach (UnityEngine.Object obj in objects) {
CUDLR.Console.Log(obj.name);
}
}
[CUDLR.Command("object print", "lists properties of the object")]
public static void PrintGameObject(string[] args) {
if (args.Length < 1) {
CUDLR.Console.Log( "expected : object print <Object Name>" );
return;
}
GameObject obj = GameObject.Find( args[0] );
if (obj == null) {
CUDLR.Console.Log("GameObject not found : "+args[0]);
} else {
CUDLR.Console.Log("Game Object : "+obj.name);
foreach (Component component in obj.GetComponents(typeof(Component))) {
CUDLR.Console.Log(" Component : "+component.GetType());
foreach (FieldInfo f in component.GetType().GetFields()) {
CUDLR.Console.Log(" "+f.Name+" : "+f.GetValue(component));
}
}
}
}
}
/**
* Example console route for getting information about GameObjects
*
*/
public static class GameObjectRoutes {
[CUDLR.Route("^/object/list.json$", @"(GET|HEAD)", true)]
public static void ListGameObjects(CUDLR.RequestContext context) {
string json = "[";
UnityEngine.Object[] objects = UnityEngine.Object.FindObjectsOfType(typeof(GameObject));
foreach (UnityEngine.Object obj in objects) {
// FIXME object names need to be escaped.. use minijson or similar
json += string.Format("\"{0}\", ", obj.name);
}
json = json.TrimEnd(new char[]{',', ' '}) + "]";
context.Response.WriteString(json, "application/json");
}
}