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
Merged

Conversation

Indigocoder1
Copy link
Contributor

Changes made in this pull request

  • Adds a guide for creating Asset Bundles on the Nautilus docs
  • Added the guide to the overview.md
  • Added the guide to the toc.yml

Breaking changes

  • Should be none

Copy link
Contributor

github-actions bot commented Feb 28, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Indigocoder1
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Feb 28, 2024
@LeeTwentyThree
Copy link
Member

I’d suggest a more broad name since asset bundles can be used for MUCH more than just custom models.

@Indigocoder1
Copy link
Contributor Author

Hm. True. Maybe "Using external assets"? I can also add something about loading other types than GameObjects in the guide at the end.

@LeeTwentyThree
Copy link
Member

I think something very basic for sprites and sounds would be amazing. I can help out with audio if you need.

Copy link
Member

@LeeTwentyThree LeeTwentyThree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I have a lot of suggestions, some more nitpicky than others, but this absolutely works as a guide for new modders and anyone looking to add custom models.

One of the more broad suggestions I have is adding headers to split the guide up into smaller sections.

Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
@LeeTwentyThree
Copy link
Member

Resolves #334.

@LeeTwentyThree LeeTwentyThree linked an issue Feb 28, 2024 that may be closed by this pull request
@Indigocoder1
Copy link
Contributor Author

I incorporated your feedback into the latest commit. I also added the custom prefab guide and moved some stuff around

@Indigocoder1
Copy link
Contributor Author

I can also add a small section on other things like sprites and audio like you said. I forgot to do that last night. I'm not too familiar with importing audio but I'll look into it.

Copy link
Member

@LeeTwentyThree LeeTwentyThree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor things. Looks great.

Comment on lines 141 to 159
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; }

//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"));

//This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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; }
//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"));
//This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
}
}
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; }
// 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"));
// This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
}
}

Comment on lines 175 to 190
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; }

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")

//This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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; }
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")
//This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
}
}
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; }
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")
// This name needs to be the exact same name as the prefab you put in the bundle
GameObject mirrorVariant1 = assetBundle.LoadAsset<GameObject>("myGameObject");
}
}

Comment on lines 224 to 260
public static void Patch()
{
PrefabInfo prefabInfo = PrefabInfo.WithTechType("myCoolPrefab", "My Cool Prefab", "Pretty cool, right!")
.WithIcon(SpriteManager.Get(TechType.Titanium));
//Just using the Titanium sprite as a placeholder

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

var prefab = new CustomPrefab(prefabInfo);

//Create the recipe
RecipeData recipe = new RecipeData
{
craftAmount = 1,
Ingredients =
{
new Ingredient(TechType.Titanium, 2),
new Ingredient(TechType.CopperWire, 2),
},
};

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

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

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

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

prefab.Register();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static void Patch()
{
PrefabInfo prefabInfo = PrefabInfo.WithTechType("myCoolPrefab", "My Cool Prefab", "Pretty cool, right!")
.WithIcon(SpriteManager.Get(TechType.Titanium));
//Just using the Titanium sprite as a placeholder
//Cache the tech type for use in other places
techType = prefabInfo.TechType;
var prefab = new CustomPrefab(prefabInfo);
//Create the recipe
RecipeData recipe = new RecipeData
{
craftAmount = 1,
Ingredients =
{
new Ingredient(TechType.Titanium, 2),
new Ingredient(TechType.CopperWire, 2),
},
};
//Set the prefab GamrObject to the result of the GetAssetBundlePrefab method
prefab.SetGameObject(GetAssetBundlePrefab());
//Using the Seaglide as a placeholder unlock
prefab.SetUnlock(TechType.Seaglide);
//Set the recipe
prefab.SetRecipe(recipe)
.WithCraftingTime(6f);
//Add the prefab to the Miscellaneous tab of the blueprints in the PDA
prefab.SetPdaGroupCategory(TechGroup.Miscellaneous, TechCategory.Misc);
prefab.Register();
}
public static void Patch()
{
PrefabInfo prefabInfo = PrefabInfo.WithTechType("MyCoolPrefab", "My Cool Prefab", "Pretty cool, right!")
.WithIcon(SpriteManager.Get(TechType.Titanium));
// Just using the Titanium sprite as a placeholder
// Cache the tech type for use in other places
techType = prefabInfo.TechType;
var prefab = new CustomPrefab(prefabInfo);
// Create the recipe
RecipeData recipe = new RecipeData
{
craftAmount = 1,
Ingredients =
{
new Ingredient(TechType.Titanium, 2),
new Ingredient(TechType.CopperWire, 2),
},
};
// Set the prefab GamrObject to the result of the GetAssetBundlePrefab method
prefab.SetGameObject(GetAssetBundlePrefab());
// Using the Seaglide as a placeholder unlock
prefab.SetUnlock(TechType.Seaglide);
// Set the recipe
prefab.SetRecipe(recipe)
.WithCraftingTime(6f);
// Add the prefab to the Miscellaneous tab of the blueprints in the PDA
prefab.SetPdaGroupCategory(TechGroup.Miscellaneous, TechCategory.Misc);
prefab.Register();
}

Comment on lines 266 to 275
//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);

//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 myCoolPrefab;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two suggestions here:

  1. When creating the custom prefab, cache the PrefabInfo instead of JUST the TechType.
  2. Spaces after "//"

Copy link
Member

@LeeTwentyThree LeeTwentyThree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very small thing

Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
Copy link
Member

@LeeTwentyThree LeeTwentyThree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this

Nautilus/Documentation/guides/assetbundles.md Outdated Show resolved Hide resolved
@LeeTwentyThree LeeTwentyThree merged commit cc80268 into SubnauticaModding:master Mar 1, 2024
1 check passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asset Bundle documentation
2 participants