CapersProject/Packages/com.distantlands.cozy.core/Editor/E_CozyMenuItems.cs
2024-06-04 03:26:03 +09:00

228 lines
8.3 KiB
C#

// Distant Lands 2024
// COZY: Stylized Weather 3
// All code included in this file is protected under the Unity Asset Store Eula
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace DistantLands.Cozy.EditorScripts
{
public class E_CozyMenuItems : MonoBehaviour
{
[MenuItem("Tools/Cozy: Stylized Weather 3/Create Cozy Volume", false, 102)]
public static void CozyVolumeCreation()
{
Camera view = SceneView.lastActiveSceneView.camera;
GameObject i = new GameObject();
i.name = "Cozy Volume";
i.AddComponent<BoxCollider>().isTrigger = true;
i.AddComponent<CozyVolume>();
i.transform.position = (view.transform.forward * 5) + view.transform.position;
Undo.RegisterCreatedObjectUndo(i, "Create Cozy Volume");
Selection.activeGameObject = i;
}
[MenuItem("Tools/Cozy: Stylized Weather 3/Create Cozy FX Block Zone", false, 102)]
public static void CozyBlockZoneCreation()
{
Camera view = SceneView.lastActiveSceneView.camera;
GameObject i = new GameObject();
i.name = "Cozy FX Block Zone";
i.AddComponent<BoxCollider>().isTrigger = true;
i.tag = "FX Block Zone";
i.transform.position = (view.transform.forward * 5) + view.transform.position;
Undo.RegisterCreatedObjectUndo(i, "Create Cozy FX Block Zone");
Selection.activeGameObject = i;
}
[MenuItem("Tools/Cozy: Stylized Weather 3/Create Cozy Biome", false, 102)]
public static void CozyBiomeCreation()
{
Camera view = SceneView.lastActiveSceneView.camera;
GameObject i = new GameObject();
i.name = "Cozy Biome";
i.AddComponent<CozyBiome>();
i.transform.position = (view.transform.forward * 5) + view.transform.position;
Undo.RegisterCreatedObjectUndo(i, "Create Cozy Biome");
Selection.activeGameObject = i;
}
[MenuItem("Tools/Cozy: Stylized Weather 3/Toggle Tooltips", false, 300)]
public static void CozyToggleTooltips()
{
EditorPrefs.SetBool("CZY_Tooltips", !EditorPrefs.GetBool("CZY_Tooltips"));
}
[MenuItem("Tools/Cozy: Stylized Weather 3/Documentation", false, 1000)]
public static void Docs()
{
Application.OpenURL("https://distant-lands.gitbook.io/cozy-stylized-weather-documentation/welcome/hello");
}
[MenuItem("Tools/Cozy: Stylized Weather 3/Discord", false, 1000)]
public static void Discord()
{
Application.OpenURL("https://discord.gg/eZXxGCp9ww");
}
[MenuItem("Tools/Cozy: Stylized Weather 3/Setup Scene (No Modules)", false, 1)]
public static void CozySetupSceneSimple()
{
if (FindAnyObjectByType<CozyWeather>())
{
EditorUtility.DisplayDialog("Cozy:Weather", "You already have a Cozy:Weather system in your scene!", "Ok");
return;
}
if (!Camera.main)
{
EditorUtility.DisplayDialog("Cozy:Weather", "You need a main camera in your scene to setup for Cozy:Weather!", "Ok");
return;
}
if (FindObjectsByType<Light>(FindObjectsSortMode.None).Length != 0)
foreach (Light i in FindObjectsByType<Light>(FindObjectsSortMode.None))
{
if (i.type == LightType.Directional)
if (EditorUtility.DisplayDialog("You already have a directional light!", "Do you want to delete " + i.gameObject.name + "? Cozy:Weather will properly light your scene", "Delete", "Keep this light"))
DestroyImmediate(i.gameObject);
}
if (!Camera.main.GetComponent<FlareLayer>())
Camera.main.gameObject.AddComponent<FlareLayer>();
#if UNITY_POST_PROCESSING_STACK_V2 && !(COZY_URP || COZY_HDRP)
if (!FindObjectOfType<UnityEngine.Rendering.PostProcessing.PostProcessVolume>())
{
List<string> path = new List<string>();
path.Add("Assets/Cozy Weather/Post FX/");
GameObject i = new GameObject();
i.name = "Post FX Volume";
i.AddComponent<UnityEngine.Rendering.PostProcessing.PostProcessVolume>().profile = GetAssets<UnityEngine.Rendering.PostProcessing.PostProcessProfile>(path.ToArray(), "Post FX")[0];
i.GetComponent<UnityEngine.Rendering.PostProcessing.PostProcessVolume>().isGlobal = true;
i.layer = 1;
if (!Camera.main.GetComponent<UnityEngine.Rendering.PostProcessing.PostProcessLayer>())
Camera.main.gameObject.AddComponent<UnityEngine.Rendering.PostProcessing.PostProcessLayer>().volumeLayer = 2;
}
#endif
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Trilight;
GameObject weatherSphere = Instantiate(Resources.Load("Cozy Prefabs/Empty Weather Sphere Reference") as GameObject);
weatherSphere.name = "Cozy Weather Sphere";
}
[MenuItem("Tools/Cozy: Stylized Weather 3/Setup Scene", false, 1)]
public static void CozySetupScene()
{
if (FindAnyObjectByType<CozyWeather>())
{
EditorUtility.DisplayDialog("Cozy:Weather", "You already have a Cozy:Weather system in your scene!", "Ok");
return;
}
if (!Camera.main)
{
EditorUtility.DisplayDialog("Cozy:Weather", "You need a main camera in your scene to setup for Cozy:Weather!", "Ok");
return;
}
if (FindObjectsByType<Light>(FindObjectsSortMode.None).Length != 0)
foreach (Light i in FindObjectsByType<Light>(FindObjectsSortMode.None))
{
if (i.type == LightType.Directional)
if (EditorUtility.DisplayDialog("You already have a directional light!", "Do you want to delete " + i.gameObject.name + "? Cozy:Weather will properly light your scene", "Delete", "Keep this light"))
DestroyImmediate(i.gameObject);
}
if (!Camera.main.GetComponent<FlareLayer>())
Camera.main.gameObject.AddComponent<FlareLayer>();
// #if UNITY_POST_PROCESSING_STACK_V2
// if (!FindObjectOfType<UnityEngine.Rendering.PostProcessing.PostProcessVolume>())
// {
// List<string> path = new List<string>();
// path.Add("Assets/Cozy Weather/Post FX/");
// GameObject i = new GameObject();
// i.name = "Post FX Volume";
// i.AddComponent<UnityEngine.Rendering.PostProcessing.PostProcessVolume>().profile = GetAssets<UnityEngine.Rendering.PostProcessing.PostProcessProfile>(path.ToArray(), "Post FX")[0];
// i.GetComponent<UnityEngine.Rendering.PostProcessing.PostProcessVolume>().isGlobal = true;
// i.layer = 1;
// if (!Camera.main.GetComponent<UnityEngine.Rendering.PostProcessing.PostProcessLayer>())
// Camera.main.gameObject.AddComponent<UnityEngine.Rendering.PostProcessing.PostProcessLayer>().volumeLayer = 2;
// }
// #endif
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Trilight;
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
GameObject weatherSphere = Instantiate(Resources.Load("Cozy Prefabs/Cozy Weather Sphere") as GameObject);
weatherSphere.name = "Cozy Weather Sphere";
}
public static List<T> GetAssets<T>(string[] _foldersToSearch, string _filter) where T : UnityEngine.Object
{
string[] guids = AssetDatabase.FindAssets(_filter, _foldersToSearch);
List<T> a = new List<T>();
for (int i = 0; i < guids.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
a.Add(AssetDatabase.LoadAssetAtPath<T>(path));
}
return a;
}
}
}