Pārlūkot izejas kodu

sdk接入

master
LuanShi pirms 2 mēnešiem
vecāks
revīzija
aae1a5870f
20 mainītis faili ar 1910 papildinājumiem un 145 dzēšanām
  1. Binārs
      Assets/Image/dly_btn_sjdl.png
  2. +110
    -0
      Assets/Image/dly_btn_sjdl.png.meta
  3. Binārs
      Assets/Image/dly_btn_wxdl.png
  4. +110
    -0
      Assets/Image/dly_btn_wxdl.png.meta
  5. +8
    -0
      Assets/Plugins/SDK.meta
  6. +41
    -0
      Assets/Plugins/SDK/AndroidImpl.cs
  7. +1
    -1
      Assets/Plugins/SDK/AndroidImpl.cs.meta
  8. +92
    -0
      Assets/Plugins/SDK/CommSDK.cs
  9. +12
    -0
      Assets/Plugins/SDK/CommSDK.cs.meta
  10. +22
    -0
      Assets/Plugins/SDK/CommSDKImpl.cs
  11. +11
    -0
      Assets/Plugins/SDK/CommSDKImpl.cs.meta
  12. +67
    -0
      Assets/Plugins/SDK/EnumState.cs
  13. +12
    -0
      Assets/Plugins/SDK/EnumState.cs.meta
  14. +745
    -0
      Assets/Plugins/SDK/MiniJSON.cs
  15. +12
    -0
      Assets/Plugins/SDK/MiniJSON.cs.meta
  16. +101
    -0
      Assets/Plugins/SDK/NativeBridgeUtil.cs
  17. +11
    -0
      Assets/Plugins/SDK/NativeBridgeUtil.cs.meta
  18. +441
    -2
      Assets/Scenes/Init.unity
  19. +114
    -94
      Assets/Scripts/LoginAndPay/LoginView.cs
  20. +0
    -48
      Assets/WeChatLogin.cs

Binārs
Assets/Image/dly_btn_sjdl.png Parādīt failu

Pirms Pēc
Platums: 327  |  Augstums: 109  |  Izmērs: 42 KiB

+ 110
- 0
Assets/Image/dly_btn_sjdl.png.meta Parādīt failu

@@ -0,0 +1,110 @@
fileFormatVersion: 2
guid: 27f253e451b91484b9dddd97028c0699
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binārs
Assets/Image/dly_btn_wxdl.png Parādīt failu

Pirms Pēc
Platums: 327  |  Augstums: 109  |  Izmērs: 40 KiB

+ 110
- 0
Assets/Image/dly_btn_wxdl.png.meta Parādīt failu

@@ -0,0 +1,110 @@
fileFormatVersion: 2
guid: b712e65990021194795e721125b0ad46
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

+ 8
- 0
Assets/Plugins/SDK.meta Parādīt failu

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 82c5dbbc9224d6a48a69171dfbe330bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 41
- 0
Assets/Plugins/SDK/AndroidImpl.cs Parādīt failu

@@ -0,0 +1,41 @@
using UnityEngine;
using System.Collections;
using System;
namespace ETModel
{
namespace com.commsdk.unity3d
{
public class AndroidImpl : CommSDKImpl
{
private AndroidJavaObject currActivity;
public AndroidImpl(string callbackObj, string callbackMethod)
{
currActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
InitSDK(callbackObj, callbackMethod);
}
private string WxAppId = "wxe3784691d154266f";
private string WxAppSecret = "e11c9277651822d48a00425d4ffc08e2";
public override void InitSDK(string callbackObj, string callbackMethod)
{
if (currActivity != null)
{
currActivity.Call("initSdk", callbackObj, callbackMethod, WxAppId, WxAppSecret);
}
}
/// <summary>
/// Authorize the specified platform.
/// </summary>
public override void Authorize(int type, int reqID)
{
if (currActivity != null)
{
currActivity.Call("authorize", type, reqID);
}
}
}
}
}

Assets/WeChatLogin.cs.meta → Assets/Plugins/SDK/AndroidImpl.cs.meta Parādīt failu

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ae686ed626ce4f844bd3b8a007577ae7
guid: 7aa1e0ac5ca98644d896e65604559a3f
MonoImporter:
externalObjects: {}
serializedVersion: 2

+ 92
- 0
Assets/Plugins/SDK/CommSDK.cs Parādīt failu

