Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
SpriteVertexPositionChanger.cs
Go to the documentation of this file.
1using System;
2using Unity.Collections;
3using UnityEngine;
4using UnityEngine.Rendering;
5using UnityEngine.U2D;
6using UnityEngine.UI;
7
8namespace Applibot;
9
10public class SpriteVertexPositionChanger : MonoBehaviour
11{
12 public float scale = 1.5f;
13
14 [NonSerialized]
15 private Image _image;
16
17 private void Start()
18 {
19 _image = GetComponent<Image>();
20 if (_image == null)
21 {
22 Debug.LogError("Imageコンポーネントが必要です");
23 return;
24 }
25 _image.useSpriteMesh = true;
26 Sprite sprite = _image.sprite;
27 if (sprite.packed)
28 {
29 _image.rectTransform.sizeDelta *= scale;
30 }
31 ChangeMeshScale(sprite);
32 }
33
34 private void ChangeMeshScale(Sprite sprite)
35 {
36 NativeSlice<Vector3> vertexAttribute = sprite.GetVertexAttribute<Vector3>(VertexAttribute.Position);
37 NativeArray<Vector3> src = new NativeArray<Vector3>(vertexAttribute.Length, Allocator.Temp);
38 for (int i = 0; i < vertexAttribute.Length; i++)
39 {
40 src[i] = vertexAttribute[i] * scale;
41 }
42 sprite.SetVertexAttribute(VertexAttribute.Position, src);
43 src.Dispose();
44 }
45}