public static void MeasureAllCollisionDistance( [CommandParameter(Help = "if true, considers the local axis instead" + " of the global one", DefaultValueMethod = "DefaultLocal", DefaultValueNameOverride = "Global")] AxisReference localAxisReference) { MonkeyEditorUtils. AddSceneCommand(new DistanceAxisShowingSceneCommand( Selection.gameObjects, Color.green.DarkerBrighter(-0.2f), Vector3.up, localAxisReference == AxisReference.LOCAL, 0)); MonkeyEditorUtils. AddSceneCommand(new DistanceAxisShowingSceneCommand( Selection.gameObjects, Color.green.DarkerBrighter(-0.2f), Vector3.down, localAxisReference == AxisReference.LOCAL, 0)); MonkeyEditorUtils. AddSceneCommand(new DistanceAxisShowingSceneCommand( Selection.gameObjects, Color.blue, Vector3.forward, localAxisReference == AxisReference.LOCAL, 0)); MonkeyEditorUtils. AddSceneCommand(new DistanceAxisShowingSceneCommand( Selection.gameObjects, Color.blue, Vector3.back, localAxisReference == AxisReference.LOCAL, 0)); MonkeyEditorUtils. AddSceneCommand(new DistanceAxisShowingSceneCommand( Selection.gameObjects, Color.red, Vector3.left, localAxisReference == AxisReference.LOCAL, 0)); MonkeyEditorUtils. AddSceneCommand(new DistanceAxisShowingSceneCommand( Selection.gameObjects, Color.red, Vector3.right, localAxisReference == AxisReference.LOCAL, 0)); }
private static void ToggleObjects(bool recursive = true, params GameObject[] objects) { bool[] previousActivation = objects.Convert(_ => _.activeInHierarchy).ToArray(); int i = 0; int undoID = MonkeyEditorUtils.CreateUndoGroup("Activate / Deactivate"); foreach (var gameObject in objects) { Undo.RecordObject(gameObject, "activation"); if (gameObject.activeInHierarchy && previousActivation[i]) { gameObject.SetActive(false); continue; } gameObject.SetActive(true); if (recursive && gameObject.transform.parent && !gameObject.transform.parent.gameObject.activeInHierarchy) { ToggleObjects(true, gameObject.transform.parent.gameObject); } i++; } Undo.CollapseUndoOperations(undoID); }
public static StaticCommandParameterAutoComplete FieldAutoComplete(int typeFieldID, Type fieldType) { var typeFound = (Type)MonkeyEditorUtils.GetParsedParameter(typeFieldID); var fields = typeFound. GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Default); var properties = typeFound.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Default & BindingFlags.SetProperty); var complete = new StaticCommandParameterAutoComplete(typeof(string), new Dictionary <string, object>()); foreach (var fieldInfo in fields) { if (fieldInfo.FieldType == fieldType) { complete.ObjectsPerName.Add(fieldInfo.Name, fieldInfo.Name); } } foreach (var fieldInfo in properties) { if (fieldInfo.PropertyType == fieldType) { complete.ObjectsPerName.Add(fieldInfo.Name, fieldInfo.Name); } } return(complete); }
public static void CopyTransform() { MonkeyEditorUtils.AddSceneCommand(new TransformCopyCommand(Selection.gameObjects) { CopyPosition = true, CopyRotation = true, CopyScale = true }); }
public static void ToggleEditorPhysicsSelected() { #if UNITY_2017_1_OR_NEWER if (currentEditorPhysics != null) { currentEditorPhysics.Stop(); return; } List <Rigidbody> bodies = new List <Rigidbody>(); List <GameObject> withoutBodies = new List <GameObject>(); foreach (var gameObject in Selection.gameObjects) { var rb = gameObject.GetComponentsInChildren <Rigidbody>(); if (rb.Length == 0) { withoutBodies.Add(gameObject); } bodies.AddRange(rb); } currentEditorPhysics = new EditorPhysicsSceneCommand(bodies.ToArray(), withoutBodies.ToArray()); MonkeyEditorUtils.AddSceneCommand(currentEditorPhysics); #endif }
public override void Stop() { base.Stop(); List <PositionRotation> newPosRot = new List <PositionRotation>(CachedObjectsToMove.Length); foreach (var gameObject in CachedObjectsToMove) { newPosRot.Add( new PositionRotation(gameObject.transform.position, gameObject.transform.rotation)); } for (int i = 0; i < previousPosRot.Count; i++) { CachedObjectsToMove[i].transform.position = previousPosRot[i].Position; CachedObjectsToMove[i].transform.rotation = previousPosRot[i].Rotation; } int undoIndex = MonkeyEditorUtils.CreateUndoGroup("Mouse Raycast"); for (int i = 0; i < newPosRot.Count; i++) { Undo.RecordObject(CachedObjectsToMove[i].transform, "Applying new position"); CachedObjectsToMove[i].transform.position = newPosRot[i].Position; CachedObjectsToMove[i].transform.rotation = newPosRot[i].Rotation; } Selection.objects = CachedObjectsToMove.Convert(_ => _ as Object).ToArray(); Undo.CollapseUndoOperations(undoIndex); }
protected override void OnSpaceDownAction() { base.OnSpaceDownAction(); toRandomize.RemoveAll(_ => !_); if (info == null && propInfo == null) { Debug.LogWarning("MonKey - Error when attempting to change the value of a field, the value wasn't changed"); return; } int undoID = MonkeyEditorUtils.CreateUndoGroup("MonKey - Set Float Value"); foreach (var o in toRandomize) { Undo.RecordObject(o, "modify Value"); info?.SetValue(o, Vector3.Lerp(minValue, maxValue, Random.value) * Multiplier); propInfo?.SetValue(o, Vector3.Lerp(minValue, maxValue, Random.value) * Multiplier, null); EditorUtility.SetDirty(o); } Undo.CollapseUndoOperations(undoID); }
public override void Update() { base.Update(); bool collision = false; Vector3 normal; selfAndChildren = selfAndChildren.Where(_ => _).ToArray(); var position = MonkeyEditorUtils.GetMouseRayCastedPosition(selfAndChildren, Offset, out collision, out normal, IgnoreInvisibleColliders); if (collision) { CachedObjectsToMove = CachedObjectsToMove.Where(_ => _).ToArray(); foreach (GameObject gameObject in CachedObjectsToMove) { gameObject.transform.AlignTransformToCollision(position, normal, true, AlignToNormal, ForwardAlign); gameObject.transform.rotation = Quaternion.AngleAxis(AngleOffset, normal) * gameObject.transform.rotation; } } }
public static void ReplaceNameUntilFirst( [CommandParameter(Help = "The first term until which the replacement will apply")] string term = " ", [CommandParameter(Help = "The text to replace the start of the name with")] string replacement = "") { int undoID = MonkeyEditorUtils.CreateUndoGroup("Replace before in Names"); int i = 0; foreach (Object o in MonkeyEditorUtils.OrderedSelectedObjects) { Undo.RecordObject(o, "renaming"); if (EditorUtility.DisplayCancelableProgressBar("Renaming Selection...", "MonKey is renaming the objects, please wait!", (float)i / MonkeyEditorUtils.OrderedSelectedObjects.Count())) { break; } string finalReplacement = o.name.ReplaceUntil(term, replacement); if (AssetDatabase.Contains(o)) { finalReplacement = finalReplacement.GetSafeForFileName(); } o.RenameObjectAndAsset(finalReplacement); i++; } EditorUtility.ClearProgressBar(); Undo.CollapseUndoOperations(undoID); }
public static void RenameAddNumberInOrder( [CommandParameter(Help = "The number to start the counting with")] int startingNumber = 0, [CommandParameter(Help = "the text to include before the number")] string beforeNumber = " ", [CommandParameter(Help = "the text to include after the number")] string afterNumber = "") { int undoID = MonkeyEditorUtils.CreateUndoGroup("Replace after in Names"); int i = startingNumber; int j = 0; foreach (Object o in new List <Object>(MonkeyEditorUtils.OrderedSelectedObjects)) { Undo.RecordObject(o, "renaming"); if (EditorUtility.DisplayCancelableProgressBar("Renaming Selection...", "MonKey is renaming the objects, please wait!", (float)j / MonkeyEditorUtils.OrderedSelectedObjects.Count())) { break; } o.RenameObjectAndAsset(o.name + beforeNumber + i + afterNumber); j++; i++; } EditorUtility.ClearProgressBar(); Undo.CollapseUndoOperations(undoID); }
public static void SortByName() { List <GameObject> freeObjects = new List <GameObject>(); Dictionary <Transform, List <GameObject> > selectedObjectsByParent = new Dictionary <Transform, List <GameObject> >(); int undoID = MonkeyEditorUtils.CreateUndoGroup("Order Siblings"); foreach (GameObject gameObject in Selection.gameObjects) { Transform parent = gameObject.transform.parent; if (parent == null) { freeObjects.Add(gameObject); } else if (selectedObjectsByParent.ContainsKey(parent)) { selectedObjectsByParent[parent].Add(gameObject); } else { selectedObjectsByParent.Add(parent, new List <GameObject>()); selectedObjectsByParent[parent].Add(gameObject); } } SortSiblings(freeObjects); foreach (List <GameObject> gameObjects in selectedObjectsByParent.Values) { SortSiblings(gameObjects); } Undo.CollapseUndoOperations(undoID); }
public static void RenameSelection( [CommandParameter(Help = "The Names to use (if less names than select objects, will loop)")] string[] newNames) { int i = 0; int j = 0; int undoID = MonkeyEditorUtils.CreateUndoGroup("Selection Rename"); foreach (var o in MonkeyEditorUtils.OrderedSelectedObjects) { if (i >= newNames.Length) { i = 0; } if (EditorUtility.DisplayCancelableProgressBar("Renaming Selection...", "MonKey is renaming the objects, please wait!", (float)j / MonkeyEditorUtils.OrderedSelectedObjects.Count())) { break; } Undo.RecordObject(o, "renaming"); o.RenameObjectAndAsset(newNames[i]); i++; j++; } EditorUtility.ClearProgressBar(); Undo.CollapseUndoOperations(undoID); }
private void OnGUIActiveMode() { HandleInput(); HandleCommandChoice(); if ((!IsDocked && focusedWindow != this && !MonKeyInternalSettings.Instance.PreventFocusOnPopup) || JustOpenedActiveMode || MonKeyInternalSettings.Instance.ForceFocusOnDocked) { Focus(); } InitDisplayWindow(); if (IsParametricMethodCompletion) { ParametricPanelDisplay.DisplayParametricPanel(this); } else { CommandSearchPanelDisplay.DisplayCommandPanel(this); } if (JustOpenedActiveMode) { JustOpenedActiveMode = false; } HandleCommandChoice(); if (MonkeyEditorUtils.IsKeyDown(KeyCode.Tab)) { TabFrames = 5; } }
public static void MovePivotToChildrenCenter() { int undoID = MonkeyEditorUtils.CreateUndoGroup("Move Pivot"); foreach (var go in Selection.gameObjects) { Transform[] children = go.GetComponentsInChildren <Transform>() .Where(_ => _ != go.transform).ToArray(); Vector3[] childrenPos = children.Convert(_ => _.position).ToArray(); Vector3 weightCenter = new Vector3(); foreach (Transform child in children) { weightCenter += child.position; } weightCenter /= children.Length; Undo.RecordObject(go.transform, "moving pivot"); go.transform.position = weightCenter; for (int i = 0; i < children.Length; i++) { Undo.RecordObject(children[i], "moving"); children[i].position = childrenPos[i]; } } Undo.CollapseUndoOperations(undoID); }
public static void SelectAssetHotKeyOverride() { //yes, you can also do it this way!! //however, we recommend calling the method directly, as names are subject to changes //use it preferably for commands with parameters, to call MonKey's interface MonkeyEditorUtils.CallCommand("Find Asset"); }
public static void ShowHandles( [CommandParameter("The Objects to show the handle on", DefaultValueMethod = "SelectionDefault", ForceAutoCompleteUsage = true)] GameObject[] objects) { MonkeyEditorUtils.AddSceneCommand(new TransformHandleShowingSceneCommand(objects)); }
public static void ExpandUITransform() { int undoID = MonkeyEditorUtils.CreateUndoGroup("expand all"); ExpandAnchors(); CornersToAnchors(); Undo.CollapseUndoOperations(undoID); }
public static void ShowDistances( [CommandParameter(Help = "The color of the debug on the scene view", DefaultValueMethod = "DefaultDebugColor", DefaultValueNameOverride = "Debug Green")] Color debugColor) { MonkeyEditorUtils. AddSceneCommand(new DistanceShowingSceneCommand(Selection.gameObjects, debugColor, 0)); }
public void OnEnable() { InitAliases(); AutoCompleteManager.InitializeManager(); MonkeyEditorUtils.EditorUpdatePlug(this); MonKeySelectionUtils.PluginImporter(); RetrieveAllCommands(); }
protected override void OnSpaceDownAction() { base.OnSpaceDownAction(); int undoID = MonkeyEditorUtils.CreateUndoGroup("Randomization"); int objectID = 0; toRandomize.RemoveAll(_ => !_); foreach (GameObject gameObject in toRandomize) { Undo.RecordObject(gameObject.transform, "Randomization trans"); if (randomPerAxis != null && randomPerAxis.Length > 0) { int i = 0; gameObject.transform.position = previousPositions[objectID]; Vector3 previousUp = LocalSpace? gameObject.transform.up:Vector3.up; Vector3 previousRight = LocalSpace ? gameObject.transform.right : Vector3.right; Vector3 previousForward = LocalSpace ? gameObject.transform.forward : Vector3.forward; foreach (Axis axis in randomAxes) { int j = i; if (i >= randomPerAxis.Length) { j = 0; } float positionJitter = Random.Range(randomPerAxis[j].x, randomPerAxis[j].y) * Multiplier; switch (axis) { case Axis.X: gameObject.transform.position = gameObject.transform.position + positionJitter * previousRight; break; case Axis.Y: gameObject.transform.position = gameObject.transform.position + positionJitter * previousUp; break; case Axis.Z: gameObject.transform.position = gameObject.transform.position + positionJitter * previousForward; break; } i++; } } objectID++; } Undo.CollapseUndoOperations(undoID); }
public static void MeasureCollisionDistance2D( [CommandParameter(Help = "The color of the debug on the scene view", DefaultValueMethod = "DefaultDebugColor", DefaultValueNameOverride = "Debug Green")] Color debugColor) { MonkeyEditorUtils. AddSceneCommand(new DistanceAxisShowingSceneCommand2D( Selection.gameObjects, debugColor, Vector3.down, false, 0)); }
public static void ExecuteInEditMode() { List <MonoBehaviour> behaviours = new List <MonoBehaviour>(); foreach (var go in Selection.gameObjects) { behaviours.AddRange(go.GetComponents <MonoBehaviour>()); } MonkeyEditorUtils.AddSceneCommand(new ExecuteInEditModeSceneCommand(behaviours.ToArray())); }
public override void InitializeAutoComplete() { if (PopulateOnInit) { GenerateAndSortAutoComplete(""); } if (showAssetPreview) { MonkeyEditorUtils.AddEditorDelegate(UpdatePreviewTextures, 0.25f); } }
public static void ResetRotations() { int undoID = MonkeyEditorUtils.CreateUndoGroup("Reset Transforms"); foreach (Transform transform in Selection.transforms) { Undo.RecordObject(transform, "reset"); transform.rotation = Quaternion.identity; } Undo.CollapseUndoOperations(undoID); }
public static void Rotation2DFlip(Axis axis = Axis.Y) { int undoID = MonkeyEditorUtils.CreateUndoGroup("rotation flip"); foreach (GameObject o in Selection.gameObjects) { Undo.RecordObject(o.transform, "rotation"); Vector3 axisVector = o.transform.AxisToVector(axis, true); o.transform.Rotate(axisVector, 180, Space.Self); } Undo.CollapseUndoOperations(undoID); }
public static void ToggleEditorPhysics2D() { #if UNITY_2017_1_OR_NEWER if (currentEditorPhysics2D != null) { currentEditorPhysics2D.Stop(); return; } currentEditorPhysics2D = new EditorPhysics2DSceneCommand(Object.FindObjectsOfType <Rigidbody2D>()); MonkeyEditorUtils.AddSceneCommand(currentEditorPhysics2D); #endif }
public static void TogglePausePhysics() { if (currentPhysicsCommand != null) { currentPhysicsCommand.Stop(); currentPhysicsCommand = null; return; } currentPhysicsCommand = new PhysicsPauseCommand(0); MonkeyEditorUtils.AddSceneCommand(currentPhysicsCommand); }
public static void SetPosition( [CommandParameter(Help = "The local position to set on the selected objects")] Vector3 position) { int id = MonkeyEditorUtils.CreateUndoGroup("MonKey : Local Position Set"); foreach (GameObject gameObject in Selection.gameObjects) { Undo.RecordObject(gameObject.transform, " tr"); gameObject.transform.localPosition = position; } Undo.CollapseUndoOperations(id); }
public static void MovePivotOnBoundingBox() { if (Selection.activeGameObject.transform.childCount == 0) { Debug.LogWarning("MonKey Warning:" + " You are trying to move a a game object as a pivot " + "but it is not a pivot since it doesn't have children objects: " + "this command will not be executed"); return; } MonkeyEditorUtils.AddSceneCommand(new MovePivotSceneCommand()); }
public static void SetFloatValue( [CommandParameter(Help = "The type of script on which to change a value", AutoCompleteMethodName = "TypeAuto", ForceAutoCompleteUsage = true, PreventDefaultValueUsage = true)] Type scriptType, [CommandParameter(Help = "The name of the field the change the value of" , AutoCompleteMethodName = "FloatFieldAuto", ForceAutoCompleteUsage = true, PreventDefaultValueUsage = true)] string fieldName, float value) { List <UnityEngine.Object> objectsToChange = new List <UnityEngine.Object>(); foreach (var o in Selection.objects) { if (o.GetType() == scriptType) { objectsToChange.Add(o); } else if (o is GameObject go) { objectsToChange.AddRange(go.GetComponentsInChildren(scriptType)); } } PropertyInfo propInfo = null; var info = scriptType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Default); if (info == null) { propInfo = scriptType.GetProperty(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Default); } if (info == null && propInfo == null) { Debug.LogWarning("MonKey - Error when attempting to change the value of a field, the value wasn't changed"); return; } int undoID = MonkeyEditorUtils.CreateUndoGroup("MonKey - Set Float Value"); foreach (var o in objectsToChange) { Undo.RecordObject(o, "modify Value"); info?.SetValue(o, value); propInfo?.SetValue(o, value, null); EditorUtility.SetDirty(o); } Undo.CollapseUndoOperations(undoID); }