Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ModItem.cs
Go to the documentation of this file.
1using System.IO;
2using UnityEngine;
3
4public class ModItem<T> where T : Object
5{
7
8 public string category;
9
10 public string id;
11
12 public string resourcePath;
13
14 public string parent;
15
16 public string parentParent;
17
18 public FileInfo fileInfo;
19
20 public T cache;
21
22 public ModItem(FileInfo _fileInfo, string path = null, ModItemList<T> _list = null, string desiredID = null)
23 {
24 list = _list;
25 resourcePath = path;
26 Set(_fileInfo, path, desiredID);
27 }
28
29 public void Set(FileInfo _fileInfo, string path, string desiredID = null)
30 {
31 if (_fileInfo != null)
32 {
33 fileInfo = _fileInfo;
34 parent = ((fileInfo != null) ? fileInfo.Directory.Name : Path.GetDirectoryName(path));
35 parentParent = ((fileInfo != null) ? fileInfo.Directory.Parent.Name : Path.GetDirectoryName(path.Split('/')[0]));
36 id = desiredID ?? Path.GetFileNameWithoutExtension((fileInfo != null) ? fileInfo.Name : path);
37 if (list != null && list.catLength > 0)
38 {
39 category = id.Substring(0, list.catLength);
40 }
41 }
42 }
43
44 public T GetObject(object option = null)
45 {
46 if (fileInfo == null)
47 {
48 return null;
49 }
50 if (list == null)
51 {
52 if (cache == null)
53 {
54 cache = IO.LoadObject<T>(fileInfo, option);
55 }
56 return cache;
57 }
58 if (resourcePath != null)
59 {
60 return list.cache.Get(resourcePath, ResourceLoadType.Resource, option);
61 }
62 return list.cache.Get(fileInfo.FullName, ResourceLoadType.Streaming, option);
63 }
64
65 public void ClearCache()
66 {
67 if (list == null)
68 {
69 if ((bool)cache)
70 {
71 Object.DestroyImmediate(cache);
72 }
73 }
74 else
75 {
76 list.cache.Clear();
77 }
78 }
79}
ResourceLoadType
string parentParent
Definition: ModItem.cs:16
string id
Definition: ModItem.cs:10
FileInfo fileInfo
Definition: ModItem.cs:18
string parent
Definition: ModItem.cs:14
void Set(FileInfo _fileInfo, string path, string desiredID=null)
Definition: ModItem.cs:29
string category
Definition: ModItem.cs:8
T GetObject(object option=null)
Definition: ModItem.cs:44
ModItemList< T > list
Definition: ModItem.cs:6
string resourcePath
Definition: ModItem.cs:12
void ClearCache()
Definition: ModItem.cs:65
T cache
Definition: ModItem.cs:20
ModItem(FileInfo _fileInfo, string path=null, ModItemList< T > _list=null, string desiredID=null)
Definition: ModItem.cs:22