Пример #1
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();
        }