1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using SC;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace SC.Tools
- {
- public abstract class AndroidPluginBase:PersonSystemBase
- {
- protected static AndroidJavaObject CurrentActivity;
- protected static AndroidJavaClass UnityPlayerClass;
- protected List<AndroidCallBackBase> androidCallbackList = new List<AndroidCallBackBase>();
- static AndroidPluginBase() {
- #if UNITY_ANDROID && !UNITY_EDITOR
- UnityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- CurrentActivity = UnityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
- #endif
- }
- public virtual void addListener(string listenerName, AndroidCallBackBase listener){
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call (listenerName , listener);
- androidCallbackList.Add(listener);
- #endif
- }
- public override void Awake() {
- base.Awake();
- foreach (var item in androidCallbackList) {
- item.OnAwake();
- }
- }
- public override void OnEnable() {
- base.OnEnable();
- foreach (var item in androidCallbackList) {
- item.OnEnable();
- }
- }
- public override void Start() {
- base.Start();
- foreach (var item in androidCallbackList) {
- item.OnStart();
- }
- }
- public override void Update() {
- base.Update();
- foreach (var item in androidCallbackList) {
- item.OnUpdate();
- }
- }
- public override void OnDisable() {
- base.OnDisable();
- foreach (var item in androidCallbackList) {
- item.OnDisable();
- }
- }
- public override void OnDestroy() {
- base.OnDestroy();
- foreach (var item in androidCallbackList) {
- item.OnDestroy();
- }
- }
- }
- }
|