@@ -0,0 +1,92 @@
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Reflection;
using ETModel.com.commsdk.unity3d;
using ETModel;
namespace ETHotfix
{
namespace com.commsdk.unity3d
{
/// <summary>
///公用的原生sdk
/// </summary>
public class CommSDKComponent : MonoBehaviour
{
private int WeReqID;
private CommSDKImpl commSdkUtils;
public EventWechatHandler responseHandler;
public void Init()
{
if (Application.platform == RuntimePlatform.Android)
{
Debug.Log("GameObject.name = " + gameObject.name);
commSdkUtils = new AndroidImpl(gameObject.name, "_Callback");
}
}
/// <summary>
/// callback the specified data.
/// </summary>
/// <param name='data'>
/// Data.
/// </param>
private void _Callback(string data)
{
if (data == null)
{
Debug.Log("OnWechatLogin DataIsNull" + data + "DataIsNull Data");
return;
}
Hashtable res = (Hashtable)MiniJSON.jsonDecode(data);
if (res == null || res.Count <= 0)
{
Debug.Log("OnWechatLogin ResIsNull" + data + "ResIsNull Data");
return;
}
int status = Convert.ToInt32(res["status"]);
int reqID = Convert.ToInt32(res["reqID"]);
int action = Convert.ToInt32(res["action"]);
Hashtable resp = null;
switch ((RespState)status)
{
case RespState.Success:
case RespState.Fail:
resp = (Hashtable)res["res"];
break;
case RespState.Cancel:
break;
}
if (resp == null)
{
Debug.Log("OnWechatLogin RespIsNull" + data + "RespIsNull");
}
if (null != responseHandler)
{
responseHandler(reqID, (ActionType)action, (RespState)status, resp);
}
}
public int Authorize(int type)
{
WeReqID++;
commSdkUtils.Authorize(type, WeReqID);
return WeReqID;
}
/// <summary>
/// Event result listener.
/// </summary>
public delegate void EventWechatHandler(int reqID, ActionType type, RespState state, Hashtable data);
}
}
}

+ 12
- 0
Assets/Plugins/SDK/CommSDK.cs.meta Parādīt failu

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 359fd104cc365a345847d9b6c9bf8d75
timeCreated: 1485338619
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 22
- 0
Assets/Plugins/SDK/CommSDKImpl.cs Parādīt failu

@@ -0,0 +1,22 @@
using UnityEngine;
using System.Collections;
namespace ETModel
{
namespace com.commsdk.unity3d
{
public abstract class CommSDKImpl
{
public abstract void InitSDK(string objName, string methodName);
/// <summary>
/// Authorize the specified platform.
/// </summary>
public abstract void Authorize(int type, int reqID);
}
}
}

+ 11
- 0
Assets/Plugins/SDK/CommSDKImpl.cs.meta Parādīt failu

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

+ 67
- 0
Assets/Plugins/SDK/EnumState.cs Parādīt failu

@@ -0,0 +1,67 @@
using UnityEngine;
using System.Collections;
namespace ETHotfix
{
namespace com.commsdk.unity3d
{
/// <summary>
/// Response state.
/// </summary>
public enum RespState
{
Begin = 0, //Begin
Success = 1, //Success
Fail = 2, //Failure
Cancel = 3 //Cancel
}
/// <summary>
/// action type
/// </summary>
public enum ActionType
{
Begin = 0,
Authorize = 1, //授权
Share = 2, //分享
Pay = 3, //支付
Location = 4, // 定位返回
XianLiaoAuthorize = 5, //闲聊授权
DuoLiaoAuthorize = 6 //多聊授权
}
public enum PlatformType
{
WeChat = 0, //微信好友
WeChatMoments = 1, //微信朋友圈
XlChat = 2, //闲聊
DuoLiao = 3, //多聊
MoWang = 4 //默往
}
/// <summary>
/// Content type.
/// </summary>
public enum ContentType
{
Auto = 0, //自动(iOS为自动,安卓仅为Text)
Text = 1, //文字分享
Image = 2, //图文分享
Webpage = 4, //链接分享
Music = 5, //音乐分享
Video = 6, //视频分享
App = 7, //应用分享
File = 8, //附件分享
Emoji = 9, //表情分享
LINK = 10 //闲聊链接分享
}
}
}

+ 12
- 0
Assets/Plugins/SDK/EnumState.cs.meta Parādīt failu

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8ffdaed2b28fc2348988d036464d68b1
timeCreated: 1485338619
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 745
- 0
Assets/Plugins/SDK/MiniJSON.cs Parādīt failu

@@ -0,0 +1,745 @@
using System;
using System.Collections;
using System.Text;
using System.Collections.Generic;
namespace ETModel
{
/* Based on the JSON parser from
* http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
*
* I simplified it so that it doesn't throw exceptions
* and can be used in Unity iPhone with maximum code stripping.
*/
/// <summary>
/// This class encodes and decodes JSON strings.
/// Spec. details, see http://www.json.org/
///
/// JSON uses Arrays and Objects. These correspond here to the datatypes ArrayList and Hashtable.
/// All numbers are parsed to doubles.
/// </summary>
public class MiniJSON
{
private const int TOKEN_NONE = 0;
private const int TOKEN_CURLY_OPEN = 1;
private const int TOKEN_CURLY_CLOSE = 2;
private const int TOKEN_SQUARED_OPEN = 3;
private const int TOKEN_SQUARED_CLOSE = 4;
private const int TOKEN_COLON = 5;
private const int TOKEN_COMMA = 6;
private const int TOKEN_STRING = 7;
private const int TOKEN_NUMBER = 8;
private const int TOKEN_TRUE = 9;
private const int TOKEN_FALSE = 10;
private const int TOKEN_NULL = 11;
private const int BUILDER_CAPACITY = 2000;
/// <summary>
/// On decoding, this value holds the position at which the parse failed (-1 = no error).
/// </summary>
protected static int lastErrorIndex = -1;
protected static string lastDecode = "";
/// <summary>
/// Parses the string json into a value
/// </summary>
/// <param name="json">A JSON string.</param>
/// <returns>An ArrayList, a Hashtable, a double, a string, null, true, or false</returns>
public static object jsonDecode(string json)
{
// save the string for debug information
MiniJSON.lastDecode = json;
if (json != null)
{
char[] charArray = json.ToCharArray();
int index = 0;
bool success = true;
object value = MiniJSON.parseValue(charArray, ref index, ref success);
if (success)
MiniJSON.lastErrorIndex = -1;
else
MiniJSON.lastErrorIndex = index;
return value;
}
else
{
return null;
}
}
/// <summary>
/// Converts a Hashtable / ArrayList / Dictionary(string,string) object into a JSON string
/// </summary>
/// <param name="json">A Hashtable / ArrayList</param>
/// <returns>A JSON encoded string, or null if object 'json' is not serializable</returns>
public static string jsonEncode(object json)
{
var builder = new StringBuilder(BUILDER_CAPACITY);
var success = MiniJSON.serializeValue(json, builder);
return (success ? builder.ToString() : null);
}
/// <summary>
/// On decoding, this function returns the position at which the parse failed (-1 = no error).
/// </summary>
/// <returns></returns>
public static bool lastDecodeSuccessful()
{
return (MiniJSON.lastErrorIndex == -1);
}
/// <summary>
/// On decoding, this function returns the position at which the parse failed (-1 = no error).
/// </summary>
/// <returns></returns>
public static int getLastErrorIndex()
{
return MiniJSON.lastErrorIndex;
}
/// <summary>
/// If a decoding error occurred, this function returns a piece of the JSON string
/// at which the error took place. To ease debugging.
/// </summary>
/// <returns></returns>
public static string getLastErrorSnippet()
{
if (MiniJSON.lastErrorIndex == -1)
{
return "";
}
else
{
int startIndex = MiniJSON.lastErrorIndex - 5;
int endIndex = MiniJSON.lastErrorIndex + 15;
if (startIndex < 0)
startIndex = 0;
if (endIndex >= MiniJSON.lastDecode.Length)
endIndex = MiniJSON.lastDecode.Length - 1;
return MiniJSON.lastDecode.Substring(startIndex, endIndex - startIndex + 1);
}
}
#region Parsing
protected static Hashtable parseObject(char[] json, ref int index)
{
Hashtable table = new Hashtable();
int token;
// {
nextToken(json, ref index);
bool done = false;
while (!done)
{
token = lookAhead(json, index);
if (token == MiniJSON.TOKEN_NONE)
{
return null;
}
else if (token == MiniJSON.TOKEN_COMMA)
{
nextToken(json, ref index);
}
else if (token == MiniJSON.TOKEN_CURLY_CLOSE)
{
nextToken(json, ref index);
return table;
}
else
{
// name
string name = parseString(json, ref index);
if (name == null)
{
return null;
}
// :
token = nextToken(json, ref index);
if (token != MiniJSON.TOKEN_COLON)
return null;
// value
bool success = true;
object value = parseValue(json, ref index, ref success);
if (!success)
return null;
table[name] = value;
}
}
return table;
}
protected static ArrayList parseArray(char[] json, ref int index)
{
ArrayList array = new ArrayList();
// [
nextToken(json, ref index);
bool done = false;
while (!done)
{
int token = lookAhead(json, index);
if (token == MiniJSON.TOKEN_NONE)
{
return null;
}
else if (token == MiniJSON.TOKEN_COMMA)
{
nextToken(json, ref index);
}
else if (token == MiniJSON.TOKEN_SQUARED_CLOSE)
{
nextToken(json, ref index);
break;
}
else
{
bool success = true;
object value = parseValue(json, ref index, ref success);
if (!success)
return null;
array.Add(value);
}
}
return array;
}
protected static object parseValue(char[] json, ref int index, ref bool success)
{
switch (lookAhead(json, index))
{
case MiniJSON.TOKEN_STRING:
return parseString(json, ref index);
case MiniJSON.TOKEN_NUMBER:
return parseNumber(json, ref index);
case MiniJSON.TOKEN_CURLY_OPEN:
return parseObject(json, ref index);
case MiniJSON.TOKEN_SQUARED_OPEN:
return parseArray(json, ref index);
case MiniJSON.TOKEN_TRUE:
nextToken(json, ref index);
return Boolean.Parse("TRUE");
case MiniJSON.TOKEN_FALSE:
nextToken(json, ref index);
return Boolean.Parse("FALSE");
case MiniJSON.TOKEN_NULL:
nextToken(json, ref index);
return null;
case MiniJSON.TOKEN_NONE:
break;
}
success = false;
return null;
}
protected static string parseString(char[] json, ref int index)
{
string s = "";
char c;
eatWhitespace(json, ref index);
// "
c = json[index++];
bool complete = false;
while (!complete)
{
if (index == json.Length)
break;
c = json[index++];
if (c == '"')
{
complete = true;
break;
}
else if (c == '\\')
{
if (index == json.Length)
break;
c = json[index++];
if (c == '"')
{
s += '"';
}
else if (c == '\\')
{
s += '\\';
}
else if (c == '/')
{
s += '/';
}
else if (c == 'b')
{
s += '\b';
}
else if (c == 'f')
{
s += '\f';
}
else if (c == 'n')
{
s += '\n';
}
else if (c == 'r')
{
s += '\r';
}
else if (c == 't')
{
s += '\t';
}
else if (c == 'u')
{
int remainingLength = json.Length - index;
if (remainingLength >= 4)
{
char[] unicodeCharArray = new char[4];
Array.Copy(json, index, unicodeCharArray, 0, 4);
uint codePoint = UInt32.Parse(new string(unicodeCharArray), System.Globalization.NumberStyles.HexNumber);
// convert the integer codepoint to a unicode char and add to string
s += Char.ConvertFromUtf32((int)codePoint);
// skip 4 chars
index += 4;
}
else
{
break;
}
}
}
else
{
s += c;
}
}
if (!complete)
return null;
return s;
}
protected static double parseNumber(char[] json, ref int index)
{
eatWhitespace(json, ref index);
int lastIndex = getLastIndexOfNumber(json, index);
int charLength = (lastIndex - index) + 1;
char[] numberCharArray = new char[charLength];
Array.Copy(json, index, numberCharArray, 0, charLength);
index = lastIndex + 1;
return Double.Parse(new string(numberCharArray)); // , CultureInfo.InvariantCulture);
}
protected static int getLastIndexOfNumber(char[] json, int index)
{
int lastIndex;
for (lastIndex = index; lastIndex < json.Length; lastIndex++)
if ("0123456789+-.eE".IndexOf(json[lastIndex]) == -1)
{
break;
}
return lastIndex - 1;
}
protected static void eatWhitespace(char[] json, ref int index)
{
for (; index < json.Length; index++)
if (" \t\n\r".IndexOf(json[index]) == -1)
{
break;
}
}
protected static int lookAhead(char[] json, int index)
{
int saveIndex = index;
return nextToken(json, ref saveIndex);
}
protected static int nextToken(char[] json, ref int index)
{
eatWhitespace(json, ref index);
if (index == json.Length)
{
return MiniJSON.TOKEN_NONE;
}
char c = json[index];
index++;
switch (c)
{
case '{':
return MiniJSON.TOKEN_CURLY_OPEN;
case '}':
return MiniJSON.TOKEN_CURLY_CLOSE;
case '[':
return MiniJSON.TOKEN_SQUARED_OPEN;
case ']':
return MiniJSON.TOKEN_SQUARED_CLOSE;
case ',':
return MiniJSON.TOKEN_COMMA;
case '"':
return MiniJSON.TOKEN_STRING;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
return MiniJSON.TOKEN_NUMBER;
case ':':
return MiniJSON.TOKEN_COLON;
}
index--;
int remainingLength = json.Length - index;
// false
if (remainingLength >= 5)
{
if (json[index] == 'f' &&
json[index + 1] == 'a' &&
json[index + 2] == 'l' &&
json[index + 3] == 's' &&
json[index + 4] == 'e')
{
index += 5;
return MiniJSON.TOKEN_FALSE;
}
}
// true
if (remainingLength >= 4)
{
if (json[index] == 't' &&
json[index + 1] == 'r' &&
json[index + 2] == 'u' &&
json[index + 3] == 'e')
{
index += 4;
return MiniJSON.TOKEN_TRUE;
}
}
// null
if (remainingLength >= 4)
{
if (json[index] == 'n' &&
json[index + 1] == 'u' &&
json[index + 2] == 'l' &&
json[index + 3] == 'l')
{
index += 4;
return MiniJSON.TOKEN_NULL;
}
}
return MiniJSON.TOKEN_NONE;
}
#endregion
#region Serialization
protected static bool serializeObjectOrArray(object objectOrArray, StringBuilder builder)
{
if (objectOrArray is Hashtable)
{
return serializeObject((Hashtable)objectOrArray, builder);
}
else if (objectOrArray is ArrayList)
{
return serializeArray((ArrayList)objectOrArray, builder);
}
else
{
return false;
}
}
protected static bool serializeObject(Hashtable anObject, StringBuilder builder)
{
builder.Append("{");
IDictionaryEnumerator e = anObject.GetEnumerator();
bool first = true;
while (e.MoveNext())
{
string key = e.Key.ToString();
object value = e.Value;
if (!first)
{
builder.Append(", ");
}
serializeString(key, builder);
builder.Append(":");
if (!serializeValue(value, builder))
{
return false;
}
first = false;
}
builder.Append("}");
return true;
}
protected static bool serializeDictionary(Dictionary<string, string> dict, StringBuilder builder)
{
builder.Append("{");
bool first = true;
foreach (var kv in dict)
{
if (!first)
builder.Append(", ");
serializeString(kv.Key, builder);
builder.Append(":");
serializeString(kv.Value, builder);
first = false;
}
builder.Append("}");
return true;
}
protected static bool serializeArray(ArrayList anArray, StringBuilder builder)
{
builder.Append("[");
bool first = true;
for (int i = 0; i < anArray.Count; i++)
{
object value = anArray[i];
if (!first)
{
builder.Append(", ");
}
if (!serializeValue(value, builder))
{
return false;
}
first = false;
}
builder.Append("]");
return true;
}
protected static bool serializeValue(object value, StringBuilder builder)
{
//Type t = value.GetType();
//UnityEngine.Debug.Log("type: " + t.ToString() + " isArray: " + t.IsArray);
if (value == null)
{
builder.Append("null");
}
else if (value.GetType().IsArray)
{
serializeArray(new ArrayList((ICollection)value), builder);
}
else if (value is string)
{
serializeString((string)value, builder);
}
else if (value is Char)
{
serializeString(Convert.ToString((char)value), builder);
}
else if (value is decimal)
{
serializeString(Convert.ToString((decimal)value), builder);
}
else if (value is Hashtable)
{
serializeObject((Hashtable)value, builder);
}
else if (value is Dictionary<string, string>)
{
serializeDictionary((Dictionary<string, string>)value, builder);
}
else if (value is ArrayList)
{
serializeArray((ArrayList)value, builder);
}
else if ((value is Boolean) && ((Boolean)value == true))
{
builder.Append("true");
}
else if ((value is Boolean) && ((Boolean)value == false))
{
builder.Append("false");
}
else if (value.GetType().IsPrimitive)
{
serializeNumber(Convert.ToDouble(value), builder);
}
else
{
return false;
}
return true;
}
protected static void serializeString(string aString, StringBuilder builder)
{
builder.Append("\"");
char[] charArray = aString.ToCharArray();
for (int i = 0; i < charArray.Length; i++)
{
char c = charArray[i];
if (c == '"')
{
builder.Append("\\\"");
}
else if (c == '\\')
{
builder.Append("\\\\");
}
else if (c == '\b')
{
builder.Append("\\b");
}
else if (c == '\f')
{
builder.Append("\\f");
}
else if (c == '\n')
{
builder.Append("\\n");
}
else if (c == '\r')
{
builder.Append("\\r");
}
else if (c == '\t')
{
builder.Append("\\t");
}
else
{
int codepoint = Convert.ToInt32(c);
if ((codepoint >= 32) && (codepoint <= 126))
{
builder.Append(c);
}
else
{
builder.Append("\\u" + Convert.ToString(codepoint, 16).PadLeft(4, '0'));
}
}
}
builder.Append("\"");
}
protected static void serializeNumber(double number, StringBuilder builder)
{
builder.Append(Convert.ToString(number)); // , CultureInfo.InvariantCulture));
}
#endregion
}
#region Extension methods
public static class MiniJsonExtensions
{
public static string toJson(this Hashtable obj)
{
return MiniJSON.jsonEncode(obj);
}
public static string toJson(this Dictionary<string, string> obj)
{
return MiniJSON.jsonEncode(obj);
}
public static ArrayList arrayListFromJson(this string json)
{
return MiniJSON.jsonDecode(json) as ArrayList;
}
public static Hashtable hashtableFromJson(this string json)
{
return MiniJSON.jsonDecode(json) as Hashtable;
}
}
#endregion
}

+ 12
- 0
Assets/Plugins/SDK/MiniJSON.cs.meta Parādīt failu

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f15edb53581ba284f959684b8b76e9a4
timeCreated: 1485338621
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 101
- 0
Assets/Plugins/SDK/NativeBridgeUtil.cs Parādīt failu

@@ -0,0 +1,101 @@
using UnityEngine;
using System.Collections;
using ETHotfix.com.commsdk.unity3d;
using System.Text.RegularExpressions;
using System;
using System.Collections.Generic;
using ETModel;
using ETModel.com.commsdk.unity3d;
/// <summary>
/// 原生code 与Unity通信
/// </summary>
public class NativeBridgeUtil : MonoBehaviour
{
// 单例模式
public static NativeBridgeUtil Instance { get; private set; }
CommSDKComponent csdk;
public void Awake()
{
// 实现单例模式
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
else
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
gameObject.name = "NativeReceiver";
csdk = gameObject.AddComponent<CommSDKComponent>();
csdk.Init();
csdk.responseHandler = OnWechatResponse;
}
public void Start()
{
#if UNITY_ANDROID //android系统
AndroidJNI.AttachCurrentThread();
#endif
}
#region 通用SDK
//0 1 微信 2 闲聊 3多聊
public void WeChatLogin(int type)
{
#if UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE
csdk.Authorize(type);
#endif
}
void OnWechatResponse(int reqID, ActionType type, RespState state, Hashtable data)
{
Debug.Log("OnWechatResponse: reqid=" + reqID + ",action=" + type + ",state=" + state);
switch (type)
{
case ActionType.Authorize:
OnAuthorizedHandler(reqID, state, data);
break;
case ActionType.Share:
break;
case ActionType.Pay:
break;
case ActionType.Location:
break;
}
}
//微信申请授权后回调
void OnAuthorizedHandler(int reqID, RespState state, Hashtable result)
{
if (state == RespState.Success)
{
//UILoginCtrl.Self.OnWechatLogin(result);
Debug.Log("OnAuthorizedHandler->Success:result=" + result);
string unionid = result["unionid"].ToString();
Debug.Log("OnAuthorizedHandler->Success:unionid=" + unionid);
}
else if (state == RespState.Fail)
{
string errorMsg = result["error_msg"].ToString();
string statck = result["stack"].ToString();
Debug.Log("OnAuthorizedHandler->Fail:errorMsg=" + errorMsg + ",statck=" + statck);
}
else if (state == RespState.Cancel)
{
Debug.Log("OnAuthorizedHandler: Cancel");
}
}
#endregion
}

