private void Start()
        {
            // Create a GameObject to create a prototype from
            prototypeGameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);

            // Set material of the GameObject
            SetMaterial();

            // Create a list to keep track of instances
            instanceList = new List <GameObject>();

            // Add the original to the instanceList
            instanceList.Add(prototypeGameObject);

            // Your instantiation logic. Uses the prototype GameObject to identify the newly generated prototype.
            // This example just instantiates objects at random positions inside a sphere with radius of 20;
            // Replace this with how you want to generate your instances.
            for (int i = 0; i < 1000; i++)
            {
                instanceList.Add(Instantiate(prototypeGameObject, UnityEngine.Random.insideUnitSphere * 20, Quaternion.identity));
            }

            // Define the prototype
            prototype = GPUInstancerAPI.DefineGameObjectAsPrefabPrototypeAtRuntime(prefabManager, prototypeGameObject);

            // Make changes in the prototype settings
            prototype.enableRuntimeModifications = true;
            prototype.autoUpdateTransformData    = true;

            // Add the prototype instances
            GPUInstancerAPI.AddInstancesToPrefabPrototypeAtRuntime(prefabManager, prototype, instanceList);

            // Start Coroutine to change instances over time
            StartCoroutine(AddRemoveAtRuntime());
        }
Exemplo n.º 2
0
 public static void CheckPrefabRigidbodies(GPUInstancerPrefabPrototype prototype)
 {
     if (prototype.prefabObject != null && !prototype.meshRenderersDisabled)
     {
         EditorGUI.BeginChangeCheck();
         Rigidbody rigidbody = prototype.prefabObject.GetComponent <Rigidbody>();
         if (rigidbody != null)
         {
             prototype.hasRigidBody = true;
             if (prototype.rigidbodyData == null)
             {
                 prototype.rigidbodyData = new GPUInstancerPrefabPrototype.RigidbodyData();
             }
             prototype.rigidbodyData.useGravity    = rigidbody.useGravity;
             prototype.rigidbodyData.angularDrag   = rigidbody.angularDrag;
             prototype.rigidbodyData.mass          = rigidbody.mass;
             prototype.rigidbodyData.constraints   = rigidbody.constraints;
             prototype.rigidbodyData.drag          = rigidbody.drag;
             prototype.rigidbodyData.isKinematic   = rigidbody.isKinematic;
             prototype.rigidbodyData.interpolation = rigidbody.interpolation;
         }
         else
         {
             prototype.hasRigidBody = false;
         }
         if (EditorGUI.EndChangeCheck())
         {
             EditorUtility.SetDirty(prototype);
         }
     }
 }
Exemplo n.º 3
0
        public override void DrawGPUInstancerPrototypeAdvancedActions()
        {
            if (Application.isPlaying)
            {
                return;
            }

            GUILayout.Space(10);

            EditorGUILayout.BeginVertical();
            // title
            Rect foldoutRect = GUILayoutUtility.GetRect(0, 20, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));

            foldoutRect.x  += 12;
            showAdvancedBox = EditorGUI.Foldout(foldoutRect, showAdvancedBox, GPUInstancerEditorConstants.TEXT_advancedActions, true, GPUInstancerEditorConstants.Styles.foldout);

            //GUILayout.Space(10);

            if (showAdvancedBox)
            {
                EditorGUILayout.HelpBox(GPUInstancerEditorConstants.HELPTEXT_advancedActions, MessageType.Warning);

                GPUInstancerPrefabPrototype prefabPrototype = (GPUInstancerPrefabPrototype)_prefabManager.selectedPrototype;

                if (prefabPrototype != null)
                {
                    if (prefabPrototype.meshRenderersDisabled)
                    {
                        GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.enableMeshRenderers, GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                                      () =>
                        {
                            GPUInstancerPrefabManagerEditor.SetRenderersEnabled(prefabPrototype, true);
                        });
                    }
                    else
                    {
                        GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.disableMeshRenderers, GPUInstancerEditorConstants.Colors.lightBlue, Color.white, FontStyle.Bold, Rect.zero,
                                                                      () =>
                        {
                            if (EditorUtility.DisplayDialog(GPUInstancerEditorConstants.TEXT_disableMeshRenderers, GPUInstancerEditorConstants.TEXT_disableMeshRenderersAreYouSure, "Yes", "No"))
                            {
                                GPUInstancerPrefabManagerEditor.SetRenderersEnabled(prefabPrototype, false);
                            }
                        });
                    }
                    DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_disableMeshRenderers);
                }
            }

            EditorGUILayout.EndVertical();
        }
        IEnumerator AddRemoveAtRuntime()
        {
            while (true)
            {
                // Loop through primitives
                foreach (PrimitiveType primitiveType in Enum.GetValues(typeof(PrimitiveType)))
                {
                    yield return(new WaitForSeconds(3));

                    // Remove runtime generated prototype definition
                    GPUInstancerAPI.RemovePrototypeAtRuntime(prefabManager, prototype);
                    // Clear the instances
                    ClearInstances();

                    yield return(new WaitForSeconds(1));

                    // Create a GameObject to create a prototype from
                    prototypeGameObject = GameObject.CreatePrimitive(primitiveType);

                    // Set material of the GameObject
                    SetMaterial();

                    // Add the original to the instanceList
                    instanceList.Add(prototypeGameObject);

                    // Define the prototype
                    prototype = GPUInstancerAPI.DefineGameObjectAsPrefabPrototypeAtRuntime(prefabManager, prototypeGameObject);

                    // Create 1000 new instances
                    for (int i = 0; i < 1000; i++)
                    {
                        instanceList.Add(Instantiate(prototypeGameObject, UnityEngine.Random.insideUnitSphere * 20, Quaternion.identity));
                    }

                    // Add instances to manager
                    GPUInstancerAPI.AddInstancesToPrefabPrototypeAtRuntime(prefabManager, prototype, instanceList);

                    yield return(new WaitForSeconds(1));
                }
            }
        }
Exemplo n.º 5
0
        public static void SetRenderersEnabled(GPUInstancerPrefabPrototype prefabPrototype, bool enabled)
        {
#if UNITY_2018_3_OR_NEWER
            GameObject prefabContents = GPUInstancerUtility.LoadPrefabContents(prefabPrototype.prefabObject);
#else
            GameObject prefabContents = prefabPrototype.prefabObject;
#endif
            MeshRenderer[] meshRenderers = prefabContents.GetComponentsInChildren <MeshRenderer>(true);
            if (meshRenderers != null && meshRenderers.Length > 0)
            {
                for (int mr = 0; mr < meshRenderers.Length; mr++)
                {
                    meshRenderers[mr].enabled = enabled;
                }
            }

            BillboardRenderer[] billboardRenderers = prefabContents.GetComponentsInChildren <BillboardRenderer>(true);
            if (billboardRenderers != null && billboardRenderers.Length > 0)
            {
                for (int mr = 0; mr < billboardRenderers.Length; mr++)
                {
                    billboardRenderers[mr].enabled = enabled;
                }
            }

            LODGroup lodGroup = prefabContents.GetComponent <LODGroup>();
            if (lodGroup != null)
            {
                lodGroup.enabled = enabled;
            }

            if (prefabPrototype.hasRigidBody)
            {
                Rigidbody rigidbody = prefabContents.GetComponent <Rigidbody>();

                if (enabled || prefabPrototype.autoUpdateTransformData)
                {
                    if (rigidbody == null)
                    {
                        GPUInstancerPrefabPrototype.RigidbodyData rigidbodyData = prefabPrototype.rigidbodyData;
                        if (rigidbodyData != null)
                        {
                            rigidbody                  = prefabPrototype.prefabObject.AddComponent <Rigidbody>();
                            rigidbody.useGravity       = rigidbodyData.useGravity;
                            rigidbody.angularDrag      = rigidbodyData.angularDrag;
                            rigidbody.mass             = rigidbodyData.mass;
                            rigidbody.constraints      = rigidbodyData.constraints;
                            rigidbody.detectCollisions = true;
                            rigidbody.drag             = rigidbodyData.drag;
                            rigidbody.isKinematic      = rigidbodyData.isKinematic;
                            rigidbody.interpolation    = rigidbodyData.interpolation;
                        }
                    }
                }
                else if (rigidbody != null && !prefabPrototype.autoUpdateTransformData)
                {
                    DestroyImmediate(rigidbody, true);
                }
            }

#if UNITY_2018_3_OR_NEWER
            GPUInstancerUtility.UnloadPrefabContents(prefabPrototype.prefabObject, prefabContents, true);
#endif
            EditorUtility.SetDirty(prefabPrototype.prefabObject);
            prefabPrototype.meshRenderersDisabled = !enabled;
            EditorUtility.SetDirty(prefabPrototype);
        }
