Skip to content

Instantly share code, notes, and snippets.

@Demkeys
Last active August 20, 2019 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Demkeys/48ec5a159f29fd7192a2e16baa6cf195 to your computer and use it in GitHub Desktop.
Save Demkeys/48ec5a159f29fd7192a2e16baa6cf195 to your computer and use it in GitHub Desktop.
Simple example script showing how to add more menu options to the Transform component in Unity.
using UnityEngine;
using UnityEditor;
public class ContexMenuExtensions : Editor
{
[MenuItem("CONTEXT/Transform/IncrementXScaleBy1")]
static void IncrementXScaleBy1(MenuCommand command)
{
Transform t = (Transform)command.context;
Vector3 tScale = t.localScale;
tScale.x += 1;
Undo.RecordObject((Object)t, "TransformXScale"); // Record changes to allow Undo.
t.localScale = tScale;
}
[MenuItem("CONTEXT/Transform/IncrementPositionBy1")]
static void IncrementYPositionBy1(MenuCommand command)
{
Transform t = (Transform)command.context;
Vector3 tPos = t.position;
tPos.y += 1;
Undo.RecordObject((Object)t, "TransformYPosition"); // Record changes to allow Undo.
t.position = tPos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment