Elin Decompiled Documentation EA 23.347 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
 
int extraRows
 
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 202 of file TextureData.cs.

203 {
204 TextureReplace textureReplace = dictReplace.TryGetValue(r.index);
205 if (textureReplace != null)
206 {
207 if (r.source == TextureReplace.Source.Local && textureReplace.source != TextureReplace.Source.Local)
208 {
209 r.original = textureReplace;
210 }
211 else
212 {
213 textureReplace.DestoryTex();
214 }
215 }
216 if (r.source == TextureReplace.Source.Local)
217 {
218 listReplaceLocal.Add(r);
219 }
220 dictReplace[r.index] = r;
221 }
Dictionary< int, TextureReplace > dictReplace
Definition: TextureData.cs:60
List< TextureReplace > listReplaceLocal
Definition: TextureData.cs:63

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

Referenced by TileManager.Blit(), and TextureManager.TryAddReplace().

◆ CreateReplace()

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

Definition at line 183 of file TextureData.cs.

184 {
185 string text = id + "_" + index + ".png";
186 Texture2D texture2D = new Texture2D(tileW * sizeX, tileH * sizeY);
187 int srcX = index % 100 * tileW;
188 int srcY = tex.height - index / 100 * tileH - texture2D.height;
189 Graphics.CopyTexture(tex, 0, 0, srcX, srcY, tileW * sizeX, tileH * sizeY, texture2D, 0, 0, 0, 0);
190 byte[] bytes = texture2D.EncodeToPNG();
191 try
192 {
193 File.WriteAllBytes(path + text, bytes);
194 EClass.core.textures.TryAddReplace(new FileInfo(path + text), source, add: true, refresh: true);
195 }
196 catch
197 {
198 }
199 UnityEngine.Object.Destroy(texture2D);
200 }
TextureManager textures
Definition: Core.cs:45
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
Texture2D tex
Definition: TextureData.cs:39
string path
Definition: TextureData.cs:51
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 223 of file TextureData.cs.

224 {
225 r.file.Delete();
227 }
void RemoveDeletedReplace(int index)
Definition: TextureData.cs:229

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

Referenced by LayerTextureViewer.Update().

◆ ForceRefresh()

void TextureData.ForceRefresh ( )
inline

Definition at line 101 of file TextureData.cs.

102 {
103 forceRefresh = true;
104 TryRefresh();
105 }
bool forceRefresh
Definition: TextureData.cs:41
void TryRefresh()
Definition: TextureData.cs:65

References forceRefresh, and TryRefresh().

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

◆ IsValid()

virtual bool TextureData.IsValid ( )
inlinevirtual

Definition at line 119 of file TextureData.cs.

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

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

Referenced by TryRefresh().

◆ Load()

void TextureData.Load ( bool  dateMatched)
inline

Definition at line 139 of file TextureData.cs.

140 {
141 if (!dateMatched)
142 {
143 Texture2D texture2D = IO.LoadPNG(path);
144 if (!texture2D)
145 {
146 Debug.Log(path);
147 }
148 int num = extraRows * tileH;
149 if (tex.width != texture2D.width || tex.height != texture2D.height + num)
150 {
151 Debug.Log(id + "/" + texture2D.width + "/" + texture2D.height + "/" + path);
152 tex.Reinitialize(texture2D.width, texture2D.height + num, tex.format, tex.mipmapCount > 1);
153 }
154 if (num > 0)
155 {
156 tex.SetPixels32(0, 0, tex.width, num, new Color32[tex.width * num]);
157 }
158 tex.SetPixels32(0, num, texture2D.width, texture2D.height, texture2D.GetPixels32());
159 tex.Apply();
160 UnityEngine.Object.Destroy(texture2D);
161 Debug.Log("Reloaded Texture:" + path);
162 }
163 switch (type)
164 {
165 case Type.Pass:
166 {
167 foreach (MeshPass item in listPass)
168 {
169 item.mat.SetTexture(texName, tex);
170 if (item.haveShadowPass)
171 {
172 item.shadowPass.mat.SetTexture(texName, tex);
173 }
174 }
175 break;
176 }
177 case Type.World:
178 EClass.scene.tileset.AtlasTexture = tex;
179 break;
180 }
181 }
Definition: IO.cs:10
static Texture2D LoadPNG(string _path, FilterMode filter=FilterMode.Point)
Definition: IO.cs:473

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

Referenced by TryRefresh().

◆ RefreshAll()

static void TextureData.RefreshAll ( )
inlinestatic

Definition at line 107 of file TextureData.cs.

108 {
110 {
111 return;
112 }
113 foreach (TextureData value in EClass.core.textures.texMap.Values)
114 {
115 value.ForceRefresh();
116 }
117 }
bool IsGameStarted
Definition: Core.cs:87
void ForceRefresh()
Definition: TextureData.cs:101
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 229 of file TextureData.cs.

230 {
231 TextureReplace textureReplace = dictReplace.TryGetValue(index);
232 if (textureReplace != null)
233 {
234 textureReplace.DestoryTex();
235 if (textureReplace.original != null && textureReplace.original.file.Exists)
236 {
237 dictReplace[index] = textureReplace.original;
238 }
239 else
240 {
241 dictReplace.Remove(index);
242 }
243 }
244 }
TextureReplace original

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

Referenced by DeleteReplace(), and TryRefresh().

◆ TryRefresh()

void TextureData.TryRefresh ( )
inline

Definition at line 65 of file TextureData.cs.

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

◆ extraRows

int TextureData.extraRows

Definition at line 48 of file TextureData.cs.

Referenced by Load().

◆ 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>()

◆ listReplaceLocal

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

Definition at line 63 of file TextureData.cs.

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

◆ path

string TextureData.path

Definition at line 51 of file TextureData.cs.

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

◆ tex

◆ texName

string TextureData.texName

Definition at line 54 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: