Example #1
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));
 }
Example #2
0
        private void MapMagicTerrainAddPrefabManagerSingleton(Terrain terrain)
        {
            if (prefabPrototypes != null && prefabPrototypes.Count > 0)
            {
                if (prefabManagerInstance == null)
                {
                    GameObject prefabManagerInstanceGO = new GameObject("GPUI Prefab Manager");
                    prefabManagerInstance = prefabManagerInstanceGO.AddComponent <GPUInstancerPrefabManager>();
                    prefabManagerInstance.isFrustumCulling   = isFrustumCulling;
                    prefabManagerInstance.isOcclusionCulling = isOcclusionCulling;
                    prefabManagerInstance.minCullingDistance = minCullingDistance;
                    prefabManagerInstance.autoSelectCamera   = autoSelectCamera;
                    prefabManagerInstance.cameraData.SetCamera(cameraData.mainCamera);
                    prefabManagerInstance.cameraData.renderOnlySelectedCamera = cameraData.renderOnlySelectedCamera;
                    prefabManagerInstance.cameraData.hiZOcclusionGenerator    = null;
                    prefabManagerInstance.InitializeCameraData();
                    prefabManagerInstance.enableMROnRemoveInstance = false;
                    prefabManagerInstance.enableMROnManagerDisable = false;

                    prefabManagerInstance.prototypeList = prefabPrototypes;
                    prefabManagerInstance.InitializeRuntimeDataAndBuffers();
                }

                GPUInstancerPrefabListRuntimeHandler plrh = terrain.gameObject.GetComponent <GPUInstancerPrefabListRuntimeHandler>();
                if (plrh == null)
                {
                    plrh = terrain.gameObject.AddComponent <GPUInstancerPrefabListRuntimeHandler>();
                }
                plrh.runInThreads = prefabRunInThreads;
                plrh.SetManager(prefabManagerInstance);
            }
        }
Example #3
0
        private void MapMagicTerrainAddPrefabManager(Terrain terrain)
        {
            if (terrain.GetComponent <GPUInstancerPrefabManager>() == null && prefabPrototypes != null && prefabPrototypes.Count > 0)
            {
                GPUInstancerPrefab[] prefabList = terrain.gameObject.GetComponentsInChildren <GPUInstancerPrefab>(true);
                if (prefabList.Length > 0)
                {
                    GPUInstancerPrefabManager newPrefabManager = terrain.gameObject.AddComponent <GPUInstancerPrefabManager>();
                    newPrefabManager.isFrustumCulling   = isFrustumCulling;
                    newPrefabManager.isOcclusionCulling = isOcclusionCulling;
                    newPrefabManager.minCullingDistance = minCullingDistance;
                    newPrefabManager.autoSelectCamera   = autoSelectCamera;
                    newPrefabManager.cameraData.SetCamera(cameraData.mainCamera);
                    newPrefabManager.cameraData.renderOnlySelectedCamera = cameraData.renderOnlySelectedCamera;
                    newPrefabManager.cameraData.hiZOcclusionGenerator    = null;
                    newPrefabManager.InitializeCameraData();
                    newPrefabManager.enableMROnManagerDisable = false;

                    newPrefabManager.prototypeList = prefabPrototypes;
                    newPrefabManager.RegisterPrefabInstanceList(prefabList);
                    if (terrain.gameObject.activeSelf)
                    {
                        newPrefabManager.InitializeRuntimeDataAndBuffers();
                    }
                }
            }
        }
        private GPUInstancerPrefabManager GetPrefabManager()
        {
            GPUInstancerPrefabManager prefabManager = null;

            if (GPUInstancerManager.activeManagerList != null)
            {
                if (!_managerDictionary.TryGetValue(gpuiPrefab.prefabPrototype, out prefabManager))
                {
                    prefabManager = (GPUInstancerPrefabManager)GPUInstancerManager.activeManagerList.Find(manager => manager.prototypeList.Contains(gpuiPrefab.prefabPrototype));
                    if (prefabManager == null)
                    {
                        Debug.LogWarning("Can not find GPUI Prefab Manager for prototype: " + gpuiPrefab.prefabPrototype);
                        return(null);
                    }
                    _managerDictionary.Add(gpuiPrefab.prefabPrototype, prefabManager);
                }
                if (prefabManager == null)
                {
                    prefabManager = (GPUInstancerPrefabManager)GPUInstancerManager.activeManagerList.Find(manager => manager.prototypeList.Contains(gpuiPrefab.prefabPrototype));
                    if (prefabManager == null)
                    {
                        return(null);
                    }
                    _managerDictionary[gpuiPrefab.prefabPrototype] = prefabManager;
                }
            }
            return(prefabManager);
        }
