using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; [Serializable] public class AMEventAction : AMAction { public MethodInfo methodInfo { get { if (this.component == null) { return null; } if (this.cachedMethodInfo != null) { return this.cachedMethodInfo; } if (this.methodName == null) { return null; } try { this.cachedMethodInfo = this.component.GetType().GetMethod(this.methodName); } catch { this.cachedMethodInfo = null; Debug.LogError("MonoBehaviorでなければなりません。"); } return this.cachedMethodInfo; } set { if (value != null) { this.methodName = value.Name; } else { this.methodName = null; } this.cachedMethodInfo = value; } } public override void execute(int frameRate, float delay, string trackId) { if (this.useSendMessage) { if (this.component == null || this.methodName == null) { return; } if (this.parameters == null || this.parameters.Count <= 0) { AMTween.SendMessage(this.component.gameObject, AMTween.Hash(new object[] { "delay", base.getWaitTime(frameRate, delay), "methodname", this.methodName })); } else { AMTween.SendMessage(this.component.gameObject, AMTween.Hash(new object[] { "trackid", trackId, "delay", base.getWaitTime(frameRate, delay), "methodname", this.methodName, "parameter", this.parameters[0].toObject() })); } return; } else { if (this.component == null || this.methodInfo == null) { return; } object[] array = new object[this.parameters.Count]; for (int i = 0; i < this.parameters.Count; i++) { if (this.parameters[i].isArray()) { this.setObjectInArray(ref array[i], this.parameters[i].lsArray); } else { array[i] = this.parameters[i].toObject(); } } if (array.Length <= 0) { array = null; } AMTween.InvokeMethod(this.component, AMTween.Hash(new object[] { "trackid", trackId, "delay", base.getWaitTime(frameRate, delay), "methodinfo", this.methodInfo, "parameters", array })); return; } } public void setObjectInArray(ref object obj, List lsArray) { if (lsArray.Count <= 0) { return; } int valueType = lsArray[0].valueType; if (valueType == 9) { string[] array = new string[lsArray.Count]; for (int i = 0; i < lsArray.Count; i++) { array[i] = (string)lsArray[i].toObject(); } obj = array; return; } if (valueType == 10) { char[] array2 = new char[lsArray.Count]; for (int j = 0; j < lsArray.Count; j++) { array2[j] = (char)lsArray[j].toObject(); } obj = array2; return; } if (valueType == 0 || valueType == 1) { int[] array3 = new int[lsArray.Count]; for (int k = 0; k < lsArray.Count; k++) { array3[k] = (int)lsArray[k].toObject(); } obj = array3; return; } if (valueType == 2 || valueType == 3) { float[] array4 = new float[lsArray.Count]; for (int l = 0; l < lsArray.Count; l++) { array4[l] = (float)lsArray[l].toObject(); } obj = array4; return; } if (valueType == 4) { Vector2[] array5 = new Vector2[lsArray.Count]; for (int m = 0; m < lsArray.Count; m++) { array5[m] = new Vector2(lsArray[m].val_vect2.x, lsArray[m].val_vect2.y); } obj = array5; return; } if (valueType == 5) { Vector3[] array6 = new Vector3[lsArray.Count]; for (int n = 0; n < lsArray.Count; n++) { array6[n] = new Vector3(lsArray[n].val_vect3.x, lsArray[n].val_vect3.y, lsArray[n].val_vect3.z); } obj = array6; return; } if (valueType == 6) { Vector4[] array7 = new Vector4[lsArray.Count]; for (int num = 0; num < lsArray.Count; num++) { array7[num] = new Vector4(lsArray[num].val_vect4.x, lsArray[num].val_vect4.y, lsArray[num].val_vect4.z, lsArray[num].val_vect4.w); } obj = array7; return; } if (valueType == 7) { Color[] array8 = new Color[lsArray.Count]; for (int num2 = 0; num2 < lsArray.Count; num2++) { array8[num2] = new Color(lsArray[num2].val_color.r, lsArray[num2].val_color.g, lsArray[num2].val_color.b, lsArray[num2].val_color.a); } obj = array8; return; } if (valueType == 8) { Rect[] array9 = new Rect[lsArray.Count]; for (int num3 = 0; num3 < lsArray.Count; num3++) { array9[num3] = new Rect(lsArray[num3].val_rect.x, lsArray[num3].val_rect.y, lsArray[num3].val_rect.width, lsArray[num3].val_rect.height); } obj = array9; return; } if (valueType == 11) { UnityEngine.Object[] array10 = new UnityEngine.Object[lsArray.Count]; for (int num4 = 0; num4 < lsArray.Count; num4++) { array10[num4] = (UnityEngine.Object)lsArray[num4].toObject(); } obj = array10; return; } if (valueType == 12) { object[] array11 = new object[lsArray.Count]; for (int num5 = 0; num5 < lsArray.Count; num5++) { this.setObjectInArray(ref array11[num5], lsArray[num5].lsArray); } obj = array11; return; } obj = null; } public string ToString(int codeLanguage, int frameRate, string methodInfoVarName) { if (this.component == null) { return null; } string text = string.Empty; if (!this.useSendMessage) { if (codeLanguage == 0) { string text2 = text; text = string.Concat(new object[] { text2, "AMTween.InvokeMethod(", methodInfoVarName, "CMP, AMTween.Hash (\"delay\", ", base.getWaitTime(frameRate, 0f), "f, \"methodinfo\", ", methodInfoVarName }); if (this.parameters != null && this.parameters.Count > 0) { text = text + ", \"parameters\", new object[]{" + this.parametersToString(codeLanguage) + "}"; } text += "));"; } else { string text2 = text; text = string.Concat(new object[] { text2, "AMTween.InvokeMethod(", methodInfoVarName, "CMP, {\"delay\": ", base.getWaitTime(frameRate, 0f), ", \"methodinfo\": ", methodInfoVarName }); if (this.parameters != null && this.parameters.Count > 0) { text = text + ", \"parameters\": [" + this.parametersToString(codeLanguage) + "]"; } text += "});"; } return text; } if (this.methodName == null) { return null; } if (codeLanguage == 0) { string text2 = text; text = string.Concat(new object[] { text2, "AMTween.SendMessage(obj.gameObject, AMTween.Hash (\"delay\", ", base.getWaitTime(frameRate, 0f), "f, \"methodname\", \"", this.methodName, "\"" }); if (this.parameters != null && this.parameters.Count > 0) { text = text + ", \"parameter\", " + this.parametersToString(codeLanguage); } text += "));"; } else { string text2 = text; text = string.Concat(new object[] { text2, "AMTween.SendMessage(obj.gameObject, {\"delay\": ", base.getWaitTime(frameRate, 0f), ", \"methodname\": \"", this.methodName, "\"" }); if (this.parameters != null && this.parameters.Count > 0) { text = text + ", \"parameter\": " + this.parametersToString(codeLanguage); } text += "});"; } return text; } private string parametersToString(int codeLanguage) { string text = string.Empty; for (int i = 0; i < this.parameters.Count; i++) { text += this.declareObjectToString(this.parameters[i].toObject(), codeLanguage); if (i < this.parameters.Count - 1) { text += ", "; } } return text; } private string declareObjectToString(object obj, int codeLanguage) { if (obj is string) { return "\"" + obj.ToString() + "\""; } if (obj is bool) { return obj.ToString().ToLower(); } if (obj is char) { return "'" + obj.ToString() + "'"; } if (codeLanguage == 0 && obj is decimal) { return obj.ToString() + "m"; } if (codeLanguage == 0 && obj is float) { return obj.ToString() + "f"; } if (obj is Vector2) { Vector2 vector = (Vector2)obj; if (codeLanguage == 0) { return string.Concat(new object[] { "new Vector2(", vector.x, "f, ", vector.y, "f)" }); } return string.Concat(new object[] { "Vector2(", vector.x, ", ", vector.y, ")" }); } else if (obj is Vector3) { Vector3 vector2 = (Vector3)obj; if (codeLanguage == 0) { return string.Concat(new object[] { "new Vector3(", vector2.x, "f, ", vector2.y, "f, ", vector2.z, "f)" }); } return string.Concat(new object[] { "Vector3(", vector2.x, ", ", vector2.y, ", ", vector2.z, ")" }); } else if (obj is Vector4) { Vector4 vector3 = (Vector4)obj; if (codeLanguage == 0) { return string.Concat(new object[] { "new Vector4(", vector3.x, "f, ", vector3.y, "f, ", vector3.z, "f, ", vector3.w, "f)" }); } return string.Concat(new object[] { "Vector4(", vector3.x, ", ", vector3.y, ", ", vector3.z, ", ", vector3.w, ")" }); } else if (obj is Color) { Color color = (Color)obj; if (codeLanguage == 0) { return string.Concat(new object[] { "new Color(", color.r, "f, ", color.g, "f, ", color.b, "f, ", color.a, "f)" }); } return string.Concat(new object[] { "Color(", color.r, ", ", color.g, ", ", color.b, ", ", color.a, ")" }); } else if (obj is Rect) { Rect rect = (Rect)obj; if (codeLanguage == 0) { return string.Concat(new object[] { "new Rect(", rect.x, "f, ", rect.y, "f, ", rect.width, "f, ", rect.height, "f)" }); } return string.Concat(new object[] { "Rect(", rect.x, ", ", rect.y, ", ", rect.width, ", ", rect.height, ")" }); } else { if (obj is GameObject) { return "GameObject.Find(\"" + (obj as GameObject).name + "\")"; } if (obj is Component) { return string.Concat(new string[] { "GameObject.Find(\"", (obj as Component).gameObject.name, "\").GetComponent(\"", (obj as Component).GetType().Name, "\")" }); } if (obj is Array) { Type elementType = (obj as Array).GetType().GetElementType(); string text = string.Empty; if (codeLanguage == 0) { text += "new "; if (elementType == typeof(string)) { text += "string"; } else if (elementType == typeof(bool)) { text += "bool"; } else if (elementType == typeof(char)) { text += "char"; } else if (elementType == typeof(decimal)) { text += "decimal"; } else if (elementType == typeof(float)) { text += "float"; } else if (elementType == typeof(bool)) { text += "bool"; } else if (elementType == typeof(int)) { text += "int"; } else if (elementType == typeof(long)) { text += "long"; } else if (elementType == typeof(double)) { text += "double"; } else if (elementType == typeof(Vector2)) { text += "Vector2"; } else if (elementType == typeof(Vector3)) { text += "Vector3"; } else if (elementType == typeof(Color)) { text += "Color"; } else if (elementType == typeof(Rect)) { text += "Rect"; } else if (elementType == typeof(GameObject)) { text += "GameObject"; } else if (elementType == typeof(Component)) { text += (obj as Component).GetType().Name; } else { text += "Object"; } text += "[]{"; } else { text += "["; } Array array = (Array)obj; for (int i = 0; i < array.Length; i++) { text += this.declareObjectToString(array.GetValue(i), codeLanguage); if (i < array.Length - 1) { text += ", "; } } if (codeLanguage == 0) { text += "}"; } else { text += "]"; } return text; } if (obj == null) { return null; } return obj.ToString(); } } public override AnimatorTimeline.JSONAction getJSONAction(int frameRate) { if (this.component == null) { return null; } AnimatorTimeline.JSONAction jsonaction = new AnimatorTimeline.JSONAction(); jsonaction.delay = base.getWaitTime(frameRate, 0f); jsonaction.go = this.component.gameObject.name; if (this.useSendMessage) { if (this.methodName == null) { return null; } jsonaction.method = "sendmessage"; jsonaction.strings = new string[] { this.methodName }; if (this.parameters != null && this.parameters.Count > 0) { jsonaction.eventParams = new AnimatorTimeline.JSONEventParameter[] { this.parameters[0].toJSON() }; } } else { if (this.methodInfo == null) { return null; } jsonaction.method = "invokemethod"; jsonaction.eventParams = new AnimatorTimeline.JSONEventParameter[this.parameters.Count]; for (int i = 0; i < this.parameters.Count; i++) { jsonaction.eventParams[i] = this.parameters[i].toJSON(); } jsonaction.strings = new string[] { this.component.GetType().Name, this.methodInfo.Name }; } return jsonaction; } public Component component; public bool useSendMessage; public List parameters; public string methodName; private MethodInfo cachedMethodInfo; }