質問編集履歴
2
コードの全文
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,7 +3,79 @@
|
|
3
3
|
|
4
4
|
エラー箇所のコードの前後です。
|
5
5
|
```
|
6
|
+
private AnimationClip ParameterToAnimationClip(Image image, string[] parameters)
|
7
|
+
{
|
8
|
+
string[] ps = parameters[0].Replace(" ", "").Split(',');
|
9
|
+
string path = animationsDirectory + SceneManager.GetActiveScene().name + "/" + image.name;
|
10
|
+
AnimationClip prevAnimation = Resources.Load<AnimationClip>(path + "/" + ps[0]);
|
11
|
+
AnimationClip animation;
|
12
|
+
#if UNITY_EDITOR
|
13
|
+
if (ps[3].Equals("Replay") && prevAnimation != null)
|
14
|
+
return Instantiate(prevAnimation);
|
15
|
+
animation = new AnimationClip();
|
16
|
+
Color startcolor = image.color;
|
17
|
+
Vector3[] start = new Vector3[3];
|
18
|
+
start[0] = image.GetComponent<RectTransform>().sizeDelta;
|
19
|
+
start[1] = image.GetComponent<RectTransform>().anchoredPosition;
|
20
|
+
Color endcolor = startcolor;
|
21
|
+
if (parameters[1] != "") endcolor = ParameterToColor(parameters[1]);
|
22
|
+
Vector3[] end = new Vector3[3];
|
23
|
+
for (int i = 0; i < 2; i++)
|
24
|
+
{
|
25
|
+
if (parameters[i + 2] != "")
|
26
|
+
end[i] = ParameterToVector3(parameters[i + 2]);
|
27
|
+
else end[i] = start[i];
|
28
|
+
}
|
29
|
+
AnimationCurve[,] curves = new AnimationCurve[4, 4];
|
30
|
+
if (ps[3].Equals("EaseInOut"))
|
31
|
+
{
|
32
|
+
curves[0, 0] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.r, float.Parse(ps[2]), endcolor.r);
|
33
|
+
curves[0, 1] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.g, float.Parse(ps[2]), endcolor.g);
|
34
|
+
curves[0, 2] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.b, float.Parse(ps[2]), endcolor.b);
|
35
|
+
curves[0, 3] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.a, float.Parse(ps[2]), endcolor.a);
|
36
|
+
for (int i = 0; i < 2; i++)
|
37
|
+
{
|
38
|
+
curves[i + 1, 0] = AnimationCurve.EaseInOut(float.Parse(ps[1]), start[i].x, float.Parse(ps[2]), end[i].x);
|
39
|
+
curves[i + 1, 1] = AnimationCurve.EaseInOut(float.Parse(ps[1]), start[i].y, float.Parse(ps[2]), end[i].y);
|
40
|
+
curves[i + 1, 2] = AnimationCurve.EaseInOut(float.Parse(ps[1]), start[i].z, float.Parse(ps[2]), end[i].z);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
else
|
44
|
+
{
|
45
|
+
curves[0, 0] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.r, float.Parse(ps[2]), endcolor.r);
|
46
|
+
curves[0, 1] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.g, float.Parse(ps[2]), endcolor.g);
|
47
|
+
curves[0, 2] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.b, float.Parse(ps[2]), endcolor.b);
|
48
|
+
curves[0, 3] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.a, float.Parse(ps[2]), endcolor.a);
|
49
|
+
for (int i = 0; i < 2; i++)
|
50
|
+
{
|
51
|
+
curves[i + 1, 0] = AnimationCurve.Linear(float.Parse(ps[1]), start[i].x, float.Parse(ps[2]), end[i].x);
|
52
|
+
curves[i + 1, 1] = AnimationCurve.Linear(float.Parse(ps[1]), start[i].y, float.Parse(ps[2]), end[i].y);
|
53
|
+
curves[i + 1, 2] = AnimationCurve.Linear(float.Parse(ps[1]), start[i].z, float.Parse(ps[2]), end[i].z);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
string[] b1 = { "r", "g", "b", "a" };
|
57
|
+
for (int i = 0; i < 4; i++)
|
58
|
+
{
|
59
|
+
AnimationUtility.SetEditorCurve(
|
60
|
+
animation,
|
61
|
+
EditorCurveBinding.FloatCurve("", typeof(Image), "m_Color." + b1[i]),
|
62
|
+
curves[0, i]
|
63
|
+
);
|
64
|
+
}
|
65
|
+
string[] a = { "m_SizeDelta", "m_AnchoredPosition" };
|
66
|
+
string[] b2 = { "x", "y", "z" };
|
67
|
+
for (int i = 0; i < 2; i++)
|
68
|
+
{
|
69
|
+
for (int j = 0; j < 3; j++)
|
70
|
+
{
|
71
|
+
AnimationUtility.SetEditorCurve(
|
72
|
+
animation,
|
73
|
+
EditorCurveBinding.FloatCurve("", typeof(RectTransform), a[i] + "." + b2[j]),
|
74
|
+
curves[i + 1, j]
|
75
|
+
);
|
76
|
+
}
|
77
|
+
}
|
6
|
-
if (!Directory.Exists("Assets/Resources/" + path))
|
78
|
+
if (!Directory.Exists("Assets/Resources/" + path))
|
7
79
|
Directory.CreateDirectory("Assets/Resources/" + path);
|
8
80
|
AssetDatabase.CreateAsset(animation, "Assets/Resources/" + path + "/" + ps[0] + ".anim");
|
9
81
|
AssetDatabase.ImportAsset("Assets/Resources/" + path + "/" + ps[0] + ".anim");
|
1
コードを見やすくする
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
ビルドエラーCS0165で「未割り当てのローカル変数 'animation' の使用」と出てしまいました。
|
3
3
|
|
4
4
|
エラー箇所のコードの前後です。
|
5
|
-
|
5
|
+
```
|
6
|
-
|
6
|
+
if (!Directory.Exists("Assets/Resources/" + path))
|
7
7
|
Directory.CreateDirectory("Assets/Resources/" + path);
|
8
8
|
AssetDatabase.CreateAsset(animation, "Assets/Resources/" + path + "/" + ps[0] + ".anim");
|
9
9
|
AssetDatabase.ImportAsset("Assets/Resources/" + path + "/" + ps[0] + ".anim");
|
@@ -12,7 +12,7 @@
|
|
12
12
|
#endif
|
13
13
|
return Instantiate(animation);
|
14
14
|
}
|
15
|
+
```
|
15
16
|
|
16
|
-
|
17
17
|
の最後のanimationでエラーが出てしまいました。
|
18
18
|
animationのローカル変数が初期化されていないらしいのですが、どう書けばいいのか分かりません。
|