private static void OnSavedPrefabAddedToScene(GameObject instance, AGXUnity.IO.SavedPrefabLocalData savedPrefabData) { if (savedPrefabData == null || savedPrefabData.DisabledGroups.Length == 0) { return; } Undo.SetCurrentGroupName("Adding prefab data for " + instance.name + " to scene."); var grouId = Undo.GetCurrentGroup(); foreach (var disabledGroup in savedPrefabData.DisabledGroups) { TopMenu.GetOrCreateUniqueGameObject <CollisionGroupsManager>().SetEnablePair(disabledGroup.First, disabledGroup.Second, false); } Undo.CollapseUndoOperations(grouId); }
public void Duplicate(PathGuide toDupe) { #if UNITY_EDITOR Undo.SetCurrentGroupName("Duplicate Curve Node"); GameObject dupe = Instantiate(toDupe.gameObject); Undo.RegisterCreatedObjectUndo(dupe, ""); dupe.transform.parent = toDupe.transform.parent; dupe.transform.position = toDupe.transform.position; int index = (toDupe.transform.GetSiblingIndex() == 0) ? 0 : toDupe.transform.GetSiblingIndex() + 1; dupe.transform.SetSiblingIndex(index); Undo.RegisterFullObjectHierarchyUndo(dupe.transform.parent.gameObject, ""); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); Selection.activeGameObject = dupe; GetOwnerPath().RefreshChildIndexes(); #endif }
public void Select(List <ISelectableElement> elements) { Undo.IncrementCurrentGroup(); foreach (ISelectableElement e in elements) { if (!e.IsSelected()) { Select(e); } } Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); Repaint(); }
void AddTimeline() { Undo.IncrementCurrentGroup(); UnityEngine.Object[] objsToSave = new UnityEngine.Object[] { SequenceEditor, SequenceEditor.GetSequence() }; Undo.RecordObjects(objsToSave, string.Empty); GameObject timelineGO = new GameObject("TimeLine"); FTimeline timeline = timelineGO.AddComponent <Flux.FTimeline>(); //timeline.SetOwner(((GameObject)obj).transform); SequenceEditor.GetSequence().Add(timeline); Undo.RegisterCompleteObjectUndo(objsToSave, string.Empty); Undo.RegisterCreatedObjectUndo(timeline.gameObject, "create Timeline"); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); }
public static void CreateChild(GameObject target, Rect activatorPosition) { Validate(target); CreateMenu ( activatorPosition, created => { Undo.SetTransformParent(created.transform, target.transform, "Create Child"); created.transform.localPosition = Vector3.zero; created.transform.localRotation = Quaternion.identity; Selection.activeGameObject = created; Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } ); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (ToggleButtonStyleNormal == null) { ToggleButtonStyleNormal = "Button"; ToggleButtonStyleToggled = new GUIStyle(ToggleButtonStyleNormal); ToggleButtonStyleToggled.normal.background = ToggleButtonStyleToggled.active.background; } if (GUILayout.Button("Edit Area", (m_IsInEditMode) ? ToggleButtonStyleToggled : ToggleButtonStyleNormal)) { m_IsInEditMode = !m_IsInEditMode; if (m_IsInEditMode) { Undo.SetCurrentGroupName("Edit Area2D"); m_CurrEditModeUndoGroupId = Undo.GetCurrentGroup(); Undo.RecordObject(target, "Edit Area2D"); m_LastTool = Tools.current; Tools.current = Tool.None; } else { if (m_CurrEditModeUndoGroupId != -1) { Undo.CollapseUndoOperations(m_CurrEditModeUndoGroupId); m_CurrEditModeUndoGroupId = -1; } Tools.current = m_LastTool; } } //Vector2 newOffset = EditorGUILayout.Vector2Field("Offset", m_Target.Offset); //Vector2 newExtents = EditorGUILayout.Vector2Field("Size", m_Target.Extents * 2f) / 2.0f; m_Offset.vector2Value = EditorGUILayout.Vector2Field("Offset", m_Offset.vector2Value); m_Extents.vector2Value = EditorGUILayout.Vector2Field("Size", m_Extents.vector2Value * 2.0f) / 2.0f; m_Target.Offset = m_Offset.vector2Value; m_Target.Extents = m_Extents.vector2Value; m_Bounds.serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties(); }
private void OnAddElement(ReorderableList list) { var menu = new GenericMenu(); IEnumerable < MonoScript > monoScripts = Resources.FindObjectsOfTypeAll<MonoScript>().Where(s => s.GetClass() != null && !s.GetClass().IsAbstract && s.GetClass().IsSubclassOf(typeof(T))).OrderBy(s => s.name); for (int i = 0; i < monoScripts.Count(); i++) { MonoScript monoScript = monoScripts.ElementAt(i); menu.AddItem(new GUIContent(monoScript.name), false, () => { var newObject = ScriptableObject.CreateInstance(monoScript.GetClass()); if(null != newObject) { newObject.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(newObject, target); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); Undo.RegisterCreatedObjectUndo(newObject, "Add"); Undo.RecordObjects(new Object[] { target, newObject }, "Add"); newObject.name = newObject.GetType().Name; Undo.RecordObject(target, "Add"); serializedProperty.arraySize += 1; Undo.RecordObject(target, "Add"); serializedProperty.GetArrayElementAtIndex(serializedProperty.arraySize - 1).objectReferenceValue = newObject; Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); serializedProperty.serializedObject.ApplyModifiedProperties(); list.index = serializedProperty.arraySize - 1; OnChange(this); if(null != repaint) { repaint(); } } } ); } menu.ShowAsContext(); }
private Object ResourceHandler(ConveyorBelt.ResourceHandlerRequest request, Object context, Type type) { if (request == ConveyorBelt.ResourceHandlerRequest.Begin) { if (m_undoGroupId < 0) { Undo.SetCurrentGroupName("Belt"); m_undoGroupId = Undo.GetCurrentGroup(); if (m_undoGroupId < 0) { Debug.Log("Undo group id < 0: " + m_undoGroupId.ToString()); } } else { Debug.Log("Undo id is already set."); } return(null); } else if (request == ConveyorBelt.ResourceHandlerRequest.End) { if (m_undoGroupId >= 0) { Undo.CollapseUndoOperations(m_undoGroupId); } m_undoGroupId = -1; return(null); } else if (request == ConveyorBelt.ResourceHandlerRequest.AboutToChange) { Undo.RecordObject(context, $"{context.name} changes."); return(null); } else if (request == ConveyorBelt.ResourceHandlerRequest.AddComponent) { return(Undo.AddComponent(context as GameObject, type)); } else if (request == ConveyorBelt.ResourceHandlerRequest.DestroyObject) { Undo.DestroyObjectImmediate(context); return(null); } Debug.LogError($"Unknown Belt resource request: {request}"); return(null); }
static T Convert <T, TBetter>(T source, bool downgrade, params string[] skipFields) where T : MonoBehaviour where TBetter : T { var fields = CollectAllFieldValues(typeof(T), source, new HashSet <string>(skipFields)).ToArray(); var refs = new HashSet <KeyValuePair <SerializedObject, string> >(FindReferencesTo(source)); GameObject go = source.gameObject; int order = GetComponentOrder(source); Undo.SetCurrentGroupName(string.Format("Make Better {0}", DateTime.Now.ToFileTimeUtc())); Undo.DestroyObjectImmediate(source); T better = (downgrade) ? Undo.AddComponent <T>(go) : Undo.AddComponent <TBetter>(go); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); foreach (var kv in fields) { try { kv.Key.SetValue(better, kv.Value); } catch (Exception ex) { Debug.LogErrorFormat("Could not set value {0}: {1}", kv.Key.Name, ex.Message); } } foreach (var r in refs) { SetReference(r.Key, r.Value, better); } for (int i = 0; i < order; i++) { UnityEditorInternal.ComponentUtility.MoveComponentUp(better); } return(better); }
private static void RefreshAllSettings( StandardOutfit outfit, bool singleUndo = true, string undoLabel = "Refresh All Outfit Settings") { if (singleUndo) { Undo.IncrementCurrentGroup(); } Undo.RecordObjects(StandardOutfit.UnsafeGetUndoObjects(outfit).ToArray(), undoLabel); StandardOutfit.UnsafeRefreshAllSettings(outfit); if (singleUndo) { Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } }
public void DeleteItem(ReorderableList list) { var graphPath = AssetDatabase.GetAssetPath(_node); var graph = AssetDatabase.LoadAssetAtPath <ScriptableObject>(graphPath); var listItem = _list[list.index]; Undo.SetCurrentGroupName("Delete type"); Undo.RecordObject(graph, "Delete type"); Undo.RecordObject(_node, "Delete type"); _list.Remove(listItem); Undo.DestroyObjectImmediate(listItem); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); AssetDatabase.SaveAssets(); }
private static void LinkWaypoints() { var selectedObjects = Selection.gameObjects.ToList <GameObject>(); if (selectedObjects.Count == 2) { if (selectedObjects[0].layer != 15 || selectedObjects[1].layer != 15) { return; } var waypoint_02 = Selection.activeTransform.GetComponent <Waypoint>(); selectedObjects.Remove(waypoint_02.gameObject); var waypoint_01 = selectedObjects[0].GetComponent <Waypoint>(); Undo.IncrementCurrentGroup(); Undo.SetCurrentGroupName("Link Waypoints"); var undoGroupIndex = Undo.GetCurrentGroup(); Undo.RegisterCompleteObjectUndo(waypoint_01, ""); Undo.RegisterCompleteObjectUndo(waypoint_02, ""); Undo.CollapseUndoOperations(undoGroupIndex); waypoint_01.nextWaypoint = waypoint_02; //waypoint_02.prevWaypoint = waypoint_01; } else if (selectedObjects.Count == 3) { var waypoint_01 = selectedObjects[2].GetComponent <Waypoint>(); var waypoint_02 = selectedObjects[1].GetComponent <Waypoint>(); var waypoint_03 = selectedObjects[0].GetComponent <Waypoint>(); Undo.SetCurrentGroupName("Link Waypoints"); var undoGroupIndex = Undo.GetCurrentGroup(); Undo.RegisterCompleteObjectUndo(waypoint_01, ""); Undo.RegisterCompleteObjectUndo(waypoint_02, ""); Undo.RegisterCompleteObjectUndo(waypoint_03, ""); Undo.CollapseUndoOperations(undoGroupIndex); waypoint_03.waypointType = WaypointType.FORK; waypoint_03.nextWaypoint = waypoint_02; waypoint_03.nextWaypoint_02 = waypoint_01; //waypoint_01.prevWaypoint = waypoint_03; //waypoint_02.prevWaypoint = waypoint_03; } }
public void ReplaceNode(GameObject selectedNode, GameObject newNodePrefab) { Undo.SetCurrentGroupName("Replace Node"); int group = Undo.GetCurrentGroup(); //Delete the old prefab Undo.DestroyObjectImmediate(selectedNode.transform.GetChild(0).gameObject); //Instantiate new prefab GameObject newNodeInstance = PrefabUtility.InstantiatePrefab(newNodePrefab) as GameObject; newNodeInstance.transform.parent = selectedNode.transform; newNodeInstance.transform.localPosition = Vector3.zero; Undo.RegisterCreatedObjectUndo(newNodeInstance, "Create Node"); Undo.CollapseUndoOperations(group); }
private void CreateImpl() { EnsureAssetDirectoryExists(prefabDirectory); Undo.IncrementCurrentGroup(); Undo.SetCurrentGroupName("Combat Unit named " + unitName); var undoGroupIndex = Undo.GetCurrentGroup(); try { CreateSpawnerGo(); } finally { Undo.CollapseUndoOperations(undoGroupIndex); } }
ShapeState ValidateShape() { tool.RebuildShape(); tool.m_ProBuilderShape.pivotGlobalPosition = tool.m_BB_Origin; tool.m_ProBuilderShape.gameObject.hideFlags = HideFlags.None; DrawShapeTool.s_ActiveShapeIndex.value = Array.IndexOf(EditorShapeUtility.availableShapeTypes, tool.m_ProBuilderShape.shape.GetType()); DrawShapeTool.SaveShapeParams(tool.m_ProBuilderShape); // make sure that the whole shape creation process is a single undo group var group = Undo.GetCurrentGroup() - 1; Selection.activeObject = tool.m_ProBuilderShape.gameObject; Undo.CollapseUndoOperations(group); return(NextState()); }
/// <summary> /// Remove Environment of the collection at given index /// </summary> /// <param name="index">Index where to remove Environment</param> public void Remove(int index) { Undo.SetCurrentGroupName("Remove Environment"); int group = Undo.GetCurrentGroup(); Environment environment = environments[index]; Undo.RecordObject(this, "Remove Environment"); environments.RemoveAt(index); Undo.DestroyObjectImmediate(environment); Undo.CollapseUndoOperations(group); // Force save / refresh EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); }
public static InputMapping AddMap(ref InputManager _manager, string newName) { var parent = _manager.transform.Find("InputMappings"); if (!parent) { new GameObject("InputMappings").transform.parent = _manager.transform; return AddMap(ref _manager, newName); } InputMapping tempMapping = (InputMapping)Undo.AddComponent(parent.gameObject, typeof(InputMapping)); Undo.SetCurrentGroupName("Added Input Map" + newName); tempMapping.mapName = newName; Undo.RecordObject(_manager, "Added Input Map" + newName); _manager.RefreshInputMappings(); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); return tempMapping; }
public static void CreateSibling(GameObject target, Rect activatorPosition) { Validate(target); CreateMenu ( activatorPosition, created => { Undo.SetTransformParent(created.transform, target.transform.parent, "Create Sibling"); created.transform.position = target.transform.position; created.transform.rotation = target.transform.rotation; created.transform.SetSiblingIndex(target.transform.GetSiblingIndex()); Selection.activeGameObject = created; Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } ); }
public override void OnInspectorGUI() { ONSPPropagationMaterial material = target as ONSPPropagationMaterial; EditorGUI.BeginChangeCheck(); Rect r = EditorGUILayout.GetControlRect(); r.width -= rightMargin; ONSPPropagationMaterial.Preset newPreset = (ONSPPropagationMaterial.Preset)EditorGUI.EnumPopup(r, "Preset", material.preset); Event e = Event.current; EventType type = e.type; absorption.Draw(e); scattering.Draw(e); transmission.Draw(e); if (EditorGUI.EndChangeCheck()) { string groupName = Undo.GetCurrentGroupName(); Undo.RegisterCompleteObjectUndo(material, groupName); if (groupName == "Point Added") { Undo.CollapseUndoOperations(Undo.GetCurrentGroup() - 1); } if (material.preset != newPreset) { material.preset = newPreset; } else { material.preset = ONSPPropagationMaterial.Preset.Custom; } if (Application.isPlaying) { material.UploadMaterial(); } } }
static void OnSceneGUI(SceneView sceneView) { if (noSkin) { InitSkin(); } if (!snapping) { checkForInput(); } if (snapping == false && haveInput) { Handles.BeginGUI(); DrawGUI(); Handles.EndGUI(); } else if (snapping) { //if(currentSelection[currentIndex].position != currentPosition[currentIndex]) if (Time.realtimeSinceStartup >= lastTime + .05f) { currentIndex++; if (currentIndex >= currentSelection.Count) { snapping = false; //Debug.Log("Snapped " + currentIndex + " objects"); currentSelection.Clear(); Undo.CollapseUndoOperations(undoGroupID); } else { SnapTransform(currentSelection[currentIndex], currentDirection); } } sceneView.Repaint(); } if (haveInput) { sceneView.Repaint(); } }
public static void Split() { if (Selection.activeGameObject != null) { Undo.IncrementCurrentGroup(); string undo = "Split bone"; GameObject old = Selection.activeGameObject; Undo.RecordObject(old, undo); Bone b = old.GetComponent <Bone>(); GameObject n1 = new GameObject(old.name + "1"); Undo.RegisterCreatedObjectUndo(n1, undo); Bone b1 = n1.AddComponent <Bone>(); b1.index = b.index; b1.transform.parent = b.transform.parent; b1.snapToParent = b.snapToParent; b1.length = b.length / 2; b1.transform.localPosition = b.transform.localPosition; b1.transform.localRotation = b.transform.localRotation; GameObject n2 = new GameObject(old.name + "2"); Undo.RegisterCreatedObjectUndo(n2, undo); Bone b2 = n2.AddComponent <Bone>(); b2.index = b.GetMaxIndex(); b2.length = b.length / 2; n2.transform.parent = n1.transform; b2.transform.localRotation = Quaternion.Euler(0, 0, 0); n2.transform.position = b1.Head; var children = (from Transform child in b.transform select child).ToArray <Transform>(); b.transform.DetachChildren(); foreach (Transform child in children) { Undo.SetTransformParent(child, n2.transform, undo); child.parent = n2.transform; } Undo.DestroyObjectImmediate(old); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); Selection.activeGameObject = b2.gameObject; } }
public static void ReplaceNameTerm( [CommandParameter(Help = "The term to look for in the name")] string termToLookFor, [CommandParameter(Help = "The texts that will replace the " + "term, one by one (and then looped to the start if less terms than objects ")] string[] toReplaceWith, [CommandParameter(Help = "if true, will consider capital letters as normal letters")] bool ignoreCase = true) { int undoID = MonkeyEditorUtils.CreateUndoGroup("Replace in Names"); int i = 0; int j = 0; foreach (Object o in MonkeyEditorUtils.OrderedSelectedObjects) { Undo.RecordObject(o, "renaming"); if (i >= toReplaceWith.Length) { i -= toReplaceWith.Length; } if (EditorUtility.DisplayCancelableProgressBar("Renaming Selection...", "MonKey is renaming the objects, please wait!", (float)j / MonkeyEditorUtils.OrderedSelectedObjects.Count())) { break; } string finalReplacement = toReplaceWith[i]; if (AssetDatabase.Contains(o)) { finalReplacement = finalReplacement.GetSafeForFileName(); } o.RenameObjectAndAsset(o.name.Replace(termToLookFor, finalReplacement, ignoreCase)); i++; j++; } EditorUtility.ClearProgressBar(); Undo.CollapseUndoOperations(undoID); }
public void Dispose() { if (!_isDisposed) { _isDisposed = true; if (_object != null) { ChangeHelper.Finish(_object); } else if (_serializedObject != null) { ChangeHelper.Finish(_serializedObject); } Undo.CollapseUndoOperations(_group); } }
public void DeleteTransitionsInvolving(int sceneId) { Undo.SetCurrentGroupName("Delete Transitions"); int currentGroup = Undo.GetCurrentGroup(); for (int t = TransitionsProp.arraySize - 1; t >= 0; t--) { SerializedTransition currentTrans = GetTransitionAtIndex(t); if (currentTrans.DestSceneIdProp.intValue == sceneId || SceneIdProp.intValue == sceneId) { DeleteTransitionAtIndex(t); } } Undo.CollapseUndoOperations(currentGroup); }
public static void Create() { Undo.IncrementCurrentGroup(); GameObject o = new GameObject("Skeleton"); Undo.RegisterCreatedObjectUndo(o, "Create skeleton"); o.AddComponent <Skeleton> (); GameObject b = new GameObject("Bone"); Undo.RegisterCreatedObjectUndo(b, "Create Skeleton"); b.AddComponent <Bone> (); b.transform.parent = o.transform; Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); }
private void DeleteChoice(ChoiceData choice) { var choiceIndex = _data.choices.IndexOf(choice); var connection = _connections[choiceIndex]; var serializedObject = _serializedObjects[choiceIndex]; Undo.SetCurrentGroupName($"Delete {choice.name}"); Undo.RecordObject(_data, $"Delete {choice.name}"); connection.Links.ClearAllLinks(); _data.choices.Remove(choice); _node.RemoveConnection(connection); _connections.Remove(connection); _serializedObjects.Remove(serializedObject); Undo.DestroyObjectImmediate(choice); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); }
/// <summary> /// Callback from InspectorEditor when in OnDisable and target == null, /// meaning the target has been deleted. /// </summary> public static void OnEditorTargetsDeleted() { var undoGroupId = Undo.GetCurrentGroup(); // Deleted RigidBody component leaves dangling MassProperties // so we've to delete them explicitly. var mps = Object.FindObjectsOfType <AGXUnity.MassProperties>(); foreach (var mp in mps) { if (mp.RigidBody == null) { Undo.DestroyObjectImmediate(mp); } } Undo.CollapseUndoOperations(undoGroupId); }
public void OnPortAdded([NotNull] SerializedBehaviorTreeNode node) { Undo.SetCurrentGroupName("Behavior Tree changed"); int undoGroup = Undo.GetCurrentGroup(); Undo.RegisterCompleteObjectUndo(m_serializedBehaviorTree, "Changed Behavior Tree"); SerializedProperty serializedBehaviorData = GetPropertyData(node); SerializedProperty childrenIndices = serializedBehaviorData .FindPropertyRelative(ChildrenIndicesPropertyName); int last = childrenIndices.arraySize++; childrenIndices.GetArrayElementAtIndex(last).intValue = -1; m_serializedBehaviorTreeObject.ApplyModifiedProperties(); Undo.CollapseUndoOperations(undoGroup); }
public void Rotate() { int undoID = MonkeyEditorUtils.CreateUndoGroup("Rotate Around"); foreach (var gameObject in ObjectsToRotate) { if (gameObject == ReferenceObject) { continue; } Undo.RecordObject(gameObject.transform, "rotated"); gameObject.transform.RotateAround(ReferenceObject.transform.position, ReferenceObject.transform.AxisToVector(RotationAxis, true), Angle); } Undo.CollapseUndoOperations(undoID); }
protected void drawSwitchNowButtons() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Switch On Now", "Calls OnNow() on the selected switch(es)."))) { // Support undo history. Undo.IncrementCurrentGroup(); var curGroupIdx = Undo.GetCurrentGroup(); // Note: It is the responsibility of the IPropertySwitch implementation // to perform operations that correctly report their actions in OnNow() to the // Undo history! foreach (var target in targets) { target.OnNow(); } Undo.CollapseUndoOperations(curGroupIdx); Undo.SetCurrentGroupName("Switch Object(s) On Now"); } if (GUILayout.Button(new GUIContent("Switch Off Now", "Calls OffNow() on the selected switch(es)."))) { // Support undo history. Undo.IncrementCurrentGroup(); var curGroupIdx = Undo.GetCurrentGroup(); // Note: It is the responsibility of the IPropertySwitch implementation // to perform operations in OffNow() that correctly report their actions to the // Undo history! foreach (var target in targets) { target.OffNow(); } Undo.CollapseUndoOperations(curGroupIdx); Undo.SetCurrentGroupName("Switch Object(s) Off Now"); } EditorGUILayout.EndHorizontal(); }