Created
October 1, 2017 01:57
-
-
Save chiepomme/bca79eb10a48c8266cfc77fe501a52eb to your computer and use it in GitHub Desktop.
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 Layout3D : MonoBehaviour | |
{ | |
public bool mirrorX; | |
public bool mirrorY; | |
public bool mirrorZ; | |
public bool enableXPos; | |
public AnimationCurve xPosCurve; | |
public bool enableYPos; | |
public AnimationCurve yPosCurve; | |
public bool enableZPos; | |
public AnimationCurve zPosCurve; | |
public bool enableXRot; | |
public AnimationCurve xRotCurve; | |
public bool enableYRot; | |
public AnimationCurve yRotCurve; | |
public bool enableZRot; | |
public AnimationCurve zRotCurve; | |
#if UNITY_EDITOR | |
void Update() | |
{ | |
var count = transform.childCount; | |
for (var i = 0; i < transform.childCount; i++) | |
{ | |
var child = transform.GetChild(i); | |
var pos = child.transform.localPosition; | |
var rot = child.transform.localEulerAngles; | |
if (enableXPos) pos.x = xPosCurve.Evaluate((float)i / count) * (mirrorX ? -1 : 1); | |
if (enableYPos) pos.y = yPosCurve.Evaluate((float)i / count) * (mirrorY ? -1 : 1); | |
if (enableZPos) pos.z = zPosCurve.Evaluate((float)i / count) * (mirrorZ ? -1 : 1); | |
if (enableXRot) rot.x = xRotCurve.Evaluate((float)i / count) * 360 * (mirrorY ? -1 : 1) * (mirrorZ ? -1 : 1); | |
if (enableYRot) rot.y = yRotCurve.Evaluate((float)i / count) * 360 * (mirrorX ? -1 : 1) * (mirrorZ ? -1 : 1); | |
if (enableZRot) rot.z = zRotCurve.Evaluate((float)i / count) * 360 * (mirrorX ? -1 : 1) * (mirrorY ? -1 : 1); | |
child.transform.localPosition = pos; | |
child.transform.localEulerAngles = rot; | |
} | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment