Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
TextureData Class Reference
Inheritance diagram for TextureData:
EScriptable

Classes

class  Date
 

Public Types

enum  Type { Pass , World , DestTex }
 

Public Member Functions

void TryRefresh ()
 
void ForceRefresh ()
 
virtual bool IsValid ()
 
void Load (bool dateMatched)
 
void CreateReplace (int index, string path, TextureReplace.Source source, int sizeX, int sizeY)
 
void AddReplace (TextureReplace r)
 
void DeleteReplace (TextureReplace r)
 
void RemoveDeletedReplace (int index)
 

Static Public Member Functions

static void RefreshAll ()
 
- Static Public Member Functions inherited from EScriptable
static int rnd (int a)
 

Public Attributes

string id
 
Type type
 
Date date
 
Texture2D tex
 
bool forceRefresh
 
int tileW
 
int tileH
 
string path
 
string texName
 
List< MeshPasslistPass = new List<MeshPass>()
 
Dictionary< int, TextureReplacedictReplace = new Dictionary<int, TextureReplace>()
 
List< TextureReplacelistReplaceLocal = new List<TextureReplace>()
 

Detailed Description

Definition at line 6 of file TextureData.cs.

Member Enumeration Documentation

◆ Type

Enumerator
Pass 
World 
DestTex 

Definition at line 26 of file TextureData.cs.

Member Function Documentation

◆ AddReplace()

void TextureData.AddReplace ( TextureReplace  r)
inline

Definition at line 193 of file TextureData.cs.

194 {
195 TextureReplace textureReplace = dictReplace.TryGetValue(r.index);
196 if (textureReplace != null)
197 {
198 if (r.source == TextureReplace.Source.Local && textureReplace.source != TextureReplace.Source.Local)
199 {
200 r.original = textureReplace;
201 }
202 else
203 {
204 textureReplace.DestoryTex();
205 }
206 }
207 if (r.source == TextureReplace.Source.Local)
208 {
209 listReplaceLocal.Add(r);
210 }
211 dictReplace[r.index] = r;
212 }
Dictionary< int, TextureReplace > dictReplace
Definition: TextureData.cs:57
List< TextureReplace > listReplaceLocal
Definition: TextureData.cs:60

References TextureReplace.DestoryTex(), dictReplace, TextureReplace.index, listReplaceLocal, and TextureReplace.source.

Referenced by TextureManager.TryAddReplace().

◆ CreateReplace()

void TextureData.CreateReplace ( int  index,
string  path,
TextureReplace::Source  source,
int  sizeX,
int  sizeY 
)
inline

Definition at line 174 of file TextureData.cs.

175 {
176 string text = id + "_" + index + ".png";
177 Texture2D texture2D = new Texture2D(tileW * sizeX, tileH * sizeY);
178 int srcX = index % 100 * tileW;
179 int srcY = tex.height - index / 100 * tileH - texture2D.height;
180 Graphics.CopyTexture(tex, 0, 0, srcX, srcY, tileW * sizeX, tileH * sizeY, texture2D, 0, 0, 0, 0);
181 byte[] bytes = texture2D.EncodeToPNG();
182 try
183 {
184 File.WriteAllBytes(path + text, bytes);
185 EClass.core.textures.TryAddReplace(new FileInfo(path + text), source, add: true, refresh: true);
186 }
187 catch
188 {
189 }
190 UnityEngine.Object.Destroy(texture2D);
191 }
TextureManager textures
Definition: Core.cs:45
Definition: EClass.cs:5
static Core core
Definition: EClass.cs:6
Texture2D tex
Definition: TextureData.cs:39
string path
Definition: TextureData.cs:48
bool TryAddReplace(FileInfo file, TextureReplace.Source source=TextureReplace.Source.Mod, bool add=true, bool refresh=false)

References EClass.core, path, tex, Core.textures, tileH, tileW, and TextureManager.TryAddReplace().

Referenced by LayerTextureViewer.Update().

◆ DeleteReplace()

void TextureData.DeleteReplace ( TextureReplace  r)
inline

Definition at line 214 of file TextureData.cs.

215 {
216 r.file.Delete();
218 }
void RemoveDeletedReplace(int index)
Definition: TextureData.cs:220

References TextureReplace.file, TextureReplace.index, and RemoveDeletedReplace().

Referenced by LayerTextureViewer.Update().

◆ ForceRefresh()

void TextureData.ForceRefresh ( )
inline

Definition at line 98 of file TextureData.cs.

99 {
100 forceRefresh = true;
101 TryRefresh();
102 }
bool forceRefresh
Definition: TextureData.cs:41
void TryRefresh()
Definition: TextureData.cs:62

References forceRefresh, and TryRefresh().

Referenced by RefreshAll(), and LayerTextureViewer.Update().

◆ IsValid()

virtual bool TextureData.IsValid ( )
inlinevirtual

Definition at line 116 of file TextureData.cs.

117 {
118 switch (type)
119 {
120 case Type.Pass:
121 foreach (MeshPass item in listPass)
122 {
123 if (!item.mat.GetTexture(texName))
124 {
125 return false;
126 }
127 }
128 return true;
129 case Type.World:
130 return EClass.scene.tileset.AtlasTexture;
131 default:
132 return true;
133 }
134 }
static Scene scene
Definition: EClass.cs:30
Tileset tileset
Definition: Scene.cs:101
string texName
Definition: TextureData.cs:51
List< MeshPass > listPass
Definition: TextureData.cs:54

References item, listPass, EClass.scene, texName, Scene.tileset, and type.

Referenced by TryRefresh().

◆ Load()

void TextureData.Load ( bool  dateMatched)
inline

Definition at line 136 of file TextureData.cs.

137 {
138 if (!dateMatched)
139 {
140 Texture2D texture2D = IO.LoadPNG(path);
141 if (!texture2D)
142 {
143 Debug.Log(path);
144 }
145 if (tex.width != texture2D.width || tex.height != texture2D.height)
146 {
147 Debug.Log(id + "/" + texture2D.width + "/" + texture2D.height + "/" + path);
148 }
149 tex.SetPixels32(texture2D.GetPixels32());
150 tex.Apply();
151 UnityEngine.Object.Destroy(texture2D);
152 Debug.Log("Reloaded Texture:" + path);
153 }
154 switch (type)
155 {
156 case Type.Pass:
157 {
158 foreach (MeshPass item in listPass)
159 {
160 item.mat.SetTexture(texName, tex);
161 if (item.haveShadowPass)
162 {
163 item.shadowPass.mat.SetTexture(texName, tex);
164 }
165 }
166 break;
167 }
168 case Type.World:
169 EClass.scene.tileset.AtlasTexture = tex;
170 break;
171 }
172 }
Definition: IO.cs:11
static Texture2D LoadPNG(string _path, FilterMode filter=FilterMode.Point)
Definition: IO.cs:421

References Debug, item, listPass, path, tex, texName, and type.

Referenced by TryRefresh().

◆ RefreshAll()

static void TextureData.RefreshAll ( )
inlinestatic

Definition at line 104 of file TextureData.cs.

105 {
107 {
108 return;
109 }
110 foreach (TextureData value in EClass.core.textures.texMap.Values)
111 {
112 value.ForceRefresh();
113 }
114 }
bool IsGameStarted
Definition: Core.cs:84
void ForceRefresh()
Definition: TextureData.cs:98
Dictionary< string, TextureData > texMap

References EClass.core, ForceRefresh(), Core.IsGameStarted, TextureManager.texMap, and Core.textures.

◆ RemoveDeletedReplace()

void TextureData.RemoveDeletedReplace ( int  index)
inline

Definition at line 220 of file TextureData.cs.

221 {
222 TextureReplace textureReplace = dictReplace.TryGetValue(index);
223 if (textureReplace != null)
224 {
225 textureReplace.DestoryTex();
226 if (textureReplace.original != null && textureReplace.original.file.Exists)
227 {
228 dictReplace[index] = textureReplace.original;
229 }
230 else
231 {
232 dictReplace.Remove(index);
233 }
234 }
235 }
TextureReplace original

References TextureReplace.DestoryTex(), dictReplace, TextureReplace.file, and TextureReplace.original.

Referenced by DeleteReplace(), and TryRefresh().

◆ TryRefresh()

void TextureData.TryRefresh ( )
inline

Definition at line 62 of file TextureData.cs.

63 {
64 DateTime lastWriteTime = File.GetLastWriteTime(path);
65 bool flag = date.DateTime.Year != 1 && date.DateTime.Equals(lastWriteTime);
66 if (dictReplace.Count > 0)
67 {
68 List<int> list = new List<int>();
69 foreach (TextureReplace value in dictReplace.Values)
70 {
71 if (!File.Exists(value.file.FullName))
72 {
73 forceRefresh = true;
74 list.Add(value.index);
75 }
76 }
77 foreach (int item in list)
78 {
80 }
81 }
82 if (forceRefresh)
83 {
84 forceRefresh = false;
85 flag = false;
86 }
87 if (!flag || !IsValid())
88 {
89 Load(flag);
90 }
91 foreach (TextureReplace value2 in dictReplace.Values)
92 {
93 value2.TryRefresh(!flag);
94 }
95 date.DateTime = lastWriteTime;
96 }
DateTime DateTime
Definition: TextureData.cs:14
virtual bool IsValid()
Definition: TextureData.cs:116
void Load(bool dateMatched)
Definition: TextureData.cs:136
void TryRefresh(bool force)

References date, TextureData.Date.DateTime, dictReplace, TextureReplace.file, forceRefresh, TextureReplace.index, IsValid(), item, Load(), path, RemoveDeletedReplace(), and TextureReplace.TryRefresh().

Referenced by ForceRefresh(), TextureManager.RefreshTextures(), and TextureManager.TryAddReplace().

Member Data Documentation

◆ date

Date TextureData.date

Definition at line 37 of file TextureData.cs.

Referenced by TryRefresh().

◆ dictReplace

◆ forceRefresh

bool TextureData.forceRefresh

Definition at line 41 of file TextureData.cs.

Referenced by ForceRefresh(), and TryRefresh().

◆ id

string TextureData.id

◆ listPass

List<MeshPass> TextureData.listPass = new List<MeshPass>()

Definition at line 54 of file TextureData.cs.

Referenced by IsValid(), Load(), and TextureManager.TryAddReplace().

◆ listReplaceLocal

List<TextureReplace> TextureData.listReplaceLocal = new List<TextureReplace>()

Definition at line 60 of file TextureData.cs.

Referenced by AddReplace(), and TextureManager.ApplyLocalReplace().

◆ path

string TextureData.path

Definition at line 48 of file TextureData.cs.

Referenced by CreateReplace(), Load(), and TryRefresh().

◆ tex

Texture2D TextureData.tex

◆ texName

string TextureData.texName

Definition at line 51 of file TextureData.cs.

Referenced by IsValid(), and Load().

◆ tileH

◆ tileW

◆ type

Type TextureData.type

Definition at line 35 of file TextureData.cs.

Referenced by IsValid(), and Load().


The documentation for this class was generated from the following file: