Пример #1
0
        void DestroyInternalEditor()
        {
            if (m_InternalEditor != null)
            {
                // Do not destroy anything if we are just reloading assemblies or re-importing.
                bool shouldDestroyEverything = Unsupported.IsDestroyScriptableObject(this);
                if (shouldDestroyEverything)
                {
                    DestroyImmediate(m_InternalEditor);
                }

                // On Destroy, look for instances id instead of target because they may already be null.
                for (var index = 0; index < m_PresetsInstanceIds.Count; index++)
                {
                    var instanceId = m_PresetsInstanceIds[index];
                    if (--s_References[instanceId].count == 0)
                    {
                        if (shouldDestroyEverything)
                        {
                            if (s_References[instanceId].reference is Component)
                            {
                                var go = ((Component)s_References[instanceId].reference).gameObject;
                                go.hideFlags = HideFlags.None; // make sure we remove the don't destroy flag before calling destroy
                                DestroyImmediate(go);
                            }
                            else
                            {
                                DestroyImmediate(s_References[instanceId].reference);
                            }
                        }
                        s_References.Remove(instanceId);
                    }
                }
            }
        }
        //		internal override void OnHeaderIconGUI(Rect iconRect)
        //		{
        //			this.assetEditor.OnHeaderIconGUI(iconRect);
        //		}

        //		internal override SerializedObject GetSerializedObjectInternal()
        //		{
        //			if (this.m_SerializedObject == null)
        //			{
        //				this.m_SerializedObject = SerializedObject.LoadFromCache(base.GetInstanceID());
        //			}
        //			if (this.m_SerializedObject == null)
        //			{
        //				this.m_SerializedObject = new SerializedObject(base.targets);
        //			}
        //			return this.m_SerializedObject;
        //		}

        public virtual void OnDisable()
        {
            AssetImporter assetImporter = this.target as AssetImporter;

            if (Unsupported.IsDestroyScriptableObject(this) && this.m_MightHaveModified && assetImporter != null && !InternalEditorUtility.ignoreInspectorChanges && this.HasModified() && !this.AssetWasUpdated())
            {
                string message = "Unapplied import settings for '" + assetImporter.assetPath + "'";
                if (base.targets.Length > 1)
                {
                    message = "Unapplied import settings for '" + base.targets.Length + "' files";
                }
                if (EditorUtility.DisplayDialog("Unapplied import settings", message, "Apply", "Revert"))
                {
                    this.Apply();
                    this.m_MightHaveModified = false;
                    AssetImporterInspector.ImportAssets(this.GetAssetPaths());
                }
            }

            /*
             * if (this.serializedObject != null && this.serializedObject.hasModifiedProperties)
             * {
             *      this.serializedObject.Cache(base.GetInstanceID());
             *      this.serializedObject = null;
             * }
             */
        }
 public override void OnDisable()
 {
     if (Unsupported.IsDestroyScriptableObject(this))
     {
         if (spriteAtlasAsset && HasModified())
         {
             if (EditorUtility.DisplayDialog("Unapplied import settings", "Unapplied import settings for \'" + m_AssetPath + "\'", "Apply", "Revert"))
             {
                 ApplyAndImportSpriteAtlas();
             }
             else
             {
                 ResetValues();
             }
         }
     }
     base.OnDisable();
 }
        public virtual void OnDisable()
        {
            ////FIXME: The code below wreaks havoc with tabbed editors.  Triggering a re-import will
            ////    cause all active editors to be destroyed which, if we're part of a tabbed editor,
            ////    will take down our parent while it is trying to switch editors.  Also, we'll be
            ////    doing all this while InspectorWindow.OnGUI() is still going through the active
            ////    editors to draw them so we're killing them right under its nose.

            // When destroying the inspector check if we have any unapplied modifications
            // and apply them.
            AssetImporter importer = target as AssetImporter;

            if (Unsupported.IsDestroyScriptableObject(this) && m_MightHaveModified && importer != null && HasModified() && !AssetWasUpdated())
            {
                string dialogText = string.Format(L10n.Tr("Unapplied import settings for \'{0}\'"), importer.assetPath);

                if (targets.Length > 1)
                {
                    dialogText = string.Format(L10n.Tr("Unapplied import settings for \'{0}\' files"), targets.Length);
                }

                if (EditorUtility.DisplayDialog(L10n.Tr("Unapplied import settings"), dialogText, L10n.Tr("Apply"), L10n.Tr("Revert")))
                {
                    Apply();
                    m_MightHaveModified = false;
                    ImportAssets(GetAssetPaths());
                }
            }

            // Only cache SerializedObject if it has modified properties.
            // If we have multiple editors (e.g. a tabbed editor and its editor for the active tab) we don't
            // want the one that doesn't do anything with the SerializedObject to overwrite the cache.
            if (m_SerializedObject != null && m_SerializedObject.hasModifiedProperties)
            {
                m_SerializedObject.Cache(GetInstanceID());
                m_SerializedObject = null;
            }
        }
