public static void Init() { if (unitAnimList != null) { return; } isDirty = false; // Load all animations unitAnimList = new List <UnitAnim>(); if (V_Animation.DATA_LOCATION == V_Animation.DataLocation.Assets) { LoadFromDataFolder(); } else { //RenameAnimationsInResources(); // Run once when updating resources folder LoadFromResources(); } DefaultAnimation = UnitAnim.GetUnitAnim("DefaultAnimation"); //LoadOldVersionSaves(); #if !SILENT Debug.Log("Loaded Animations: " + unitAnimList.Count); #endif }
public void PlayAnim(UnitAnim unitAnim, float frameRateModModifier, OnAnimComplete onAnimComplete, OnAnimTrigger onAnimTrigger, OnAnimInterrupted onAnimInterrupted) { if (this.onAnimInterrupted != null) { OnAnimInterrupted tmpAnimInterrupted = this.onAnimInterrupted; this.onAnimInterrupted = null; tmpAnimInterrupted(lastUnitAnim, unitAnim, alreadyLooped); if (OnAnyAnimInterrupted != null) { OnAnyAnimInterrupted(lastUnitAnim, unitAnim, alreadyLooped); } } this.onAnimComplete = onAnimComplete; this.onAnimTrigger = onAnimTrigger; this.onAnimInterrupted = onAnimInterrupted; lastUnitAnim = unitAnim; alreadyLooped = false; // Dynamic anim V_Skeleton_Updater newSkeletonUpdater = new V_Skeleton_Updater(mesh, unitAnim.GetAnims(), frameRateMod, frameRateModModifier, onAnimTrigger, OnAnyAnimTrigger); newSkeletonUpdater.TestFirstFrameTrigger(); skeletonUpdater = newSkeletonUpdater; if (OnAnyPlayAnim != null) { OnAnyPlayAnim(unitAnim); } }
public static void Init() { if (isInit) { return; } isInit = true; #if !SILENT Debug.Log("V_Animation.Init " + DATA_LOCATION); #endif System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); if (DATA_LOCATION == DataLocation.Assets) { Init_Folders(); } else { //UnitAnim.RenameAnimationsInResources(); // Run once when updating resources folder } UVType.Init(); UnitAnim.Init(); UnitAnimType.Init(); }
public static UnitAnim Load(string save) { string[] content = V_Animation.SplitString(save, "#ANIMATION#"); UnitAnim unitAnim = new UnitAnim(content[1], V_Animation.V_LoadAnimationString(content[0], ANIMATION_FRAME_MULTIPLIER)); return(unitAnim); }
public void UpdateAnim(UnitAnimType animType, int angle, float frameRateMod) { // Update animation if different angle if (animType == activeAnimType) { // Same anim, check angle if (activeAngle == angle) { // Same angle, ignore return; } else { // Different angle activeAngle = angle; UnitAnim unitAnim = activeAnimType.GetUnitAnim(activeAngle); activeAnim = unitAnim; unitSkeleton.PlayAnimContinueFrames(unitAnim, frameRateMod); } } else { // Different anim PlayAnim(animType, angle, frameRateMod, null, null, null); } }
public void ReplaceBodyPartSkeletonAnim(UnitAnim unitAnim, params string[] bodyPartNameArr) { foreach (string bodyPartName in bodyPartNameArr) { TryReplaceBodyPartSkeletonAnim(bodyPartName, unitAnim.GetSkeletonAnim_BodyPartCustom(bodyPartName)); } }
public void UpdateAnim(UnitAnimType animType, int angle, float frameRateMod, V_UnitSkeleton.OnAnimComplete onAnimComplete, V_UnitSkeleton.OnAnimTrigger onAnimTrigger, V_UnitSkeleton.OnAnimInterrupted onAnimInterrupted) { // Update animation if different angle if (animType == activeAnimType) { // Same anim, check angle if (activeAngle == angle) { // Same angle, ignore return; } else { // Different angle activeAngle = angle; UnitAnim unitAnim = activeAnimType.GetUnitAnim(activeAngle); activeAnim = unitAnim; unitSkeleton.PlayAnimContinueFrames(unitAnim, frameRateMod, onAnimComplete, onAnimTrigger, onAnimInterrupted); } } else { // Different anim PlayAnim(animType, angle, frameRateMod, onAnimComplete, onAnimTrigger, onAnimInterrupted); } }
public void SetAnimAll(UnitAnim unitAnim) { foreach (UnitAnim.AnimDir animDir in System.Enum.GetValues(typeof(UnitAnim.AnimDir))) { singleAnimDic[animDir] = unitAnim; } }
public void PlayAnimForced(UnitAnim unitAnim, float frameRateMod, V_UnitSkeleton.OnAnimComplete onAnimComplete, V_UnitSkeleton.OnAnimTrigger onAnimTrigger, V_UnitSkeleton.OnAnimInterrupted onAnimInterrupted) { // Forcefully play animation no matter what is currently playing activeAnimType = unitAnim.GetUnitAnimType(); activeAnim = unitAnim; unitSkeleton.PlayAnim(unitAnim, frameRateMod, onAnimComplete, onAnimTrigger, onAnimInterrupted); }
public void PlayAnimForced(UnitAnim unitAnim, float frameRateMod, Action onAnimComplete) { PlayAnimForced(unitAnim, frameRateMod, (UnitAnim u) => { if (onAnimComplete != null) { onAnimComplete(); } }, null, null); }
private static void LoadOldVersionSaves() { // Load Old Version saves string dirPath = V_Animation.LOC_ANIMATIONS + "OldVersion/"; DirectoryInfo dir = new DirectoryInfo(dirPath); List <FileInfo> fileInfoList = new List <FileInfo>(dir.GetFiles("*.txt")); foreach (FileInfo fileInfo in fileInfoList) { string readAllText = File.ReadAllText(fileInfo.FullName); UnitAnim unitAnim = UnitAnim.Load(readAllText); string prefix = "dSwordTwoHandedBack_"; unitAnim.name = prefix + unitAnim.name.Replace(" ", ""); V_Skeleton_Anim[] anims = unitAnim.GetAnims(); for (int i = 0; i < anims.Length; i++) { V_Skeleton_Anim skeletonAnim = anims[i]; foreach (V_Skeleton_Frame frame in skeletonAnim.frames) { switch (skeletonAnim.bodyPart.customName) { case "FootL": frame.SetNewSize(frame.GetSize() * .5f); break; case "FootR": frame.SetNewSize(frame.GetSize() * .5f); break; case "Body": frame.SetNewSize(frame.GetSize() * 0.85f); break; case "Head": frame.SetNewSize(frame.GetSize() * 0.916f); break; case "Sword": frame.SetNewSize(frame.GetSize() * 1.03f); break; case "HandL": frame.SetNewSize(frame.GetSize() * .5f); break; case "HandR": frame.SetNewSize(frame.GetSize() * .5f); break; } frame.RefreshVertices(); } skeletonAnim.RemakeTween(); } List <V_Skeleton_Anim> animsList = new List <V_Skeleton_Anim>(anims); for (int i = 0; i < animsList.Count; i++) { V_Skeleton_Anim skeletonAnim = animsList[i]; if (skeletonAnim.bodyPart.customName == "Pointer_1" || skeletonAnim.bodyPart.customName == "Pointer_2" || skeletonAnim.bodyPart.customName == "Pointer_3") { animsList.RemoveAt(i); i--; } } unitAnim = new UnitAnim(unitAnim.name, animsList.ToArray()); string saveString = unitAnim.Save(); SaveSystem.Save(V_Animation.LOC_ANIMATIONS, unitAnim.name + "." + V_Animation.fileExtention_Animation, SaveSystem.FileData.FileType.Animation, saveString); } }
public bool PlayAnimIfOnCompleteMatches(UnitAnim unitAnim, OnAnimComplete onAnimComplete) { if (this.onAnimComplete == onAnimComplete) { // Matches!, Play anim PlayAnim(unitAnim, 1f, null, null, null); return(true); } return(false); }
static UnitAnimEnum() { FieldInfo[] fieldInfoArr = typeof(UnitAnimEnum).GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo fieldInfo in fieldInfoArr) { if (fieldInfo != null) { fieldInfo.SetValue(null, UnitAnim.GetUnitAnim(fieldInfo.Name)); } } }
public void PlayAnim(UnitAnim unitAnim, float frameRateMod, V_UnitSkeleton.OnAnimComplete onAnimComplete, V_UnitSkeleton.OnAnimTrigger onAnimTrigger, V_UnitSkeleton.OnAnimInterrupted onAnimInterrupted) { // Ignores if same animType, same angle and same frameRateMod if (unitAnim == activeAnim) { // Same anim, same angle return; } PlayAnimForced(unitAnim, frameRateMod, onAnimComplete, onAnimTrigger, onAnimInterrupted); }
public UnitAnim CloneDeep() { V_Skeleton_Anim[] skeletonAnimArray = new V_Skeleton_Anim[anims.Length]; for (int i = 0; i < anims.Length; i++) { skeletonAnimArray[i] = anims[i].CloneDeep(); } UnitAnim clone = new UnitAnim(name, skeletonAnimArray); return(clone); }
public List <string> GetTriggerList() { List <string> ret = new List <string>(); foreach (UnitAnim.AnimDir animDir in System.Enum.GetValues(typeof(UnitAnim.AnimDir))) { UnitAnim unitAnim = singleAnimDic[animDir]; ret.AddRange(unitAnim.GetTriggerList()); } return(ret); }
public void SetAnims(UnitAnim animDown, UnitAnim animUp, UnitAnim animLeft, UnitAnim animRight, UnitAnim animDownLeft, UnitAnim animDownRight, UnitAnim animUpLeft, UnitAnim animUpRight) { singleAnimDic[UnitAnim.AnimDir.Down] = animDown; singleAnimDic[UnitAnim.AnimDir.Up] = animUp; singleAnimDic[UnitAnim.AnimDir.Left] = animLeft; singleAnimDic[UnitAnim.AnimDir.Right] = animRight; singleAnimDic[UnitAnim.AnimDir.DownLeft] = animDownLeft; singleAnimDic[UnitAnim.AnimDir.DownRight] = animDownRight; singleAnimDic[UnitAnim.AnimDir.UpLeft] = animUpLeft; singleAnimDic[UnitAnim.AnimDir.UpRight] = animUpRight; }
// All body parts in this UnitAnim get replaced in the current anim, if one doesnt exist it is added public void ReplaceAllBodyPartsInAnimation(UnitAnim unitAnim) { foreach (V_Skeleton_Anim skeletonAnim in unitAnim.GetAnims()) { bool replaced = TryReplaceBodyPartSkeletonAnim(skeletonAnim); if (!replaced) { // Didn't replace, body part doesn't exist, add GetSkeletonUpdater().AddAnim(skeletonAnim); } } }
public void PlayAnimIdleIfOnCompleteMatches(Vector3 dir, V_UnitSkeleton.OnAnimComplete OnAnimComplete, UnitAnimType idleAnimType) { int angle = GetAngleFromVector(dir); UnitAnim unitAnim = idleAnimType.GetUnitAnim(angle); if (unitSkeleton.PlayAnimIfOnCompleteMatches(unitAnim, OnAnimComplete)) { // Playing anim activeAnimType = idleAnimType; activeAnim = unitAnim; activeAngle = angle; } }
public static void Init() { if (isInit) { return; } isInit = true; #if !SILENT Debug.Log("V_Animation.Init " + DATA_LOCATION); #endif if (DATA_LOCATION == DataLocation.Assets) { Init_Folders(); } UVType.Init(); UnitAnim.Init(); UnitAnimType.Init(); }
public void TryFillDirections() { foreach (UnitAnim.AnimDir animDir in System.Enum.GetValues(typeof(UnitAnim.AnimDir))) { UnitAnim unitAnim = UnitAnim.GetUnitAnim(name + animDir); if (unitAnim != null) { SetAnim(animDir, unitAnim); } } if (singleAnimDic[UnitAnim.AnimDir.Down] != null) { if (singleAnimDic[UnitAnim.AnimDir.DownLeft] == null) { singleAnimDic[UnitAnim.AnimDir.DownLeft] = singleAnimDic[UnitAnim.AnimDir.Down]; } if (singleAnimDic[UnitAnim.AnimDir.DownRight] == null) { singleAnimDic[UnitAnim.AnimDir.DownRight] = singleAnimDic[UnitAnim.AnimDir.Down]; } } if (singleAnimDic[UnitAnim.AnimDir.Up] != null) { if (singleAnimDic[UnitAnim.AnimDir.UpLeft] == null) { singleAnimDic[UnitAnim.AnimDir.UpLeft] = singleAnimDic[UnitAnim.AnimDir.Up]; } if (singleAnimDic[UnitAnim.AnimDir.UpRight] == null) { singleAnimDic[UnitAnim.AnimDir.UpRight] = singleAnimDic[UnitAnim.AnimDir.Up]; } } { UnitAnim unitAnim = UnitAnim.GetUnitAnim(name); if (unitAnim != null) { foreach (UnitAnim.AnimDir animDir in System.Enum.GetValues(typeof(UnitAnim.AnimDir))) { SetAnim(animDir, unitAnim); } } } }
public static UnitAnimType Load(string save) { string[] content = V_Animation.SplitString(save, "#UNITANIMTYPE#"); UnitAnimType unitAnimType = new UnitAnimType(content[0]); unitAnimType.SetAnims( UnitAnim.Load(content[1]), UnitAnim.Load(content[2]), UnitAnim.Load(content[3]), UnitAnim.Load(content[4]), UnitAnim.Load(content[5]), UnitAnim.Load(content[6]), UnitAnim.Load(content[7]), UnitAnim.Load(content[8]) ); return(unitAnimType); }
public void PlayAnimContinueFrames(UnitAnim unitAnim, float frameRateModModifier) { //Play new anim starting from same frames lastUnitAnim = unitAnim; alreadyLooped = false; // Dynamic anim if (skeletonUpdater is V_Skeleton_Updater) { // Continuing from normal updater V_Skeleton_Updater newSkeletonUpdater = new V_Skeleton_Updater(mesh, unitAnim.GetAnims(), frameRateMod, frameRateModModifier, onAnimTrigger, OnAnyAnimTrigger); newSkeletonUpdater.SetFramesToSame((skeletonUpdater as V_Skeleton_Updater).GetAnims()); skeletonUpdater = newSkeletonUpdater; } else { // Previous was cached updater, ignore continue frames skeletonUpdater = new V_Skeleton_Updater(mesh, unitAnim.GetAnims(), frameRateMod, frameRateModModifier, onAnimTrigger, OnAnyAnimTrigger); } }
private static void LoadFromResources() { //TextAsset animationResourceTreeTextAsset = Resources.Load<TextAsset>("AnimationData/animationResourceTreeTextAsset"); //string folderCSV = animationResourceTreeTextAsset.text; string folderCSV = "_Default/Animations,Animations";//,AnimationTypes"; string[] folderArr = V_Animation.SplitString(folderCSV, ","); foreach (string folder in folderArr) { if (folder != "") { // Load resources in folder TextAsset[] textAssetArr = Resources.LoadAll <TextAsset>("AnimationData/" + folder); //Debug.Log("Animations folder: "+folder+"; Found Animations: "+ textAssetArr.Length); foreach (TextAsset textAsset in textAssetArr) { //Debug.Log("Loading: "+textAsset.name); byte[] byteArr = textAsset.bytes; string readAllText; SaveSystem.FileData fileData; if (SaveSystem.Load(byteArr, out fileData)) { // Loaded! readAllText = fileData.save; } else { // Load failed! readAllText = null; } UnitAnim unitAnim = UnitAnim.Load(readAllText); unitAnimList.Add(unitAnim); } } } }
public static void Init() { if (isInit) { return; } isInit = true; #if !SILENT Debug.Log("V_Animation.Init " + DATA_LOCATION); #endif if (DATA_LOCATION == DataLocation.Assets) { Init_Folders(); } else { //UnitAnim.RenameAnimationsInResources(); // Run once when updating resources folder } UVType.Init(); UnitAnim.Init(); UnitAnimType.Init(); }
public void PlayAnimContinueFrames(UnitAnim unitAnim, float frameRateModModifier, OnAnimComplete onAnimComplete, OnAnimTrigger onAnimTrigger, OnAnimInterrupted onAnimInterrupted) { //Play new anim starting from same frames if (this.onAnimInterrupted != null) { OnAnimInterrupted tmpAnimInterrupted = this.onAnimInterrupted; this.onAnimInterrupted = null; tmpAnimInterrupted(lastUnitAnim, unitAnim, alreadyLooped); if (OnAnyAnimInterrupted != null) { OnAnyAnimInterrupted(lastUnitAnim, unitAnim, alreadyLooped); } } this.onAnimComplete = onAnimComplete; this.onAnimTrigger = onAnimTrigger; this.onAnimInterrupted = onAnimInterrupted; lastUnitAnim = unitAnim; alreadyLooped = false; // Dynamic anim if (skeletonUpdater is V_Skeleton_Updater) { // Continuing from normal updater V_Skeleton_Updater newSkeletonUpdater = new V_Skeleton_Updater(mesh, unitAnim.GetAnims(), frameRateMod, frameRateModModifier, onAnimTrigger, OnAnyAnimTrigger); newSkeletonUpdater.SetFramesToSame((skeletonUpdater as V_Skeleton_Updater).GetAnims()); skeletonUpdater = newSkeletonUpdater; } else { // Previous was cached updater, ignore continue frames skeletonUpdater = new V_Skeleton_Updater(mesh, unitAnim.GetAnims(), frameRateMod, frameRateModModifier, onAnimTrigger, OnAnyAnimTrigger); } }
public void SetAnim(UnitAnim.AnimDir animDir, UnitAnim unitAnim) { singleAnimDic[animDir] = unitAnim; }
private static void LoadFromDataFolder() { // Load Default Animations DirectoryInfo defaultDirMain = new DirectoryInfo(V_Animation.LOC_DEFAULT_ANIMATIONS); DirectoryInfo[] defaultDirArr = defaultDirMain.GetDirectories(); foreach (DirectoryInfo defaultDir in defaultDirArr) { List <FileInfo> defaultDirFileInfoList = new List <FileInfo>(defaultDir.GetFiles("*." + V_Animation.fileExtention_Animation)); foreach (FileInfo fileInfo in defaultDirFileInfoList) { string readAllText; SaveSystem.FileData fileData; if (SaveSystem.Load(V_Animation.LOC_DEFAULT_ANIMATIONS + defaultDir.Name + "/", fileInfo.Name, out fileData)) { // Loaded! readAllText = fileData.save; } else { // Load failed! continue; } UnitAnim unitAnim = UnitAnim.Load(readAllText); unitAnim.disableOverwrite = true; unitAnimList.Add(unitAnim); } } // Load Default Animations on Main Default Folder List <FileInfo> defaultFileInfoList = new List <FileInfo>(defaultDirMain.GetFiles("*." + V_Animation.fileExtention_Animation)); foreach (FileInfo fileInfo in defaultFileInfoList) { string readAllText; SaveSystem.FileData fileData; if (SaveSystem.Load(V_Animation.LOC_DEFAULT_ANIMATIONS + "/", fileInfo.Name, out fileData)) { // Loaded! readAllText = fileData.save; } else { // Load failed! continue; } UnitAnim unitAnim = UnitAnim.Load(readAllText); unitAnim.disableOverwrite = true; unitAnimList.Add(unitAnim); } // Load Custom Animations DirectoryInfo dir = new DirectoryInfo(V_Animation.LOC_ANIMATIONS); List <FileInfo> fileInfoList = new List <FileInfo>(dir.GetFiles("*." + V_Animation.fileExtention_Animation)); Debug.Log("ANIMATIONS FOUND: " + fileInfoList.Count); float startTime = Time.realtimeSinceStartup; foreach (FileInfo fileInfo in fileInfoList) { string readAllText; SaveSystem.FileData fileData; if (SaveSystem.Load(V_Animation.LOC_ANIMATIONS, fileInfo.Name, out fileData)) { // Loaded! readAllText = fileData.save; } else { // Load failed! continue; } UnitAnim unitAnim = UnitAnim.Load(readAllText); unitAnimList.Add(unitAnim); } Debug.Log("Loaded animations " + ((Time.realtimeSinceStartup - startTime) * 1000f) + "ms"); }
public UnitAnim GetUnitAnim(int angle) { return(singleAnimDic[UnitAnim.GetAnimDirFromAngle(angle)]); }
public bool TryReplaceBodyPartSkeletonAnim(string bodyPartName, UnitAnim unitAnim) { return(TryReplaceBodyPartSkeletonAnim(bodyPartName, unitAnim.GetSkeletonAnim_BodyPartCustom(bodyPartName))); }