Ejemplo n.º 1
0
        public static void Init(IEnumerable <GameObject> toConvert)
        {
            ConvertToPrefabEditorWindow window = CreateWindow <ConvertToPrefabEditorWindow>();

            window.InitializeWindow();
            window.SetGameObjectsToConvert(toConvert);
            window.Show();
        }
Ejemplo n.º 2
0
        public static GameObject[] CreateInstantiatedModelPrefab(
            GameObject [] unityGameObjectsToConvert)
        {
            var toExport = ModelExporter.RemoveRedundantObjects(unityGameObjectsToConvert);

            if (ExportSettings.instance.ShowConvertToPrefabDialog)
            {
                ConvertToPrefabEditorWindow.Init(toExport);
                return(toExport.ToArray());
            }

            var converted     = new List <GameObject>();
            var exportOptions = ExportSettings.instance.ConvertToPrefabSettings.info;

            foreach (var go in toExport)
            {
                var convertedGO = Convert(go, exportOptions: exportOptions);
                if (convertedGO != null)
                {
                    converted.Add(convertedGO);
                }
            }
            return(converted.ToArray());
        }
        public static GameObject[] CreateInstantiatedModelPrefab(
            GameObject[] unityGameObjectsToConvert)
        {
            var toExport = ModelExporter.RemoveRedundantObjects(unityGameObjectsToConvert);

            if (ExportSettings.instance.DisplayOptionsWindow)
            {
                if (toExport.Count == 1)
                {
                    var go = toExport.First();
                    if (PrefabUtility.IsPartOfNonAssetPrefabInstance(go) && !PrefabUtility.IsOutermostPrefabInstanceRoot(go))
                    {
                        DisplayInvalidSelectionDialog(go,
                                                      "Children of a Prefab instance cannot be converted.\nYou can open the Prefab in Prefab Mode or unpack the Prefab instance to convert it's children");
                        return(null);
                    }

                    if (PrefabUtility.IsPartOfPrefabAsset(go) && go.transform.parent != null)
                    {
                        DisplayInvalidSelectionDialog(go,
                                                      "Children of a Prefab Asset cannot be converted.\nYou can open the Prefab in Prefab Mode or unpack the Prefab instance to convert it's children");
                        return(null);
                    }

                    // can't currently handle converting root of prefab in prefab preview scene
                    if (SceneManagement.EditorSceneManager.IsPreviewSceneObject(go) && go.transform.parent == null)
                    {
                        DisplayInvalidSelectionDialog(go,
                                                      "Cannot convert Prefab root in the Prefab Preview Scene.\nYou can convert a Prefab Instance or convert the Prefab Asset directly in the Project view");
                        return(null);
                    }
                }
                ConvertToPrefabEditorWindow.Init(toExport);
                return(toExport.ToArray());
            }

            bool onlyPrefabAssets = ConvertToNestedPrefab.SetContainsOnlyPrefabAssets(unityGameObjectsToConvert);
            int  groupIndex       = -1;

            // If only Prefab Assets on disk are selected (nothing in the scene), then do not
            // try to undo as modifications on disk cannot be undone.
            if (!onlyPrefabAssets)
            {
                Undo.IncrementCurrentGroup();
                groupIndex = Undo.GetCurrentGroup();
                Undo.SetCurrentGroupName(UndoConversionCreateObject);
            }
            var converted     = new List <GameObject>();
            var exportOptions = ExportSettings.instance.ConvertToPrefabSettings.info;

            foreach (var go in toExport)
            {
                var convertedGO = Convert(go, exportOptions: exportOptions);
                if (convertedGO != null)
                {
                    converted.Add(convertedGO);
                }
            }
            if (!onlyPrefabAssets && groupIndex >= 0)
            {
                Undo.CollapseUndoOperations(groupIndex);
                Undo.IncrementCurrentGroup();
            }
            return(converted.ToArray());
        }