Exemple #1
0
        public void TestAllMethods()
        {
            PrefixTest();

            SpriteLayer clothesLayer = new ClothesLayer();

            SpriteLayer weaponLayer = new WeaponLayer();

            animation.PutLayer(clothesLayer);
            animation.PutLayer(weaponLayer);


            if (animation.IsPlaying)
            {
                animation.Stop();
                UUnitAssert.False(animation.IsPlaying);
                animation.Play();
                UUnitAssert.True(animation.IsPlaying);
            }
            else
            {
                animation.Play();
                UUnitAssert.True(animation.IsPlaying);
                animation.Stop();
                UUnitAssert.False(animation.IsPlaying);
            }

            weaponLayer = animation.GetLayer(LayerID.WEAPON);
            UUnitAssert.NotNull(weaponLayer);
            animation.Clear(weaponLayer);

            weaponLayer = animation.GetLayer(weaponLayer.id);
            UUnitAssert.NotNull(weaponLayer);
            weaponLayer.spritePrefab = weaponPrefab;
            animation.PutLayer(weaponLayer);

            animation.Open(clothesPrefab1, LayerID.CLOTHES);
        }
Exemple #2
0
        /// <summary>
        /// 生成 NPC 动画
        /// </summary>
        /// <param name="gobj">npc 的 prefab</param>
        public static void GenerateAnimation(GameObject obj)
        {
            // 判断该对象是不是
            Sprite sprite = obj.GetComponent <Sprite>();

            Debug.Log(sprite);
            if (sprite != null)
            {
                GameObject animationObj = new GameObject();
                animationObj.name = obj.name + "-animation";
                SpriteAnimation animation = animationObj.AddComponent <SpriteAnimation>();

                // animation.
                SpriteLayer clothesLayer = new ClothesLayer(obj.GetComponent <Sprite>());
                animation.PutLayer(clothesLayer);

                string             prefabPath = npcPrefabDirPath + "/" + animationObj.name + ".prefab";
                UnityEngine.Object prefab     = PrefabUtility.CreateEmptyPrefab(prefabPath);
                PrefabUtility.ReplacePrefab(animationObj, prefab, ReplacePrefabOptions.ConnectToPrefab);

                // destory game object
                GameObject.DestroyImmediate(animationObj);
            }
        }