1
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Callbacks;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
internal class JCompileLogger
|
||||
{
|
||||
private const string PACKAGE_NAME = "Jupiter - Low Poly Sky And Weather System";
|
||||
private const string PACKAGE_NAME_PLACEHOLDER = "${PACKAGE_NAME}";
|
||||
|
||||
private const string WEBSITE = "http://pinwheel.studio";
|
||||
private const string WEBSITE_PLACEHOLDER = "${WEBSITE}";
|
||||
|
||||
private const string SUPPORT_MAIL = "support@pinwheel.studio";
|
||||
private const string SUPPORT_MAIL_PLACEHOLDER = "${SUPPORT_MAIL}";
|
||||
|
||||
private const string LINK_COLOR = "blue";
|
||||
private const string LINK_COLOR_PLACEHOLDER = "${LC}";
|
||||
|
||||
private const float LOG_MESSAGE_PROBABIILITY = 0.03F;
|
||||
private static string[] messages = new string[]
|
||||
{
|
||||
"Thanks for using the ${PACKAGE_NAME}, please contact <color=${LC}>${SUPPORT_MAIL}</color> for support!",
|
||||
"Thanks for using the ${PACKAGE_NAME}, please give it a 5-stars rating and a positive review on the store!"
|
||||
};
|
||||
|
||||
//[DidReloadScripts]
|
||||
public static void ShowMessageOnCompileSucceeded()
|
||||
{
|
||||
ValidatePackageAndNamespace();
|
||||
if (Random.value < LOG_MESSAGE_PROBABIILITY)
|
||||
{
|
||||
if (messages.Length == 0)
|
||||
return;
|
||||
int msgIndex = Random.Range(0, messages.Length);
|
||||
string msg = messages[msgIndex]
|
||||
.Replace(PACKAGE_NAME_PLACEHOLDER, JVersionInfo.ProductNameAndVersionShort)
|
||||
.Replace(WEBSITE_PLACEHOLDER, WEBSITE)
|
||||
.Replace(SUPPORT_MAIL_PLACEHOLDER, SUPPORT_MAIL)
|
||||
.Replace(LINK_COLOR_PLACEHOLDER, LINK_COLOR);
|
||||
Debug.Log(msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidatePackageAndNamespace()
|
||||
{
|
||||
bool isPackageNameInvalid = PACKAGE_NAME.Equals("PACKAGE_NAME");
|
||||
bool isNamespaceInvalid = typeof(JCompileLogger).Namespace.Contains("PACKAGE_NAME");
|
||||
if (isPackageNameInvalid)
|
||||
{
|
||||
string message = "<color=red>Invalid PACKAGE_NAME in CompileLogger, fix it before release!</color>";
|
||||
Debug.Log(message);
|
||||
}
|
||||
if (isNamespaceInvalid)
|
||||
{
|
||||
string message = "<color=red>Invalid NAMESPACE in CompileLogger, fix it before release!</color>";
|
||||
Debug.Log(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,151 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
public static class JEditorMenus
|
||||
{
|
||||
[MenuItem("GameObject/3D Object/Jupiter Sky/Sunny Day")]
|
||||
public static JSky CreateSunnyDaySky(MenuCommand cmd)
|
||||
{
|
||||
GameObject g = new GameObject("Sunny Day Sky");
|
||||
if (cmd != null && cmd.context != null)
|
||||
{
|
||||
GameObject root = cmd.context as GameObject;
|
||||
GameObjectUtility.SetParentAndAlign(g, root);
|
||||
}
|
||||
|
||||
JSky skyComponent = g.AddComponent<JSky>();
|
||||
JSkyProfile profile = JSkyProfile.CreateInstance<JSkyProfile>();
|
||||
string fileName = "SkyProfile-" + JCommon.GetUniqueID();
|
||||
string filePath = string.Format("Assets/{0}.asset", fileName);
|
||||
AssetDatabase.CreateAsset(profile, filePath);
|
||||
|
||||
profile.CopyFrom(JJupiterSettings.Instance.DefaultProfileSunnyDay);
|
||||
skyComponent.Profile = profile;
|
||||
skyComponent.MoonLightSource = null;
|
||||
|
||||
Light[] lights = Object.FindObjectsOfType<Light>();
|
||||
for (int i = 0; i < lights.Length; ++i)
|
||||
{
|
||||
if (lights[i].type == LightType.Directional)
|
||||
{
|
||||
skyComponent.SunLightSource = lights[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return skyComponent;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/3D Object/Jupiter Sky/Starry Night")]
|
||||
public static JSky CreateStarryNightSky(MenuCommand cmd)
|
||||
{
|
||||
GameObject g = new GameObject("Starry Night Sky");
|
||||
if (cmd != null && cmd.context != null)
|
||||
{
|
||||
GameObject root = cmd.context as GameObject;
|
||||
GameObjectUtility.SetParentAndAlign(g, root);
|
||||
}
|
||||
|
||||
JSky skyComponent = g.AddComponent<JSky>();
|
||||
JSkyProfile profile = JSkyProfile.CreateInstance<JSkyProfile>();
|
||||
string fileName = "SkyProfile-" + JCommon.GetUniqueID();
|
||||
string filePath = string.Format("Assets/{0}.asset", fileName);
|
||||
AssetDatabase.CreateAsset(profile, filePath);
|
||||
|
||||
profile.CopyFrom(JJupiterSettings.Instance.DefaultProfileStarryNight);
|
||||
skyComponent.Profile = profile;
|
||||
skyComponent.SunLightSource = null;
|
||||
|
||||
Light[] lights = Object.FindObjectsOfType<Light>();
|
||||
for (int i = 0; i < lights.Length; ++i)
|
||||
{
|
||||
if (lights[i].type == LightType.Directional)
|
||||
{
|
||||
skyComponent.MoonLightSource = lights[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return skyComponent;
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Tools/Cubemap Creator")]
|
||||
public static void ShowCubemapCreator()
|
||||
{
|
||||
JCubemapCreatorWindow.ShowWindow();
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Project/Settings")]
|
||||
public static void ShowSettings()
|
||||
{
|
||||
Selection.activeObject = JJupiterSettings.Instance;
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Project/Version Info")]
|
||||
public static void ShowVersionInfo()
|
||||
{
|
||||
EditorUtility.DisplayDialog(
|
||||
"Version Info",
|
||||
JVersionInfo.ProductNameAndVersion,
|
||||
"OK");
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Project/Update Dependencies")]
|
||||
public static void UpdateDependencies()
|
||||
{
|
||||
JPackageInitializer.Init();
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Learning Resources/Youtube Channel")]
|
||||
public static void ShowYoutubeChannel()
|
||||
{
|
||||
Application.OpenURL(JCommon.YOUTUBE_CHANNEL);
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Learning Resources/Online Manual")]
|
||||
public static void ShowOnlineManual()
|
||||
{
|
||||
Application.OpenURL(JCommon.ONLINE_MANUAL);
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Community/Forum")]
|
||||
public static void ShowForum()
|
||||
{
|
||||
Application.OpenURL(JCommon.FORUM);
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Community/Discord")]
|
||||
public static void ShowDiscord()
|
||||
{
|
||||
Application.OpenURL(JCommon.DISCORD);
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Contact/Support")]
|
||||
public static void ShowSupportEmailEditor()
|
||||
{
|
||||
JEditorCommon.OpenEmailEditor(
|
||||
JCommon.SUPPORT_EMAIL,
|
||||
"[Jupiter] SHORT_QUESTION_HERE",
|
||||
"YOUR_QUESTION_IN_DETAIL");
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Contact/Business")]
|
||||
public static void ShowBusinessEmailEditor()
|
||||
{
|
||||
JEditorCommon.OpenEmailEditor(
|
||||
JCommon.BUSINESS_EMAIL,
|
||||
"[Jupiter] SHORT_MESSAGE_HERE",
|
||||
"YOUR_MESSAGE_IN_DETAIL");
|
||||
}
|
||||
|
||||
[MenuItem("Window/Jupiter/Leave a Review")]
|
||||
public static void OpenStorePage()
|
||||
{
|
||||
Application.OpenURL("http://u3d.as/1Hry");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using System;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
public static class JPackageInitializer
|
||||
{
|
||||
public delegate void InitCompletedHandler();
|
||||
public static event InitCompletedHandler Completed;
|
||||
|
||||
public static string JUPITER_KW = "JUPITER";
|
||||
|
||||
private static ListRequest listPackageRequest = null;
|
||||
|
||||
#pragma warning disable 0414
|
||||
|
||||
#pragma warning restore 0414
|
||||
|
||||
[DidReloadScripts]
|
||||
public static void Init()
|
||||
{
|
||||
CheckThirdPartyPackages();
|
||||
CheckUnityPackagesAndInit();
|
||||
}
|
||||
|
||||
private static void CheckThirdPartyPackages()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static void CheckUnityPackagesAndInit()
|
||||
{
|
||||
listPackageRequest = Client.List(true);
|
||||
EditorApplication.update += OnRequestingPackageList;
|
||||
}
|
||||
|
||||
private static void OnRequestingPackageList()
|
||||
{
|
||||
if (listPackageRequest == null)
|
||||
return;
|
||||
if (!listPackageRequest.IsCompleted)
|
||||
return;
|
||||
if (listPackageRequest.Error != null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (UnityEditor.PackageManager.PackageInfo p in listPackageRequest.Result)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
EditorApplication.update -= OnRequestingPackageList;
|
||||
InitPackage();
|
||||
}
|
||||
|
||||
private static void InitPackage()
|
||||
{
|
||||
BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
BuildTargetGroup buildGroup = BuildPipeline.GetBuildTargetGroup(buildTarget);
|
||||
|
||||
string symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildGroup);
|
||||
List<string> symbolList = new List<string>(symbols.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
|
||||
|
||||
bool isDirty = false;
|
||||
if (!symbolList.Contains(JUPITER_KW))
|
||||
{
|
||||
symbolList.Add(JUPITER_KW);
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
if (isDirty)
|
||||
{
|
||||
symbols = symbolList.ListElementsToString(";");
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildGroup, symbols);
|
||||
}
|
||||
|
||||
if (Completed != null)
|
||||
{
|
||||
Completed.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SetKeywordActive(List<string> kwList, string keyword, bool active)
|
||||
{
|
||||
bool isDirty = false;
|
||||
if (active && !kwList.Contains(keyword))
|
||||
{
|
||||
kwList.Add(keyword);
|
||||
isDirty = true;
|
||||
}
|
||||
else if (!active && kwList.Contains(keyword))
|
||||
{
|
||||
kwList.RemoveAll(s => s.Equals(keyword));
|
||||
isDirty = true;
|
||||
}
|
||||
return isDirty;
|
||||
}
|
||||
|
||||
public static List<System.Type> GetAllLoadedTypes()
|
||||
{
|
||||
List<System.Type> loadedTypes = new List<System.Type>();
|
||||
List<string> typeName = new List<string>();
|
||||
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var t in assembly.GetTypes())
|
||||
{
|
||||
if (t.IsVisible && !t.IsGenericType)
|
||||
{
|
||||
typeName.Add(t.Name);
|
||||
loadedTypes.Add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
return loadedTypes;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,361 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
[CustomEditor(typeof(JSky))]
|
||||
public class JSkyInspector : Editor
|
||||
{
|
||||
private JSky sky;
|
||||
private JSkyProfile profile;
|
||||
private JDayNightCycle dnc;
|
||||
|
||||
private const string DNC_LABEL = "Controlled by Day Night Cycle";
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
sky = target as JSky;
|
||||
profile = sky.Profile;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
sky.Profile = JEditorCommon.ScriptableObjectField<JSkyProfile>("Profile", sky.Profile);
|
||||
profile = sky.Profile;
|
||||
if (sky.Profile == null)
|
||||
return;
|
||||
dnc = sky.GetComponent<JDayNightCycle>();
|
||||
|
||||
DrawSceneReferencesGUI();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
DrawSkyGUI();
|
||||
DrawStarsGUI();
|
||||
DrawSunGUI();
|
||||
DrawMoonGUI();
|
||||
DrawHorizonCloudGUI();
|
||||
DrawOverheadCloudGUI();
|
||||
DrawDetailOverlayGUI();
|
||||
DrawUtilitiesGUI();
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
profile.UpdateMaterialProperties();
|
||||
EditorUtility.SetDirty(sky);
|
||||
EditorUtility.SetDirty(profile);
|
||||
}
|
||||
|
||||
DrawAddDayNightCycleGUI();
|
||||
}
|
||||
|
||||
private void DrawSceneReferencesGUI()
|
||||
{
|
||||
string label = "Scene References";
|
||||
string id = "scene-references";
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
sky.SunLightSource = EditorGUILayout.ObjectField("Sun Light Source", sky.SunLightSource, typeof(Light), true) as Light;
|
||||
sky.MoonLightSource = EditorGUILayout.ObjectField("Moon Light Source", sky.MoonLightSource, typeof(Light), true) as Light;
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawSkyGUI()
|
||||
{
|
||||
string label = "Sky";
|
||||
string id = "sky" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.SkyColor = ColorField("Sky Color", profile.SkyColor, true, true, true, nameof(profile.SkyColor));
|
||||
profile.HorizonColor = ColorField("Horizon Color", profile.HorizonColor, true, true, true, nameof(profile.HorizonColor));
|
||||
profile.GroundColor = ColorField("Ground Color", profile.GroundColor, true, true, true, nameof(profile.GroundColor));
|
||||
if (profile.AllowStepEffect)
|
||||
{
|
||||
profile.HorizonStep = EditorGUILayout.IntField("Horizon Step", profile.HorizonStep);
|
||||
}
|
||||
profile.HorizonExponent = FloatField("Horizon Exponent", profile.HorizonExponent, nameof(profile.HorizonExponent));
|
||||
profile.HorizonThickness = Slider("Horizon Thickness", profile.HorizonThickness, 0f, 1f, nameof(profile.HorizonThickness));
|
||||
profile.FogSyncOption = (JFogSyncOption)EditorGUILayout.EnumPopup("Fog Sync", profile.FogSyncOption);
|
||||
if (profile.FogSyncOption == JFogSyncOption.CustomColor)
|
||||
{
|
||||
profile.FogColor = ColorField("Fog Color", profile.FogColor, true, true, false, nameof(profile.FogColor));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawStarsGUI()
|
||||
{
|
||||
string label = "Stars";
|
||||
string id = "stars" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.EnableStars = EditorGUILayout.Toggle("Enable", profile.EnableStars);
|
||||
if (profile.EnableStars)
|
||||
{
|
||||
profile.UseBakedStars = EditorGUILayout.Toggle("Baked", profile.UseBakedStars);
|
||||
}
|
||||
if (profile.EnableStars && !profile.UseBakedStars)
|
||||
{
|
||||
profile.StarsStartPosition = Slider("Start", profile.StarsStartPosition, -1, 1, nameof(profile.StarsStartPosition));
|
||||
profile.StarsEndPosition = Slider("End", profile.StarsEndPosition, -1, 1, nameof(profile.StarsEndPosition));
|
||||
profile.StarsOpacity = Slider("Opacity", profile.StarsOpacity, 0f, 1f, nameof(profile.StarsOpacity));
|
||||
profile.StarsLayerCount = EditorGUILayout.DelayedIntField("Layers", profile.StarsLayerCount);
|
||||
|
||||
if (profile.StarsLayerCount > 0)
|
||||
{
|
||||
JEditorCommon.Separator();
|
||||
EditorGUILayout.LabelField("Layer 0");
|
||||
EditorGUI.indentLevel += 1;
|
||||
profile.StarsColor0 = ColorField("Color", profile.StarsColor0, true, true, true, nameof(profile.StarsColor0));
|
||||
profile.StarsDensity0 = Slider("Density", profile.StarsDensity0, 0.01f, 1f, nameof(profile.StarsDensity0));
|
||||
profile.StarsSize0 = Slider("Size", profile.StarsSize0, 0.01f, 1f, nameof(profile.StarsSize0));
|
||||
profile.StarsGlow0 = Slider("Glow", profile.StarsGlow0, 0f, 1f, nameof(profile.StarsGlow0));
|
||||
profile.StarsTwinkle0 = FloatField("Twinkle", profile.StarsTwinkle0, nameof(profile.StarsTwinkle0));
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
if (profile.StarsLayerCount > 1)
|
||||
{
|
||||
JEditorCommon.Separator();
|
||||
EditorGUILayout.LabelField("Layer 1");
|
||||
EditorGUI.indentLevel += 1;
|
||||
profile.StarsColor1 = ColorField("Color", profile.StarsColor1, true, true, true, nameof(profile.StarsColor1));
|
||||
profile.StarsDensity1 = Slider("Density", profile.StarsDensity1, 0.01f, 1f, nameof(profile.StarsDensity1));
|
||||
profile.StarsSize1 = Slider("Size", profile.StarsSize1, 0.01f, 1f, nameof(profile.StarsSize1));
|
||||
profile.StarsGlow1 = Slider("Glow", profile.StarsGlow1, 0f, 1f, nameof(profile.StarsGlow1));
|
||||
profile.StarsTwinkle1 = FloatField("Twinkle", profile.StarsTwinkle1, nameof(profile.StarsTwinkle1));
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
if (profile.StarsLayerCount > 2)
|
||||
{
|
||||
JEditorCommon.Separator();
|
||||
EditorGUILayout.LabelField("Layer 2");
|
||||
EditorGUI.indentLevel += 1;
|
||||
profile.StarsColor2 = ColorField("Color", profile.StarsColor2, true, true, true, nameof(profile.StarsColor2));
|
||||
profile.StarsDensity2 = Slider("Density", profile.StarsDensity2, 0.01f, 1f, nameof(profile.StarsDensity2));
|
||||
profile.StarsSize2 = Slider("Size", profile.StarsSize2, 0.01f, 1f, nameof(profile.StarsSize2));
|
||||
profile.StarsGlow2 = Slider("Glow", profile.StarsGlow2, 0f, 1f, nameof(profile.StarsGlow2));
|
||||
profile.StarsTwinkle2 = FloatField("Twinkle", profile.StarsTwinkle2, nameof(profile.StarsTwinkle2));
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
}
|
||||
if (profile.EnableStars && profile.UseBakedStars)
|
||||
{
|
||||
profile.StarsCubemap = JEditorCommon.InlineCubemapField("Cubemap", profile.StarsCubemap, -1);
|
||||
profile.StarsTwinkleMap = JEditorCommon.InlineTexture2DField("Twinkle Map", profile.StarsTwinkleMap, -1);
|
||||
profile.StarsOpacity = Slider("Opacity", profile.StarsOpacity, 0f, 1f, nameof(profile.StarsOpacity));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawSunGUI()
|
||||
{
|
||||
string label = "Sun";
|
||||
string id = "sun" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.EnableSun = EditorGUILayout.Toggle("Enable", profile.EnableSun);
|
||||
if (profile.EnableSun)
|
||||
{
|
||||
profile.UseBakedSun = EditorGUILayout.Toggle("Baked", profile.UseBakedSun);
|
||||
}
|
||||
if (profile.EnableSun && !profile.UseBakedSun)
|
||||
{
|
||||
profile.SunTexture = JEditorCommon.InlineTexture2DField("Texture", profile.SunTexture, -1);
|
||||
profile.SunColor = ColorField("Color", profile.SunColor, true, true, true, nameof(profile.SunColor));
|
||||
profile.SunSize = Slider("Size", profile.SunSize, 0f, 1f, nameof(profile.SunSize));
|
||||
profile.SunSoftEdge = Slider("Soft Edge", profile.SunSoftEdge, 0f, 1f, nameof(profile.SunSoftEdge));
|
||||
profile.SunGlow = Slider("Glow", profile.SunGlow, 0f, 1f, nameof(profile.SunGlow));
|
||||
}
|
||||
if (profile.EnableSun && profile.UseBakedSun)
|
||||
{
|
||||
profile.SunCubemap = JEditorCommon.InlineCubemapField("Cubemap", profile.SunCubemap, -1);
|
||||
}
|
||||
if (profile.EnableSun)
|
||||
{
|
||||
profile.SunLightColor = ColorField("Light Color", profile.SunLightColor, true, false, false, nameof(profile.SunLightColor));
|
||||
profile.SunLightIntensity = FloatField("Light Intensity", profile.SunLightIntensity, nameof(profile.SunLightIntensity));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawMoonGUI()
|
||||
{
|
||||
string label = "Moon";
|
||||
string id = "moon" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.EnableMoon = EditorGUILayout.Toggle("Enable", profile.EnableMoon);
|
||||
if (profile.EnableMoon)
|
||||
{
|
||||
profile.UseBakedMoon = EditorGUILayout.Toggle("Baked", profile.UseBakedMoon);
|
||||
}
|
||||
if (profile.EnableMoon && !profile.UseBakedMoon)
|
||||
{
|
||||
profile.MoonTexture = JEditorCommon.InlineTexture2DField("Texture", profile.MoonTexture, -1);
|
||||
profile.MoonColor = ColorField("Color", profile.MoonColor, true, true, true, nameof(profile.MoonColor));
|
||||
profile.MoonSize = Slider("Size", profile.MoonSize, 0f, 1f, nameof(profile.MoonSize));
|
||||
profile.MoonSoftEdge = Slider("Soft Edge", profile.MoonSoftEdge, 0f, 1f, nameof(profile.MoonSoftEdge));
|
||||
profile.MoonGlow = Slider("Glow", profile.MoonGlow, 0f, 1f, nameof(profile.MoonGlow));
|
||||
}
|
||||
if (profile.EnableMoon && profile.UseBakedMoon)
|
||||
{
|
||||
profile.MoonCubemap = JEditorCommon.InlineCubemapField("Cubemap", profile.MoonCubemap, -1);
|
||||
}
|
||||
if (profile.EnableMoon)
|
||||
{
|
||||
profile.MoonLightColor = ColorField("Light Color", profile.MoonLightColor, true, false, false, nameof(profile.MoonLightColor));
|
||||
profile.MoonLightIntensity = FloatField("Light Intensity", profile.MoonLightIntensity, nameof(profile.MoonLightIntensity));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawHorizonCloudGUI()
|
||||
{
|
||||
string label = "Horizon Cloud";
|
||||
string id = "horizon-cloud" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.EnableHorizonCloud = EditorGUILayout.Toggle("Enable", profile.EnableHorizonCloud);
|
||||
if (profile.EnableHorizonCloud)
|
||||
{
|
||||
profile.CustomCloudTexture = JEditorCommon.InlineTexture2DField("Texture", profile.CustomCloudTexture, -1);
|
||||
profile.HorizonCloudColor = ColorField("Color", profile.HorizonCloudColor, true, true, false, nameof(profile.HorizonCloudColor));
|
||||
profile.HorizonCloudStartPosition = Slider("Start", profile.HorizonCloudStartPosition, -1, 1, nameof(profile.HorizonCloudStartPosition));
|
||||
profile.HorizonCloudEndPosition = Slider("End", profile.HorizonCloudEndPosition, -1, 1, nameof(profile.HorizonCloudEndPosition));
|
||||
profile.HorizonCloudSize = FloatField("Size", profile.HorizonCloudSize, nameof(profile.HorizonCloudSize));
|
||||
if (profile.AllowStepEffect)
|
||||
{
|
||||
profile.HorizonCloudStep = EditorGUILayout.IntField("Step", profile.HorizonCloudStep);
|
||||
}
|
||||
profile.HorizonCloudAnimationSpeed = FloatField("Animation Speed", profile.HorizonCloudAnimationSpeed, nameof(profile.HorizonCloudAnimationSpeed));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawOverheadCloudGUI()
|
||||
{
|
||||
string label = "Overhead Cloud";
|
||||
string id = "overhead-cloud" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.EnableOverheadCloud = EditorGUILayout.Toggle("Enable", profile.EnableOverheadCloud);
|
||||
if (profile.EnableOverheadCloud)
|
||||
{
|
||||
profile.CustomCloudTexture = JEditorCommon.InlineTexture2DField("Texture", profile.CustomCloudTexture, -1);
|
||||
profile.OverheadCloudColor = ColorField("Color", profile.OverheadCloudColor, true, true, false, nameof(profile.OverheadCloudColor));
|
||||
profile.OverheadCloudAltitude = FloatField("Altitude", profile.OverheadCloudAltitude, nameof(profile.OverheadCloudAltitude));
|
||||
profile.OverheadCloudSize = FloatField("Size", profile.OverheadCloudSize, nameof(profile.OverheadCloudSize));
|
||||
if (profile.AllowStepEffect)
|
||||
{
|
||||
profile.OverheadCloudStep = EditorGUILayout.IntField("Step", profile.OverheadCloudStep);
|
||||
}
|
||||
profile.OverheadCloudAnimationSpeed = FloatField("Animation Speed", profile.OverheadCloudAnimationSpeed, nameof(profile.OverheadCloudAnimationSpeed));
|
||||
profile.OverheadCloudFlowDirectionX = Slider("Flow X", profile.OverheadCloudFlowDirectionX, -1, 1, nameof(profile.OverheadCloudFlowDirectionX));
|
||||
profile.OverheadCloudFlowDirectionZ = Slider("Flow Z", profile.OverheadCloudFlowDirectionZ, -1, 1, nameof(profile.OverheadCloudFlowDirectionZ));
|
||||
profile.OverheadCloudRemapMin = FloatField("Remap Min", profile.OverheadCloudRemapMin, nameof(profile.OverheadCloudRemapMin));
|
||||
profile.OverheadCloudRemapMax = FloatField("Remap Max", profile.OverheadCloudRemapMax, nameof(profile.OverheadCloudRemapMax));
|
||||
profile.OverheadCloudCastShadow = EditorGUILayout.Toggle("Cast Shadow (Experimental)", profile.OverheadCloudCastShadow);
|
||||
if (profile.OverheadCloudCastShadow)
|
||||
{
|
||||
profile.OverheadCloudShadowClipMask = EditorGUILayout.Slider("Clip Mask", profile.OverheadCloudShadowClipMask, 0f, 1f);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawDetailOverlayGUI()
|
||||
{
|
||||
string label = "Detail Overlay";
|
||||
string id = "detail-overlay" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.EnableDetailOverlay = EditorGUILayout.Toggle("Enable", profile.EnableDetailOverlay);
|
||||
if (profile.EnableDetailOverlay)
|
||||
{
|
||||
profile.DetailOverlayTintColor = ColorField("Color", profile.DetailOverlayTintColor, true, true, false, nameof(profile.DetailOverlayTintColor));
|
||||
profile.DetailOverlayCubeMap = JEditorCommon.InlineCubemapField("Cubemap", profile.DetailOverlayCubeMap, -1);
|
||||
profile.DetailOverlayLayer = (JDetailOverlayLayer)EditorGUILayout.EnumPopup("Layer", profile.DetailOverlayLayer);
|
||||
profile.DetailOverlayRotationSpeed = FloatField("Rotation Speed", profile.DetailOverlayRotationSpeed, nameof(profile.DetailOverlayRotationSpeed));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawUtilitiesGUI()
|
||||
{
|
||||
string label = "Utilities";
|
||||
string id = "utilities" + profile.GetInstanceID(); ;
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
profile.AllowStepEffect = EditorGUILayout.Toggle("Allow Step Effect", profile.AllowStepEffect);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawAddDayNightCycleGUI()
|
||||
{
|
||||
JDayNightCycle cycle = sky.GetComponent<JDayNightCycle>();
|
||||
if (cycle != null)
|
||||
return;
|
||||
|
||||
string label = "Day Night Cycle";
|
||||
string id = "day-night-cycle" + sky.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
if (GUILayout.Button("Add Day Night Cycle"))
|
||||
{
|
||||
sky.gameObject.AddComponent<JDayNightCycle>();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Color ColorField(string label, Color color, bool colorPicker, bool alpha, bool hdr, string propName)
|
||||
{
|
||||
if (dnc != null && dnc.enabled == true && dnc.Profile != null && dnc.Profile.ContainProperty(propName))
|
||||
{
|
||||
EditorGUILayout.LabelField(label, DNC_LABEL, JEditorCommon.ItalicLabel);
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EditorGUILayout.ColorField(new GUIContent(label), color, colorPicker, alpha, hdr);
|
||||
}
|
||||
}
|
||||
|
||||
private float FloatField(string label, float value, string propName)
|
||||
{
|
||||
if (dnc != null && dnc.enabled == true && dnc.Profile != null && dnc.Profile.ContainProperty(propName))
|
||||
{
|
||||
EditorGUILayout.LabelField(label, DNC_LABEL, JEditorCommon.ItalicLabel);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EditorGUILayout.FloatField(label, value);
|
||||
}
|
||||
}
|
||||
|
||||
private float Slider(string label, float value, float min, float max, string propName)
|
||||
{
|
||||
if (dnc != null && dnc.enabled == true && dnc.Profile != null && dnc.Profile.ContainProperty(propName))
|
||||
{
|
||||
EditorGUILayout.LabelField(label, DNC_LABEL, JEditorCommon.ItalicLabel);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EditorGUILayout.Slider(label, value, min, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
[CustomEditor(typeof(JSkyProfile))]
|
||||
public class JSkyProfileInspector : Editor
|
||||
{
|
||||
private JSkyProfile instance;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
instance = target as JSkyProfile;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.LabelField("Select the sky object in the scene to edit this profile.", JEditorCommon.WordWrapItalicLabel);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,394 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
[CustomEditor(typeof(JDayNightCycle))]
|
||||
public class JDayNightCycleInspector : Editor
|
||||
{
|
||||
private static List<JAnimatedProperty> allProperties;
|
||||
private static List<JAnimatedProperty> AllProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
if (allProperties == null)
|
||||
{
|
||||
allProperties = new List<JAnimatedProperty>();
|
||||
}
|
||||
return allProperties;
|
||||
}
|
||||
set
|
||||
{
|
||||
allProperties = value;
|
||||
}
|
||||
}
|
||||
|
||||
static JDayNightCycleInspector()
|
||||
{
|
||||
InitAllAnimatableProperties();
|
||||
}
|
||||
|
||||
private static void InitAllAnimatableProperties()
|
||||
{
|
||||
AllProperties.Clear();
|
||||
Type type = typeof(JSkyProfile);
|
||||
PropertyInfo[] props = type.GetProperties();
|
||||
for (int i = 0; i < props.Length; ++i)
|
||||
{
|
||||
Attribute att = props[i].GetCustomAttribute(typeof(JAnimatableAttribute));
|
||||
if (att != null)
|
||||
{
|
||||
JAnimatableAttribute animAtt = att as JAnimatableAttribute;
|
||||
AllProperties.Add(JAnimatedProperty.Create(props[i].Name, animAtt.DisplayName, animAtt.CurveOrGradient));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JDayNightCycle cycle;
|
||||
private JDayNightCycleProfile profile;
|
||||
bool isTimeFoldoutExpanded;
|
||||
|
||||
private static readonly int[] resolutionValues = new int[]
|
||||
{
|
||||
16,32,64,128,256,512,1024,2048
|
||||
};
|
||||
|
||||
private static readonly string[] resolutionLabels = new string[]
|
||||
{
|
||||
"16","32","64","128","256","512","1024","2048"
|
||||
};
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
cycle = target as JDayNightCycle;
|
||||
profile = cycle.Profile;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
cycle.Profile = JEditorCommon.ScriptableObjectField<JDayNightCycleProfile>("Profile", cycle.Profile);
|
||||
profile = cycle.Profile;
|
||||
if (cycle.Profile == null)
|
||||
return;
|
||||
|
||||
DrawSceneReferencesGUI();
|
||||
DrawTimeGUI();
|
||||
DrawSkyGUI();
|
||||
DrawStarsGUI();
|
||||
DrawSunGUI();
|
||||
DrawMoonGUI();
|
||||
DrawHorizonCloudGUI();
|
||||
DrawOverheadCloudGUI();
|
||||
DrawDetailOverlayGUI();
|
||||
DrawEnvironmentReflectionGUI();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorUtility.SetDirty(cycle);
|
||||
EditorUtility.SetDirty(profile);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSceneReferencesGUI()
|
||||
{
|
||||
string label = "Scene References";
|
||||
string id = "scene-ref" + cycle.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
cycle.Sky = EditorGUILayout.ObjectField("Sky", cycle.Sky, typeof(JSky), true) as JSky;
|
||||
cycle.SunOrbitPivot = EditorGUILayout.ObjectField("Orbit Pivot", cycle.SunOrbitPivot, typeof(Transform), true) as Transform;
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawTimeGUI()
|
||||
{
|
||||
string label = "Time";
|
||||
string id = "time" + cycle.GetInstanceID();
|
||||
|
||||
isTimeFoldoutExpanded = JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
cycle.StartTime = EditorGUILayout.FloatField("Start Time", cycle.StartTime);
|
||||
cycle.TimeIncrement = EditorGUILayout.FloatField("Time Increment", cycle.TimeIncrement);
|
||||
GUI.enabled = !cycle.AutoTimeIncrement;
|
||||
cycle.Time = EditorGUILayout.Slider("Time", cycle.Time, 0f, 24f);
|
||||
GUI.enabled = true;
|
||||
cycle.AutoTimeIncrement = EditorGUILayout.Toggle("Auto", cycle.AutoTimeIncrement);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawSkyGUI()
|
||||
{
|
||||
string label = "Sky";
|
||||
string id = "sky" + profile.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
DisplayAddedProperties("Sky");
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
DisplayAllPropertiesAsContext("Sky");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawStarsGUI()
|
||||
{
|
||||
string label = "Stars";
|
||||
string id = "stars" + profile.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
DisplayAddedProperties("Stars");
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
DisplayAllPropertiesAsContext("Stars");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawSunGUI()
|
||||
{
|
||||
string label = "Sun";
|
||||
string id = "sun" + profile.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
cycle.UseSunPivot = EditorGUILayout.Toggle("Custom Pivot", cycle.UseSunPivot);
|
||||
if (cycle.UseSunPivot)
|
||||
{
|
||||
cycle.SunOrbitPivot = EditorGUILayout.ObjectField("Pivot", cycle.SunOrbitPivot, typeof(Transform), true) as Transform;
|
||||
}
|
||||
JEditorCommon.Separator();
|
||||
|
||||
DisplayAddedProperties("Sun");
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
DisplayAllPropertiesAsContext("Sun");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawMoonGUI()
|
||||
{
|
||||
string label = "Moon";
|
||||
string id = "moon" + profile.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
cycle.UseMoonPivot = EditorGUILayout.Toggle("Custom Pivot", cycle.UseMoonPivot);
|
||||
if (cycle.UseMoonPivot)
|
||||
{
|
||||
cycle.MoonOrbitPivot = EditorGUILayout.ObjectField("Pivot", cycle.MoonOrbitPivot, typeof(Transform), true) as Transform;
|
||||
}
|
||||
JEditorCommon.Separator();
|
||||
|
||||
DisplayAddedProperties("Moon");
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
DisplayAllPropertiesAsContext("Moon");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawHorizonCloudGUI()
|
||||
{
|
||||
string label = "Horizon Cloud";
|
||||
string id = "horizon-cloud" + profile.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
DisplayAddedProperties("Horizon Cloud");
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
DisplayAllPropertiesAsContext("Horizon Cloud");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawOverheadCloudGUI()
|
||||
{
|
||||
string label = "Overhead Cloud";
|
||||
string id = "overhead-cloud" + profile.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
DisplayAddedProperties("Overhead Cloud");
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
DisplayAllPropertiesAsContext("Overhead Cloud");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawDetailOverlayGUI()
|
||||
{
|
||||
string label = "Detail Overlay";
|
||||
string id = "detail-overlay" + profile.GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
DisplayAddedProperties("Detail Overlay");
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
DisplayAllPropertiesAsContext("Detail Overlay");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawEnvironmentReflectionGUI()
|
||||
{
|
||||
string label = "Environment Reflection";
|
||||
string id = "env-reflection";
|
||||
|
||||
JEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
cycle.ShouldUpdateEnvironmentReflection = EditorGUILayout.Toggle("Enable", cycle.ShouldUpdateEnvironmentReflection);
|
||||
if (cycle.ShouldUpdateEnvironmentReflection)
|
||||
{
|
||||
cycle.EnvironmentReflectionResolution = EditorGUILayout.IntPopup("Resolution", cycle.EnvironmentReflectionResolution, resolutionLabels, resolutionValues);
|
||||
cycle.EnvironmentReflectionTimeSlicingMode = (ReflectionProbeTimeSlicingMode)EditorGUILayout.EnumPopup("Time Slicing", cycle.EnvironmentReflectionTimeSlicingMode);
|
||||
EditorGUILayout.LabelField("Realtime Reflection Probe must be enabled in Quality Settings.", JEditorCommon.WordWrapItalicLabel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DisplayAddedProperties(string group)
|
||||
{
|
||||
EditorGUI.indentLevel -= 1;
|
||||
JAnimatedProperty toRemoveProp = null;
|
||||
List<JAnimatedProperty> props = profile.AnimatedProperties.FindAll(p => p.DisplayName.StartsWith(group));
|
||||
for (int i = 0; i < props.Count; ++i)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
JAnimatedProperty p = props[i];
|
||||
if (GUILayout.Button("▬", EditorStyles.miniLabel, GUILayout.Width(12)))
|
||||
{
|
||||
toRemoveProp = p;
|
||||
}
|
||||
|
||||
string itemLabel = p.DisplayName.Substring(p.DisplayName.IndexOf("/") + 1);
|
||||
itemLabel = ObjectNames.NicifyVariableName(itemLabel);
|
||||
if (p.CurveOrGradient == JCurveOrGradient.Curve)
|
||||
{
|
||||
p.Curve = EditorGUILayout.CurveField(itemLabel, p.Curve);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.Gradient = EditorGUILayout.GradientField(new GUIContent(itemLabel), p.Gradient, true);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
if (props.Count > 0)
|
||||
{
|
||||
JEditorCommon.Separator();
|
||||
}
|
||||
|
||||
if (toRemoveProp != null)
|
||||
{
|
||||
profile.AnimatedProperties.Remove(toRemoveProp);
|
||||
}
|
||||
EditorGUI.indentLevel += 1;
|
||||
}
|
||||
|
||||
private void DisplayAllPropertiesAsContext(string group)
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
List<JAnimatedProperty> props = AllProperties.FindAll(p => p.DisplayName.StartsWith(group));
|
||||
if (props.Count == 0)
|
||||
{
|
||||
menu.AddDisabledItem(new GUIContent("No item found"));
|
||||
menu.ShowAsContext();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < props.Count; ++i)
|
||||
{
|
||||
JAnimatedProperty p = props[i];
|
||||
string itemLabel = p.DisplayName.Substring(p.DisplayName.IndexOf("/") + 1);
|
||||
bool added = profile.AnimatedProperties.FindIndex(p0 => p0.Name.Equals(p.Name)) >= 0;
|
||||
|
||||
if (added)
|
||||
{
|
||||
menu.AddDisabledItem(new GUIContent(itemLabel));
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.AddItem(
|
||||
new GUIContent(itemLabel),
|
||||
false,
|
||||
() =>
|
||||
{
|
||||
profile.AddProperty(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
public override bool RequiresConstantRepaint()
|
||||
{
|
||||
return isTimeFoldoutExpanded;
|
||||
}
|
||||
|
||||
private void OnSceneGUI()
|
||||
{
|
||||
if (cycle == null)
|
||||
return;
|
||||
|
||||
float evalTime = Mathf.InverseLerp(0f, 24f, cycle.Time);
|
||||
|
||||
if (cycle.Sky.Profile.EnableSun && cycle.Sky.SunLightSource != null)
|
||||
{
|
||||
Color c = cycle.Sky.Profile.SunColor;
|
||||
c.a = Mathf.Max(0.1f, c.a);
|
||||
|
||||
Transform pivot = (cycle.UseSunPivot && cycle.SunOrbitPivot != null) ? cycle.SunOrbitPivot : cycle.transform;
|
||||
Vector3 normal = pivot.right;
|
||||
Handles.color = c;
|
||||
float radius = 10;
|
||||
Handles.DrawWireDisc(pivot.position, normal, radius);
|
||||
|
||||
float angle = evalTime * 360f;
|
||||
Matrix4x4 localRotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0));
|
||||
Vector3 localDirection = localRotationMatrix.MultiplyVector(Vector3.up);
|
||||
|
||||
Matrix4x4 localToWorld = pivot.localToWorldMatrix;
|
||||
Vector3 worldDirection = localToWorld.MultiplyVector(localDirection);
|
||||
|
||||
Vector3 worldPos = pivot.transform.position - worldDirection * radius;
|
||||
Handles.color = c;
|
||||
Handles.DrawSolidDisc(worldPos, normal, 1);
|
||||
}
|
||||
|
||||
if (cycle.Sky.Profile.EnableMoon && cycle.Sky.MoonLightSource != null)
|
||||
{
|
||||
Color c = cycle.Sky.Profile.MoonColor;
|
||||
c.a = Mathf.Max(0.1f, c.a);
|
||||
|
||||
Transform pivot = (cycle.UseMoonPivot && cycle.MoonOrbitPivot != null) ? cycle.MoonOrbitPivot : cycle.transform;
|
||||
Vector3 normal = pivot.right;
|
||||
Handles.color = c;
|
||||
float radius = 10;
|
||||
Handles.DrawWireDisc(pivot.position, normal, radius);
|
||||
|
||||
float angle = evalTime * 360f;
|
||||
Matrix4x4 localRotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0));
|
||||
Vector3 localDirection = localRotationMatrix.MultiplyVector(Vector3.down);
|
||||
|
||||
Matrix4x4 localToWorld = pivot.localToWorldMatrix;
|
||||
Vector3 worldDirection = localToWorld.MultiplyVector(localDirection);
|
||||
|
||||
Vector3 worldPos = pivot.transform.position - worldDirection * radius;
|
||||
Handles.color = c;
|
||||
Handles.DrawSolidDisc(worldPos, normal, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
[CustomEditor(typeof(JDayNightCycleProfile))]
|
||||
public class JDayNightCycleProfileInspector : Editor
|
||||
{
|
||||
private JDayNightCycleProfile instance;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
instance = target as JDayNightCycleProfile;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.LabelField("Select the sky object in the scene to edit this profile.", JEditorCommon.WordWrapItalicLabel);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,170 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Pinwheel.Jupiter;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
public class JCubemapCreatorWindow : EditorWindow
|
||||
{
|
||||
public Vector3 CameraPosition { get; set; }
|
||||
public float CameraNearPlane { get; set; }
|
||||
public float CameraFarPlane { get; set; }
|
||||
public CameraClearFlags CameraClearFlag { get; set; }
|
||||
public Color CameraBackgroundColor { get; set; }
|
||||
public int Resolution { get; set; }
|
||||
public bool ExportFaceTextures { get; set; }
|
||||
public string Directory { get; set; }
|
||||
|
||||
public static readonly int[] ResolutionValues = new int[] { 16, 32, 64, 128, 256, 512, 1024, 2048 };
|
||||
public static readonly string[] ResolutionLabels = new string[] { "16", "32", "64", "128", "256", "512", "1024", "2048" };
|
||||
|
||||
public const string PREF_PREFIX = "cubemap-creator";
|
||||
public const string CAM_POS_X = "cam-pos-x";
|
||||
public const string CAM_POS_Y = "cam-pos-y";
|
||||
public const string CAM_POS_Z = "cam-pos-z";
|
||||
public const string CAM_NEAR_PLANE = "cam-near-plane";
|
||||
public const string CAM_FAR_PLANE = "cam-far-plane";
|
||||
public const string CAM_CLEAR_FLAG = "cam-clear-flag";
|
||||
public const string CAM_BG_COLOR = "cam-background-color";
|
||||
public const string RESOLUTION = "resolution";
|
||||
public const string EXPORT_FACE_TEXTURES = "export-face-textures";
|
||||
public const string DIRECTORY = "directory";
|
||||
|
||||
public static void ShowWindow()
|
||||
{
|
||||
JCubemapCreatorWindow window = EditorWindow.CreateInstance<JCubemapCreatorWindow>();
|
||||
window.titleContent = new GUIContent("Cubemap Creator");
|
||||
window.minSize = new Vector2(400, 300);
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
float x = EditorPrefs.GetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_POS_X), 0);
|
||||
float y = EditorPrefs.GetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_POS_Y), 0);
|
||||
float z = EditorPrefs.GetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_POS_Z), 0);
|
||||
CameraPosition = new Vector3(x, y, z);
|
||||
CameraNearPlane = EditorPrefs.GetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_NEAR_PLANE), 0.1f);
|
||||
CameraFarPlane = EditorPrefs.GetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_FAR_PLANE), 100);
|
||||
CameraClearFlag = (CameraClearFlags)EditorPrefs.GetInt(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_CLEAR_FLAG), 0);
|
||||
string htmlColor = EditorPrefs.GetString(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_BG_COLOR), "FFFFFF");
|
||||
Color c = Color.white;
|
||||
ColorUtility.TryParseHtmlString("#" + htmlColor, out c);
|
||||
CameraBackgroundColor = c;
|
||||
Resolution = EditorPrefs.GetInt(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, RESOLUTION), 512);
|
||||
ExportFaceTextures = EditorPrefs.GetBool(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_FACE_TEXTURES), false);
|
||||
Directory = EditorPrefs.GetString(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY), "Assets/");
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_POS_X), CameraPosition.x);
|
||||
EditorPrefs.SetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_POS_Y), CameraPosition.y);
|
||||
EditorPrefs.SetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_POS_Z), CameraPosition.z);
|
||||
EditorPrefs.SetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_NEAR_PLANE), CameraNearPlane);
|
||||
EditorPrefs.SetFloat(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_FAR_PLANE), CameraFarPlane);
|
||||
EditorPrefs.SetInt(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_CLEAR_FLAG), (int)CameraClearFlag);
|
||||
EditorPrefs.SetString(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CAM_BG_COLOR), ColorUtility.ToHtmlStringRGB(CameraBackgroundColor));
|
||||
EditorPrefs.SetInt(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, RESOLUTION), Resolution);
|
||||
EditorPrefs.SetBool(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_FACE_TEXTURES), ExportFaceTextures);
|
||||
EditorPrefs.SetString(JEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY), Directory);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
DrawExportGUI();
|
||||
}
|
||||
|
||||
private void DrawExportGUI()
|
||||
{
|
||||
string label = "Export";
|
||||
string id = "export" + GetInstanceID();
|
||||
|
||||
JEditorCommon.Foldout(label, true, id, () =>
|
||||
{
|
||||
CameraPosition = JEditorCommon.InlineVector3Field("Position", CameraPosition);
|
||||
CameraNearPlane = EditorGUILayout.FloatField("Near Plane", CameraNearPlane);
|
||||
CameraFarPlane = EditorGUILayout.FloatField("Far Plane", CameraFarPlane);
|
||||
CameraClearFlag = (CameraClearFlags)EditorGUILayout.EnumPopup("Clear Flags", CameraClearFlag);
|
||||
if (CameraClearFlag == CameraClearFlags.Color)
|
||||
{
|
||||
CameraBackgroundColor = EditorGUILayout.ColorField("Background Color", CameraBackgroundColor);
|
||||
}
|
||||
|
||||
Resolution = EditorGUILayout.IntPopup("Resolution", Resolution, ResolutionLabels, ResolutionValues);
|
||||
ExportFaceTextures = EditorGUILayout.Toggle("Export Face Textures", ExportFaceTextures);
|
||||
|
||||
string dir = Directory;
|
||||
JEditorCommon.BrowseFolder("Directory", ref dir);
|
||||
Directory = dir;
|
||||
|
||||
GUI.enabled = !string.IsNullOrEmpty(Directory);
|
||||
if (GUILayout.Button("Export"))
|
||||
{
|
||||
Export();
|
||||
}
|
||||
GUI.enabled = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void Export()
|
||||
{
|
||||
JUtilities.EnsureDirectoryExists(Directory);
|
||||
|
||||
Cubemap cube = new Cubemap(Resolution, TextureFormat.ARGB32, false);
|
||||
JCubemapRendererArgs args = new JCubemapRendererArgs()
|
||||
{
|
||||
CameraPosition = this.CameraPosition,
|
||||
CameraNearPlane = this.CameraNearPlane,
|
||||
CameraFarPlane = this.CameraFarPlane,
|
||||
CameraClearFlag = this.CameraClearFlag,
|
||||
CameraBackgroundColor = this.CameraBackgroundColor,
|
||||
Resolution = this.Resolution,
|
||||
Cubemap = cube,
|
||||
Face = (CubemapFace)63
|
||||
};
|
||||
JCubemapRenderer.Render(args);
|
||||
|
||||
string fileName = Path.Combine(Directory, "Cubemap-" + JCommon.GetUniqueID() + ".cubemap");
|
||||
AssetDatabase.CreateAsset(cube, fileName);
|
||||
|
||||
if (ExportFaceTextures)
|
||||
{
|
||||
ExportFace(cube, CubemapFace.PositiveX);
|
||||
ExportFace(cube, CubemapFace.NegativeX);
|
||||
ExportFace(cube, CubemapFace.PositiveY);
|
||||
ExportFace(cube, CubemapFace.NegativeY);
|
||||
ExportFace(cube, CubemapFace.PositiveZ);
|
||||
ExportFace(cube, CubemapFace.NegativeZ);
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
EditorGUIUtility.PingObject(cube);
|
||||
Selection.activeObject = cube;
|
||||
}
|
||||
|
||||
private void ExportFace(Cubemap cube, CubemapFace face)
|
||||
{
|
||||
Texture2D tex = new Texture2D(cube.width, cube.height);
|
||||
Color[] data = cube.GetPixels(face);
|
||||
Color[] flipData = new Color[data.Length];
|
||||
for (int y = 0; y < Resolution; ++y)
|
||||
{
|
||||
for (int x = 0; x < Resolution; ++x)
|
||||
{
|
||||
flipData[JUtilities.To1DIndex(x, y, Resolution)] = data[JUtilities.To1DIndex(Resolution - 1 - x, Resolution - 1 - y, Resolution)];
|
||||
}
|
||||
}
|
||||
tex.SetPixels(flipData);
|
||||
tex.Apply();
|
||||
|
||||
byte[] bytes = tex.EncodeToPNG();
|
||||
string fileName = Path.Combine(Directory, cube.name + "-" + face.ToString() + ".png");
|
||||
File.WriteAllBytes(fileName, bytes);
|
||||
JUtilities.DestroyObject(tex);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,138 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Pinwheel.Jupiter
|
||||
{
|
||||
public class JTwoPaneWindowWindow : EditorWindow
|
||||
{
|
||||
protected float toolbarHeight = EditorGUIUtility.singleLineHeight;
|
||||
protected int toolbarOffsetX = 4;
|
||||
protected int toolbarOverflowY = 5;
|
||||
protected int rightPaneWidth = 300;
|
||||
protected int rightPaneWidthMin = 200;
|
||||
protected int rightPaneWidthMax = 400;
|
||||
protected int resizeRectWidth = 10;
|
||||
protected bool isResizinng = false;
|
||||
|
||||
protected Vector2 rightPaneScrollPos;
|
||||
|
||||
protected Rect LeftPaneRect
|
||||
{
|
||||
get
|
||||
{
|
||||
Rect r = new Rect();
|
||||
r.size = new Vector2(position.size.x - rightPaneWidth, position.size.y - toolbarHeight - toolbarOverflowY);
|
||||
r.position = new Vector2(0, toolbarHeight + toolbarOverflowY);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
protected Rect RightPaneRect
|
||||
{
|
||||
get
|
||||
{
|
||||
Rect r = new Rect();
|
||||
r.size = new Vector2(rightPaneWidth, position.size.y - toolbarHeight - toolbarOverflowY);
|
||||
r.position = new Vector2(position.size.x - rightPaneWidth, toolbarHeight + toolbarOverflowY);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
protected Rect ResizePaneRect
|
||||
{
|
||||
get
|
||||
{
|
||||
Rect r = new Rect();
|
||||
r.position = new Vector2(position.size.x - rightPaneWidth - resizeRectWidth * 0.5f, toolbarHeight + toolbarOverflowY);
|
||||
r.size = new Vector2(resizeRectWidth, position.size.y - toolbarHeight - toolbarOverflowY);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
DrawToolbar();
|
||||
DrawLeftPane();
|
||||
DrawRightPane();
|
||||
HandleResize();
|
||||
HandleRepaint();
|
||||
}
|
||||
|
||||
private void DrawToolbar()
|
||||
{
|
||||
Rect r = EditorGUILayout.GetControlRect();
|
||||
RectOffset offset = new RectOffset(toolbarOffsetX, toolbarOffsetX, 0, 0);
|
||||
GUI.Box(offset.Add(r), string.Empty, EditorStyles.toolbar);
|
||||
|
||||
OnToolbarGUI(r);
|
||||
}
|
||||
|
||||
protected virtual void OnToolbarGUI(Rect r)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void DrawLeftPane()
|
||||
{
|
||||
OnLeftPaneGUI(LeftPaneRect);
|
||||
}
|
||||
|
||||
protected virtual void OnLeftPaneGUI(Rect r)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void DrawRightPane()
|
||||
{
|
||||
Color separatorColor = JEditorCommon.boxBorderColor;
|
||||
JEditorCommon.DrawLine(
|
||||
new Vector2(RightPaneRect.min.x - 2, RightPaneRect.min.y - 2),
|
||||
new Vector2(RightPaneRect.min.x - 2, RightPaneRect.max.y),
|
||||
separatorColor);
|
||||
|
||||
GUILayout.BeginArea(RightPaneRect);
|
||||
rightPaneScrollPos = EditorGUILayout.BeginScrollView(rightPaneScrollPos);
|
||||
|
||||
OnRightPaneScrollViewGUI();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
protected virtual void OnRightPaneScrollViewGUI()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void HandleResize()
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(ResizePaneRect, MouseCursor.ResizeHorizontal);
|
||||
if (Event.current == null)
|
||||
return;
|
||||
if (Event.current.type == EventType.MouseDown &&
|
||||
ResizePaneRect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
isResizinng = true;
|
||||
}
|
||||
else if (Event.current.type == EventType.MouseUp)
|
||||
{
|
||||
isResizinng = false;
|
||||
}
|
||||
|
||||
if (isResizinng)
|
||||
{
|
||||
rightPaneWidth = (int)(position.size.x - Event.current.mousePosition.x);
|
||||
rightPaneWidth = Mathf.Clamp(rightPaneWidth, rightPaneWidthMin, rightPaneWidthMax);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleRepaint()
|
||||
{
|
||||
if (Event.current == null)
|
||||
return;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user