Jump to content

Vanilla Asset Bundle Loading Hooks


sphereii

Recommended Posts

Alpha 17e has introduced native support in loading Unity's unity3d asset bundles. What this means to us, is that we can load in custom blocks and entities, as well as adding new sounds into the game, without using SDX.

 

** Note: Any modlets that use Asset Bundles must be installed on the Client and the Server **

 

This is going to be a short tutorial just to get you started by showing you which hooks we have available to us. It's not meant to be a full tutorial on how to use unity.

 

All of the hooks below use the following syntax:

#@modfolder:<ModSubFolder>/<Unity3DFile>?<UnityPrefabName>

# 			is the hook that makes the code going down a different path to load.
@modfolder:     	At run time, this gets resolved to Mods/MyMod/ path where the Unity3D file is found.
<ModSubFolder> 		This is a subfolder in your MyMod folder, that will hold the resources. Typically it's called "Resources".
<Unity3DFile>		This is the full unity3d file name, including extension, of your unity asset bundle.
?			Is a hook to tell the game to load the follow as a prefab
<UnityPrefabName>	This is your unity prefab name.

 

Example:

 

I have a sound file called myBatteryBankSound, stored in the mysound.unity3d asset bundle. My Mod is called SphereII_Tutorial. It only contains an xpath to change the sound ClipName.

	
Mods/SphereII_Tutorial/Config/sounds.xml
Mods/SphereII_Tutorial/Resources/mysound.unity3d
Mods/ModInfo.xml

sounds.xml:
<configs>
<set xpath="/Sounds/SoundDataNode[@name='batterybank_idle']/AudioClip/@ClipName">#@modfolder:Resources/mysound.unity3d?myBatteryBankSound</set>
</configs>

[/CoDE]

@modfolder: is updated at run time and replaced as Mods/SphereII_Tutorial/

 

In the exported configs, you'd see

 

<AudioClip ClipName="#@modfolder(SphereII_Tutorial):Resources/mysound.unity3d?myBatteryBankSound" Loop="true"/>

 

he type of prefab and asset you make depends on the context in what you'll want to use it in. For example, in the above example, myBatteryBankSound must be a supported sound file, otherwise the game will not load it. Likewise, if you try to load up a Model on the block, it has to be a block prefab in Unity.

 

[u]Unity 2018.2.18[/u]

For Alpha 17e, Unity 2018.2.0f is used by the game. You must use a unity version that matches that, although the last digit is less important. For example, you could probably use 2018.2.18.

 

https://unity3d.com/get-unity/download/archive?_ga=2.59587373.189228578.1543509469-764944493.1525198827

 

[u]Export Asset Bundles: [/u]

The ExportAssetBundles.ca has been hosted here: https://github.com/7D2D/Templates-and-Utilities

 

In Unity, drag and drop the exportassetbundles.cs into Assets window. It'll compile and add itself to the right click, context menu.

 

[u]Tutorials[/u]

The following tutorials are still mostly valid for creating unity blocks and entities. We'll be working on newer tutorials. The biggest difference is that the version of Unity that we are using is much newer, but the workflow should be the same.

 

 

https://7d2dsdx.github.io/Tutorials/

 

The following post will include all currently known modfolder hooks.

Link to comment
Share on other sites

The following hooks are known to exist, even if we do not yet know what kind of unity prefab they'll will take.

 

AudioClips:

ClipName

AudioSourceName

 

Items:

DropMeshFile

HandMeshFile

Meshfile

LightSource

 

ItemActionZoom:

Zoom_overlay

 

EntityClasses:

Mesh

AddFurToMaterial

Prefab

MeshFP

Model-Damage-*

ParticleOnSpawn

ReplaceMaterial[0-5]

 

UMA Animal EntityClasses:

Colliders

 

Player and SupplyCrate EntityClasses:

SkinTexture

 

Blocks of "New" or "ModelEntity" shape:

Model

 

Biome/Weather particle effect:

prefab

 

MinEventActionAttachPrefabToHeldItem:

prefab

 

MinEventActionAttachParticleEffectToEntity:

particle

Link to comment
Share on other sites

Colliders and activation text on multi blocks

 

Here's a little info on how to get the colliders and activation text working correctly on blocks that are bigger than 1x1x1

 

The first thing you will need is a blank MonoBehaviour script called RootTransformRefParent.cs see the bottom of this post for a example.

 

