Skip to content

Commit

Permalink
add offset angle xyz.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Nov 13, 2016
1 parent dc702c6 commit 9f8a026
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
{
[SerializeField] float radius = 10f;
[SerializeField][Range(-180f, 180f)] float offsetAngle = 0f;
[SerializeField] Vector3 offsetAngle = Vector3.zero;

void OnDisable()
{
Expand All @@ -27,14 +27,19 @@ protected override void Layout()
radius = Mathf.Max(radius, (totalWidth + margin) / (2 * Mathf.PI));
var totalAngle = totalWidth / radius;

float angle = -totalAngle / 2 + offsetAngle * Mathf.Deg2Rad;
float angle = -totalAngle / 2;
var offsetRot = Quaternion.Euler(offsetAngle);
foreach (var info in monitors) {
var uddTex = info.uddTexture;
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);

angle += (width / radius) * 0.5f;
uddTex.transform.localPosition = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);
uddTex.transform.localRotation = Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.up) * info.originalRotation;
var pos = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);
pos += radius * Vector3.forward;
pos = offsetRot * pos;
pos -= radius * Vector3.forward;
uddTex.transform.localPosition = pos;
uddTex.transform.localRotation = offsetRot * Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.up) * info.originalRotation;
angle += (width * 0.5f + margin) / radius;

uddTex.bend = true;
Expand Down

0 comments on commit 9f8a026

Please sign in to comment.