public override void OnInspectorGUI()
        {
            serializedObject.Update();

            base.OnInspectorGUI();

            if (_treeManager.terrain == null)
            {
                if (!Application.isPlaying && Event.current.type == EventType.ExecuteCommand && pickerControlID > 0 && Event.current.commandName == "ObjectSelectorClosed")
                {
                    if (EditorGUIUtility.GetObjectPickerControlID() == pickerControlID)
                    {
                        AddTerrainPickerObject(EditorGUIUtility.GetObjectPickerObject());
                    }
                    pickerControlID = -1;
                }

                EditorGUI.BeginDisabledGroup(Application.isPlaying);
                DrawTreeTerrainAddButton();
                EditorGUI.EndDisabledGroup();
                return;
            }
            else if (_treeManager.terrainSettings == null)
            {
                _treeManager.SetupManagerWithTerrain(_treeManager.terrain);
            }

            DrawSceneSettingsBox();

            if (_treeManager.terrainSettings != null)
            {
                DrawGlobalValuesBox();

                if (Application.isPlaying)
                {
                    DrawRegisteredPrefabsBox();
                }

                DrawGPUInstancerPrototypesBox();
            }

            HandlePickerObjectSelection();

            serializedObject.ApplyModifiedProperties();

            base.InspectorGUIEnd();
        }
Exemple #2
0
        private void MapMagicTerrainAddTreeManager(Terrain terrain)
        {
            if (terrain.GetComponent <GPUInstancerTreeManager>() == null && treePrototypes != null && treePrototypes.Count > 0)
            {
                GPUInstancerTreeManager newTreeManager = terrain.gameObject.AddComponent <GPUInstancerTreeManager>();
                newTreeManager.isFrustumCulling   = isFrustumCulling;
                newTreeManager.isOcclusionCulling = isOcclusionCulling;
                newTreeManager.minCullingDistance = minCullingDistance;
                newTreeManager.autoSelectCamera   = autoSelectCamera;
                newTreeManager.cameraData.SetCamera(cameraData.mainCamera);
                newTreeManager.cameraData.renderOnlySelectedCamera = cameraData.renderOnlySelectedCamera;
                newTreeManager.cameraData.hiZOcclusionGenerator    = null;
                newTreeManager.InitializeCameraData();
                // for mapmagic tree optimization
                if (terrain.terrainData.treePrototypes.Length != treePrototypes.Count)
                {
                    int terrainTreeIndex = 0;
                    List <GPUInstancerPrototype> newPrototypeList = new List <GPUInstancerPrototype>();
                    for (int i = 0; i < treePrototypes.Count; i++)
                    {
                        if (terrainTreeIndex >= terrain.terrainData.treePrototypes.Length)
                        {
                            break;
                        }

                        GPUInstancerTreePrototype tp = (GPUInstancerTreePrototype)treePrototypes[i];
                        if (!terrain.terrainData.treePrototypes[terrainTreeIndex].prefab == tp.prefabObject)
                        {
                            newPrototypeList.Add(tp);
                            terrainTreeIndex++;
                        }
                    }
                    newTreeManager.prototypeList = newPrototypeList;
                }
                else
                {
                    newTreeManager.prototypeList = treePrototypes;
                }
                newTreeManager.SetupManagerWithTerrain(terrain);

                newTreeManager.terrainSettings.maxTreeDistance = terrainSettings.maxTreeDistance;

                if (terrain.gameObject.activeSelf)
                {
                    newTreeManager.InitializeRuntimeDataAndBuffers();
                }
            }
        }