private void OpenFile() { string path = EditorUtility.OpenFilePanel("Open", LocationEditorHelper.locationFolder, "json"); if (LocationEditorHelper.LoadInterior(path, out levelData)) { if (parent != null) { DestroyImmediate(parent); } currentWorkFile = Path.GetFileName(path); parent = new GameObject("Location : " + currentWorkFile); LoadObjects(); editMode = EditMode.EditMode; } else { path = ""; } //We clear the Undo Undo.ClearAll(); }
protected override void OnKeyEvent(EventType type, Vector2 mousePosition, KeyCode keyCode) { if (!_IsActive) { return; } base.OnKeyEvent(type, mousePosition, keyCode); switch (type) { case EventType.MouseMove: _CurrentMousePosition = mousePosition; _ParentWindow.Repaint(); break; case EventType.MouseDown: var position = _ParentWindow.Grid.GUIToGrid(mousePosition); if (Event.current.button == 0) { Undo.RegisterCompleteObjectUndo(_CurrentRoom, "Add Room point"); if (!_CurrentRoom.Add(_CurrentRoom.ParentApartment.Dimensions.Clamp(position))) { Undo.ClearAll(); _ParentWindow.CreateRoomStateEnd(_CurrentRoom); } } break; } }
void OnCriterionCompleted(Criterion sender) { if (!m_Paragraphs.Any(p => p.criteria.Any(c => c.criterion == sender))) { return; } if (sender.completed) { int paragraphIndex, criterionIndex; if (GetIndicesForCriterion(sender, out paragraphIndex, out criterionIndex)) { // only play sound effect and clear undo if all preceding criteria are already complete var playSoundEffect = true; for (int i = 0; i < paragraphIndex; ++i) { if (!m_Paragraphs[i].criteria.All(c => c.criterion.completed)) { playSoundEffect = false; break; } } if (playSoundEffect) { Undo.ClearAll(); if (m_CompletedSound != null) { AudioUtilProxy.PlayClip(m_CompletedSound); } playedCompletionSound?.Invoke(this); } } } ValidateCriteria(); }
protected override void OnDestroy() { base.OnDestroy(); DeselectCurrentGraphOrAnyOfItsNodes(); WindowSettings.SetDirty(true); Undo.ClearAll(); }
void Start() { Undo.ClearAll(); for (int i = 0; i < states.Count; i++) { states[i].GetComponent <Links>().State = (LinkState)i; // Debug.Log((LinkState)i); } List <LinkData> PlayerChain = new List <LinkData>(); List <LinkData> EnemyChain = new List <LinkData>(); if (File.Exists(Application.dataPath + "/StreamingAssets/Player.json")) { PlayerChain = JsonMapper.ToObject <List <LinkData> >(File.ReadAllText(Application.dataPath + "/StreamingAssets/Player.json")); } if (File.Exists(Application.dataPath + "/StreamingAssets/Enemy.json")) { EnemyChain = JsonMapper.ToObject <List <LinkData> >(File.ReadAllText(Application.dataPath + "/StreamingAssets/Enemy.json")); } if (GameObject.FindGameObjectsWithTag("SceneIdentifier").Length > 1) { LoadSession(EnemyChain); } else { LoadSession(PlayerChain); } }
static void RemoveComponent(MenuCommand command) { CustomMonoBehaviour target = (CustomMonoBehaviour)command.context; if (PrefabUtility.IsPartOfPrefabAsset(target)) { var prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(target); var root = PrefabUtility.LoadPrefabContents(prefabPath); target.onPrefabAssetRemoveComponent?.Invoke(root); // note that in the prefab asset inspector, you can only inspect the root gameObject, so the // removed component must be a part of it; automatically picks the right CustomMonoBehaviour DestroyImmediate(root.GetComponent <CustomMonoBehaviour>()); PrefabUtility.SaveAsPrefabAsset(root, prefabPath); PrefabUtility.UnloadPrefabContents(root); Undo.ClearAll(); // not the best fix for unexpected Undo behaviour } else { Undo.DestroyObjectImmediate(target); } }
public static void Initialize(bool createNewIvy) { Undo.ClearAll(); EditorApplication.playModeStateChanged += OnPlayModeStateChanged; ivyParametersGUI = ScriptableObject.CreateInstance <IvyParametersGUI>(); controller = ScriptableObject.CreateInstance <RealIvyProWindowController>(); controller.Init(instance, ivyParametersGUI); windowSkin = (GUISkin)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("b0545e8c97ca8684182a76c2fb22c7ff"), typeof(GUISkin)); downArrowTex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("8ee6aee77df7d3e4485148aa889f9b6b"), typeof(Texture2D)); materialTex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("eb3b714e29c31744888e1bc4bcfe23d6"), typeof(Texture2D)); leaveTex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("14bbaf6e0a8b00f4ea30434e5eeeaf8c"), typeof(Texture2D)); dropdownShadowTex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("9cd9a16c9e229684983f50ff07427219"), typeof(Texture2D)); presetTex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("9dd821bf05e345d4a8a501a8768c7144"), typeof(Texture2D)); infoTex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("d73d5146604f9594996de4e08eec4bdf"), typeof(Texture2D)); Undo.undoRedoPerformed += MyUndoCallback; IvyPreset defaultPresset = GetDefaultPreset(); if (realIvyProToolsWindow != null) { realIvyProToolsWindow.QuitWindow(); } CreateTools(); if (createNewIvy) { controller.CreateNewIvy(defaultPresset); ivyParametersGUI.CopyFrom(controller.infoPool.ivyParameters); } }
static void ClearAllUndoHistory() { if (EditorUtility.DisplayDialog("Clear All Undo History", "Do you want to clear all undo history?", "Yes", "No")) { Undo.ClearAll(); Debug.Log("Clear All Undo History!"); } }
public void OnDestroy() { // 注意:清空所有撤销操作 Undo.ClearAll(); if (AssetBundleCollectorSettingData.IsDirty) { AssetBundleCollectorSettingData.SaveFile(); } }
private void SynchronizeUndoRedoState() { if (m_graphUndoStack == null) { return; } if (m_graphUndoStack.IsDirtyState()) { try { m_graphUndoStack.RestoreCurrentGraphState(); m_reentrant = true; ExpressionGraphDirty = true; model.GetOrCreateGraph().UpdateSubAssets(); EditorUtility.SetDirty(graph); NotifyUpdate(); m_reentrant = false; m_graphUndoStack.CleanDirtyState(); } catch (Exception e) { Debug.LogError(e); Undo.ClearAll(); m_graphUndoStack = new VFXGraphUndoStack(graph); } } else { //The graph didn't change by this undo, only, potentially the slot values. // Any undo could be a slot value undo: update input slot expressions and expression graph values ExpressionGraphDirty = true; ExpressionGraphDirtyParamOnly = true; if (model != null && graph != null) { foreach (var element in AllSlotContainerControllers) { foreach (var slot in (element.model as IVFXSlotContainer).inputSlots) { slot.UpdateDefaultExpressionValue(); } } foreach (var parameter in m_ParameterControllers.Keys) { parameter.UpdateDefaultExpressionValue(); } graph.SetExpressionValueDirty(); } } }
public virtual void Term() { Undo.ClearAll(); if (string.IsNullOrEmpty(_testDirectory)) { return; } // Delete the directory on the next editor update. Otherwise, // prefabs don't get deleted and the directory delete fails. EditorApplication.update += DeleteOnNextUpdate; }
protected override void DeleteReferenceInstance(int index) { SOVariable source = (SOVariable)this.spReferences .GetArrayElementAtIndex(index) .objectReferenceValue; this.spReferences.RemoveFromObjectArrayAt(index); this.RemoveSubEditorsElement(index); DestroyImmediate(source, true); AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(Path.Combine(PATH_ASSET, NAME_ASSET)); Undo.ClearAll(); }
public void ProjectLocalesIsUpdatedWhenRemoveLocaleIsUndone() { Undo.ClearAll(); const string localeAssetPath = "Assets/HebrewRemove.asset"; var locale = Locale.CreateLocale(SystemLanguage.Hebrew); AssetDatabase.CreateAsset(locale, localeAssetPath); LocalizationEditorSettings.AddLocale(locale, false); Assert.That(LocalizationEditorSettings.GetLocales(), Does.Contain(locale), "Expected new locale asset to be added to Project Locales."); LocalizationEditorSettings.RemoveLocale(locale, true); Assert.That(LocalizationEditorSettings.GetLocales(), Does.Not.Contains(locale), "Expected locale to not be in project locales after calling RemoveLocale."); Undo.PerformUndo(); Assert.That(LocalizationEditorSettings.GetLocales(), Does.Contain(locale), "Expected locale asset to be in project locale after calling Undo."); Assert.True(AssetDatabase.DeleteAsset(localeAssetPath), "Failed to delete asset"); Undo.ClearAll(); }
public static void EventListener <T>(object obj, ref T value) { Event e = Event.current; if (e != null) { #if UNITY_2017_2_OR_NEWER if (e.control) { Undo.ClearAll(); } #endif if (e.control && e.keyCode == KeyCode.Z && obj.Equals(UndoHelper.obj)) { value = (T)cachedValue; GUI.SetNextControlName("noFocus"); GUI.Label(new Rect(-100, -100, 1, 1), ""); GUI.FocusControl("noFocus"); } } }
/// <Summary> /// Clear Undo/Redo stack to prevent setting data of another file. /// </Summary> void ClearUndoStack() { Undo.FlushUndoRecordObjects(); Undo.ClearAll(); }
public virtual void Init() { Undo.ClearAll(); }
protected IEnumerator TestPrereqCommandPostreq(TestingMode mode, Action checkReqs, Func <int, TestPhase> doUndoableStuff, Action checkPostReqs, int framesToWait = 1) { yield return(null); IEnumerator WaitFrames() { for (int i = 0; i < framesToWait; ++i) { yield return(null); } } int currentFrame; switch (mode) { case TestingMode.Command: BaseFixture.AssumePreviousTest(checkReqs); currentFrame = 0; while (doUndoableStuff(currentFrame++) == TestPhase.WaitForNextFrame) { yield return(null); } yield return(WaitFrames()); checkPostReqs(); break; case TestingMode.UndoRedo: Undo.ClearAll(); Undo.IncrementCurrentGroup(); BaseFixture.AssumePreviousTest(checkReqs); currentFrame = 0; while (doUndoableStuff(currentFrame++) == TestPhase.WaitForNextFrame) { yield return(null); } Undo.IncrementCurrentGroup(); yield return(WaitFrames()); BaseFixture.AssumePreviousTest(checkPostReqs); yield return(WaitFrames()); Undo.PerformUndo(); yield return(WaitFrames()); BaseFixture.AssertPreviousTest(checkReqs); Undo.PerformRedo(); yield return(WaitFrames()); BaseFixture.AssertPreviousTest(checkPostReqs); break; default: throw new ArgumentOutOfRangeException(); } }
private void MapGenerationGUI() { GUILayout.Label("Grid generation", EditorStyles.boldLabel); GUILayout.Label("Camera", EditorStyles.boldLabel); useMovableCamera = EditorGUILayout.Toggle("Use movable camera", useMovableCamera, new GUILayoutOption[0]); if (useMovableCamera) { cameraScrollSpeed = EditorGUILayout.FloatField(new GUIContent("Scroll Speed"), cameraScrollSpeed); cameraScrollEdge = EditorGUILayout.Slider("Scroll Edge", cameraScrollEdge, 0.05f, 0.25f, new GUILayoutOption[0]); } GUILayout.Label("Players", EditorStyles.boldLabel); nHumanPlayer = EditorGUILayout.IntField(new GUIContent("Human players No"), nHumanPlayer); nComputerPlayer = EditorGUILayout.IntField(new GUIContent("AI players No"), nComputerPlayer); GUILayout.Label("Grid", EditorStyles.boldLabel); mapTypeIndex = EditorGUILayout.Popup("Plane", mapTypeIndex, mapTypes, new GUILayoutOption[0]); GUI.changed = false; generatorIndex = EditorGUILayout.Popup("Generator", generatorIndex, generatorNames, new GUILayoutOption[0]); if (GUI.changed) { parameterValues = new Dictionary <string, object>(); } foreach (var field in generators[generatorIndex].GetFields().Where(f => f.IsPublic)) { if (field.FieldType == typeof(int)) { int x = 0; if (parameterValues.ContainsKey(field.Name)) { x = (int)(parameterValues[field.Name]); } x = EditorGUILayout.IntField(new GUIContent(field.Name), x); parameterValues[field.Name] = x; } else if (field.FieldType == typeof(GameObject)) { GameObject g = null; if (parameterValues.ContainsKey(field.Name)) { g = (GameObject)(parameterValues[field.Name]); } g = (GameObject)EditorGUILayout.ObjectField(field.Name, g, typeof(GameObject), false, new GUILayoutOption[0]); parameterValues[field.Name] = g; if (mapTypes[mapTypeIndex].Equals(MAP_TYPE_3D) && g != null && g.GetComponent <Collider2D>() != null) { shouldDisplayCollider2DWarning = true; } else { shouldDisplayCollider2DWarning = false; } } } if (shouldDisplayCollider2DWarning) { GUIStyle style = new GUIStyle(EditorStyles.wordWrappedLabel); style.fontStyle = FontStyle.Bold; style.normal.textColor = Color.red; GUILayout.Label("You are trying to generate a map on XZ plane with a prefab containg a 2D collider. 2D colliders will not work in XZ axis. Add a 3D collider to your tile prefab or select XY plane", style); } if (GUILayout.Button("Generate scene")) { Undo.ClearAll(); GenerateBaseStructure(); } if (GUILayout.Button("Clear scene")) { string dialogTitle = "Confirm delete"; string dialogMessage = "This will delete all objects on the scene. Do you wish to continue?"; string dialogOK = "Ok"; string dialogCancel = "Cancel"; bool shouldDelete = EditorUtility.DisplayDialog(dialogTitle, dialogMessage, dialogOK, dialogCancel); if (shouldDelete) { Undo.ClearAll(); GridHelperUtils.ClearScene(); } } }
public override void TearDown() { base.TearDown(); Undo.ClearAll(); }
static void ExchangeSnapToObject() { Transform[] transforms = Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable); if (transforms.Length == 0) { EditorUtility.DisplayDialog("No selections in the scene", "Need to select at least one object.", "Ok"); return; } Dictionary <string, string> ObjInfo = new Dictionary <string, string>(); ObjInfo.Clear(); ObjInfo = GetObjectMatchingTable(PrefabPath); foreach (Transform t in transforms) { string FoundPrefabPath = GetPrefabPath(t.gameObject); if (!FoundPrefabPath.ToLower().Contains(PrefabPath.Replace(Application.dataPath, string.Empty).ToLower())) { return; } FoundPrefabPath = Path.GetFileNameWithoutExtension(FoundPrefabPath).ToLower(); if (ObjInfo.ContainsKey(FoundPrefabPath)) { string targetPrefab = string.Empty; if (ObjInfo.TryGetValue(FoundPrefabPath, out targetPrefab)) { bool swapResult = SwapGameObjectByTargetPath(t.gameObject, targetPrefab); if (swapResult == false) { Debug.LogWarning(string.Format("Could not swap the object : {0}", t.name)); } } } else { Selection.activeObject = t; Debug.LogWarning(string.Format("Could not find the matchable object : {0}", t.name)); Regex reg = new Regex(@"_snaps[0-9][0-9][0-9]$"); string pPath = GetPrefabPath(t.gameObject).ToLower(); Undo.RegisterCompleteObjectUndo(t.gameObject, "Before unpacking"); UnpackNestedPrefab.UnpackSelectedPrefab(t.gameObject); Transform[] childTransforms = t.gameObject.GetComponentsInChildren <Transform>(); int successCount = 0; foreach (Transform childTransform in childTransforms) { if (childTransform == null) { continue; } if (childTransform.gameObject == null) { continue; } if (PrefabUtility.GetPrefabAssetType(childTransform.gameObject) != PrefabAssetType.Regular) { continue; } Selection.activeObject = childTransform.gameObject; if (ReExchangeSnapToObject()) { successCount++; } } if (successCount < 1) { Undo.PerformUndo(); //Undo.ClearUndo(t.gameObject); continue; } string GenSnapsHDPath = UnpackNestedPrefab.CreateGenSnapsHDFolder(); string GenSnapsPrototypePath = UnpackNestedPrefab.CreateGenSnapsPrototypeFolder(); string GenSnapsName = string.Empty; if (reg.IsMatch(FoundPrefabPath)) { GenSnapsName = string.Format("{0}/{1}.prefab", GenSnapsHDPath, FoundPrefabPath); } else { GenSnapsName = string.Format("{0}/{1}_{2}.prefab", GenSnapsHDPath, FoundPrefabPath, PrefabPostfix); } Object GenPrefab = PrefabUtility.SaveAsPrefabAsset(t.gameObject, GenSnapsName); SwapGameObjectByTargetPath(t.gameObject, GenSnapsName); reg = new Regex(@"_snaps[0-9][0-9][0-9].prefab$"); if (pPath.Contains(UnpackNestedPrefab.PrefabRoot.ToLower())) { if (!reg.IsMatch(pPath)) { AssetDatabase.RenameAsset(pPath, Path.GetFileNameWithoutExtension(pPath) + "_" + PrefabPostfix); } } else { if (!reg.IsMatch(pPath)) { AssetDatabase.MoveAsset(pPath, GenSnapsPrototypePath + "/" + Path.GetFileNameWithoutExtension(pPath) + "_" + PrefabPostfix + ".prefab"); } else { AssetDatabase.MoveAsset(pPath, GenSnapsPrototypePath + "/" + Path.GetFileName(pPath)); } } } } Undo.ClearAll(); }