123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using JsonFx.Json;
- using UnityEngine;
- public class AnimatorTimeline : MonoBehaviour
- {
- public static Component aData
- {
- get
- {
- if (AnimatorTimeline._aData != null)
- {
- return AnimatorTimeline._aData;
- }
- AnimatorTimeline.cachedInvoker = null;
- GameObject gameObject = GameObject.Find("AnimatorData");
- if (gameObject)
- {
- AnimatorTimeline._aData = gameObject.GetComponent("AnimatorData");
- }
- if (!AnimatorTimeline._aData)
- {
- Debug.LogWarning("Animator: Could not find AnimatorData component.");
- }
- return AnimatorTimeline._aData;
- }
- }
- private static MethodInfo invoker
- {
- get
- {
- if (AnimatorTimeline.cachedInvoker == null)
- {
- AnimatorTimeline.cachedInvoker = AnimatorTimeline.aData.GetType().GetMethod("Invoker");
- }
- return AnimatorTimeline.cachedInvoker;
- }
- }
- public static bool isPlaying
- {
- get
- {
- return (bool)AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 0
- }
- });
- }
- set
- {
- Debug.LogWarning("Animator: Variable Animator.isPlaying is read-only!");
- }
- }
- public static bool isPaused
- {
- get
- {
- return (bool)AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 12
- }
- });
- }
- set
- {
- Debug.LogWarning("Animator: Variable Animator.isPaused is read-only!");
- }
- }
- public static string nowPlayingTake
- {
- get
- {
- return (string)AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 1
- }
- });
- }
- set
- {
- Debug.LogWarning("Animator: Variable Animator.nowPlayingTake is read-only!");
- }
- }
- public static float runningTime
- {
- get
- {
- return (float)AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 10
- }
- });
- }
- set
- {
- Debug.LogWarning("Animator: Variable Animator.runningTime is read-only!");
- }
- }
- public static float totalTime
- {
- get
- {
- return (float)AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 11
- }
- });
- }
- set
- {
- Debug.LogWarning("Animator: Variable Animator.totalTime is read-only!");
- }
- }
- public static void Play(string takeName, bool loop = false)
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 2,
- takeName,
- loop
- }
- });
- }
- }
- public static void Stop()
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 3
- }
- });
- }
- }
- public static void Pause()
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 4
- }
- });
- }
- }
- public static void Resume()
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 5
- }
- });
- }
- }
- public static void PlayFromTime(string takeName, float time, bool loop = false)
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 6,
- takeName,
- time,
- loop
- }
- });
- }
- }
- public static void PlayFromFrame(string takeName, int frame, bool loop = false)
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 7,
- takeName,
- frame,
- loop
- }
- });
- }
- }
- public static void PreviewFrame(string takeName, float frame)
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 8,
- takeName,
- frame
- }
- });
- }
- }
- public static void PreviewTime(string takeName, float time)
- {
- if (AnimatorTimeline.aData)
- {
- AnimatorTimeline.invoker.Invoke(AnimatorTimeline.aData, new object[]
- {
- new object[]
- {
- 9,
- takeName,
- time
- }
- });
- }
- }
- public static void ParseJSON(string textAssetName)
- {
- TextAsset textAsset = (TextAsset)Resources.Load(textAssetName);
- if (!textAsset)
- {
- Debug.LogError("Animator: Could not find TextAsset '" + textAssetName + ".txt', make sure it's placed in a Resources folder!");
- }
- AnimatorTimeline.ParseJSON(textAsset);
- }
- private static void ParseJSON(TextAsset json)
- {
- AnimatorTimeline.ParseJSONString(json.ToString());
- }
- public static void ParseJSONString(string json)
- {
- AnimatorTimeline.JSONTake j = JsonReader.Deserialize<AnimatorTimeline.JSONTake>(json);
- if (!AnimatorTimeline.parseJSONTake(j))
- {
- Debug.LogWarning("Animator: Error parsing JSON");
- }
- }
- private static AnimatorTimeline.JSONVector3[] getJSONVector3Array(Vector3[] v)
- {
- List<AnimatorTimeline.JSONVector3> list = new List<AnimatorTimeline.JSONVector3>();
- foreach (Vector3 value in v)
- {
- AnimatorTimeline.JSONVector3 jsonvector = new AnimatorTimeline.JSONVector3();
- jsonvector.setValue(value);
- list.Add(jsonvector);
- }
- return list.ToArray();
- }
- private static bool setInitialValue(AnimatorTimeline.JSONInit init)
- {
- string type = init.type;
- if (type != null)
- {
- if (AnimatorTimeline.<>f__switch$map1 == null)
- {
- AnimatorTimeline.<>f__switch$map1 = new Dictionary<string, int>(13)
- {
- {
- "position",
- 0
- },
- {
- "rotation",
- 1
- },
- {
- "orientation",
- 2
- },
- {
- "propertymorph",
- 3
- },
- {
- "propertyint",
- 4
- },
- {
- "propertylong",
- 5
- },
- {
- "propertyfloat",
- 6
- },
- {
- "propertydouble",
- 7
- },
- {
- "propertyvect2",
- 8
- },
- {
- "propertyvect3",
- 9
- },
- {
- "propertycolor",
- 10
- },
- {
- "propertyrect",
- 11
- },
- {
- "cameraswitcher",
- 12
- }
- };
- }
- int num;
- if (AnimatorTimeline.<>f__switch$map1.TryGetValue(type, out num))
- {
- switch (num)
- {
- case 0:
- if (init.position == null || init.go == null)
- {
- return false;
- }
- AnimatorTimeline.getGO(init.go).transform.position = init.position.toVector3();
- break;
- case 1:
- if (init.rotation == null || init.go == null)
- {
- return false;
- }
- AnimatorTimeline.getGO(init.go).transform.rotation = init.rotation.toQuaternion();
- break;
- case 2:
- if (init.position == null || init.go == null)
- {
- return false;
- }
- AnimatorTimeline.getGO(init.go).transform.LookAt(init.position.toVector3());
- break;
- case 3:
- if (init.go == null || init.floats == null)
- {
- return false;
- }
- AMTween.SetMorph(AnimatorTimeline.getCMP(init.go, "MegaMorph"), AnimatorTimeline.getMethodInfo(init.go, "MegaMorph", "SetPercent", new string[]
- {
- "System.Int32",
- "System.Single"
- }), init.floats);
- break;
- case 4:
- if (!AnimatorTimeline.setInitialValueForProperty(init, init._int))
- {
- return false;
- }
- break;
- case 5:
- if (!AnimatorTimeline.setInitialValueForProperty(init, init._long))
- {
- return false;
- }
- break;
- case 6:
- if (init.floats == null || init.floats.Length <= 0)
- {
- return false;
- }
- if (!AnimatorTimeline.setInitialValueForProperty(init, init.floats[0]))
- {
- return false;
- }
- break;
- case 7:
- if (!AnimatorTimeline.setInitialValueForProperty(init, init._double))
- {
- return false;
- }
- break;
- case 8:
- if (init._vect2 == null)
- {
- return false;
- }
- if (!AnimatorTimeline.setInitialValueForProperty(init, init._vect2.toVector2()))
- {
- return false;
- }
- break;
- case 9:
- if (init.position == null)
- {
- return false;
- }
- if (!AnimatorTimeline.setInitialValueForProperty(init, init.position.toVector3()))
- {
- return false;
- }
- break;
- case 10:
- if (init._color == null)
- {
- return false;
- }
- if (!AnimatorTimeline.setInitialValueForProperty(init, init._color.toColor()))
- {
- return false;
- }
- break;
- case 11:
- if (init._rect == null)
- {
- return false;
- }
- if (!AnimatorTimeline.setInitialValueForProperty(init, init._rect.toRect()))
- {
- return false;
- }
- break;
- case 12:
- if (init.strings != null && init.strings.Length > 0)
- {
- AnimatorTimeline.allCameras = new Camera[init.strings.Length];
- for (int i = 0; i < init.strings.Length; i++)
- {
- AnimatorTimeline.allCameras[i] = AnimatorTimeline.getGO(init.strings[i]).GetComponent<Camera>();
- }
- }
- if (init.typeExtra == "camera")
- {
- if (init.go == null)
- {
- return false;
- }
- AMTween.SetTopCamera(AnimatorTimeline.getGO(init.go).GetComponent<Camera>(), AnimatorTimeline.allCameras);
- }
- else
- {
- if (init._color == null)
- {
- return false;
- }
- AMTween.ShowColor(init._color.toColor());
- }
- break;
- case 13:
- goto IL_441;
- default:
- goto IL_441;
- }
- return true;
- }
- }
- IL_441:
- Debug.LogWarning("Animator: Error parsing initial value type '" + init.type + "'");
- return false;
- }
- private static bool setInitialValueForProperty(AnimatorTimeline.JSONInit init, object value)
- {
- if (init.go == null || value == null || init.strings == null || init.strings.Length < 2 || init.typeExtra == null)
- {
- return false;
- }
- if (init.typeExtra == "fieldInfo")
- {
- AnimatorTimeline.getFieldInfo(init.go, init.strings[0], init.strings[1]).SetValue(AnimatorTimeline.getCMP(init.go, init.strings[0]), value);
- }
- else
- {
- AnimatorTimeline.getPropertyInfo(init.go, init.strings[0], init.strings[1]).SetValue(AnimatorTimeline.getCMP(init.go, init.strings[0]), value, null);
- }
- return true;
- }
- private static bool parseJSONTake(AnimatorTimeline.JSONTake j)
- {
- AnimatorTimeline.dictGameObjects = new Dictionary<string, GameObject>();
- AnimatorTimeline.dictComponents = new Dictionary<string, Component>();
- AnimatorTimeline.dictMethodInfos = new Dictionary<string, MethodInfo>();
- AnimatorTimeline.dictFieldInfos = new Dictionary<string, FieldInfo>();
- AnimatorTimeline.dictPropertyInfos = new Dictionary<string, PropertyInfo>();
- AnimatorTimeline.allCameras = null;
- bool flag = false;
- if (j.inits != null)
- {
- foreach (AnimatorTimeline.JSONInit initialValue in j.inits)
- {
- if (!AnimatorTimeline.setInitialValue(initialValue))
- {
- flag = true;
- }
- }
- }
- if (j.actions != null)
- {
- AnimatorTimeline.JSONAction[] actions = j.actions;
- int k = 0;
- while (k < actions.Length)
- {
- AnimatorTimeline.JSONAction jsonaction = actions[k];
- string method = jsonaction.method;
- if (method == null)
- {
- goto IL_249;
- }
- if (AnimatorTimeline.<>f__switch$map2 == null)
- {
- AnimatorTimeline.<>f__switch$map2 = new Dictionary<string, int>(10)
- {
- {
- "moveto",
- 0
- },
- {
- "rotateto",
- 1
- },
- {
- "lookfollow",
- 2
- },
- {
- "looktofollow",
- 3
- },
- {
- "playanimation",
- 4
- },
- {
- "playaudio",
- 5
- },
- {
- "propertyto",
- 6
- },
- {
- "sendmessage",
- 7
- },
- {
- "invokemethod",
- 8
- },
- {
- "camerafade",
- 9
- }
- };
- }
- int num;
- if (!AnimatorTimeline.<>f__switch$map2.TryGetValue(method, out num))
- {
- goto IL_249;
- }
- switch (num)
- {
- case 0:
- if (!AnimatorTimeline.parseMoveTo(jsonaction))
- {
- flag = true;
- }
- break;
- case 1:
- if (!AnimatorTimeline.parseRotateTo(jsonaction))
- {
- flag = true;
- }
- break;
- case 2:
- if (!AnimatorTimeline.parseLookFollow(jsonaction))
- {
- flag = true;
- }
- break;
- case 3:
- if (!AnimatorTimeline.parseLookToFollow(jsonaction))
- {
- flag = true;
- }
- break;
- case 4:
- if (!AnimatorTimeline.parsePlayAnimation(jsonaction))
- {
- flag = true;
- }
- break;
- case 5:
- if (!AnimatorTimeline.parsePlayAudio(jsonaction))
- {
- flag = true;
- }
- break;
- case 6:
- if (!AnimatorTimeline.parsePropertyTo(jsonaction))
- {
- flag = true;
- }
- break;
- case 7:
- if (!AnimatorTimeline.parseSendMessage(jsonaction))
- {
- flag = true;
- }
- break;
- case 8:
- if (!AnimatorTimeline.parseInvokeMethod(jsonaction))
- {
- flag = true;
- }
- break;
- case 9:
- if (!AnimatorTimeline.parseCameraFade(jsonaction))
- {
- flag = true;
- }
- break;
- case 10:
- goto IL_249;
- default:
- goto IL_249;
- }
- IL_26B:
- k++;
- continue;
- IL_249:
- Debug.LogWarning("Animator: Error parsing method '" + jsonaction.method + "'");
- flag = true;
- goto IL_26B;
- }
- }
- AMTween.StartDisabled();
- return !flag;
- }
- private static bool parseCameraFade(AnimatorTimeline.JSONAction a)
- {
- if (a.ints == null || a.ints.Length < 3)
- {
- Debug.LogWarning("Animator: CameraFade missing fade type, start or end targets.");
- return false;
- }
- if (a.strings == null || a.strings.Length < 2 || a.colors == null || a.colors.Length < 2)
- {
- Debug.LogWarning("Animator: CameraFade missing start or end targets.");
- return false;
- }
- Hashtable hashtable = new Hashtable();
- hashtable.Add("time", a.time);
- hashtable.Add("delay", a.delay);
- AnimatorTimeline.setupHashEase(hashtable, a);
- if (a.bools != null && a.bools.Length > 0)
- {
- hashtable.Add("reversed", a.bools[0]);
- }
- if (a.ints[1] == 0 || a.ints[2] == 0)
- {
- hashtable.Add("allcameras", AnimatorTimeline.allCameras);
- }
- if (a.stringsExtra != null && a.stringsExtra.Length > 0)
- {
- hashtable.Add("texture", AMTween.LoadTexture2D(a.stringsExtra[0]));
- }
- if (a.ints[1] == 0)
- {
- hashtable.Add("camera1", AnimatorTimeline.getGO(a.strings[0]).GetComponent<Camera>());
- }
- else
- {
- hashtable.Add("color1", a.colors[0].toColor());
- }
- if (a.ints[2] == 0)
- {
- hashtable.Add("camera2", AnimatorTimeline.getGO(a.strings[1]).GetComponent<Camera>());
- }
- else
- {
- hashtable.Add("color2", a.colors[1].toColor());
- }
- float[] array = a.floats;
- if (array == null)
- {
- array = new float[0];
- }
- AMTween.CameraFade(a.ints[0], a.bools != null && a.bools.Length >= 2 && a.bools[1], array, hashtable);
- return true;
- }
- private static bool parseInvokeMethod(AnimatorTimeline.JSONAction a)
- {
- if (a.strings == null || a.strings.Length < 2)
- {
- Debug.LogWarning("Animator: SendMessage missing Component or MethodInfo Name.");
- return false;
- }
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- hashtable.Add("methodinfo", AnimatorTimeline.getMethodInfo(a.go, a.strings[0], a.strings[1], null));
- if (a.eventParams != null && a.eventParams.Length > 0)
- {
- object[] array = new object[a.eventParams.Length];
- for (int i = 0; i < a.eventParams.Length; i++)
- {
- array[i] = a.eventParams[i].toObject();
- }
- if (array.Length <= 0)
- {
- array = null;
- }
- hashtable.Add("parameters", array);
- }
- AMTween.InvokeMethod(AnimatorTimeline.getCMP(a.go, a.strings[0]), hashtable);
- return true;
- }
- private static bool parseSendMessage(AnimatorTimeline.JSONAction a)
- {
- if (a.strings == null || a.strings.Length < 1)
- {
- Debug.LogWarning("Animator: SendMessage missing Method Name.");
- return false;
- }
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- hashtable.Add("methodname", a.strings[0]);
- if (a.eventParams != null && a.eventParams.Length > 0)
- {
- hashtable.Add("parameter", a.eventParams[0].toObject());
- }
- AMTween.SendMessage(AnimatorTimeline.getGO(a.go), hashtable);
- return true;
- }
- private static bool parsePropertyTo(AnimatorTimeline.JSONAction a)
- {
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- hashtable.Add("time", a.time);
- AnimatorTimeline.setupHashEase(hashtable, a);
- if (a.strings == null || a.strings.Length < 2)
- {
- Debug.LogWarning("Animator: PropertyTo missing Component or property type.");
- return false;
- }
- string componentName = a.strings[0];
- bool flag = false;
- string text = a.strings[1];
- if (text != null)
- {
- if (AnimatorTimeline.<>f__switch$map3 == null)
- {
- AnimatorTimeline.<>f__switch$map3 = new Dictionary<string, int>(9)
- {
- {
- "morph",
- 0
- },
- {
- "integer",
- 1
- },
- {
- "long",
- 2
- },
- {
- "float",
- 3
- },
- {
- "double",
- 4
- },
- {
- "vector2",
- 5
- },
- {
- "vector3",
- 6
- },
- {
- "color",
- 7
- },
- {
- "rect",
- 8
- }
- };
- }
- int num;
- if (AnimatorTimeline.<>f__switch$map3.TryGetValue(text, out num))
- {
- switch (num)
- {
- case 0:
- if (a.floats == null || a.floatsExtra == null)
- {
- flag = true;
- }
- hashtable.Add("methodtype", "morph");
- hashtable.Add("methodinfo", AnimatorTimeline.getMethodInfo(a.go, "MegaMorph", "SetPercent", new string[]
- {
- "System.Int32",
- "System.Single"
- }));
- hashtable.Add("from", a.floats);
- hashtable.Add("to", a.floatsExtra);
- break;
- case 1:
- if (a.ints == null || a.ints.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.ints[0]);
- hashtable.Add("to", a.ints[1]);
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 2:
- if (a.longs == null || a.longs.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.longs[0]);
- hashtable.Add("to", a.longs[1]);
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 3:
- if (a.floats == null || a.floats.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.floats[0]);
- hashtable.Add("to", a.floats[1]);
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 4:
- if (a.doubles == null || a.doubles.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.doubles[0]);
- hashtable.Add("to", a.doubles[1]);
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 5:
- if (a.vect2s == null || a.vect2s.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.vect2s[0].toVector2());
- hashtable.Add("to", a.vect2s[1].toVector2());
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 6:
- if (a.path == null || a.path.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.path[0].toVector3());
- hashtable.Add("to", a.path[1].toVector3());
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 7:
- if (a.colors == null || a.colors.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.colors[0].toColor());
- hashtable.Add("to", a.colors[1].toColor());
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 8:
- if (a.rects == null || a.rects.Length < 2)
- {
- flag = true;
- }
- hashtable.Add("from", a.rects[0].toRect());
- hashtable.Add("to", a.rects[1].toRect());
- AnimatorTimeline.setupHashFieldOrPropertyInfo(hashtable, a);
- break;
- case 9:
- goto IL_4C3;
- default:
- goto IL_4C3;
- }
- if (flag)
- {
- Debug.LogWarning("Animator: PropertyTo missing 'to' or 'from' targets.");
- return false;
- }
- AMTween.PropertyTo(AnimatorTimeline.getCMP(a.go, componentName), hashtable);
- return true;
- }
- }
- IL_4C3:
- Debug.LogWarning("Animator: PropertyTo unknown property type '" + a.strings[1] + "'.");
- return false;
- }
- private static void setupHashFieldOrPropertyInfo(Hashtable hash, AnimatorTimeline.JSONAction a)
- {
- if (a.strings.Length < 4)
- {
- Debug.LogWarning("Animator: PropertyTo missing Component or property type.");
- return;
- }
- if (a.strings[2] == "fieldinfo")
- {
- hash.Add("fieldinfo", AnimatorTimeline.getFieldInfo(a.go, a.strings[0], a.strings[3]));
- }
- else
- {
- hash.Add("propertyinfo", AnimatorTimeline.getPropertyInfo(a.go, a.strings[0], a.strings[3]));
- }
- }
- private static bool parsePlayAudio(AnimatorTimeline.JSONAction a)
- {
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- if (a.strings.Length < 1)
- {
- Debug.LogWarning("Animator: PlayAudio missing 'audioclip' clip name.");
- return false;
- }
- AudioClip audioClip = (AudioClip)Resources.Load(a.strings[0]);
- if (audioClip == null)
- {
- Debug.LogWarning("Animator: Could not find AudioClip '" + a.strings[0] + "'. Make sure the audio file is placed in a Resources folder!");
- return false;
- }
- hashtable.Add("audioclip", audioClip);
- if (a.bools.Length >= 1)
- {
- hashtable.Add("loop", a.bools[0]);
- AMTween.PlayAudio((AudioSource)AnimatorTimeline.getCMP(a.go, "AudioSource"), hashtable);
- return true;
- }
- Debug.LogWarning("Animator: PlayAudio missing 'loop'.");
- return false;
- }
- private static bool parsePlayAnimation(AnimatorTimeline.JSONAction a)
- {
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- if (a.strings.Length < 1)
- {
- Debug.LogWarning("Animator: PlayAnimation missing 'animation' clip name.");
- return false;
- }
- hashtable.Add("animation", a.strings[0]);
- if (a.floats.Length < 2)
- {
- Debug.LogWarning("Animator: PlayAnimation missing 'wrapmode' or 'fadeLength'.");
- return false;
- }
- hashtable.Add("wrapmode", (WrapMode)a.floats[0]);
- hashtable.Add("fadeLength", a.floats[1]);
- if (a.bools.Length >= 1)
- {
- hashtable.Add("crossfade", a.bools[0]);
- AMTween.PlayAnimation(AnimatorTimeline.getGO(a.go), hashtable);
- return true;
- }
- Debug.LogWarning("Animator: PlayAnimation missing 'crossfade'.");
- return false;
- }
- private static bool parseLookToFollow(AnimatorTimeline.JSONAction a)
- {
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- hashtable.Add("time", a.time);
- AnimatorTimeline.setupHashEase(hashtable, a);
- if (a.strings.Length >= 1)
- {
- hashtable.Add("looktarget", AnimatorTimeline.getGO(a.strings[0]).transform);
- if (a.path != null && a.path.Length >= 1)
- {
- hashtable.Add("endposition", a.path[0].toVector3());
- }
- AMTween.LookToFollow(AnimatorTimeline.getGO(a.go), hashtable);
- return true;
- }
- Debug.LogWarning("Animator: LookFollow missing 'looktarget'.");
- return false;
- }
- private static bool parseLookFollow(AnimatorTimeline.JSONAction a)
- {
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- hashtable.Add("time", a.time);
- AnimatorTimeline.setupHashEase(hashtable, a);
- if (a.strings.Length >= 1)
- {
- hashtable.Add("looktarget", AnimatorTimeline.getGO(a.strings[0]).transform);
- AMTween.LookFollow(AnimatorTimeline.getGO(a.go), hashtable);
- return true;
- }
- Debug.LogWarning("Animator: LookFollow missing 'looktarget'.");
- return false;
- }
- private static bool parseMoveTo(AnimatorTimeline.JSONAction a)
- {
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- hashtable.Add("time", a.time);
- AnimatorTimeline.setupHashEase(hashtable, a);
- if (a.path.Length > 1)
- {
- hashtable.Add("path", a.getVector3Path());
- }
- else
- {
- if (a.path.Length != 1)
- {
- Debug.LogWarning("Animator: MoveTo missing 'position' or 'path'.");
- return false;
- }
- hashtable.Add("position", a.path[0].toVector3());
- }
- AMTween.MoveTo(AnimatorTimeline.getGO(a.go), hashtable);
- return true;
- }
- private static bool parseRotateTo(AnimatorTimeline.JSONAction a)
- {
- Hashtable hashtable = new Hashtable();
- hashtable.Add("disable", true);
- hashtable.Add("delay", a.delay);
- hashtable.Add("time", a.time);
- AnimatorTimeline.setupHashEase(hashtable, a);
- if (a.path.Length >= 1)
- {
- hashtable.Add("rotation", a.path[0].toVector3());
- AMTween.RotateTo(AnimatorTimeline.getGO(a.go), hashtable);
- return true;
- }
- Debug.LogWarning("Animator: RotateTo missing 'rotation'.");
- return false;
- }
- private static void setupHashEase(Hashtable hashTable, AnimatorTimeline.JSONAction a)
- {
- if (a.customEase.Length > 0)
- {
- AnimationCurve value = AMTween.GenerateCurve(a.customEase);
- hashTable.Add("easecurve", value);
- }
- else
- {
- hashTable.Add("easetype", (AMTween.EaseType)a.easeType);
- }
- }
- private static GameObject getGO(string name)
- {
- if (name == null)
- {
- Debug.LogWarning("Animator: Error parsing GameObject with null value");
- return null;
- }
- if (AnimatorTimeline.dictGameObjects.ContainsKey(name))
- {
- return AnimatorTimeline.dictGameObjects[name];
- }
- GameObject gameObject = GameObject.Find(name);
- if (!gameObject)
- {
- Debug.LogWarning("Animator: Error parsing JSON; Could not find GameObject '" + name + "'.");
- }
- AnimatorTimeline.dictGameObjects.Add(name, gameObject);
- return gameObject;
- }
- private static Component getCMP(string goName, string componentName)
- {
- if (goName == null || componentName == null)
- {
- Debug.LogWarning("Animator: Error parsing GameObject or Component with null value: " + goName + ", " + componentName);
- return null;
- }
- string key = goName + "." + componentName;
- if (AnimatorTimeline.dictComponents.ContainsKey(key))
- {
- return AnimatorTimeline.dictComponents[key];
- }
- GameObject go = AnimatorTimeline.getGO(goName);
- Component component = go.GetComponent(componentName);
- if (!component)
- {
- Debug.LogWarning(string.Concat(new string[]
- {
- "Animator: Error parsing JSON; Could not find Component '",
- componentName,
- "' on GameObject '",
- goName,
- "'."
- }));
- }
- AnimatorTimeline.dictComponents.Add(key, component);
- return component;
- }
- private static MethodInfo getMethodInfo(string goName, string componentName, string methodName, string[] typeNames)
- {
- if (methodName == null || componentName == null)
- {
- Debug.LogWarning("Animator: Error parsing MethodInfo or Component with null value");
- return null;
- }
- string text = componentName + "." + methodName;
- List<Type> list = new List<Type>();
- if (typeNames != null)
- {
- for (int i = 0; i < typeNames.Length; i++)
- {
- text = text + "." + typeNames[i];
- }
- foreach (string typeName in typeNames)
- {
- list.Add(Type.GetType(typeName));
- }
- }
- if (AnimatorTimeline.dictMethodInfos.ContainsKey(text))
- {
- return AnimatorTimeline.dictMethodInfos[text];
- }
- MethodInfo method;
- if (typeNames == null)
- {
- method = AnimatorTimeline.getCMP(goName, componentName).GetType().GetMethod(methodName);
- }
- else
- {
- method = AnimatorTimeline.getCMP(goName, componentName).GetType().GetMethod(methodName, list.ToArray());
- }
- AnimatorTimeline.dictMethodInfos.Add(text, method);
- return AnimatorTimeline.dictMethodInfos[text];
- }
- private static FieldInfo getFieldInfo(string goName, string componentName, string fieldName)
- {
- if (fieldName == null || componentName == null)
- {
- Debug.LogWarning("Animator: Error parsing FieldInfo or Component with null value");
- return null;
- }
- string key = componentName + "." + fieldName;
- if (AnimatorTimeline.dictFieldInfos.ContainsKey(key))
- {
- return AnimatorTimeline.dictFieldInfos[key];
- }
- AnimatorTimeline.dictFieldInfos.Add(key, AnimatorTimeline.getCMP(goName, componentName).GetType().GetField(fieldName));
- return AnimatorTimeline.dictFieldInfos[key];
- }
- private static PropertyInfo getPropertyInfo(string goName, string componentName, string propertyName)
- {
- if (propertyName == null || componentName == null)
- {
- Debug.LogWarning("Animator: Error parsing PropertyInfo or Component with null value");
- return null;
- }
- string key = componentName + "." + propertyName;
- if (AnimatorTimeline.dictPropertyInfos.ContainsKey(key))
- {
- return AnimatorTimeline.dictPropertyInfos[key];
- }
- AnimatorTimeline.dictPropertyInfos.Add(key, AnimatorTimeline.getCMP(goName, componentName).GetType().GetProperty(propertyName));
- return AnimatorTimeline.dictPropertyInfos[key];
- }
- private static Component _aData;
- private static MethodInfo cachedInvoker;
- private static Dictionary<string, GameObject> dictGameObjects;
- private static Dictionary<string, Component> dictComponents;
- private static Dictionary<string, MethodInfo> dictMethodInfos;
- private static Dictionary<string, FieldInfo> dictFieldInfos;
- private static Dictionary<string, PropertyInfo> dictPropertyInfos;
- private static Camera[] allCameras;
- public class JSONTake
- {
- public string takeName;
- public AnimatorTimeline.JSONInit[] inits;
- public AnimatorTimeline.JSONAction[] actions;
- }
- public class JSONInit
- {
- public string type;
- public string typeExtra;
- public string go;
- public AnimatorTimeline.JSONVector3 position;
- public AnimatorTimeline.JSONQuaternion rotation;
- public float[] floats;
- public string[] strings;
- public string[] stringsExtra;
- public int _int;
- public long _long;
- public double _double;
- public AnimatorTimeline.JSONVector2 _vect2;
- public AnimatorTimeline.JSONColor _color;
- public AnimatorTimeline.JSONRect _rect;
- }
- public class JSONAction
- {
- public void setPath(Vector3[] _path)
- {
- this.path = AnimatorTimeline.getJSONVector3Array(_path);
- }
- public Vector3[] getVector3Path()
- {
- List<Vector3> list = new List<Vector3>();
- for (int i = 0; i < this.path.Length; i++)
- {
- list.Add(this.path[i].toVector3());
- }
- return list.ToArray();
- }
- public string method;
- public string go;
- public float delay;
- public float time;
- public int easeType;
- public float[] customEase;
- public string[] strings;
- public string[] stringsExtra;
- public float[] floats;
- public float[] floatsExtra;
- public bool[] bools;
- public int[] ints;
- public long[] longs;
- public double[] doubles;
- public AnimatorTimeline.JSONVector3[] path;
- public AnimatorTimeline.JSONVector2[] vect2s;
- public AnimatorTimeline.JSONColor[] colors;
- public AnimatorTimeline.JSONRect[] rects;
- public AnimatorTimeline.JSONEventParameter[] eventParams;
- }
- public class JSONEventParameter
- {
- 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)
- {
- if (this.valueType == 12)
- {
- if (this.array == null || this.array.Length <= 0)
- {
- Debug.LogError("Animator: Expected array parameters in JSON");
- return null;
- }
- if (this.array[0].valueType == 13)
- {
- bool[] array = new bool[this.array.Length];
- for (int i = 0; i < this.array.Length; i++)
- {
- array[i] = this.array[i].val_bool;
- }
- return array;
- }
- if (this.array[0].valueType == 9)
- {
- string[] array2 = new string[this.array.Length];
- for (int j = 0; j < this.array.Length; j++)
- {
- array2[j] = this.array[j].val_string;
- }
- return array2;
- }
- if (this.array[0].valueType == 10)
- {
- char[] array3 = new char[this.array.Length];
- for (int k = 0; k < this.array.Length; k++)
- {
- array3[k] = this.array[k].val_string[0];
- }
- return array3;
- }
- if (this.array[0].valueType == 0 || this.array[0].valueType == 1)
- {
- int[] array4 = new int[this.array.Length];
- for (int l = 0; l < this.array.Length; l++)
- {
- array4[l] = this.array[l].val_int;
- }
- return array4;
- }
- if (this.array[0].valueType == 2 || this.array[0].valueType == 3)
- {
- float[] array5 = new float[this.array.Length];
- for (int m = 0; m < this.array.Length; m++)
- {
- array5[m] = this.array[m].val_float;
- }
- return array5;
- }
- if (this.array[0].valueType == 4)
- {
- Vector2[] array6 = new Vector2[this.array.Length];
- for (int n = 0; n < this.array.Length; n++)
- {
- array6[n] = this.array[n].val_vect2.toVector2();
- }
- return array6;
- }
- if (this.array[0].valueType == 5)
- {
- Vector3[] array7 = new Vector3[this.array.Length];
- for (int num = 0; num < this.array.Length; num++)
- {
- array7[num] = this.array[num].val_vect3.toVector3();
- }
- return array7;
- }
- if (this.array[0].valueType == 6)
- {
- Vector4[] array8 = new Vector4[this.array.Length];
- for (int num2 = 0; num2 < this.array.Length; num2++)
- {
- array8[num2] = this.array[num2].val_vect4.toVector4();
- }
- return array8;
- }
- if (this.array[0].valueType == 7)
- {
- Color[] array9 = new Color[this.array.Length];
- for (int num3 = 0; num3 < this.array.Length; num3++)
- {
- array9[num3] = this.array[num3].val_color.toColor();
- }
- return array9;
- }
- if (this.array[0].valueType == 8)
- {
- Rect[] array10 = new Rect[this.array.Length];
- for (int num4 = 0; num4 < this.array.Length; num4++)
- {
- array10[num4] = this.array[num4].val_rect.toRect();
- }
- return array10;
- }
- if (this.array[0].valueType == 11)
- {
- UnityEngine.Object[] array11 = new UnityEngine.Object[this.array.Length];
- for (int num5 = 0; num5 < this.array.Length; num5++)
- {
- array11[num5] = AnimatorTimeline.getGO(this.array[num5].val_obj);
- }
- return array11;
- }
- }
- Debug.LogError("Animator: Type not found for Event Parameter valueType " + this.valueType);
- return null;
- }
- if (this.val_obj_extra == null)
- {
- return AnimatorTimeline.getGO(this.val_obj);
- }
- return AnimatorTimeline.getCMP(this.val_obj_extra, this.val_obj);
- }
- }
- public int valueType;
- public bool val_bool;
- public int val_int;
- public float val_float;
- public AnimatorTimeline.JSONVector2 val_vect2;
- public AnimatorTimeline.JSONVector3 val_vect3;
- public AnimatorTimeline.JSONVector4 val_vect4;
- public AnimatorTimeline.JSONColor val_color;
- public AnimatorTimeline.JSONRect val_rect;
- public string val_string;
- public string val_obj;
- public string val_obj_extra;
- public AnimatorTimeline.JSONEventParameter[] array;
- public enum ValueType
- {
- Integer,
- Long,
- Float,
- Double,
- Vector2,
- Vector3,
- Vector4,
- Color,
- Rect,
- String,
- Char,
- Object,
- Array,
- Boolean
- }
- }
- public class JSONVector4
- {
- public void setValue(Vector4 v)
- {
- this.x = v.x;
- this.y = v.y;
- this.z = v.z;
- this.w = v.w;
- }
- public Vector4 toVector4()
- {
- return new Vector4(this.x, this.y, this.z, this.w);
- }
- public float x;
- public float y;
- public float z;
- public float w;
- }
- public class JSONVector3
- {
- public void setValue(Vector3 v)
- {
- this.x = v.x;
- this.y = v.y;
- this.z = v.z;
- }
- public Vector3 toVector3()
- {
- return new Vector3(this.x, this.y, this.z);
- }
- public float x;
- public float y;
- public float z;
- }
- public class JSONVector2
- {
- public void setValue(Vector2 v)
- {
- this.x = v.x;
- this.y = v.y;
- }
- public Vector2 toVector2()
- {
- return new Vector2(this.x, this.y);
- }
- public float x;
- public float y;
- }
- public class JSONQuaternion
- {
- public void setValue(Vector4 q)
- {
- this.x = q.x;
- this.y = q.y;
- this.z = q.z;
- this.w = q.w;
- }
- public Quaternion toQuaternion()
- {
- return new Quaternion(this.x, this.y, this.z, this.w);
- }
- public float x;
- public float y;
- public float z;
- public float w;
- }
- public class JSONColor
- {
- public void setValue(Color c)
- {
- this.r = c.r;
- this.g = c.g;
- this.b = c.b;
- this.a = c.a;
- }
- public Color toColor()
- {
- return new Color(this.r, this.g, this.b, this.a);
- }
- public float r;
- public float g;
- public float b;
- public float a;
- }
- public class JSONRect
- {
- public void setValue(Rect r)
- {
- this.x = r.x;
- this.y = r.y;
- this.width = r.width;
- this.height = r.height;
- }
- public Rect toRect()
- {
- return new Rect(this.x, this.y, this.width, this.height);
- }
- public float x;
- public float y;
- public float width;
- public float height;
- }
- }
|