Created
November 22, 2018 07:38
-
-
Save maxattack/5ada9e4c1ee51f9a65b75e030fe1fcbb to your computer and use it in GitHub Desktop.
ExecuteInEditMode Sample
This file contains 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
using UnityEngine; | |
[ExecuteInEditMode] | |
public class AbsoluteScale : MonoBehaviour { | |
public Vector3 scale = new Vector3(1f, 1f, 1f); | |
#if UNITY_EDITOR | |
void Update () { | |
if (Application.isPlaying) | |
return; | |
if (transform.parent) { | |
var parentScale = transform.parent.lossyScale; | |
var relativeScale = new Vector3( | |
scale.x / parentScale.x, | |
scale.y / parentScale.y, | |
scale.z / parentScale.z | |
); | |
transform.localScale = relativeScale; | |
} else { | |
transform.localScale = scale; | |
} | |
} | |
#endif | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment