mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 01:40:06 +00:00
XCharts 2.0
This commit is contained in:
76
Assets/XChartsDemo/Runtime/UIUtil.cs
Normal file
76
Assets/XChartsDemo/Runtime/UIUtil.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XChartsDemo
|
||||
{
|
||||
public static class UIUtil
|
||||
{
|
||||
|
||||
public static RectTransform GetRectTransform(Transform transform, string path)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
transform = transform.Find(path);
|
||||
}
|
||||
if (transform != null)
|
||||
{
|
||||
return transform.gameObject.GetComponent<RectTransform>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void SetRectTransformWidth(Transform transform, float width, string path = null)
|
||||
{
|
||||
var rect = GetRectTransform(transform, path);
|
||||
if (rect != null)
|
||||
{
|
||||
rect.sizeDelta = new Vector2(width, rect.sizeDelta.y);
|
||||
}
|
||||
}
|
||||
public static void SetRectTransformHeight(Transform transform, float height, string path = null)
|
||||
{
|
||||
var rect = GetRectTransform(transform, path);
|
||||
if (rect != null)
|
||||
{
|
||||
rect.sizeDelta = new Vector2(rect.sizeDelta.x, height);
|
||||
}
|
||||
}
|
||||
public static void SetRectTransformLeft(Transform transform, float width, string path = null)
|
||||
{
|
||||
var rect = GetRectTransform(transform, path);
|
||||
if (rect != null)
|
||||
{
|
||||
rect.anchoredPosition = new Vector2(width, rect.anchoredPosition.y);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetGridLayoutGroup(Transform transform, Vector2 cellSize, Vector2 spacing, string path = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
transform = transform.Find(path);
|
||||
}
|
||||
if (transform != null)
|
||||
{
|
||||
var com = transform.gameObject.GetComponent<GridLayoutGroup>();
|
||||
if (com != null)
|
||||
{
|
||||
com.cellSize = cellSize;
|
||||
com.spacing = spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("SetGridLayoutGroupSize ERROR:can't find GridLayoutGroup: " + (transform.name + "/" + path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user