2015-09-20 07:24:17 +08:00
|
|
|
|
2015-09-20 08:21:29 +08:00
|
|
|
/// Credit Danny Goodayle
|
2015-09-20 07:24:17 +08:00
|
|
|
/// Sourced from - http://www.justapixel.co.uk/radial-layouts-nice-and-simple-in-unity3ds-ui-system/
|
2020-07-09 03:38:28 +08:00
|
|
|
/// Updated by SimonDarksideJ - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
|
|
|
|
/// Child Layout fix by John Hattan - enables an options
|
2015-09-20 07:24:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
Radial Layout Group by Just a Pixel (Danny Goodayle) - http://www.justapixel.co.uk
|
|
|
|
Copyright (c) 2015
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
{
|
2015-09-20 08:21:29 +08:00
|
|
|
[AddComponentMenu("Layout/Extensions/Radial Layout")]
|
|
|
|
public class RadialLayout : LayoutGroup
|
2015-09-20 07:24:17 +08:00
|
|
|
{
|
2015-09-20 08:21:29 +08:00
|
|
|
public float fDistance;
|
|
|
|
[Range(0f, 360f)]
|
|
|
|
public float MinAngle, MaxAngle, StartAngle;
|
2018-04-20 01:01:41 +08:00
|
|
|
public bool OnlyLayoutVisible = false;
|
2015-09-20 08:21:29 +08:00
|
|
|
protected override void OnEnable() { base.OnEnable(); CalculateRadial(); }
|
|
|
|
public override void SetLayoutHorizontal()
|
2015-09-20 07:24:17 +08:00
|
|
|
{
|
2015-09-20 08:21:29 +08:00
|
|
|
}
|
|
|
|
public override void SetLayoutVertical()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
public override void CalculateLayoutInputVertical()
|
|
|
|
{
|
|
|
|
CalculateRadial();
|
|
|
|
}
|
|
|
|
public override void CalculateLayoutInputHorizontal()
|
|
|
|
{
|
|
|
|
CalculateRadial();
|
|
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
protected override void OnValidate()
|
|
|
|
{
|
|
|
|
base.OnValidate();
|
|
|
|
CalculateRadial();
|
|
|
|
}
|
|
|
|
#endif
|
2022-12-24 21:28:19 +08:00
|
|
|
|
|
|
|
protected override void OnDisable()
|
|
|
|
{
|
|
|
|
m_Tracker.Clear(); // key change - do not restore - false
|
|
|
|
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
|
|
|
|
}
|
|
|
|
|
2015-09-20 08:21:29 +08:00
|
|
|
void CalculateRadial()
|
|
|
|
{
|
|
|
|
m_Tracker.Clear();
|
|
|
|
if (transform.childCount == 0)
|
|
|
|
return;
|
2018-04-20 01:01:41 +08:00
|
|
|
|
|
|
|
int ChildrenToFormat = 0;
|
|
|
|
if (OnlyLayoutVisible)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
|
|
{
|
|
|
|
RectTransform child = (RectTransform)transform.GetChild(i);
|
|
|
|
if ((child != null) && child.gameObject.activeSelf)
|
|
|
|
++ChildrenToFormat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ChildrenToFormat = transform.childCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
float fOffsetAngle = (MaxAngle - MinAngle) / ChildrenToFormat;
|
2015-09-20 08:21:29 +08:00
|
|
|
|
|
|
|
float fAngle = StartAngle;
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
2015-09-20 07:24:17 +08:00
|
|
|
{
|
2015-09-20 08:21:29 +08:00
|
|
|
RectTransform child = (RectTransform)transform.GetChild(i);
|
2018-04-20 01:01:41 +08:00
|
|
|
if ((child != null) && (!OnlyLayoutVisible || child.gameObject.activeSelf))
|
2015-09-20 08:21:29 +08:00
|
|
|
{
|
2018-04-20 01:01:41 +08:00
|
|
|
//Adding the elements to the tracker stops the user from modifying their positions via the editor.
|
2015-09-20 08:21:29 +08:00
|
|
|
m_Tracker.Add(this, child,
|
|
|
|
DrivenTransformProperties.Anchors |
|
|
|
|
DrivenTransformProperties.AnchoredPosition |
|
|
|
|
DrivenTransformProperties.Pivot);
|
|
|
|
Vector3 vPos = new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0);
|
|
|
|
child.localPosition = vPos * fDistance;
|
|
|
|
//Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points.
|
|
|
|
child.anchorMin = child.anchorMax = child.pivot = new Vector2(0.5f, 0.5f);
|
|
|
|
fAngle += fOffsetAngle;
|
|
|
|
}
|
2015-09-20 07:24:17 +08:00
|
|
|
}
|
2015-09-20 08:21:29 +08:00
|
|
|
}
|
2015-09-20 07:24:17 +08:00
|
|
|
}
|
|
|
|
}
|