-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathWaitSetImage.cs
More file actions
89 lines (80 loc) · 2.75 KB
/
WaitSetImage.cs
File metadata and controls
89 lines (80 loc) · 2.75 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using GameFramework;
using UnityEditor;
#if ODIN_INSPECTOR
using Sirenix.OdinInspector;
using Sirenix.Serialization;
#endif
using UnityEngine;
using UnityEngine.UI;
namespace UGFExtensions.SpriteCollection
{
[Serializable]
public class WaitSetImage : ISetSpriteObject
{
#if ODIN_INSPECTOR
[ShowInInspector]
#endif
private Image m_Image;
public static WaitSetImage Create(Image obj, string collection, string spriteName)
{
WaitSetImage waitSetImage = ReferencePool.Acquire<WaitSetImage>();
waitSetImage.m_Image = obj;
waitSetImage.SpritePath = spriteName;
waitSetImage.CollectionPath = collection;
int index1 = waitSetImage.SpritePath.LastIndexOf("/", StringComparison.Ordinal);
int index2 = waitSetImage.SpritePath.LastIndexOf(".", StringComparison.Ordinal);
waitSetImage.SpriteName = index2 < index1
? waitSetImage.SpritePath.Substring(index1 + 1)
: waitSetImage.SpritePath.Substring(index1 + 1, index2 - index1 - 1);
return waitSetImage;
}
#if ODIN_INSPECTOR
[ShowInInspector]
#endif
public string SpritePath { get; private set; }
#if ODIN_INSPECTOR
[ShowInInspector]
#endif
public string CollectionPath { get; private set; }
#if ODIN_INSPECTOR
[ShowInInspector]
#endif
private string SpriteName { get; set; }
public void SetSprite(Sprite sprite)
{
if (m_Image != null)
{
m_Image.sprite = sprite;
}
}
public bool IsCanRelease()
{
return m_Image == null || m_Image.sprite == null || m_Image.sprite.name != SpriteName;
}
#if !ODIN_INSPECTOR && UNITY_EDITOR
public Rect DrawSetSpriteObject(Rect rect)
{
EditorGUI.ObjectField(rect, "Image", m_Image, typeof(Image), true);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.TextField(rect, "CollectionPath", CollectionPath);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.TextField(rect, "SpritePath", SpritePath);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.TextField(rect, "CollectionPath", CollectionPath);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.TextField(rect, "SpriteName", SpriteName);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.Toggle(rect, "IsCanRelease", IsCanRelease());
return rect;
}
#endif
public void Clear()
{
m_Image = null;
SpritePath = null;
CollectionPath = null;
SpriteName = null;
}
}
}