예제 #1
0
    public void PlayAnimations(tk2dSpriteAnimationClip.WrapMode mode, float fps)
    {
        string clipName = GetClipName();

        Dictionary <string, tk2dSpriteAnimator> .Enumerator etor = animators.GetEnumerator();
        while (etor.MoveNext())
        {
            tk2dSpriteAnimator animator = etor.Current.Value;
            if (!animator.gameObject.activeInHierarchy)
            {
                continue;
            }

            tk2dSpriteAnimationClip clip = animator.GetClipByName(clipName);
            if (null == clip)
            {
                clipName = GetClipName(PlayerAniConifg.directionStatus.SOUTHEAST, action, isRiding);
                clip     = animator.GetClipByName(clipName);
            }

            if (null == clip)
            {
                JZLog.LogWarning(etor.Current.Key + " 没有该动画数据: " + clipName);
                continue;
            }

            clip.wrapMode          = mode;
            clip.fps               = fps;
            animator.DefaultClipId = 0;
            animator.PlayFromFrame(clip, 0);

            CheckRotation(etor.Current.Key, direction, animator);
            CheckLayer(etor.Current.Key, animator.gameObject.transform);
        }
    }
        /**
         * <summary>Plays an animation.</summary>
         * <param name = "sprite">The Transform with the 2Dtk Sprite</param>
         * <param name = "clipName">The name of the animation clip to play</param>
         * <param name = "changeWrapMode">If True, then the clip's wrap mode will be changed</param>
         * <param name = "wrapMode">The new WrapMode to use, if changeWrapMode = True</param>
         * <param name = "frame">The frame number to play. If >= 0, then the animation will freeze at the specified frame</param>
         */
        public static bool PlayAnimation(Transform sprite, string clipName, bool changeWrapMode, WrapMode wrapMode, int frame = -1)
        {
                        #if tk2DIsPresent
            tk2dSpriteAnimationClip.WrapMode wrapMode2D = tk2dSpriteAnimationClip.WrapMode.Once;
            if (wrapMode == WrapMode.Loop)
            {
                wrapMode2D = tk2dSpriteAnimationClip.WrapMode.Loop;
            }
            else if (wrapMode == WrapMode.PingPong)
            {
                wrapMode2D = tk2dSpriteAnimationClip.WrapMode.PingPong;
            }

            if (sprite && sprite.GetComponent <tk2dSpriteAnimator>())
            {
                tk2dSpriteAnimator      anim = sprite.GetComponent <tk2dSpriteAnimator>();
                tk2dSpriteAnimationClip clip = anim.GetClipByName(clipName);

                if (clip != null)
                {
                    if (!anim.IsPlaying(clip))
                    {
                        if (changeWrapMode)
                        {
                            clip.wrapMode = wrapMode2D;
                        }

                        anim.Play(clip);

                        if (frame >= 0)
                        {
                            anim.SetFrame(frame);
                            anim.Stop();
                        }
                    }

                    return(true);
                }

                return(false);
            }
                        #else
            ACDebug.Log("The 'tk2DIsPresent' preprocessor is not defined - check your Build Settings.");
                        #endif

            return(true);
        }
        public static tk2dSpriteAnimationClip AddAnimation(tk2dSpriteAnimator animator, tk2dSpriteCollectionData collection, List <int> spriteIDs,
                                                           string clipName, tk2dSpriteAnimationClip.WrapMode wrapMode = tk2dSpriteAnimationClip.WrapMode.Loop, float fps = 15)
        {
            if (animator.Library == null)
            {
                animator.Library         = animator.gameObject.AddComponent <tk2dSpriteAnimation>();
                animator.Library.clips   = new tk2dSpriteAnimationClip[0];
                animator.Library.enabled = true;
            }

            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            for (int i = 0; i < spriteIDs.Count; i++)
            {
                tk2dSpriteDefinition sprite = collection.spriteDefinitions[spriteIDs[i]];
                if (sprite.Valid)
                {
                    frames.Add(new tk2dSpriteAnimationFrame()
                    {
                        spriteCollection = collection,
                        spriteId         = spriteIDs[i]
                    });
                }
            }

            var clip = new tk2dSpriteAnimationClip()
            {
                name     = clipName,
                fps      = fps,
                wrapMode = wrapMode,
            };

            Array.Resize(ref animator.Library.clips, animator.Library.clips.Length + 1);
            animator.Library.clips[animator.Library.clips.Length - 1] = clip;

            clip.frames = frames.ToArray();
            return(clip);
        }
예제 #4
0
        public static void SetupCustomAnimation(string character, string animation, int fps, tk2dSpriteAnimationClip.WrapMode wrapMode, int loopStart = 0)
        {
            SetupCustomBreachAnimation(character, animation, fps, wrapMode, loopStart);

            /*character = character.ToLower();
             * BotsModule.Log(CharacterBuilder.storedCharacters.GetFirst().Key);
             * if (CharacterBuilder.storedCharacters.ContainsKey(character) && CharacterBuilder.storedCharacters[character].Second.GetComponent<PlayerController>().spriteAnimator != null)
             * {
             *  var library = CharacterBuilder.storedCharacters[character].Second.GetComponent<PlayerController>().spriteAnimator.Library;
             *  if (library.GetClipByName(animation) != null)
             *  {
             *      library.GetClipByName(animation).fps = fps;
             *      library.GetClipByName(animation).wrapMode = wrapMode;
             *      if (wrapMode == tk2dSpriteAnimationClip.WrapMode.LoopSection)
             *      {
             *          library.GetClipByName(animation).loopStart = loopStart;
             *      }
             *  }
             *  else
             *  {
             *      ETGModConsole.Log($"No animation found under the name \"{animation}\"");
             *  }
             *
             * }
             * else
             * {
             *  ETGModConsole.Log($"No character found under the name \"{character}\" or tk2dSpriteAnimator is null");
             * }*/
        }
예제 #5
0
 public static void SetupCustomBreachAnimation(string character, string animation, int fps, tk2dSpriteAnimationClip.WrapMode wrapMode, int loopStart = 0, float maxFidgetDuration = 0, float minFidgetDuration = 0)
 {
     character = character.ToLower();
     //BotsModule.Log(CharacterBuilder.storedCharacters.GetFirst().Key);
     if (CharacterBuilder.storedCharacters.ContainsKey(character) && CharacterBuilder.storedCharacters[character].Second.GetComponent <PlayerController>().spriteAnimator != null)
     {
         var library = CharacterBuilder.storedCharacters[character].Second.GetComponent <PlayerController>().spriteAnimator.Library;
         if (library.GetClipByName(animation) != null)
         {
             library.GetClipByName(animation).fps      = fps;
             library.GetClipByName(animation).wrapMode = wrapMode;
             if (wrapMode == tk2dSpriteAnimationClip.WrapMode.LoopSection)
             {
                 library.GetClipByName(animation).loopStart = loopStart;
             }
             if (wrapMode == tk2dSpriteAnimationClip.WrapMode.LoopFidget)
             {
                 library.GetClipByName(animation).maxFidgetDuration = maxFidgetDuration;
                 library.GetClipByName(animation).minFidgetDuration = minFidgetDuration;
             }
         }
         else
         {
             Debug.LogError($"No animation found under the name \"{animation}\"");
         }
     }
     else
     {
         Debug.LogError($"No character found under the name \"{character}\" or tk2dSpriteAnimator is null");
     }
 }
예제 #6
0
        public static tk2dSpriteAnimationClip BuildAnimation(AIAnimator aiAnimator, string name, string spriteDirectory, int fps, tk2dSpriteAnimationClip.WrapMode wrapMode = tk2dSpriteAnimationClip.WrapMode.Loop)
        {
            tk2dSpriteCollectionData collection = aiAnimator.GetComponent <tk2dSpriteCollectionData>();

            if (!collection)
            {
                collection = SpriteBuilder.ConstructCollection(aiAnimator.gameObject, $"{aiAnimator.name}_collection");
            }

            string[]   resources = ResourceExtractor.GetResourceNames();
            List <int> indices   = new List <int>();

            for (int i = 0; i < resources.Length; i++)
            {
                if (resources[i].StartsWith(spriteDirectory.Replace('/', '.'), StringComparison.OrdinalIgnoreCase))
                {
                    indices.Add(SpriteBuilder.AddSpriteToCollection(resources[i], collection));
                }
            }
            tk2dSpriteAnimationClip clip = SpriteBuilder.AddAnimation(aiAnimator.spriteAnimator, collection, indices, name, tk2dSpriteAnimationClip.WrapMode.Loop);

            clip.fps      = fps;
            clip.wrapMode = wrapMode;
            return(clip);
        }
