-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcube.cs
More file actions
72 lines (60 loc) · 2.3 KB
/
cube.cs
File metadata and controls
72 lines (60 loc) · 2.3 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine.UI;
using UnityEngine;
#if UNITY_IOS || UNITY_TVOS
public class NativeAPI {
[DllImport("__Internal")]
public static extern void showHostMainWindow(string lastStringColor);
}
#endif
public class Cube : MonoBehaviour
{
public Text text;
void appendToText(string line) { text.text += line + "\n"; }
void Update()
{
transform.Rotate(0, Time.deltaTime*10, 0);
if (Application.platform == RuntimePlatform.Android)
if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit();
}
string lastStringColor = "";
void ChangeColor(string newColor)
{
appendToText( "Chancing Color to " + newColor );
lastStringColor = newColor;
if (newColor == "red") GetComponent<Renderer>().material.color = Color.red;
else if (newColor == "blue") GetComponent<Renderer>().material.color = Color.blue;
else if (newColor == "yellow") GetComponent<Renderer>().material.color = Color.yellow;
else GetComponent<Renderer>().material.color = Color.black;
}
void showHostMainWindow()
{
#if UNITY_ANDROID
try
{
AndroidJavaClass jc = new AndroidJavaClass("com.company.product.OverrideUnityActivity");
AndroidJavaObject overrideActivity = jc.GetStatic<AndroidJavaObject>("instance");
overrideActivity.Call("showMainActivity", lastStringColor);
} catch(Exception e)
{
appendToText("Exception during showHostMainWindow");
appendToText(e.Message);
}
#elif UNITY_IOS || UNITY_TVOS
NativeAPI.showHostMainWindow(lastStringColor);
#endif
}
void OnGUI()
{
GUIStyle style = new GUIStyle("button");
style.fontSize = 30;
if (GUI.Button(new Rect(10, 10, 200, 100), "Red", style)) ChangeColor("red");
if (GUI.Button(new Rect(10, 110, 200, 100), "Blue", style)) ChangeColor("blue");
if (GUI.Button(new Rect(10, 300, 400, 100), "Show Main With Color", style)) showHostMainWindow();
if (GUI.Button(new Rect(10, 400, 400, 100), "Unload", style)) Application.Unload();
if (GUI.Button(new Rect(440, 400, 400, 100), "Quit", style)) Application.Quit();
}
}