Exemplo n.º 6
0
 /// <summary>
 ///     <para>Specifies a variation buffer for a GPU Instancer prototype that is defined in the prefab's shader. Required to use <see cref="AddVariation{T}"/></para>
 ///     <prara>Use this if you want any type of variation between this prototype's instances.</prara>
 ///     <para>To define the buffer necessary for this variation in your shader, you need to create a StructuredBuffer field of the relevant type in that shader.
 ///     You can then access this buffer with "gpuiTransformationMatrix[unity_InstanceID]"</para>
 ///     <para>see <seealso cref="ColorVariations"/> and its demo scene for an example</para>
 /// </summary>
 ///
 /// <example>
 ///     This sample shows how to use the variation buffer in your shader:
 ///
 ///     <code><![CDATA[
 ///     ...
 ///     fixed4 _Color;
 ///
 ///     #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
 ///         StructuredBuffer<float4> colorBuffer;
 ///     #endif
 ///     ...
 ///     void surf (Input IN, inout SurfaceOutputStandard o) {
 ///     ...
 ///         #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
 ///             uint index = gpuiTransformationMatrix[unity_InstanceID];
 ///             col = colorBuffer[index];
 ///         #else
 ///             col = _Color;
 ///         #endif
 ///     ...
 ///     }
 ///     ]]></code>
 ///
 ///     See "GPUInstancer/ColorVariationShader" for the full example.
 ///
 /// </example>
 ///
 /// <typeparam name="T">The type of variation buffer. Must be defined in the instance prototype's shader</typeparam>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prototype">The GPU Instancer prototype to define variations.</param>
 /// <param name="bufferName">The name of the variation buffer in the prototype's shader.</param>
 public static void DefinePrototypeVariationBuffer <T>(GPUInstancerPrefabManager manager, GPUInstancerPrefabPrototype prototype, string bufferName)
 {
     manager.DefinePrototypeVariationBuffer <T>(prototype, bufferName);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Use this method to add new instances to prototype when you do not use prefabs (Ex: when you create a prototype with DefineGameObjectAsPrefabPrototypeAtRuntime API method)
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prefabPrototype">GPUI Prefab Prototype</param>
 /// <param name="instances">List of GameObjects to register on the manager</param>
 public static void AddInstancesToPrefabPrototypeAtRuntime(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prefabPrototype, IEnumerable <GameObject> instances)
 {
     prefabManager.AddInstancesToPrefabPrototypeAtRuntime(prefabPrototype, instances);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Use this method to remove a prototype definition at runtime
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prefabPrototype">GPUI Prefab Prototype ro remove from the manager</param>
 public static void RemovePrototypeAtRuntime(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prefabPrototype)
 {
     prefabManager.RemovePrototypeAtRuntime(prefabPrototype);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Use this method to update transform data of all prefab instances with a Matrix4x4 array. By default all the data from the array will be
 /// uploaded to the GPU. You can make partial uploads by setting the arrayStartIndex, bufferStartIndex, and count parameters.
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prototype">GPUI Prefab Prototype</param>
 /// <param name="matrix4x4Array">Array of Matrix4x4 that store the transform data of prefab instances</param>
 /// <param name="arrayStartIndex">Start index of the given array that the data will be uploaded to the buffer</param>
 /// <param name="bufferStartIndex">Start index of the buffer to set the data from the array</param>
 /// <param name="count">Total number of matrices to set to the buffer from the array</param>
 public static void UpdateVisibilityBufferWithMatrix4x4Array(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prototype, Matrix4x4[] matrix4x4Array,
                                                             int arrayStartIndex = 0, int bufferStartIndex = 0, int count = 0)
 {
     GPUInstancerUtility.UpdateVisibilityBufferWithMatrix4x4Array(prefabManager, prototype, matrix4x4Array, arrayStartIndex, bufferStartIndex, count);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initialize single prefab prototype for preparing runtime data and buffers for instanced rendering
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prefabPrototype">GPUI Prefab Prototype</param>
 /// <returns></returns>
 public static GPUInstancerRuntimeData InitializeGPUInstancer(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prototype)
 {
     // initialize PrefabManager if it is not already initialized
     prefabManager.InitializeRuntimeDataAndBuffers(false);
     // generate and return prototype runtime data
     return(prefabManager.InitializeRuntimeDataForPrefabPrototype(prototype));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Updates the variation values for the given array for the specified prototype and buffer.
 /// </summary>
 /// <typeparam name="T">The type of variation buffer. Must be defined in the instance prototype's shader</typeparam>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prototype">The GPU Instancer prototype to define variations.</param>
 /// <param name="bufferName">The name of the variation buffer in the prototype's shader.</param>
 /// <param name="variationArray">The array that stores the variation information.</param>
 /// <param name="arrayStartIndex">Start index of the given array that the data will be uploaded to the buffer</param>
 /// <param name="bufferStartIndex">Start index of the buffer to set the data from the array</param>
 /// <param name="count">Total number of variation data to set to the buffer from the array</param>
 public static void UpdateVariationFromArray <T>(GPUInstancerPrefabManager manager, GPUInstancerPrefabPrototype prototype, string bufferName, T[] variationArray,
                                                 int arrayStartIndex = 0, int bufferStartIndex = 0, int count = 0)
 {
     manager.UpdateVariationsFromArray <T>(prototype, bufferName, variationArray, arrayStartIndex, bufferStartIndex, count);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Use this method to create prefab instances with the given transform information without creating GameObjects.
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prototype">GPUI Prefab Prototype</param>
 /// <param name="matrix4x4Array">Array of Matrix4x4 that store the transform data of prefab instances</param>
 public static void InitializeWithMatrix4x4Array(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prototype, Matrix4x4[] matrix4x4Array)
 {
     GPUInstancerUtility.InitializeWithMatrix4x4Array(prefabManager, prototype, matrix4x4Array);
 }
Exemplo n.º 13
0
        public static void DrawGPUInstancerPrototypeInfo(GPUInstancerPrototype selectedPrototype, UnityAction <string> DrawHelpText)
        {
            EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box);
            GPUInstancerEditorConstants.DrawCustomLabel(GPUInstancerEditorConstants.TEXT_prefabRuntimeSettings, GPUInstancerEditorConstants.Styles.boldLabel);

            GPUInstancerPrefabPrototype prototype = (GPUInstancerPrefabPrototype)selectedPrototype;

            prototype.enableRuntimeModifications = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_enableRuntimeModifications, prototype.enableRuntimeModifications);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_enableRuntimeModifications);

            EditorGUI.BeginDisabledGroup(!prototype.enableRuntimeModifications);

            EditorGUI.BeginDisabledGroup(!prototype.hasRigidBody || prototype.autoUpdateTransformData);
            prototype.startWithRigidBody = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_startWithRigidBody, prototype.startWithRigidBody);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_startWithRigidBody);
            EditorGUI.EndDisabledGroup();

            prototype.addRemoveInstancesAtRuntime = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_addRemoveInstancesAtRuntime, prototype.addRemoveInstancesAtRuntime);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_addRemoveInstancesAtRuntime);

            EditorGUI.BeginDisabledGroup(!prototype.addRemoveInstancesAtRuntime);
            prototype.extraBufferSize = EditorGUILayout.IntSlider(GPUInstancerEditorConstants.TEXT_extraBufferSize, prototype.extraBufferSize, 0, GPUInstancerConstants.PREFAB_EXTRA_BUFFER_SIZE);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_extraBufferSize);

            prototype.addRuntimeHandlerScript = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_addRuntimeHandlerScript, prototype.addRuntimeHandlerScript);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_addRuntimeHandlerScript);

            if (prototype.addRemoveInstancesAtRuntime && !Application.isPlaying)
            {
                GPUInstancerPrefabRuntimeHandler prefabRuntimeHandler = prototype.prefabObject.GetComponent <GPUInstancerPrefabRuntimeHandler>();
                if (prototype.addRuntimeHandlerScript && prefabRuntimeHandler == null)
                {
#if UNITY_2018_3_OR_NEWER
                    GPUInstancerUtility.AddComponentToPrefab <GPUInstancerPrefabRuntimeHandler>(prototype.prefabObject);
#else
                    prototype.prefabObject.AddComponent <GPUInstancerPrefabRuntimeHandler>();
#endif
                    EditorUtility.SetDirty(prototype.prefabObject);
                }
                else if (!prototype.addRuntimeHandlerScript && prefabRuntimeHandler != null)
                {
#if UNITY_2018_3_OR_NEWER
                    GPUInstancerUtility.RemoveComponentFromPrefab <GPUInstancerPrefabRuntimeHandler>(prototype.prefabObject);
#else
                    DestroyImmediate(prefabRuntimeHandler, true);
#endif
                    EditorUtility.SetDirty(prototype.prefabObject);
                }
            }
            EditorGUI.EndDisabledGroup();

            bool autoUpdateTransformData = prototype.autoUpdateTransformData;
            prototype.autoUpdateTransformData = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_autoUpdateTransformData, prototype.autoUpdateTransformData);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_autoUpdateTransformData);
            if (autoUpdateTransformData != prototype.autoUpdateTransformData && prototype.meshRenderersDisabled)
            {
                SetRenderersEnabled(prototype, !prototype.meshRenderersDisabled);
            }
            EditorGUI.EndDisabledGroup();

            if (!prototype.enableRuntimeModifications)
            {
                if (prototype.addRemoveInstancesAtRuntime)
                {
                    prototype.addRemoveInstancesAtRuntime = false;
                }
                if (prototype.startWithRigidBody)
                {
                    prototype.startWithRigidBody = false;
                }
                if (prototype.autoUpdateTransformData)
                {
                    prototype.autoUpdateTransformData = false;
                    if (prototype.meshRenderersDisabled)
                    {
                        SetRenderersEnabled(prototype, !prototype.meshRenderersDisabled);
                    }
                }
            }

            if ((!prototype.enableRuntimeModifications || !prototype.addRemoveInstancesAtRuntime) && prototype.extraBufferSize > 0)
            {
                prototype.extraBufferSize = 0;
            }

            if ((!prototype.enableRuntimeModifications || !prototype.addRemoveInstancesAtRuntime) && prototype.addRuntimeHandlerScript)
            {
                prototype.addRuntimeHandlerScript = false;
                GPUInstancerPrefabRuntimeHandler prefabRuntimeHandler = prototype.prefabObject.GetComponent <GPUInstancerPrefabRuntimeHandler>();
                if (prefabRuntimeHandler != null)
                {
#if UNITY_2018_3_OR_NEWER
                    GPUInstancerUtility.RemoveComponentFromPrefab <GPUInstancerPrefabRuntimeHandler>(prototype.prefabObject);
#else
                    DestroyImmediate(prefabRuntimeHandler, true);
#endif
                    EditorUtility.SetDirty(prototype.prefabObject);
                }
            }

            EditorGUILayout.EndVertical();
        }