예제 #7
0
        public static tk2dSpriteAnimationClip AddAnimation(this GameObject obj, string name, string spriteDirectory, int fps, AnimationType type, DirectionType directionType = DirectionType.None, tk2dSpriteAnimationClip.WrapMode wrapMode = tk2dSpriteAnimationClip.WrapMode.Loop, FlipType flipType = FlipType.None, bool assignAnimation = true)
        {
            AIAnimator           aiAnimator = obj.GetOrAddComponent <AIAnimator>();
            DirectionalAnimation animation  = aiAnimator.GetDirectionalAnimation(name, directionType, type);

            if (animation == null)
            {
                animation = new DirectionalAnimation()
                {
                    AnimNames = new string[0],
                    Flipped   = new FlipType[0],
                    Type      = directionType,
                    Prefix    = string.Empty
                };
            }

            animation.AnimNames = animation.AnimNames.Concat(new string[] { name }).ToArray();
            animation.Flipped   = animation.Flipped.Concat(new FlipType[] { flipType }).ToArray();

            if (assignAnimation)
            {
                aiAnimator.AssignDirectionalAnimation(name, animation, type);
            }
            return(BuildAnimation(aiAnimator, name, spriteDirectory, fps, wrapMode));
        }
        public static GameObject MakeAnimatedOrbital(string name, float orbitRadius, float orbitalDegreesPerSecond, int orbitalTier, PlayerOrbital.OrbitalMotionStyle motionStyle, float perfectOrbitalFactor, List <string> idleAnimPaths, int fps, Vector2 colliderDimensions, Vector2 colliderOffsets, tk2dBaseSprite.Anchor anchorMode, tk2dSpriteAnimationClip.WrapMode wrapMode)
        {
            GameObject prefab = SpriteBuilder.SpriteFromResource(idleAnimPaths[0]);

            prefab.name = name;
            var body = prefab.GetComponent <tk2dSprite>().SetUpSpeculativeRigidbody(colliderOffsets.ToIntVector2(), colliderDimensions.ToIntVector2());

            body.CollideWithTileMap = false;
            body.CollideWithOthers  = true;
            body.PrimaryPixelCollider.CollisionLayer = CollisionLayer.EnemyBulletBlocker;

            tk2dSpriteCollectionData spriteCollection = SpriteBuilder.ConstructCollection(prefab, $"{name}_Collection");

            prefab.AddAnimationToObject(spriteCollection, "start", idleAnimPaths, fps, colliderDimensions, colliderOffsets, anchorMode, wrapMode, true);

            PlayerOrbital orbitalPrefab = prefab.AddComponent <PlayerOrbital>();

            orbitalPrefab.motionStyle           = motionStyle;
            orbitalPrefab.shouldRotate          = false;
            orbitalPrefab.orbitRadius           = orbitRadius;
            orbitalPrefab.perfectOrbitalFactor  = perfectOrbitalFactor;
            orbitalPrefab.orbitDegreesPerSecond = orbitalDegreesPerSecond;
            orbitalPrefab.SetOrbitalTier(orbitalTier);

            prefab.MakeFakePrefab();
            return(prefab);
        }
예제 #9
0
    private static tk2dSpriteAnimationClip[] CreateAnimationClip(tk2dSpriteCollectionData spriteCollectionData, string name, string action, string[] directionNames, tk2dSpriteAnimationClip.WrapMode wrapMode)
    {
        List <tk2dSpriteDefinition> frames = new List <tk2dSpriteDefinition>();

        foreach (var spriteDefine in spriteCollectionData.spriteDefinitions)
        {
            if (spriteDefine.name.Contains(name + "_" + action.ToLower()))
            {
                frames.Add(spriteDefine);
            }
        }
        frames = frames.OrderBy(o => o.name).ToList();
        var frameCount = frames.Count / directionNames.Length;

        tk2dSpriteAnimationClip[] clips = new tk2dSpriteAnimationClip[directionNames.Length];
        for (int i = 0; i < directionNames.Length; i++)
        {
            var clip = new tk2dSpriteAnimationClip();
            clips[i] = clip;
            clip.fps = 10;
            if (directionNames[i] == "")
            {
                clip.name = name + "_" + action;
            }
            else
            {
                clip.name = name + "_" + action + "_" + directionNames[i];
            }
            clip.frames   = new tk2dSpriteAnimationFrame[frameCount];
            clip.wrapMode = wrapMode;
            for (int j = 0; j < clip.frames.Length; ++j)
            {
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame();
                frame.spriteCollection = spriteCollectionData;
                frame.spriteId         = frame.spriteCollection.GetSpriteIdByName(frames[i * frameCount + j].name);

                clip.frames[j] = frame;
            }
        }
        return(clips);
    }
