Skip to content

Instantly share code, notes, and snippets.

@LokoSoloGames
LokoSoloGames / PreserveAspectEnvelopImage.cs
Created May 31, 2023 03:09
Unity UI Image that stretch sprite to fit in RectTransform in Simple Image Type with preserve aspect toggled
using UnityEngine.Sprites;
namespace UnityEngine.UI {
public class PreserveAspectEnvelopImage : Image {
protected override void OnPopulateMesh(VertexHelper toFill) {
if (type == Type.Simple && !useSpriteMesh && preserveAspect) {
GenerateSimpleSprite(toFill);
} else {
base.OnPopulateMesh(toFill);
}
@LokoSoloGames
LokoSoloGames / InversedSlicedImage.cs
Last active May 31, 2023 03:06
Unity UI Image that expand sprite borders in Sliced Image Type
using UnityEngine.Sprites;
namespace UnityEngine.UI {
public class InversedSlicedImage : Image {
private static readonly Vector2[] s_VertCache = new Vector2[4];
private static readonly Vector2[] s_UVCache = new Vector2[4];
protected override void OnPopulateMesh(VertexHelper toFill) {
if (type == Type.Sliced && hasBorder) {
GenerateInversedSlicedSprite(toFill);
@LokoSoloGames
LokoSoloGames / SlicedFilledImage.cs
Last active June 12, 2024 07:40 — forked from yasirkula/SlicedFilledImage.cs
Combining UI Image's Sliced+Filled features together in Unity
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_2017_4 || UNITY_2018_2_OR_NEWER
using UnityEngine.U2D;
#endif
using Sprites = UnityEngine.Sprites;
#if UNITY_EDITOR