Skip to content

Commit bdee4c9

Browse files
committed
Initial Commit
1 parent a459b86 commit bdee4c9

220 files changed

Lines changed: 32854 additions & 0 deletions

File tree

Some content is hidden

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

Assets/Animation Window.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.

Assets/Animation Window/Editor.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.

Assets/Animation Window/Editor/Animation.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: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using UnityEditor;
8+
using UnityEngine;
9+
using Object = UnityEngine.Object;
10+
11+
namespace UnityEditorInternal.PlayEm
12+
{
13+
static internal class MaterialAnimationUtility
14+
{
15+
const string kMaterialPrefix = "material.";
16+
17+
static PropertyModification[] CreatePropertyModifications(int count, Object target)
18+
{
19+
PropertyModification[] modifications = new PropertyModification[count];
20+
for (int i = 0; i < modifications.Length; i++)
21+
{
22+
modifications[i] = new PropertyModification();
23+
modifications[i].target = target;
24+
}
25+
return modifications;
26+
}
27+
28+
static void SetupPropertyModification(string name, float value, PropertyModification prop)
29+
{
30+
prop.propertyPath = kMaterialPrefix + name;
31+
prop.value = value.ToString();
32+
}
33+
34+
static PropertyModification[] MaterialPropertyToPropertyModifications(MaterialProperty materialProp, Object target, float value)
35+
{
36+
PropertyModification[] modifications = CreatePropertyModifications(1, target);
37+
SetupPropertyModification(materialProp.name, value, modifications[0]);
38+
return modifications;
39+
}
40+
41+
static PropertyModification[] MaterialPropertyToPropertyModifications(MaterialProperty materialProp, Object target, Color color)
42+
{
43+
PropertyModification[] modifications = CreatePropertyModifications(4, target);
44+
SetupPropertyModification(materialProp.name + ".r", color.r, modifications[0]);
45+
SetupPropertyModification(materialProp.name + ".g", color.g, modifications[1]);
46+
SetupPropertyModification(materialProp.name + ".b", color.b, modifications[2]);
47+
SetupPropertyModification(materialProp.name + ".a", color.a, modifications[3]);
48+
return modifications;
49+
}
50+
51+
static PropertyModification[] MaterialPropertyToPropertyModifications(MaterialProperty materialProp, Object target, Vector4 vec)
52+
{
53+
return MaterialPropertyToPropertyModifications(materialProp.name, target, vec);
54+
}
55+
56+
static PropertyModification[] MaterialPropertyToPropertyModifications(string name, Object target, Vector4 vec)
57+
{
58+
PropertyModification[] modifications = CreatePropertyModifications(4, target);
59+
SetupPropertyModification(name + ".x", vec.x, modifications[0]);
60+
SetupPropertyModification(name + ".y", vec.y, modifications[1]);
61+
SetupPropertyModification(name + ".z", vec.z, modifications[2]);
62+
SetupPropertyModification(name + ".w", vec.w, modifications[3]);
63+
return modifications;
64+
}
65+
66+
static bool ApplyMaterialModificationToAnimationRecording(PropertyModification[] modifications)
67+
{
68+
UndoPropertyModification[] undoModifications = new UndoPropertyModification[modifications.Length];
69+
for (int i = 0; i < undoModifications.Length; ++i)
70+
{
71+
undoModifications[i].previousValue = modifications[i];
72+
}
73+
74+
UndoPropertyModification[] ret = Undo.InvokePostprocessModifications(undoModifications);
75+
return ret.Length != modifications.Length;
76+
}
77+
78+
static public bool OverridePropertyColor(MaterialProperty materialProp, Renderer target, out Color color)
79+
{
80+
var propertyPaths = new List<string>();
81+
string basePropertyPath = kMaterialPrefix + materialProp.name;
82+
83+
if (materialProp.type == MaterialProperty.PropType.Texture)
84+
{
85+
propertyPaths.Add(basePropertyPath + "_ST.x");
86+
propertyPaths.Add(basePropertyPath + "_ST.y");
87+
propertyPaths.Add(basePropertyPath + "_ST.z");
88+
propertyPaths.Add(basePropertyPath + "_ST.w");
89+
}
90+
else if (materialProp.type == MaterialProperty.PropType.Color)
91+
{
92+
propertyPaths.Add(basePropertyPath + ".r");
93+
propertyPaths.Add(basePropertyPath + ".g");
94+
propertyPaths.Add(basePropertyPath + ".b");
95+
propertyPaths.Add(basePropertyPath + ".a");
96+
}
97+
else
98+
{
99+
propertyPaths.Add(basePropertyPath);
100+
}
101+
102+
if (propertyPaths.Exists(path => AnimationMode.IsPropertyAnimated(target, path)))
103+
{
104+
color = AnimationMode.animatedPropertyColor;
105+
if (AnimationMode.InAnimationRecording())
106+
color = AnimationMode.recordedPropertyColor;
107+
else if (propertyPaths.Exists(path => AnimationMode.IsPropertyCandidate(target, path)))
108+
color = AnimationMode.candidatePropertyColor;
109+
110+
return true;
111+
}
112+
113+
color = Color.white;
114+
return false;
115+
}
116+
117+
static public void SetupMaterialPropertyBlock(MaterialProperty materialProp, int changedMask, Renderer target)
118+
{
119+
MaterialPropertyBlock block = new MaterialPropertyBlock();
120+
target.GetPropertyBlock(block);
121+
materialProp.WriteToMaterialPropertyBlock(block, changedMask);
122+
target.SetPropertyBlock(block);
123+
}
124+
125+
static public void TearDownMaterialPropertyBlock(Renderer target)
126+
{
127+
target.SetPropertyBlock(null);
128+
}
129+
130+
static public bool ApplyMaterialModificationToAnimationRecording(MaterialProperty materialProp, int changedMask, Renderer target, object oldValue)
131+
{
132+
bool applied = false;
133+
switch (materialProp.type)
134+
{
135+
case MaterialProperty.PropType.Color:
136+
SetupMaterialPropertyBlock(materialProp, changedMask, target);
137+
applied = ApplyMaterialModificationToAnimationRecording(MaterialPropertyToPropertyModifications(materialProp, target, (Color)oldValue));
138+
if (!applied)
139+
TearDownMaterialPropertyBlock(target);
140+
return applied;
141+
142+
case MaterialProperty.PropType.Vector:
143+
SetupMaterialPropertyBlock(materialProp, changedMask, target);
144+
applied = ApplyMaterialModificationToAnimationRecording(MaterialPropertyToPropertyModifications(materialProp, target, (Vector4)oldValue));
145+
if (!applied)
146+
TearDownMaterialPropertyBlock(target);
147+
return applied;
148+
149+
case MaterialProperty.PropType.Float:
150+
case MaterialProperty.PropType.Range:
151+
SetupMaterialPropertyBlock(materialProp, changedMask, target);
152+
applied = ApplyMaterialModificationToAnimationRecording(MaterialPropertyToPropertyModifications(materialProp, target, (float)oldValue));
153+
if (!applied)
154+
TearDownMaterialPropertyBlock(target);
155+
return applied;
156+
157+
case MaterialProperty.PropType.Texture:
158+
{
159+
if (MaterialProperty.IsTextureOffsetAndScaleChangedMask(changedMask))
160+
{
161+
string name = materialProp.name + "_ST";
162+
SetupMaterialPropertyBlock(materialProp, changedMask, target);
163+
applied = ApplyMaterialModificationToAnimationRecording(MaterialPropertyToPropertyModifications(name, target, (Vector4)oldValue));
164+
if (!applied)
165+
TearDownMaterialPropertyBlock(target);
166+
return applied;
167+
}
168+
else
169+
return false;
170+
}
171+
}
172+
173+
return false;
174+
}
175+
176+
static public PropertyModification[] MaterialPropertyToPropertyModifications(MaterialProperty materialProp, Renderer target)
177+
{
178+
switch (materialProp.type)
179+
{
180+
case MaterialProperty.PropType.Color:
181+
return MaterialPropertyToPropertyModifications(materialProp, target, materialProp.colorValue);
182+
case MaterialProperty.PropType.Vector:
183+
return MaterialPropertyToPropertyModifications(materialProp, target, materialProp.vectorValue);
184+
case MaterialProperty.PropType.Float:
185+
case MaterialProperty.PropType.Range:
186+
return MaterialPropertyToPropertyModifications(materialProp, target, materialProp.floatValue);
187+
188+
case MaterialProperty.PropType.Texture:
189+
{
190+
string name = materialProp.name + "_ST";
191+
return MaterialPropertyToPropertyModifications(name, target, materialProp.vectorValue);
192+
}
193+
}
194+
195+
return null;
196+
}
197+
}
198+
}

Assets/Animation Window/Editor/Animation/MaterialAnimationUtility.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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using UnityEngine;
6+
using System.Collections;
7+
8+
[System.Serializable]
9+
internal class SerializedStringTable
10+
{
11+
[SerializeField] private string[] keys;
12+
[SerializeField] private int[] values;
13+
private Hashtable table;
14+
public Hashtable hashtable { get { SanityCheck(); return table; } }
15+
16+
public int Length { get { SanityCheck(); return keys.Length; } }
17+
18+
private void SanityCheck()
19+
{
20+
if (keys == null)
21+
{
22+
keys = new string[0];
23+
values = new int[0];
24+
}
25+
if (table == null)
26+
{
27+
table = new Hashtable();
28+
for (int i = 0; i < keys.Length; i++) table[keys[i]] = values[i];
29+
}
30+
}
31+
32+
private void SynchArrays()
33+
{
34+
keys = new string[table.Count];
35+
values = new int[table.Count];
36+
table.Keys.CopyTo(keys, 0);
37+
table.Values.CopyTo(values, 0);
38+
}
39+
40+
public void Set(string key, int value)
41+
{
42+
SanityCheck();
43+
table[key] = value;
44+
SynchArrays();
45+
}
46+
47+
public void Set(string key)
48+
{
49+
Set(key, 0);
50+
}
51+
52+
public bool Contains(string key)
53+
{
54+
SanityCheck();
55+
return table.Contains(key);
56+
}
57+
58+
public int Get(string key)
59+
{
60+
SanityCheck();
61+
if (!table.Contains(key)) return -1;
62+
return (int)table[key];
63+
}
64+
65+
public void Remove(string key)
66+
{
67+
SanityCheck();
68+
if (table.Contains(key)) table.Remove(key);
69+
SynchArrays();
70+
}
71+
}

Assets/Animation Window/Editor/Animation/SerializedStringTable.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)