-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathAttributes.cs
47 lines (37 loc) · 1.42 KB
/
Attributes.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
using System;
using UnityEngine;
namespace UnityEditorHelper
{
public class LayerAttribute : PropertyAttribute { }
public class LimitAttribute : PropertyAttribute
{
private enum Mode { LimitLower, LimitUpper, LimitBoth }
private readonly Mode _limitMode;
private readonly int _lowerLimit;
private readonly int _upperLimit;
public LimitAttribute(int lowerLimit) : this(Mode.LimitLower, lowerLimit, int.MaxValue) { }
public LimitAttribute(int lowerLimit, int upperLimit) : this(Mode.LimitBoth, lowerLimit, upperLimit) { }
private LimitAttribute(Mode mode, int lowerLimit, int upperLimit)
{
_limitMode = mode;
_lowerLimit = lowerLimit;
_upperLimit = upperLimit;
}
public int Limit(int value)
{
switch (_limitMode)
{
case Mode.LimitLower:
return Mathf.Clamp(value, _lowerLimit, int.MaxValue);
case Mode.LimitUpper:
return Mathf.Clamp(value, int.MinValue, _upperLimit);
case Mode.LimitBoth:
return Mathf.Clamp(value, _lowerLimit, _upperLimit);
default:
throw new ArgumentOutOfRangeException();
}
}
}
public class SortingLayerAttribute : PropertyAttribute { }
public class TagAttribute : PropertyAttribute { }
}