+ 11
- 0
Assets/Plugins/SDK/NativeBridgeUtil.cs.meta Parādīt failu

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

+ 441
- 2
Assets/Scenes/Init.unity Parādīt failu

@@ -471,6 +471,76 @@ MonoBehaviour:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 5
--- !u!1001 &24259649
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3375001057570166699, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_Name
value: NativeReceiver
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3452914372860290207, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 8586933507933314822, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2, type: 3}
--- !u!1 &39222622
GameObject:
m_ObjectHideFlags: 0
@@ -645,6 +715,80 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 45376342}
m_CullTransparentMesh: 0
--- !u!1 &160562201
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 160562202}
- component: {fileID: 160562204}
- component: {fileID: 160562203}
m_Layer: 5
m_Name: Image (2)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &160562202
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 160562201}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.6, y: 0.6, z: 1}
m_Children: []
m_Father: {fileID: 705294046}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 295.86}
m_SizeDelta: {x: 1130, y: 526}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &160562203
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 160562201}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 21300000, guid: 63d2a9582e37ede419f177ee40443388, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!222 &160562204
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 160562201}
m_CullTransparentMesh: 0
--- !u!1 &179665039
GameObject:
m_ObjectHideFlags: 0
@@ -996,6 +1140,44 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 656682076}
m_CullTransparentMesh: 0
--- !u!1 &705294045
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 705294046}
m_Layer: 5
m_Name: loginBthTrans
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &705294046
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705294045}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1719537384}
- {fileID: 1445372296}
- {fileID: 160562202}
m_Father: {fileID: 1392791841}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -172.5}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &867391742
GameObject:
m_ObjectHideFlags: 0
@@ -1282,12 +1464,12 @@ GameObject:
m_Component:
- component: {fileID: 1302099225}
m_Layer: 5
m_Name: GameObject
m_Name: PhoneTrans
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1302099225
RectTransform:
m_ObjectHideFlags: 0
@@ -1485,6 +1667,7 @@ RectTransform:
- {fileID: 1796563212}
- {fileID: 1302099225}
- {fileID: 1768218918}
- {fileID: 705294046}
m_Father: {fileID: 75}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -1511,6 +1694,127 @@ MonoBehaviour:
SendCodeButton: {fileID: 1957083329}
SendCodeButtonText: {fileID: 192227197}
LoginButton: {fileID: 867391744}
PhoneTrans: {fileID: 1302099224}
loginBthTrans: {fileID: 705294045}
PhoneLoginButton: {fileID: 1445372299}
WxLoginButton: {fileID: 1719537387}
--- !u!1 &1445372295
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1445372296}
- component: {fileID: 1445372298}
- component: {fileID: 1445372297}
- component: {fileID: 1445372299}
m_Layer: 5
m_Name: phoneLogin
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1445372296
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1445372295}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 705294046}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 250, y: 0}
m_SizeDelta: {x: 327, y: 109}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1445372297
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1445372295}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 21300000, guid: b712e65990021194795e721125b0ad46, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!222 &1445372298
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1445372295}
m_CullTransparentMesh: 0
--- !u!114 &1445372299
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1445372295}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1445372297}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!1 &1622434996
GameObject:
m_ObjectHideFlags: 0
@@ -1652,6 +1956,123 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1622434996}
m_CullTransparentMesh: 0
--- !u!1 &1719537383
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1719537384}
- component: {fileID: 1719537386}
- component: {fileID: 1719537385}
- component: {fileID: 1719537387}
m_Layer: 5
m_Name: wxLogin
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1719537384
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1719537383}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 705294046}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -250, y: 0}
m_SizeDelta: {x: 327, y: 109}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1719537385
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1719537383}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 21300000, guid: 27f253e451b91484b9dddd97028c0699, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!222 &1719537386
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1719537383}
m_CullTransparentMesh: 0
--- !u!114 &1719537387
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1719537383}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1719537385}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!1 &1722103140
GameObject:
m_ObjectHideFlags: 0
@@ -2014,6 +2435,24 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1957083327}
m_CullTransparentMesh: 0
--- !u!1 &2072301149 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 3375001057570166699, guid: 9b0f4d97ae0b01149a8ba8adb6bd35e2,
type: 3}
m_PrefabInstance: {fileID: 24259649}
m_PrefabAsset: {fileID: 0}
--- !u!114 &2072301150
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2072301149}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 845cd578293274746aef9615b7c5048c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &9222194805866882313
PrefabInstance:
m_ObjectHideFlags: 0


+ 114
- 94
Assets/Scripts/LoginAndPay/LoginView.cs Parādīt failu

@@ -1,95 +1,115 @@
using System;
using System.Collections;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class LoginView : MonoBehaviour
{
public InputField PhoneNumberInputField;
public InputField VerifyCodeInputField;
public Text ErrorText;
public Button SendCodeButton;
public Text SendCodeButtonText;
public Button LoginButton;


// Start is called before the first frame update
void Start()
using System;
using System.Collections;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using ETHotfix;
public class LoginView : MonoBehaviour
{
public InputField PhoneNumberInputField;
public InputField VerifyCodeInputField;
public Text ErrorText;
public Button SendCodeButton;
public Text SendCodeButtonText;
public Button LoginButton;
public GameObject PhoneTrans;
public GameObject loginBthTrans;
public Button PhoneLoginButton;
public Button WxLoginButton;
// Start is called before the first frame update
void Start()
{
SendCodeButton.onClick.AddListener(SendVerifyCode);
LoginButton.onClick.AddListener(Login);
PhoneLoginButton.onClick.AddListener(ClickPhoneLoginButton);
WxLoginButton.onClick.AddListener(ClickWxLoginButton);
// 读取缓存的手机号
if (PlayerPrefs.HasKey("CachedPhoneNumber"))
{
string cachedPhoneNumber = PlayerPrefs.GetString("CachedPhoneNumber");
if (!string.IsNullOrEmpty(cachedPhoneNumber))
{
HttpManager.Instance.phoneNum = cachedPhoneNumber;
SceneManager.LoadScene("LoadingScreen");
}
}
}
private void SendVerifyCode()
{
SendVerifyCodeTask().Forget();
}
async UniTask SendVerifyCodeTask()
{
CodeResponse codeResponse = await HttpManager.Instance.RequestPost<CodeRequest, CodeResponse>("request-code", new CodeRequest(){phone = PhoneNumberInputField.text});
if (codeResponse.message == "验证码已发送")
{
SendCodeButton.interactable = false;
Countdown(30).Forget();
}
ErrorText.text = codeResponse.message;
}
private async UniTaskVoid Countdown(int duration)
{
// SendCodeButtonText.color = Color.gray;
while (duration > 0)
{
SendCodeButtonText.text = $"发送验证码({duration})";
await UniTask.Delay(TimeSpan.FromSeconds(1), ignoreTimeScale: false);
duration--;
}
SendCodeButtonText.text = "发送验证码";
SendCodeButton.interactable = true;
// SendCodeButtonText.color = Color.black;
}
void Login()
{
LoginTask().Forget();
NativeBridgeUtil.Instance.WeChatLogin(1);
}
async UniTask LoginTask()
{
string phonenum = PhoneNumberInputField.text;
LoginResponse loginResponse = await HttpManager.Instance.RequestPost<LoginRequest, LoginResponse>("verify-code", new LoginRequest(){phone = phonenum, code = VerifyCodeInputField.text});
if (loginResponse.message == "验证成功")
{
// 缓存手机号
PlayerPrefs.SetString("CachedPhoneNumber", phonenum);
PlayerPrefs.Save();
//ShowHomeView(phonenum);
//SceneManager.LoadSceneAsync("LoadingScreen");
HttpManager.Instance.phoneNum = phonenum;
SceneManager.LoadScene("LoadingScreen");
}
else
{
ErrorText.text = loginResponse.message;
}
}
void ClickPhoneLoginButton()
{
SendCodeButton.onClick.AddListener(SendVerifyCode);
LoginButton.onClick.AddListener(Login);
// 读取缓存的手机号
if (PlayerPrefs.HasKey("CachedPhoneNumber"))
{
string cachedPhoneNumber = PlayerPrefs.GetString("CachedPhoneNumber");
if (!string.IsNullOrEmpty(cachedPhoneNumber))
{
HttpManager.Instance.phoneNum = cachedPhoneNumber;
SceneManager.LoadScene("LoadingScreen");
}
}
}

private void SendVerifyCode()
{
SendVerifyCodeTask().Forget();
}

async UniTask SendVerifyCodeTask()
{
CodeResponse codeResponse = await HttpManager.Instance.RequestPost<CodeRequest, CodeResponse>("request-code", new CodeRequest(){phone = PhoneNumberInputField.text});
if (codeResponse.message == "验证码已发送")
{
SendCodeButton.interactable = false;
Countdown(30).Forget();
}
ErrorText.text = codeResponse.message;

}

private async UniTaskVoid Countdown(int duration)
{
// SendCodeButtonText.color = Color.gray;
while (duration > 0)
{
SendCodeButtonText.text = $"发送验证码({duration})";
await UniTask.Delay(TimeSpan.FromSeconds(1), ignoreTimeScale: false);
duration--;
}
SendCodeButtonText.text = "发送验证码";
SendCodeButton.interactable = true;
// SendCodeButtonText.color = Color.black;
}


void Login()
{
LoginTask().Forget();
}

async UniTask LoginTask()
{
string phonenum = PhoneNumberInputField.text;
LoginResponse loginResponse = await HttpManager.Instance.RequestPost<LoginRequest, LoginResponse>("verify-code", new LoginRequest(){phone = phonenum, code = VerifyCodeInputField.text});
if (loginResponse.message == "验证成功")
{
// 缓存手机号
PlayerPrefs.SetString("CachedPhoneNumber", phonenum);
PlayerPrefs.Save();

//ShowHomeView(phonenum);
//SceneManager.LoadSceneAsync("LoadingScreen");
HttpManager.Instance.phoneNum = phonenum;
SceneManager.LoadScene("LoadingScreen");
}
else
{
ErrorText.text = loginResponse.message;
}
}

}
}
void ClickWxLoginButton()
{
NativeBridgeUtil.Instance.WeChatLogin(1);
}
}

+ 0
- 48
Assets/WeChatLogin.cs Parādīt failu

@@ -1,48 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeChatLogin : MonoBehaviour
{
// 单例模式
public static WeChatLogin Instance { get; private set; }
private void Awake()
{
// 实现单例模式
if (Instance != null && Instance != this)
{
Destroy(gameObject);
}
else
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
}
// 发起微信登录
public void Login()
{
#if UNITY_ANDROID && !UNITY_EDITOR
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
// 调用你在 Android 插件中实现的微信登录方法
using (AndroidJavaClass wxApiClass = new AndroidJavaClass("com.yourcompany.wxapi.WXEntryActivity"))
{
// 这里可以调用一个静态方法,例如 LoginWeChat()
wxApiClass.CallStatic("LoginWeChat", "your_state_value");
}
}
#endif
}
// 该方法会被 Android 端通过 UnitySendMessage 调用,传回登录结果(JSON格式字符串)
public void OnWeChatLoginResult(string result)
{
Debug.Log("微信登录返回:" + result);
// 在此解析 result,得到 unionid、openid 等信息
}
}

Notiek ielāde…
Atcelt
Saglabāt