Created
April 10, 2016 21:06
-
-
Save tsubaki/9cd50f4250d34a93b03b7be584605ab1 to your computer and use it in GitHub Desktop.
リングコマンド的なUIの羅列
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; | |
using System.Collections; | |
using UnityEngine.UI; | |
using UnityEngine.EventSystems; | |
public class SimpleCircleLayoutGroup : UIBehaviour, ILayoutGroup | |
{ | |
public float radius = 100; | |
public float offsetAngle; | |
protected override void OnValidate () | |
{ | |
base.OnValidate (); | |
Arrange (); | |
} | |
// 要素数が変わると自動的に呼ばれるコールバック | |
#region ILayoutController implementation | |
public void SetLayoutHorizontal (){} | |
public void SetLayoutVertical () | |
{ | |
Arrange (); | |
} | |
#endregion | |
void Arrange() | |
{ | |
float splitAngle = 360 / transform.childCount; | |
var rect = transform as RectTransform; | |
for (int elementId = 0; elementId < transform.childCount; elementId++) { | |
var child = transform.GetChild (elementId) as RectTransform; | |
float currentAngle = splitAngle * elementId + offsetAngle; | |
child.anchoredPosition = new Vector2 ( | |
Mathf.Cos (currentAngle * Mathf.Deg2Rad), | |
Mathf.Sin (currentAngle * Mathf.Deg2Rad)) * radius; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment