Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset bundles guide #534

Merged
merged 11 commits into from
Mar 1, 2024
Prev Previous commit
Next Next commit
Fixed names and comment spaces
  • Loading branch information
Indigocoder1 committed Mar 1, 2024
commit c8d44e86cb9920d4d641516bc72a91079a9523c0
65 changes: 33 additions & 32 deletions Nautilus/Documentation/guides/assetbundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ namespace Examples
{
internal class AssetBundles : BaseUnityPlugin
{
//Usually this is done in your Plugin script but technically you can do it wherever
public static AssetBundle assetBundle { get; private set; }
// Usually this is done in your Plugin script but technically you can do it wherever
public static AssetBundle MyAssetBundle { get; private set; }

//This gets the path to the "Assets" folder inside my plugin folder
//If you don't have an assets folder you can replace "AssetsFolderPath" with Assembly.GetExecutingAssembly().Location
//That just gets the path to the .dll of the mod
// This gets the path to the "Assets" folder inside my plugin folder
// If you don't have an assets folder you can replace "AssetsFolderPath" with Assembly.GetExecutingAssembly().Location
// That just gets the path to the .dll of the mod
public static string AssetsFolderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Assets");

private void Awake()
{
//Keep in mind that the assetbundle can only be open in one place at a time, so keep a reference
assetBundle = AssetBundle.LoadFromFile(Path.Combine(AssetsFolderPath, "myAssetBundle"));
// Keep in mind that the assetbundle can only be open in one place at a time, so keep a reference
MyAssetBundle = AssetBundle.LoadFromFile(Path.Combine(AssetsFolderPath, "myAssetBundle"));

//This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
// This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = AssetBundle.LoadAsset<GameObject>("myGameObject");
}
}
}
Expand All @@ -174,18 +174,18 @@ namespace Examples
{
internal class AssetBundles : BaseUnityPlugin
{
//Usually this is done in your Plugin script but technically you can do it wherever
public static AssetBundle assetBundle { get; private set; }
// Usually this is done in your Plugin script but technically you can do it wherever
public static AssetBundle MyAssetBundle { get; private set; }

private void Awake()
{
//Keep in mind that the assetbundle can only be open in one place at a time, so keep a reference
//This method assumes you have a folder named "Assets" in your mod's plugin folder
//The second parameter needs to be the name of the asset bundle file (Usually they don't have file extensions)
assetBundle = AssetBundleLoadingUtils.LoadFromAssetsFolder(Assembly.GetExecutingAssembly(), "myAssetBundle")
// Keep in mind that the assetbundle can only be open in one place at a time, so keep a reference
// This method assumes you have a folder named "Assets" in your mod's plugin folder
// The second parameter needs to be the name of the asset bundle file (Usually they don't have file extensions)
MyAssetBundle = AssetBundleLoadingUtils.LoadFromAssetsFolder(Assembly.GetExecutingAssembly(), "myAssetBundle")

//This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
// This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = MyAssetBundle.LoadAsset<GameObject>("myGameObject");
}
}
}
Expand Down Expand Up @@ -219,20 +219,20 @@ namespace ExamplePrefab
{
internal static class MyCoolPrefab
{
public static TechType techType { get; private set; }
public static PrefabInfo MyPrefabInfo { get; private set; }

public static void Patch()
{
PrefabInfo prefabInfo = PrefabInfo.WithTechType("myCoolPrefab", "My Cool Prefab", "Pretty cool, right!")
Indigocoder1 marked this conversation as resolved.
Show resolved Hide resolved
.WithIcon(SpriteManager.Get(TechType.Titanium));
//Just using the Titanium sprite as a placeholder
// Just using the Titanium sprite as a placeholder

//Cache the tech type for use in other places
techType = prefabInfo.TechType;
// Cache the tech type for use in other places
MyPrefabInfo = prefabInfo;

var prefab = new CustomPrefab(prefabInfo);

//Create the recipe
// Create the recipe
RecipeData recipe = new RecipeData
{
craftAmount = 1,
Expand All @@ -243,35 +243,36 @@ namespace ExamplePrefab
},
};

//Set the prefab GamrObject to the result of the GetAssetBundlePrefab method
// Set the prefab GamrObject to the result of the GetAssetBundlePrefab method
prefab.SetGameObject(GetAssetBundlePrefab());

//Using the Seaglide as a placeholder unlock
// Using the Seaglide as a placeholder unlock
prefab.SetUnlock(TechType.Seaglide);

//Set the recipe
// Set the recipe
prefab.SetRecipe(recipe)
.WithCraftingTime(6f);

//Add the prefab to the Miscellaneous tab of the blueprints in the PDA
// Add the prefab to the Miscellaneous tab of the blueprints in the PDA
prefab.SetPdaGroupCategory(TechGroup.Miscellaneous, TechCategory.Misc);

// Register the prefab to the Nautilus prefab database
prefab.Register();
}

private static GameObject GetAssetBundlePrefab()
{
GameObject myCoolPrefab = assetBundle.LoadAsset<GameObject>("myCoolPrefab");

//The classID is the same as the one we put into the PrefabInfo.WithTechType up above
//The LargeWorldEntity.CellLevel determines how far away the object will be loaded from the player
PrefabUtils.AddBasicComponents(myCoolPrefab, "myCoolPrefab", techType, LargeWorldEntity.CellLevel.Medium);
// The classID is the same as the one we put into the PrefabInfo.WithTechType up above
// The LargeWorldEntity.CellLevel determines how far away the object will be loaded from the player
PrefabUtils.AddBasicComponents(myCoolPrefab, "myCoolPrefab", MyPrefabInfo.TechType, LargeWorldEntity.CellLevel.Medium);
Indigocoder1 marked this conversation as resolved.
Show resolved Hide resolved

//Makes the GameObject have the correct shaders
//You can use the optional inputs here to change the look of your object
// Makes the GameObject have the correct shaders
// You can use the optional inputs here to change the look of your object
MaterialUtils.ApplySNShaders(myCoolPrefab);

//Return the GameObject with all the components added
// Return the GameObject with all the components added
return myCoolPrefab;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Documentation/guides/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
- [Development Setup Guide](dev-setup.md)
- [Simple Mod Guide](simple-mod.md)
- [Updating from SML 2.0 to Nautilus](sml2-to-nautilus.md)
- [Using external models (Asset Bundles)](assetbundles.md)
- [Using External Assets (Asset Bundles)](assetbundles.md)
2 changes: 1 addition & 1 deletion Nautilus/Documentation/guides/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
href: simple-mod.md
- name: Updating to Nautilus
href: sml2-to-nautilus.md
- name: Using external models (Asset Bundles)
- name: Using External Assets (Asset Bundles)
href: assetbundles.md