Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f9e4ba6
Showing
51 changed files
with
2,814 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[Ll]ibrary/ | ||
[Tt]emp/ | ||
[Oo]bj/ | ||
[Bb]uild/ | ||
[Bb]uilds/ | ||
Assets/AssetStoreTools* | ||
|
||
# Visual Studio cache directory | ||
.vs/ | ||
|
||
# Autogenerated VS/MD/Consulo solution and project files | ||
ExportedObj/ | ||
.consulo/ | ||
*.csproj | ||
*.unityproj | ||
*.sln | ||
*.suo | ||
*.tmp | ||
*.user | ||
*.userprefs | ||
*.pidb | ||
*.booproj | ||
*.svd | ||
*.pdb | ||
*.opendb | ||
|
||
# Unity3D generated meta files | ||
*.pidb.meta | ||
*.pdb.meta | ||
|
||
# Unity3D Generated File On Crash Reports | ||
sysinfo.txt | ||
|
||
# Builds | ||
*.apk | ||
*.unitypackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"files.exclude": | ||
{ | ||
"**/.DS_Store":true, | ||
"**/.git":true, | ||
"**/.gitignore":true, | ||
"**/.gitmodules":true, | ||
"**/*.booproj":true, | ||
"**/*.pidb":true, | ||
"**/*.suo":true, | ||
"**/*.user":true, | ||
"**/*.userprefs":true, | ||
"**/*.unityproj":true, | ||
"**/*.dll":true, | ||
"**/*.exe":true, | ||
"**/*.pdf":true, | ||
"**/*.mid":true, | ||
"**/*.midi":true, | ||
"**/*.wav":true, | ||
"**/*.gif":true, | ||
"**/*.ico":true, | ||
"**/*.jpg":true, | ||
"**/*.jpeg":true, | ||
"**/*.png":true, | ||
"**/*.psd":true, | ||
"**/*.tga":true, | ||
"**/*.tif":true, | ||
"**/*.tiff":true, | ||
"**/*.3ds":true, | ||
"**/*.3DS":true, | ||
"**/*.fbx":true, | ||
"**/*.FBX":true, | ||
"**/*.lxo":true, | ||
"**/*.LXO":true, | ||
"**/*.ma":true, | ||
"**/*.MA":true, | ||
"**/*.obj":true, | ||
"**/*.OBJ":true, | ||
"**/*.asset":true, | ||
"**/*.cubemap":true, | ||
"**/*.flare":true, | ||
"**/*.mat":true, | ||
"**/*.meta":true, | ||
"**/*.prefab":true, | ||
"**/*.unity":true, | ||
"build/":true, | ||
"Build/":true, | ||
"Library/":true, | ||
"library/":true, | ||
"obj/":true, | ||
"Obj/":true, | ||
"ProjectSettings/":true, | ||
"temp/":true, | ||
"Temp/":true | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using UnityEngine; | ||
using UnityEditor.Experimental.AssetImporters; | ||
using System.IO; | ||
|
||
namespace CastleDBImporter | ||
{ | ||
[ScriptedImporter(1, "cdb")] | ||
public class CDBImporter : ScriptedImporter | ||
{ | ||
public float m_Scale = 1; | ||
|
||
public override void OnImportAsset(AssetImportContext ctx) | ||
{ | ||
CastleDB castle = ScriptableObject.CreateInstance<CastleDB>(); | ||
castle.Init(File.ReadAllText(ctx.assetPath)); | ||
// JsonUtility.FromJsonOverwrite(File.ReadAllText(ctx.assetPath), scriptable); | ||
// var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); | ||
// var position = JsonUtility.FromJson<Vector3>(File.ReadAllText(ctx.assetPath)); | ||
|
||
// cube.transform.position = position; | ||
// cube.transform.localScale = new Vector3(m_Scale, m_Scale, m_Scale); | ||
|
||
// 'cube' is a a GameObject and will be automatically converted into a prefab | ||
// (Only the 'Main Asset' is elligible to become a Prefab.) | ||
ctx.AddObjectToAsset("main obj", castle); | ||
ctx.SetMainObject(castle); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using UnityEngine; | ||
|
||
namespace CastleDBImporter | ||
{ | ||
public class CastleAssemblyGenerator | ||
{ | ||
public void GenerateAssemblies(CastleDB.Root rootNode) | ||
{ | ||
foreach (CastleDB.Sheet sheet in rootNode.sheets) | ||
{ | ||
// Each sheet generates a class | ||
AssemblyName aName = new AssemblyName(sheet.name + "Assembly"); | ||
AssemblyBuilder ab = | ||
AppDomain.CurrentDomain.DefineDynamicAssembly( | ||
aName, | ||
AssemblyBuilderAccess.RunAndSave); | ||
|
||
// For a single-module assembly, the module name is usually | ||
// the assembly name plus an extension. | ||
ModuleBuilder mb = | ||
ab.DefineDynamicModule(aName.Name, aName.Name + ".dll"); | ||
|
||
TypeBuilder tb = mb.DefineType( | ||
sheet.name, | ||
TypeAttributes.Public); | ||
|
||
|
||
// Each column defines the fields of its given type | ||
int typeCount = sheet.columns.Count; | ||
Type[] parameterTypes = new Type[typeCount]; | ||
FieldBuilder[] fields = new FieldBuilder[typeCount]; | ||
string[] fieldNames = new string[typeCount]; | ||
for (int i = 0; i < typeCount; i++) | ||
{ | ||
CastleDB.Column column = sheet.columns[i]; | ||
Type fieldType = CastleDBUtils.GetTypeFromCastleDBType(column.typeStr); | ||
parameterTypes[i] = fieldType; | ||
|
||
// Add a public field of the specific type | ||
FieldBuilder fb = tb.DefineField( | ||
column.name, | ||
fieldType, | ||
FieldAttributes.Public); | ||
fields[i] = fb; | ||
fieldNames[i] = column.name; | ||
} | ||
|
||
|
||
// Define a constructor that takes an integer argument and | ||
// stores it in the private field. | ||
ConstructorBuilder ctor1 = tb.DefineConstructor( | ||
MethodAttributes.Public, | ||
CallingConventions.Standard, | ||
parameterTypes); | ||
|
||
ILGenerator ctor1IL = ctor1.GetILGenerator(); | ||
// For a constructor, argument zero is a reference to the new | ||
// instance. Push it on the stack before calling the base | ||
// class constructor. Specify the default constructor of the | ||
// base class (System.Object) by passing an empty array of | ||
// types (Type.EmptyTypes) to GetConstructor. | ||
ctor1IL.Emit(OpCodes.Ldarg_0); | ||
ctor1IL.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes)); | ||
// Push the instance on the stack before pushing the argument | ||
// that is to be assigned to the private field m_number. | ||
// ctor1IL.Emit(OpCodes.Ldarg_0); | ||
|
||
for (int i = 0; i < typeCount; i++) | ||
{ | ||
ctor1IL.Emit(OpCodes.Ldarg_S, i+1); | ||
ctor1IL.Emit(OpCodes.Stfld, fields[i]); | ||
// ctor1IL.Emit(OpCodes.Ldarg_1); | ||
// ctor1IL.Emit(OpCodes.Stfld, fbNumber); | ||
} | ||
|
||
ctor1IL.Emit(OpCodes.Ret); | ||
|
||
// Finish the type. | ||
Type t = tb.CreateType(); | ||
|
||
// The following line saves the single-module assembly. This | ||
// requires AssemblyBuilderAccess to include Save. You can now | ||
// type "ildasm MyDynamicAsm.dll" at the command prompt, and | ||
// examine the assembly. You can also write a program that has | ||
// a reference to the assembly, and use the MyDynamicType type. | ||
// | ||
ab.Save(aName.Name + ".dll"); | ||
|
||
foreach (CastleDB.Line line in sheet.lines) | ||
{ | ||
if(sheet.name != "unityTest3") { continue;} | ||
FieldInfo fi = t.GetField("testStringColumn"); | ||
// Create an instance of MyDynamicType using the constructor | ||
// that specifies m_Number. The constructor is identified by | ||
// matching the types in the argument array. In this case, | ||
// the argument array is created on the fly. Display the | ||
// property value. | ||
|
||
//need to get all the generate fields | ||
//then convert the raw line stream to json? | ||
//then loop through generated fields and set their value to their value of the named key in json | ||
object generated = Activator.CreateInstance(t); | ||
// object generated = Activator.CreateInstance(t, | ||
// new object[]{ | ||
// "testTextValue" | ||
// }); | ||
// JsonUtility.FromJsonOverwrite(line.rawLine, generated); | ||
Debug.Log($"o2.Number: {fi.GetValue(generated)}"); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using UnityEngine; | ||
using UnityEditor.Experimental.AssetImporters; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
||
namespace CastleDBImporter | ||
{ | ||
public class CastleDB : ScriptableObject | ||
{ | ||
//each sheet is it's own type and needs its own assembly (for now) | ||
//create the type from the columns | ||
//create the objects from the lines | ||
public void Init(string raw) | ||
{ | ||
Root rootNode = JsonUtility.FromJson<Root>(raw); | ||
foreach (Sheet item in rootNode.sheets) | ||
{ | ||
Debug.Log(item.name); | ||
} | ||
CastleAssemblyGenerator generator = new CastleAssemblyGenerator(); | ||
generator.GenerateAssemblies(rootNode); | ||
} | ||
|
||
[System.Serializable] | ||
public class Root | ||
{ | ||
public List<Sheet> sheets; | ||
public List<CustomType> customTypes; | ||
public bool compress; | ||
} | ||
|
||
[System.Serializable] | ||
public class Sheet | ||
{ | ||
public string name; | ||
public List<Column> columns; | ||
public List<Line> lines; | ||
public List<Seperator> seperators; | ||
public List<Property> props; | ||
} | ||
|
||
[System.Serializable] | ||
public class Column | ||
{ | ||
public string typeStr; | ||
public string name; | ||
public string display; | ||
} | ||
|
||
[System.Serializable] | ||
public class Line | ||
{ | ||
public string rawLine; | ||
} | ||
|
||
[System.Serializable] | ||
public class Seperator | ||
{ | ||
} | ||
|
||
[System.Serializable] | ||
public class Property | ||
{ | ||
} | ||
|
||
[System.Serializable] | ||
public class CustomType | ||
{ | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.