Class ZOSimDocumentRoot
A ZOSim root document. This is the "document root" and "root" GameObject component in the
Unity object hierarchy.
For example the Unity structure could be:
ZOSimDocumentRoot:
ZOSimOccurrence:
ZOSimOccurrence:
ZOSimOccurrence:
ZOSimOccurrence:
ZOSimOccurrence:
It is primarily responsible for serialization of the Unity structure to ZoSim JSON document and deserialization from ZoSim JSON document to a Unity structure.
Inheritance
Inherited Members
Namespace: ZO.Document
Assembly: Unity.ZeroSim.dll
Syntax
[ExecuteAlways]
public class ZOSimDocumentRoot : MonoBehaviour
Fields
| Improve this Doc View Source_zoSimDocumentFilePath
The ZOSim JSON document path.
Declaration
[SerializeField]
public string _zoSimDocumentFilePath
Field Value
Type | Description |
---|---|
System.String |
Properties
| Improve this Doc View SourceAssetBundle
A ZoSim document can have an asset bundle associated with it that contains things like visual and collision meshes. NOTE: This lazy loads the asset bundle on first request
Declaration
public AssetBundle AssetBundle { get; }
Property Value
Type | Description |
---|---|
UnityEngine.AssetBundle |
JSON
The ZOSim JSON for this document root.
Declaration
public JObject JSON { get; set; }
Property Value
Type | Description |
---|---|
Newtonsoft.Json.Linq.JObject |
Name
The name of this zosim document root. Note that it should be unique, so if you are spawing a bunch of these make sure to set the "document_name" in the ZeroSim JSON to something unique!
Declaration
public string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ZOSimDocumentFilePath
Declaration
public string ZOSimDocumentFilePath { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceDeserialize(JObject)
Declaration
public void Deserialize(JObject json)
Parameters
Type | Name | Description |
---|---|---|
Newtonsoft.Json.Linq.JObject | json |
FindAssetsByName(String)
Attempts to find an assets, first checking asset bundle and then in the Assets directory. NOTE: if only a partial name is give it will return all matches of asset that has the name.
Declaration
public Object[] FindAssetsByName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Either full asset path or a partial name. If given just a partial name and there are multiple matches it will return all the assets that have that partial name. |
Returns
Type | Description |
---|---|
UnityEngine.Object[] |
GetComponentJSON(String)
Get the JSON for a ZoSim component name.
Declaration
public JObject GetComponentJSON(string componentName)
Parameters
Type | Name | Description |
---|---|---|
System.String | componentName | The name of the component. |
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JObject | A JSON Object of the conmponent or null if it doesn't exist. |
GetOccurrence(String)
Get zosim occurrence by name.
Declaration
public ZOSimOccurrence GetOccurrence(string occurrenceName)
Parameters
Type | Name | Description |
---|---|---|
System.String | occurrenceName | the name of the occurrence |
Returns
Type | Description |
---|---|
ZOSimOccurrence | ZOSimOccurrence |
GetOccurrenceJSON(String, JArray)
Declaration
public JObject GetOccurrenceJSON(string occurrenceName, JArray occurrences = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | occurrenceName | |
Newtonsoft.Json.Linq.JArray | occurrences |
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JObject |
LoadFromZOSimFile(String)
Load Zero Sim JSON file.
Declaration
public void LoadFromZOSimFile(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | path to zosim file |
OnPostDeserializationNotification(Action<ZOSimDocumentRoot>)
If someone needs to be notified after a deserialization of a ZOSim File. For example a ZOHingeJoint needs to fixup the connected bodies that may or may not exist during the Deserialize call.
Declaration
public void OnPostDeserializationNotification(Action<ZOSimDocumentRoot> notification)
Parameters
Type | Name | Description |
---|---|---|
System.Action<ZOSimDocumentRoot> | notification |
SaveToZOSimFile(String)
Saves to ZOSim file.
Declaration
public void SaveToZOSimFile(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath |
Serialize()
Builds ZOSim document by traversing hierarchy.
Declaration
public JObject Serialize()
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JObject |
ToJSON(Quaternion)
Convert Unity Quaternion to JSON token.
Declaration
public static JToken ToJSON(Quaternion v)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Quaternion | v | Unity Quaternion |
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JToken | JSON token |
ToJSON(Vector3)
Convert Unity Vector3 to JSON token.
Declaration
public static JToken ToJSON(Vector3 v)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Vector3 | v | Unity Vector3 |
Returns
Type | Description |
---|---|
Newtonsoft.Json.Linq.JToken | JSON token |
ToQuaternion(JToken)
Convert JSON token to Unity Quaternion.
Declaration
public static Quaternion ToQuaternion(JToken json)
Parameters
Type | Name | Description |
---|---|---|
Newtonsoft.Json.Linq.JToken | json | JSON Token. Must be a JArray! |
Returns
Type | Description |
---|---|
UnityEngine.Quaternion | Unity Quaternion |
ToVector3(JToken)
Convert JSON token to Unity Vector3.
Declaration
public static Vector3 ToVector3(JToken json)
Parameters
Type | Name | Description |
---|---|---|
Newtonsoft.Json.Linq.JToken | json | JSON Token. Must be a JArray! |
Returns
Type | Description |
---|---|
UnityEngine.Vector3 |