Skip to content

Commit

Permalink
[GitHub Action] Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 6, 2024
1 parent d587efc commit ab51859
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
32 changes: 18 additions & 14 deletions docs/Mod-Creation/Assets/Loading-Assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ The structure of your Plugin folder is one of the most important things to load

###### example folder structure of Starstorm2 nightly, all the assetbundles are in the assetbundles folder, all the language files are in languages, and the soundbank is in soundbanks.

When going to make a .zip for thunderstore (or to import to r2modman locally), wrap these in a folder called "plugins" and have that folder next to your manifest.json and icon.png in the root of your zip.

### File Location

The easiest and safest way of getting the location of your DLL is thru your main plugin, via the Info property. To easily get access to the Info property, you can create a static field in your MainPlugin of type PluginInfo, and set it on Awake.

```csharp
Expand All @@ -32,7 +36,7 @@ public class MainClass : BaseUnityPlugin
}
```

### Loading AssetBundles
## Loading AssetBundles

For loading the AssetBundle for your mod, you can use the following class as an example.

Expand All @@ -41,23 +45,23 @@ using UnityEngine;
using System.IO;

//Static class for ease of access
public static class Assets
public static class Asset
{
//The mod's AssetBundle
//You will load the assetbundle and assign it to here.
public static AssetBundle mainBundle
//A constant of the AssetBundle's name.
public const string bundleName = "mybundle";
// Not necesary, but useful if you want to store the bundle on its own folder.
// Uncomment this if your assetbundle is in its own folder. Of course, make sure the name of the folder matches this.
// public const string assetBundleFolder = "AssetBundles";
//The direct path to your AssetBundle
public static string AssetBundlePath
{
get
{
//This returns the path to your assetbundle assuming said bundle is on the same folder as your DLL. If you have your bundle in a folder, you can uncomment the statement below this one.
return Path.Combine(Path.GetDirectoryName(MainClass.PInfo.Location), myBundle);
//return Path.Combine(Path.GetDirectoryName(MainClass.PInfo.Location), assetBundleFolder, myBundle);
//This returns the path to your assetbundle assuming said bundle is on the same folder as your DLL. If you have your bundle in a folder, you can instead uncomment the statement below this one.
return Path.Combine(Path.GetDirectoryName(MainClass.PInfo.Location), bundleName);
//return Path.Combine(Path.GetDirectoryName(MainClass.PInfo.Location), assetBundleFolder, bundleName);
}
}

Expand All @@ -71,9 +75,9 @@ public static class Assets

You can also load multiple assetBundles for your mod, but the loading of multiple bundles is outside of the scope of this guide.

### Loading SoundBanks
## Loading SoundBanks

#### Loading SoundBanks from a folder
### Loading SoundBanks from a folder

```csharp
using System.IO;
Expand Down Expand Up @@ -121,19 +125,19 @@ public static class SoundBank
}
```

#### Loading Soundbanks with R2API
### Loading Soundbanks with R2API

Loading a soundBank with R2API is trivial, since you just need to put your soundBank file in the bepinex/plugins folder and change its extension from `.bnk` to `.sound`. R2API will load it

### Loading Language Files
## Loading Language Files

Loading LanguageFiles requires a special setup of the Languages folder, an example "Language Folder Tree" can be seen here.

![image](https://github.com/user-attachments/assets/47a9b67f-b23f-416d-86dd-38de50d11cc0)

###### Example language folder tree of starstorm, Notice how the root folder named Languages contains a set of subFolders, and each subFolder has the name of one of the Languages in ROR2, en is for English, es-419 for spanish, etc. While each of those subFolders has a .json file with the Language Tokens and strings.

#### Loading Language Files with RoR2's Language system
### Loading Language Files with RoR2's Language system

Loading your language files with a delegate within the game allows them to be loaded directly to ROR2's language systems, which means you're avoiding depending on LanguageAPI for loading tokens.
Keep in mind this has to be before the Language system is initialized.
Expand Down Expand Up @@ -165,9 +169,9 @@ public static class Languages
}
```

#### Loading LanguageFiles with R2API
### Loading LanguageFiles with R2API

R2API automatically load any file with extension .language if it detects one in the bepinex/plugins folder
R2API automatically loads any file with extension .language if it detects one in the bepinex/plugins folder
[More details in this page](https://risk-of-thunder.github.io/R2Wiki/Mod-Creation/Assets/Localization/)

If you want to load language files manually instead, you can do something like this:
Expand Down
14 changes: 7 additions & 7 deletions docs/Mod-Creation/C#-Programming/Unity-and-MonoBehaviour.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Generally when people say "component" they are talking about classes derived fro

### Constructor
Generally, you shouldn't use constructors in classes derived from MonoBehaviour. If you need to initialize something, do it in Awake.
https://ilkinulas.github.io/development/unity/2016/05/30/monobehaviour-constructor.html
[https://ilkinulas.github.io/development/unity/2016/05/30/monobehaviour-constructor.html](https://ilkinulas.github.io/development/unity/2016/05/30/monobehaviour-constructor.html)

## MonoBehaviour Messages
Every instance of MonoBehaviour has some special functions that are called by the engine at specific events.
Here is the game loop: https://docs.unity3d.com/uploads/Main/monobehaviour_flowchart.svg
[Here is the game loop.](https://docs.unity3d.com/uploads/Main/monobehaviour_flowchart.svg)

All MonoBehaviour callbacks are described in unity documentation: [Check under "Messages" header](https://docs.unity3d.com/ScriptReference/MonoBehaviour.html)
But down below we'll talk about some of them.
All MonoBehaviour callbacks are described in unity documentation: [Check under "Messages" header](https://docs.unity3d.com/ScriptReference/MonoBehaviour.html)
Down below we'll talk about some of them.

### Awake
Awake is the first thing that is called when a GameObject with this MonoBehaviour attached is created.
Expand Down Expand Up @@ -69,7 +69,7 @@ Avoid, same as Invoke.

Starts an asynchronous process similar to a thread. Use this to repeat a function a specific number of times or Lerp a value without slowdown.

interesting article about coroutine vs threading: https://gamedev.stackexchange.com/questions/143454/unity-coroutine-vs-threads
[interesting article about coroutine vs threading](https://gamedev.stackexchange.com/questions/143454/unity-coroutine-vs-threads)

## Manipulating Components
These functions are used to add, reference, and remove components of GameObjects. If your mod is done through code, you will likely have to wrangle with these a lot.
Expand Down Expand Up @@ -103,5 +103,5 @@ Should be avoided even more than GetComponent
Do not ever use this
The power to find any object in a scene with a desired component sounds appealing, but it will iterate through every single object in the scene, searching through their components. It is a terrible performance killer and if you are caught using this you will be publicly shamed.

# Using Scripts in Editor
While you are free to manipulate them as much as you want through code, MonoBehaviour components were intended to use in editor. Refer to this article on how to do as such: https://risk-of-thunder.github.io/R2Wiki/Mod-Creation/C%23-Programming/Using-MonoBehaviour-Scripts-in-Editor/
## Using Scripts in Editor
While you are free to manipulate them as much as you want through code, MonoBehaviour components were intended to use in editor. Refer to [this article](https://risk-of-thunder.github.io/R2Wiki/Mod-Creation/C%23-Programming/Using-MonoBehaviour-Scripts-in-Editor/) on how to do as such
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MonoBehaviours are components that are attached to Unity GameObjects and perform various functions. See our article about them [here](https://risk-of-thunder.github.io/R2Wiki/Mod-Creation/C%23-Programming/Unity-and-MonoBehaviour/), and see Unity documentation about them [here](https://docs.unity3d.com/Manual/ScriptingImportantClasses.html)

MonoBehaviours are most commonly used in prefabs, created in the Unity Editor. From here, this article will assume you know how to create prefabs, attach scripts to them, and build those prefabs into assetbundles.
MonoBehaviours are most commonly used in prefabs, created in the Unity Editor. From here, this article will assume you know how to create prefabs, attach scripts to them, and build those prefabs into assetbundles. See [here](https://risk-of-thunder.github.io/R2Wiki/Mod-Creation/Assets/Loading-Assets/)
to learn how to load those assetbundles into your mod.

If you are creating and loading prefabs for use in your mod, you have the ability to attach any of the game's MonoBehaviours, and any custom MonoBehaviours that you want to write as well. Refer to the respective sections on how to do each.

Expand All @@ -17,15 +18,15 @@ Preferred if you are only using a few scripts

1. Create a script with the same name and namespace as an existing RoR2 script
2. fill this script out with any Serialized Fields in the script that you want to use in editor.
i. this includes any any `public` field, and any field with the `[SerializedField]` attribute
- this includes any any `public` field, and any field with the `[SerializedField]` attribute

That's it. pretty simple, but this doesn't really scale. You will have to do this with *every* script you want to use in editor.
Consider the next option if you want to use many RoR2 scripts.

### Option 2: Importing all RoR2 scripts
Preferred if you are using many RoR2 scripts, namely if you are creating projectiles.

If you are currently creating your mod in code, and only using Unity to build assetbundles, you can use ThunderKit to import the RoR2 codebase into your unity project, and you will have access to all unity components.
If you are currently creating your mod in code, and only using Unity to build assetbundles, you can use ThunderKit to import the RoR2 codebase into your unity project, and you will have access to all unity components. After which, you can return to buliding your mod in code as before.

This will take some setup, but if you are using components a lot, and if you want to work with projectiles, it is definitely worth it.

Expand Down Expand Up @@ -53,7 +54,8 @@ This works perfectly fine, but does not scale. It can easily become tedious to t
Any MonoBehaviour in your mod code can be attached to a prefab in unity.

1. Create a script with the same name and namespace as your MonoBehaviour class in your mod
i. You can likely just copy the whole code over, but if you can't, you only need the class name and any serialized fields you want to use in editor.
- You can likely just copy the whole code over, but if you can't, you only need the class name and any serialized fields you want to use in editor.
- this includes any any `public` field, and any field with the `[SerializedField]` attribute
2. Put this script in a folder in your Unity project
2. Right click and create an Assembly Definition in this folder, with the same name as the .csproj of your mod

Expand All @@ -65,7 +67,7 @@ Note: If your code runs into errors because it references other RoR2 code, you w
You can just take your whole mod dll and slap it in your unity project.
To do this, you will need to use Thunderkit to add RoR2 and all other dependencies of your mod to your unity project.

In my experience, this just ended up slowing down my development. The above process worked well for my purposes. If you are considering this option because you are using a ton of components, it may be time to pursue a thunderkit setup
In my experience, this just ended up slowing down my development, compared to Option 1. If you are considering this option because you are using a ton of components, it may be time to pursue a thunderkit setup

### Option 3: Just Use Thunderkit
If you are more unity-minded, Thunderkit is an mod creating workflow where everything is in editor.
Expand Down

0 comments on commit ab51859

Please sign in to comment.