Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 3b2c6f8

Browse files
committed
Update SFSMod to support assets
1 parent 97a90d8 commit 3b2c6f8

1 file changed

Lines changed: 100 additions & 13 deletions

File tree

ModLoader/SFSMod.cs

Lines changed: 100 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,124 @@
11
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;
64

75
namespace ModLoader
86
{
97
/// <summary>
108
/// This interface is a mod entry point. so if you want to create mod, you need implement this interface
119
/// in the main class, but only in the main class to prevent errors.
1210
/// </summary>
13-
public interface SFSMod
11+
public abstract class SFSMod
1412
{
1513

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+
1655
/// <summary>
17-
/// The modder can specify mod name in this function.
56+
/// get a descripton about what do this mod
1857
/// </summary>
19-
string getModName();
58+
public string Description
59+
{
60+
get { return this._description; }
61+
}
2062

2163
/// <summary>
22-
/// get the creator mod.
64+
/// get the list of mods need it to work.
2365
/// </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+
25112

26113
/// <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
28115
/// </summary>
29-
void load();
116+
public abstract void load();
30117

31118
/// <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.
33120
/// </summary>
34-
void unload();
121+
public abstract void unload();
35122

36123
}
37124
}

0 commit comments

Comments
 (0)