2026-05-07 10:14:44 +02:00

41 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Wing.Utils
{
public static class UnityExt
{
public static Mesh GetMesh(this GameObject go)
{
var filter = go.GetComponent<MeshFilter>();
if (filter == null)
{
return null;
}
return filter.mesh;
}
public static void SetRectTransformSize(this RectTransform trans, Vector2 newSize)
{
Vector2 oldSize = trans.rect.size;
Vector2 deltaSize = newSize - oldSize;
trans.offsetMin = trans.offsetMin - new Vector2(deltaSize.x * trans.pivot.x, deltaSize.y * trans.pivot.y);
trans.offsetMax = trans.offsetMax + new Vector2(deltaSize.x * (1f - trans.pivot.x), deltaSize.y * (1f - trans.pivot.y));
}
public static void SetLayerWithChildren(this GameObject go, string layer)
{
var lyr = LayerMask.NameToLayer(layer);
go.layer = lyr;
var children = go.transform.GetComponentsInChildren<Transform>();
foreach(var c in children)
{
c.gameObject.layer = lyr;
}
}
}
}