using System; using System.Collections.Generic; using System.IO; using System.Text; using UnityEngine; using wf; [Serializable] public class AMEventParameter : ScriptableObject { public bool setBool(bool val_bool) { if (this.val_bool != val_bool) { this.val_bool = val_bool; return true; } return false; } public bool setInt(int val_int) { if (this.val_int != val_int) { this.val_int = val_int; return true; } return false; } public bool setFloat(float val_float) { if (this.val_float != val_float) { this.val_float = val_float; return true; } return false; } public bool setVector2(Vector2 val_vect2) { if (this.val_vect2 != val_vect2) { this.val_vect2 = val_vect2; return true; } return false; } public bool setVector3(Vector3 val_vect3) { if (this.val_vect3 != val_vect3) { this.val_vect3 = val_vect3; return true; } return false; } public bool setVector4(Vector4 val_vect4) { if (this.val_vect4 != val_vect4) { this.val_vect4 = val_vect4; return true; } return false; } public bool setColor(Color val_color) { if (this.val_color != val_color) { this.val_color = val_color; return true; } return false; } public bool setRect(Rect val_rect) { if (this.val_rect != val_rect) { this.val_rect = val_rect; return true; } return false; } public bool setString(string val_string) { if (this.val_string != val_string) { this.val_string = val_string; return true; } return false; } public bool setObject(UnityEngine.Object val_obj) { if (this.val_obj != val_obj) { this.val_obj = val_obj; return true; } return false; } public Type getParamType() { if (this.valueType == 13) { return typeof(bool); } if (this.valueType == 0 || this.valueType == 1) { return typeof(int); } if (this.valueType == 2 || this.valueType == 3) { return typeof(float); } if (this.valueType == 4) { return typeof(Vector2); } if (this.valueType == 5) { return typeof(Vector3); } if (this.valueType == 6) { return typeof(Vector4); } if (this.valueType == 7) { return typeof(Color); } if (this.valueType == 8) { return typeof(Rect); } if (this.valueType == 11) { return typeof(UnityEngine.Object); } if (this.valueType == 12) { if (this.lsArray.Count <= 0) { return typeof(object[]); } return this.lsArray[0].getParamType(); } else { if (this.valueType == 9) { return typeof(string); } if (this.valueType == 10) { return typeof(char); } Debug.LogError("Animator: Type not found for Event Parameter."); return typeof(object); } } public void destroy() { foreach (AMEventParameter ameventParameter in this.lsArray) { ameventParameter.destroy(); } UnityEngine.Object.DestroyImmediate(this); } public string getStringValue() { if (this.valueType == 13) { return this.val_bool.ToString().ToLower(); } if (this.valueType == 9) { return "\"" + this.val_string + "\""; } if (this.valueType == 10) { if (this.val_string == null || this.val_string.Length <= 0) { return "''"; } return "'" + this.val_string[0] + "'"; } else { if (this.valueType == 0 || this.valueType == 1) { return this.val_int.ToString(); } if (this.valueType == 2 || this.valueType == 3) { return this.val_float.ToString(); } if (this.valueType == 4) { return this.val_vect2.ToString(); } if (this.valueType == 5) { return this.val_vect3.ToString(); } if (this.valueType == 6) { return this.val_vect4.ToString(); } if (this.valueType == 7) { return this.val_color.ToString(); } if (this.valueType == 8) { return this.val_rect.ToString(); } if (this.valueType == 11) { if (!this.val_obj) { return "None"; } return this.val_obj.name; } else { if (this.valueType == 12) { return "Array"; } Debug.LogError("Animator: Type not found for Event Parameter."); return "object"; } } } public void setValueType(Type t) { if (t == typeof(bool)) { this.valueType = 13; } else if (t == typeof(string)) { this.valueType = 9; } else if (t == typeof(char)) { this.valueType = 10; } else if (t == typeof(int)) { this.valueType = 0; } else if (t == typeof(long)) { this.valueType = 1; } else if (t == typeof(float)) { this.valueType = 2; } else if (t == typeof(double)) { this.valueType = 3; } else if (t == typeof(Vector2)) { this.valueType = 4; } else if (t == typeof(Vector3)) { this.valueType = 5; } else if (t == typeof(Vector4)) { this.valueType = 6; } else if (t == typeof(Color)) { this.valueType = 7; } else if (t == typeof(Rect)) { this.valueType = 8; } else if (t.IsArray) { this.valueType = 12; } else if (t.BaseType.BaseType == typeof(UnityEngine.Object)) { this.valueType = 11; } else { this.valueType = 11; } } public object toObject() { if (this.valueType == 13) { return this.val_bool; } if (this.valueType == 9) { return this.val_string; } if (this.valueType == 10) { if (this.val_string == null || this.val_string.Length <= 0) { return '\0'; } return this.val_string[0]; } else { if (this.valueType == 0 || this.valueType == 1) { return this.val_int; } if (this.valueType == 2 || this.valueType == 3) { return this.val_float; } if (this.valueType == 4) { return this.val_vect2; } if (this.valueType == 5) { return this.val_vect3; } if (this.valueType == 6) { return this.val_vect4; } if (this.valueType == 7) { return this.val_color; } if (this.valueType == 8) { return this.val_rect; } if (this.valueType == 11) { return this.val_obj; } if (this.valueType == 12 && this.lsArray.Count > 0) { if (this.lsArray[0].valueType == 13) { bool[] array = new bool[this.lsArray.Count]; for (int i = 0; i < this.lsArray.Count; i++) { array[i] = this.lsArray[i].val_bool; } return array; } if (this.lsArray[0].valueType == 9) { string[] array2 = new string[this.lsArray.Count]; for (int j = 0; j < this.lsArray.Count; j++) { array2[j] = this.lsArray[j].val_string; } return array2; } if (this.lsArray[0].valueType == 10) { char[] array3 = new char[this.lsArray.Count]; for (int k = 0; k < this.lsArray.Count; k++) { array3[k] = this.lsArray[k].val_string[0]; } return array3; } if (this.lsArray[0].valueType == 0 || this.lsArray[0].valueType == 1) { int[] array4 = new int[this.lsArray.Count]; for (int l = 0; l < this.lsArray.Count; l++) { array4[l] = this.lsArray[l].val_int; } return array4; } if (this.lsArray[0].valueType == 2 || this.lsArray[0].valueType == 3) { float[] array5 = new float[this.lsArray.Count]; for (int m = 0; m < this.lsArray.Count; m++) { array5[m] = this.lsArray[m].val_float; } return array5; } if (this.lsArray[0].valueType == 4) { Vector2[] array6 = new Vector2[this.lsArray.Count]; for (int n = 0; n < this.lsArray.Count; n++) { array6[n] = this.lsArray[n].val_vect2; } return array6; } if (this.lsArray[0].valueType == 5) { Vector3[] array7 = new Vector3[this.lsArray.Count]; for (int num = 0; num < this.lsArray.Count; num++) { array7[num] = this.lsArray[num].val_vect3; } return array7; } if (this.lsArray[0].valueType == 6) { Vector4[] array8 = new Vector4[this.lsArray.Count]; for (int num2 = 0; num2 < this.lsArray.Count; num2++) { array8[num2] = this.lsArray[num2].val_vect4; } return array8; } if (this.lsArray[0].valueType == 7) { Color[] array9 = new Color[this.lsArray.Count]; for (int num3 = 0; num3 < this.lsArray.Count; num3++) { array9[num3] = this.lsArray[num3].val_color; } return array9; } if (this.lsArray[0].valueType == 8) { Rect[] array10 = new Rect[this.lsArray.Count]; for (int num4 = 0; num4 < this.lsArray.Count; num4++) { array10[num4] = this.lsArray[num4].val_rect; } return array10; } if (this.lsArray[0].valueType == 11) { UnityEngine.Object[] array11 = new UnityEngine.Object[this.lsArray.Count]; for (int num5 = 0; num5 < this.lsArray.Count; num5++) { array11[num5] = this.lsArray[num5].val_obj; } return array11; } } Debug.LogError("Animator: Type not found for Event Parameter."); return null; } } public AnimatorTimeline.JSONEventParameter toJSON() { AnimatorTimeline.JSONEventParameter jsoneventParameter = new AnimatorTimeline.JSONEventParameter(); jsoneventParameter.valueType = this.valueType; if (this.valueType == 13) { jsoneventParameter.val_bool = this.val_bool; } if (this.valueType == 9) { jsoneventParameter.val_string = this.val_string; } if (this.valueType == 10) { if (this.val_string == null || this.val_string.Length <= 0) { jsoneventParameter.val_string = "\0"; } jsoneventParameter.val_string = string.Empty + this.val_string[0]; } if (this.valueType == 0 || this.valueType == 1) { jsoneventParameter.val_int = this.val_int; } if (this.valueType == 2 || this.valueType == 3) { jsoneventParameter.val_float = this.val_float; } if (this.valueType == 4) { AnimatorTimeline.JSONVector2 jsonvector = new AnimatorTimeline.JSONVector2(); jsonvector.setValue(this.val_vect2); jsoneventParameter.val_vect2 = jsonvector; } if (this.valueType == 5) { AnimatorTimeline.JSONVector3 jsonvector2 = new AnimatorTimeline.JSONVector3(); jsonvector2.setValue(this.val_vect3); jsoneventParameter.val_vect3 = jsonvector2; } if (this.valueType == 6) { AnimatorTimeline.JSONVector4 jsonvector3 = new AnimatorTimeline.JSONVector4(); jsonvector3.setValue(this.val_vect4); jsoneventParameter.val_vect4 = jsonvector3; } if (this.valueType == 7) { AnimatorTimeline.JSONColor jsoncolor = new AnimatorTimeline.JSONColor(); jsoncolor.setValue(this.val_color); jsoneventParameter.val_color = jsoncolor; } if (this.valueType == 8) { AnimatorTimeline.JSONRect jsonrect = new AnimatorTimeline.JSONRect(); jsonrect.setValue(this.val_rect); jsoneventParameter.val_rect = jsonrect; } if (this.valueType == 11) { if (this.val_obj.GetType() != typeof(GameObject)) { jsoneventParameter.val_obj_extra = this.val_obj.name; jsoneventParameter.val_obj = this.val_obj.GetType().Name; } else { jsoneventParameter.val_obj_extra = null; jsoneventParameter.val_obj = this.val_obj.name; } } if (this.valueType == 12 && this.lsArray.Count > 0) { AnimatorTimeline.JSONEventParameter[] array = new AnimatorTimeline.JSONEventParameter[this.lsArray.Count]; for (int i = 0; i < this.lsArray.Count; i++) { array[i] = this.lsArray[i].toJSON(); } jsoneventParameter.array = array; } return jsoneventParameter; } public object[] toArray() { object[] array = new object[this.lsArray.Count]; for (int i = 0; i < this.lsArray.Count; i++) { array[i] = this.lsArray[i].toObject(); } return array; } public bool isArray() { return this.lsArray.Count > 0; } public AMEventParameter CreateClone() { AMEventParameter ameventParameter = ScriptableObject.CreateInstance(); ameventParameter.val_bool = this.val_bool; ameventParameter.valueType = this.valueType; ameventParameter.val_int = this.val_int; ameventParameter.val_float = this.val_float; ameventParameter.val_vect2 = this.val_vect2; ameventParameter.val_vect3 = this.val_vect3; ameventParameter.val_vect4 = this.val_vect4; ameventParameter.val_color = this.val_color; ameventParameter.val_rect = this.val_rect; ameventParameter.val_string = this.val_string; ameventParameter.val_obj = this.val_obj; foreach (AMEventParameter ameventParameter2 in this.lsArray) { ameventParameter.lsArray.Add(ameventParameter2.CreateClone()); } return ameventParameter; } public static AMEventParameter CreateFromStringData(string data_text) { AMEventParameter ameventParameter = ScriptableObject.CreateInstance(); string @string = Encoding.GetEncoding("UTF-8").GetString(Convert.FromBase64String(data_text)); string[] array = @string.Split(new char[] { ':' }); int num = 0; ameventParameter.val_bool = bool.Parse(array[num++]); ameventParameter.valueType = int.Parse(array[num++]); ameventParameter.val_int = int.Parse(array[num++]); ameventParameter.val_float = float.Parse(array[num++]); ameventParameter.val_vect2 = Parse.Vector2(array[num++]); ameventParameter.val_vect3 = Parse.Vector3(array[num++]); ameventParameter.val_vect4 = Parse.Vector4(array[num++]); ameventParameter.val_color = Parse.Color(array[num++]); ameventParameter.val_rect = default(Rect); ameventParameter.val_rect.x = float.Parse(array[num++]); ameventParameter.val_rect.y = float.Parse(array[num++]); ameventParameter.val_rect.width = float.Parse(array[num++]); ameventParameter.val_rect.height = float.Parse(array[num++]); ameventParameter.val_string = array[num++]; ameventParameter.val_obj = null; ameventParameter.lsArray.Clear(); int num2 = int.Parse(array[num++]); for (int i = 0; i < num2; i++) { ameventParameter.lsArray.Add(AMEventParameter.CreateFromStringData(array[num++])); } return ameventParameter; } public string ToStringData() { List list = new List(); list.Add(this.val_bool.ToString()); list.Add(this.valueType.ToString()); list.Add(this.val_int.ToString()); list.Add(this.val_float.ToString()); list.Add(this.val_vect2.ToString("G")); list.Add(this.val_vect3.ToString("G")); list.Add(this.val_vect4.ToString("G")); list.Add(this.val_color.ToString("G")); list.Add(this.val_rect.x.ToString()); list.Add(this.val_rect.y.ToString()); list.Add(this.val_rect.width.ToString()); list.Add(this.val_rect.height.ToString()); list.Add(this.val_string); if (this.val_obj != null) { Debug.LogError("AMEventParameter::ToStringData\nオブジェクトの引数には対応していません\nnullで処理します"); } list.Add(this.lsArray.Count.ToString()); for (int i = 0; i < this.lsArray.Count; i++) { list.Add(this.lsArray[i].ToStringData()); } string text = list[0]; for (int j = 1; j < list.Count; j++) { text = text + ":" + list[j]; } return Convert.ToBase64String(Encoding.GetEncoding("UTF-8").GetBytes(text)); } public List getDependencies() { List list = new List(); if (this.valueType == 11 && this.val_obj) { if (this.val_obj is GameObject) { list.Add((GameObject)this.val_obj); } else { list.Add((this.val_obj as Component).gameObject); } } else if (this.valueType == 12 && this.lsArray.Count > 0 && this.lsArray[0].valueType == 11) { foreach (AMEventParameter ameventParameter in this.lsArray) { if (ameventParameter.val_obj) { if (ameventParameter.val_obj is GameObject) { list.Add((GameObject)ameventParameter.val_obj); } else { list.Add((ameventParameter.val_obj as Component).gameObject); } } } } return list; } public bool updateDependencies(List newReferences, List oldReferences) { bool result = false; if (this.valueType == 11 && this.val_obj) { for (int i = 0; i < oldReferences.Count; i++) { if (this.val_obj is GameObject) { if (oldReferences[i] == this.val_obj) { this.val_obj = newReferences[i]; result = true; break; } } else if (oldReferences[i] == (this.val_obj as Component).gameObject) { this.val_obj = newReferences[i].GetComponent(this.val_obj.GetType()); result = true; break; } } } else if (this.valueType == 12 && this.lsArray.Count > 0 && this.lsArray[0].valueType == 11) { for (int j = 0; j < oldReferences.Count; j++) { foreach (AMEventParameter ameventParameter in this.lsArray) { if (ameventParameter.val_obj) { if (ameventParameter.val_obj is GameObject) { if (oldReferences[j] == ameventParameter.val_obj) { ameventParameter.val_obj = newReferences[j]; result = true; break; } } else if (oldReferences[j] == (ameventParameter.val_obj as Component).gameObject) { ameventParameter.val_obj = newReferences[j].GetComponent(ameventParameter.val_obj.GetType()); result = true; break; } } } } } return result; } public void Write(BinaryWriter binary) { binary.Write(this.valueType); if (this.isArray()) { binary.Write(this.lsArray.Count); for (int i = 0; i < this.lsArray.Count; i++) { this.lsArray[i].Write(binary); } } else { AMEventParameter.ValueType valueType = (AMEventParameter.ValueType)this.valueType; if (valueType == AMEventParameter.ValueType.Integer || valueType == AMEventParameter.ValueType.Long) { binary.Write(this.val_int); } else if (valueType == AMEventParameter.ValueType.Float || valueType == AMEventParameter.ValueType.Double) { binary.Write(this.val_float); } else if (valueType == AMEventParameter.ValueType.Vector2) { binary.Write(this.val_vect2.x); binary.Write(this.val_vect2.y); } else if (valueType == AMEventParameter.ValueType.Vector3) { binary.Write(this.val_vect3.x); binary.Write(this.val_vect3.y); binary.Write(this.val_vect3.z); } else if (valueType == AMEventParameter.ValueType.Vector4) { binary.Write(this.val_vect4.x); binary.Write(this.val_vect4.y); binary.Write(this.val_vect4.z); binary.Write(this.val_vect4.w); } else if (valueType == AMEventParameter.ValueType.Color) { binary.Write(this.val_color.a); binary.Write(this.val_color.r); binary.Write(this.val_color.g); binary.Write(this.val_color.b); } else if (valueType == AMEventParameter.ValueType.Rect) { binary.Write(this.val_rect.xMin); binary.Write(this.val_rect.xMax); binary.Write(this.val_rect.yMin); binary.Write(this.val_rect.yMax); } else if (valueType == AMEventParameter.ValueType.String || valueType == AMEventParameter.ValueType.Char) { if (this.val_string == null) { this.val_string = string.Empty; } binary.Write(this.val_string); } else if (valueType == AMEventParameter.ValueType.Boolean) { binary.Write(this.val_bool); } else if (valueType == AMEventParameter.ValueType.Object) { string value = string.Empty; GameObject gameObject = this.val_obj as GameObject; NDebug.Assert(gameObject != null, "AMEventParameter error type."); value = UTY.GetObjectTreePath(gameObject); binary.Write(value); } } } public void Read(BinaryReader binary) { this.val_bool = false; this.valueType = 0; this.val_int = 0; this.val_float = 0f; this.val_vect2 = Vector2.zero; this.val_vect3 = Vector3.zero; this.val_vect4 = Vector4.zero; this.val_color = default(Color); this.val_rect = default(Rect); this.val_string = null; this.val_obj = null; this.lsArray.Clear(); this.valueType = binary.ReadInt32(); if (this.valueType == 12) { int num = binary.ReadInt32(); for (int i = 0; i < num; i++) { AMEventParameter ameventParameter = new AMEventParameter(); ameventParameter.Read(binary); this.lsArray.Add(ameventParameter); } } else { AMEventParameter.ValueType valueType = (AMEventParameter.ValueType)this.valueType; if (valueType == AMEventParameter.ValueType.Integer || valueType == AMEventParameter.ValueType.Long) { this.val_int = binary.ReadInt32(); } else if (valueType == AMEventParameter.ValueType.Float || valueType == AMEventParameter.ValueType.Double) { this.val_float = binary.ReadSingle(); } else if (valueType == AMEventParameter.ValueType.Vector2) { this.val_vect2.x = binary.ReadSingle(); this.val_vect2.y = binary.ReadSingle(); } else if (valueType == AMEventParameter.ValueType.Vector3) { this.val_vect3.x = binary.ReadSingle(); this.val_vect3.y = binary.ReadSingle(); this.val_vect3.z = binary.ReadSingle(); } else if (valueType == AMEventParameter.ValueType.Vector4) { this.val_vect4.x = binary.ReadSingle(); this.val_vect4.y = binary.ReadSingle(); this.val_vect4.z = binary.ReadSingle(); this.val_vect4.w = binary.ReadSingle(); } else if (valueType == AMEventParameter.ValueType.Color) { this.val_color.a = binary.ReadSingle(); this.val_color.r = binary.ReadSingle(); this.val_color.g = binary.ReadSingle(); this.val_color.b = binary.ReadSingle(); } else if (valueType == AMEventParameter.ValueType.Rect) { this.val_rect.xMin = binary.ReadSingle(); this.val_rect.xMax = binary.ReadSingle(); this.val_rect.yMin = binary.ReadSingle(); this.val_rect.yMax = binary.ReadSingle(); } else if (valueType == AMEventParameter.ValueType.String || valueType == AMEventParameter.ValueType.Char) { this.val_string = binary.ReadString(); } else if (valueType == AMEventParameter.ValueType.Boolean) { this.val_bool = binary.ReadBoolean(); } else if (valueType == AMEventParameter.ValueType.Object) { string name = binary.ReadString(); this.val_obj = GameObject.Find(name); } } } public bool val_bool; public int valueType; public int val_int; public float val_float; public Vector2 val_vect2; public Vector3 val_vect3; public Vector4 val_vect4; public Color val_color; public Rect val_rect; public string val_string; public UnityEngine.Object val_obj; public List lsArray = new List(); public enum ValueType { Integer, Long, Float, Double, Vector2, Vector3, Vector4, Color, Rect, String, Char, Object, Array, Boolean } }