Exemplo n.º 1
0
 public void SetParam(MovieProxyPlayableAssetParam param)
 {
     Version    = param.Version;
     Resolution = param.Resolution;
     QuadSize   = param.QuadSize;
     Pictures   = param.Pictures;
     Folder     = param.Folder;
 }
Exemplo n.º 2
0
        public static void import(PictureFileImporterParam param)
        {
            if (param.DoNotCopy)
            {
                param.strDstFolder = param.strSrcFolder.Replace("\\", "/");
            }
            else
            {
                string dstFolder = param.strDstFolder.Replace("\\", "/");
                if (param.mode == PictureFileImporterParam.Mode.StereamingAssets)
                {
                    if (dstFolder.StartsWith(Application.dataPath) && !dstFolder.StartsWith(Path.Combine(Application.dataPath, "StreamingAssets").Replace("\\", "/")))
                    {
                        Debug.LogError("Files must be located under StreamingAssets folder.");
                        return;
                    }
                }
                else
                {
                    if (dstFolder.StartsWith(Application.dataPath) && dstFolder.StartsWith(Path.Combine(Application.dataPath, "StreamingAssets").Replace("\\", "/")))
                    {
                        Debug.LogError("Files must not be located under StreamingAssets folder.");
                        return;
                    }
                }

                if (!Directory.Exists(param.strDstFolder))
                {
                    Directory.CreateDirectory(param.strDstFolder);
                }

                for (int ii = 0; ii < param.files.Length; ii++)
                {
                    string strAbsFilePathDst = Path.Combine(param.strDstFolder, param.files[ii]).Replace("\\", "/");
                    if (File.Exists(strAbsFilePathDst))
                    {
                        File.Delete(strAbsFilePathDst);
                    }
                    string strAbsFilePathSrc = Path.Combine(param.strSrcFolder, param.files[ii]).Replace("\\", "/");
                    FileUtil.CopyFileOrDirectory(strAbsFilePathSrc, strAbsFilePathDst);
                }
            }

            /// ceate assets
            MovieProxyPlayableAssetParam trackMovieContainer = new MovieProxyPlayableAssetParam();

            trackMovieContainer.Pictures = new string[param.files.Length];
            for (int ii = 0; ii < param.files.Length; ii++)
            {
                trackMovieContainer.Pictures[ii] = param.files[ii];
            }

            ///   if possible, convert folder names to relative path.
            string strUnityProjectFolder = null;
            Regex  regAssetFolder        = new Regex("/Assets$");

            strUnityProjectFolder = Application.dataPath;
            strUnityProjectFolder = regAssetFolder.Replace(strUnityProjectFolder, "");


            if (param.strDstFolder.StartsWith(strUnityProjectFolder))
            {
                int start = strUnityProjectFolder.Length + 1;
                int end   = param.strDstFolder.Length - start;
                param.strDstFolder = param.strDstFolder.Substring(start, end);
            }
            trackMovieContainer.Folder = param.strDstFolder;

            if (param.mode == PictureFileImporterParam.Mode.SpriteAnimation)
            {
                Sprite[] sprites = new Sprite[param.files.Length];
                for (int ii = 0; ii < param.files.Length; ii++)
                {
                    string strAssetPath = Path.Combine(param.strDstFolder, param.files[ii]).Replace("\\", "/");

                    AssetDatabase.ImportAsset(strAssetPath);
                    TextureImporter importer = AssetImporter.GetAtPath(strAssetPath) as TextureImporter;
                    importer.textureType = TextureImporterType.Sprite;
                    AssetDatabase.WriteImportSettingsIfDirty(strAssetPath);

                    Texture2D tex = (Texture2D)AssetDatabase.LoadAssetAtPath(strAssetPath, typeof(Texture2D));

                    sprites[ii] = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f));
                }

                AnimationClip newClip = new AnimationClip();
                newClip.wrapMode = WrapMode.Once;
                SerializedObject   serializedClip = new SerializedObject(newClip);
                SerializedProperty settings       = serializedClip.FindProperty("m_AnimationClipSettings");
                while (settings.Next(true))
                {
                    if (settings.name == "m_LoopTime")
                    {
                        break;
                    }
                }

                settings.boolValue = true;
                serializedClip.ApplyModifiedProperties();
                ObjectReferenceKeyframe[] Keyframes    = new ObjectReferenceKeyframe[param.files.Length];
                EditorCurveBinding        curveBinding = new EditorCurveBinding();


                for (int ii = 0; ii < param.files.Length; ii++)
                {
                    Keyframes[ii]       = new ObjectReferenceKeyframe();
                    Keyframes[ii].time  = 0.25F * ii;
                    Keyframes[ii].value = sprites[ii];
                }
#if false
                curveBinding.type         = typeof(SpriteRenderer);
                curveBinding.path         = string.Empty;
                curveBinding.propertyName = "m_Sprite";
#else
                curveBinding.type         = typeof(Image);
                curveBinding.path         = string.Empty;
                curveBinding.propertyName = "m_Sprite";
#endif
                AnimationUtility.SetObjectReferenceCurve(newClip, curveBinding, Keyframes);
                AssetDatabase.CreateAsset(newClip, Path.Combine(param.strDstFolder, "Animation.anim").Replace("\\", "/"));

                //            var proxyAsset = ScriptableObject.CreateInstance<MovieProxyPlayableAsset>(); //new MovieProxyPlayableAsset(trackMovieContainer);
                //            proxyAsset.SetParam(trackMovieContainer);
                //            var strProxyPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", param.strAssetName + "_MovieProxy.playable").Replace("\\", "/"));*/
                AssetDatabase.Refresh();
            }
            else
            {
                var proxyAsset = ScriptableObject.CreateInstance <MovieProxyPlayableAsset>(); //new MovieProxyPlayableAsset(trackMovieContainer);
                proxyAsset.SetParam(trackMovieContainer);
                var strProxyPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", param.strAssetName + "_MovieProxy.playable").Replace("\\", "/"));

                AssetDatabase.CreateAsset(proxyAsset, strProxyPath);
                if (!param.DoNotCopy)
                {
                    AssetDatabase.Refresh();
                }
            }
        }