-
Notifications
You must be signed in to change notification settings - Fork 37
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
Asset bundles guide #534
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
I’d suggest a more broad name since asset bundles can be used for MUCH more than just custom models. |
Hm. True. Maybe "Using external assets"? I can also add something about loading other types than GameObjects in the guide at the end. |
I think something very basic for sprites and sounds would be amazing. I can help out with audio if you need. |
There was a problem hiding this 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.
Resolves #334. |
I incorporated your feedback into the latest commit. I also added the custom prefab guide and moved some stuff around |
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. |
There was a problem hiding this 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.
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"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); | |
} | |
} |
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"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); | |
} | |
} |
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(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); | |
} |
//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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two suggestions here:
- When creating the custom prefab, cache the PrefabInfo instead of JUST the TechType.
- Spaces after "//"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very small thing
Co-authored-by: Lee23 <31892011+LeeTwentyThree@users.noreply.github.com>
Co-authored-by: Lee23 <31892011+LeeTwentyThree@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this
Changes made in this pull request
Breaking changes