コード例 #1
0
        public void OnDestroy()
        {
            rootObjects = null;

            importMenu = null;

            fileSelector = null;

            if (importer != null)
            {
                importer.Dispose();
            }
        }
コード例 #2
0
        public void OnGUI()
        {
            //Initialisation/ reinit to avoid null object on runtime launch
            if (importer == null)
            {
                importer = new Model.Importer();
            }

            if (fileSelector == null)
            {
                fileSelector = new NativeSelectorEditor();
            }

            if (importMenu == null)
            {
                importMenu = new UI.Menu();
            }

            if (rootObjects == null)
            {
                rootObjects = new List <GameObject>();
            }

            GUILayout.BeginVertical();

            GUILayout.Label("Select files to import:");

            string[] extensions = importer.SupportedExtensions;

            for (int i = 0; i < extensions.Length; i++)
            {
                extensions[i] = extensions[i].Insert(0, "*.");
            }

            fileSelector.DisplayConfiguration(string.Join(";", extensions), true);

            if (fileSelector.Filenames != null)
            {
                if (fileSelector.Modified)
                {
                    displayAssimpOptions = false;

                    foreach (string file in fileSelector.Filenames)
                    {
                        if (Path.GetExtension(file).Remove(0, 1).ToLower() != Constants.binaryExtension)
                        {
                            displayAssimpOptions = true;

                            break;
                        }
                    }

                    importMenu.Options.Init(importer, fileSelector.Filenames);
                    fileSelector.Modified = false;
                }

                if (displayAssimpOptions)
                {
                    importMenu.DisplayConfiguration();
                }
                else
                {
                    GUILayout.FlexibleSpace();
                }

                if (GUILayout.Button("Import"))
                {
                    rootObjects.Clear();
                    duration = new TimeSpan(0);
                    vertices = 0;
                    faces    = 0;

                    importMenu.Options.ApplyConfiguration(importer);

                    // Use serialization to create a deep copy clone
                    Model.Option.Import options;
                    using (Stream stream = new MemoryStream())
                    {
                        IFormatter formatter = new BinaryFormatter();

                        formatter.Serialize(stream, importMenu.Options);

                        stream.Seek(0, SeekOrigin.Begin);

                        options = (Model.Option.Import)formatter.Deserialize(stream);
                    }

                    if (options != null)
                    {
                        IEnumerator it = Import(importer, options);

                        while (it.MoveNext())
                        {
                            ;
                        }
                    }
                    else
                    {
                        Debug.LogError("Impossible to save import options.");
                    }
                }

                bool display_stats = false;
                foreach (GameObject root in rootObjects)
                {
                    if (root != null)
                    {
                        EditorGUILayout.ObjectField(root, typeof(GameObject), false);

                        display_stats = true;
                    }
                }

                if (display_stats)
                {
                    EditorGUILayout.LabelField("Vertices: " + vertices);
                    EditorGUILayout.LabelField("Faces: " + faces);
                    EditorGUILayout.LabelField("Duration: " + duration);
                }
            }

            GUILayout.EndVertical();
        }