Exemple #1
0
        private GameObject generateAnimation(GameObject obj)
        {
            var animation = obj.AddComponent <Animation>();

            var          SKN    = System.IO.File.ReadAllBytes(this.ANMFiles[12]);
            BinaryReader reader = new BinaryReader(new MemoryStream(SKN));
            AnmHeader    header = new AnmHeader(reader);
            AnmData      ad     = new AnmData(reader);

            AnimationClip clip = new AnimationClip();

            clip.name      = "clip1";
            clip.wrapMode  = WrapMode.Once;
            clip.legacy    = true;
            clip.frameRate = ad.FPS;

            foreach (var item in ad.Frames)
            {
                var curvex = new AnimationCurve();
                var curvey = new AnimationCurve();
                var curvez = new AnimationCurve();
                var curvew = new AnimationCurve();

                var    boneExtra = sklData.Bones.Where(x => x.Hash == item.BoneHash).FirstOrDefault();
                string boneName  = "u" + item.BoneHash;

                if (boneExtra != null)
                {
                    boneName = boneExtra.Name;
                }

                foreach (var k in item.Quaternion)
                {
                    Vector3 v = k.Rotation.eulerAngles;
                    curvex.AddKey(k.Time, v.x);
                    curvey.AddKey(k.Time, v.y);
                    curvez.AddKey(k.Time, v.z);
                    //curvez.AddKey(k.Time, v.w);
                }

                var t = GetRelatedPath(obj, boneName);

                t = t.Replace(obj.name + "/", "");
                //localRotation
                //rotation
                clip.SetCurve(t, typeof(Transform), "localEulerAnglesRaw.x", curvex);
                clip.SetCurve(t, typeof(Transform), "localEulerAnglesRaw.y", curvey);
                clip.SetCurve(t, typeof(Transform), "localEulerAnglesRaw.z", curvez);
                //clip.SetCurve(t, typeof(Transform), "m_LocalEulerAngles.w", curvew);
            }

            animation.AddClip(clip, clip.name);
            animation.Play(clip.name);

            return(obj);
        }
Exemple #2
0
    // Token: 0x06000012 RID: 18 RVA: 0x00002348 File Offset: 0x00000748
    private void CreateGameObjects(AnmData anmData)
    {
        Texture2D texture2D  = Resources.Load <Texture2D>(this.pngName);
        Texture2D texture2D2 = new Texture2D(texture2D.width, texture2D.height, TextureFormat.RGB24, false);

        texture2D2 = texture2D;
        int width  = texture2D2.width;
        int height = texture2D2.height;
        int num    = anmData.modules.Length;

        this.modules = new Sprite[num];
        for (int i = 0; i < num; i++)
        {
            AnmModule anmModule = anmData.modules[i];
            int       x         = anmModule.x;
            int       num2      = height - anmModule.y - anmModule.h;
            int       w         = anmModule.w;
            int       h         = anmModule.h;
            Sprite    sprite    = Sprite.Create(texture2D2, new Rect((float)x, (float)num2, (float)w, (float)h), new Vector2(0f, 1f), 100f);
            this.modules[i] = sprite;
        }
        num          = anmData.sprites.Length;
        this.sprites = new GameObject[num];
        for (int j = 0; j < num; j++)
        {
            AnmSprite  anmSprite  = anmData.sprites[j];
            GameObject gameObject = new GameObject(string.Format("Sprite{0}", j));
            gameObject.AddComponent <SpriteRenderer>().sprite = this.modules[anmSprite.module];
            gameObject.transform.parent = base.gameObject.transform;
            float x2 = (float)anmSprite.x / 100f;
            float y  = (float)(-(float)anmSprite.y) / 100f;
            float z  = (float)(-(float)j) / 100f;
            gameObject.transform.position = new Vector3(x2, y, z);
            this.sprites[j] = gameObject;
        }
        this.Deactivate();
    }