Elin Decompiled Documentation EA 23.356.1 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 (option == null)
59 {
60 option = list.loadOption;
61 }
62 if (resourcePath != null)
63 {
64 return list.cache.Get(resourcePath, ResourceLoadType.Resource, option);
65 }
66 return list.cache.Get(fileInfo.FullName, ResourceLoadType.Streaming, option);
67 }
68
69 public void ClearCache()
70 {
71 if (list == null)
72 {
73 if ((bool)cache)
74 {
75 Object.DestroyImmediate(cache);
76 }
77 }
78 else
79 {
80 list.cache.Clear();
81 }
82 }
83}
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:69
T cache
Definition: ModItem.cs:20
ModItem(FileInfo _fileInfo, string path=null, ModItemList< T > _list=null, string desiredID=null)
Definition: ModItem.cs:22