Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private AxisFlag scaleAxisFlag;
- private float minScale, maxScale;
- private bool scaleSame = true;
- private void RandomScaleInspector()
- {
- EditorGUILayout.LabelField("Random Scale (local)", EditorStyles.boldLabel, layoutMaxWidth);
- scaleAxisFlag = (AxisFlag)EditorGUILayout.EnumMaskField("Scale Axis", scaleAxisFlag, layoutMaxWidth);
- scaleSame = EditorGUILayout.ToggleLeft("Scale same", scaleSame, layoutMaxWidth);
- minScale = EditorGUILayout.FloatField("Min:", minScale, layoutMaxWidth);
- maxScale = EditorGUILayout.FloatField("Max", maxScale, layoutMaxWidth);
- Transform[] selectedTransforms = Selection.transforms;
- string btnLabel = "Scale " + _transform.name;
- if (selectedTransforms.Length > 1)
- btnLabel = "Scale selection";
- if (Button(btnLabel))
- {
- RandomScale(scaleAxisFlag, selectedTransforms, scaleSame);
- }
- }
- private void RandomScale(AxisFlag axis, Transform[] selected , bool scaleSame)
- {
- for (int i = 0; i < selected.Length; i++)
- {
- Vector3 temp = selected[i].localScale;
- Vector3 random = Vector3.zero;
- if (scaleSame)
- {
- float rdm = Random.Range(minScale, maxScale);
- random.x = rdm;
- random.y = rdm;
- random.z = rdm;
- }
- else
- {
- random.x = Random.Range(minScale, maxScale);
- random.y = Random.Range(minScale, maxScale);
- random.z = Random.Range(minScale, maxScale);
- }
- if ((axis & AxisFlag.X) == AxisFlag.X)
- temp.x = random.x;
- if ((axis & AxisFlag.Y) == AxisFlag.Y)
- temp.y = random.y;
- if ((axis & AxisFlag.Z) == AxisFlag.Z)
- temp.z = random.z;
- Undo.RecordObject(_transform, "random scale " + selected[i].name);
- selected[i].localScale = temp;
- }
- }
- private Vector3 minPosition, maxPosition;
- private void RandomPositionInspector()
- {
- EditorGUILayout.LabelField("Random Position", EditorStyles.boldLabel, layoutMaxWidth);
- minPosition = EditorGUILayout.Vector3Field("Min", minPosition, layoutMaxWidth);
- maxPosition = EditorGUILayout.Vector3Field("Max", maxPosition, layoutMaxWidth);
- Transform[] selectedTransforms = Selection.transforms;
- string btnLabel = "Move " + _transform.name;
- if (selectedTransforms.Length > 1)
- btnLabel = "Move selection";
- if (Button(btnLabel))
- {
- RandomPosition(minPosition, maxPosition, selectedTransforms);
- }
- }
- private void RandomPosition(Vector3 min , Vector3 max, Transform[] t)
- {
- for (int i = 0; i < t.Length; i++)
- {
- Vector3 temp = t[i].position;
- if (!Mathf.Approximately(min.x, max.x))
- temp.x = Random.Range(min.x, max.x);
- if (!Mathf.Approximately(min.y, max.y))
- temp.y = Random.Range(min.y, max.y);
- if (!Mathf.Approximately(min.z, max.z))
- temp.z = Random.Range(min.z, max.z);
- Undo.RecordObject(t[i], "Random position " + t[i].name);
- t[i].position = temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement