Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
 public void ReplaceBodyPartSkeletonAnim(UnitAnim unitAnim, params string[] bodyPartNameArr)
 {
     foreach (string bodyPartName in bodyPartNameArr)
     {
         TryReplaceBodyPartSkeletonAnim(bodyPartName, unitAnim.GetSkeletonAnim_BodyPartCustom(bodyPartName));
     }
 }
Exemplo n.º 7
0
 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);
     }
 }
Exemplo n.º 8
0
 public void SetAnimAll(UnitAnim unitAnim)
 {
     foreach (UnitAnim.AnimDir animDir in System.Enum.GetValues(typeof(UnitAnim.AnimDir)))
     {
         singleAnimDic[animDir] = unitAnim;
     }
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 public void PlayAnimForced(UnitAnim unitAnim, float frameRateMod, Action onAnimComplete)
 {
     PlayAnimForced(unitAnim, frameRateMod, (UnitAnim u) => { if (onAnimComplete != null)
                                                              {
                                                                  onAnimComplete();
                                                              }
                    }, null, null);
 }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
 public bool PlayAnimIfOnCompleteMatches(UnitAnim unitAnim, OnAnimComplete onAnimComplete)
 {
     if (this.onAnimComplete == onAnimComplete)
     {
         // Matches!, Play anim
         PlayAnim(unitAnim, 1f, null, null, null);
         return(true);
     }
     return(false);
 }
Exemplo n.º 13
0
 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));
         }
     }
 }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
 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;
 }
Exemplo n.º 18
0
 // 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);
         }
     }
 }
Exemplo n.º 19
0
        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;
            }
        }
Exemplo n.º 20
0
        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();
        }
Exemplo n.º 21
0
        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);
                    }
                }
            }
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        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);
            }
        }
Exemplo n.º 24
0
        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);
                    }
                }
            }
        }
Exemplo n.º 25
0
        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();
        }
Exemplo n.º 26
0
        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);
            }
        }
Exemplo n.º 27
0
 public void SetAnim(UnitAnim.AnimDir animDir, UnitAnim unitAnim)
 {
     singleAnimDic[animDir] = unitAnim;
 }
Exemplo n.º 28
0
        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");
        }
Exemplo n.º 29
0
 public UnitAnim GetUnitAnim(int angle)
 {
     return(singleAnimDic[UnitAnim.GetAnimDirFromAngle(angle)]);
 }
Exemplo n.º 30
0
 public bool TryReplaceBodyPartSkeletonAnim(string bodyPartName, UnitAnim unitAnim)
 {
     return(TryReplaceBodyPartSkeletonAnim(bodyPartName, unitAnim.GetSkeletonAnim_BodyPartCustom(bodyPartName)));
 }