GPU Instancer Pro:APIDocumentation

From GurBu Wiki
Jump to: navigation, search

About GPU Instance Pro | Getting Started | Terminology | Best Practices | API Documentation | F.A.Q. | Support


You can use the GPUI API to manage your instanced objects at runtime smoothly through scripting. All the API methods are designed to be straightforward and to allow you to tap into the GPUI rendering pipeline. Using this API, you can enable/disable instancing per instance basis, add and remove instances and terrains, update transform matrices and much more. In this page, you will find detailed information on all the API methods and their parameters.

Please also note that you need to reference the GPUInstancerPro namespaces to use the API methods with: using GPUInstancerPro; or using GPUInstancerPro.PrefabModule; or using GPUInstancerPro.TerrainModule;

API methods are static methods and can be invoked with the class name, such as: GPUICoreAPI.RegisterRenderer or GPUIPrefabAPI.AddPrefabInstance or GPUITerrainAPI.AddTerrain




GPUInstancerPro.GPUICoreAPI


RegisterRenderer



public static bool RegisterRenderer(UnityEngine.Object source, GameObject prefab, out int rendererKey)

Parameters
source The source responsible for registering the renderer. E.g. the MonoBehaviour class
prefab GameObject that the renderers will be based on
rendererKey Integer key output that uniquely identifies the renderer


Description:

The RegisterRenderer method is used to set up GPUI renderers for the specified GameObject. This method needs to be called to produce a renderKey, which can then be used with the SetMatrices method to start rendering instances with the given transform matrices. To stop the rendering, the DisposeRenderer method should be called with the rendererKey output.



RegisterRenderer



public static bool RegisterRenderer(UnityEngine.Object source, GameObject prefab, GPUIProfile profile, out int rendererKey)

Parameters
source The source responsible for registering the renderer. E.g. the MonoBehaviour class
prefab GameObject that the renderers will be based on
profile GPUIProfile that determines various rendering settings
rendererKey Integer key output that uniquely identifies the renderer


Description:

The RegisterRenderer method is used to set up GPUI renderers for the specified GameObject. This method needs to be called to produce a renderKey, which can then be used with the SetMatrices method to start rendering instances with the given transform matrices. To stop the rendering, the DisposeRenderer method should be called with the rendererKey output.



DisposeRenderer



public static void DisposeRenderer(int rendererKey)

Parameters
rendererKey Integer key that uniquely identifies the renderer


Description:

Disposes the renderer data previously defined with the RegisterRenderer method.



SetMatrices



public static bool SetMatrices(int rendererKey, Matrix4x4[] matrices)

Parameters
rendererKey Integer key that uniquely identifies the renderer
matrices Matrix4x4 collection that store the transform data of instances


Description:

Sets the transform matrix data to a renderer previously defined with the RegisterRenderer method.



SetMatrices



public static bool SetMatrices(int rendererKey, List<Matrix4x4> matrices)

Parameters
rendererKey Integer key that uniquely identifies the renderer
matrices Matrix4x4 collection that store the transform data of instances


Description:

Sets the transform matrix data to a renderer previously defined with the RegisterRenderer method.



SetMatrices



public static bool SetMatrices(int rendererKey, NativeArray<Matrix4x4> matrices)

Parameters
rendererKey Integer key that uniquely identifies the renderer
matrices Matrix4x4 collection that store the transform data of instances


Description:

Sets the transform matrix data to a renderer previously defined with the RegisterRenderer method.



SetBufferSize



public static bool SetBufferSize(int rendererKey, int bufferSize)

Parameters
rendererKey Integer key that uniquely identifies the renderer
bufferSize Size of the buffer to allocate in GPU memory


Description:

Sets the transform matrix data to a renderer previously defined with the RegisterRenderer method.




AddCameraEventOnPreCull



public static void AddCameraEventOnPreCull(UnityAction<GPUICameraData> cameraEvent)

Parameters
cameraEvent Action that will be executed for each camera


Description:

Adds a method to execute before each camera's visibility calculations.



RemoveCameraEventOnPreCull



public static void RemoveCameraEventOnPreCull(UnityAction<GPUICameraData> cameraEvent)

Parameters
cameraEvent Action that is previously added with the AddCameraEvent method


Description:

Removes the method previously added with the AddCameraEventOnPreCull method.



AddCameraEventOnPreRender



public static void AddCameraEventOnPreRender(UnityAction<GPUICameraData> cameraEvent)

Parameters
cameraEvent Action that will be executed for each camera


Description:

Adds a method to execute after each camera's visibility calculations and before draw calls.



RemoveCameraEventOnPreRender



public static void RemoveCameraEventOnPreRender(UnityAction<GPUICameraData> cameraEvent)

Parameters
cameraEvent Action that is previously added with the AddCameraEvent method


Description:

Removes the method previously added with the AddCameraEventOnPreRender method.



AddCameraEventOnPostRender



public static void AddCameraEventOnPostRender(UnityAction<GPUICameraData> cameraEvent)

Parameters
cameraEvent Action that will be executed for each camera


Description:

Adds a method to execute after each camera's draw calls.



RemoveCameraEventOnPostRender



public static void RemoveCameraEventOnPostRender(UnityAction<GPUICameraData> cameraEvent)

Parameters
cameraEvent Action that is previously added with the AddCameraEvent method


Description:

Removes the method previously added with the AddCameraEventOnPostRender method.



GPUInstancerPro.PrefabModule.GPUIPrefabAPI


AddPrototype



public static int AddPrototype(GPUIPrefabManager prefabManager, GameObject prefab)

Parameters
prefabManager
prefab


Description:

Adds the given GameObject as a prototype to the Prefab Manager



AddPrefabInstance



public static void AddPrefabInstance(GPUIPrefab gpuiPrefab)

