Skip to content

Commit 75db4d2

Browse files
committed
Initial framework for automatic Editor Window Element creation
1 parent 4a36f36 commit 75db4d2

17 files changed

+502
-13
lines changed

Runtime/Elements/Attributes.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.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Runtime.InteropServices.WindowsRuntime;
3+
using UnityEngine;
4+
using UnityEngine.UIElements;
5+
6+
namespace instance.id.EATK.Extensions
7+
{
8+
/// <summary>
9+
/// Attribute providing easier creation of custom internal editor windows
10+
/// </summary>
11+
[Serializable, AttributeUsage(AttributeTargets.Field)]
12+
public class EditorFieldAttribute : PropertyAttribute, IEquatable<EditorFieldAttribute>
13+
{
14+
public string description;
15+
public string toolTip;
16+
public VisualElement element;
17+
public ContainerData container;
18+
19+
/// <summary>
20+
/// Attribute providing easier creation of custom internal editor windows
21+
/// </summary>
22+
public EditorFieldAttribute() { }
23+
24+
/// <summary>
25+
/// Attribute providing easier creation of custom internal editor windows
26+
/// </summary>
27+
/// <param name="Description"></param>
28+
/// <param name="ToolTip"></param>
29+
/// <param name="ContainerId"></param>
30+
/// <param name="Order"></param>
31+
/// <param name="ContainerType"></param>
32+
/// <param name="ContainerName"></param>
33+
public EditorFieldAttribute(string Description = default, ContainerStyle ContainerType = default, string ContainerName = default,
34+
int ContainerId = -1,
35+
int Order = -1,
36+
string ToolTip = default)
37+
{
38+
if (Description == default)
39+
{
40+
description = "Field Description Missing!";
41+
toolTip = "Please fill out the field description in the EditorField attribute!";
42+
}
43+
else
44+
{
45+
description = Description;
46+
toolTip = default ? Description : ToolTip;
47+
}
48+
49+
container = new ContainerData
50+
{
51+
order = Order,
52+
containerId = ContainerId,
53+
containerType = ContainerType,
54+
containerName = ContainerName
55+
};
56+
}
57+
58+
#region Equality Methods
59+
60+
/// <inheritdoc />
61+
public bool Equals(EditorFieldAttribute other)
62+
{
63+
if (ReferenceEquals(null, other)) return false;
64+
if (ReferenceEquals(this, other)) return true;
65+
return base.Equals(other) && description == other.description && toolTip == other.toolTip && Equals(element, other.element);
66+
}
67+
68+
/// <inheritdoc />
69+
public override bool Equals(object obj)
70+
{
71+
if (ReferenceEquals(null, obj)) return false;
72+
if (ReferenceEquals(this, obj)) return true;
73+
if (obj.GetType() != this.GetType()) return false;
74+
return Equals((EditorFieldAttribute)obj);
75+
}
76+
77+
/// <inheritdoc />
78+
public override int GetHashCode()
79+
{
80+
unchecked
81+
{
82+
int hashCode = base.GetHashCode();
83+
hashCode = (hashCode * 397) ^ (description != null ? description.GetHashCode() : 0);
84+
hashCode = (hashCode * 397) ^ (toolTip != null ? toolTip.GetHashCode() : 0);
85+
hashCode = (hashCode * 397) ^ (element != null ? element.GetHashCode() : 0);
86+
return hashCode;
87+
}
88+
}
89+
90+
#endregion
91+
}
92+
}

Runtime/Elements/Attributes/EditorFieldAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace instance.id.EATK.Extensions
6+
{
7+
[Serializable]
8+
public class ClassData<T> where T : Attribute , new()
9+
{
10+
[SerializeField] public string typeName;
11+
[SerializeField] public List<T> fieldList = new List<T>();
12+
public Dictionary<string, FieldData<T>> fieldDatas = new Dictionary<string, FieldData<T>>();
13+
14+
public ClassData(Type type) => typeName = type.Name;
15+
}
16+
}

Runtime/Scripts/Extensions/DataTypes/ClassData.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using UnityEngine;
6+
7+
namespace instance.id.EATK.Extensions
8+
{
9+
10+
[Serializable]
11+
public class FieldData<T> where T : Attribute, new()
12+
{
13+
public Type fieldType;
14+
public FieldInfo fieldInfo;
15+
[SerializeField] public T attributeData;
16+
[SerializeField] public string name;
17+
[SerializeField] public string fieldTypeString;
18+
[SerializeField] public List<string> fieldTypeParametersString;
19+
[SerializeField] public List<Type> fieldTypeParameters;
20+
21+
public FieldData(FieldInfo fieldInfo)
22+
{
23+
this.fieldInfo = fieldInfo;
24+
name = fieldInfo.Name;
25+
fieldType = fieldInfo.FieldType;
26+
fieldTypeString = fieldInfo.FieldType.GetRealTypeName();
27+
fieldTypeParameters = fieldInfo.FieldType
28+
.GetGenericArguments()
29+
.Select(x => x)
30+
.ToList();
31+
32+
fieldTypeParametersString = fieldInfo.FieldType
33+
.GetGenericArguments()
34+
.Select(x => x.Name.ToString())
35+
.ToList();
36+
37+
CheckForAttributes(fieldInfo);
38+
}
39+
40+
private void CheckForAttributes(FieldInfo fieldInfo)
41+
{
42+
var catAttrib = (T) Attribute.GetCustomAttribute(fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)), typeof(T));
43+
attributeData = catAttrib ?? new T();
44+
}
45+
}
46+
}

Runtime/Scripts/Extensions/DataTypes/FieldData.cs.meta

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

Runtime/Scripts/Extensions/ElementGeneration.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.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using UnityEngine.UIElements;
2+
3+
namespace instance.id.EATK.Extensions
4+
{
5+
public class ContainerData
6+
{
7+
public ContainerStyle containerType;
8+
public VisualElement element;
9+
public string containerName;
10+
public int containerId;
11+
public int order;
12+
}
13+
14+
public struct ContainerDatas
15+
{
16+
public ContainerStyle containerType;
17+
public VisualElement element;
18+
public string containerName;
19+
public int containerId;
20+
public int order;
21+
}
22+
}

Runtime/Scripts/Extensions/ElementGeneration/ContainerData.cs.meta

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