Initial Unity project commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Modern UI Pack/Layout/Layout Group Fix")]
|
||||
public class LayoutGroupFix : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool fixOnEnable = true;
|
||||
[SerializeField] private bool fixWithDelay = true;
|
||||
float fixDelay = 0.025f;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
|
||||
if (Application.isPlaying == false) { return; }
|
||||
#endif
|
||||
if (fixWithDelay == false && fixOnEnable == true) { LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>()); }
|
||||
else if (fixWithDelay == true) { StartCoroutine(FixDelay()); }
|
||||
}
|
||||
|
||||
public void FixLayout()
|
||||
{
|
||||
if (fixWithDelay == false) { LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>()); }
|
||||
else { StartCoroutine(FixDelay()); }
|
||||
}
|
||||
|
||||
IEnumerator FixDelay()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(fixDelay);
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4f4ae5cbba538d449b15cffc97daa7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 1ee61fa8a667ceb48bedcd774003f519, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Layout Group/LayoutGroupFix.cs
|
||||
uploadId: 778406
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[AddComponentMenu("Modern UI Pack/Layout Group/Radial Layout Group")]
|
||||
public class RadialLayoutGroup : LayoutGroup
|
||||
{
|
||||
public enum Direction { Clockwise = 0, Counterclockwise = 1, Bidirectional = 2 }
|
||||
|
||||
public enum ConstraintMode { Interval = 0, Range = 1 }
|
||||
|
||||
[SerializeField] private Direction refLayoutDir;
|
||||
public Direction layoutDir { get { return refLayoutDir; } set { SetProperty(ref refLayoutDir, value); } }
|
||||
|
||||
[SerializeField] private float refRadiusStart = 200;
|
||||
public float radiusStart { get { return refRadiusStart; } set { SetProperty(ref refRadiusStart, value); } }
|
||||
|
||||
[SerializeField] private float refRadiusDelta;
|
||||
public float radiusDelta { get { return refRadiusDelta; } set { SetProperty(ref refRadiusDelta, value); } }
|
||||
|
||||
[SerializeField] private float refRadiusRange;
|
||||
public float radiusRange { get { return refRadiusRange; } set { SetProperty(ref refRadiusRange, value); } }
|
||||
|
||||
[SerializeField] private float refAngleDelta;
|
||||
public float angleDelta { get { return refAngleDelta; } set { SetProperty(ref refAngleDelta, value); } }
|
||||
|
||||
[SerializeField] private float refAngleStart;
|
||||
public float angleStart { get { return refAngleStart; } set { SetProperty(ref refAngleStart, value); } }
|
||||
|
||||
[SerializeField] private float refAngleCenter;
|
||||
public float angleCenter { get { return refAngleCenter; } set { SetProperty(ref refAngleCenter, value); } }
|
||||
|
||||
[SerializeField] private float refAngleRange = 200;
|
||||
public float angleRange { get { return refAngleRange; } set { SetProperty(ref refAngleRange, value); } }
|
||||
|
||||
[SerializeField] private bool refChildRotate = false;
|
||||
public bool childRotate { get { return refChildRotate; } set { SetProperty(ref refChildRotate, value); } }
|
||||
|
||||
public override void CalculateLayoutInputVertical() { }
|
||||
public override void CalculateLayoutInputHorizontal() { }
|
||||
public override void SetLayoutHorizontal() { CalculateChildrenPositions(); }
|
||||
public override void SetLayoutVertical() { CalculateChildrenPositions(); }
|
||||
|
||||
private List<RectTransform> childList = new List<RectTransform>();
|
||||
private List<ILayoutIgnorer> ignoreList = new List<ILayoutIgnorer>();
|
||||
|
||||
private void CalculateChildrenPositions()
|
||||
{
|
||||
this.m_Tracker.Clear();
|
||||
childList.Clear();
|
||||
|
||||
for (int i = 0; i < this.transform.childCount; ++i)
|
||||
{
|
||||
RectTransform rect = this.transform.GetChild(i) as RectTransform;
|
||||
|
||||
if (!rect.gameObject.activeSelf)
|
||||
continue;
|
||||
|
||||
ignoreList.Clear();
|
||||
rect.GetComponents(ignoreList);
|
||||
|
||||
if (ignoreList.Count == 0)
|
||||
{
|
||||
childList.Add(rect);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < ignoreList.Count; j++)
|
||||
{
|
||||
if (!ignoreList[j].ignoreLayout)
|
||||
{
|
||||
childList.Add(rect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ignoreList.Clear();
|
||||
}
|
||||
|
||||
EnsureParameters(childList.Count);
|
||||
|
||||
for (int i = 0; i < childList.Count; ++i)
|
||||
{
|
||||
var child = childList[i];
|
||||
float delta = i * angleDelta;
|
||||
float angle = layoutDir == Direction.Clockwise ? angleStart - delta : angleStart + delta;
|
||||
ProcessOneChild(child, angle, radiusStart + (i * radiusDelta));
|
||||
}
|
||||
|
||||
childList.Clear();
|
||||
}
|
||||
|
||||
private void EnsureParameters(int childCount)
|
||||
{
|
||||
EnsureAngleParameters(childCount);
|
||||
EnsureRadiusParameters(childCount);
|
||||
}
|
||||
|
||||
private void EnsureAngleParameters(int childCount)
|
||||
{
|
||||
int intervalCount = childCount - 1;
|
||||
|
||||
switch (layoutDir)
|
||||
{
|
||||
case Direction.Clockwise:
|
||||
if (intervalCount > 0) { this.angleDelta = this.angleRange / intervalCount; }
|
||||
else { this.angleDelta = 0; }
|
||||
break;
|
||||
|
||||
case Direction.Counterclockwise:
|
||||
if (intervalCount > 0) { this.angleDelta = this.angleRange / intervalCount; }
|
||||
else { this.angleDelta = 0; }
|
||||
break;
|
||||
|
||||
case Direction.Bidirectional:
|
||||
if (intervalCount > 0) { this.angleDelta = this.angleRange / intervalCount; }
|
||||
else { this.angleDelta = 0; }
|
||||
this.angleStart = this.angleCenter - angleRange * 0.5f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void EnsureRadiusParameters(int childCount)
|
||||
{
|
||||
int intervalCount = childCount - 1;
|
||||
|
||||
switch (layoutDir)
|
||||
{
|
||||
case Direction.Clockwise:
|
||||
if (intervalCount > 0) { this.radiusDelta = radiusRange / intervalCount; }
|
||||
else { this.radiusDelta = 0; }
|
||||
break;
|
||||
|
||||
case Direction.Counterclockwise:
|
||||
|
||||
case Direction.Bidirectional:
|
||||
if (intervalCount > 0) { this.radiusDelta = radiusRange / intervalCount; }
|
||||
else { this.radiusDelta = 0; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Vector2 center = new Vector2(0.5f, 0.5f);
|
||||
|
||||
private void ProcessOneChild(RectTransform child, float angle, float radius)
|
||||
{
|
||||
Vector3 pos = new Vector3(
|
||||
Mathf.Cos(angle * Mathf.Deg2Rad),
|
||||
Mathf.Sin(angle * Mathf.Deg2Rad),
|
||||
0.0f);
|
||||
child.localPosition = pos * radius;
|
||||
|
||||
DrivenTransformProperties drivenProperties =
|
||||
DrivenTransformProperties.Anchors | DrivenTransformProperties.AnchoredPosition | DrivenTransformProperties.Rotation | DrivenTransformProperties.Pivot;
|
||||
m_Tracker.Add(this, child, drivenProperties);
|
||||
|
||||
child.anchorMin = center;
|
||||
child.anchorMax = center;
|
||||
child.pivot = center;
|
||||
|
||||
if (this.childRotate) { child.localEulerAngles = new Vector3(0, 0, angle); }
|
||||
else { child.localEulerAngles = Vector3.zero; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 675308088538b8340a8c91f8ac5d38e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a6728f3c9bd53624fa556ca3f560cc9b, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Layout Group/RadialLayoutGroup.cs
|
||||
uploadId: 778406
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[CustomEditor(typeof(RadialLayoutGroup))]
|
||||
public class RadialLayoutGroupEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private RadialLayoutGroup rlgTarget;
|
||||
private int currentTab;
|
||||
|
||||
private SerializedProperty layoutDir;
|
||||
private SerializedProperty radiusStart;
|
||||
private SerializedProperty radiusRange;
|
||||
private SerializedProperty angleStart;
|
||||
private SerializedProperty angleCenter;
|
||||
private SerializedProperty angleRange;
|
||||
private SerializedProperty childRotate;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (this.target == null)
|
||||
return;
|
||||
|
||||
this.rlgTarget = this.target as RadialLayoutGroup;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
|
||||
|
||||
var serObj = this.serializedObject;
|
||||
this.layoutDir = serObj.FindProperty("refLayoutDir");
|
||||
this.radiusStart = serObj.FindProperty("refRadiusStart");
|
||||
this.radiusRange = serObj.FindProperty("refRadiusRange");
|
||||
this.angleStart = serObj.FindProperty("refAngleStart");
|
||||
this.angleCenter = serObj.FindProperty("refAngleCenter");
|
||||
this.angleRange = serObj.FindProperty("refAngleRange");
|
||||
this.childRotate = serObj.FindProperty("refChildRotate");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
MUIPEditorHandler.DrawComponentHeader(customSkin, "RLG Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[1];
|
||||
toolbarTabs[0] = new GUIContent("Settings");
|
||||
|
||||
currentTab = MUIPEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 0;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
serializedObject.Update();
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
MUIPEditorHandler.DrawPropertyPlain(layoutDir, customSkin, "Layout Direction");
|
||||
EditorGUI.indentLevel = 1;
|
||||
|
||||
if (rlgTarget.layoutDir != RadialLayoutGroup.Direction.Bidirectional)
|
||||
EditorGUILayout.PropertyField(angleStart, new GUIContent("Angle Start"));
|
||||
else
|
||||
EditorGUILayout.PropertyField(angleCenter, new GUIContent("Angle Center"));
|
||||
|
||||
EditorGUILayout.PropertyField(angleRange, new GUIContent("Angle Range"));
|
||||
EditorGUILayout.PropertyField(radiusStart, new GUIContent("Radius Start"));
|
||||
EditorGUILayout.PropertyField(radiusRange, new GUIContent("Radius Range"));
|
||||
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.EndVertical();
|
||||
|
||||
childRotate.boolValue = MUIPEditorHandler.DrawToggle(childRotate.boolValue, customSkin, "Rotate Child");
|
||||
|
||||
if (Application.isPlaying == false) { this.Repaint(); }
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 079ef68e9c033fd47ad1ce2e4a5550f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Layout Group/RadialLayoutGroupEditor.cs
|
||||
uploadId: 778406
|
||||
Reference in New Issue
Block a user