Parameters
gpuiPrefab


Description:

Adds the prefab instance to an existing Prefab Manager. The corresponding prefab should be defined as a prototype on the Prefab Manager. The prefab instance will be registered on the Prefab Manager with the manager's next LateUpdate. If you wish to add the instance immediately, please use the AddPrefabInstanceImmediate(GPUIPrefab) method.



AddPrefabInstances



public static void AddPrefabInstances(IEnumerable<GPUIPrefab> gpuiPrefabs)

Parameters
gpuiPrefabs


Description:

Adds the collection of prefab instances to an existing Prefab Manager. The corresponding prefabs should be defined as a prototype on the Prefab Manager. The instances will be registered on the Prefab Manager with manager's next LateUpdate. If you wish to add the instances immediately, please use the AddPrefabInstanceImmediate(GPUIPrefab) method.



AddPrefabInstances



public static bool AddPrefabInstances(GPUIPrefabManager prefabManager, IEnumerable<GPUIPrefab> instances, int prototypeIndex)

Parameters
prefabManager
instances Collection of instances of a specific prefab
prototypeIndex The prototype index of the prefab on the Prefab Manager


Description:

Adds the collection of instances of a specific prefab to the Prefab Manager. The instances will be registered on the Prefab Manager with manager's next LateUpdate. If you wish to add the instances immediately, please use the AddPrefabInstanceImmediate(GPUIPrefab) method.



AddPrefabInstance



public static bool AddPrefabInstance(GPUIPrefabManager prefabManager, GameObject go, int prototypeIndex)

Parameters
prefabManager
go
prototypeIndex The prototype index of the prefab on the Prefab Manager


Description:

Adds the prefab instance to the Prefab Manager. The instances will be registered on the Prefab Manager with manager's next LateUpdate. If you wish to add the instance immediately, please use the AddPrefabInstanceImmediate method.



AddPrefabInstance



public static bool AddPrefabInstance(GPUIPrefabManager prefabManager, GPUIPrefab gpuiPrefab, int prototypeIndex = -1)

Parameters
prefabManager
gpuiPrefab
prototypeIndex The prototype index of the prefab on the Prefab Manager


Description:

Adds the prefab instance to the Prefab Manager. The instances will be registered on the Prefab Manager with manager's next LateUpdate. If you wish to add the instance immediately, please use the AddPrefabInstanceImmediate(GPUIPrefab) method.



AddPrefabInstanceImmediate



public static int AddPrefabInstanceImmediate(GPUIPrefabManager prefabManager, GPUIPrefab gpuiPrefab, int prototypeIndex = -1)

Parameters
prefabManager
gpuiPrefab
prototypeIndex


Description:

Immediately adds the prefab instance to the Prefab Manager without waiting for LateUpdate.



RemovePrefabInstance



public static void RemovePrefabInstance(GPUIPrefab gpuiPrefab)

Parameters
gpuiPrefab


Description:

Removes the prefab instance from the Prefab Manager.



UpdateTransformData



public static void UpdateTransformData(GPUIPrefabManager prefabManager)

Parameters
prefabManager


Description:

Notifies the Prefab Manager to update the transform data buffers.



UpdateTransformData



public static void UpdateTransformData(GPUIPrefabManager prefabManager, GPUIPrefab gpuiPrefab)

Parameters
prefabManager
gpuiPrefab


Description:

Updates the Matrix4x4 data for the given prefab instance.



GPUInstancerPro.TerrainModule.GPUITerrainAPI


AddTerrains<T>



public static void AddTerrains<T>(GPUITerrainManager<T> terrainManager, IEnumerable<Terrain> terrains) where T : GPUIPrototypeData, new()

Parameters
terrainManager The Tree or Detail Manager to which the terrain will be added
terrains Collection of terrains to add to the manager


Description:

Adds the given terrain collection to the Detail or Tree Manager.



AddTerrains<T>



public static void AddTerrains<T>(GPUITerrainManager<T> terrainManager, IEnumerable<GPUITerrain> gpuiTerrains) where T : GPUIPrototypeData, new()

Parameters
terrainManager The Tree or Detail Manager to which the terrain will be added
gpuiTerrains Collection of GPUI terrains to add to the manager


Description:

Adds the given terrain collection to the Detail or Tree Manager.



AddTerrain<T>



public static bool AddTerrain<T>(GPUITerrainManager<T> terrainManager, Terrain terrain) where T : GPUIPrototypeData, new()

Parameters
terrainManager The Tree or Detail Manager to which the terrain will be added
terrain Terrain to add to the manager


Description:

Adds the given terrain to the Detail or Tree Manager.



AddTerrain<T>



public static bool AddTerrain<T>(GPUITerrainManager<T> terrainManager, GPUITerrain gpuiTerrain) where T : GPUIPrototypeData, new()

Parameters
terrainManager The Tree or Detail Manager to which the terrain will be added
gpuiTerrain GPUI terrain to add to the manager


Description:

Adds the given terrain to the Detail or Tree Manager.



RemoveTerrain<T>



public static bool RemoveTerrain<T>(GPUITerrainManager<T> terrainManager, Terrain terrain) where T : GPUIPrototypeData, new()

Parameters
terrainManager The Tree or Detail Manager from which the terrain will be removed
terrain Terrain to remove from the manager


Description:

Removes the given terrain from the Detail or Tree Manager.



RemoveTerrain<T>



public static bool RemoveTerrain<T>(GPUITerrainManager<T> terrainManager, GPUITerrain gpuiTerrain) where T : GPUIPrototypeData, new()

Parameters
terrainManager The Tree or Detail Manager from which the terrain will be removed
gpuiTerrain GPUI terrain to remove from the manager


Description:

Removes the given terrain from the Detail or Tree Manager.