提交 4246d344 编写于 作者: Z zhengxiaofeng

【Xlua框架】Lua和C#之间相互调用测试

上级 fba1615d
fileFormatVersion: 2
guid: 2f0d8566f81a39344b9e1abbf40d9701
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Shader "光照/漫反射_逐顶点光照"
{
Properties
{
_Diffuse("Diffuse",color) = (1,1,1,1)
}
SubShader
{
Pass
{
Tags {"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
fixed4 _Diffuse
struct a2v
{
float4 vertex : POSITION;
float3 normal : NORMAL;
}
struct v2f
{
float4 pos : SV_POSITION;
fixed3 color : COLOR;
}
v2f vert()
{
v2f o;
o.pos = mul(UNITY_MATRIX_M)
}
fixed4 frag(v2f f)
{
return fixed4(f.color,1.0)
}
ENDCG
}
}
FallBack "Diffuse"
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2fc5537c632c4994aa9d7faeaeca8a68
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 607248d26123ade4f984187e93f5eea8
guid: 4c13d118ac45d8b4287caf0e6036c06b
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
fileFormatVersion: 2
guid: d004b7c99f393844d8b16776e9350326
guid: 29e96dc8203e6c54fbbb8ae007077416
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
......@@ -27,9 +27,25 @@ function CSCallLuaFunc()
print("全局函数")
end
function LuaTest:LuaCallCSharp()
local StaticVariant = CS.Test.Test_LuaCallCSharp.CSharpString;
print("1. 调用C#内的静态变量 : "..StaticVariant)
CS.Test.Test_LuaCallCSharp:LuaCallCSharpTest()
print("3. 调用C#端公有方法")
local objectTest = CS.ZFramework.Core.AssetManager.Instance:GetGameObject("Prefab/Cube.prefab")
end
function LuaTest:LocalTest()
print("公有函数")
print("-------------------------------开始测试lua调用C#-----------------------------------")
LuaTest:LuaCallCSharp()
end
return LuaTest
......@@ -207,7 +207,7 @@ namespace ZFramework.Core
}
}
private void ProcessSubAssets(Object[] assets)
public void ProcessSubAssets(Object[] assets)
{
_subAssetObjects = new Dictionary<string, Object>();
if (assets[0] is SpriteAtlas)
......
......@@ -8,6 +8,7 @@ namespace ZFramework.Core
{
public class AssetRegistry
{
public const string AssetRootPath = "Assets/AssetSources/AbResources";
public const string MetaFileName = "AssetBundleMeta.bin";
private readonly Dictionary<string,string> _assetPathToBundleName = new Dictionary<string, string>();
......@@ -101,6 +102,7 @@ namespace ZFramework.Core
public AssetData GetAssetAtPath(string path,bool withSubAssets = false)
{
AssetData assetData = null;
#if ASSETBUNDLE_ENABLE
AssetBundleData bundleData = FindAssetBundle(path); //获取资源所在的AB数据
if (bundleData!= null)
{
......@@ -112,6 +114,33 @@ namespace ZFramework.Core
bundleData.SetAsset(path,assetData); //把asset数据和bundle数据关联起来
}
}
#elif UNITY_EDITOR
if (withSubAssets)
{
UnityEngine.Object[] subAssets = UnityEditor.AssetDatabase.LoadAllAssetsAtPath($"{AssetRootPath}/{path}");
if (subAssets != null && subAssets.Length > 0)
{
assetData = new AssetData(path);
assetData.ProcessSubAssets(subAssets);
}
else
{
Debug.LogError($"Can not load the asset '{path}'");
}
}
else
{
UnityEngine.Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.Object>($"{AssetRootPath}/{path}");
if (obj != null)
{
assetData = new AssetData(path, null, obj);
}
else
{
Debug.LogError($"Can not load the asset '{path}'");
}
}
#endif
return assetData;
}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
namespace Test
{
[LuaCallCSharp]
public class Test_LuaCallCSharp
{
public static string CSharpString = "C#端测试string";
public static void LuaCallCSharpTest()
{
Debug.Log("2. 调用C#端静态函数");
}
}
}
fileFormatVersion: 2
guid: fe8a2ad273b76ca4584cf17a492a84de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7fd92acba61afb4448f6a0f7250878c7
guid: b6d93b40157c53648baf28d5d586aa4b
DefaultImporter:
externalObjects: {}
userData:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册