예제 #10
0
        public static tk2dSpriteAnimationClip AddAnimation(tk2dSpriteAnimator animator, tk2dSpriteCollectionData collection, List <int> spriteIDs, string clipName, tk2dSpriteAnimationClip.WrapMode wrapMode = tk2dSpriteAnimationClip.WrapMode.Loop, int frameRate = 15, int loopStart = 0, float minFidgetDuration = 0.5f, float maxFidgetDuration = 1)
        {
            if (animator.Library == null)
            {
                animator.Library       = animator.gameObject.AddComponent <tk2dSpriteAnimation>();
                animator.Library.clips = new tk2dSpriteAnimationClip[0];
            }
            List <tk2dSpriteAnimationFrame> list = new List <tk2dSpriteAnimationFrame>();

            for (int i = 0; i < spriteIDs.Count; i++)
            {
                tk2dSpriteDefinition spriteDefinition = collection.spriteDefinitions[spriteIDs[i]];
                if (spriteDefinition.Valid)
                {
                    list.Add(new tk2dSpriteAnimationFrame {
                        spriteCollection  = collection,
                        spriteId          = spriteIDs[i],
                        invulnerableFrame = false
                    });
                }
            }
            tk2dSpriteAnimationClip animationClip = new tk2dSpriteAnimationClip()
            {
                name              = clipName,
                frames            = list.ToArray(),
                fps               = frameRate,
                wrapMode          = wrapMode,
                loopStart         = loopStart,
                minFidgetDuration = minFidgetDuration,
                maxFidgetDuration = maxFidgetDuration,
            };

            Array.Resize(ref animator.Library.clips, animator.Library.clips.Length + 1);
            animator.Library.clips[animator.Library.clips.Length - 1] = animationClip;
            return(animationClip);
        }
예제 #11
0
        // Token: 0x06000007 RID: 7 RVA: 0x0000226C File Offset: 0x0000046C
        public static tk2dSpriteAnimationClip AddAnimation(tk2dSpriteAnimator animator, tk2dSpriteCollectionData collection, List <int> spriteIDs, string clipName, tk2dSpriteAnimationClip.WrapMode wrapMode = tk2dSpriteAnimationClip.WrapMode.Loop)
        {
            bool flag = animator.Library == null;

            if (flag)
            {
                animator.Library         = animator.gameObject.AddComponent <tk2dSpriteAnimation>();
                animator.Library.clips   = new tk2dSpriteAnimationClip[0];
                animator.Library.enabled = true;
            }
            List <tk2dSpriteAnimationFrame> list = new List <tk2dSpriteAnimationFrame>();

            for (int i = 0; i < spriteIDs.Count; i++)
            {
                tk2dSpriteDefinition tk2dSpriteDefinition = collection.spriteDefinitions[spriteIDs[i]];
                bool valid = tk2dSpriteDefinition.Valid;
                if (valid)
                {
                    list.Add(new tk2dSpriteAnimationFrame
                    {
                        spriteCollection = collection,
                        spriteId         = spriteIDs[i]
                    });
                }
            }
            tk2dSpriteAnimationClip tk2dSpriteAnimationClip = new tk2dSpriteAnimationClip();

            tk2dSpriteAnimationClip.name     = clipName;
            tk2dSpriteAnimationClip.fps      = 15f;
            tk2dSpriteAnimationClip.wrapMode = wrapMode;
            Array.Resize <tk2dSpriteAnimationClip>(ref animator.Library.clips, animator.Library.clips.Length + 1);
            animator.Library.clips[animator.Library.clips.Length - 1] = tk2dSpriteAnimationClip;
            tk2dSpriteAnimationClip.frames = list.ToArray();
            return(tk2dSpriteAnimationClip);
        }
