Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class TestPlugin : MonoBehaviour
- {
- const string pluginName = "com.cw.unity.MyPlugin";
- static AndroidJavaClass _pluginClass;
- static AndroidJavaObject _pluginInstance;
- public static AndroidJavaClass PluginClass
- {
- get
- {
- if (_pluginClass == null)
- {
- _pluginClass = new AndroidJavaClass(pluginName);
- }
- return _pluginClass;
- }
- }
- public static AndroidJavaObject PluginInstance
- {
- get
- {
- if (_pluginInstance == null)
- {
- _pluginInstance = PluginClass.CallStatic<AndroidJavaObject>("getInstance");
- }
- return _pluginInstance;
- }
- }
- private void Start()
- {
- Debug.LogFormat("Start");
- Debug.LogFormat("{0}", PluginClass);
- Debug.LogFormat("{1}", PluginInstance);
- //Debug.LogFormat("Start {0}", GetElapsedTime());
- }
- float elapsedTime = 0;
- private void Update()
- {
- elapsedTime += Time.deltaTime;
- if (elapsedTime >= 5)
- {
- elapsedTime -= 5;
- Debug.LogFormat("Tick {0}", GetElapsedTime());
- }
- }
- double GetElapsedTime()
- {
- if (Application.platform == RuntimePlatform.Android)
- {
- return PluginInstance.Call<double>("getElapsedTime");
- }
- Debug.LogWarning("Wrong platform!");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement