forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializedMinMaxGradient.cs
More file actions
95 lines (79 loc) · 2.93 KB
/
Copy pathSerializedMinMaxGradient.cs
File metadata and controls
95 lines (79 loc) · 2.93 KB
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
namespace UnityEditor
{
// Must be in sync with enum in ParticleSystemCurves.h
internal enum MinMaxGradientState
{
k_Color = 0,
k_Gradient = 1,
k_RandomBetweenTwoColors = 2,
k_RandomBetweenTwoGradients = 3,
k_RandomColor = 4
};
internal class SerializedMinMaxGradient
{
public SerializedProperty m_RootProperty;
public SerializedProperty m_MaxGradient;
public SerializedProperty m_MinGradient;
public SerializedProperty m_MaxColor;
public SerializedProperty m_MinColor;
private SerializedProperty m_MinMaxState;
public bool m_AllowColor;
public bool m_AllowGradient;
public bool m_AllowRandomBetweenTwoColors;
public bool m_AllowRandomBetweenTwoGradients;
public bool m_AllowRandomColor;
public MinMaxGradientState state
{
get { return (MinMaxGradientState)m_MinMaxState.intValue; }
set { SetMinMaxState(value); }
}
public bool stateHasMultipleDifferentValues
{
get { return m_MinMaxState.hasMultipleDifferentValues; }
}
public SerializedMinMaxGradient(SerializedModule m)
{
Init(m, "gradient");
}
public SerializedMinMaxGradient(SerializedModule m, string name)
{
Init(m, name);
}
void Init(SerializedModule m, string name)
{
m_RootProperty = m.GetProperty(name);
m_MaxGradient = m.GetProperty(name, "maxGradient");
m_MinGradient = m.GetProperty(name, "minGradient");
m_MaxColor = m.GetProperty(name, "maxColor");
m_MinColor = m.GetProperty(name, "minColor");
m_MinMaxState = m.GetProperty(name, "minMaxState");
m_AllowColor = true;
m_AllowGradient = true;
m_AllowRandomBetweenTwoColors = true;
m_AllowRandomBetweenTwoGradients = true;
m_AllowRandomColor = false;
}
private void SetMinMaxState(MinMaxGradientState newState)
{
if (newState == state)
return;
m_MinMaxState.intValue = (int)newState;
}
public static Color GetGradientAsColor(SerializedProperty gradientProp)
{
Gradient gradient = gradientProp.gradientValue;
return gradient.constantColor;
}
public static void SetGradientAsColor(SerializedProperty gradientProp, Color color)
{
Gradient gradient = gradientProp.gradientValue;
gradient.constantColor = color;
// We have changed a gradient so clear preview cache
UnityEditorInternal.GradientPreviewCache.ClearCache();
}
}
} // namespace UnityEditor