//----------------------------------------------------------------------------------------------------------------------

        private static void InitializeAssetFromDefaultAsset(StreamingImageSequencePlayableAsset playableAsset,
                                                            UnityEditor.DefaultAsset timelineDefaultAsset)
        {
            string     path        = AssetDatabase.GetAssetPath(timelineDefaultAsset).Replace("\\", "/");
            const bool ASK_TO_COPY = false;

            ImageSequenceImporter.ImportImages(path, playableAsset, ASK_TO_COPY);
        }
Beispiel #2
0
        private static void RegisterFilesAndCreateStreamingImageSequence()
        {
            string path = EditorUtility.OpenFilePanel("Open File", "", PNG_EXTENSION + "," + TGA_EXTENSION);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            ImageSequenceImporter.ImportImages(path, null);
        }
//----------------------------------------------------------------------------------------------------------------------

        /// Import images in the path to create StreamingImageSequence assets with those images
        /// <param name="path"> Can be a directory path or a file path</param>
        /// <param name="targetAsset"> The target asset where the images are assigned to</param>
        /// <param name="askToCopy"> Ask to copy if path is not under StreamingAssets. Default to true</param>
        internal static void ImportImages(string path,
                                          StreamingImageSequencePlayableAsset targetAsset, bool askToCopy = true)
        {
            Assert.IsFalse(string.IsNullOrEmpty(path));

            FindFolderAndImages(path, out string folder, out List <WatchedFileInfo> relFilePaths);
            if (relFilePaths.Count <= 0)
            {
                EditorUtility.DisplayDialog(StreamingImageSequenceConstants.DIALOG_HEADER, @"No files in folder:: " + folder, "OK");
                return;
            }

            //Estimate the asset name. Use the filename without numbers at the end
            string assetName = EstimateAssetName(relFilePaths[0].GetName());

            // set dest folder
            string streamingAssetsPath = AssetUtility.NormalizeAssetPath(Application.streamingAssetsPath);

            //Set importer param
            ImageFileImporterParam importerParam = new ImageFileImporterParam {
                strSrcFolder          = folder,
                ImageFiles            = relFilePaths,
                CopyToStreamingAssets = true,
                TargetAsset           = targetAsset
            };


            //Import immediately if the assets are already under StreamingAssets
            if (folder.StartsWith(streamingAssetsPath) || !askToCopy)
            {
                importerParam.strDstFolder          = importerParam.strSrcFolder;
                importerParam.CopyToStreamingAssets = false;
                ImageSequenceImporter.Import(importerParam);
            }
            else
            {
                importerParam.strDstFolder = Path.Combine(streamingAssetsPath, assetName).Replace("\\", "/");
                ImageSequenceImportWindow.Show(importerParam);
            }
        }
Beispiel #4
0
//----------------------------------------------------------------------------------------------------------------------
    private void ImportImages(string path) {
        ImageSequenceImporter.ImportImages(path, m_asset);
        m_isImageListDirty = true;
    }
//----------------------------------------------------------------------------------------------------------------------

        void OnGUI()
        {
            if (m_importerParam == null)
            {
                Debug.LogError("m_importerParam is null");
                return;
            }

            InitStyles();


            Rect rect  = new Rect(0, 0, Screen.width, Screen.height);
            Rect rect2 = new Rect(2, 2, Screen.width - 4, Screen.height - 4);

            EditorGUI.DrawRect(rect, Color.gray);
            EditorGUI.DrawRect(rect2, new Color(0.3f, 0.3f, 0.3f));
            EditorGUILayout.BeginVertical();
            GUILayout.Space(8);

            GUILayout.Label(StreamingImageSequenceConstants.DIALOG_HEADER + " Importer", m_headerStyle);
            if (m_importerParam.ImageFiles != null)
            {
                int numFiles = m_importerParam.ImageFiles.Count;
                GUILayout.Label(numFiles.ToString() + " external files found in: ");
                GUILayout.Label(m_importerParam.strSrcFolder);

                const int SCROLL_VIEW_COUNT  = 16;
                const int SCROLL_ITEM_HEIGHT = 12;
                const int TOP_MARGIN         = 12;

                int numDigits = (int)Math.Floor(Math.Log10(numFiles) + 1);

                m_scrollPos = DrawScrollView(m_scrollPos, TOP_MARGIN, numFiles, SCROLL_VIEW_COUNT, SCROLL_ITEM_HEIGHT, (int index) => {
                    GUILayout.Space(30);

                    string indexStr = index.ToString();
                    indexStr        = indexStr.PadLeft(numDigits - indexStr.Length);

                    string str = indexStr + ":";

                    EditorGUILayout.LabelField(str, GUILayout.Width(40));
                    EditorGUILayout.LabelField(m_importerParam.ImageFiles[index].GetName());
                });
            }

            GUILayout.Space(4);


            //Copy Toggle
            EditorGUILayout.BeginHorizontal();
            // C#var options = new GUILayoutOption[] { GUILayout.MaxWidth(Screen.width- space), GUILayout.MinWidth(120.0F) };
            string copyText = @"Copy to StreamingAssets (Recommended)";

            m_importerParam.CopyToStreamingAssets = GUILayout.Toggle(m_importerParam.CopyToStreamingAssets, copyText);
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(8);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(8);
            EditorGUI.BeginDisabledGroup(!m_importerParam.CopyToStreamingAssets);
            EditorGUILayout.LabelField("Copy to:", GUILayout.Width(120));
            m_importerParam.strDstFolder = EditorGUILayout.TextField(m_importerParam.strDstFolder);
            if (GUILayout.Button("...", GUILayout.Width(40)))
            {
                if (Directory.Exists(m_importerParam.strDstFolder))
                {
                    m_importerParam.strDstFolder = EditorUtility.OpenFolderPanel("Choose folder to copy", m_importerParam.strDstFolder, null);
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(4);


            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(320 / 2);
            if (GUILayout.Button("OK"))
            {
                ImageSequenceImporter.Import(m_importerParam);

                this.Close();
            }

            if (GUILayout.Button("Cancel"))
            {
                this.Close();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
        }