Created
April 21, 2020 14:19
-
-
Save openroomxyz/8c4eca5416162d86619544c207d80090 to your computer and use it in GitHub Desktop.
Unity : Can i see an example of [ExecuteInEditMode] and [SelectionBase] ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ExecuteInEditMode] | |
[SelectionBase] | |
public class CubeEditor : MonoBehaviour | |
{ | |
[SerializeField][Range(1f, 20f)] float gridSize = 10f; | |
TextMesh textMesh; | |
private void Start() | |
{ | |
textMesh = GetComponentInChildren<TextMesh>(); | |
textMesh.text = "BIP3"; | |
} | |
void Update() | |
{ | |
//Debug.Log("Editor causes this update"); | |
Vector3 snapPos; | |
snapPos.x = Mathf.RoundToInt(transform.position.x / gridSize) * gridSize; | |
snapPos.z = Mathf.RoundToInt(transform.position.z / gridSize) * gridSize; | |
transform.position = new Vector3(snapPos.x, 0f, snapPos.z); | |
string labelText = snapPos.x / gridSize + "," + snapPos.z / gridSize; | |
textMesh.text = labelText; | |
gameObject.name = labelText; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment