Skip to content

Commit 578daa3

Browse files
authored
Merge pull request #10 from ChessGame/Develop
Develop
2 parents a25166c + 3f171ff commit 578daa3

27 files changed

Lines changed: 1421 additions & 79 deletions

AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/AdroidApi.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*************************************************************************************
2+
**文 件 名:AndroidApi
3+
**创建时间:2017/8/11 星期五 下午 3:10:15
4+
**作 者:罗弘(email: 243515320@qq.com)
5+
**工 号:102193
6+
**说 明:
7+
**版 本:V1.0.0
8+
**修改时间:
9+
**修 改 人:
10+
*************************************************************************************/
11+
using System;
12+
using System.Collections.Generic;
13+
using UnityEngine;
14+
using Code.Core;
15+
16+
namespace Code.AdroidApi
17+
{
18+
public class AndroidApi : Singleton<AndroidApi>
19+
{
20+
private AndroidJavaObject _javaObj;
21+
22+
public AndroidJavaObject JavaObj
23+
{
24+
25+
get
26+
{
27+
if (_javaObj == null)
28+
{
29+
using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
30+
{
31+
_javaObj = jc.GetStatic<AndroidJavaObject>("currentActivity");
32+
}
33+
}
34+
return _javaObj;
35+
}
36+
}
37+
38+
public T SDKCall<T>(string method, params object[] param)
39+
{
40+
try
41+
{
42+
return JavaObj.Call<T>(method, param);
43+
}
44+
catch (Exception e)
45+
{
46+
Debug.LogError(e);
47+
}
48+
return default(T);
49+
}
50+
51+
public void SDKCall(string method, params object[] param)
52+
{
53+
try
54+
{
55+
JavaObj.Call(method, param);
56+
}
57+
catch (Exception e)
58+
{
59+
Debug.LogError(e);
60+
}
61+
}
62+
63+
}
64+
}

AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/AndroidApi.cs.meta renamed to AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/AdroidApi/AndroidApi.cs.meta

File renamed without changes.

AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Bootstrap.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using UnityEngine;
1414
using UnityEngine.UI;
1515
using Autofac;
16+
using Code.AdroidApi;
17+
1618
public class Bootstrap:MonoBehaviour
1719
{
1820
public Button Btn_1;
@@ -39,19 +41,19 @@ private void UnityCallAndroid()
3941
{
4042
int a = UnityEngine.Random.Range(1, 100);
4143
int b = UnityEngine.Random.Range(1, 100);
42-
int c = AndroidApi.Instance.SDKCall<int>("add", a, b);
44+
int c = AndroidApi.getInstance().SDKCall<int>("add", a, b);
4345
ShowText.text = a+"+"+b+" 呼叫Adroid返回的结果:" + c;
4446
}
4547

4648
private void UnityCallAndroidToastMsg()
4749
{
48-
AndroidApi.Instance.SDKCall("ShowToast", "安卓需要显示一下哟!!!");
50+
AndroidApi.getInstance().SDKCall("ShowToast", "安卓需要显示一下哟!!!");
4951
}
5052

5153
private void AndroidCallUnity()
5254
{
5355
/// android 方法, 挂有呼叫方法的对象名字,方法名字
54-
AndroidApi.Instance.SDKCall("CallUnity", "Canvas", "ToLuaFunc");
56+
AndroidApi.getInstance().SDKCall("CallUnity", "Canvas", "ToLuaFunc");
5557
}
5658

5759
private int callnum = 0;

AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/ConstDefine.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*************************************************************************************
2+
**文 件 名:AppConst
3+
**创建时间:2017/8/15 星期二 下午 5:54:39
4+
**作 者:罗弘(email: 243515320@qq.com)
5+
**工 号:102193
6+
**说 明:
7+
**版 本:V1.0.0
8+
**修改时间:
9+
**修 改 人:
10+
*************************************************************************************/
11+
using System;
12+
using System.Collections.Generic;
13+
using UnityEngine;
14+
15+
namespace WorthGod
16+
{
17+
public class AppConst
18+
{
19+
public const bool DebugMode = false; //调试模式-用于内部测试
20+
21+
/// <summary>
22+
/// 如果想删掉框架自带的例子,那这个例子模式必须要
23+
/// 关闭,否则会出现一些错误。
24+
/// </summary>
25+
public const bool ExampleMode = true; //例子模式
26+
27+
/// <summary>
28+
/// 如果开启更新模式,前提必须启动框架自带服务器端。
29+
/// 否则就需要自己将StreamingAssets里面的所有内容
30+
/// 复制到自己的Webserver上面,并修改下面的WebUrl。
31+
/// </summary>
32+
public const bool UpdateMode = false; //更新模式-默认关闭
33+
34+
public const bool AutoWrapMode = true; //自动添加Wrap模式
35+
36+
public const int TimerInterval = 1;
37+
public const int GameFrameRate = 30; //游戏帧频
38+
39+
public const bool UsePbc = true; //PBC
40+
public const bool UseLpeg = true; //LPEG
41+
public const bool UsePbLua = true; //Protobuff-lua-gen
42+
public const bool UseCJson = true; //CJson
43+
public const bool UseSproto = true; //Sproto
44+
public const bool LuaEncode = false; //使用LUA编码
45+
46+
public const string AppName = "SimpleFramework"; //应用程序名称
47+
public const string AppPrefix = AppName + "_"; //应用程序前缀
48+
public const string ExtName = ".assetbundle"; //素材扩展名
49+
public const string AssetDirname = "StreamingAssets"; //素材目录
50+
public const string WebUrl = "http://localhost:6688/"; //测试更新地址
51+
52+
public static string UserId = string.Empty; //用户ID
53+
public static int SocketPort = 8080; //Socket服务器端口
54+
public static string SocketAddress = "127.0.0.1"; //Socket服务器地址
55+
56+
public static string LuaBasePath
57+
{
58+
get { return Application.dataPath + "/uLua/Source/"; }
59+
}
60+
61+
public static string LuaWrapPath
62+
{
63+
get { return LuaBasePath + "LuaWrap/"; }
64+
}
65+
}
66+
}

AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/ConstDefine/AppConst.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/AndroidApi.cs

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*************************************************************************************
2+
**文 件 名:AppBootStrap
3+
**创建时间:2017/8/15 星期二 下午 3:14:01
4+
**作 者:罗弘(email: 243515320@qq.com)
5+
**工 号:102193
6+
**说 明:依赖注入接口,表示该接口的实现类将自动注册到IoC容器中
7+
**版 本:V1.0.0
8+
**修改时间:
9+
**修 改 人:
10+
*************************************************************************************/
11+
using System;
12+
using System.Reflection;
13+
using UnityEngine;
14+
using Autofac;
15+
16+
namespace Code.Core
17+
{
18+
public class AppBootStrap : Singleton<AppBootStrap>
19+
{
20+
public ContainerBuilder Builder;
21+
IContainer _container;
22+
public void Injection()
23+
{
24+
ContainerBuilder builder = new ContainerBuilder();
25+
foreach (Assembly b in AppDomain.CurrentDomain.GetAssemblies())
26+
{
27+
InjectAssembly(b, builder);
28+
}
29+
_container = builder.Build();
30+
}
31+
private void InjectAssembly(Assembly getExecutingAssembly, ContainerBuilder builder)
32+
{
33+
Type[] ts = getExecutingAssembly.GetTypes();
34+
foreach (var types in ts)
35+
{
36+
var temarrtibute = types.GetCustomAttributes(typeof(InjectionAttribute), false);
37+
foreach (var customAttributes in temarrtibute)
38+
{
39+
var temaaa = (InjectionAttribute)customAttributes;
40+
if (temaaa != null)
41+
{
42+
if (temaaa.Autoregister) //自动注册
43+
{
44+
if (temaaa.IsSingleton)
45+
{
46+
var tem = Activator.CreateInstance(temaaa.Sourcetype);
47+
builder.RegisterInstance(tem).As(temaaa.Interfacetype).PropertiesAutowired().SingleInstance();
48+
}
49+
else
50+
{
51+
builder.RegisterType(temaaa.Sourcetype).As(temaaa.Interfacetype).PropertiesAutowired();
52+
}
53+
}
54+
else //手动注册
55+
{
56+
var tem = Activator.CreateInstance(types) as BaseComponentMode;
57+
if (tem != null)
58+
{
59+
builder.RegisterModule(tem);
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
67+
public T Get<T>()
68+
{
69+
return _container.Resolve<T>();
70+
}
71+
}
72+
}

AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/AppBootStrap.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)