예제 #12
0
        // Token: 0x0600015D RID: 349 RVA: 0x0000D300 File Offset: 0x0000B500
        public static tk2dSpriteAnimationClip BuildAnimation(AIAnimator aiAnimator, string name, string spriteDirectory, int fps, tk2dSpriteAnimationClip.WrapMode warpmode = tk2dSpriteAnimationClip.WrapMode.Loop)
        {
            tk2dSpriteCollectionData tk2dSpriteCollectionData = aiAnimator.GetComponent <tk2dSpriteCollectionData>();
            bool flag  = !tk2dSpriteCollectionData;
            bool flag2 = flag;
            bool flag3 = flag2;

            if (flag3)
            {
                tk2dSpriteCollectionData = SpriteBuilder.ConstructCollection(aiAnimator.gameObject, aiAnimator.name + "_collection");
            }
            string[]   resourceNames = ResourceExtractor.GetResourceNames();
            List <int> list          = new List <int>();

            for (int i = 0; i < resourceNames.Length; i++)
            {
                bool flag4 = resourceNames[i].StartsWith(spriteDirectory.Replace('/', '.'), StringComparison.OrdinalIgnoreCase);
                bool flag5 = flag4;
                bool flag6 = flag5;
                if (flag6)
                {
                    list.Add(SpriteBuilder.AddSpriteToCollection(resourceNames[i], tk2dSpriteCollectionData));
                }
            }
            bool flag7 = list.Count == 0;
            bool flag8 = flag7;
            bool flag9 = flag8;

            if (flag9)
            {
                ETGModConsole.Log("No sprites found for animation " + name);
            }
            tk2dSpriteAnimationClip tk2dSpriteAnimationClip = SpriteBuilder.AddAnimation(aiAnimator.spriteAnimator, tk2dSpriteCollectionData, list, name, warpmode);

            tk2dSpriteAnimationClip.fps = (float)fps;
            return(tk2dSpriteAnimationClip);
        }
예제 #13
0
        // Token: 0x0600015A RID: 346 RVA: 0x0000D168 File Offset: 0x0000B368
        public static tk2dSpriteAnimationClip AddAnimation(this GameObject obj, string name, string spriteDirectory, int fps, NPCBuilder.AnimationType type, DirectionalAnimation.DirectionType directionType = DirectionalAnimation.DirectionType.None, DirectionalAnimation.FlipType flipType = DirectionalAnimation.FlipType.None, tk2dSpriteAnimationClip.WrapMode warpmode = tk2dSpriteAnimationClip.WrapMode.Loop)
        {
            obj.AddComponent <tk2dSpriteAnimator>();
            AIAnimator aianimator = obj.GetComponent <AIAnimator>();
            bool       flag       = !aianimator;
            bool       flag2      = flag;
            bool       flag3      = flag2;

            if (flag3)
            {
                aianimator = NPCBuilder.CreateNewAIAnimator(obj);
            }
            DirectionalAnimation directionalAnimation = aianimator.GetDirectionalAnimation(name, directionType, type);
            bool flag4 = directionalAnimation == null;
            bool flag5 = flag4;
            bool flag6 = flag5;

            if (flag6)
            {
                directionalAnimation = new DirectionalAnimation
                {
                    AnimNames = new string[0],
                    Flipped   = new DirectionalAnimation.FlipType[0],
                    Type      = directionType,
                    Prefix    = string.Empty
                };
            }
            directionalAnimation.AnimNames = directionalAnimation.AnimNames.Concat(new string[]
            {
                name
            }).ToArray <string>();
            directionalAnimation.Flipped = directionalAnimation.Flipped.Concat(new DirectionalAnimation.FlipType[]
            {
                flipType
            }).ToArray <DirectionalAnimation.FlipType>();
            aianimator.AssignDirectionalAnimation(name, directionalAnimation, type);
            return(NPCBuilder.BuildAnimation(aianimator, name, spriteDirectory, fps, warpmode));
        }
예제 #14
0
        public static GameObject CreateVFX(string name, List <string> spritePaths, int fps, IntVector2 Dimensions, tk2dBaseSprite.Anchor anchor, bool usesZHeight, float zHeightOffset, float emissivePower = -1, Color?emissiveColour = null, tk2dSpriteAnimationClip.WrapMode wrap = tk2dSpriteAnimationClip.WrapMode.Once, bool persist = false)
        {
            GameObject Obj   = new GameObject(name);
            VFXObject  vfObj = new VFXObject();

            Obj.SetActive(false);
            FakePrefab.MarkAsFakePrefab(Obj);
            UnityEngine.Object.DontDestroyOnLoad(Obj);

            tk2dSpriteCollectionData VFXSpriteCollection = SpriteBuilder.ConstructCollection(Obj, (name + "_Collection"));
            int spriteID = SpriteBuilder.AddSpriteToCollection(spritePaths[0], VFXSpriteCollection);

            tk2dSprite sprite = Obj.GetOrAddComponent <tk2dSprite>();

            sprite.SetSprite(VFXSpriteCollection, spriteID);
            tk2dSpriteDefinition defaultDef = sprite.GetCurrentSpriteDef();

            defaultDef.colliderVertices = new Vector3[] {
                new Vector3(0f, 0f, 0f),
                new Vector3((Dimensions.x / 16), (Dimensions.y / 16), 0f)
            };

            tk2dSpriteAnimator  animator  = Obj.GetOrAddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimation animation = Obj.GetOrAddComponent <tk2dSpriteAnimation>();

            animation.clips  = new tk2dSpriteAnimationClip[0];
            animator.Library = animation;
            tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
            {
                name = "start", frames = new tk2dSpriteAnimationFrame[0], fps = fps
            };
            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            for (int i = 0; i < spritePaths.Count; i++)
            {
                tk2dSpriteCollectionData collection = VFXSpriteCollection;
                int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(spritePaths[i], collection);
                tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                frameDef.ConstructOffsetsFromAnchor(anchor);
                frameDef.colliderVertices = defaultDef.colliderVertices;
                if (emissivePower > 0)
                {
                    frameDef.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                }
                if (emissivePower > 0)
                {
                    frameDef.material.SetFloat("_EmissiveColorPower", emissivePower);
                }
                if (emissiveColour != null)
                {
                    frameDef.material.SetColor("_EmissiveColor", (Color)emissiveColour);
                }
                if (emissivePower > 0)
                {
                    frameDef.materialInst.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                }
                if (emissivePower > 0)
                {
                    frameDef.materialInst.SetFloat("_EmissiveColorPower", emissivePower);
                }
                if (emissiveColour != null)
                {
                    frameDef.materialInst.SetColor("_EmissiveColor", (Color)emissiveColour);
                }
                frames.Add(new tk2dSpriteAnimationFrame {
                    spriteId = frameSpriteId, spriteCollection = collection
                });
            }
            if (emissivePower > 0)
            {
                sprite.renderer.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
            }
            if (emissivePower > 0)
            {
                sprite.renderer.material.SetFloat("_EmissiveColorPower", emissivePower);
            }
            if (emissiveColour != null)
            {
                sprite.renderer.material.SetColor("_EmissiveColor", (Color)emissiveColour);
            }
            clip.frames     = frames.ToArray();
            clip.wrapMode   = wrap;
            animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
            if (!persist)
            {
                SpriteAnimatorKiller kill = animator.gameObject.AddComponent <SpriteAnimatorKiller>();
                kill.fadeTime             = -1f;
                kill.animator             = animator;
                kill.delayDestructionTime = -1f;
            }
            animator.playAutomatically = true;
            animator.DefaultClipId     = animator.GetClipIdByName("start");
            vfObj.attached             = true;
            vfObj.persistsOnDeath      = false;
            vfObj.usesZHeight          = usesZHeight;
            vfObj.zHeight      = zHeightOffset;
            vfObj.alignment    = VFXAlignment.NormalAligned;
            vfObj.destructible = false;
            vfObj.effect       = Obj;
            return(Obj);
        }
예제 #15
0
        void DrawClipInspector()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Clip", EditorStyles.largeLabel);
            if (GUILayout.Button("Delete", GUILayout.Width(46)) &&
                EditorUtility.DisplayDialog("Delete clip", "Are you sure you want to delete the selected clip?", "Yes", "No"))
            {
                OnClipDeleted();
            }
            GUILayout.EndHorizontal();

            GUI.SetNextControlName("tk2dAnimName");
            string changedName = EditorGUILayout.TextField("Name", clip.name).Trim();

            if (selectClipNameField)
            {
                GUI.FocusControl("tk2dAnimName");
                selectClipNameField = false;
            }
            if (changedName != clip.name && changedName.Length > 0)
            {
                clip.name = changedName;
                OnClipNameChanged();
            }
            EditorGUILayout.IntField("Frames", clip.frames.Length);
            float fps = EditorGUILayout.FloatField("Frame rate", clip.fps);

            if (fps > 0)
            {
                clip.fps = fps;
            }
            float clipTime    = clip.frames.Length / fps;
            float newClipTime = EditorGUILayout.FloatField("Clip time", clipTime);

            if (newClipTime > 0 && newClipTime != clipTime)
            {
                clip.fps = clip.frames.Length / newClipTime;
            }
            tk2dSpriteAnimationClip.WrapMode newWrapMode = (tk2dSpriteAnimationClip.WrapMode)EditorGUILayout.EnumPopup("Wrap Mode", clip.wrapMode);
            if (clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.LoopSection)
            {
                clip.loopStart = EditorGUILayout.IntField("Loop Start", clip.loopStart);
                clip.loopStart = Mathf.Clamp(clip.loopStart, 0, clip.frames.Length - 1);
            }
            if (newWrapMode != clip.wrapMode)
            {
                if (newWrapMode == tk2dSpriteAnimationClip.WrapMode.Single && clip.frames.Length > 1)
                {
                    // Will we be truncating the animation?
                    if (EditorUtility.DisplayDialog("Wrap mode -> Single", "This will truncate your clip to a single frame. Do you want to continue?", "Yes", "No"))
                    {
                        clip.wrapMode = newWrapMode;
                        frameGroups.RemoveRange(1, frameGroups.Count - 1);
                        frameGroups[0].SetFrameCount(1);
                        ClipEditor.RecalculateFrames(clip, frameGroups);
                    }
                }
                else
                {
                    clip.wrapMode = newWrapMode;
                }
            }

            // Tools
            GUILayout.Space(8);
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            GUILayout.BeginVertical();
            bool changed = false;

            foreach (tk2dEditor.SpriteAnimationEditor.AnimOperator animOp in animOps)
            {
                changed = animOp.OnClipInspectorGUI(clip, frameGroups, timelineEditor.CurrentState);
                if ((animOp.AnimEditOperations & tk2dEditor.SpriteAnimationEditor.AnimEditOperations.ClipContentChanged) != tk2dEditor.SpriteAnimationEditor.AnimEditOperations.None)
                {
                    RecalculateFrames();
                    changed = true;
                }
                if ((animOp.AnimEditOperations & tk2dEditor.SpriteAnimationEditor.AnimEditOperations.ClipNameChanged) != tk2dEditor.SpriteAnimationEditor.AnimEditOperations.None)
                {
                    OnClipNameChanged();
                    changed = true;
                }
            }
            if (changed)
            {
                Repaint();
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            GUILayout.Space(8);
        }
예제 #16
0
        public static void AddAnimationToObject(this GameObject target, tk2dSpriteCollectionData spriteCollection, string animationName, List <string> spritePaths, int fps, Vector2 colliderDimensions, Vector2 colliderOffsets, tk2dBaseSprite.Anchor anchor, tk2dSpriteAnimationClip.WrapMode wrapMode, bool isDefaultAnimation = false)
        {
            tk2dSpriteAnimator  animator  = target.GetOrAddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimation animation = target.GetOrAddComponent <tk2dSpriteAnimation>();

            animation.clips  = new tk2dSpriteAnimationClip[0];
            animator.Library = animation;

            tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
            {
                name = animationName, frames = new tk2dSpriteAnimationFrame[0], fps = fps
            };

            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            foreach (string path in spritePaths)
            {
                tk2dSpriteCollectionData collection = spriteCollection;
                int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];

                frameDef.colliderVertices = new Vector3[] {
                    new Vector3(colliderOffsets.x / 16, colliderOffsets.y / 16, 0f),
                    new Vector3((colliderDimensions.x / 16), (colliderDimensions.y / 16), 0f)
                };

                frameDef.ConstructOffsetsFromAnchor(anchor);
                frames.Add(new tk2dSpriteAnimationFrame {
                    spriteId = frameSpriteId, spriteCollection = collection
                });
            }
            clip.frames     = frames.ToArray();
            clip.wrapMode   = wrapMode;
            animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();

            if (isDefaultAnimation)
            {
                animator.DefaultClipId     = animation.GetClipIdByName(animationName);
                animator.playAutomatically = true;
            }
        }
예제 #17
0
 /// <summary>
 /// 设置播放模式
 /// </summary>
 /// <param name="model"></param>
 public void PlayMode(tk2dSpriteAnimationClip.WrapMode model)
 {
     m_tAnimator.CurrentClip.wrapMode = model;
 }