Exemplo n.º 14
0
 /// <summary>
 /// Specifies a variation buffer for a GPU Instancer prototype that is defined in the prefab's shader. And sets the variation values for the given array.
 /// </summary>
 /// <typeparam name="T">The type of variation buffer. Must be defined in the instance prototype's shader</typeparam>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prototype">The GPU Instancer prototype to define variations.</param>
 /// <param name="bufferName">The name of the variation buffer in the prototype's shader.</param>
 /// <param name="variationArray">The array that stores the variation information.</param>
 public static void DefineAndAddVariationFromArray <T>(GPUInstancerPrefabManager manager, GPUInstancerPrefabPrototype prototype, string bufferName, T[] variationArray)
 {
     manager.DefineAndAddVariationFromArray <T>(prototype, bufferName, variationArray);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Use this method to update transform data of all prefab instances with a Matrix4x4 array
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prototype">GPUI Prefab Prototype</param>
 /// <param name="matrix4x4Array">Array of Matrix4x4 that store the transform data of prefab instances</param>
 public static void UpdateVisibilityBufferWithMatrix4x4Array(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prototype, Matrix4x4[] matrix4x4Array)
 {
     GPUInstancerUtility.UpdateVisibilityBufferWithMatrix4x4Array(prefabManager, prototype, matrix4x4Array);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Updates the variation values for the given array for the specified prototype and buffer.
 /// </summary>
 /// <typeparam name="T">The type of variation buffer. Must be defined in the instance prototype's shader</typeparam>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prototype">The GPU Instancer prototype to define variations.</param>
 /// <param name="bufferName">The name of the variation buffer in the prototype's shader.</param>
 /// <param name="variationArray">The array that stores the variation information.</param>
 public static void UpdateVariationFromArray <T>(GPUInstancerPrefabManager manager, GPUInstancerPrefabPrototype prototype, string bufferName, T[] variationArray)
 {
     manager.UpdateVariationsFromArray <T>(prototype, bufferName, variationArray);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Use this method to update transform data of all prefab instances with a float4x4 native array. By default all the data from the array will be
 /// uploaded to the GPU. You can make partial uploads by setting the arrayStartIndex, bufferStartIndex, and count parameters.
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prototype">GPUI Prefab Prototype</param>
 /// <param name="float4x4Array">Array of float4x4 that store the transform data of prefab instances. Struct reference is not forced so you can use any float4x4 struct (e.g. Matrix4x4 or float4x4 from Mathematics package)</param>
 /// <param name="arrayStartIndex">(Optional) Start index of the given array that the data will be uploaded to the buffer</param>
 /// <param name="bufferStartIndex">(Optional) Start index of the buffer to set the data from the array</param>
 /// <param name="count">(Optional) Total number of matrices to set to the buffer from the array</param>
 public static void UpdateVisibilityBufferWithNativeArray <T>(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prototype, NativeArray <T> float4x4Array,
                                                              int arrayStartIndex = 0, int bufferStartIndex = 0, int count = 0) where T : struct
 {
     GPUInstancerUtility.UpdateVisibilityBufferWithNativeArray(prefabManager, prototype, float4x4Array, arrayStartIndex, bufferStartIndex, count);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Use this method to initialize buffers for the given prototype and set the buffer data later with UpdateVisibilityBuffer API methods. Please note that you will
 /// need to provide a positive integer buffer size to initialize the buffers successfully.
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype is defined on</param>
 /// <param name="prototype">GPUI Prefab Prototype</param>
 /// <param name="bufferSize">Size of the buffer to allocate in GPU memory</param>
 /// <param name="instanceCount">(Optional) Initial instance count to render. Can also be set later with SetInstanceCount API method</param>
 public static void InitializePrototype(GPUInstancerPrefabManager prefabManager, GPUInstancerPrefabPrototype prototype, int bufferSize, int instanceCount = 0)
 {
     GPUInstancerUtility.InitializePrototype(prefabManager, prototype, bufferSize, instanceCount);
 }
Exemplo n.º 19
0
 /// <summary>
 /// Specifies a variation buffer for a GPU Instancer prototype that is defined in the prefab's shader. And sets the variation values for the given array.
 /// </summary>
 /// <typeparam name="T">The type of variation buffer. Must be defined in the instance prototype's shader</typeparam>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prototype">The GPU Instancer prototype to define variations.</param>
 /// <param name="bufferName">The name of the variation buffer in the prototype's shader.</param>
 /// <param name="variationArray">The array that stores the variation information.</param>
 public static PrefabVariationData <T> DefineAndAddVariationFromArray <T>(GPUInstancerPrefabManager manager, GPUInstancerPrefabPrototype prototype, string bufferName, T[] variationArray)
 {
     return(manager.DefineAndAddVariationFromArray <T>(prototype, bufferName, variationArray));
 }