Skip to content

Commit 4f54fd2

Browse files
authored
Merge pull request #20 from arimger/develop
Develop
2 parents 3b62e70 + 02ce618 commit 4f54fd2

Some content is hidden

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

43 files changed

+628
-253
lines changed

Assets/Editor Toolbox/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.8.13 [04.07.2021]
2+
3+
### Added:
4+
- Begin/EndHorizontalGroupAttribute
5+
6+
### Changed:
7+
- Fix overall layouting issues
8+
- Fix IgnoreParentAttribute issues
9+
110
## 0.8.11 [02.07.2021]
211

312
### Added:

Assets/Editor Toolbox/Editor/Drawers/Storages.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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
using UnityEngine;
4+
5+
namespace Toolbox.Editor.Drawers
6+
{
7+
public class ControlDataStorage<T> : DrawerDataStorage<int, Vector2, Vector2>
8+
{
9+
public ControlDataStorage(Func<int, Vector2, Vector2> createMethod) : base(createMethod)
10+
{ }
11+
12+
13+
protected override string GetKey(int context)
14+
{
15+
return context.ToString();
16+
}
17+
18+
19+
public int GetControlId()
20+
{
21+
return GUIUtility.GetControlID(FocusType.Passive);
22+
}
23+
}
24+
}

Assets/Editor Toolbox/Editor/Drawers/Storages/ControlDataStorage.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: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using System.Collections.Generic;
2+
using System;
3+
4+
namespace Toolbox.Editor.Drawers
5+
{
6+
/// <summary>
7+
/// Internal system responsible for keeping and clearing data between <see cref="UnityEditor.Editor"/>s.
8+
/// This small system works only for attribute-based drawers and should be defined as a static field.
9+
/// </summary>
10+
/// <typeparam name="T">Key-related object.</typeparam>
11+
/// <typeparam name="T1">Data to store.</typeparam>
12+
/// <typeparam name="T2">Any type needed for storage item creation. Pass <see cref="EventArgs.Empty"/> if no additional data is needed.</typeparam>
13+
public abstract class DrawerDataStorage<T, T1, T2> : DrawerDataStorageBase
14+
{
15+
protected readonly Dictionary<string, T1> items = new Dictionary<string, T1>();
16+
17+
protected readonly Func<T, T2, T1> createMethod;
18+
protected readonly Action<T1> removeMethod;
19+
20+
21+
public DrawerDataStorage(Func<T, T2, T1> createMethod) : this(createMethod, null)
22+
{ }
23+
24+
public DrawerDataStorage(Func<T, T2, T1> createMethod, Action<T1> removeMethod)
25+
{
26+
this.createMethod = createMethod;
27+
this.removeMethod = removeMethod;
28+
}
29+
30+
31+
protected abstract string GetKey(T context);
32+
33+
34+
/// <summary>
35+
/// Returns and if needed creates new item.
36+
/// </summary>
37+
public virtual T1 ReturnItem(T context, T2 args)
38+
{
39+
var key = GetKey(context);
40+
if (items.TryGetValue(key, out var item))
41+
{
42+
return item;
43+
}
44+
else
45+
{
46+
return items[key] = CreateItem(context, args);
47+
}
48+
}
49+
50+
public virtual T1 CreateItem(T context, T2 args)
51+
{
52+
return CreateItem(context, args, true);
53+
}
54+
55+
public virtual T1 CreateItem(T context, T2 args, bool append)
56+
{
57+
var item = createMethod(context, args);
58+
if (append)
59+
{
60+
AppendItem(context, item);
61+
}
62+
63+
return item;
64+
}
65+
66+
public virtual T1 AppendItem(T context, T1 item)
67+
{
68+
var key = GetKey(context);
69+
return items[key] = item;
70+
}
71+
72+
public virtual void ClearItem(T context)
73+
{
74+
var key = GetKey(context);
75+
if (removeMethod != null)
76+
{
77+
if (items.TryGetValue(key, out var value))
78+
{
79+
removeMethod(value);
80+
items.Remove(key);
81+
}
82+
}
83+
else
84+
{
85+
items.Remove(key);
86+
}
87+
}
88+
89+
public override void ClearItems()
90+
{
91+
if (removeMethod != null)
92+
{
93+
foreach (var item in items.Values)
94+
{
95+
removeMethod(item);
96+
}
97+
}
98+
99+
items.Clear();
100+
}
101+
}
102+
}

Assets/Editor Toolbox/Editor/Internal/DrawerDataStorage.cs.meta renamed to Assets/Editor Toolbox/Editor/Drawers/Storages/DrawerDataStorage.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
3+
namespace Toolbox.Editor.Drawers
4+
{
5+
public abstract class DrawerDataStorageBase
6+
{
7+
static DrawerDataStorageBase()
8+
{
9+
InspectorUtility.OnEditorReload += () =>
10+
{
11+
for (var i = 0; i < storages.Count; i++)
12+
{
13+
storages[i].ClearItems();
14+
}
15+
};
16+
}
17+
18+
19+
protected DrawerDataStorageBase()
20+
{
21+
storages.Add(this);
22+
}
23+
24+
~DrawerDataStorageBase()
25+
{
26+
storages.Remove(this);
27+
}
28+
29+
30+
private static readonly List<DrawerDataStorageBase> storages = new List<DrawerDataStorageBase>();
31+
32+
33+
/// <summary>
34+
/// Called each time Editor is completely destroyed.
35+
/// </summary>
36+
public abstract void ClearItems();
37+
}
38+
}

Assets/Editor Toolbox/Editor/Drawers/Storages/DrawerDataStorageBase.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)