Unity 2019.3.12f1を使用しています。
ビルドエラーCS0165で「未割り当てのローカル変数 'animation' の使用」と出てしまいました。
エラー箇所のコードの前後です。
private AnimationClip ParameterToAnimationClip(Image image, string[] parameters) { string[] ps = parameters[0].Replace(" ", "").Split(','); string path = animationsDirectory + SceneManager.GetActiveScene().name + "/" + image.name; AnimationClip prevAnimation = Resources.Load<AnimationClip>(path + "/" + ps[0]); AnimationClip animation; #if UNITY_EDITOR if (ps[3].Equals("Replay") && prevAnimation != null) return Instantiate(prevAnimation); animation = new AnimationClip(); Color startcolor = image.color; Vector3[] start = new Vector3[3]; start[0] = image.GetComponent<RectTransform>().sizeDelta; start[1] = image.GetComponent<RectTransform>().anchoredPosition; Color endcolor = startcolor; if (parameters[1] != "") endcolor = ParameterToColor(parameters[1]); Vector3[] end = new Vector3[3]; for (int i = 0; i < 2; i++) { if (parameters[i + 2] != "") end[i] = ParameterToVector3(parameters[i + 2]); else end[i] = start[i]; } AnimationCurve[,] curves = new AnimationCurve[4, 4]; if (ps[3].Equals("EaseInOut")) { curves[0, 0] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.r, float.Parse(ps[2]), endcolor.r); curves[0, 1] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.g, float.Parse(ps[2]), endcolor.g); curves[0, 2] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.b, float.Parse(ps[2]), endcolor.b); curves[0, 3] = AnimationCurve.EaseInOut(float.Parse(ps[1]), startcolor.a, float.Parse(ps[2]), endcolor.a); for (int i = 0; i < 2; i++) { curves[i + 1, 0] = AnimationCurve.EaseInOut(float.Parse(ps[1]), start[i].x, float.Parse(ps[2]), end[i].x); curves[i + 1, 1] = AnimationCurve.EaseInOut(float.Parse(ps[1]), start[i].y, float.Parse(ps[2]), end[i].y); curves[i + 1, 2] = AnimationCurve.EaseInOut(float.Parse(ps[1]), start[i].z, float.Parse(ps[2]), end[i].z); } } else { curves[0, 0] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.r, float.Parse(ps[2]), endcolor.r); curves[0, 1] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.g, float.Parse(ps[2]), endcolor.g); curves[0, 2] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.b, float.Parse(ps[2]), endcolor.b); curves[0, 3] = AnimationCurve.Linear(float.Parse(ps[1]), startcolor.a, float.Parse(ps[2]), endcolor.a); for (int i = 0; i < 2; i++) { curves[i + 1, 0] = AnimationCurve.Linear(float.Parse(ps[1]), start[i].x, float.Parse(ps[2]), end[i].x); curves[i + 1, 1] = AnimationCurve.Linear(float.Parse(ps[1]), start[i].y, float.Parse(ps[2]), end[i].y); curves[i + 1, 2] = AnimationCurve.Linear(float.Parse(ps[1]), start[i].z, float.Parse(ps[2]), end[i].z); } } string[] b1 = { "r", "g", "b", "a" }; for (int i = 0; i < 4; i++) { AnimationUtility.SetEditorCurve( animation, EditorCurveBinding.FloatCurve("", typeof(Image), "m_Color." + b1[i]), curves[0, i] ); } string[] a = { "m_SizeDelta", "m_AnchoredPosition" }; string[] b2 = { "x", "y", "z" }; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { AnimationUtility.SetEditorCurve( animation, EditorCurveBinding.FloatCurve("", typeof(RectTransform), a[i] + "." + b2[j]), curves[i + 1, j] ); } } if (!Directory.Exists("Assets/Resources/" + path)) Directory.CreateDirectory("Assets/Resources/" + path); AssetDatabase.CreateAsset(animation, "Assets/Resources/" + path + "/" + ps[0] + ".anim"); AssetDatabase.ImportAsset("Assets/Resources/" + path + "/" + ps[0] + ".anim"); #elif UNITY_STANDALONE animation = prevAnimation; #endif return Instantiate(animation); }
の最後のanimationでエラーが出てしまいました。
animationのローカル変数が初期化されていないらしいのですが、どう書けばいいのか分かりません。
回答4件
あなたの回答
tips
プレビュー