Skip to content

Commit 5aba23e

Browse files
committed
First release
0 parents  commit 5aba23e

File tree

100 files changed

+3485
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+3485
-0
lines changed

.gitignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This .gitignore file should be placed at the root of your Unity project directory
2+
#
3+
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
4+
#
5+
/[Ll]ibrary/
6+
/[Tt]emp/
7+
/[Oo]bj/
8+
/[Bb]uild/
9+
/[Bb]uilds/
10+
/[Ll]ogs/
11+
/[Uu]ser[Ss]ettings/
12+
13+
# MemoryCaptures can get excessive in size.
14+
# They also could contain extremely sensitive data
15+
/[Mm]emoryCaptures/
16+
17+
# Asset meta data should only be ignored when the corresponding asset is also ignored
18+
!/[Aa]ssets/**/*.meta
19+
20+
# Uncomment this line if you wish to ignore the asset store tools plugin
21+
# /[Aa]ssets/AssetStoreTools*
22+
23+
# Autogenerated Jetbrains Rider plugin
24+
/[Aa]ssets/Plugins/Editor/JetBrains*
25+
26+
# Visual Studio cache directory
27+
.vs/
28+
29+
# Gradle cache directory
30+
.gradle/
31+
32+
# Autogenerated VS/MD/Consulo solution and project files
33+
ExportedObj/
34+
.consulo/
35+
*.csproj
36+
*.unityproj
37+
*.sln
38+
*.suo
39+
*.tmp
40+
*.user
41+
*.userprefs
42+
*.pidb
43+
*.booproj
44+
*.svd
45+
*.pdb
46+
*.mdb
47+
*.opendb
48+
*.VC.db
49+
50+
# Unity3D generated meta files
51+
*.pidb.meta
52+
*.pdb.meta
53+
*.mdb.meta
54+
55+
# Unity3D generated file on crash reports
56+
sysinfo.txt
57+
58+
# Builds
59+
*.apk
60+
*.aab
61+
*.unitypackage
62+
63+
# Crashlytics generated file
64+
crashlytics-build.properties
65+
66+
# Packed Addressables
67+
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
68+
69+
# Temporary auto-generated Android Assets
70+
/[Aa]ssets/[Ss]treamingAssets/aa.meta
71+
/[Aa]ssets/[Ss]treamingAssets/aa/*

Editor.meta

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

Editor/ComponentField.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using Leopotam.EcsLite;
5+
using Nomnom.EcsLiteDebugger.Editor.Fields;
6+
using UnityEditor;
7+
using UnityEngine.UIElements;
8+
9+
namespace Nomnom.EcsLiteDebugger.Editor {
10+
public class ComponentField: VisualElement {
11+
private static Dictionary<Type, Type> _lookup;
12+
13+
private readonly IEcsPool _pool;
14+
private readonly int _entity;
15+
private readonly FieldInfo _fieldInfo;
16+
17+
private VisualElement _field;
18+
private IFieldGui _guiInstance;
19+
20+
static ComponentField() {
21+
_lookup = new Dictionary<Type, Type>();
22+
23+
TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom(typeof(FieldGui<>));
24+
25+
foreach (Type type in types) {
26+
Type[] args = type.BaseType.GenericTypeArguments;
27+
28+
_lookup[args[0]] = type;
29+
}
30+
}
31+
32+
public ComponentField(IEcsPool pool, int entity, FieldInfo fieldInfo) {
33+
_pool = pool;
34+
_entity = entity;
35+
_fieldInfo = fieldInfo;
36+
}
37+
38+
public void Refresh() {
39+
if (_field == null) {
40+
_field = GatherValue(GetReference(), _fieldInfo);
41+
Add(_field);
42+
return;
43+
}
44+
45+
UpdateValue();
46+
}
47+
48+
private object GetReference() {
49+
return _pool.GetRaw(_entity);
50+
}
51+
52+
private VisualElement GatherValue(object item, FieldInfo fieldInfo) {
53+
Type type = fieldInfo.FieldType;
54+
VisualElement element;
55+
bool hasLookup = _lookup.TryGetValue(type, out Type guiType);
56+
57+
if (hasLookup || TryFindBaseType(type, out guiType)) {
58+
_guiInstance = (IFieldGui)Activator.CreateInstance(guiType, this);
59+
element = _guiInstance.Create(item, fieldInfo);
60+
} else {
61+
element = new Label("Unsupported type");
62+
}
63+
64+
return element;
65+
}
66+
67+
private bool TryFindBaseType(Type type, out Type gui) {
68+
foreach (Type lookupKey in _lookup.Keys) {
69+
if (!lookupKey.IsAssignableFrom(type)) {
70+
continue;
71+
}
72+
73+
gui = _lookup[lookupKey];
74+
return true;
75+
}
76+
77+
gui = default;
78+
return false;
79+
}
80+
81+
public void UpdateReference(FieldInfo info, object value) {
82+
object reference = GetReference();
83+
info.SetValue(reference, value);
84+
_pool.SetRaw(_entity, reference);
85+
}
86+
87+
private void UpdateValue() {
88+
if (_guiInstance == null || _guiInstance.IsEditing) {
89+
return;
90+
}
91+
92+
object value = _fieldInfo.GetValue(GetReference());
93+
_guiInstance.UpdateValue(value);
94+
}
95+
}
96+
}

Editor/ComponentField.cs.meta

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

Editor/ComponentGUI.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Reflection;
3+
using Leopotam.EcsLite;
4+
using UnityEngine.UIElements;
5+
6+
namespace Nomnom.EcsLiteDebugger.Editor {
7+
internal class ComponentGUI: VisualElement {
8+
private Type _type;
9+
private FieldInfo[] _fields;
10+
private EcsWorld _world;
11+
private int _entity;
12+
private bool _empty;
13+
14+
public ComponentGUI(Type type, int entity, EcsWorld world) {
15+
_type = type;
16+
_fields = _type.GetFields();
17+
_world = world;
18+
_entity = entity;
19+
_empty = _fields.Length == 0;
20+
21+
if (_empty) {
22+
Add(new Label("No fields to show"));
23+
}
24+
}
25+
26+
public void Refresh() {
27+
if (_empty) {
28+
return;
29+
}
30+
31+
if (_fields.Length != childCount) {
32+
Clear();
33+
34+
IEcsPool pool = _world.GetPoolByType(_type);
35+
36+
foreach (FieldInfo fieldInfo in _fields) {
37+
ComponentField field = new ComponentField(pool, _entity, fieldInfo);
38+
field.Refresh();
39+
Add(field);
40+
}
41+
}
42+
43+
if (parent is Toggle {value: false}) {
44+
return;
45+
}
46+
47+
foreach (VisualElement visualElement in Children()) {
48+
ComponentField field = visualElement as ComponentField;
49+
field.Refresh();
50+
}
51+
}
52+
}
53+
}

Editor/ComponentGUI.cs.meta

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

Editor/DuoVia.FuzzyStrings.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2+
* Derived from http://www.codeguru.com/vb/gen/vb_misc/algorithms/article.php/c13137__1/Fuzzy-Matching-Demo-in-Access.htm
3+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
4+
5+
using System.Linq;
6+
7+
namespace DuoVia.FuzzyStrings
8+
{
9+
public static class DiceCoefficientExtensions
10+
{
11+
/// <summary>
12+
/// Dice Coefficient based on bigrams. <br />
13+
/// A good value would be 0.33 or above, a value under 0.2 is not a good match, from 0.2 to 0.33 is iffy.
14+
/// </summary>
15+
/// <param name="input"></param>
16+
/// <param name="comparedTo"></param>
17+
/// <returns></returns>
18+
public static double DiceCoefficient(this string input, string comparedTo)
19+
{
20+
var ngrams = input.ToBiGrams();
21+
var compareToNgrams = comparedTo.ToBiGrams();
22+
return ngrams.DiceCoefficient(compareToNgrams);
23+
}
24+
25+
/// <summary>
26+
/// Dice Coefficient used to compare nGrams arrays produced in advance.
27+
/// </summary>
28+
/// <param name="nGrams"></param>
29+
/// <param name="compareToNGrams"></param>
30+
/// <returns></returns>
31+
public static double DiceCoefficient(this string[] nGrams, string[] compareToNGrams)
32+
{
33+
int matches = nGrams.Intersect(compareToNGrams).Count();
34+
if (matches == 0) return 0.0d;
35+
double totalBigrams = nGrams.Length + compareToNGrams.Length;
36+
return (2 * matches) / totalBigrams;
37+
}
38+
39+
public static string[] ToBiGrams(this string input)
40+
{
41+
// nLength == 2
42+
// from Jackson, return %j ja ac ck ks so on n#
43+
// from Main, return #m ma ai in n#
44+
input = SinglePercent + input + SinglePound;
45+
return ToNGrams(input, 2);
46+
}
47+
48+
public static string[] ToTriGrams(this string input)
49+
{
50+
// nLength == 3
51+
// from Jackson, return %%j %ja jac ack cks kso son on# n##
52+
// from Main, return ##m #ma mai ain in# n##
53+
input = DoublePercent + input + DoublePount;
54+
return ToNGrams(input, 3);
55+
}
56+
57+
private static string[] ToNGrams(string input, int nLength)
58+
{
59+
int itemsCount = input.Length - 1;
60+
string[] ngrams = new string[input.Length - 1];
61+
for (int i = 0; i < itemsCount; i++) ngrams[i] = input.Substring(i, nLength);
62+
return ngrams;
63+
}
64+
65+
private const string SinglePercent = "%";
66+
private const string SinglePound = "#";
67+
private const string DoublePercent = "&&";
68+
private const string DoublePount = "##";
69+
}
70+
}

Editor/DuoVia.FuzzyStrings/DiceCoefficientExtensions.cs.meta

Lines changed: 3 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)