-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathReorderableListAttribute.cs
117 lines (96 loc) · 3.9 KB
/
ReorderableListAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using UnityEngine;
namespace UnityExtensions
{
[AttributeUsage(AttributeTargets.Field)]
public class ReorderableListAttribute : PropertyAttribute
{
public float r, g, b;
public bool disableAdding;
public bool disableRemoving;
public bool disableAddingAndRemoving
{
get { return disableAdding && disableRemoving; }
set { disableAdding = disableRemoving = value; }
}
public bool disableDragging;
public bool elementsAreSubassets;
public string elementHeaderFormat;
public string listHeaderFormat;
public bool hideFooterButtons;
public string[] parallelListNames;
public enum ParallelListLayout { Rows, Columns };
public ParallelListLayout parallelListLayout;
public ReorderableListAttribute() { }
public ReorderableListAttribute(params string[] parallelListNames)
{
this.parallelListNames = parallelListNames;
}
public const string SingularPluralBlockBegin = "{{";
public const string SingularPluralBlockSeparator = "|";
public const string SingularPluralBlockEnd = "}}";
public string singularListHeaderFormat
{
get
{
if (listHeaderFormat == null)
return null;
var value = listHeaderFormat;
while (value.Contains(SingularPluralBlockBegin)) {
int beg = value.IndexOf(SingularPluralBlockBegin);
int end = value.IndexOf(SingularPluralBlockEnd, beg);
if (end < 0) break;
end += SingularPluralBlockEnd.Length;
int blockLen = end - beg;
var block = value.Substring(beg, blockLen);
int sep = value.IndexOf(SingularPluralBlockSeparator, beg);
if (sep < 0) {
value = value.Replace(block, "");
}
else
{
beg += SingularPluralBlockBegin.Length;
int singularLen = (sep - beg);
var singular = value.Substring(beg, singularLen);
value = value.Replace(block, singular);
}
}
return value;
}
}
public string pluralListHeaderFormat
{
get
{
if (listHeaderFormat == null)
return null;
var value = listHeaderFormat;
while (value.Contains(SingularPluralBlockBegin)) {
int beg = value.IndexOf(SingularPluralBlockBegin);
int end = value.IndexOf(SingularPluralBlockEnd, beg);
if (end < 0) break;
end += SingularPluralBlockEnd.Length;
int blockLen = end - beg;
var block = value.Substring(beg, blockLen);
int sep = value.IndexOf(SingularPluralBlockSeparator, beg);
if (sep < 0) {
beg += SingularPluralBlockBegin.Length;
end -= SingularPluralBlockEnd.Length;
int pluralLen = (end - beg);
var plural = value.Substring(beg, pluralLen);
value = value.Replace(block, plural);
}
else
{
sep = sep + SingularPluralBlockSeparator.Length;
end -= SingularPluralBlockEnd.Length;
int pluralLen = (end - sep);
var plural = value.Substring(beg, pluralLen);
value = value.Replace(block, plural);
}
}
return value;
}
}
}
}