Example #5
0
        protected override void OnEnable()
        {
            base.OnEnable();

            wikiHash = "#The_Prefab_Manager";

            _prefabManager = (target as GPUInstancerPrefabManager);
        }
 private void Start()
 {
     if (gpuiPrefab.state == PrefabInstancingState.None)
     {
         GPUInstancerPrefabManager prefabManager = GetPrefabManager();
         if (prefabManager != null)
         {
             prefabManager.AddPrefabInstance(gpuiPrefab, true);
         }
     }
 }
 private void OnDisable()
 {
     if (gpuiPrefab.state == PrefabInstancingState.Instanced)
     {
         GPUInstancerPrefabManager prefabManager = GetPrefabManager();
         if (prefabManager != null)
         {
             prefabManager.RemovePrefabInstance(gpuiPrefab);
         }
     }
 }
Example #8
0
 public void SetManager(GPUInstancerPrefabManager prefabManager)
 {
     if (_isIntancesAdded)
     {
         OnDisable();
     }
     this.prefabManager = prefabManager;
     if (isActiveAndEnabled)
     {
         OnEnable();
     }
 }
 private void OnDisable()
 {
     if (gpuiPrefab.state == PrefabInstancingState.Instanced)
     {
         if (_prefabManager == null)
         {
             _prefabManager = GetPrefabManager();
         }
         if (_prefabManager != null && !_prefabManager.isQuiting)
         {
             _prefabManager.RemovePrefabInstance(gpuiPrefab, false);
         }
     }
 }
 private void OnEnable()
 {
     if (gpuiPrefab.state == PrefabInstancingState.None)
     {
         if (_prefabManager == null)
         {
             _prefabManager = GetPrefabManager();
         }
         if (_prefabManager != null)
         {
             if (!_prefabManager.isInitialized)
             {
                 _prefabManager.InitializeRuntimeDataAndBuffers();
             }
             _prefabManager.AddPrefabInstance(gpuiPrefab, true);
         }
     }
 }
Example #11
0
    void Start()
    {
        _spawnArray     = new Matrix4x4[spawnCount];
        _variationArray = new Vector4[spawnCount];
        for (var i = 0; i < spawnCount; i++)
        {
            Spawn(i);
        }

        _prefabManager = FindObjectOfType <GPUInstancerPrefabManager>();

        if (_prefabManager != null && _prefabManager.prototypeList.Count > 0)
        {
            GPUInstancerPrefabPrototype prototype = (GPUInstancerPrefabPrototype)_prefabManager.prototypeList[0];
            GPUInstancerAPI.InitializeWithMatrix4x4Array(_prefabManager, prototype, _spawnArray);
            GPUInstancerAPI.DefineAndAddVariationFromArray(_prefabManager, prototype, _variationBufferName, _variationArray);
            _transformDataBuffer = GPUInstancerAPI.GetTransformDataBuffer(_prefabManager, prototype);
        }
    }
        private void Awake()
        {
            _enteredInstances = new List <GPUInstancerPrefab>();
            _collider         = GetComponent <Collider>();

            if (prefabManager == null)
            {
                prefabManager = FindObjectOfType <GPUInstancerPrefabManager>();
            }

            if (prefabManager != null)
            {
                prefabManager.AddModificationCollider(this);
            }
            else
            {
                Debug.LogWarning("GPUInstancerModificationCollider does not have a GPUInstancerPrefabManager defined.");
            }
        }
Example #13
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);
 }
Example #14
0
 /// <summary>
 ///     <para>Updates the variation value for this prefab instance. The variation buffer for the prototype must be defined
 ///     with <see cref="DefinePrototypeVariationBuffer{T}"/> before using this.</para>
 /// </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="prefabInstance">The prefab instance to update the variation at.</param>
 /// <param name="bufferName">The name of the variation buffer in the prototype's shader.</param>
 /// <param name="value">The value of the variation.</param>
 public static void UpdateVariation <T>(GPUInstancerPrefabManager manager, GPUInstancerPrefab prefabInstance, string bufferName, T value)
 {
     prefabInstance.AddVariation(bufferName, value);
     manager.UpdateVariationData(prefabInstance, bufferName, value);
 }
Example #15
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);
 }
Example #16
0
 /// <summary>
 ///     <para>Updates and synchronizes the GPU Instancer transform data (position, rotation and scale) for the given prefab instance.</para>
 ///     <para>Use this if you want to update, rotate, and/or scale prefab instances after initialization.</para>
 ///     <para>The updated values are taken directly from the transformation operations made beforehand on the instance's Unity transform component.
 ///     (These operations will not reflect on the GPU Instanced prefab automatically unless you use this method).</para>
 /// </summary>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prefabInstance">The prefab instance to update the transform values of. The instance's Unity transform component must be updated beforehand.</param>
 public static void UpdateTransformDataForInstance(GPUInstancerPrefabManager manager, GPUInstancerPrefab prefabInstance)
 {
     manager.UpdateTransformDataForInstance(prefabInstance);
 }
