109 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			109 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System.Collections.Generic; | |||
|  | 
 | |||
|  | namespace EFSDK | |||
|  | { | |||
|  |     using UnityEngine; | |||
|  | 
 | |||
|  |     public class EFSdkAndroid : MonoBehaviour | |||
|  |     { | |||
|  |         private string COIN_CLICK = "coin_click"; | |||
|  |         private string BALLOON_CLICK = "balloon_click"; | |||
|  |         private string Coin_Show = "Coin_Show"; | |||
|  |         private string Box_Show = "Box_Show"; | |||
|  |         private string Gam_Load_Succ = "Gam_Load_Succ"; | |||
|  |         private string On_Resume = "onResume"; | |||
|  |         private string Can_Goback = "canGoback"; | |||
|  | 
 | |||
|  |         public void OnReceiverAnd(string message) | |||
|  |         { | |||
|  |             WLoom.QueueOnMainThread(_ => | |||
|  |             { | |||
|  |                 Debug.Log("Received message from Android: " + message); | |||
|  |                 if (message.Contains(On_Resume)) | |||
|  |                 { | |||
|  |                     EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.ON_RESUME, message); | |||
|  |                 } | |||
|  |                 if (message.Contains(Can_Goback)) | |||
|  |                 { | |||
|  |                     EFSdk.get().mCanGobackAction?.Invoke(bool.Parse(message.Split('#')[1])); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (BALLOON_CLICK.Equals(message)) | |||
|  |                 { | |||
|  |                     //点击气球 | |||
|  |                     EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.BALLOON_CLICK, message); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (Coin_Show.Equals(message)) | |||
|  |                 { | |||
|  |                     //金币展示出来了 | |||
|  |                     EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.COIN_SHOW, message); | |||
|  |                 } | |||
|  |                 if (COIN_CLICK.Equals(message)) | |||
|  |                 { | |||
|  |                     //金币点击 | |||
|  |                     EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.COIN_CLICK, message); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (Box_Show.Equals(message)) | |||
|  |                 { | |||
|  |                     //宝箱展示出来了 | |||
|  |                     EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.BOX_SHOW, message); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (message.Contains(Gam_Load_Succ)) | |||
|  |                 { | |||
|  |                     //GAM页面加载成功 Gam_Load_Succ@id | |||
|  |                     string[] parts = message.Split('@'); | |||
|  |                     EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.GAM_LOAD_SUCC, parts[1]); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (message.StartsWith("reqNotifyPermission#")) | |||
|  |                 { | |||
|  |                     string[] flag = message.Split('#'); | |||
|  |                     EFSdk.get().mReqNotifyPermissionAction?.Invoke(flag[1].Equals("1")); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (message.StartsWith("Event#")) | |||
|  |                 { | |||
|  |                     string[] eventKeys = message.Split('#'); | |||
|  |                     if (eventKeys.Length > 0) | |||
|  |                     { | |||
|  |                         if (message.Contains("hd_h5_impression")) | |||
|  |                         { | |||
|  |                             //互动广告展示 | |||
|  |                             string url = eventKeys[2]; | |||
|  |                             EFSdk.get().HdH5ImpressionAction?.Invoke(url); | |||
|  |                         } | |||
|  |                         else if (eventKeys.Length == 2) | |||
|  |                         { | |||
|  |                             // 只有一个事件key | |||
|  |                             string eventKey = eventKeys[1]; | |||
|  |                             EFSdk.get().ActionSDKEventCallback?.Invoke(eventKey, null); | |||
|  |                         } | |||
|  |                         else if (eventKeys.Length == 3) | |||
|  |                         { | |||
|  |                             // key-value事件 | |||
|  |                             string eventKey = eventKeys[1]; | |||
|  |                             string value = eventKeys[2]; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             //多属性事件 | |||
|  |                             string eventKey = eventKeys[1]; | |||
|  |                             Dictionary<string, string> attrs = new Dictionary<string, string>(); | |||
|  |                             for (int i = 2; i < eventKeys.Length - 1; i += 2) | |||
|  |                             { | |||
|  |                                 string key = eventKeys[i]; | |||
|  |                                 string value = eventKeys[i + 1]; | |||
|  |                                 attrs[key] = value; | |||
|  |                             } | |||
|  | 
 | |||
|  |                             EFSdk.get().ActionSDKEventCallback?.Invoke(eventKey, attrs); | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             }, ""); | |||
|  |         } | |||
|  |     } | |||
|  | } |