public Object[] GetOrigClips() { switch (S2USettings.GetOrCreateSettings().ImportOption) { case AnimationImportOption.NestedInPrefab: return(AssetDatabase.LoadAllAssetRepresentationsAtPath(PrefabPath)); case AnimationImportOption.SeparateFolder: return(AssetDatabase.LoadAllAssetsAtPath(AnimationsPath)); } return(null); }
public void Build(Animation animation, IDictionary <int, TimeLine> timeLines) { var clip = new AnimationClip(); clip.name = animation.name; var pendingTransforms = new Dictionary <string, Transform> (Transforms); //This Dictionary will shrink in size for every transform foreach (var key in animation.mainlineKeys) //that is considered "used" { var parentTimelines = new Dictionary <int, List <TimeLineKey> > (); var brefs = new Queue <Ref> (key.boneRefs ?? new Ref [0]); while (brefs.Count > 0) { var bref = brefs.Dequeue(); if (bref.parent < 0 || parentTimelines.ContainsKey(bref.parent)) { var timeLine = timeLines [bref.timeline]; parentTimelines [bref.id] = new List <TimeLineKey> (timeLine.keys); Transform bone; if (pendingTransforms.TryGetValue(timeLine.name, out bone)) //Skip it if it's already "used" { List <TimeLineKey> parentTimeline; parentTimelines.TryGetValue(bref.parent, out parentTimeline); SetCurves(bone, DefaultBones [timeLine.name], parentTimeline, timeLine, clip, animation); pendingTransforms.Remove(timeLine.name); } } else { brefs.Enqueue(bref); } } foreach (var sref in key.objectRefs) { var timeLine = timeLines [sref.timeline]; Transform sprite; if (pendingTransforms.TryGetValue(timeLine.name, out sprite)) { var defaultZ = sref.z_index; List <TimeLineKey> parentTimeline; parentTimelines.TryGetValue(sref.parent, out parentTimeline); SetCurves(sprite, DefaultSprites [timeLine.name], parentTimeline, timeLine, clip, animation, ref defaultZ); SetAdditionalCurves(sprite, animation.mainlineKeys, timeLine, clip, defaultZ); pendingTransforms.Remove(timeLine.name); } } foreach (var kvPair in pendingTransforms) //Disable the remaining tansforms if they are sprites and not already disabled { if (DefaultSprites.ContainsKey(kvPair.Key) && kvPair.Value.gameObject.activeSelf) { var curve = new AnimationCurve(new Keyframe(0f, 0f, inf, inf)); clip.SetCurve(GetPathToChild(kvPair.Value), typeof(GameObject), "m_IsActive", curve); } } } var settings = AnimationUtility.GetAnimationClipSettings(clip); settings.stopTime = animation.length; //Set the animation's length and other settings if (animation.looping) { clip.wrapMode = WrapMode.Loop; settings.loopTime = true; } else { clip.wrapMode = WrapMode.ClampForever; } AnimationUtility.SetAnimationClipSettings(clip, settings); if (OriginalClips.ContainsKey(animation.name)) //If the clip already exists, copy this clip into the old one { var oldClip = OriginalClips [animation.name]; var cachedEvents = oldClip.events; EditorUtility.CopySerialized(clip, oldClip); clip = oldClip; AnimationUtility.SetAnimationEvents(clip, cachedEvents); ProcessingInfo.ModifiedAnims.Add(clip); } else { switch (S2USettings.GetOrCreateSettings().ImportOption) { case AnimationImportOption.NestedInPrefab: AssetDatabase.AddObjectToAsset(clip, PrefabPath); //Otherwise create a new one break; case AnimationImportOption.SeparateFolder: if (!AssetDatabase.IsValidFolder(AnimationsPath)) { var splitIndex = AnimationsPath.LastIndexOf('/'); var path = AnimationsPath.Substring(0, splitIndex); var newFolder = AnimationsPath.Substring(splitIndex + 1); AssetDatabase.CreateFolder(path, newFolder); } AssetDatabase.CreateAsset(clip, string.Format("{0}/{1}.anim", AnimationsPath, clip.name)); break; } ProcessingInfo.NewAnims.Add(clip); } if (!ArrayUtility.Contains(Controller.animationClips, clip)) //Don't add the clip if it's already there { var state = GetStateFromController(clip.name); //Find a state of the same name if (state != null) { state.motion = clip; //If it exists, replace it } else { Controller.AddMotion(clip); //Otherwise add it as a new state } if (!ModdedController) { if (!ProcessingInfo.NewControllers.Contains(Controller) && !ProcessingInfo.ModifiedControllers.Contains(Controller)) { ProcessingInfo.ModifiedControllers.Add(Controller); } ModdedController = true; } } }