-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathSetRawImage.cs
74 lines (64 loc) · 1.93 KB
/
SetRawImage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using GameFramework;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if ODIN_INSPECTOR
using Sirenix.OdinInspector;
#endif
using UnityEngine;
using UnityEngine.UI;
namespace UGFExtensions.Texture
{
[Serializable]
public class SetRawImage : ISetTexture2dObject
{
#if ODIN_INSPECTOR
[ShowInInspector]
#endif
private RawImage m_RawImage;
#if ODIN_INSPECTOR
[ShowInInspector]
#endif
private Texture2D Texture2D { get; set; }
#if ODIN_INSPECTOR
[ShowInInspector]
#endif
public string Texture2dFilePath { get; private set; }
public void SetTexture(Texture2D texture)
{
m_RawImage.texture = texture;
Texture2D = texture;
}
public bool IsCanRelease()
{
return m_RawImage == null || m_RawImage.texture == null || m_RawImage.texture != Texture2D;
}
public static SetRawImage Create(RawImage rawImage, string filePath)
{
SetRawImage item = ReferencePool.Acquire<SetRawImage>();
item.m_RawImage = rawImage;
item.Texture2dFilePath = filePath;
return item;
}
public void Clear()
{
m_RawImage = null;
Texture2D = null;
Texture2dFilePath = null;
}
#if !ODIN_INSPECTOR && UNITY_EDITOR
public Rect DrawSetTextureObject(Rect rect)
{
EditorGUI.ObjectField(rect, "RawImage", m_RawImage, typeof(RawImage), true);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.TextField(rect, "Texture2dFilePath", Texture2dFilePath);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.ObjectField(rect, "Texture", Texture2D, typeof(Texture2D), false);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.Toggle(rect, "IsCanRelease", IsCanRelease());
return rect;
}
#endif
}
}