123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- 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<AMEventParameter> 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<AMEventParameter> parameters;
- public string methodName;
- private MethodInfo cachedMethodInfo;
- }
|