Example #17
0
 /// <summary>
 ///     <para>Enables GPU instancing and disables Unity renderers for the given prefab instance without re-adding it to the list of registerd prefabs.</para>
 ///     <para>Use this if you want to unpause GPU Instancing for a prefab.</para>
 ///     <para>Note that the prefab must be enabled for runtime modifications in the manager in order for this to work (for performance reasons).</para>
 ///     <para>Also note that you can also add <seealso cref="GPUInstancerModificationCollider"/> to a game object to use its collider to automatically
 ///     enable/disable instancing when a prefab instance enters/exits its collider.</para>
 /// </summary>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prefabInstance">The prefab instance to enable the GPU Instancing of.</param>
 /// <param name="disableMeshRenderers">If set to false Mesh Renderer components will not be disabled after enabling instancing. Should be used only for instances
 /// that have already disabled mesh renderers to speed up the process.</param>
 public static void EnableInstancingForInstance(GPUInstancerPrefabManager manager, GPUInstancerPrefab prefabInstance, bool setRenderersDisabled = true)
 {
     manager.EnableInstancingForInstance(prefabInstance, setRenderersDisabled);
 }
Example #18
0
 /// <summary>
 ///     <para>Removes a prefab instance from an already initialized list of registered instances. </para>
 ///     <para>Use this if you want to remove a prefab instance after you have initialized a list of prefabs with <see cref="InitializeGPUInstancer"/>
 ///     (usually before destroying the GameObject).</para>
 ///     <para>The prefab of this instance must be previously defined in the given manager (either at runtime or editor time).</para>
 ///     <para>Note that the prefab must be enabled for adding and removal in the manager in order for this to work (for performance reasons).</para>
 /// </summary>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prefabInstance">The prefab instance to remove.</param>
 /// <param name="setRenderersEnabled">If set to false Mesh Renderer components will not be enabled after removing prefab instance which will make the
 /// instance invisible.</param>
 public static void RemovePrefabInstance(GPUInstancerPrefabManager manager, GPUInstancerPrefab prefabInstance, bool setRenderersEnabled = true)
 {
     manager.RemovePrefabInstance(prefabInstance, setRenderersEnabled);
 }
Example #19
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);
 }
Example #20
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);
 }
Example #21
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);
 }
Example #22
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);
 }
Example #23
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);
 }
Example #24
0
 /// <summary>
 ///     <para>Unregisters a list of prefab instances from GPU Instancer. You must use <see cref="InitializeGPUInstancer"/> after unregistering these prefabs for final initialization.</para>
 ///     <para>The prefabs of the instances in this list must be previously defined in the given manager (either at runtime or editor time).</para>
 /// </summary>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prefabInstanceList">The list of prefabs instances to be removed from  GPU instancer.</param>
 public static void UnregisterPrefabInstanceList(GPUInstancerPrefabManager manager, IEnumerable <GPUInstancerPrefab> prefabInstanceList)
 {
     manager.UnregisterPrefabInstanceList(prefabInstanceList);
 }
Example #25
0
 /// <summary>
 /// Use this method to define Prefab Prototypes at runtime for procedurally generated GameObjects
 /// </summary>
 /// <param name="prefabManager">The GPUI Prefab Manager that the prefab prototype will be defined on</param>
 /// <param name="prototypeGameObject">GameObject to use as reference for the prototype</param>
 /// <returns></returns>
 public static GPUInstancerPrefabPrototype DefineGameObjectAsPrefabPrototypeAtRuntime(GPUInstancerPrefabManager prefabManager, GameObject prototypeGameObject)
 {
     return(prefabManager.DefineGameObjectAsPrefabPrototypeAtRuntime(prototypeGameObject));
 }
Example #26
0
 /// <summary>
 ///     <para>Clears the registered prefab instances from the prefab manager.</para>
 /// </summary>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 public static void ClearRegisteredPrefabInstances(GPUInstancerPrefabManager manager)
 {
     manager.ClearRegisteredPrefabInstances();
 }
Example #27
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);
 }
Example #28
0
 /// <summary>
 ///     <para>Clears the registered prefab instances from the prefab manager for a specific prototype.</para>
 /// </summary>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prototype">The prototype to clear registered instances for.</param>
 public static void ClearRegisteredPrefabInstances(GPUInstancerPrefabManager manager, GPUInstancerPrototype prototype)
 {
     manager.ClearRegisteredPrefabInstances(prototype);
 }
