public void RegClass(System.Type klass, string macro, ECSType csType) { if (klass.IsGenericType) { return; } var methods = klass.GetMethods(); foreach (var i in methods) { var rpcAttr = Rtti.AttributeHelper.GetCustomAttribute(i, typeof(RPCCallAttribute).FullName, true); if (rpcAttr == null) { continue; } var args = i.GetParameters(); var proc_type = GetRPCMethodProcessor(args); if (proc_type == null) { Profiler.Log.WriteLine(Profiler.ELogTag.Warning, "RPC", $"Method: {i.DeclaringType.FullName}.{i.Name} arguments is not valid"); continue; } var type = Rtti.RttiHelper.GetTypeFromTypeFullName(proc_type.FullName, csType); //var atts = type.GetCustomAttributes(typeof(RPCProcessorAttribute), false); //if (atts == null || atts.Length == 0) // continue; //var senderDesc = atts[0] as RPCProcessorAttribute; //var sender = RPCProcessor.InitProcessor(senderDesc.ProcessorType, type, senderDesc.ReturnType); var sender = RPCProcessor.GetProcessorByArgument(type); RegRPC(sender, i, type, macro); } }
public static VAssembly GetAnalyseAssembly(ECSType csType, string keyName) { lock (mAnalyseAssemblyDic) { if (csType == ECSType.All || csType == ECSType.Common) { foreach (var asmDic in mAnalyseAssemblyDic.Values) { VAssembly assembly; if (asmDic.TryGetValue(keyName, out assembly)) { return(assembly); } } } else { Dictionary <string, VAssembly> asmDic; if (mAnalyseAssemblyDic.TryGetValue(csType, out asmDic)) { VAssembly assembly; if (asmDic.TryGetValue(keyName, out assembly)) { return(assembly); } } } } return(null); }
public static Type[] GetTypes(ECSType csType) { List <Type> retList = new List <Type>(); if (csType == ECSType.All || csType == ECSType.Common) { foreach (var assemDic in mAnalyseAssemblyDic.Values) { foreach (var assembly in assemDic.Values) { retList.AddRange(assembly.GetTypes()); } } } else { Dictionary <string, VAssembly> assemDic; if (mAnalyseAssemblyDic.TryGetValue(csType, out assemDic)) { foreach (var assembly in assemDic.Values) { retList.AddRange(assembly.GetTypes()); } } } return(retList.ToArray()); }
public static void Class_StructDefinition(ECSType type, StreamWriter sw, string name) { switch (type) { case ECSType.ENTITY: sw.WriteLine("public class " + name + "Spawner : MonoBehaviour {"); sw.WriteLine(); sw.WriteLine("public int quantity = 10;"); sw.WriteLine(); break; case ECSType.COMPONENT: sw.WriteLine("[GenerateAuthoringComponent]"); sw.WriteLine("public struct " + name + " : IComponentData {"); break; default: sw.WriteLine("//public int quantity = 10; //Only necessary for spawner script."); sw.WriteLine(); sw.WriteLine("//[AlwaysSynchronizeSystem]"); sw.WriteLine("//public class " + name + " : JobComponentSystem {"); sw.WriteLine("//public class " + name + "Spawner : MonoBehavior {"); break; } }
public void RegClass(System.Type klass, string macro, ECSType csType) { var methods = klass.GetMethods(); foreach (var i in methods) { var rpcAttr = Rtti.AttributeHelper.GetCustomAttribute(i, typeof(RPCCallAttribute).FullName, true); if (rpcAttr == null) { continue; } var args = i.GetParameters(); if (args.Length != 1) { continue; } if (Rtti.RttiHelper.IsSubclassOf(args[0].ParameterType, typeof(RPCParameter).FullName) == false) { continue; } var type = Rtti.RttiHelper.GetTypeFromTypeFullName(args[0].ParameterType.FullName, csType); var parameter = System.Activator.CreateInstance(type) as RPCParameter; RegRPC(parameter, i, macro); } }
//Create script for systems public static void Write(StreamWriter sw, string name, SystemAsset system) { ECSType type = ECSType.SYSTEM; Header(type, sw, system.isNetworked); Class_StructDefinition(type, sw, name, system.isMainThread, system.isNetworked); Define(system, sw); Terminate(sw); }
//Create script for systems that act on single (non-composite) components, or creates a script for a single (non-composite) component; public static void Write(StreamWriter sw, string name, ComponentAsset component) { ECSType type = ECSType.COMPONENT; Header(type, sw, false); Class_StructDefinition(type, sw, name); Define(component, sw); Terminate(sw); }
//Create script for Entity Archetypes spawner public static void Write(StreamWriter sw, string name, EntityAsset entityAsset) { ECSType type = ECSType.ENTITY; Header(type, sw, false); Class_StructDefinition(type, sw, name); Define(entityAsset, name, sw); Terminate(sw); }
public CResult ReadAllByType(ECSType eCSType) { ArrayList oCSList = new ArrayList(); oResult = new CResult(); conn = oConnManager.GetConnection(out s_DBError); if (conn != null) { try { DataSet ds = new DataSet(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "sp_Cust_ReadAllByType"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CSType", ((int)eCSType).ToString()); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { oCSList.Add(GetResultSetToCS(dr)); } oResult.IsSuccess = true; oResult.Data = oCSList; } catch (SqlException e) { oResult.IsSuccess = false; oResult.ErrMsg = e.Message; } finally { oConnManager.Close(); } } else { oResult.IsSuccess = false; oResult.ErrMsg = s_DBError; } return(oResult); }
//public static void Write(StreamWriter sw, string name, ) //Establish Unity dependencies public static void Header(ECSType type, StreamWriter sw, bool isNetworked) { switch (type) { case ECSType.ENTITY: sw.WriteLine("using Unity.Entities;"); sw.WriteLine("using Unity.Collections;"); sw.WriteLine("using System.Collections;"); sw.WriteLine("using System.Collections.Generic;"); sw.WriteLine("using UnityEngine;"); sw.WriteLine(); break; case ECSType.COMPONENT: sw.WriteLine("using Unity.Entities;"); sw.WriteLine("using Unity.Collections;"); sw.WriteLine(); break; case ECSType.SYSTEM: sw.WriteLine("using UnityEngine;"); sw.WriteLine("using Unity.Entities;"); sw.WriteLine("using Unity.Jobs;"); sw.WriteLine("using Unity.Burst;"); if (isNetworked) { sw.WriteLine("using Unity.NetCode;"); sw.WriteLine("using Unity.Networking.Transport;"); } sw.WriteLine(); break; default: sw.WriteLine("using UnityEngine;"); sw.WriteLine("using Unity.Entities;"); sw.WriteLine("using Unity.Collections;"); sw.WriteLine("using Unity.Jobs;"); sw.WriteLine("using Unity.Burst;"); sw.WriteLine("using System.Collections;"); sw.WriteLine("using System.Collections.Generic;"); sw.WriteLine("using Unity.NetCode;"); sw.WriteLine("using Unity.Networking.Transport;"); sw.WriteLine(); break; } }
public static Type[] GetTypes(ECSType csType, string attributeTypeFullName, bool inherit) { List <Type> retList = new List <Type>(); if (csType == ECSType.All || csType == ECSType.Common) { foreach (var assemDic in mAnalyseAssemblyDic.Values) { foreach (var assembly in assemDic.Values) { foreach (var type in assembly.GetTypes()) { var att = AttributeHelper.GetCustomAttribute(type, attributeTypeFullName, inherit); if (att == null) { continue; } retList.Add(type); } } } } else { Dictionary <string, VAssembly> assemDic; if (mAnalyseAssemblyDic.TryGetValue(csType, out assemDic)) { foreach (var assembly in assemDic.Values) { foreach (var type in assembly.GetTypes()) { var att = AttributeHelper.GetCustomAttribute(type, attributeTypeFullName, inherit); if (att == null) { continue; } retList.Add(type); } } } } return(retList.ToArray()); }
public static VAssembly[] GetAnalyseAssemblys(ECSType csType) { List <VAssembly> retAssemblys = new List <VAssembly>(); if (csType == ECSType.All || csType == ECSType.Common) { foreach (var asmDic in mAnalyseAssemblyDic.Values) { retAssemblys.AddRange(asmDic.Values); } } else { Dictionary <string, VAssembly> dic; if (mAnalyseAssemblyDic.TryGetValue(csType, out dic)) { retAssemblys.AddRange(dic.Values); } } return(retAssemblys.ToArray()); }
public VAssembly GetAssembly(System.Reflection.Assembly assembly, ECSType csType, string keyName = "") { if (assembly == null) { return(null); } var vAssem = EngineNS.Rtti.RttiHelper.GetAnalyseAssemblyByFullName(assembly.FullName); if (vAssem != null) { mAssembly_FullNameDic[vAssem.FullName] = vAssem; if (!assembly.IsDynamic) { mAssembly_AbsFileDic[assembly.Location.Replace("\\", "/")] = vAssem; } return(vAssem); } if (mAssembly_FullNameDic.TryGetValue(assembly.FullName, out vAssem)) { return(vAssem); } vAssem = new VAssembly(assembly, csType); if (string.IsNullOrEmpty(keyName)) { vAssem.KeyName = assembly.GetName().Name;// + ".dll"; } else { vAssem.KeyName = keyName; } mAssembly_FullNameDic[assembly.FullName] = vAssem; if (!assembly.IsDynamic) { mAssembly_AbsFileDic[assembly.Location.Replace("\\", "/")] = vAssem; } return(vAssem); }
//Create class or struct definition. public static void Class_StructDefinition(ECSType type, StreamWriter sw, string name, bool isMainThread, bool isNetworked) { if (type != ECSType.SYSTEM) { isMainThread = false; } switch (type) { case ECSType.ENTITY: sw.WriteLine("public int quantity = 10;"); sw.WriteLine(); sw.WriteLine("public class " + name + "Spawner : MonoBehavior {"); break; case ECSType.COMPONENT: sw.WriteLine("[GenerateAuthoringComponent]"); sw.WriteLine("public struct " + name + " : IComponentData {"); break; case ECSType.SYSTEM: if (isMainThread && !isNetworked) { sw.WriteLine("[AlwaysSynchronizeSystem]"); } else if (isMainThread && isNetworked) { sw.WriteLine("[AlwaysUpdateSystem, UpdateInWorld(UpdateInWorld.TargetWorld.ClientAndServer)]"); } sw.WriteLine("public class " + name + " : JobComponentSystem {"); break; default: sw.WriteLine("//public struct " + name + " : EntityArchetype {"); sw.WriteLine("//public struct " + name + " : IComponentData {"); sw.WriteLine("//public class " + name + " : JobComponentSystem {"); break; } }
public static VAssembly GetAssemblyFromDllFileName(ECSType csType, string dllName, string relativePath = "", bool fromBytes = false, bool userCashe = true, bool useVPDB = true) { try { string dllFullname = dllName; dllName = EngineNS.CEngine.Instance.FileManager.GetPureFileFromFullName(dllName, false); var idx = dllFullname.LastIndexOf(".dll"); if (idx < 0) { dllFullname = dllFullname + ".dll"; } if (userCashe) { VAssembly retVal; if (mRuntimeAssemblyCache.TryGetValue(dllName, out retVal)) { return(retVal); } var assem = GetAnalyseAssembly(csType, dllName); if (assem != null) { mRuntimeAssemblyCache[assem.KeyName] = assem; return(assem); } } //if (csType == ECSType.Server) //{ // System.Diagnostics.Debug.Assert(!dllFullname.Contains("Client.dll")); // System.Diagnostics.Debug.Assert(!dllFullname.Contains("ClientCommon.dll")); //} //else if (csType == ECSType.Client) //{ // System.Diagnostics.Debug.Assert(!dllFullname.Contains("Server.dll")); // System.Diagnostics.Debug.Assert(!dllFullname.Contains("Server.Windows.dll")); //} if (userCashe) { var assemblys = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblys) { if (assembly.GetName().Name + ".dll" == dllFullname) { var ra = VAssemblyManager.Instance.GetAssembly(assembly, csType, dllName); mRuntimeAssemblyCache[ra.KeyName] = ra; return(ra); } } } if (!System.IO.Path.IsPathRooted(dllFullname)) { var pathString = ""; switch (csType) { case ECSType.Client: pathString = CEngine.Instance.Desc.Client_Directory + "/"; dllFullname = CEngine.Instance.FileManager.EngineRoot + pathString + relativePath + dllFullname; break; case ECSType.Server: pathString = CEngine.Instance.Desc.Server_Directory + "/"; dllFullname = CEngine.Instance.FileManager.EngineRoot + pathString + relativePath + dllFullname; break; case ECSType.Common: case ECSType.All: dllFullname = CEngine.Instance.FileManager.Bin + relativePath + dllFullname; break; } } var retAssembly = VAssemblyManager.Instance.LoadAssembly(dllFullname, csType, fromBytes, userCashe, dllName, useVPDB); if (retAssembly != null) { mRuntimeAssemblyCache[retAssembly.KeyName] = retAssembly; } return(retAssembly); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(null); }
//public static readonly string MacrossCollectorDllName_Android = "MacrossCollector.Android.dll"; //public static readonly string MacrossCollectorDllName = "MacrossCollector.dll"; //public static readonly string MacrossScriptDllName_Android = "MacrossScript.Android.dll"; //public static readonly string MacrossScriptDllName = "MacrossScript.dll"; public string GetCollectorCodeFileName(ECSType csType) { var dir = EngineNS.CEngine.Instance.FileManager.EditorContent + "Macross"; return($"{dir}/MacrossCollector_{csType.ToString()}.cs".Replace("/", "\\")); }