Пример #1
0
        public void DestroyExportedModel(CSGModelExported exportedModel, bool undoable = false)
        {
            if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (undoable)            // && exportedModel)
            {
                UnityEditor.Undo.RegisterCompleteObjectUndo(exportedModel, "Destroying model");
            }

            if (exportedModel.hiddenComponents != null)
            {
                foreach (var hiddenComponent in exportedModel.hiddenComponents)
                {
                    var behaviour = hiddenComponent.behaviour;
                    if (!behaviour)
                    {
                        continue;
                    }

                    if (undoable)
                    {
                        UnityEditor.Undo.DestroyObjectImmediate(behaviour);
                    }
                    else
                    {
                        UnityEngine.Object.DestroyImmediate(behaviour);
                    }
                }
            }

            if (exportedModel.containedModel)
            {
                if (undoable)
                {
                    UnityEditor.Undo.DestroyObjectImmediate(exportedModel.containedModel);
                }
                else
                {
                    UnityEngine.Object.DestroyImmediate(exportedModel.containedModel);
                }
            }
        }
        public static void ReverseExport(CSGModelExported exported)
        {
            if (exported.hiddenComponents != null)
            {
                for (var i = exported.hiddenComponents.Length - 1; i >= 0; i--)
                {
                    if (!exported.hiddenComponents[i].behaviour)
                    {
                        continue;
                    }

                    Undo.RegisterCompleteObjectUndo(exported.hiddenComponents[i].behaviour, "Show hidden component");
                    exported.hiddenComponents[i].behaviour.enabled   = exported.hiddenComponents[i].enabled;
                    exported.hiddenComponents[i].behaviour.hideFlags = exported.hiddenComponents[i].hideFlags;
                }
            }
            if (exported.containedExportedModel)
            {
                UnityEditor.Undo.DestroyObjectImmediate(exported.containedExportedModel);
            }
        }