Esempio n. 1
0
    void updateFrame(int f, float scale = 0.5f)
    {
        if (pause)
        {
            return;
        }

        for (int i = 0; i < objects.Count; i++)
        {
            Destroy(objects[i]);
            objects[i].transform.SetParent(null);
        }

        objects.Clear();
        objectsAlpha.Clear();

        if (onAnimationEvent != null)
        {
            onAnimationEvent(f);
        }

        frameTime = 0.04f + saf1[f].time * 0.04f + delay;

        for (int i = 0; i < saf1[f].count; i++)
        {
            if (UI)
            {
                GameObject objImage = Resources.Load <GameObject>("Prefab/Image");

                GameObject img = Instantiate(objImage);
                img.name = animationName + "_t" + (saf1[f].saf11[i].textureID);

                RectTransform trans = img.GetComponent <RectTransform>();

                trans.SetParent(transform);
                trans.pivot            = pivot;
                trans.localScale       = new Vector3(1.0f, 1.0f, 1.0f);
                trans.anchoredPosition = new Vector2(saf1[f].saf11[i].textureX + offsetX
                                                     , -saf1[f].saf11[i].textureY + offsetY);


                Image image = img.GetComponent <Image>();

                image.color = color;

                switch (saf1[f].saf11[i].unknow10)
                {
                case 16:
                {
                    float alpha = Mathf.Min(saf1[f].saf11[i].unknow8 * 0.05f, 1.0f);
                    image.color = new Color(1.0f, 1.0f, 1.0f, alpha);
                }
                break;

                default:
                    break;
                }

                int otherTextureID = GameDefine.INVALID_ID;

                if (saf1[f].saf11[i].textureID >= 0x8000)
                {
                    otherTextureID = saf1[f].saf11[i].textureID - 0x8000 + 1;
                }

                if (otherTextureID != GameDefine.INVALID_ID)
                {
                    if (otherGameAnimation == null)
                    {
                        objects.Add(img);
                        objectsAlpha.Add(image.color.a);
                        continue;
                    }

                    if (otherGameAnimation.sprites != null &&
                        otherGameAnimation.sprites.Length > 0)
                    {
                        if (otherGameAnimation.saf1[otherTextureID].saf11.Length == 0)
                        {
                            otherTextureID = 1;
                        }

                        image.sprite = otherGameAnimation.sprites[otherGameAnimation.saf1[otherTextureID].saf11[0].textureID];
                    }
                    else
                    {
                        image.sprite = Resources.Load <Sprite>("Texture/" + otherGameAnimation.animationName + "_t" + (otherGameAnimation.saf1[otherTextureID].saf11[0].textureID));

                        if (image.sprite == null)
                        {
                            string[] nn = otherGameAnimation.animationName.Split('/');
                            image.sprite = Resources.Load <Sprite>("Texture/" + otherGameAnimation.animationName + "/" + nn[nn.Length - 1] + "_t" + (otherGameAnimation.saf1[otherTextureID].saf11[0].textureID));
                        }
                    }

                    image.material = GameMaterialConfig.instance.getMaterial(otherGameAnimation.saf1[otherTextureID].saf11[0].textureType);

                    //#if UNITY_EDITOR
                    if (image.sprite == null)
                    {
                        //                Debug.Log( "animationName" + animationName );
                        objects.Add(img);
                        objectsAlpha.Add(image.color.a);
                        continue;
                    }
                    //#endif
                    scale = 0.5f;
                    float w1 = image.sprite.rect.width * scale;
                    float h1 = image.sprite.rect.height * scale;

                    trans.sizeDelta = new Vector2(w1, h1);

                    trans.SetAsFirstSibling();
                    //            image.SetNativeSize();


                    objects.Add(img);
                    objectsAlpha.Add(image.color.a);

                    continue;
                }

                if (sprites != null &&
                    sprites.Length > 0)
                {
                    image.sprite = sprites[saf1[f].saf11[i].textureID];
                }
                else
                {
                    image.sprite = Resources.Load <Sprite>("Texture/" + animationName + "_t" + (saf1[f].saf11[i].textureID));

                    if (image.sprite == null)
                    {
                        string[] nn = animationName.Split('/');
                        image.sprite = Resources.Load <Sprite>("Texture/" + animationName + "/" + nn[nn.Length - 1] + "_t" + (saf1[f].saf11[i].textureID));
                    }
                }

                int type = saf1[f].saf11[i].textureType;

                if (type == 7)
                {
                    trans.SetAsFirstSibling();
                }

                if (saf1[f].saf11[i].textureType == 2 &&
                    saf1[f].saf11[i].unknow10 == 0)
                {
                    type = 0;
                }

                image.material = GameMaterialConfig.instance.getMaterial(type);

                //#if UNITY_EDITOR
                if (image.sprite == null)
                {
                    //                Debug.Log( "animationName" + animationName );
                    objects.Add(img);
                    objectsAlpha.Add(image.color.a);
                    continue;
                }
                //#endif
                scale = 0.5f;
                float w = image.sprite.rect.width * scale;
                float h = image.sprite.rect.height * scale;

                trans.sizeDelta = new Vector2(w, h);

                if (pivot.x == 0.0f && pivot.y == 0.0f)
                {
                    trans.localScale       = new Vector3(-1.0f, 1.0f, 1.0f);
                    trans.anchoredPosition = new Vector2(w + saf1[f].saf11[i].textureX + offsetX
                                                         , -saf1[f].saf11[i].textureY + offsetY);
                }

                //            image.SetNativeSize();

                objects.Add(img);
                objectsAlpha.Add(image.color.a);
            }
            else
            {
                GameObject objSprite = Resources.Load <GameObject>("Prefab/Sprite");

                GameObject sprite = Instantiate(objSprite);
                sprite.name = animationName + "_t" + (saf1[f].saf11[i].textureID);

                Transform trans = sprite.transform;

                trans.SetParent(transform);
                trans.localScale    = new Vector3(1.0f, 1.0f, 1.0f);
                trans.localPosition = new Vector3(saf1[f].saf11[i].textureX + offsetX,
                                                  -saf1[f].saf11[i].textureY + offsetY,
                                                  -i);

                SpriteRenderer spriteRenderer = sprite.GetComponent <SpriteRenderer>();
                spriteRenderer.color = color;

                switch (saf1[f].saf11[i].unknow10)
                {
                case 16:
                {
                    float alpha = Mathf.Min(saf1[f].saf11[i].unknow8 * 0.05f, 1.0f);
                    spriteRenderer.color = new Color(color.r, color.g, color.b, color.a * alpha);
                }
                break;

                default:
                    break;
                }

                if (sprites != null &&
                    sprites.Length > 0)
                {
                    spriteRenderer.sprite = sprites[saf1[f].saf11[i].textureID];
                }
                else
                {
                    spriteRenderer.sprite = Resources.Load <Sprite>("Texture/" + animationName + "_t" + (saf1[f].saf11[i].textureID));

                    if (spriteRenderer.sprite == null)
                    {
                        string[] nn = animationName.Split('/');
                        spriteRenderer.sprite = Resources.Load <Sprite>("Texture/" + animationName + "/" + nn[nn.Length - 1] + "_t" + (saf1[f].saf11[i].textureID));
                    }
                }

                int type = saf1[f].saf11[i].textureType;

                if (type == 7)
                {
                    trans.localPosition = new Vector3(saf1[f].saf11[i].textureX + offsetX,
                                                      -saf1[f].saf11[i].textureY + offsetY,
                                                      i);
                }

                if (saf1[f].saf11[i].textureType == 2 &&
                    saf1[f].saf11[i].unknow10 == 0)
                {
                    type = 0;
                }

                spriteRenderer.material = GameMaterialConfig.instance.getMaterial(type);

                //#if UNITY_EDITOR
                if (spriteRenderer.sprite == null)
                {
                    //                Debug.Log( "animationName" + animationName );
                    objects.Add(sprite);
                    objectsAlpha.Add(spriteRenderer.color.a);
                    continue;
                }
                //#endif
                //            scale = 0.5f;
                //            float w = sprie.sprite.rect.width * scale;
                //            float h = sprie.sprite.rect.height * scale;

                //trans.sizeDelta = new Vector2( w , h );

                //            image.SetNativeSize();

                objects.Add(sprite);
                objectsAlpha.Add(spriteRenderer.color.a);
            }
        }

        active = saf1[f];

        if (saf1[f].sound != -1 &&
            playSound)
        {
            //            Debug.Log( "Sound/" + animationName + "_s" + saf1[ f ].sound );
            GameMusicManager.instance.playSound("Sound/" + saf1[f].sound);
        }
    }
Esempio n. 2
0
    public void load(string path)
    {
        int n1 = path.IndexOf("Objects/");

        animationName = path.Substring(n1 + 8, path.Length - n1 - 8 - 4).Replace("SAF/", "");

        safHead = new SAFHead();

        FileStream fs = File.OpenRead(path);

        byte[] bytes = new byte[fs.Length];
        fs.Read(bytes, 0, (int)fs.Length);

        int index = 0;

        safHead.count1 = (short)BitConverter.ToInt32(bytes, index); index += 2;
        safHead.count2 = (short)BitConverter.ToInt32(bytes, index); index += 2;

        saf1 = new SAF1[safHead.count1];
        saf2 = new SAF2[safHead.count2];

        for (int i = 0; i < 32; i++)
        {
            short count = (short)BitConverter.ToInt16(bytes, index); index += 2;
            safHead.count3[i] = count;
        }

//        Dictionary<int , int> dic = new Dictionary<int , int>();

        for (int i = 0; i < safHead.count1; i++)
        {
            saf1[i] = new SAF1();

            saf1[i].sound   = (short)BitConverter.ToInt16(bytes, index); index += 2;
            saf1[i].time    = (short)BitConverter.ToInt16(bytes, index); index += 2;
            saf1[i].hit     = bytes[index]; index += 1;
            saf1[i].color   = bytes[index]; index += 1;
            saf1[i].shake   = bytes[index]; index += 1;
            saf1[i].unknow4 = bytes[index]; index += 1;
            saf1[i].count   = (short)BitConverter.ToInt16(bytes, index); index += 2;

            saf1[i].saf11 = new SAF11[saf1[i].count];

            for (int j = 0; j < saf1[i].count; j++)
            {
                saf1[i].saf11[j] = new SAF11();

                saf1[i].saf11[j].textureID   = (ushort)BitConverter.ToUInt16(bytes, index); index += 2;
                saf1[i].saf11[j].textureX    = (short)BitConverter.ToInt16(bytes, index); index += 2;
                saf1[i].saf11[j].textureY    = (short)BitConverter.ToInt16(bytes, index); index += 2;
                saf1[i].saf11[j].textureType = bytes[index]; index += 1;
                saf1[i].saf11[j].unknow8     = (short)BitConverter.ToInt16(bytes, index); index += 2;
                saf1[i].saf11[j].unknow10    = (short)BitConverter.ToInt16(bytes, index); index += 2;
                saf1[i].saf11[j].unknow12    = (short)BitConverter.ToInt16(bytes, index); index += 2;

//                 if ( dic.ContainsKey( saf1[ i ].saf11[ j ].textureID ) )
//                 {
//                     if ( dic[ saf1[ i ].saf11[ j ].textureID ] != saf1[ i ].saf11[ j ].unknow8 )
//                     {
//                         Debug.Log( i + " " + j + " " + saf1[ i ].saf11[ j ].textureID + " " + dic[ saf1[ i ].saf11[ j ].textureID ]  + " " + saf1[ i ].saf11[ j ].unknow8 );
//                     }
//                 }
//                 else
//                 {
//                     dic.Add( saf1[ i ].saf11[ j ].textureID , saf1[ i ].saf11[ j ].unknow8 );
//                 }
            }
        }

        for (int i = 0; i < safHead.count2; i++)
        {
            saf2[i] = new SAF2();

            saf2[i].width  = (short)BitConverter.ToInt16(bytes, index); index += 2;
            saf2[i].height = (short)BitConverter.ToInt16(bytes, index); index += 2;
        }

        if (safHead.count2 > 0)
        {
            string[] str = animationName.Split('/');

            //        Debug.Log( "Assets/Objects/Texture/" + animationName + "/" + str[ str.Length - 1 ] + ".png" );
            UnityEngine.Object[] objs = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("Assets/Objects/Texture/" + animationName + "/" + str[str.Length - 1] + ".png");

            if (objs.Length > 0)
            {
                sprites = new Sprite[safHead.count2];

                for (int i = 0; i < sprites.Length; i++)
                {
                    sprites[i] = (Sprite)objs[i + 1];
//                    sprites[ i ].p
                }
            }
            else
            {
//                 for ( int i = 0 ; i < sprites.Length ; i++ )
//                 {
//                     sprites[ i ] = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>( "Assets/Objects/Texture/" + animationName + "/" + str[ str.Length - 1 ] + "_t" + i + ".png" );
//                 }
            }
        }

        //updateFrame( 0 );
    }