コード例 #1
0
        public GPUInstancerTerrainProxy AddProxyToTerrain()
        {
#if UNITY_EDITOR
            if (terrain != null && gameObject != terrain.gameObject)
            {
                GPUInstancerTerrainProxy terrainProxy = terrain.GetComponent <GPUInstancerTerrainProxy>();
                if (terrainProxy == null)
                {
                    Undo.RecordObject(terrain.gameObject, "Added GPUInstancerTerrainProxy component");
                    terrainProxy = terrain.gameObject.AddComponent <GPUInstancerTerrainProxy>();
                }
                if (this is GPUInstancerDetailManager && terrainProxy.detailManager != this)
                {
                    terrainProxy.detailManager = (GPUInstancerDetailManager)this;
                }
                else if (this is GPUInstancerTreeManager && terrainProxy.treeManager != this)
                {
                    terrainProxy.treeManager = (GPUInstancerTreeManager)this;
                }
                while (UnityEditorInternal.ComponentUtility.MoveComponentUp(terrainProxy))
                {
                    ;
                }

                return(terrainProxy);
            }
#endif
            return(null);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            GPUInstancerTerrainProxy terrainProxy = (GPUInstancerTerrainProxy)target;

            if (terrainProxy.detailManager != null)
            {
                GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.goToGPUInstancerDetail, GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                              () =>
                {
                    if (terrainProxy.detailManager != null && terrainProxy.detailManager.gameObject != null)
                    {
                        Selection.activeGameObject = terrainProxy.detailManager.gameObject;
                    }
                });
            }
            if (terrainProxy.treeManager != null)
            {
                GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.goToGPUInstancerTree, GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                              () =>
                {
                    if (terrainProxy.treeManager != null && terrainProxy.treeManager.gameObject != null)
                    {
                        Selection.activeGameObject = terrainProxy.treeManager.gameObject;
                    }
                });
            }
            EditorGUILayout.HelpBox(GPUInstancerEditorConstants.HELPTEXT_terrainProxyWarning, MessageType.Warning);

            // select terrain tool
            if (terrainProxy.terrainSelectedToolIndex > 0)
            {
                try
                {
                    if (terrainInspectorType == null)
                    {
                        terrainInspectorType = Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.TerrainInspector");
                    }
                    PropertyInfo selectedTool = terrainInspectorType.GetProperty("selectedTool", BindingFlags.NonPublic | BindingFlags.Instance);

                    UnityEngine.Object[] terrainInspectors = Resources.FindObjectsOfTypeAll(terrainInspectorType);
                    foreach (UnityEngine.Object terrainInspector in terrainInspectors)
                    {
                        //Debug.Log(selectedTool.GetValue(terrainInspector, new object[0]));
                        selectedTool.SetValue(terrainInspector, terrainProxy.terrainSelectedToolIndex, new object[0]);
                        break;
                    }
                }
                catch (Exception) { };

                terrainProxy.terrainSelectedToolIndex = -1;
            }
        }
コード例 #3
0
        public override void DrawSettingContents()
        {
            EditorGUI.BeginDisabledGroup(Application.isPlaying);
            //EditorGUILayout.PropertyField(prop_settings);

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField(GPUInstancerEditorConstants.TEXT_terrain, _treeManager.terrain, typeof(Terrain), true);
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.BeginHorizontal();
            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.paintOnTerrain, GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                if (_treeManager.terrain != null)
                {
                    GPUInstancerTerrainProxy proxy = _treeManager.AddProxyToTerrain();
                    Selection.activeGameObject     = _treeManager.terrain.gameObject;

                    proxy.terrainSelectedToolIndex = 4;
                }
            });
            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.removeTerrain, Color.red, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                if (EditorUtility.DisplayDialog(GPUInstancerEditorConstants.TEXT_removeTerrainConfirmation, GPUInstancerEditorConstants.TEXT_removeTerrainAreYouSure, GPUInstancerEditorConstants.TEXT_unset, GPUInstancerEditorConstants.TEXT_cancel))
                {
                    _treeManager.SetupManagerWithTerrain(null);
                }
            });
            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_terrain);

            EditorGUILayout.Space();

            EditorGUI.EndDisabledGroup();

            DrawCameraDataFields();

            DrawCullingSettings(_treeManager.prototypeList);

            DrawFloatingOriginFields();

            DrawLayerMaskFields();
        }
コード例 #4
0
        public override void DrawSettingContents()
        {
            EditorGUI.BeginDisabledGroup(Application.isPlaying);
            //EditorGUILayout.PropertyField(prop_settings);

            if (Application.isPlaying)
            {
                int index = 1;
                foreach (Terrain terrain in _treeManager.GetTerrains())
                {
                    EditorGUILayout.ObjectField("Terrain " + index, terrain, typeof(Terrain), true);
                    index++;
                }
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.ObjectField("Main " + GPUInstancerEditorConstants.TEXT_terrain, _treeManager.terrain, typeof(Terrain), true);
                EditorGUI.EndDisabledGroup();

                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(prop_additionalTerrains, true);
                EditorGUI.indentLevel--;

                if (prop_additionalTerrains.arraySize > 0)
                {
                    EditorGUILayout.HelpBox("When using Tree Manager with multiple Terrains, it requires every Terrain to have the same Tree prototypes defined on it. Adding Terrains with different tree prototypes might cause incorrect rendering and errors.", MessageType.Warning);
                }
            }

            EditorGUILayout.BeginHorizontal();
            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.paintOnTerrain, GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                if (_treeManager.terrain != null)
                {
                    GPUInstancerTerrainProxy proxy = _treeManager.AddProxyToTerrain();
                    Selection.activeGameObject     = _treeManager.terrain.gameObject;

                    proxy.terrainSelectedToolIndex = 4;
                }
            });
            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.removeTerrain, Color.red, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                if (EditorUtility.DisplayDialog(GPUInstancerEditorConstants.TEXT_removeTerrainConfirmation, GPUInstancerEditorConstants.TEXT_removeTerrainAreYouSure, GPUInstancerEditorConstants.TEXT_unset, GPUInstancerEditorConstants.TEXT_cancel))
                {
                    _treeManager.SetupManagerWithTerrain(null);
                }
            });
            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_terrain);

            EditorGUILayout.Space();

            EditorGUI.EndDisabledGroup();

            DrawCameraDataFields();

            DrawCullingSettings(_treeManager.prototypeList);

            DrawFloatingOriginFields();

            DrawLayerMaskFields();
        }