Now add a tag to your unity project in tag number 4 called T_Block This MUST be in tag number 4!

 

Select all the meshes that have colliders, tag them with the T_Block tag and add the RootTransformRefParent.cs script to them all.

 

Now select the Prefab (root object) and tag it with T_Block as well, but don't add the script this time. Don't tag any of the other empty GameObject.

 

 

 

Export it like normal and all your colliders and activation text should be working.

 

Don't forget to add the required xml properties

<property name="DisplayType" value="blockMulti" />
<property name="MultiBlockDim" value="4,1,6"/>

 

 

RootTransformRefParent.cs should look like this:

using UnityEngine;
using System.Collections;

public class RootTransformRefParent : MonoBehaviour {

void Start () {

}

void Update () {

}
}

Link to comment
Share on other sites

If I do not use it through the Xpatch, and make changes directly to the original configs - it does not work.

 

Or i do need a different syntax? (the same resources work if the blocks are written through a Xpatch)

 

 

(I use to check the modlet from Xyth)

if i use this line directly in the original block.xml:

<property name="Model" value="#@modfolder:Resources/PinupPosters.unity3d?PinupPoster01Prefab" />

I get an error in the console:

2018-12-02T20:58:01 11.906 INF StartAsServer

Unable to open archive file: C:/Program Files (x86)/Steam/steamapps/common/7 Days To Die MOD/7DaysToDie_Data/../Data/Bundles/@modfolder:Resources/PinupPosters.unity3d

 

(Filename: Line: 586)

 

2018-12-02T20:58:04 14.914 ERR Loading AssetBundle "C:/Program Files (x86)/Steam/steamapps/common/7 Days To Die MOD/7DaysToDie_Data/../Data/Bundles/@modfolder:Resources/PinupPosters.unity3d" failed!

2018-12-02T20:58:04 14.914 ERR Model '#@modfolder:Resources/PinupPosters.unity3d?PinupPoster01Prefab' not found on block with name zombiePinup01

2018-12-02T20:58:04 14.914 ERR XML loader: Loading and parsing 'blocks.xml' failed

2018-12-02T20:58:04 14.915 EXC Model '#@modfolder:Resources/PinupPosters.unity3d?PinupPoster01Prefab' not found on block with name zombiePinup01

Exception: Model '#@modfolder:Resources/PinupPosters.unity3d?PinupPoster01Prefab' not found on block with name zombiePinup01

at BlockShapeModelEntity.Init (.Block _block) [0x00000] in <filename unknown>:0

at BlocksFromXml.CreateBlocks (.XmlFile _xmlFile, Boolean _fillLookupTable) [0x00000] in <filename unknown>:0

at BlocksFromXml.CreateBlocks (.XmlFile _xmlFile) [0x00000] in <filename unknown>:0

at WorldStaticData.LoadBlocks (.XmlFile _xmlFile) [0x00000] in <filename unknown>:0

at WorldStaticData+<loadSingleXml>c__Iterator1.MoveNext () [0x00000] in <filename unknown>:0

UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)

UnityEngine.DebugLogHandler:LogException(Exception, Object)

UnityEngine.Logger:LogException(Exception, Object)

UnityEngine.Debug:LogException(Exception)

Logger:masterLogException(Exception)

Logger:Exception(Exception)

Log:Exception(Exception)

<loadSingleXml>c__Iterator1:MoveNext()

UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Link to comment
Share on other sites

If I do not use it through the Xpatch, and make changes directly to the original configs - it does not work.

 

Or i do need a different syntax? (the same resources work if the blocks are written through a Xpatch)

 

 

(I use to check the modlet from Xyth)

if i use this line directly in the original block.xml:

<property name="Model" value="#@modfolder:Resources/PinupPosters.unity3d?PinupPoster01Prefab" />

I get an error in the console:

 

If you do not use the xpath hooks, you'll have to place your unity bundle under Data/Bundles, and just reference the last part:

 

value="#pinupPosters.unity3d?PinupPoster01Prefab" />

Link to comment
Share on other sites

If you do not use the xpath hooks, you'll have to place your unity bundle under Data/Bundles, and just reference the last part:

 

value="#pinupPosters.unity3d?PinupPoster01Prefab" />

Yes it solved the problem!

Thanks so much! :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...