10 public void TryRefresh()
12 DateTime lastWriteTime = File.GetLastWriteTime(this.path);
13 bool flag = this.date.DateTime.Year != 1 && this.date.DateTime.Equals(lastWriteTime);
14 if (this.dictReplace.Count > 0)
16 List<int> list =
new List<int>();
19 if (!File.Exists(textureReplace.file.FullName))
21 this.forceRefresh =
true;
22 list.Add(textureReplace.index);
25 foreach (
int index
in list)
27 this.RemoveDeletedReplace(index);
30 if (this.forceRefresh)
32 this.forceRefresh =
false;
35 if (!flag || !this.IsValid())
39 foreach (
TextureReplace textureReplace2
in this.dictReplace.Values)
41 textureReplace2.TryRefresh(!flag);
43 this.date.DateTime = lastWriteTime;
47 public void ForceRefresh()
49 this.forceRefresh =
true;
54 public static void RefreshAll()
56 if (!
EClass.core.IsGameStarted)
62 textureData.ForceRefresh();
67 public virtual bool IsValid()
69 TextureData.Type type = this.type;
72 return type != TextureData.Type.World ||
EClass.scene.tileset.AtlasTexture;
74 using (List<MeshPass>.Enumerator enumerator = this.listPass.GetEnumerator())
76 while (enumerator.MoveNext())
78 if (!enumerator.Current.mat.GetTexture(
this.texName))
88 public void Load(
bool dateMatched)
92 Texture2D texture2D = IO.LoadPNG(this.path, FilterMode.Point);
97 if (this.tex.width != texture2D.width ||
this.tex.height != texture2D.height)
99 Debug.Log(
string.Concat(
new string[]
103 texture2D.width.ToString(),
105 texture2D.height.ToString(),
110 this.tex.SetPixels32(texture2D.GetPixels32());
112 UnityEngine.Object.Destroy(texture2D);
113 Debug.Log(
"Reloaded Texture:" + this.path);
115 TextureData.Type type = this.type;
125 using (List<MeshPass>.Enumerator enumerator = this.listPass.GetEnumerator())
127 while (enumerator.MoveNext())
129 MeshPass meshPass = enumerator.Current;
130 meshPass.mat.SetTexture(this.texName, this.tex);
131 if (meshPass.haveShadowPass)
133 meshPass.shadowPass.mat.SetTexture(this.texName, this.tex);
139 EClass.scene.tileset.AtlasTexture = this.tex;
143 public void CreateReplace(
int index,
string path,
TextureReplace.Source source,
int sizeX,
int sizeY)
145 string str = this.id +
"_" + index.ToString() +
".png";
146 Texture2D texture2D =
new Texture2D(this.tileW * sizeX, this.tileH * sizeY);
147 int srcX = index % 100 * this.tileW;
148 int srcY = this.tex.height - index / 100 * this.tileH - texture2D.height;
149 Graphics.CopyTexture(this.tex, 0, 0, srcX, srcY, this.tileW * sizeX, this.tileH * sizeY, texture2D, 0, 0, 0, 0);
150 byte[] bytes = texture2D.EncodeToPNG();
153 File.WriteAllBytes(path + str, bytes);
154 EClass.core.textures.TryAddReplace(
new FileInfo(path + str), source,
true,
true);
159 UnityEngine.Object.Destroy(texture2D);
165 TextureReplace textureReplace = this.dictReplace.TryGetValue(r.index,
null);
166 if (textureReplace !=
null)
170 r.original = textureReplace;
174 textureReplace.DestoryTex();
179 this.listReplaceLocal.Add(r);
181 this.dictReplace[r.index] = r;
188 this.RemoveDeletedReplace(r.index);
192 public void RemoveDeletedReplace(
int index)
194 TextureReplace textureReplace = this.dictReplace.TryGetValue(index,
null);
195 if (textureReplace ==
null)
199 textureReplace.DestoryTex();
200 if (textureReplace.original !=
null && textureReplace.original.file.Exists)
202 this.dictReplace[index] = textureReplace.original;
205 this.dictReplace.Remove(index);
212 public TextureData.Type type;
218 public Texture2D tex;
221 public bool forceRefresh;
235 public string texName;
239 public List<MeshPass> listPass =
new List<MeshPass>();
243 public Dictionary<int, TextureReplace> dictReplace =
new Dictionary<int, TextureReplace>();
247 public List<TextureReplace> listReplaceLocal =
new List<TextureReplace>();
256 public DateTime DateTime
260 return new DateTime(this.ticks);
264 this.ticks = value.Ticks;