[WIP] firebase init Error

This commit is contained in:
2024-08-02 20:09:59 +08:00
commit b77fd9f498
7087 changed files with 1466846 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using UnityEngine;
using System.Runtime.InteropServices;
namespace tysdk
{
public static class AppRequestReview
{
#if UNITY_EDITOR || UNITY_ANDROID
public static void RequestReview(string customReviewURL)
{
Debug.Log("RequestReview is not supported on this platform");
}
#elif UNITY_IOS
[DllImport("__Internal")]
public static extern void RequestReview(string customReviewURL);
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b4630fc5c78457748a2f763ac5168df6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,327 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using asap.core;
using Newtonsoft.Json.Linq;
using UnityEngine;
namespace tysdk
{
public class TYSdkFacade : MonoBehaviour
{
public class AccountInfo
{
public int userId;
public string token;
public string jwtToken;
public string strUserId => userId.ToString();
public bool IDVerified;
}
private static AccountInfo _accountInfo;
public AccountInfo TYAccountInfo => _accountInfo;
private static IDictionary<string, Action<ITYSdkCallback>> callbacks = new Dictionary<string, Action<ITYSdkCallback>>();
private static TYSdkFacade _instance;
public static TYSdkFacade Instance
{
get
{
if (_instance == null)
{
_instance = new GameObject("TYSdkFacade").AddComponent<TYSdkFacade>();
DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
/*================================================
_ _
/ \ ___ ___ ___ _ _ _ __ | |_
/ _ \ / __/ __/ _ \| | | | '_ \| __|
/ ___ \ (_| (_| (_) | |_| | | | | |_
/_/ \_\___\___\___/ \__,_|_| |_|\__|
=================================================*/
public bool IsLoggedIn => _accountInfo != null;
public void LogOut()
{
UnityBridgeFunc.UnityLoginOut();
_accountInfo = null;
}
public void logOutByChannel()
{
UnityBridgeFunc.UnityLoginOut();
_accountInfo = null;
}
public async Task<LoginInfo> Login(EAccoutType accoutType)
{
#if UNITY_EDITOR
await Task.Yield();
var deviceId = UnityEngine.Device.SystemInfo.deviceUniqueIdentifier.Split('-')[0].Substring(0,8);
var userId = (int)ulong.Parse(deviceId, System.Globalization.NumberStyles.HexNumber);
_accountInfo = new AccountInfo()
{
userId = userId,
};
return new LoginInfo()
{
isSuccess = true,
userId = userId
};
#elif UNITY_ANDROID || UNITY_IOS
var taskSource = new TaskCompletionSource<LoginInfo>();
callbacks.Add("LoginResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((LoginInfo)callback);
});
UnityBridgeFunc.UnityLogin(accoutType);
return await taskSource.Task;
#endif
}
public void LoginResult(string json)
{
Debug.Log("[TYSdkFacade] Login callback:");
var result = new LoginInfo();
var data = JObject.Parse(json);
var code = (int)data["code"];
result.code = code;
if (code == 0)
{
var loginData = data["respObj"]["result"];
_accountInfo = new AccountInfo()
{
userId = (int)loginData["userId"],
token = (string)loginData["token"],
jwtToken = (string)loginData["jwttoken"],
};
result.isSuccess = true;
result.userId = _accountInfo.userId;
SetUserInfo();
}
if (callbacks.TryGetValue("LoginResult", out var action))
{
action.Invoke(result);
callbacks.Remove("LoginResult");
}
}
private void SetUserInfo()
{
if (_accountInfo == null) return;
var strUserId = _accountInfo.strUserId;
UnityBridgeFunc.SetGaUserInfo(strUserId);
UnityBridgeFunc.UnitySetAdBoxUserInfo(strUserId);
UnityBridgeFunc.UnityInitADSConfig();
}
/*================================================
_____ _ _____ _
| ____|_ _____ _ __ | |_ |_ _| __ __ _ ___| | __
| _| \ \ / / _ \ '_ \| __| | || '__/ _` |/ __| |/ /
| |___ \ V / __/ | | | |_ | || | | (_| | (__| <
|_____| \_/ \___|_| |_|\__| |_||_| \__,_|\___|_|\_\
=================================================*/
public void EventTrack(int type, string name, string content)
{
#if UNITY_IOS || UNITY_ANDROID
UnityBridgeFunc.GAReportParams(type, name, content);
#endif
}
/*================================================
____ _
| _ \ __ _ _ _ _ __ ___ ___ _ __ | |_
| |_) / _` | | | | '_ ` _ \ / _ \ '_ \| __|
| __/ (_| | |_| | | | | | | __/ | | | |_
|_| \__,_|\__, |_| |_| |_|\___|_| |_|\__|
|___/
=================================================*/
//TODO
public async Task<PaymentInfo> Pay(string prodId, string prodPrice, string prodName, int count, string orderId, string extraInfo)
{
if (!IsLoggedIn) return new PaymentInfo() { code = "-1", msg = "未登录" };
#if UNITY_EDITOR
await Task.Yield();
var result = new PaymentInfo()
{
code = "0",
msg = "success",
count = count,
orderId = orderId,
productId = prodId,
price = prodPrice
};
return result;
#elif UNITY_ANDROID
var taskSource = new TaskCompletionSource<PaymentInfo>();
callbacks.Add("PayResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((PaymentInfo)callback);
});
UnityBridgeFunc.UnityKnow(_accountInfo.strUserId, prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo);
var result = await taskSource.Task;
result.count = count;
result.orderId = orderId;
result.productId = prodId;
result.price = prodPrice;
return result;
#elif UNITY_IOS
var taskSource = new TaskCompletionSource<PaymentInfo>();
callbacks.Add("PayResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((PaymentInfo)callback);
});
UnityBridgeFunc.UnityKnow(_accountInfo.strUserId, prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo);
var result = await taskSource.Task;
result.count = count;
result.orderId = orderId;
result.productId = prodId;
result.price = prodPrice;
return result;
#endif
}
//支付的回调
public void PayResult(string json)
{
Debug.Log("[TYSdkFacade] pay callback:");
var jresult = JObject.Parse(json);
var result = new PaymentInfo();
result.code = jresult["code"].ToString();
result.msg = jresult["errStr"].ToString();
if (callbacks.TryGetValue("PayResult", out var action))
{
action.Invoke(result);
callbacks.Remove("PayResult");
}
}
/*================================================
_ _____ _____
/ \|_ _|_ _|
/ _ \ | | | |
/ ___ \| | | |
/_/ \_\_| |_|
=================================================*/
public bool IsAttAccepted()
{
return UnityBridgeFunc.GetATT() == 1;
}
public async Task<ATTInfo> RequestATT()
{
#if UNITY_EDITOR || UNITY_ANDROID
await Task.Yield();
return new ATTInfo(){isAccepted = true};
#elif UNITY_IOS
var taskSource = new TaskCompletionSource<ATTInfo>();
callbacks.Add("RequestATT", (ITYSdkCallback callback) =>
{
taskSource.SetResult((ATTInfo)callback);
});
UnityBridgeFunc.RequestATT();
return await taskSource.Task;
#endif
}
public void RequestATTResult(string r)
{
if (callbacks.TryGetValue("RequestATT", out var action))
{
action.Invoke(new ATTInfo(){isAccepted = r == "1"});
callbacks.Remove("RequestATT");
}
}
/*================================================
_ ____
/ \ | _ \
/ _ \ | | | |
/ ___ \| |_| |
/_/ \_\____/
=================================================*/
public void InitAdCallback(string jstr)
{
try{
var jobj = JObject.Parse(jstr);
if(jobj["code"].ToString() == "0")
UnityEngine.Debug.Log($"[TYSdkFacade] InitAdCallback Success");
else
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback Failed ");
}
catch(Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback error: {e.Message}");
}
}
public void LoadAdCallback(string jstr)
{
try
{
var adLoadinfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ADLoadInfo>(jstr);
GContext.Publish(adLoadinfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] LoadAdCallback error: {e.Message}");
}
}
public void ShowAdCallback(string jstr)
{
try
{
var adShowInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ShowADInfo>(jstr);
GContext.Publish(adShowInfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] ShowAdCallback error: {e.Message}");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: db12db58fbcc54046aa4dac203cd4971
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
namespace tysdk
{
public interface ITYSdkCallback { }
public class LoginInfo : ITYSdkCallback
{
public bool isSuccess;
public int userId;
public string StrUserId => userId.ToString();
public string msg;
public int code;
}
public class PaymentInfo : ITYSdkCallback
{
public bool isSuccess => code == "0";
public int count;
public string orderId;
public string productId;
public string price;
public string code;
public string msg;
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
}
public class ATTInfo : ITYSdkCallback
{
public bool isAccepted;
}
public class ADLoadInfo
{
public bool isSuccess => code == "0";
public string code;
public string errStr;
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
}
public enum EShowAdState : byte
{
StartShow = 1,
Reward = 2,
Loading = 3,
LoadFaild = 4,
ShowFaild = 5,
Closed = 6,
Finished = 7,
TimeOut = 8
}
public class ShowADInfo
{
public string code;
public string message;
public string reward;
public EShowAdState state => (EShowAdState)int.Parse(code);
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b94c8e87cc23b4053a4cbf592ff14db3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,238 @@
using System.Runtime.InteropServices;
namespace tysdk
{
public enum EAccoutType
{
hwGoogle,
hwFacebook,
hwGuest,
}
public static class UnityBridgeFunc
{
#if UNITY_EDITOR
//更新登录支付域名
public static void UnityResetServerUrl(string url){}
//登录
public static void UnityLoginByTokenFun(string token){}
public static void UnityLogin(EAccoutType accoutType){}
public static void UnityGetIdentityFun(string type){}
public static void UnityLoginOut(){}
//支付
public static void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo){}
//打点
public static void SetGaUserInfo(string userId){}
public static void SetGaCommonInfo(string SetGaCommonInfo){}
public static void GAReportParams(int type, string eventstr, string paramstr){}
//ATT
public static void RequestATT(){}
public static int GetATT() {return 1;}
//广告相关
public static void UnitySetAdBoxUserInfo(string userId){}
public static void UnityInitADSConfig(){}
public static void UnityLoadRvADS(){}
public static void UnityShowRVAD(){}
#elif UNITY_ANDROID
private static string SDK_CLASS = "com.unity3d.player.SDKManager";
//更新登录支付域名
public static void UnityResetServerUrl(string url)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityResetServerUrl", url);
}
}
//登录
public static void UnityLoginByTokenFun(string token)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLoginByTokenFun", token);
}
}
public static void UnityLogin(EAccoutType accoutType)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLogin", accoutType);
}
}
public static void UnityGetIdentityFun(string type)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityGetIdentityFun", type);
}
}
public static void UnityLoginOut()
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLoginOut");
}
}
public static void UnityLogOutByChannel()
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
if(PlayerPrefs.HasKey("last_login_channel"))
{
sdkManager.CallStatic("UnityLogOutByChannel", PlayerPrefs.GetString("last_login_channel"));
}
}
}
//支付
public static void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityKnow",userId, productId, productPrice, productName,
productCount, prodorderId, appInfo);
}
}
//打点
public static void SetGaUserInfo(string userId)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("SetGaUserInfo", userId);
}
}
public static void SetGaCommonInfo(string SetGaCommonInfo)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("SetGaCommonInfo", SetGaCommonInfo);
}
}
public static void GAReportParams(int type, string eventstr, string paramstr)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("GAReportParams", type, eventstr, paramstr);
}
}
//ATT
public static void RequestATT(){}
public static int GetATT() {return 1;}
//广告相关
public static void UnitySetAdBoxUserInfo(string userId){}
public static void UnityInitADSConfig(){}
public static void UnityLoadRvADS(){}
public static void UnityShowRVAD(){}
#elif UNITY_IOS
//更新登录支付域名
[DllImport("__Internal")]
public static extern void UnityResetServerUrl(string url);
//登录
[DllImport("__Internal")]
public static extern void UnityLoginByTokenFun(string token);
public static void UnityLogin(EAccoutType accoutType)
{
switch (accoutType)
{
case EAccoutType.hwGoogle:
UnityLoginByGoogle();
break;
case EAccoutType.hwFacebook:
UnityLoginByFacebook();
break;
case EAccoutType.hwGuest:
UnityLoginByGuest();
break;
}
}
[DllImport("__Internal")]
public static extern void UnityLoginByGuest();
[DllImport("__Internal")]
public static extern void UnityLoginByGoogle();
[DllImport("__Internal")]
public static extern void UnityLoginByFacebook();
[DllImport("__Internal")]
public static extern void UnityGetIdentityFun(string type);
[DllImport("__Internal")]
public static extern void UnityLoginOut();
//支付
[DllImport("__Internal")]
public static extern void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo);
//打点
[DllImport("__Internal")]
public static extern void SetGaUserInfo(string userId);
[DllImport("__Internal")]
public static extern void SetGaCommonInfo(string SetGaCommonInfo);
[DllImport("__Internal")]
public static extern void GAReportParams(int type, string eventstr, string paramstr);
//广告相关
[DllImport("__Internal")]
public static extern void UnitySetAdBoxUserInfo(string userId);
[DllImport("__Internal")]
public static extern void UnityInitADSConfig();
[DllImport("__Internal")]
public static extern void UnityLoadRvADS();
[DllImport("__Internal")]
public static extern void UnityShowRVAD();
//ATT
[DllImport("__Internal")]
public static extern void RequestATT();
[DllImport("__Internal")]
public static extern int GetATT();
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 16335dd05906d48bf81e297920aecf31
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
{
"name": "tysdk",
"rootNamespace": "tysdk",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"asap.core.dll",
"Newtonsoft.Json.dll"
],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b208fff54a2d840269b62e6585c0b390
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: