Ejemplo n.º 1
0
        public static void CreateAsset(string path, byte[] data)
        {
            EffekseerResourcePath resourcePath = new EffekseerResourcePath();

            if (!ReadResourcePath(data, ref resourcePath))
            {
                return;
            }

            float defaultScale = 1.0f;

            string assetPath = Path.ChangeExtension(path, ".asset");
            var    asset     = AssetDatabase.LoadAssetAtPath <EffekseerEffectAsset>(assetPath);

            if (asset != null)
            {
                defaultScale = asset.Scale;
            }

            string assetDir = assetPath.Substring(0, assetPath.LastIndexOf('/'));

            bool isNewAsset = false;

            if (asset == null)
            {
                isNewAsset = true;
                asset      = CreateInstance <EffekseerEffectAsset>();
            }

            asset.efkBytes = data;

            asset.textureResources = new EffekseerTextureResource[resourcePath.TexturePathList.Count];
            for (int i = 0; i < resourcePath.TexturePathList.Count; i++)
            {
                asset.textureResources[i] = EffekseerTextureResource.LoadAsset(assetDir, resourcePath.TexturePathList[i]);
            }

            asset.soundResources = new EffekseerSoundResource[resourcePath.SoundPathList.Count];
            for (int i = 0; i < resourcePath.SoundPathList.Count; i++)
            {
                asset.soundResources[i] = EffekseerSoundResource.LoadAsset(assetDir, resourcePath.SoundPathList[i]);
            }

            asset.modelResources = new EffekseerModelResource[resourcePath.ModelPathList.Count];
            for (int i = 0; i < resourcePath.ModelPathList.Count; i++)
            {
                asset.modelResources[i] = EffekseerModelResource.LoadAsset(assetDir, resourcePath.ModelPathList[i]);
            }

            asset.Scale = defaultScale;

            if (isNewAsset)
            {
                AssetDatabase.CreateAsset(asset, assetPath);
            }
            else
            {
                EditorUtility.SetDirty(asset);
            }

            AssetDatabase.Refresh();
        }
Ejemplo n.º 2
0
        public static bool ReadResourcePath(byte[] data, ref EffekseerResourcePath resourcePath)
        {
            if (data.Length < 4 || data[0] != 'S' || data[1] != 'K' || data[2] != 'F' || data[3] != 'E')
            {
                return(false);
            }

            int filepos = 4;

            // Get Format Version number
            resourcePath.Version = BitConverter.ToInt32(data, filepos);
            filepos += 4;

            resourcePath.TexturePathList = new List <string>();
            resourcePath.SoundPathList   = new List <string>();
            resourcePath.ModelPathList   = new List <string>();

            // Get color texture paths
            {
                int colorTextureCount = BitConverter.ToInt32(data, filepos);
                filepos += 4;
                for (int i = 0; i < colorTextureCount; i++)
                {
                    resourcePath.TexturePathList.Add(ReadString(data, ref filepos));
                }
            }

            if (resourcePath.Version >= 9)
            {
                // Get normal texture paths
                int normalTextureCount = BitConverter.ToInt32(data, filepos);
                filepos += 4;
                for (int i = 0; i < normalTextureCount; i++)
                {
                    resourcePath.TexturePathList.Add(ReadString(data, ref filepos));
                }

                // Get normal texture paths
                int distortionTextureCount = BitConverter.ToInt32(data, filepos);
                filepos += 4;
                for (int i = 0; i < distortionTextureCount; i++)
                {
                    resourcePath.TexturePathList.Add(ReadString(data, ref filepos));
                }
            }

            if (resourcePath.Version >= 1)
            {
                // Get sound paths
                int soundCount = BitConverter.ToInt32(data, filepos);
                filepos += 4;
                for (int i = 0; i < soundCount; i++)
                {
                    resourcePath.SoundPathList.Add(ReadString(data, ref filepos));
                }
            }

            if (resourcePath.Version >= 6)
            {
                // Get sound paths
                int modelCount = BitConverter.ToInt32(data, filepos);
                filepos += 4;
                for (int i = 0; i < modelCount; i++)
                {
                    resourcePath.ModelPathList.Add(ReadString(data, ref filepos));
                }
            }

            return(true);
        }