Example #29
0
        void OnGUI()
        {
            if (helpIcon == null)
            {
                helpIcon = Resources.Load <Texture2D>(GPUInstancerConstants.EDITOR_TEXTURES_PATH + GPUInstancerEditorConstants.HELP_ICON);
            }
            if (helpIconActive == null)
            {
                helpIconActive = Resources.Load <Texture2D>(GPUInstancerConstants.EDITOR_TEXTURES_PATH + GPUInstancerEditorConstants.HELP_ICON_ACTIVE);
            }

            if (prefabList == null || prefabList.Count == 0)
            {
                this.Close();
            }

            EditorGUILayout.BeginHorizontal(GPUInstancerEditorConstants.Styles.box);
            EditorGUILayout.LabelField(GPUInstancerEditorConstants.GPUI_VERSION, GPUInstancerEditorConstants.Styles.boldLabel);
            GUILayout.FlexibleSpace();
            GPUInstancerEditor.DrawWikiButton(GUILayoutUtility.GetRect(40, 20), "#Scene_Prefab_Importer");
            GUILayout.Space(10);
            DrawHelpButton(GUILayoutUtility.GetRect(20, 20), showHelpText);
            EditorGUILayout.EndHorizontal();

            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterIntro, true);

            EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box);
            GUILayout.Space(5);
            EditorGUILayout.BeginHorizontal();

            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.importSelectedPrefabs, GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                List <GameObject> selectedPrefabs = new List <GameObject>();
                for (int i = 0; i < prefabList.Count; i++)
                {
                    if (isEnabledArray[i])
                    {
                        selectedPrefabs.Add(prefabList[i]);
                    }
                }

                if (selectedPrefabs.Count > 0)
                {
                    GameObject go = new GameObject("GPUI Prefab Manager");
                    GPUInstancerPrefabManager prefabManager = go.AddComponent <GPUInstancerPrefabManager>();
                    selectedPrefabs.ForEach(p => prefabManager.AddPickerObject(p));
                    this.Close();
                    Selection.activeGameObject = go;
                }
                else
                {
                    EditorUtility.DisplayDialog(GPUInstancerEditorConstants.TEXT_info, GPUInstancerEditorConstants.TEXT_noPrefabInstanceSelected, GPUInstancerEditorConstants.TEXT_close);
                }
            });

            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.cancel, Color.red, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                this.Close();
            });

            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterImportCancel);
            GUILayout.Space(10);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Select All"))
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = true;
                }
            }
            if (GUILayout.Button("Select None"))
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = false;
                }
            }
            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterSelectAllNone);

            EditorGUILayout.BeginHorizontal();
            instanceCountToSelect = EditorGUILayout.IntSlider(instanceCountToSelect, 0, maxInstanceCount);
            if (GUILayout.Button("Select Min. Instance Count"))
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = instanceCountToSelect <= instanceCountArray[i];
                }
            }
            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterSelectOverCount);
            GUILayout.Space(5);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box);
            GUILayout.Space(5);
            GPUInstancerEditorConstants.DrawCustomLabel("Prefab Instances", GPUInstancerEditorConstants.Styles.boldLabel);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterInstanceList);
            GUILayout.Space(5);
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            EditorGUILayout.BeginVertical();
            if (prefabList != null)
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = EditorGUILayout.BeginToggleGroup(prefabList[i].name + " (Instance Count: " + instanceCountArray[i] + ")", isEnabledArray[i]);
                    EditorGUILayout.EndToggleGroup();
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();

            //GameObject go = new GameObject("GPUI Prefab Manager");
            //GPUInstancerPrefabManager prefabManager = go.AddComponent<GPUInstancerPrefabManager>();

            //Selection.activeGameObject = go;
        }
Example #30
0
 /// <summary>
 ///     <para>Adds a new prefab instance for GPU instancing to an already initialized list of registered instances. </para>
 ///     <para>Use this if you want to add another instance of a prefab after you have initialized a list of prefabs with <see cref="InitializeGPUInstancer"/>.</para>
 ///     <para>The prefab of this instance must be previously defined in the given manager (either at runtime or editor time).</para>
 ///     <para>Note that the prefab must be enabled for adding and removal in the manager in order for this to work (for performance reasons).</para>
 ///     <para>Also note that the number of total instances is limited by the count of already initialized instances plus the extra amount you define in the manager.</para>
 /// </summary>
 /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param>
 /// <param name="prefabInstance">The prefab instance to add.</param>
 public static void AddPrefabInstance(GPUInstancerPrefabManager manager, GPUInstancerPrefab prefabInstance)
 {
     manager.AddPrefabInstance(prefabInstance);
 }