summaryrefslogtreecommitdiff
path: root/Assets/BOXOPHOBIC/Atmospheric Height Fog/Core/Editor/HeightFogCreate.cs
blob: bc273fca48a0cc46be47aa3775fb55810b48828c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Cristian Pop - https://boxophobic.com/

using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

namespace AtmosphericHeightFog
{
    public class HeightFogCreate
    {
        [MenuItem("GameObject/BOXOPHOBIC/Atmospheric Height Fog/Global", false, 9)]
        static void CreateGlobalVolume()
        {
            if (GameObject.Find("Height Fog Global") != null)
            {
                Debug.Log("[Atmospheric Height Fog] " + "Height Fog Global is already added to your scene!");
                return;
            }

            GameObject go = new GameObject();
            go.name = "Height Fog Global";
            go.AddComponent<HeightFogGlobal>();

            if (Selection.activeGameObject != null)
            {
                go.transform.parent = Selection.activeGameObject.transform;
            }

            Selection.activeGameObject = go;

            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }

        [MenuItem("GameObject/BOXOPHOBIC/Atmospheric Height Fog/Override Volume (Box)", false, 10)]
        static void CreateOverrideBoxVolume()
        {
            if (GameObject.Find("Height Fog Global") == null)
            {
                Debug.Log("[Atmospheric Height Fog] " + "Height Fog Global must be added to the scene first!");
                return;
            }

            GameObject go = new GameObject();
            go.name = "Height Fog Override (Box)";
            go.AddComponent<BoxCollider>();
            go.GetComponent<BoxCollider>().isTrigger = true;
            go.AddComponent<HeightFogOverride>();

            var sceneCamera = SceneView.lastActiveSceneView.camera;

            if (sceneCamera != null)
            {
                go.transform.position = sceneCamera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f));
            }
            else
            {
                go.transform.localPosition = Vector3.zero;
                go.transform.localEulerAngles = Vector3.zero;
                go.transform.localScale = Vector3.one;
            }

            if (Selection.activeGameObject != null)
            {
                go.transform.parent = Selection.activeGameObject.transform;
            }

            Selection.activeGameObject = go;

            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }

        [MenuItem("GameObject/BOXOPHOBIC/Atmospheric Height Fog/Override Volume (Sphere)", false, 11)]
        static void CreateOverrideSphereVolume()
        {
            if (GameObject.Find("Height Fog Global") == null)
            {
                Debug.Log("[Atmospheric Height Fog] " + "Height Fog Global must be added to the scene first!");
                return;
            }

            GameObject go = new GameObject();
            go.name = "Height Fog Override (Sphere)";
            go.AddComponent<SphereCollider>();
            go.GetComponent<SphereCollider>().isTrigger = true;
            go.AddComponent<HeightFogOverride>();

            var sceneCamera = SceneView.lastActiveSceneView.camera;

            if (sceneCamera != null)
            {
                go.transform.position = sceneCamera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f));
            }
            else
            {
                go.transform.localPosition = Vector3.zero;
                go.transform.localEulerAngles = Vector3.zero;
                go.transform.localScale = Vector3.one;
            }

            if (Selection.activeGameObject != null)
            {
                go.transform.parent = Selection.activeGameObject.transform;
            }

            Selection.activeGameObject = go;

            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
    }
}