Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 2900f52

Browse files
committed
Merge branch 'v0.13.0'
# Conflicts: # README.md
2 parents 7b608ce + b798ce6 commit 2900f52

39 files changed

Lines changed: 846 additions & 92 deletions

Docs/_ReleaseNotes.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
v.0.13.0
2+
New controller:
3+
- Analytics;
4+
Features:
5+
- String functor to avoid allocations when it isn’t required;
6+
Enchantment:
7+
- OneLine usage for more useful configuration;
8+
Fixes:
9+
- Raise scene load event only once, when loading scene already passed;
10+
111
v.0.12.0
212
Breaking changes:
313
- Removed: CompositeEnum, UDBaseConfig, JsonUtils, AssetUtils, CoroutineHelper, ICustomUpdate, EnumUtility, ApplicationQuitTracker, UnityCallbackTracker, UnityHelper, UpdateHelper;

Extensions/OneLine/Editor.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using UnityEditor;
7+
using UnityEngine;
8+
using System.Text.RegularExpressions;
9+
10+
namespace OneLine {
11+
internal class CustomDrawer : SimpleFieldDrawer {
12+
13+
private CustomPropertyDrawers drawers = new CustomPropertyDrawers();
14+
15+
public bool HasCustomDrawer(SerializedProperty property){
16+
return drawers.GetCustomPropertyDrawerFor(property) != null;
17+
}
18+
19+
public override void Draw(Rect rect, SerializedProperty property) {
20+
DrawProperty(rect, property);
21+
}
22+
23+
private void DrawProperty(Rect rect, SerializedProperty property){
24+
var drawer = drawers.GetCustomPropertyDrawerFor(property);
25+
if (drawer != null) {
26+
drawer.OnGUI(rect, property, GUIContent.none);
27+
}
28+
else {
29+
var message = "[OneLine] Can not draw CustomPropertyDrawer for `{0}` at property path `{1}";
30+
throw new Exception(string.Format(message, property.type, property.propertyPath));
31+
}
32+
}
33+
34+
}
35+
}

Extensions/OneLine/OneLine/Editor/Drawers/CustomDrawer.cs.meta

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

Extensions/OneLine/OneLine/Editor/Drawers/CustomDrawer.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using UnityEditor;
7+
using UnityEngine;
8+
using System.Text.RegularExpressions;
9+
10+
namespace OneLine {
11+
internal class CustomPropertyDrawers {
12+
13+
/*
14+
* Optimization
15+
* To avoid creating separate drawers for each array element
16+
*/
17+
private static readonly Regex REGEXP_ARRAY_INDEX = new Regex(".data\\[\\d+\\]");
18+
19+
private static CustomDrawerTypesCache types = new CustomDrawerTypesCache();
20+
private readonly Dictionary<string, PropertyDrawer> drawers = new Dictionary<string, PropertyDrawer>();
21+
22+
public PropertyDrawer GetCustomPropertyDrawerFor(SerializedProperty property){
23+
var key = REGEXP_ARRAY_INDEX.Replace(property.propertyPath, "");
24+
PropertyDrawer result = null;
25+
26+
if (! drawers.TryGetValue(key, out result)){
27+
result = CreatePropertyDrawerFor(property);
28+
drawers[key] = result;
29+
}
30+
31+
return result;
32+
}
33+
34+
private PropertyDrawer CreatePropertyDrawerFor(SerializedProperty property){
35+
var propertyType = property.GetRealType();
36+
if (propertyType == null) return null;
37+
38+
var result = FindAttributeDrawer(property);
39+
40+
if (result == null) {
41+
result = FindDirectDrawer(propertyType);
42+
}
43+
44+
return result;
45+
}
46+
47+
private PropertyDrawer FindAttributeDrawer(SerializedProperty property){
48+
TypeForDrawing typeDrawer = null;
49+
Attribute drawerAttribute = null;
50+
51+
var attributes = property.GetCustomAttributes<PropertyAttribute>();
52+
53+
foreach (var type in types){
54+
foreach (var attribute in attributes){
55+
if (type.IsMatch(attribute.GetType())) {
56+
typeDrawer = type;
57+
drawerAttribute = attribute;
58+
break;
59+
}
60+
}
61+
}
62+
63+
if (typeDrawer == null) return null;
64+
65+
var drawer = Activator.CreateInstance(typeDrawer.DrawerType) as PropertyDrawer;
66+
drawer.SetAttribute(drawerAttribute);
67+
return drawer;
68+
}
69+
70+
private PropertyDrawer FindDirectDrawer(Type propertyType){
71+
var typeDrawer = types.FirstOrDefault(x => x.IsMatch(propertyType));
72+
73+
if (typeDrawer == null) return null;
74+
75+
return Activator.CreateInstance(typeDrawer.DrawerType) as PropertyDrawer;
76+
}
77+
}
78+
}

Extensions/OneLine/OneLine/Editor/Drawers/CustomDrawer/CustomPropertyDrawers.cs.meta

Lines changed: 12 additions & 0 deletions
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;
2+
using System.Linq;
3+
using System.Reflection;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using UnityEditor;
7+
using UnityEngine;
8+
using System.Text.RegularExpressions;
9+
10+
namespace OneLine {
11+
internal class CustomDrawerTypesCache : IEnumerable<TypeForDrawing> {
12+
private static IEnumerable<TypeForDrawing> customDrawers;
13+
14+
private void Init(){
15+
if (customDrawers == null) {
16+
customDrawers = findAllCustomDrawers();
17+
}
18+
}
19+
20+
private static IEnumerable<TypeForDrawing> findAllCustomDrawers(){
21+
return from assembly in AppDomain.CurrentDomain.GetAssemblies()
22+
from type in assembly.GetTypes()
23+
where type.IsSubclassOf(typeof(PropertyDrawer))
24+
where type != typeof(OneLinePropertyDrawer) && ! type.IsSubclassOf(typeof(OneLinePropertyDrawer))
25+
from attribute in type.GetCustomAttributes(typeof(CustomPropertyDrawer), true)
26+
select new TypeForDrawing(attribute as CustomPropertyDrawer, type);
27+
}
28+
29+
public IEnumerator<TypeForDrawing> GetEnumerator() {
30+
Init();
31+
return customDrawers.GetEnumerator();
32+
}
33+
34+
IEnumerator IEnumerable.GetEnumerator() {
35+
return GetEnumerator();
36+
}
37+
}
38+
}

Extensions/OneLine/OneLine/Editor/Drawers/CustomDrawer/CustomPropertyTypesCache.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using UnityEditor;
7+
using UnityEngine;
8+
using System.Text.RegularExpressions;
9+
10+
namespace OneLine {
11+
internal class TypeForDrawing {
12+
private Type Type {get; set;}
13+
private bool UseForChildren {get; set;}
14+
public Type DrawerType {get; private set;}
15+
16+
public TypeForDrawing(CustomPropertyDrawer attribute, Type drawerType) {
17+
Type = attribute.GetTargetType();
18+
UseForChildren = attribute.IsForChildren();
19+
20+
DrawerType = drawerType;
21+
}
22+
23+
public bool IsMatch(Type target){
24+
if (target == null) return false;
25+
26+
if (UseForChildren){
27+
return Type == target || target.IsSubclassOf(Type);
28+
}
29+
else {
30+
return Type == target;
31+
}
32+
}
33+
}
34+
35+
}

0 commit comments

Comments
 (0)