Пример #5
0
        public virtual void OnDisable()
        {
            AssetImporter assetImporter = base.target as AssetImporter;

            if (Unsupported.IsDestroyScriptableObject(this) && this.m_MightHaveModified && assetImporter != null && !InternalEditorUtility.ignoreInspectorChanges && this.HasModified() && !this.AssetWasUpdated())
            {
                string message = string.Format(L10n.Tr("Unapplied import settings for '{0}'"), assetImporter.assetPath);
                if (base.targets.Length > 1)
                {
                    message = string.Format(L10n.Tr("Unapplied import settings for '{0}' files"), base.targets.Length);
                }
                if (EditorUtility.DisplayDialog(L10n.Tr("Unapplied import settings"), message, L10n.Tr("Apply"), L10n.Tr("Revert")))
                {
                    this.Apply();
                    this.m_MightHaveModified = false;
                    this.ImportAssets(this.GetAssetPaths());
                }
            }
            if (this.m_SerializedObject != null && this.m_SerializedObject.hasModifiedProperties)
            {
                this.m_SerializedObject.Cache(base.GetInstanceID());
                this.m_SerializedObject = null;
            }
        }
        public virtual void OnDisable()
        {
            EditorApplication.wantsToQuit            -= ApplicationWantsToQuit;
            AssemblyReloadEvents.afterAssemblyReload -= FixInspectorCache;
            AssetImporterEditorPostProcessAsset.OnAssetbundleNameChanged -= FixImporterAssetbundleName;

            if (!m_OnEnableCalled)
            {
                Debug.LogError($"{this.GetType().Name}.OnEnable must call base.OnEnable to avoid unexpected behaviour.");
            }

            // do not check on m_ApplyRevertGUICalled if OnEnable was never called
            // or we are closing before OnInspectorGUI have been called (which is the case in most of our EditorTests)
            if (m_OnEnableCalled && needsApplyRevert && !isInspectorDirty && !m_ApplyRevertGUICalled)
            {
                Debug.LogError($"{this.GetType().Name}.OnInspectorGUI must call ApplyRevertGUI to avoid unexpected behaviour.");
            }

            // When destroying the inspector check if we have any unapplied modifications
            // and apply them.
            if (Unsupported.IsDestroyScriptableObject(this))
            {
                if (!CheckForApplyOnClose())
                {
                    // we need to force back the current tracker to our assetTargets
                    if (!IsClosingInspector())
                    {
                        if (m_HasInspectorBeenSeenLocked)
                        {
                            m_Inspector.SetObjectsLocked(new List <Object>(assetTargets));
                        }
                        else
                        {
                            Selection.objects = assetTargets;
                        }
                    }
                    else
                    {
                        var inspector = ScriptableObject.CreateInstance <InspectorWindow>();
                        if (m_HasInspectorBeenSeenLocked)
                        {
                            inspector.SetObjectsLocked(new List <Object>(assetTargets));
                        }
                        else
                        {
                            Selection.objects = assetTargets;
                        }
                        inspector.Show(true);
                    }

                    if (s_UnreleasedInstances == null)
                    {
                        s_UnreleasedInstances = new List <int>();
                    }
                    foreach (var t in m_TargetsInstanceID)
                    {
                        s_UnreleasedInstances.Add(t);
                    }
                }
                else
                {
                    foreach (var t in m_TargetsInstanceID)
                    {
                        ReleaseInspectorCopy(t);
                    }
                }
            }

            m_OnEnableCalled       = false;
            m_ApplyRevertGUICalled = false;
        }
        // Called from a various number of places, like after an assembly reload or when the Editor gets created.
        internal sealed override void InternalSetTargets(Object[] t)
        {
            base.InternalSetTargets(t);

            if (m_CopySaved)                                             // coming back from an assembly reload or asset re-import
            {
                if (extraDataType != null && m_ExtraDataTargets != null) // we need to recreate the user custom array
                {
                    // just get back the data from customSerializedData array, it gets serialized and reconstructed properly
                    m_ExtraDataTargets = extraDataSerializedObject.targetObjects;
                }
                ReloadTargets(AssetWasUpdated());
            }
            else // newly created editor
            {
                var editors = Resources.FindObjectsOfTypeAll(this.GetType()).Cast <AssetImporterEditor>();

                CheckExtraDataArray();
                var loadedIds = new List <int>(t.Length);
                for (int i = 0; i < t.Length; ++i)
                {
                    int instanceID = t[i].GetInstanceID();
                    loadedIds.Add(instanceID);
                    var extraData = CreateOrReloadInspectorCopy(instanceID);
                    if (m_ExtraDataTargets != null)
                    {
                        // we got the data from another instance
                        if (extraData != null)
                        {
                            m_ExtraDataTargets[i] = extraData;
                        }
                        else
                        {
                            m_ExtraDataTargets[i]           = ScriptableObject.CreateInstance(extraDataType);
                            m_ExtraDataTargets[i].hideFlags = HideFlags.DontUnloadUnusedAsset | HideFlags.DontSaveInEditor;
                            InitializeExtraDataInstance(m_ExtraDataTargets[i], i);
                            SaveUserData(instanceID, m_ExtraDataTargets[i]);
                        }
                    }

                    // proceed to an editor count check to make sure we have the proper number of instances saved.
                    // If it is not the case, then a dispose was not done properly.
                    int count = editors.Count(e => !Unsupported.IsDestroyScriptableObject(e) && e.targets.Contains(t[i]));
                    if (s_UnreleasedInstances != null)
                    {
                        count += s_UnreleasedInstances.Count(id => id == instanceID);
                    }
                    var instances = GetInspectorCopyCount(instanceID);
                    if (count != instances)
                    {
                        if (!CanEditorSurviveAssemblyReload())
                        {
                            Debug.LogError($"The previous instance of {GetType()} was not un-loaded properly. The script has to be declared in a file with the same name.");
                        }
                        else
                        {
                            Debug.LogError($"The previous instance of {GetType()} has not been disposed correctly. Make sure you are calling base.OnDisable() in your AssetImporterEditor implementation.");
                        }

                        // Fix the cache count so it does not fail anymore.
                        FixCacheCount(instanceID, count);
                    }
                }

                // Clean-up previous instances now that we reloaded the copies
                if (s_UnreleasedInstances != null)
                {
                    for (var index = s_UnreleasedInstances.Count - 1; index >= 0; index--)
                    {
                        var copy = s_UnreleasedInstances[index];
                        if (loadedIds.Contains(copy))
                        {
                            ReleaseInspectorCopy(copy);
                            s_UnreleasedInstances.RemoveAt(index);
                        }
                    }
                }

                m_TargetsInstanceID = loadedIds;
                m_CopySaved         = true;
            }
        }