AndroidPluginBase.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using SC;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SC.Tools
  6. {
  7. public abstract class AndroidPluginBase:PersonSystemBase
  8. {
  9. protected static AndroidJavaObject CurrentActivity;
  10. protected static AndroidJavaClass UnityPlayerClass;
  11. protected List<AndroidCallBackBase> androidCallbackList = new List<AndroidCallBackBase>();
  12. static AndroidPluginBase() {
  13. #if UNITY_ANDROID && !UNITY_EDITOR
  14. UnityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  15. CurrentActivity = UnityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
  16. #endif
  17. }
  18. public virtual void addListener(string listenerName, AndroidCallBackBase listener){
  19. #if UNITY_ANDROID && !UNITY_EDITOR
  20. CurrentActivity.Call (listenerName , listener);
  21. androidCallbackList.Add(listener);
  22. #endif
  23. }
  24. public override void Awake() {
  25. base.Awake();
  26. foreach (var item in androidCallbackList) {
  27. item.OnAwake();
  28. }
  29. }
  30. public override void OnEnable() {
  31. base.OnEnable();
  32. foreach (var item in androidCallbackList) {
  33. item.OnEnable();
  34. }
  35. }
  36. public override void Start() {
  37. base.Start();
  38. foreach (var item in androidCallbackList) {
  39. item.OnStart();
  40. }
  41. }
  42. public override void Update() {
  43. base.Update();
  44. foreach (var item in androidCallbackList) {
  45. item.OnUpdate();
  46. }
  47. }
  48. public override void OnDisable() {
  49. base.OnDisable();
  50. foreach (var item in androidCallbackList) {
  51. item.OnDisable();
  52. }
  53. }
  54. public override void OnDestroy() {
  55. base.OnDestroy();
  56. foreach (var item in androidCallbackList) {
  57. item.OnDestroy();
  58. }
  59. }
  60. }
  61. }