|
1 | 1 | using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using System.Text; |
5 | | -using System.Threading.Tasks; |
| 2 | +using System.IO; |
| 3 | +using UnityEngine; |
6 | 4 |
|
7 | 5 | namespace ModLoader |
8 | 6 | { |
9 | 7 | /// <summary> |
10 | 8 | /// This interface is a mod entry point. so if you want to create mod, you need implement this interface |
11 | 9 | /// in the main class, but only in the main class to prevent errors. |
12 | 10 | /// </summary> |
13 | | - public interface SFSMod |
| 11 | + public abstract class SFSMod |
14 | 12 | { |
15 | 13 |
|
| 14 | + private string _name; |
| 15 | + private string _author; |
| 16 | + private string _modLoderVersion; |
| 17 | + private string _version; |
| 18 | + private string _description; |
| 19 | + //private Type[] _dependencies; |
| 20 | + private AssetBundle _assets; |
| 21 | + private string _assetsFilename; |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Get mod name |
| 25 | + /// </summary> |
| 26 | + public string Name |
| 27 | + { |
| 28 | + get { return this._name; } |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Get who create this mod |
| 33 | + /// </summary> |
| 34 | + public string Author |
| 35 | + { |
| 36 | + get { return this._author; } |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Get what modloader version need |
| 41 | + /// </summary> |
| 42 | + /// <value> |
| 43 | + /// v1.0.x |
| 44 | + /// </value> |
| 45 | + public string ModLoderVersion |
| 46 | + { |
| 47 | + get { return this._modLoderVersion; } |
| 48 | + } |
| 49 | + |
| 50 | + public string Version |
| 51 | + { |
| 52 | + get { return this._version; } |
| 53 | + } |
| 54 | + |
16 | 55 | /// <summary> |
17 | | - /// The modder can specify mod name in this function. |
| 56 | + /// get a descripton about what do this mod |
18 | 57 | /// </summary> |
19 | | - string getModName(); |
| 58 | + public string Description |
| 59 | + { |
| 60 | + get { return this._description; } |
| 61 | + } |
20 | 62 |
|
21 | 63 | /// <summary> |
22 | | - /// get the creator mod. |
| 64 | + /// get the list of mods need it to work. |
23 | 65 | /// </summary> |
24 | | - string getModAuthor(); |
| 66 | + //public Type[] Dependencies |
| 67 | + //{ |
| 68 | + // get { return this._dependencies; } |
| 69 | + //} |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// get the assets used for this mod. |
| 73 | + /// </summary> |
| 74 | + public AssetBundle Assets |
| 75 | + { |
| 76 | + get { return this._assets; } |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + protected SFSMod(string name, string author, string modLoderVersion, string version, string description = "", string assetsFilename = null /*,Type[] dependencies = null*/ ) |
| 81 | + { |
| 82 | + _name = name; |
| 83 | + _author = author; |
| 84 | + _modLoderVersion = modLoderVersion; |
| 85 | + _version = version; |
| 86 | + _description = description; |
| 87 | + //_dependencies = dependencies; |
| 88 | + _assetsFilename = assetsFilename; |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// This method load assets from mod folder |
| 93 | + /// </summary> |
| 94 | + public void loadAssets() |
| 95 | + { |
| 96 | + if(this._assetsFilename == null || this._assetsFilename == "") |
| 97 | + { |
| 98 | + return; |
| 99 | + } |
| 100 | + |
| 101 | + string assetFilePath = Path.Combine(FileLocations.BaseFolder, "MODS", this._name, this._assetsFilename); |
| 102 | + AssetBundle assets = AssetBundle.LoadFromFile(assetFilePath); |
| 103 | + if (assets == null) |
| 104 | + { |
| 105 | + throw new Exception("Assets file not found"); |
| 106 | + } |
| 107 | + this._assets = assets; |
| 108 | + |
| 109 | + Debug.Log(this._name+" assets loaded!"); |
| 110 | + } |
| 111 | + |
25 | 112 |
|
26 | 113 | /// <summary> |
27 | | - /// This is very important,because mod loader use this method to execute your mod. |
| 114 | + /// This method is called for modloader to start your mod |
28 | 115 | /// </summary> |
29 | | - void load(); |
| 116 | + public abstract void load(); |
30 | 117 |
|
31 | 118 | /// <summary> |
32 | | - /// For now this method do nothing, so you dont neet write nothing here. |
| 119 | + /// This method is called for modloader to remove your mod. |
33 | 120 | /// </summary> |
34 | | - void unload(); |
| 121 | + public abstract void unload(); |
35 | 122 |
|
36 | 123 | } |
37 | 124 | } |
0 commit comments