Initial commit
This commit is contained in:
1 parent
ee9615239e
commit
16feac691f
4093 files changed
+1030491
No files matched your search
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Gaia.Internal;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Handy helper for all things Gaia
|
||||
/// </summary>
|
||||
public class AboutEditor : EditorWindow
|
||||
{
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("About Gaia", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("Gaia by Procedural Worlds automates the majority of the more tedious work in creating gorgeous environments. It was crafted with much love. Enjoy!", m_wrapStyle);
|
||||
if (GUILayout.Button("Visit GAIA Forums"))
|
||||
{
|
||||
Application.OpenURL("http://forum.unity3d.com/threads/gaia-aaa-terrain-generator-procedural-texturing-planting-and-scene-creation.327342/");
|
||||
}
|
||||
if (GUILayout.Button("Visit Procedural Worlds"))
|
||||
{
|
||||
Application.OpenURL("http://www.procedural-worlds.com");
|
||||
}
|
||||
if (GUILayout.Button("Like GAIA? Support with a Review :)"))
|
||||
{
|
||||
Application.OpenURL("https://www.assetstore.unity3d.com/en/#!/content/42618");
|
||||
}
|
||||
EditorGUILayout.LabelField(string.Format("Version: {0}", PWApp.CONF.Version), m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebe89628ad7961c4c8a05f98f14c0fb8
|
||||
timeCreated: 1440531268
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility to convert stamps from the old data format into .exr images
|
||||
/// </summary>
|
||||
|
||||
class ConvertStamps : EditorWindow, IPWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
|
||||
//The folder path we will process
|
||||
string folderPath = "";
|
||||
|
||||
//Are subfolders included?
|
||||
bool includeSubFolders = true;
|
||||
|
||||
//Remove the source files after conversion?
|
||||
bool deleteSourceFiles = true;
|
||||
|
||||
//The absolute number of stamp preview jpgs we are going to process
|
||||
int jpgCount = 0;
|
||||
|
||||
//The current jpg we are at for the progress bar
|
||||
int jpgIndex = 0;
|
||||
|
||||
public bool PositionChecked { get => true; set => PositionChecked = value; }
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
m_editorUtils.Initialize();
|
||||
|
||||
m_editorUtils.Panel("ConvertGaia1Stamps", DrawConvertStamps, true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void DrawConvertStamps(bool helpEnabled)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("Info"), MessageType.Info);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
{
|
||||
folderPath = m_editorUtils.TextField("Folder", folderPath);
|
||||
if (m_editorUtils.Button("Select Folder"))
|
||||
{
|
||||
folderPath = EditorUtility.OpenFolderPanel("Select Stamp Folder", "", "");
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
m_editorUtils.InlineHelp("Folder", helpEnabled);
|
||||
GUILayout.Space(15f);
|
||||
includeSubFolders = m_editorUtils.Toggle("Include Subfolders", includeSubFolders, helpEnabled);
|
||||
deleteSourceFiles = m_editorUtils.Toggle("Remove Old Stamp Data", deleteSourceFiles, helpEnabled);
|
||||
GUILayout.Space(25f);
|
||||
|
||||
if (m_editorUtils.Button("Start Conversion"))
|
||||
{
|
||||
string popupText = "This conversion process will look for old Gaia Stamps in the folder\n\n" + folderPath +
|
||||
"\n\n and convert them into the new format. Running this process is only required if you " +
|
||||
"still have stamps that consist of a preview picture and the actual data in a 'Data' Folder.";
|
||||
|
||||
if (deleteSourceFiles)
|
||||
{
|
||||
popupText += "\n\nWARNING: You selected to delete the source files. This process will delete all .jpg files and all 'Data' folders in the given directory after the conversion.";
|
||||
}
|
||||
popupText += "\n\nContinue?";
|
||||
|
||||
|
||||
if (EditorUtility.DisplayDialog("Starting Conversion", popupText, "OK", "Cancel"))
|
||||
{
|
||||
StartConversion(folderPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void StartConversion(string folderPath)
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
//Get the count of jpg files for the progress bar
|
||||
jpgIndex = 1;
|
||||
jpgCount = Directory.GetFiles(folderPath, "*.jpg", SearchOption.AllDirectories).Length;
|
||||
|
||||
//Begin with root folder, the subfolders will be handled automatically with recursion
|
||||
ConvertFolder(folderPath);
|
||||
|
||||
jpgIndex = 1;
|
||||
|
||||
if (deleteSourceFiles)
|
||||
{
|
||||
RemoveSourceData(folderPath);
|
||||
}
|
||||
EditorUtility.ClearProgressBar();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
private void RemoveSourceData(string folderPath)
|
||||
{
|
||||
//Handle Subfolders recursively
|
||||
if (includeSubFolders)
|
||||
{
|
||||
string[] subFolders = Directory.GetDirectories(folderPath);
|
||||
foreach (string s in subFolders)
|
||||
{
|
||||
//Did we find a data folder? Delete it
|
||||
if (s.EndsWith("\\Data"))
|
||||
{
|
||||
FileUtil.DeleteFileOrDirectory(s);
|
||||
}
|
||||
else //no data folder -> search inside
|
||||
{
|
||||
RemoveSourceData(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Delete all stamp preview files
|
||||
var allJPGs = Directory.GetFiles(folderPath, "*.jpg", SearchOption.TopDirectoryOnly);
|
||||
foreach (string filename in allJPGs)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Deleting Source Files...", "Deleting File " + jpgIndex.ToString() + " of " + jpgCount.ToString(), Mathf.InverseLerp(0, jpgCount, jpgIndex));
|
||||
FileUtil.DeleteFileOrDirectory(filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ConvertFolder(string folderPath)
|
||||
{
|
||||
//Handle Subfolders recursively
|
||||
if (includeSubFolders)
|
||||
{
|
||||
string[] subFolders = Directory.GetDirectories(folderPath);
|
||||
foreach (string s in subFolders)
|
||||
{
|
||||
ConvertFolder(s);
|
||||
}
|
||||
}
|
||||
|
||||
//Do the actual file conversion in the current folder
|
||||
string[] files = Directory.GetFiles(folderPath);
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (file.EndsWith(".jpg"))
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Converting Stamps", "Processing Stamp " + jpgIndex.ToString() + " of " + jpgCount.ToString(), Mathf.InverseLerp(0, jpgCount, jpgIndex));
|
||||
//Get path relative to project folder else the function to load the asset will create a warning in the console
|
||||
string relativePath = file.Substring(file.IndexOf("Assets", 0));
|
||||
var tex = (Texture2D)GaiaUtils.GetAsset(relativePath, typeof(Texture2D));
|
||||
if (GaiaUtils.CheckValidGaiaStampPath(tex))
|
||||
{
|
||||
var heightMap = new UnityHeightMap(GaiaUtils.GetGaiaStampPath(tex));
|
||||
GaiaUtils.CompressToMultiChannelFileImage(file.Replace(".jpg", ""), heightMap, heightMap, heightMap, null, TextureFormat.RGBAFloat, GaiaConstants.ImageFileType.Exr);
|
||||
jpgIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b151bb75f3b2c69498e4907206d4f2f2
|
||||
timeCreated: 1440543342
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,441 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
using Gaia.Internal;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Handy editor specific utils
|
||||
/// </summary>
|
||||
public class EditorUtilsOLD
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
private bool m_initialized = false;
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private GUIStyle m_titleStyle;
|
||||
private GUIStyle m_headingStyle;
|
||||
private GUIStyle m_bodyStyle;
|
||||
private GUIStyle m_linkStyle;
|
||||
private bool m_positionChecked = false;
|
||||
|
||||
/// <summary>
|
||||
/// Access to position checked method
|
||||
/// </summary>
|
||||
public bool PositionChecked
|
||||
{
|
||||
get { return m_positionChecked; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize editor styles
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
if (m_bodyStyle == null)
|
||||
{
|
||||
m_bodyStyle = new GUIStyle(GUI.skin.label);
|
||||
m_bodyStyle.fontStyle = FontStyle.Normal;
|
||||
m_bodyStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
if (m_titleStyle == null)
|
||||
{
|
||||
m_titleStyle = new GUIStyle(m_bodyStyle);
|
||||
m_titleStyle.fontStyle = FontStyle.Bold;
|
||||
m_titleStyle.fontSize = 20;
|
||||
}
|
||||
|
||||
if (m_headingStyle == null)
|
||||
{
|
||||
m_headingStyle = new GUIStyle(m_bodyStyle);
|
||||
m_headingStyle.fontStyle = FontStyle.Bold;
|
||||
}
|
||||
|
||||
if (m_linkStyle == null)
|
||||
{
|
||||
m_linkStyle = new GUIStyle(m_bodyStyle);
|
||||
m_linkStyle.wordWrap = false;
|
||||
m_linkStyle.normal.textColor = new Color(0x00 / 255f, 0x78 / 255f, 0xDA / 255f, 1f);
|
||||
m_linkStyle.stretchWidth = false;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check and caclulate window adjustment for editor windows relative to scene & game view
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="maximized"></param>
|
||||
/// <returns></returns>
|
||||
public Rect CheckPosition(Rect position, bool maximized)
|
||||
{
|
||||
if (!m_positionChecked)
|
||||
{
|
||||
m_positionChecked = true;
|
||||
if (!maximized)
|
||||
{
|
||||
//Get scene position
|
||||
Rect scenePosition = new Rect(0f, 0f, 800f, 600f);
|
||||
if (SceneView.lastActiveSceneView != null)
|
||||
{
|
||||
scenePosition = SceneView.lastActiveSceneView.position;
|
||||
}
|
||||
//Check our position
|
||||
if (position.x < scenePosition.xMin || position.x > scenePosition.xMax)
|
||||
{
|
||||
position.x = scenePosition.xMin + (((scenePosition.xMax - scenePosition.xMin) / 2f) - (position.width / 2f));
|
||||
}
|
||||
if (position.y < scenePosition.yMin || position.y > scenePosition.yMax)
|
||||
{
|
||||
position.y = scenePosition.yMin + 100f;
|
||||
}
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the intro
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the intro</param>
|
||||
/// <param name="description">Description</param>
|
||||
/// <param name="url">Make description clickable if supplied</param>
|
||||
public void DrawIntro(string name, string description = "", string url = "")
|
||||
{
|
||||
if (!m_initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical(string.Format("{0} ({1})", name, PWApp.CONF.Version), m_boxStyle);
|
||||
GUILayout.Label("");
|
||||
if (!string.IsNullOrEmpty(description))
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
DrawBody(description);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DrawClickableBody(description))
|
||||
{
|
||||
Application.OpenURL(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Display an image - the image must be of type editor & legacy gui to display
|
||||
/// </summary>
|
||||
/// <param name="image">The image</param>
|
||||
/// <param name="width">The width</param>
|
||||
/// <param name="height">The height</param>
|
||||
public void DrawImage(Texture2D image, float width, float height)
|
||||
{
|
||||
GUILayout.Label(image, GUILayout.Width(width), GUILayout.Height(height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display text in title style
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
public void DrawTitle(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!m_initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
GUILayout.Label(text, m_titleStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display text in header style
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
public void DrawHeader(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!m_initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
GUILayout.Label(text, m_headingStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw header text as clickable object
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="options">Display options</param>
|
||||
/// <returns>True if it was clicked</returns>
|
||||
public bool DrawClickableHeader(string text, params GUILayoutOption[] options)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return DrawClickableHeader(GetContent(text), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw header text as clickable object
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="options">Display options</param>
|
||||
/// <returns>True if it was clicked</returns>
|
||||
public bool DrawClickableHeader(GUIContent text, params GUILayoutOption[] options)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!m_initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
var position = GUILayoutUtility.GetRect(text, m_headingStyle, options);
|
||||
Handles.BeginGUI();
|
||||
Handles.color = m_headingStyle.normal.textColor;
|
||||
Handles.DrawLine(new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax));
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI();
|
||||
EditorGUIUtility.AddCursorRect(position, MouseCursor.Link);
|
||||
return GUI.Button(position, text, m_headingStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display text in body style
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
public void DrawBody(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
GUILayout.Label(text, m_bodyStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw clickable body text
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <returns>True if it was clicked</returns>
|
||||
public bool DrawClickableBody(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return DrawLinkBody(GetContent(text));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw clickable link body
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="options">Options</param>
|
||||
/// <returns></returns>
|
||||
public bool DrawLinkBody(GUIContent text, params GUILayoutOption[] options)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!m_initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
var position = GUILayoutUtility.GetRect(text, m_bodyStyle, options);
|
||||
EditorGUIUtility.AddCursorRect(position, MouseCursor.Link);
|
||||
return GUI.Button(position, text, m_bodyStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handy wrapper
|
||||
/// </summary>
|
||||
/// <param name="label"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public bool DrawLink(string label, params GUILayoutOption[] options)
|
||||
{
|
||||
if (string.IsNullOrEmpty(label))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return DrawLinkLabel(GetContent(label), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw link label
|
||||
/// </summary>
|
||||
/// <param name="label">Label</param>
|
||||
/// <param name="options">Options</param>
|
||||
/// <returns></returns>
|
||||
public bool DrawLinkLabel(GUIContent label, params GUILayoutOption[] options)
|
||||
{
|
||||
if (label == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!m_initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
var position = GUILayoutUtility.GetRect(label, m_linkStyle, options);
|
||||
Handles.BeginGUI();
|
||||
Handles.color = m_linkStyle.normal.textColor;
|
||||
Handles.DrawLine(new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax));
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI();
|
||||
EditorGUIUtility.AddCursorRect(position, MouseCursor.Link);
|
||||
return GUI.Button(position, label, m_linkStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw a line in the space provided by the label
|
||||
/// </summary>
|
||||
/// <param name="label">Label - used for spacing / volume</param>
|
||||
/// <param name="options">Parameters - eg height / width</param>
|
||||
public void DrawBodyLine(GUIContent label, params GUILayoutOption[] options)
|
||||
{
|
||||
if (label == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!m_initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
var position = GUILayoutUtility.GetRect(label, m_bodyStyle, options);
|
||||
Handles.BeginGUI();
|
||||
Handles.color = m_bodyStyle.normal.textColor;
|
||||
Handles.DrawLine(new Vector3(position.xMin, position.y), new Vector3(position.xMax, position.y));
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw a button that takes editor indentation into account
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <returns>True if clicked</returns>
|
||||
public bool DrawButton(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return DrawButton(GetContent(text));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a button that takes editor indentation into account
|
||||
/// </summary>
|
||||
/// <param name="content">Content to display</param>
|
||||
/// <returns>True is clicked</returns>
|
||||
public bool DrawButton(GUIContent content)
|
||||
{
|
||||
TextAnchor oldalignment = GUI.skin.button.alignment;
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
Rect btnR = EditorGUILayout.BeginHorizontal();
|
||||
btnR.xMin += (EditorGUI.indentLevel * 18f);
|
||||
btnR.height += 20f;
|
||||
btnR.width -= 4f;
|
||||
bool result = GUI.Button(btnR, content);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space(22);
|
||||
GUI.skin.button.alignment = oldalignment;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the label</param>
|
||||
/// <returns>Label</returns>
|
||||
public GUIContent GetContent(string name)
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name">Name of thing</param>
|
||||
/// <param name="tooltips">Tooltips of things</param>
|
||||
/// <returns>Content plus tool tip if it exists</returns>
|
||||
public GUIContent GetContent(string name, Dictionary<string, string> tooltips)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the text of the content indexed by name, or the name if not found
|
||||
/// </summary>
|
||||
/// <param name="name">Name to search for</param>
|
||||
/// <param name="tooltips">Toolips dictionary</param>
|
||||
/// <returns></returns>
|
||||
public string GetContentText(string name, Dictionary<string, string> tooltips)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return tooltip;
|
||||
}
|
||||
else
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e6516e8d6e16e749bf3b4ec1e47aebd
|
||||
timeCreated: 1524541978
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebbffbe8412973e4d9453eacf8095a73
|
||||
timeCreated: 1440543342
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Gaia {
|
||||
|
||||
/// <summary>
|
||||
/// Editor for Gaia defaults
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(GaiaDefaults))]
|
||||
public class GaiaDefaultsEditor : Editor
|
||||
{
|
||||
GUIStyle m_boxStyle;
|
||||
GUIStyle m_wrapStyle;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Get our resource
|
||||
GaiaDefaults defaults = (GaiaDefaults)target;
|
||||
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Create a nice text intro
|
||||
GUILayout.BeginVertical("Gaia Defaults", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("These defaults will be used by Gaia when creating new terrains, and new resources files.", m_wrapStyle);
|
||||
if (defaults.m_detailDistance > 250)
|
||||
{
|
||||
EditorGUILayout.HelpBox("The current detail distance exceeds the maximum possible range in Unity. Gaia will add an overwrite script to the terrains to allow for additional detail distance.", MessageType.Info);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
DrawDefaultInspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da3764c225c07a74cb9d8c7a8231fe0e
|
||||
timeCreated: 1440190276
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Injects GAIA_PRESENT define into project
|
||||
/// </summary>
|
||||
[InitializeOnLoad]
|
||||
public class GaiaDefinesEditor : Editor
|
||||
{
|
||||
static GaiaDefinesEditor()
|
||||
{
|
||||
//Make sure we inject GAIA_2_PRESENT
|
||||
bool updateScripting = false;
|
||||
var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
|
||||
if (symbols.Contains("GAIA_PRESENT"))
|
||||
{
|
||||
updateScripting = true;
|
||||
symbols = symbols.Replace("GAIA_PRESENT", "GAIA_2_PRESENT");
|
||||
}
|
||||
|
||||
if (!symbols.Contains("GAIA_2_PRESENT"))
|
||||
{
|
||||
updateScripting = true;
|
||||
symbols += ";" + "GAIA_2_PRESENT";
|
||||
}
|
||||
|
||||
if (GaiaProUtils.GaiaProDefineCheck())
|
||||
{
|
||||
if (!symbols.Contains("GAIA_PRO_PRESENT"))
|
||||
{
|
||||
updateScripting = true;
|
||||
symbols += ";GAIA_PRO_PRESENT";
|
||||
}
|
||||
}
|
||||
|
||||
if (updateScripting)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, symbols);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if linear light intensity setup is needed
|
||||
/// </summary>
|
||||
private static void CheckLinearSetup()
|
||||
{
|
||||
if (PlayerSettings.colorSpace == UnityEngine.ColorSpace.Linear)
|
||||
{
|
||||
GraphicsSettings.lightsUseLinearIntensity = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsSettings.lightsUseLinearIntensity = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pro utils to check for gaia pro
|
||||
/// </summary>
|
||||
public static class GaiaProUtils
|
||||
{
|
||||
#region Gaia Pro
|
||||
|
||||
/// <summary>
|
||||
/// Checks if gaia pro exists
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool IsGaiaPro()
|
||||
{
|
||||
bool isPro = false;
|
||||
|
||||
isPro = GaiaDirectories.GetGaiaProDirectory();
|
||||
|
||||
#if GAIA_PRO_PRESENT
|
||||
isPro = true;
|
||||
#else
|
||||
isPro = false;
|
||||
#endif
|
||||
|
||||
return isPro;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if gaia pro exists
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool GaiaProDefineCheck()
|
||||
{
|
||||
bool isPro = false;
|
||||
|
||||
isPro = GaiaDirectories.GetGaiaProDirectory();
|
||||
|
||||
return isPro;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cca26880d92618e4c83a6d9f6374f3fa
|
||||
timeCreated: 1500246772
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using PWCommon4;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.SceneManagement;
|
||||
using System.Linq;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
public static class GaiaEditorUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Marks the active scene dirty.
|
||||
/// </summary>
|
||||
public static void MarkSceneDirty()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (!EditorSceneManager.GetActiveScene().isDirty)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to create a GUIContent for button icons - decided whether to use Unity Standard or Pro Icons and adds the tooltip text
|
||||
/// </summary>
|
||||
/// <param name="key">Localization key to get the tooltip from</param>
|
||||
/// <param name="standardIcon">Icon to use for Unity Standard Skin</param>
|
||||
/// <param name="proIcon">Icon to use for Unity Pro Skin</param>
|
||||
/// <param name="editorUtils">Current Editor Utils class to pass in to look up the localized tooltip</param>
|
||||
/// <returns>GUIContent with correct texture and tooltip.</returns>
|
||||
public static GUIContent GetIconGUIContent(string key, Texture2D standardIcon, Texture2D proIcon, EditorUtils editorUtils)
|
||||
{
|
||||
Texture icon = null;
|
||||
if (EditorGUIUtility.isProSkin)
|
||||
{
|
||||
icon = proIcon;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = standardIcon;
|
||||
}
|
||||
|
||||
return new GUIContent(icon, editorUtils.GetTooltip(key));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the resource helper window with the given operation
|
||||
/// </summary>
|
||||
/// <param name="operation">The operation mode to open the window with.</param>
|
||||
public static void ShowResourceHelperWindow(GaiaResourceHelperOperation operation, Vector2 position)
|
||||
{
|
||||
var resourceHelper = EditorWindow.GetWindow<GaiaResourceHelper>(false, "Resource Helper");
|
||||
resourceHelper.Show();
|
||||
resourceHelper.position = new Rect(position, new Vector2(300, 200));
|
||||
resourceHelper.minSize = new Vector2(300, 200);
|
||||
resourceHelper.m_operation = operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line that can be used on curves and gradients to show where the current time of day is.
|
||||
/// </summary>
|
||||
/// <param name="currentRect"></param>
|
||||
/// <param name="currentTime"></param>
|
||||
/// <param name="lineHeight"></param>
|
||||
public static void DrawTimeOfDayLine(float currentTime, float lineHeight = 0f)
|
||||
{
|
||||
Rect currentRect = GUILayoutUtility.GetLastRect();
|
||||
EditorGUI.DrawRect(new Rect(currentRect.x + EditorGUIUtility.labelWidth + Mathf.Lerp(0f, currentRect.width - EditorGUIUtility.labelWidth, currentTime), currentRect.y - EditorGUIUtility.singleLineHeight * lineHeight, 2f, EditorGUIUtility.singleLineHeight * (lineHeight + 1)), Color.red);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to draw the line on the kelvin gradient image.
|
||||
/// </summary>
|
||||
/// <param name="currentTime"></param>
|
||||
/// <param name="heightValue"></param>
|
||||
/// <param name="lineHeight"></param>
|
||||
public static void DrawKelvinLine(float currentTime, float heightValue = 0f, float lineHeight = 0f)
|
||||
{
|
||||
Rect currentRect = GUILayoutUtility.GetLastRect();
|
||||
EditorGUI.DrawRect(new Rect(currentRect.x + EditorGUIUtility.labelWidth + Mathf.Lerp(3.5f, currentRect.width - EditorGUIUtility.labelWidth - 3.5f, currentTime), currentRect.y - EditorGUIUtility.singleLineHeight * lineHeight, 2f, EditorGUIUtility.singleLineHeight * (lineHeight + 1) + heightValue), Color.green);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows to loads an asset from unitys hidden builtin-extra resources
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="aAssetPath"></param>
|
||||
/// <returns></returns>
|
||||
public static T LoadAssetFromUniqueAssetPath<T>(string aAssetPath) where T : UnityEngine.Object
|
||||
{
|
||||
if (aAssetPath.Contains("::"))
|
||||
{
|
||||
string[] parts = aAssetPath.Split(new string[] { "::" }, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
aAssetPath = parts[0];
|
||||
if (parts.Length > 1)
|
||||
{
|
||||
string assetName = parts[1];
|
||||
System.Type t = typeof(T);
|
||||
var assets = AssetDatabase.LoadAllAssetsAtPath(aAssetPath)
|
||||
.Where(i => t.IsAssignableFrom(i.GetType())).Cast<T>();
|
||||
var obj = assets.Where(i => i.name == assetName).FirstOrDefault();
|
||||
if (obj == null)
|
||||
{
|
||||
int id;
|
||||
if (int.TryParse(parts[1], out id))
|
||||
obj = assets.Where(i => i.GetInstanceID() == id).FirstOrDefault();
|
||||
}
|
||||
if (obj != null)
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return AssetDatabase.LoadAssetAtPath<T>(aAssetPath);
|
||||
}
|
||||
public static string GetUniqueAssetPath(UnityEngine.Object aObj)
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(aObj);
|
||||
if (!string.IsNullOrEmpty(aObj.name))
|
||||
path += "::" + aObj.name;
|
||||
else
|
||||
path += "::" + aObj.GetInstanceID();
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handy layer mask interface - creates a EditorGUILayout Mask field
|
||||
/// </summary>
|
||||
/// <param name="label"></param>
|
||||
/// <param name="layerMask"></param>
|
||||
/// <returns></returns>
|
||||
public static LayerMask LayerMaskField(GUIContent label, LayerMask layerMask)
|
||||
{
|
||||
List<string> layers = new List<string>();
|
||||
List<int> layerNumbers = new List<int>();
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
string layerName = LayerMask.LayerToName(i);
|
||||
if (layerName != "")
|
||||
{
|
||||
layers.Add(layerName);
|
||||
layerNumbers.Add(i);
|
||||
}
|
||||
}
|
||||
int maskWithoutEmpty = 0;
|
||||
for (int i = 0; i < layerNumbers.Count; i++)
|
||||
{
|
||||
if (((1 << layerNumbers[i]) & layerMask.value) > 0)
|
||||
maskWithoutEmpty |= (1 << i);
|
||||
}
|
||||
maskWithoutEmpty = EditorGUILayout.MaskField(label, maskWithoutEmpty, layers.ToArray());
|
||||
int mask = 0;
|
||||
for (int i = 0; i < layerNumbers.Count; i++)
|
||||
{
|
||||
if ((maskWithoutEmpty & (1 << i)) > 0)
|
||||
mask |= (1 << layerNumbers[i]);
|
||||
}
|
||||
layerMask.value = mask;
|
||||
return layerMask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handy layer mask interface - creates a EditorGUI Mask field
|
||||
/// </summary>
|
||||
/// <param name="label"></param>
|
||||
/// <param name="layerMask"></param>
|
||||
/// <returns></returns>
|
||||
public static LayerMask LayerMaskFieldRect(Rect rect, GUIContent label, LayerMask layerMask)
|
||||
{
|
||||
List<string> layers = new List<string>();
|
||||
List<int> layerNumbers = new List<int>();
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
string layerName = LayerMask.LayerToName(i);
|
||||
if (layerName != "")
|
||||
{
|
||||
layers.Add(layerName);
|
||||
layerNumbers.Add(i);
|
||||
}
|
||||
}
|
||||
int maskWithoutEmpty = 0;
|
||||
for (int i = 0; i < layerNumbers.Count; i++)
|
||||
{
|
||||
if (((1 << layerNumbers[i]) & layerMask.value) > 0)
|
||||
maskWithoutEmpty |= (1 << i);
|
||||
}
|
||||
maskWithoutEmpty = EditorGUI.MaskField(rect, label, maskWithoutEmpty, layers.ToArray());
|
||||
int mask = 0;
|
||||
for (int i = 0; i < layerNumbers.Count; i++)
|
||||
{
|
||||
if ((maskWithoutEmpty & (1 << i)) > 0)
|
||||
mask |= (1 << layerNumbers[i]);
|
||||
}
|
||||
layerMask.value = mask;
|
||||
return layerMask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e59a8487da3e7db45a6095ff9046ec37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,734 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Gaia extension exporter
|
||||
/// </summary>
|
||||
public class GaiaExtensionExporterEditor : EditorWindow
|
||||
{
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private GUIStyle m_descWrapStyle;
|
||||
private Vector2 m_scrollPosition = Vector2.zero;
|
||||
private string m_publisherName = "Exported Extensions";
|
||||
private string m_extensionName = string.Format("Extension_{0:yyyyMMdd_HHmmss}", DateTime.Now);
|
||||
private string m_aboutText = "To use first create the resources file in the resources section and then create and use the spawners that match your requirements in the spawners sections.";
|
||||
private GaiaSettings m_settings;
|
||||
private List<GaiaResource> m_resourceList = new List<GaiaResource>();
|
||||
private List<Spawner> m_spawnerList = new List<Spawner>();
|
||||
|
||||
#region Unity methods - Gui etc
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
//Get or create existing settings object
|
||||
if (m_settings == null)
|
||||
{
|
||||
m_settings = (GaiaSettings)PWCommon4.AssetUtils.GetAssetScriptableObject("GaiaSettings");
|
||||
}
|
||||
|
||||
//Grab the publisher name
|
||||
if (m_settings != null && !string.IsNullOrEmpty(m_settings.m_publisherName))
|
||||
{
|
||||
m_publisherName = m_settings.m_publisherName;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Set up the description wrap style
|
||||
if (m_descWrapStyle == null)
|
||||
{
|
||||
m_descWrapStyle = new GUIStyle(GUI.skin.textArea);
|
||||
m_descWrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("Gaia Extension (GX) Exporter", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("The Gaia Extensions exporter converts your spawners and the resources they refer to into an extension that can then be shared or used as a backup.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//Scroll
|
||||
m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, false, false);
|
||||
|
||||
m_publisherName = EditorGUILayout.TextField(GetLabel("Publisher Name"), m_publisherName);
|
||||
m_extensionName = EditorGUILayout.TextField(GetLabel("Extension Name"), m_extensionName);
|
||||
|
||||
EditorGUILayout.LabelField("About Box Content");
|
||||
m_aboutText = EditorGUILayout.TextArea(m_aboutText, m_descWrapStyle, GUILayout.MinHeight(65));
|
||||
|
||||
//Dump the resources list
|
||||
if (m_resourceList.Count > 0)
|
||||
{
|
||||
GUILayout.Space(10);
|
||||
EditorGUILayout.LabelField("Resources:");
|
||||
GaiaResource resource;
|
||||
for (int resourceIdx = 0; resourceIdx < m_resourceList.Count; resourceIdx++)
|
||||
{
|
||||
resource = m_resourceList[resourceIdx];
|
||||
if (resource != null)
|
||||
{
|
||||
EditorGUILayout.LabelField(resource.m_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Dump the spawner list
|
||||
if (m_spawnerList.Count > 0)
|
||||
{
|
||||
GUILayout.Space(10);
|
||||
EditorGUILayout.LabelField("Spawners:");
|
||||
Spawner spawner;
|
||||
for (int spawnerIdx = 0; spawnerIdx < m_spawnerList.Count; spawnerIdx++)
|
||||
{
|
||||
spawner = m_spawnerList[spawnerIdx];
|
||||
if (spawner != null)
|
||||
{
|
||||
EditorGUILayout.LabelField(spawner.gameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//End scroll
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
//Extension drop pad
|
||||
DropAreaGUI();
|
||||
|
||||
GUILayout.BeginVertical("Extension Controller", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button("Save Extension"))
|
||||
{
|
||||
SaveGX();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(5);
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(5f);
|
||||
|
||||
}
|
||||
|
||||
public void DropAreaGUI()
|
||||
{
|
||||
//Ok - set up for drag and drop
|
||||
Event evt = Event.current;
|
||||
Rect drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));
|
||||
GUI.Box(drop_area, "Drop Spawner Here:", m_boxStyle);
|
||||
|
||||
switch (evt.type)
|
||||
{
|
||||
case EventType.DragUpdated:
|
||||
case EventType.DragPerform:
|
||||
{
|
||||
if (!drop_area.Contains(evt.mousePosition))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||
|
||||
if (evt.type == EventType.DragPerform)
|
||||
{
|
||||
DragAndDrop.AcceptDrag();
|
||||
if (DragAndDrop.objectReferences.Length > 0)
|
||||
{
|
||||
//Debug.Log("Name is " + DragAndDrop.objectReferences[0].name);
|
||||
//Debug.Log("Type is " + DragAndDrop.objectReferences[0].GetType());
|
||||
if (DragAndDrop.objectReferences[0].GetType() == typeof(UnityEngine.GameObject))
|
||||
{
|
||||
GameObject go = DragAndDrop.objectReferences[0] as GameObject;
|
||||
Spawner spawner = go.GetComponent<Spawner>();
|
||||
if (spawner != null)
|
||||
{
|
||||
//Only add spawners if we dont already have them
|
||||
for (int spIdx = 0; spIdx < m_spawnerList.Count; spIdx++)
|
||||
{
|
||||
if (m_spawnerList[spIdx].m_spawnerID == spawner.m_spawnerID && m_spawnerList[spIdx].name == spawner.name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_spawnerList.Add(spawner);
|
||||
|
||||
//Check for resources that arent already there as well
|
||||
if (m_resourceList.Count == 0)
|
||||
{
|
||||
m_resourceList.Add(spawner.m_settings.m_resources);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int resIdx = 0; resIdx < m_resourceList.Count; resIdx++)
|
||||
{
|
||||
if (m_resourceList[resIdx].m_resourcesID == spawner.m_settings.m_resources.m_resourcesID)// && m_resourceList[resIdx].name == spawner.m_settings.m_resources.name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_resourceList.Add(spawner.m_settings.m_resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If we got to here then we couldnt process it
|
||||
//Debug.LogWarning("Object type not supported by exporter. Ignored.");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Engine
|
||||
|
||||
private void SaveGX()
|
||||
{
|
||||
//Only do this if we have something to do
|
||||
if (m_resourceList.Count == 0 && m_spawnerList.Count == 0)
|
||||
{
|
||||
Debug.Log("No work to do - exiting.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Make sure we have basic exported extension directory
|
||||
string path = "Assets/GaiaExtensions/";
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
path = path + FixFileName(m_publisherName) + "_" + FixFileName(m_extensionName) + ".cs";
|
||||
|
||||
Template template;
|
||||
string hdrPath = PWCommon4.AssetUtils.GetAssetPath("GaiaXtnHeader", "txt");
|
||||
string ftrPath = PWCommon4.AssetUtils.GetAssetPath("GaiaXtnFooter", "txt");
|
||||
using (StreamWriter writer = File.CreateText(path))
|
||||
{
|
||||
//Write the generic header
|
||||
template = new Template(hdrPath, true);
|
||||
template.Set("ExtensionPublisher", FixFileName(m_publisherName) + "_" + FixFileName(m_extensionName));
|
||||
template.Set("ExtensionPublisherFull", m_publisherName);
|
||||
template.Set("ExtensionPackage", FixFileName(m_extensionName));
|
||||
template.Set("ExtensionPackageFull", m_extensionName);
|
||||
writer.Write(template.ToString());
|
||||
|
||||
//Export the About Box
|
||||
if (!string.IsNullOrEmpty(m_aboutText))
|
||||
{
|
||||
writer.WriteLine("\t\t");
|
||||
writer.WriteLine("\t\t#if UNITY_EDITOR");
|
||||
writer.WriteLine("\t\tpublic static void GX_About_About()");
|
||||
writer.WriteLine("\t\t{");
|
||||
writer.WriteLine("\t\t\tEditorUtility.DisplayDialog(\"About " + m_extensionName + "\", \"" + m_aboutText + "\", \"OK\");");
|
||||
writer.WriteLine("\t\t}");
|
||||
writer.WriteLine("\t\t#endif");
|
||||
}
|
||||
|
||||
//Export the resources
|
||||
foreach (GaiaResource resource in m_resourceList)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
resource.SetAssetAssociations();
|
||||
writer.WriteLine("\t\t");
|
||||
writer.WriteLine("\t\tpublic static void GX_Resources_Create" + FixFileName(resource.m_name) + "()");
|
||||
writer.WriteLine("\t\t{");
|
||||
writer.WriteLine(DumpObject(resource, "resource", 3));
|
||||
writer.WriteLine("\t\t");
|
||||
writer.WriteLine("\t\t\t#if UNITY_EDITOR");
|
||||
writer.WriteLine("\t\t\tstring path = \"Assets/GaiaExtensions/\";");
|
||||
writer.WriteLine("\t\t\tif (!Directory.Exists(path))");
|
||||
writer.WriteLine("\t\t\t{");
|
||||
writer.WriteLine("\t\t\t\tDirectory.CreateDirectory(path);");
|
||||
writer.WriteLine("\t\t\t}");
|
||||
writer.WriteLine("\t\t\t");
|
||||
writer.WriteLine("\t\t\tpath = Path.Combine(path, \"" + FixFileName(m_publisherName) + "\");");
|
||||
writer.WriteLine("\t\t\tif (!Directory.Exists(path))");
|
||||
writer.WriteLine("\t\t\t{");
|
||||
writer.WriteLine("\t\t\t\tDirectory.CreateDirectory(path);");
|
||||
writer.WriteLine("\t\t\t}");
|
||||
writer.WriteLine("\t\t\t");
|
||||
writer.WriteLine("\t\t\tpath = Path.Combine(path, \"" + FixFileName(m_extensionName) + "\");");
|
||||
writer.WriteLine("\t\t\tif (!Directory.Exists(path))");
|
||||
writer.WriteLine("\t\t\t{");
|
||||
writer.WriteLine("\t\t\t\tDirectory.CreateDirectory(path);");
|
||||
writer.WriteLine("\t\t\t}");
|
||||
writer.WriteLine("\t\t\t");
|
||||
writer.WriteLine("\t\t\tpath = Path.Combine(path, \"" + FixFileName(m_publisherName) + "_" + FixFileName(m_extensionName) + "_" + FixFileName(resource.m_name) + ".asset\");");
|
||||
writer.WriteLine("\t\t\tAssetDatabase.CreateAsset(resource, path);");
|
||||
writer.WriteLine("\t\t\tAssetDatabase.SaveAssets();");
|
||||
writer.WriteLine("\t\t\t#endif");
|
||||
writer.WriteLine("\t\t}");
|
||||
}
|
||||
|
||||
//Export the spawners
|
||||
foreach (Spawner spawner in m_spawnerList)
|
||||
{
|
||||
if (spawner == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
writer.WriteLine("\t\t");
|
||||
writer.WriteLine("\t\tpublic static void GX_Spawners_Create" + FixFileName(spawner.gameObject.name) + "()");
|
||||
writer.WriteLine("\t\t{");
|
||||
writer.WriteLine(DumpObject(spawner, "spawner", 3));
|
||||
writer.WriteLine("\t\t");
|
||||
writer.WriteLine("\t\t\tspawner.FitToTerrain();");
|
||||
writer.WriteLine("\t\t\tspawner.Initialise();");
|
||||
writer.WriteLine("\t\t");
|
||||
writer.WriteLine("\t\t\tGameObject gaiaObj = GameObject.Find(\"Gaia\");");
|
||||
writer.WriteLine("\t\t\tif (gaiaObj == null)");
|
||||
writer.WriteLine("\t\t\t{");
|
||||
writer.WriteLine("\t\t\t\tgaiaObj = new GameObject(\"Gaia\");");
|
||||
writer.WriteLine("\t\t\t}");
|
||||
writer.WriteLine("\t\t\tgo.transform.parent = gaiaObj.transform;");
|
||||
writer.WriteLine("\t\t}");
|
||||
}
|
||||
|
||||
//Write the generic footer
|
||||
template = new Template(ftrPath, true);
|
||||
writer.Write(template.ToString());
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove any characters that could cause issues from the input string
|
||||
/// </summary>
|
||||
/// <param name="source">The source string</param>
|
||||
/// <returns>A destination string with rubbish removed</returns>
|
||||
string FixFileName(string source)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char c in source)
|
||||
{
|
||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
|
||||
{
|
||||
sb.Append(c);
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract and save the resources file
|
||||
/// </summary>
|
||||
/// <param name="writer"></param>
|
||||
/// <param name="source"></param>
|
||||
//private void SaveResources(StreamWriter writer, GaiaResource source)
|
||||
//{
|
||||
// if (writer == null)
|
||||
// {
|
||||
// Debug.LogError("Can not write resources, writer not supplied.");
|
||||
// return;
|
||||
// }
|
||||
// if (source == null)
|
||||
// {
|
||||
// Debug.LogError("Can not write resources, resources not supplied.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //Create extraction path
|
||||
// string path = "Assets/GaiaExtensions/";
|
||||
// if (!Directory.Exists(path))
|
||||
// {
|
||||
// Directory.CreateDirectory(path);
|
||||
// }
|
||||
// path += m_extensionName + "/";
|
||||
// if (!Directory.Exists(path))
|
||||
// {
|
||||
// Directory.CreateDirectory(path);
|
||||
// }
|
||||
// path += Path.GetFileName(AssetDatabase.GetAssetPath(source.GetInstanceID()));
|
||||
|
||||
// GaiaResource resources = ScriptableObject.CreateInstance<Gaia.GaiaResource>();
|
||||
// AssetDatabase.CreateAsset(resources, path);
|
||||
// resources.m_beachHeight = source.m_beachHeight;
|
||||
// resources.m_name = source.m_name;
|
||||
// resources.m_resourcesID = source.m_resourcesID;
|
||||
// //resources.m_seaLevel = source.m_seaLevel;
|
||||
// resources.m_terrainHeight = source.m_terrainHeight;
|
||||
|
||||
// //Iterate through the prototypes
|
||||
// SpawnCritera srcCrit, newCrit;
|
||||
// ResourceProtoTexture srcTex, newTex;
|
||||
// resources.m_texturePrototypes = new ResourceProtoTexture[source.m_texturePrototypes.GetLength(0)];
|
||||
// for (int resIdx = 0; resIdx < source.m_texturePrototypes.GetLength(0); resIdx++ )
|
||||
// {
|
||||
// srcTex = source.m_texturePrototypes[resIdx];
|
||||
// newTex = new ResourceProtoTexture();
|
||||
// newTex.m_metallic = srcTex.m_metallic;
|
||||
// newTex.m_name = srcTex.m_name;
|
||||
// newTex.m_normal = srcTex.m_normal;
|
||||
// newTex.m_offsetX = srcTex.m_offsetX;
|
||||
// newTex.m_offsetY = srcTex.m_offsetY;
|
||||
// newTex.m_sizeX = srcTex.m_sizeX;
|
||||
// newTex.m_sizeY = srcTex.m_sizeY;
|
||||
// newTex.m_smoothness = srcTex.m_smoothness;
|
||||
// newTex.m_texture = srcTex.m_texture;
|
||||
|
||||
// newTex.m_spawnCriteria = new SpawnCritera[srcTex.m_spawnCriteria.GetLength(0)];
|
||||
// for (int critIdx = 0; critIdx < srcTex.m_spawnCriteria.GetLength(0); critIdx++ )
|
||||
// {
|
||||
// srcCrit = srcTex.m_spawnCriteria[critIdx];
|
||||
|
||||
// newCrit = new SpawnCritera();
|
||||
// newCrit.m_checkHeight = srcCrit.m_checkHeight;
|
||||
// newCrit.m_checkProximity = srcCrit.m_checkProximity;
|
||||
// newCrit.m_checkSlope = srcCrit.m_checkSlope;
|
||||
// newCrit.m_checkTexture = srcCrit.m_checkTexture;
|
||||
// newCrit.m_checkType = srcCrit.m_checkType;
|
||||
// newCrit.m_heightFitness = srcCrit.m_heightFitness;
|
||||
// newCrit.m_isActive = srcCrit.m_isActive;
|
||||
// newCrit.m_matchingTextures = srcCrit.m_matchingTextures;
|
||||
// newCrit.m_maxHeight = srcCrit.m_maxHeight;
|
||||
|
||||
// newTex.m_spawnCriteria[critIdx] = newCrit;
|
||||
// }
|
||||
// resources.m_texturePrototypes[resIdx] = newTex;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write the content of the object out as C#, and assign the content of the original object to it
|
||||
/// </summary>
|
||||
/// <param name="src">Object to dump</param>
|
||||
/// <param name="name">Name of the variable to dump it to</param>
|
||||
/// <param name="tabDepth">Number of prefix tabs to prepend to each line</param>
|
||||
/// <param name="prefixType">Show the type of the object when creating it</param>
|
||||
/// <param name="instantiate">Write code to instantiate the object</param>
|
||||
/// <returns></returns>
|
||||
private string DumpObject(object src, string name, int tabDepth, bool prefixType = true, bool instantiate = true)
|
||||
{
|
||||
if (src == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder retS = new StringBuilder();
|
||||
FieldInfo[] fields = src.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
string tabs = "";
|
||||
for (int td = 0; td < tabDepth; td++ )
|
||||
{
|
||||
tabs += "\t";
|
||||
}
|
||||
|
||||
if (instantiate)
|
||||
{
|
||||
if (!prefixType)
|
||||
{
|
||||
if (src.GetType().BaseType == typeof(UnityEngine.ScriptableObject))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{2} = ScriptableObject.CreateInstance<{1}>();", tabs, src.GetType(), name));
|
||||
}
|
||||
else if (src.GetType().BaseType == typeof(UnityEngine.MonoBehaviour))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{2} = {2}.AddComponent<{1}>();", tabs, src.GetType(), name));
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1} = new {2}();", tabs, name, src.GetType()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (src.GetType().BaseType == typeof(UnityEngine.ScriptableObject))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1} {2} = ScriptableObject.CreateInstance<{1}>();", tabs, src.GetType(), name));
|
||||
}
|
||||
else if (src.GetType().BaseType == typeof(UnityEngine.MonoBehaviour))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}GameObject go = new GameObject();", tabs));
|
||||
retS.AppendLine(string.Format("{0}go.name = \"{1}\";", tabs, ((UnityEngine.MonoBehaviour)src).gameObject.name));
|
||||
retS.AppendLine(string.Format("{0}{1} {2} = go.AddComponent<{1}>();", tabs, src.GetType(), name));
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1} {2} = new {1}();", tabs, src.GetType(), name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (FieldInfo f in fields)
|
||||
{
|
||||
if (f.FieldType == typeof(System.String))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = \"{3}\";", tabs, name, f.Name, f.GetValue(src)));
|
||||
}
|
||||
else if (f.FieldType == typeof(System.Single))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = {3}f;", tabs, name, f.Name, f.GetValue(src)));
|
||||
}
|
||||
else if (f.FieldType == typeof(System.Double))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = {3};", tabs, name, f.Name, f.GetValue(src)));
|
||||
}
|
||||
else if (f.FieldType == typeof(System.Int32) || f.FieldType == typeof(System.UInt32) || f.FieldType == typeof(System.Int64) || f.FieldType == typeof(System.UInt64))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = {3};", tabs, name, f.Name, f.GetValue(src)));
|
||||
}
|
||||
else if (f.FieldType == typeof(System.Boolean))
|
||||
{
|
||||
//Debug.Log(name + " " + f.Name + " " + f.FieldType + " " + f.GetValue(src).ToString());
|
||||
if (f.GetValue(src).ToString() == "True")
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = true;", tabs, name, f.Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = false;", tabs, name, f.Name));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType == typeof(UnityEngine.Texture2D))
|
||||
{
|
||||
if (((UnityEngine.Texture2D)f.GetValue(src)) != null)
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = GetTexture2D(\"{3}\");", tabs, name, f.Name, AssetDatabase.GetAssetPath(((UnityEngine.Texture2D)f.GetValue(src)).GetInstanceID())));
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = null;", tabs, name, f.Name));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType == typeof(UnityEngine.AnimationCurve))
|
||||
{
|
||||
if (((UnityEngine.AnimationCurve)f.GetValue(src)) != null)
|
||||
{
|
||||
UnityEngine.AnimationCurve curve = ((UnityEngine.AnimationCurve)f.GetValue(src));
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = new UnityEngine.AnimationCurve();", tabs, name, f.Name));
|
||||
foreach(Keyframe frame in curve.keys)
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2}.AddKey({3}f,{4}f);", tabs, name, f.Name, frame.time, frame.value));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = null;", tabs, name, f.Name));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType == typeof(UnityEngine.Color))
|
||||
{
|
||||
Color c = ((UnityEngine.Color)f.GetValue(src));
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = new UnityEngine.Color({3}f,{4}f,{5}f,{6}f);", tabs, name, f.Name, c.r, c.b, c.g, c.a));
|
||||
}
|
||||
else if (f.FieldType == typeof(UnityEngine.GameObject))
|
||||
{
|
||||
if (((UnityEngine.GameObject)f.GetValue(src)) != null)
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = GetGameObject(\"{3}\");", tabs, name, f.Name, AssetDatabase.GetAssetPath(((UnityEngine.GameObject)f.GetValue(src)).GetInstanceID())));
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = null;", tabs, name, f.Name));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType.IsEnum == true)
|
||||
{
|
||||
string enumValue = "";
|
||||
foreach (var value in Enum.GetValues(f.FieldType))
|
||||
{
|
||||
if ((int)value == (int)f.GetValue(src))
|
||||
{
|
||||
enumValue = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = {3}.{4};", tabs, name, f.Name, f.FieldType.ToString().Replace("+","."), enumValue));
|
||||
}
|
||||
else if (f.FieldType == typeof(Gaia.SpawnRuleExtension[]))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = new {3}[{4}];", tabs, name, f.Name, f.FieldType.ToString().Replace("[]", ""), ((System.Array)f.GetValue(src)).GetLength(0)));
|
||||
for (int idx = 0; idx < ((System.Array)f.GetValue(src)).GetLength(0); idx++)
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}\t{1}.{2}[{3}] = GetSpawnRuleExtension(\"{4}\");", tabs, name, f.Name, idx, AssetDatabase.GetAssetPath(((Gaia.SpawnRuleExtension)(((System.Array)f.GetValue(src)).GetValue(idx))).GetInstanceID())));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType == typeof(Gaia.ResourceProtoDNA))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = new {3}();", tabs, name, f.Name, f.FieldType.ToString().Replace("[]", "")));
|
||||
retS.Append(DumpObject(f.GetValue(src), string.Format("{0}.{1}", name, f.Name), tabDepth+1, false, false));
|
||||
}
|
||||
else if (f.FieldType == typeof(Gaia.XorshiftPlus))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = new {3}();", tabs, name, f.Name, f.FieldType.ToString().Replace("[]", "")));
|
||||
retS.Append(DumpObject(f.GetValue(src), string.Format("{0}.{1}", name, f.Name), tabDepth + 1, false, false));
|
||||
}
|
||||
else if (f.FieldType == typeof(Gaia.GaiaResource))
|
||||
{
|
||||
GaiaResource resource = ((Gaia.GaiaResource)f.GetValue(src));
|
||||
if (resource != null)
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = GetResource(\"{3}\",\"{4}\");", tabs, name, f.Name,
|
||||
FixFileName(m_publisherName) + "_" + FixFileName(m_extensionName) + "_" + FixFileName(resource.m_name) + ".asset",
|
||||
resource.m_resourcesID));
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = null;", tabs, name, f.Name));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType.IsGenericType == true)
|
||||
{
|
||||
string type = f.FieldType.ToString();
|
||||
if (type.Contains("System.Collections.Generic.List"))
|
||||
{
|
||||
type = type.Substring(type.IndexOf("[") + 1);
|
||||
type = type.Substring(0, type.IndexOf("]"));
|
||||
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = new List<{3}>();", tabs, name, f.Name, type));
|
||||
|
||||
int idx = 0;
|
||||
IEnumerator enumerator = ((ICollection)f.GetValue(src)).GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2}.Add(new {3}());", tabs, name, f.Name, type));
|
||||
retS.Append(DumpObject(enumerator.Current , string.Format("{0}.{1}[{2}]", name, f.Name, idx++), tabDepth + 1, false, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}// ******* {1} {2} = {3};", tabs, name, f.FieldType, f.Name, f.GetValue(src)));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType.BaseType == typeof(System.Array))
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}{1}.{2} = new {3}[{4}];", tabs, name, f.Name, f.FieldType.ToString().Replace("[]",""), ((System.Array)f.GetValue(src)).GetLength(0)));
|
||||
for (int idx = 0; idx < ((System.Array)f.GetValue(src)).GetLength(0); idx++)
|
||||
{
|
||||
retS.Append(DumpObject(((System.Array)f.GetValue(src)).GetValue(idx), string.Format("{0}.{1}[{2}]", name, f.Name, idx), tabDepth+1, false));
|
||||
}
|
||||
}
|
||||
else if (f.FieldType == typeof(Gaia.HeightMap) || f.FieldType == typeof(Gaia.UnityHeightMap))
|
||||
{
|
||||
//Dont export
|
||||
}
|
||||
else if (f.FieldType == typeof(UnityEngine.Transform))
|
||||
{
|
||||
//Dont export
|
||||
}
|
||||
else if (f.FieldType == typeof(UnityEngine.LayerMask))
|
||||
{
|
||||
//Dont export
|
||||
}
|
||||
else if (f.FieldType == typeof(System.Random))
|
||||
{
|
||||
//Dont export
|
||||
}
|
||||
else if (f.FieldType == typeof(System.Collections.IEnumerator))
|
||||
{
|
||||
//Dont export
|
||||
}
|
||||
else if (f.FieldType == typeof(UnityEngine.Bounds))
|
||||
{
|
||||
//Dont export
|
||||
}
|
||||
else
|
||||
{
|
||||
retS.AppendLine(string.Format("{0}// ******* {1} {2} = {3};", tabs, name, f.FieldType, f.Name, f.GetValue(src)));
|
||||
}
|
||||
}
|
||||
return retS.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Prototyping
|
||||
|
||||
/// <summary>
|
||||
/// Get the resource from the ID provided
|
||||
/// </summary>
|
||||
/// <param name="path">Resource with the given ID to check</param>
|
||||
/// <param name="id">Resource with the given ID to check</param>
|
||||
/// <returns>Resource if found or null</returns>
|
||||
//public static Gaia.GaiaResource GetResource(string path, string id)
|
||||
//{
|
||||
// Gaia.GaiaResource resource = null;
|
||||
|
||||
// #if UNITY_EDITOR
|
||||
// string fileName = Path.GetFileNameWithoutExtension(path);
|
||||
// resource = (GaiaResource)PWCommon1.AssetUtils.GetAssetScriptableObject(fileName);
|
||||
// #endif
|
||||
|
||||
// return resource;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Scaffolding
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Fit To Terrain", "Fits and aligns the spawner to the terrain." },
|
||||
{ "Reset", "Resets the spawner, deletes any spawned game objects, and resets the random number generator." },
|
||||
{ "Spawn", "Run a single spawn iteration. You can run as many spawn iterations as you like." },
|
||||
};
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dfb210361a4df541bf13bfc2c309476
|
||||
timeCreated: 1452537000
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,135 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to export texture layers as masks
|
||||
/// </summary>
|
||||
public class GaiaGrassMaskExporterEditor : EditorWindow
|
||||
{
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private string m_maskName;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("Gaia Grass Mask Exporter", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("The Gaia grass mask exporter allows you to export grass splatmaps to use as masks.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (string.IsNullOrEmpty(m_maskName))
|
||||
{
|
||||
m_maskName = string.Format("Terrain-Grassmaps-{0:yyyyMMdd-HHmmss}", DateTime.Now);
|
||||
}
|
||||
m_maskName = EditorGUILayout.TextField(GetLabel("Mask Name"), m_maskName);
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (DisplayButton(GetLabel("Export Mask")))
|
||||
{
|
||||
ExportMask();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void ExportMask()
|
||||
{
|
||||
GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);
|
||||
if (mgr.TileCount > 0)
|
||||
{
|
||||
GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();
|
||||
string path = GaiaDirectories.GetExportDirectory(gsm.m_session);
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
path = Path.Combine(path, PWCommon4.Utils.FixFileName(m_maskName));
|
||||
mgr.ExportGrassmapAsPng(path);
|
||||
Debug.Log("Created " + path);
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.DisplayDialog("Export complete", " Your gass mask has been saved to : " + path, "OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("OOPS!", "You must have a valid terrain!!", "OK");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a button that takes editor indentation into account
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
bool DisplayButton(GUIContent content)
|
||||
{
|
||||
TextAnchor oldalignment = GUI.skin.button.alignment;
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
Rect btnR = EditorGUILayout.BeginHorizontal();
|
||||
btnR.xMin += (EditorGUI.indentLevel * 18f);
|
||||
btnR.height += 20f;
|
||||
btnR.width -= 4f;
|
||||
bool result = GUI.Button(btnR, content);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space(22);
|
||||
GUI.skin.button.alignment = oldalignment;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Execution Mode", "The way this spawner runs. Design time : At design time only. Runtime Interval : At run time on a timed interval. Runtime Triggered Interval : At run time on a timed interval, and only when the tagged game object is closer than the trigger range from the center of the spawner." },
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cd28ae432be2cd4b850529548d4268e
|
||||
timeCreated: 1456379518
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b96c32e0975b0a4bb026688e3bd7787
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,170 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using ProceduralWorlds.HierachySystem;
|
||||
using UnityEngine.Assertions.Must;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(GaiaHierarchyUtils))]
|
||||
public class GaiaHierarchyUtilsEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
private GaiaHierarchyUtils m_profile;
|
||||
private bool m_settingsChangedInfo;
|
||||
private Color m_guiBackground;
|
||||
private Color m_redGUI = new Color(0.905f, 0.415f, 0.396f, 1f);
|
||||
private Color m_greenGUI = new Color(0.696f, 0.905f, 0.397f, 1f);
|
||||
private Color m_orangeGUI = new Color(1.0f, 0.394f, 0.0f, 1f);
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//Get GaiaHierarchyUtils Profile object
|
||||
m_profile = (GaiaHierarchyUtils)target;
|
||||
|
||||
//Gets all the objects
|
||||
m_profile.UpdateParentObjects();
|
||||
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
|
||||
m_guiBackground = GUI.backgroundColor;
|
||||
m_settingsChangedInfo = false;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Initialization
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
if (m_profile == null)
|
||||
{
|
||||
//Get GaiaHierarchyUtils Profile object
|
||||
m_profile = (GaiaHierarchyUtils)target;
|
||||
}
|
||||
|
||||
//Monitor for changes
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
m_editorUtils.Panel("GlobalSettings", GlobalSettings, true);
|
||||
|
||||
//Check for changes, make undo record, make changes and let editor know we are dirty
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(m_profile, "Made changes");
|
||||
EditorUtility.SetDirty(m_profile);
|
||||
|
||||
m_profile.SetupHideInHierarchy();
|
||||
m_settingsChangedInfo = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the current settings by selecting the parent terrain, which forces an update of the scene view.
|
||||
/// </summary>
|
||||
public void ApplyNow()
|
||||
{
|
||||
Selection.activeObject = m_profile.transform.parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Global settings
|
||||
/// </summary>
|
||||
/// <param name="helpEnabled"></param>
|
||||
private void GlobalSettings(bool helpEnabled)
|
||||
{
|
||||
//m_profile.m_hideAllParentsInHierarchy = m_editorUtils.ToggleLeft("HideAllParentsInHierarchy", m_profile.m_hideAllParentsInHierarchy, helpEnabled);
|
||||
|
||||
if (m_profile.m_visibilityEntries != null)
|
||||
{
|
||||
int count = m_profile.m_visibilityEntries.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("No Objects found below this object to use this system please spawn some game objects to use the hide system.", MessageType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.backgroundColor = m_orangeGUI;
|
||||
if (m_settingsChangedInfo)
|
||||
{
|
||||
if (m_editorUtils.Button("ApplyNow"))
|
||||
{
|
||||
ApplyNow();
|
||||
}
|
||||
}
|
||||
GUI.backgroundColor = m_guiBackground;
|
||||
GUIContent checkboxContent = m_editorUtils.GetContent("CheckboxTooltip");
|
||||
foreach (GaiaHierarchyVisibility ghv in m_profile.m_visibilityEntries)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
ghv.m_isVisible = m_editorUtils.Toggle(ghv.m_isVisible, checkboxContent, GUILayout.Width(20));
|
||||
GUILayout.Label(ghv.m_name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUI.backgroundColor = m_orangeGUI;
|
||||
if (m_settingsChangedInfo)
|
||||
{
|
||||
if (m_editorUtils.Button("ApplyNow"))
|
||||
{
|
||||
ApplyNow();
|
||||
}
|
||||
}
|
||||
GUI.backgroundColor = m_guiBackground;
|
||||
|
||||
GUI.backgroundColor = m_redGUI;
|
||||
if (m_editorUtils.Button("HideAll"))
|
||||
{
|
||||
foreach (GaiaHierarchyVisibility ghv in m_profile.m_visibilityEntries)
|
||||
{
|
||||
ghv.m_isVisible = false;
|
||||
}
|
||||
m_profile.SetupHideInHierarchy();
|
||||
}
|
||||
|
||||
GUI.backgroundColor = m_greenGUI;
|
||||
if (m_editorUtils.Button("ShowAll"))
|
||||
{
|
||||
foreach (GaiaHierarchyVisibility ghv in m_profile.m_visibilityEntries)
|
||||
{
|
||||
ghv.m_isVisible = true;
|
||||
}
|
||||
m_profile.SetupHideInHierarchy();
|
||||
}
|
||||
|
||||
//EditorGUILayout.LabelField("Object count in parent: " + count);
|
||||
//if (m_profile.m_hideAllParentsInHierarchy)
|
||||
//{
|
||||
// GUI.backgroundColor = m_redGUI;
|
||||
// if (m_editorUtils.Button("Show"))
|
||||
// {
|
||||
// m_profile.m_hideAllParentsInHierarchy = false;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
GUI.backgroundColor = m_guiBackground;
|
||||
|
||||
//m_editorUtils.InlineHelp("HideAllParentsInHierarchy", helpEnabled);
|
||||
|
||||
if (m_editorUtils.Button("ConfigureAllInScene"))
|
||||
{
|
||||
m_profile.SetupAllHideInHierarchy();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.LabelField("Object count in parent: 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd92c909d33a13f42aaaaa07df0f8459
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,673 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
#if LWPipeline
|
||||
using UnityEngine.Rendering.LWRP;
|
||||
#endif
|
||||
using System.Collections;
|
||||
using UnityEditor.SceneManagement;
|
||||
using ProceduralWorlds.WaterSystem;
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
#endif
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Gaia.Pipeline.LWRP
|
||||
{
|
||||
/// <summary>
|
||||
/// Static class that handles all the LWRP setup in Gaia
|
||||
/// </summary>
|
||||
public static class GaiaLWRPPipelineUtils
|
||||
{
|
||||
public static float m_waitTimer1 = 1f;
|
||||
public static float m_waitTimer2 = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Configures project for LWRP
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
private static void ConfigureSceneToLWRP(UnityPipelineProfile profile)
|
||||
{
|
||||
GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings();
|
||||
if (gaiaSettings.m_currentRenderer != GaiaConstants.EnvironmentRenderer.Lightweight)
|
||||
{
|
||||
Debug.LogError("Unable to configure your scene/project to LWRP as the current render inside of gaia does not equal Lightweight as it's active render pipeline. This process [GaiaLWRPPipelineUtils.ConfigureSceneToLWRP()] will now exit.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.m_setLWPipelineProfile)
|
||||
{
|
||||
SetPipelineAsset(profile);
|
||||
}
|
||||
|
||||
if (profile.m_LWAutoConfigureCamera)
|
||||
{
|
||||
ConfigureCamera();
|
||||
}
|
||||
|
||||
if (profile.m_LWAutoConfigureLighting)
|
||||
{
|
||||
ConfigureLighting(gaiaSettings.m_gaiaLightingProfile);
|
||||
}
|
||||
|
||||
if (profile.m_LWAutoConfigureWater)
|
||||
{
|
||||
ConfigureWater(profile, gaiaSettings);
|
||||
}
|
||||
|
||||
if (profile.m_LWAutoConfigureProbes)
|
||||
{
|
||||
ConfigureReflectionProbes();
|
||||
}
|
||||
|
||||
if (profile.m_LWAutoConfigureTerrain)
|
||||
{
|
||||
ConfigureTerrain(profile);
|
||||
}
|
||||
|
||||
FinalizeLWRP(profile, gaiaSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures scripting defines in the project
|
||||
/// </summary>
|
||||
public static void SetScriptingDefines(UnityPipelineProfile profile)
|
||||
{
|
||||
bool isChanged = false;
|
||||
string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (!currBuildSettings.Contains("LWPipeline"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(currBuildSettings))
|
||||
{
|
||||
currBuildSettings = "LWPipeline";
|
||||
}
|
||||
else
|
||||
{
|
||||
currBuildSettings += ";LWPipeline";
|
||||
}
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (currBuildSettings.Contains("HDPipeline"))
|
||||
{
|
||||
currBuildSettings = currBuildSettings.Replace("HDPipeline;", "");
|
||||
currBuildSettings = currBuildSettings.Replace("HDPipeline", "");
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the pipeline asset to the procedural worlds asset if the profile is set yo change it
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
public static void SetPipelineAsset(UnityPipelineProfile profile)
|
||||
{
|
||||
if (GraphicsSettings.renderPipelineAsset == null)
|
||||
{
|
||||
GaiaPackageVersion unityVersion = GaiaPackageVersion.Unity2019_1;
|
||||
|
||||
//Installation setup
|
||||
if (Application.unityVersion.Contains("2019.2"))
|
||||
{
|
||||
unityVersion = GaiaPackageVersion.Unity2019_2;
|
||||
}
|
||||
else if (Application.unityVersion.Contains("2019.3"))
|
||||
{
|
||||
unityVersion = GaiaPackageVersion.Unity2019_3;
|
||||
}
|
||||
|
||||
UnityVersionPipelineAsset mapping = profile.m_lightweightPipelineProfiles.Find(x => x.m_unityVersion == unityVersion);
|
||||
string pipelineAssetName = "";
|
||||
|
||||
if (mapping != null)
|
||||
{
|
||||
pipelineAssetName = mapping.m_pipelineAssetName;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Could not determine the correct render pipeline settings asset for this unity version / rendering pipeline!");
|
||||
return;
|
||||
}
|
||||
|
||||
GraphicsSettings.renderPipelineAsset = AssetDatabase.LoadAssetAtPath<RenderPipelineAsset>(GetAssetPath(pipelineAssetName));
|
||||
}
|
||||
|
||||
profile.m_pipelineSwitchUpdates = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures camera to LWRP
|
||||
/// </summary>
|
||||
private static void ConfigureCamera()
|
||||
{
|
||||
Camera camera = GetCamera();
|
||||
if (camera == null)
|
||||
{
|
||||
Debug.LogWarning("[GaiaLWRPPipelineUtils.ConfigureCamera()] A camera could not be found to upgrade in your scene.");
|
||||
}
|
||||
else
|
||||
{
|
||||
#if LWPipeline
|
||||
LWRPAdditionalCameraData cameraData = camera.gameObject.GetComponent<LWRPAdditionalCameraData>();
|
||||
if (cameraData == null)
|
||||
{
|
||||
cameraData = camera.gameObject.AddComponent<LWRPAdditionalCameraData>();
|
||||
cameraData.renderShadows = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cameraData.renderShadows = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures lighting to LWRP
|
||||
/// </summary>
|
||||
private static void ConfigureLighting(GaiaLightingProfile profile)
|
||||
{
|
||||
#if LWPipeline
|
||||
LWRPAdditionalLightData[] lightsData = Object.FindObjectsOfType<LWRPAdditionalLightData>();
|
||||
if (lightsData != null)
|
||||
{
|
||||
foreach (LWRPAdditionalLightData data in lightsData)
|
||||
{
|
||||
if (data.gameObject.GetComponent<LWRPAdditionalLightData>() == null)
|
||||
{
|
||||
data.gameObject.AddComponent<LWRPAdditionalLightData>();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (profile.m_antiAliasingMode == GaiaConstants.GaiaProAntiAliasingMode.TAA)
|
||||
{
|
||||
EditorUtility.SetDirty(profile);
|
||||
profile.m_antiAliasingMode = GaiaConstants.GaiaProAntiAliasingMode.FXAA;
|
||||
Debug.Log("Antialiasing mode has been switched to FXAA. TAA in LWRP is not supported. You can change the Antialiasing mode in the Lighting profile if you wish to use a different mode.");
|
||||
|
||||
SetAntiAliasingMode(profile.m_antiAliasingMode);
|
||||
}
|
||||
|
||||
SetMotionBlurPostFX(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the sun intensity
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <param name="volumeProfile"></param>
|
||||
public static void SetSunSettings(Light light, GaiaLightingProfileValues profile)
|
||||
{
|
||||
if (light == null)
|
||||
{
|
||||
light = GetSunLight();
|
||||
}
|
||||
|
||||
if (profile.m_useKelvin)
|
||||
{
|
||||
profile.m_lWSunColor = GaiaUtils.ExecuteKelvinColor(profile.m_kelvinValue);
|
||||
}
|
||||
if (light != null)
|
||||
{
|
||||
light.color = profile.m_lWSunColor;
|
||||
light.intensity = profile.m_lWSunIntensity;
|
||||
light.shadows = profile.m_shadowCastingMode;
|
||||
light.shadowStrength = profile.m_shadowStrength;
|
||||
light.shadowResolution = profile.m_sunShadowResolution;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures water to LWRP
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
private static void ConfigureWater(UnityPipelineProfile profile, GaiaSettings gaiaSettings)
|
||||
{
|
||||
if (gaiaSettings == null)
|
||||
{
|
||||
Debug.LogError("Gaia settings could not be found. Please make sure gaia settings is import into your project");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (profile.m_underwaterHorizonMaterial != null)
|
||||
{
|
||||
profile.m_underwaterHorizonMaterial.shader = Shader.Find(profile.m_lightweightHorizonObjectShader);
|
||||
}
|
||||
|
||||
//Increasing Water mesh quality for LWRP
|
||||
gaiaSettings.m_gaiaWaterProfile.m_customMeshQuality = 8;
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaWater.UpdateWaterMeshQuality(GaiaGlobal.Instance.SceneProfile, GaiaGlobal.Instance.SceneProfile.m_waterPrefab);
|
||||
}
|
||||
|
||||
GameObject waterObject = GameObject.Find(gaiaSettings.m_gaiaWaterProfile.m_waterPrefab.name);
|
||||
if (waterObject != null)
|
||||
{
|
||||
Material waterMat = GaiaWater.GetGaiaOceanMaterial();
|
||||
if (waterMat != null)
|
||||
{
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaWater.GetProfile(0, waterMat, GaiaGlobal.Instance.SceneProfile, true, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Material could not be found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PWS_WaterSystem reflection = Object.FindObjectOfType<PWS_WaterSystem>();
|
||||
if (reflection != null)
|
||||
{
|
||||
Object.DestroyImmediate(reflection);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures reflections to LWRP
|
||||
/// </summary>
|
||||
private static void ConfigureReflectionProbes()
|
||||
{
|
||||
ReflectionProbe[] reflectionProbes = Object.FindObjectsOfType<ReflectionProbe>();
|
||||
if (reflectionProbes != null)
|
||||
{
|
||||
foreach(ReflectionProbe probe in reflectionProbes)
|
||||
{
|
||||
if (probe.resolution > 512)
|
||||
{
|
||||
Debug.Log(probe.name + " This probes resolution is quite high and could cause performance issues in Lightweight Pipeline. Recommend lowing the resolution if you're targeting mobile platform");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures and setup the terrain
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
private static void ConfigureTerrain(UnityPipelineProfile profile)
|
||||
{
|
||||
Terrain[] terrains = Terrain.activeTerrains;
|
||||
if (terrains != null)
|
||||
{
|
||||
foreach (Terrain terrain in terrains)
|
||||
{
|
||||
#if !UNITY_2019_2_OR_NEWER
|
||||
terrain.materialType = Terrain.MaterialType.Custom;
|
||||
#endif
|
||||
terrain.materialTemplate = profile.m_lightweightTerrainMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes the LWRP setup for your project
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
private static void FinalizeLWRP(UnityPipelineProfile profile, GaiaSettings gaiaSettings)
|
||||
{
|
||||
MarkSceneDirty(true);
|
||||
EditorUtility.SetDirty(profile);
|
||||
profile.m_activePipelineInstalled = GaiaConstants.EnvironmentRenderer.Lightweight;
|
||||
|
||||
GaiaManagerEditor manager = EditorWindow.GetWindow<Gaia.GaiaManagerEditor>(false, "Gaia Manager");
|
||||
if (manager != null)
|
||||
{
|
||||
manager.GaiaManagerStatusCheck(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans up LWRP components in the scene
|
||||
/// </summary>
|
||||
public static void CleanUpLWRP(UnityPipelineProfile profile, GaiaSettings gaiaSettings)
|
||||
{
|
||||
#if LWPipeline
|
||||
LWRPAdditionalCameraData[] camerasData = Object.FindObjectsOfType<LWRPAdditionalCameraData>();
|
||||
if (camerasData != null)
|
||||
{
|
||||
foreach (LWRPAdditionalCameraData data in camerasData)
|
||||
{
|
||||
Object.DestroyImmediate(data);
|
||||
}
|
||||
}
|
||||
|
||||
LWRPAdditionalLightData[] lightsData = Object.FindObjectsOfType<LWRPAdditionalLightData>();
|
||||
if (lightsData != null)
|
||||
{
|
||||
foreach (LWRPAdditionalLightData data in lightsData)
|
||||
{
|
||||
Object.DestroyImmediate(data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (profile.m_underwaterHorizonMaterial != null)
|
||||
{
|
||||
profile.m_underwaterHorizonMaterial.shader = Shader.Find(profile.m_builtInHorizonObjectShader);
|
||||
}
|
||||
|
||||
//reverting default water mesh quality
|
||||
gaiaSettings.m_gaiaWaterProfile.m_customMeshQuality = 2;
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaWater.UpdateWaterMeshQuality(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_gaiaWaterProfile.m_waterPrefab);
|
||||
}
|
||||
|
||||
GameObject waterPrefab = GameObject.Find(gaiaSettings.m_gaiaWaterProfile.m_waterPrefab.name);
|
||||
if (waterPrefab != null)
|
||||
{
|
||||
PWS_WaterSystem reflection = waterPrefab.GetComponent<PWS_WaterSystem>();
|
||||
if (reflection == null)
|
||||
{
|
||||
reflection = waterPrefab.AddComponent<PWS_WaterSystem>();
|
||||
}
|
||||
}
|
||||
|
||||
Terrain[] terrains = Terrain.activeTerrains;
|
||||
if (terrains != null)
|
||||
{
|
||||
foreach (Terrain terrain in terrains)
|
||||
{
|
||||
#if !UNITY_2019_2_OR_NEWER
|
||||
terrain.materialType = Terrain.MaterialType.BuiltInStandard;
|
||||
#else
|
||||
terrain.materialTemplate = profile.m_builtInTerrainMaterial;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Terrain terrainDetail = Terrain.activeTerrain;
|
||||
if (terrainDetail != null)
|
||||
{
|
||||
if (terrainDetail.detailObjectDensity == 0f)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Detail Density Disabled!", "Details density is disabled on your terrain would you like to activate it?", "Yes", "No"))
|
||||
{
|
||||
terrainDetail.detailObjectDensity = 0.3f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameObject LWRPReflections = GameObject.Find("LWRP Water Reflection Probe");
|
||||
if (LWRPReflections != null)
|
||||
{
|
||||
Object.DestroyImmediate(LWRPReflections);
|
||||
}
|
||||
|
||||
GraphicsSettings.renderPipelineAsset = null;
|
||||
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaUtils.GetRuntimeSceneObject();
|
||||
GaiaLighting.GetProfile(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_pipelineProfile, GaiaConstants.EnvironmentRenderer.BuiltIn);
|
||||
}
|
||||
|
||||
if (waterPrefab != null)
|
||||
{
|
||||
Material waterMat = GaiaWater.GetGaiaOceanMaterial();
|
||||
if (waterMat != null)
|
||||
{
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaWater.GetProfile(0, waterMat, GaiaGlobal.Instance.SceneProfile, true, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Material could not be found");
|
||||
}
|
||||
}
|
||||
|
||||
MarkSceneDirty(false);
|
||||
EditorUtility.SetDirty(profile);
|
||||
profile.m_activePipelineInstalled = GaiaConstants.EnvironmentRenderer.BuiltIn;
|
||||
|
||||
GaiaManagerEditor manager = EditorWindow.GetWindow<Gaia.GaiaManagerEditor>(false, "Gaia Manager");
|
||||
if (manager != null)
|
||||
{
|
||||
manager.GaiaManagerStatusCheck(true);
|
||||
}
|
||||
|
||||
bool isChanged = false;
|
||||
string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (currBuildSettings.Contains("LWPipeline"))
|
||||
{
|
||||
currBuildSettings = currBuildSettings.Replace("LWPipeline;", "");
|
||||
currBuildSettings = currBuildSettings.Replace("LWPipeline", "");
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables motion blur
|
||||
/// </summary>
|
||||
/// <param name="enabled"></param>
|
||||
private static void SetMotionBlurPostFX(bool enabled)
|
||||
{
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
//Create profile list
|
||||
List<PostProcessProfile> postProcessProfiles = new List<PostProcessProfile>();
|
||||
//Clear List
|
||||
postProcessProfiles.Clear();
|
||||
|
||||
//All volumes in scene
|
||||
PostProcessVolume[] postProcessVolumes = Object.FindObjectsOfType<PostProcessVolume>();
|
||||
if (postProcessVolumes != null)
|
||||
{
|
||||
foreach(PostProcessVolume volume in postProcessVolumes)
|
||||
{
|
||||
//Check it has a profile
|
||||
if (volume.sharedProfile != null)
|
||||
{
|
||||
//Add the profile to array
|
||||
postProcessProfiles.Add(volume.sharedProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (postProcessProfiles != null)
|
||||
{
|
||||
//Motion blur
|
||||
foreach (PostProcessProfile profile in postProcessProfiles)
|
||||
{
|
||||
//Check if profile has setting
|
||||
if (profile.TryGetSettings(out UnityEngine.Rendering.PostProcessing.MotionBlur motionBlur))
|
||||
{
|
||||
|
||||
EditorUtility.SetDirty(profile);
|
||||
//Set ture/false based on input
|
||||
motionBlur.active = enabled;
|
||||
motionBlur.enabled.value = enabled;
|
||||
|
||||
Debug.Log(profile.name + ": Motion blur has been disabled in this profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the AA mode ont he camera
|
||||
/// </summary>
|
||||
/// <param name="antiAliasingMode"></param>
|
||||
private static void SetAntiAliasingMode(GaiaConstants.GaiaProAntiAliasingMode antiAliasingMode)
|
||||
{
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
PostProcessLayer processLayer = Object.FindObjectOfType<PostProcessLayer>();
|
||||
if (processLayer != null)
|
||||
{
|
||||
Camera camera = Camera.main;
|
||||
switch (antiAliasingMode)
|
||||
{
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.None:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.None;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.FXAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.FastApproximateAntialiasing;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.MSAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.None;
|
||||
camera.allowMSAA = true;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.SMAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.TAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.TemporalAntialiasing;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets and returns the main camera in the scene
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static Camera GetCamera()
|
||||
{
|
||||
Camera camera = Camera.main;
|
||||
if (camera != null)
|
||||
{
|
||||
return camera;
|
||||
}
|
||||
|
||||
camera = Object.FindObjectOfType<Camera>();
|
||||
if (camera != null)
|
||||
{
|
||||
return camera;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets and returns the sun light in the scene
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static Light GetSunLight()
|
||||
{
|
||||
Light light = null;
|
||||
GameObject lightObject = GameObject.Find("Directional Light");
|
||||
if (lightObject != null)
|
||||
{
|
||||
light = Object.FindObjectOfType<Light>();
|
||||
if (light != null)
|
||||
{
|
||||
if (light.type == LightType.Directional)
|
||||
{
|
||||
return light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Light[] lights = Object.FindObjectsOfType<Light>();
|
||||
foreach(Light activeLight in lights)
|
||||
{
|
||||
if (activeLight.type == LightType.Directional)
|
||||
{
|
||||
return activeLight;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the LWRP Setup
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerator StartLWRPSetup(UnityPipelineProfile profile)
|
||||
{
|
||||
if (profile == null)
|
||||
{
|
||||
Debug.LogError("UnityPipelineProfile is empty");
|
||||
yield return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Installing LightWeight", "Updating scripting defines", 0.5f);
|
||||
m_waitTimer1 -= Time.deltaTime;
|
||||
if (m_waitTimer1 < 0)
|
||||
{
|
||||
SetScriptingDefines(profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
while (EditorApplication.isCompiling == true)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
EditorUtility.DisplayProgressBar("Installing LightWeight", "Updating scene to LightWeight", 0.75f);
|
||||
m_waitTimer2 -= Time.deltaTime;
|
||||
if (m_waitTimer2 < 0)
|
||||
{
|
||||
ConfigureSceneToLWRP(profile);
|
||||
profile.m_pipelineSwitchUpdates = false;
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the asset path of the first thing that matches the name
|
||||
/// </summary>
|
||||
/// <param name="name">Name to search for</param>
|
||||
/// <returns>The path or null</returns>
|
||||
private static string GetAssetPath(string name)
|
||||
{
|
||||
string[] assets = AssetDatabase.FindAssets(name, null);
|
||||
if (assets.Length > 0)
|
||||
{
|
||||
return AssetDatabase.GUIDToAssetPath(assets[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the assets and marks scene as dirty
|
||||
/// </summary>
|
||||
/// <param name="saveAlso"></param>
|
||||
private static void MarkSceneDirty(bool saveAlso)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
if (saveAlso)
|
||||
{
|
||||
if (EditorSceneManager.GetActiveScene().isDirty)
|
||||
{
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c2e17778e3c4fc499c9b3c88d836f6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(GaiaMaintenanceProfile))]
|
||||
public class GaiaMaintenanceProfileEditor : PWEditor
|
||||
{
|
||||
private GaiaMaintenanceProfile m_profile;
|
||||
private object m_editorUtils;
|
||||
private bool m_enableEditMode;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//Get Gaia Lighting Profile object
|
||||
m_profile = (GaiaMaintenanceProfile)target;
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
|
||||
m_enableEditMode = System.IO.Directory.Exists(GaiaUtils.GetAssetPath("Dev Utilities"));
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (m_enableEditMode)
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
//[MenuItem("Assets/Create/Procedural Worlds/Gaia/Maintenance Profile")]
|
||||
//public static void CreateMaintenanceProfiles()
|
||||
//{
|
||||
// GaiaMaintenanceProfile asset = ScriptableObject.CreateInstance<GaiaMaintenanceProfile>();
|
||||
// AssetDatabase.CreateAsset(asset, "Assets/Gaia Maintenance Profile.asset");
|
||||
// AssetDatabase.SaveAssets();
|
||||
// EditorUtility.FocusProjectWindow();
|
||||
// Selection.activeObject = asset;
|
||||
//}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 560613296ac6649448ff22272329a75a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c2bac199c19b3c45b0dac401b3bbd1c
|
||||
timeCreated: 1440194447
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,149 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to export texture layers as masks
|
||||
/// </summary>
|
||||
public class GaiaMaskExporterEditor : EditorWindow
|
||||
{
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private string m_maskName;
|
||||
private int m_selectedMask = 0;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (Terrain.activeTerrain != null)
|
||||
{
|
||||
m_selectedMask = GaiaSplatPrototype.GetGaiaSplatPrototypes(Terrain.activeTerrain).Length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("Gaia Mask Exporter", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("The Gaia splatmap exporter allows you to export texture splatmaps to use as masks.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (string.IsNullOrEmpty(m_maskName))
|
||||
{
|
||||
m_maskName = string.Format("Terrain-Splatmaps-{0:yyyyMMdd-HHmmss}", DateTime.Now);
|
||||
}
|
||||
m_maskName = EditorGUILayout.TextField(GetLabel("Mask Name"), m_maskName);
|
||||
|
||||
List<GUIContent> textureNames = new List<GUIContent>();
|
||||
if (Terrain.activeTerrain != null)
|
||||
{
|
||||
var splatPrototypes = GaiaSplatPrototype.GetGaiaSplatPrototypes(Terrain.activeTerrain);
|
||||
for (int idx = 0; idx < splatPrototypes.Length; idx++)
|
||||
{
|
||||
textureNames.Add(new GUIContent(splatPrototypes[idx].texture.name));
|
||||
}
|
||||
}
|
||||
textureNames.Add(new GUIContent("All"));
|
||||
m_selectedMask = EditorGUILayout.Popup(GetLabel("Selected Texture"), m_selectedMask, textureNames.ToArray());
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (DisplayButton(GetLabel("Export Selected Texture")))
|
||||
{
|
||||
ExportMask();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void ExportMask()
|
||||
{
|
||||
GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);
|
||||
if (mgr.TileCount > 0)
|
||||
{
|
||||
GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();
|
||||
string path = GaiaDirectories.GetExportDirectory(gsm.m_session);
|
||||
path = Path.Combine(path, PWCommon4.Utils.FixFileName(m_maskName));
|
||||
mgr.ExportSplatmapAsPng(path, m_selectedMask);
|
||||
Debug.Log("Created " + path);
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.FocusProjectWindow();
|
||||
EditorUtility.DisplayDialog("Export complete", " Your texture mask has been saved to : " + path, "OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("OOPS!", "You must have a valid terrain!!", "OK");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a button that takes editor indentation into account
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
bool DisplayButton(GUIContent content)
|
||||
{
|
||||
TextAnchor oldalignment = GUI.skin.button.alignment;
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
Rect btnR = EditorGUILayout.BeginHorizontal();
|
||||
btnR.xMin += (EditorGUI.indentLevel * 18f);
|
||||
btnR.height += 20f;
|
||||
btnR.width -= 4f;
|
||||
bool result = GUI.Button(btnR, content);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space(22);
|
||||
GUI.skin.button.alignment = oldalignment;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Execution Mode", "The way this spawner runs. Design time : At design time only. Runtime Interval : At run time on a timed interval. Runtime Triggered Interval : At run time on a timed interval, and only when the tagged game object is closer than the trigger range from the center of the spawner." },
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e406c006f7d5074eba1d7188cdb9d9f
|
||||
timeCreated: 1444162963
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,129 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to export terrain normal mask as a texture
|
||||
/// </summary>
|
||||
public class GaiaNormalExporterEditor : EditorWindow
|
||||
{
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private string m_maskName;
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("Gaia Terrain Normal Exporter", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("The Gaia terrain normal exporter allows you to export your terrain normals as a texture.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (string.IsNullOrEmpty(m_maskName))
|
||||
{
|
||||
m_maskName = string.Format("Terrain-Normals-{0:yyyyMMdd-HHmmss}", DateTime.Now);
|
||||
}
|
||||
m_maskName = EditorGUILayout.TextField(GetLabel("Texture Name"), m_maskName);
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (DisplayButton(GetLabel("Export Normal Map")))
|
||||
{
|
||||
ExportNormal();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
}
|
||||
|
||||
private void ExportNormal()
|
||||
{
|
||||
if (Terrain.activeTerrain == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("OOPS!", "You must have a valid terrain in your scene!!", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);
|
||||
if (mgr.TileCount > 0)
|
||||
{
|
||||
GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();
|
||||
string path = GaiaDirectories.GetExportDirectory(gsm.m_session);
|
||||
mgr.LoadFromWorld();
|
||||
path = Path.Combine(path, PWCommon4.Utils.FixFileName(m_maskName));
|
||||
mgr.ExportNormalmapAsPng(path);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
EditorUtility.DisplayDialog("Export complete", " Your normal map has been saved to : " + path, "OK");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a button that takes editor indentation into account
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
bool DisplayButton(GUIContent content)
|
||||
{
|
||||
TextAnchor oldalignment = GUI.skin.button.alignment;
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
Rect btnR = EditorGUILayout.BeginHorizontal();
|
||||
btnR.xMin += (EditorGUI.indentLevel * 18f);
|
||||
btnR.height += 20f;
|
||||
btnR.width -= 4f;
|
||||
bool result = GUI.Button(btnR, content);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space(22);
|
||||
GUI.skin.button.alignment = oldalignment;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Execution Mode", "The way this spawner runs. Design time : At design time only. Runtime Interval : At run time on a timed interval. Runtime Triggered Interval : At run time on a timed interval, and only when the tagged game object is closer than the trigger range from the center of the spawner." },
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0e71a181c927b9449bb3650c5d8a411
|
||||
timeCreated: 1455324524
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
//Automates removal of the gaia define
|
||||
public class GaiaRemovalEditor : UnityEditor.AssetModificationProcessor
|
||||
{
|
||||
public static AssetDeleteResult OnWillDeleteAsset(string AssetPath, RemoveAssetOptions rao)
|
||||
{
|
||||
if (AssetPath.Contains("Gaia"))
|
||||
{
|
||||
string symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (symbols.Contains("GAIA_PRESENT"))
|
||||
{
|
||||
symbols = symbols.Replace("GAIA_PRESENT;", "");
|
||||
symbols = symbols.Replace("GAIA_PRESENT", "");
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, symbols);
|
||||
}
|
||||
}
|
||||
return AssetDeleteResult.DidNotDelete;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c64e941266f1dea4cbd24ddc112a7703
|
||||
timeCreated: 1500247325
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a43b6f3de2a219d4189ae68f7640327d
|
||||
timeCreated: 1440043516
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,188 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[System.Serializable]
|
||||
public enum GaiaResourceHelperOperation { CopyResources, RemoveResources }
|
||||
|
||||
/// <summary>
|
||||
/// Utility to copy or remove resources / prototypes from terrains in the scene
|
||||
/// </summary>
|
||||
|
||||
class GaiaResourceHelper : EditorWindow, IPWEditor
|
||||
{
|
||||
|
||||
private EditorUtils m_editorUtils;
|
||||
bool m_targetAllTerrains = true;
|
||||
public Enum m_operation = GaiaResourceHelperOperation.CopyResources;
|
||||
Terrain m_sourceTerrain;
|
||||
private bool m_layersSelected = true;
|
||||
private bool m_terrainTreesSelected = true;
|
||||
private bool m_terrainDetailsSelected = true;
|
||||
Terrain m_targetTerrain;
|
||||
private GaiaSettings m_settings;
|
||||
|
||||
public bool PositionChecked { get => true; set => PositionChecked = value; }
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
titleContent = m_editorUtils.GetContent("WindowTitle");
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
m_editorUtils.Initialize();
|
||||
|
||||
m_editorUtils.Panel("ResourceHelper", DrawOperation, true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void DrawOperation(bool helpEnabled)
|
||||
{
|
||||
EditorGUILayout.BeginVertical();
|
||||
m_operation = m_editorUtils.EnumPopup("Operation", m_operation, helpEnabled);
|
||||
|
||||
switch (m_operation)
|
||||
{
|
||||
case GaiaResourceHelperOperation.CopyResources:
|
||||
DrawCopyOperation(helpEnabled);
|
||||
break;
|
||||
case GaiaResourceHelperOperation.RemoveResources:
|
||||
DrawRemoveOperation(helpEnabled);
|
||||
break;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
}
|
||||
|
||||
private void DrawRemoveOperation(bool helpEnabled)
|
||||
{
|
||||
m_targetAllTerrains = m_editorUtils.Toggle("DeleteAll", m_targetAllTerrains, helpEnabled);
|
||||
GUI.enabled = !m_targetAllTerrains;
|
||||
m_targetTerrain = (Terrain)m_editorUtils.ObjectField("TargetTerrain", m_targetTerrain, typeof(Terrain), true, helpEnabled);
|
||||
GUI.enabled = true;
|
||||
m_layersSelected = m_editorUtils.Toggle("TerrainLayers", m_layersSelected, helpEnabled);
|
||||
m_terrainTreesSelected = m_editorUtils.Toggle("TerrainTrees", m_terrainTreesSelected, helpEnabled);
|
||||
m_terrainDetailsSelected = m_editorUtils.Toggle("TerrainDetails", m_terrainDetailsSelected, helpEnabled);
|
||||
Color normalBGColor = GUI.backgroundColor;
|
||||
if (m_settings == null)
|
||||
{
|
||||
m_settings = GaiaUtils.GetGaiaSettings();
|
||||
}
|
||||
|
||||
GUI.backgroundColor = m_settings.GetActionButtonColor();
|
||||
if (m_editorUtils.Button("StartRemoval"))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Remove resources from target terrain(s)?", "This will remove the selected resources from to the source terrain to the given target terrains. This can heavily impact your scene, so please make a backup if you are not sure about this.", "Continue", "Cancel"))
|
||||
{
|
||||
if (m_targetAllTerrains)
|
||||
{
|
||||
if (GaiaUtils.HasDynamicLoadedTerrains())
|
||||
{
|
||||
GaiaUtils.CallFunctionOnDynamicLoadedTerrains(RemoveResourcesFromTerrain, false);
|
||||
}
|
||||
foreach (Terrain t in Terrain.activeTerrains)
|
||||
{
|
||||
RemoveResourcesFromTerrain(t);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveResourcesFromTerrain(m_targetTerrain);
|
||||
}
|
||||
}
|
||||
}
|
||||
GUI.backgroundColor = normalBGColor;
|
||||
|
||||
}
|
||||
|
||||
private void RemoveResourcesFromTerrain(Terrain t)
|
||||
{
|
||||
if (m_layersSelected)
|
||||
{
|
||||
t.terrainData.terrainLayers = new TerrainLayer[0];
|
||||
}
|
||||
if (m_terrainTreesSelected)
|
||||
{
|
||||
t.terrainData.treePrototypes = new TreePrototype[0];
|
||||
}
|
||||
if (m_terrainDetailsSelected)
|
||||
{
|
||||
t.terrainData.detailPrototypes = new DetailPrototype[0];
|
||||
}
|
||||
t.Flush();
|
||||
}
|
||||
|
||||
private void DrawCopyOperation(bool helpEnabled)
|
||||
{
|
||||
m_sourceTerrain = (Terrain)m_editorUtils.ObjectField("SourceTerrain", m_sourceTerrain, typeof(Terrain), true, helpEnabled);
|
||||
m_layersSelected = m_editorUtils.Toggle("TerrainLayers", m_layersSelected, helpEnabled);
|
||||
m_terrainTreesSelected = m_editorUtils.Toggle("TerrainTrees", m_terrainTreesSelected, helpEnabled);
|
||||
m_terrainDetailsSelected = m_editorUtils.Toggle("TerrainDetails", m_terrainDetailsSelected, helpEnabled);
|
||||
m_targetAllTerrains = m_editorUtils.Toggle("CopyAll", m_targetAllTerrains, helpEnabled);
|
||||
GUI.enabled = !m_targetAllTerrains;
|
||||
m_targetTerrain = (Terrain)m_editorUtils.ObjectField("TargetTerrain", m_targetTerrain, typeof(Terrain), true, helpEnabled);
|
||||
GUI.enabled = true;
|
||||
Color normalBGColor = GUI.backgroundColor;
|
||||
if (m_settings == null)
|
||||
{
|
||||
m_settings = GaiaUtils.GetGaiaSettings();
|
||||
}
|
||||
|
||||
GUI.backgroundColor = m_settings.GetActionButtonColor();
|
||||
if (m_editorUtils.Button("StartCopy"))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Copy terrain resources to target?", "This will copy the selected resources from to the source terrain to the given target terrains. This can heavily impact your scene, so please make a backup if you are not sure about this.", "Continue", "Cancel"))
|
||||
{
|
||||
if (m_targetAllTerrains)
|
||||
{
|
||||
if (GaiaUtils.HasDynamicLoadedTerrains())
|
||||
{
|
||||
GaiaUtils.CallFunctionOnDynamicLoadedTerrains(CopyResourcesToTerrain, false);
|
||||
}
|
||||
foreach (Terrain t in Terrain.activeTerrains)
|
||||
{
|
||||
CopyResourcesToTerrain(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyResourcesToTerrain(m_targetTerrain);
|
||||
}
|
||||
}
|
||||
}
|
||||
GUI.backgroundColor = normalBGColor;
|
||||
}
|
||||
|
||||
private void CopyResourcesToTerrain(Terrain t)
|
||||
{
|
||||
if (m_layersSelected)
|
||||
{
|
||||
t.terrainData.terrainLayers = m_sourceTerrain.terrainData.terrainLayers;
|
||||
}
|
||||
if (m_terrainTreesSelected)
|
||||
{
|
||||
t.terrainData.treePrototypes = m_sourceTerrain.terrainData.treePrototypes;
|
||||
}
|
||||
if (m_terrainDetailsSelected)
|
||||
{
|
||||
t.terrainData.detailPrototypes = m_sourceTerrain.terrainData.detailPrototypes;
|
||||
}
|
||||
t.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8990ee7353a2e8f4b89728ebf832873d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
//[InitializeOnLoad]
|
||||
public class GaiaScriptOrderManager
|
||||
{
|
||||
static GaiaScriptOrderManager()
|
||||
{
|
||||
foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts())
|
||||
{
|
||||
if (monoScript.GetClass() != null)
|
||||
{
|
||||
foreach (var a in Attribute.GetCustomAttributes(monoScript.GetClass(), typeof(GaiaScriptOrder)))
|
||||
{
|
||||
var currentOrder = MonoImporter.GetExecutionOrder(monoScript);
|
||||
var newOrder = ((GaiaScriptOrder)a).Order;
|
||||
if (currentOrder != newOrder)
|
||||
MonoImporter.SetExecutionOrder(monoScript, newOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c3c8c3ca2ba2dc4eb24e957971384df
|
||||
timeCreated: 1524564621
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,206 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor for sessions
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(GaiaSession))]
|
||||
public class GaiaSessionEditor : Editor
|
||||
{
|
||||
|
||||
GUIStyle m_boxStyle;
|
||||
GUIStyle m_wrapStyle;
|
||||
GUIStyle m_descWrapStyle;
|
||||
GaiaSession m_session;
|
||||
private bool m_showTooltips = true;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
//Get the settings and update tooltips
|
||||
GaiaSettings settings = Gaia.GaiaUtils.GetGaiaSettings();
|
||||
if (settings != null)
|
||||
{
|
||||
m_showTooltips = settings.m_showTooltips;
|
||||
}
|
||||
|
||||
//Get our resource
|
||||
m_session = (GaiaSession)target;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Get our resource
|
||||
m_session = (GaiaSession)target;
|
||||
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Set up the description wrap style
|
||||
if (m_descWrapStyle == null)
|
||||
{
|
||||
m_descWrapStyle = new GUIStyle(GUI.skin.textArea);
|
||||
m_descWrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Create a nice text intro
|
||||
GUILayout.BeginVertical("Gaia Session", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("Contains the data used to backup, share and play back sessions. Use the session manager to view, edit or play back sessions.", m_wrapStyle);
|
||||
GUILayout.Space(4);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//Make some space
|
||||
GUILayout.Space(4);
|
||||
|
||||
//Wrap it up in a box
|
||||
GUILayout.BeginVertical(m_boxStyle);
|
||||
GUILayout.BeginVertical("Summary:", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
|
||||
//Display the basic details
|
||||
EditorGUILayout.LabelField("Name", m_session.m_name);
|
||||
EditorGUILayout.LabelField("Description", m_session.m_description, m_wrapStyle);
|
||||
EditorGUILayout.LabelField("Created", m_session.m_dateCreated);
|
||||
EditorGUILayout.LabelField("Dimensions", string.Format("w{0} d{1} h{2} meters", m_session.m_terrainWidth, m_session.m_terrainDepth, m_session.m_terrainHeight));
|
||||
EditorGUILayout.LabelField("Sea Level", string.Format("{0} meters", m_session.m_seaLevel));
|
||||
EditorGUILayout.LabelField("Locked", m_session.m_isLocked.ToString());
|
||||
|
||||
Texture2D previewImage = m_session.m_previewImage;
|
||||
if (previewImage != null)
|
||||
{
|
||||
//Get aspect ratio and available space and display the image
|
||||
float width = Screen.width - 43f;
|
||||
float height = previewImage.height * (width / previewImage.width);
|
||||
GUILayout.Label(previewImage, GUILayout.MaxWidth(width), GUILayout.MaxHeight(height));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//Iterate through the operations
|
||||
GUILayout.BeginVertical("Operations:", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
|
||||
if (m_session.m_operations.Count == 0)
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
GUILayout.Label("No operations yet...");
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
else
|
||||
{
|
||||
GaiaOperation op;
|
||||
EditorGUI.indentLevel++;
|
||||
for (int opIdx = 0; opIdx < m_session.m_operations.Count; opIdx++)
|
||||
{
|
||||
op = m_session.m_operations[opIdx];
|
||||
|
||||
if (op.m_isActive)
|
||||
{
|
||||
op.m_isFoldedOut = EditorGUILayout.Foldout(op.m_isFoldedOut, op.m_description, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
op.m_isFoldedOut = EditorGUILayout.Foldout(op.m_isFoldedOut, op.m_description + " [inactive]", true);
|
||||
}
|
||||
|
||||
if (op.m_isFoldedOut)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.LabelField("Description", op.m_description, m_wrapStyle);
|
||||
EditorGUILayout.LabelField("Created", op.m_operationDateTime);
|
||||
EditorGUILayout.LabelField("Active", op.m_isActive.ToString());
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndVertical();
|
||||
if (GUILayout.Button("Play Session"))
|
||||
{
|
||||
GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false, false);
|
||||
if (gsm == null)
|
||||
{
|
||||
GameObject gaiaObj = GaiaUtils.GetGaiaGameObject();
|
||||
GameObject mgrObj = new GameObject("Session Manager");
|
||||
gsm = mgrObj.AddComponent<GaiaSessionManager>();
|
||||
mgrObj.transform.parent = gaiaObj.transform;
|
||||
}
|
||||
|
||||
|
||||
GaiaLighting.SetDefaultAmbientLight(GaiaUtils.GetGaiaSettings().m_gaiaLightingProfile);
|
||||
//make a copy of the session - otherwise there is the danger of conflicting with the old session data while playing back the session
|
||||
GaiaSession sessionCopy = Instantiate(m_session);
|
||||
sessionCopy.m_name = GaiaSessionManager.GetNewSessionName();
|
||||
sessionCopy.name = sessionCopy.m_name;
|
||||
gsm.m_session = sessionCopy;
|
||||
string path = GaiaDirectories.GetSessionDirectory();
|
||||
AssetDatabase.CreateAsset(sessionCopy, path + "/" + sessionCopy.m_name + ".asset");
|
||||
AssetDatabase.SaveAssets();
|
||||
GaiaSessionManager.PlaySession(sessionCopy);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Session in Manager"))
|
||||
{
|
||||
GaiaSessionManager.LoadSession(m_session);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_showTooltips && m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Sea Level", "The sea level the session will be rendered at. Changing this will also change the resource files when it is played." },
|
||||
{ "Locked", "When activated then this stamp is locked and no further changes can be made." },
|
||||
{ "Delete", "Delete the step." },
|
||||
{ "Apply", "Apply the step to the relevant object, but don't execute it. Great for seeing how something was configured." },
|
||||
{ "Play", "Apply the step and play it in the scene." },
|
||||
|
||||
{ "Flatten Terrain", "Flatten all terrains." },
|
||||
{ "Smooth Terrain", "Smooth all terrains." },
|
||||
{ "Clear Trees", "Clear trees on all terrains and reset all tree spawners." },
|
||||
{ "Clear Details", "Clear details on all terrains." },
|
||||
|
||||
{ "Terrain Helper", "Show the terrain helper controls." },
|
||||
{ "Play Session", "Play the session from end to end." },
|
||||
{ "Export Resources", "Export the embedded session resources to the Assest\\Gaia Sessions\\SessionName directory." },
|
||||
{ "Session", "The way this spawner runs. Design time : At design time only. Runtime Interval : At run time on a timed interval. Runtime Triggered Interval : At run time on a timed interval, and only when the tagged game object is closer than the trigger range from the center of the spawner." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11a1b649b0a9cb84f97cb0c824da5aad
|
||||
timeCreated: 1540761661
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b7460de6193629443b952f9e783185bd, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2547cdc4bbe910040b23ff32b8dc58da
|
||||
timeCreated: 1540570536
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b7460de6193629443b952f9e783185bd, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,324 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Some cool terrain modification utilities
|
||||
/// </summary>
|
||||
public class GaiaStampSelectorEditorWindow : EditorWindow, IPWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
public StamperSettings m_editedStamperSettings;
|
||||
public ImageMask m_editedImageMask;
|
||||
private Texture2D m_previewTexture;
|
||||
private string m_originalTextureGUID;
|
||||
private List<string> m_categoryNames = new List<string>();
|
||||
private Stamper[] allStampers;
|
||||
private Spawner[] allSpawners;
|
||||
private BiomeController[] allBiomeController;
|
||||
private int m_selectedCategoryID = -99;
|
||||
private FileInfo[] m_currentStampDirFileInfo;
|
||||
private int m_currentStampIndex;
|
||||
private bool m_validStampInCategory = true;
|
||||
|
||||
public bool PositionChecked { get; set; }
|
||||
|
||||
public void Init(ImageMask imageMask = null)
|
||||
{
|
||||
|
||||
allBiomeController = (BiomeController[])Resources.FindObjectsOfTypeAll(typeof(BiomeController));
|
||||
allStampers = (Stamper[])Resources.FindObjectsOfTypeAll(typeof(Stamper));
|
||||
allSpawners = (Spawner[])Resources.FindObjectsOfTypeAll(typeof(Spawner));
|
||||
|
||||
m_categoryNames.Clear();
|
||||
var info = new DirectoryInfo(GaiaDirectories.GetStampDirectory());
|
||||
var fileInfo = info.GetDirectories();
|
||||
foreach (DirectoryInfo dir in fileInfo)
|
||||
{
|
||||
m_categoryNames.Add(dir.Name);
|
||||
}
|
||||
|
||||
//Do the same with the user stamp folder
|
||||
info = new DirectoryInfo(GaiaDirectories.GetUserStampDirectory());
|
||||
fileInfo = info.GetDirectories();
|
||||
foreach (DirectoryInfo dir in fileInfo)
|
||||
{
|
||||
m_categoryNames.Add(dir.Name);
|
||||
}
|
||||
|
||||
m_categoryNames.Sort();
|
||||
|
||||
if (imageMask != null)
|
||||
{
|
||||
m_editedImageMask = imageMask;
|
||||
}
|
||||
|
||||
//read & store the original texture guid if the user wants to cancel
|
||||
if ((m_editedImageMask != null && m_editedImageMask.ImageMaskTexture != null))
|
||||
{
|
||||
string pathToImage = "";
|
||||
if (m_editedImageMask != null)
|
||||
{
|
||||
pathToImage = AssetDatabase.GetAssetPath(m_editedImageMask.ImageMaskTexture);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// pathToImage = AssetDatabase.GetAssetPath(m_editedStamperSettings.m_stamperInputImage);
|
||||
//}
|
||||
m_originalTextureGUID = AssetDatabase.AssetPathToGUID(pathToImage);
|
||||
m_previewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(pathToImage, typeof(Texture2D));
|
||||
|
||||
//Try to locate the selected image in the stamps directory
|
||||
if (pathToImage.Contains(GaiaDirectories.STAMP_DIRECTORY))
|
||||
{
|
||||
string lastFolderName = Path.GetFileName(Path.GetDirectoryName(pathToImage));
|
||||
m_selectedCategoryID = m_categoryNames.FindIndex(x => x == lastFolderName);
|
||||
LoadStampDirFileInfo();
|
||||
int index = -1;
|
||||
foreach (var fi in m_currentStampDirFileInfo)
|
||||
{
|
||||
index++;
|
||||
if (pathToImage.Contains(fi.Name))
|
||||
{
|
||||
m_currentStampIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_originalTextureGUID = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
titleContent = m_editorUtils.GetContent("WindowTitle");
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
m_editorUtils.Initialize();
|
||||
m_editorUtils.Panel("SelectStampPanel", SelectStampPanel, true);
|
||||
|
||||
}
|
||||
|
||||
private void SelectStampPanel(bool helpEnabled)
|
||||
{
|
||||
|
||||
m_editorUtils.InlineHelp("Help", helpEnabled);
|
||||
|
||||
|
||||
if (m_editedImageMask == null && m_editedStamperSettings == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("NoConnectedImageMask"), MessageType.Warning, true);
|
||||
}
|
||||
|
||||
m_editorUtils.Label("StampPreview");
|
||||
EditorGUILayout.BeginVertical();
|
||||
if (m_previewTexture != null && m_validStampInCategory)
|
||||
{
|
||||
m_editorUtils.Image(m_previewTexture, position.width - 25, position.width - 25);
|
||||
m_editorUtils.Label(new GUIContent(m_previewTexture.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!m_validStampInCategory)
|
||||
{
|
||||
GUILayout.Space(71);
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("NoValidStampInCategory"), MessageType.Info, true);
|
||||
}
|
||||
else if (m_previewTexture == null)
|
||||
{
|
||||
GUILayout.Space(67);
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("NoTexture"), MessageType.Info, true);
|
||||
}
|
||||
GUILayout.Space(155);
|
||||
}
|
||||
GUILayout.Space(EditorGUIUtility.singleLineHeight);
|
||||
|
||||
Rect rect = EditorGUILayout.GetControlRect();
|
||||
if (GUI.Button(new Rect(rect.x, rect.y, 50, EditorGUIUtility.singleLineHeight), m_editorUtils.GetContent("StampBackwardButton")))
|
||||
{
|
||||
PickNextStamp(-1);
|
||||
}
|
||||
|
||||
//Building up a value array of incrementing ints of the size of the directory names array, this array will then match the displayed string selection in the popup
|
||||
int[] categoryIDArray = Enumerable
|
||||
.Repeat(0, (int)((m_categoryNames.ToArray().Length - 0) / 1) + 1)
|
||||
.Select((tr, ti) => tr + (1 * ti))
|
||||
.ToArray();
|
||||
|
||||
int previousCategoryID = m_selectedCategoryID;
|
||||
m_selectedCategoryID = EditorGUI.IntPopup(new Rect(rect.x + 60, rect.y, rect.width - 120, EditorGUIUtility.singleLineHeight), m_selectedCategoryID, m_categoryNames.ToArray(), categoryIDArray);
|
||||
if (previousCategoryID != m_selectedCategoryID)
|
||||
{
|
||||
LoadStampDirFileInfo();
|
||||
m_currentStampIndex = -1;
|
||||
m_validStampInCategory = PickNextStamp(1);
|
||||
}
|
||||
|
||||
if (GUI.Button(new Rect(rect.x + 60 + rect.width - 110, rect.y, 50, EditorGUIUtility.singleLineHeight), m_editorUtils.GetContent("StampForwardButton")))
|
||||
{
|
||||
PickNextStamp(1);
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 2;
|
||||
|
||||
if (GUI.Button(new Rect(rect.x + 20, rect.y, 100, EditorGUIUtility.singleLineHeight * 2), m_editorUtils.GetContent("ApplyButton")))
|
||||
{
|
||||
Close();
|
||||
}
|
||||
if (GUI.Button(new Rect(rect.x + rect.width - 100 - 20, rect.y, 100, EditorGUIUtility.singleLineHeight * 2), m_editorUtils.GetContent("CancelButton")))
|
||||
{
|
||||
//Load original stamp back in and close
|
||||
if (m_editedImageMask != null)
|
||||
{
|
||||
m_editedImageMask.ImageMaskTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(m_originalTextureGUID), typeof(Texture2D));
|
||||
}
|
||||
//if (m_editedStamperSettings != null)
|
||||
//{
|
||||
// m_editedStamperSettings.m_stamperInputImage = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(m_originalTextureGUID), typeof(Texture2D));
|
||||
//}
|
||||
UpdateToolsAndScene();
|
||||
Close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private void LoadStampDirFileInfo()
|
||||
{
|
||||
if (m_selectedCategoryID != -99)
|
||||
{
|
||||
string directory = GaiaDirectories.GetStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID];
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
directory = GaiaDirectories.GetUserStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID];
|
||||
}
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Debug.LogWarning("Could not find the selected subdirectory '" + m_categoryNames[m_selectedCategoryID] + "' neither in the Gaia Stamps or in the User Stamps folder when trying to browse stamps.");
|
||||
return;
|
||||
}
|
||||
|
||||
var info = new DirectoryInfo(directory);
|
||||
|
||||
if (info == null)
|
||||
{
|
||||
Debug.LogWarning("Could not access directory " + directory + " when trying to browse stamps.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_currentStampDirFileInfo = info.GetFiles();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateToolsAndScene()
|
||||
{
|
||||
foreach (Stamper stamper in allStampers)
|
||||
{
|
||||
stamper.m_stampDirty = true;
|
||||
}
|
||||
foreach (Spawner spawner in allSpawners)
|
||||
{
|
||||
spawner.m_spawnPreviewDirty = true;
|
||||
spawner.SetWorldBiomeMasksDirty();
|
||||
}
|
||||
foreach (BiomeController controller in allBiomeController)
|
||||
{
|
||||
controller.m_biomePreviewDirty = true;
|
||||
}
|
||||
EditorWindow view = EditorWindow.GetWindow<SceneView>();
|
||||
view.Repaint();
|
||||
}
|
||||
|
||||
private bool PickNextStamp(int direction)
|
||||
{
|
||||
//try to load a stamp file from the next index
|
||||
int nextIndexCandidate = m_currentStampIndex + direction;
|
||||
|
||||
if (m_currentStampDirFileInfo == null)
|
||||
{
|
||||
LoadStampDirFileInfo();
|
||||
}
|
||||
|
||||
//still null? abort!
|
||||
if (m_currentStampDirFileInfo == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (0 <= nextIndexCandidate && nextIndexCandidate < m_currentStampDirFileInfo.Length - 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Try to load the next texture2D into the preview texture, whatever file it is.
|
||||
string assetPath = GaiaDirectories.GetStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID] + "/" + m_currentStampDirFileInfo[nextIndexCandidate].Name;
|
||||
m_previewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
|
||||
if (m_previewTexture == null)
|
||||
{
|
||||
//Not found? Try to load from the user stamps folder instead
|
||||
assetPath = GaiaDirectories.GetUserStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID] + "/" + m_currentStampDirFileInfo[nextIndexCandidate].Name;
|
||||
m_previewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
|
||||
}
|
||||
|
||||
if (m_previewTexture == null)
|
||||
{
|
||||
//no exception, but no valid texture file either, let's try the next index then
|
||||
m_currentStampIndex = nextIndexCandidate;
|
||||
return PickNextStamp(direction);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentStampIndex = nextIndexCandidate;
|
||||
if (m_editedImageMask != null)
|
||||
{
|
||||
m_editedImageMask.ImageMaskTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// m_editedStamperSettings.m_stamperInputImage = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
|
||||
//}
|
||||
UpdateToolsAndScene();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//there might be more valid files, let's try the next index then
|
||||
m_currentStampIndex = nextIndexCandidate;
|
||||
return PickNextStamp(direction);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a00aa267c2e69cc4fbe0ad977706734c
|
||||
timeCreated: 1524547112
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright © 2018 Procedural Worlds Pty Limited. All Rights Reserved.
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using PWCommon4;
|
||||
|
||||
namespace Gaia.Internal
|
||||
{
|
||||
public class GaiaStdMenu : Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Show tutorials
|
||||
/// </summary>
|
||||
[MenuItem("Window/" + PWConst.COMMON_MENU + "/Gaia/Show Gaia Tutorials...", false, 60)]
|
||||
public static void ShowTutorial()
|
||||
{
|
||||
Application.OpenURL(PWApp.CONF.TutorialsLink);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show support page
|
||||
/// </summary>
|
||||
[MenuItem("Window/" + PWConst.COMMON_MENU + "/Gaia/Show Gaia Support, Lodge a Ticket...", false, 61)]
|
||||
public static void ShowSupport()
|
||||
{
|
||||
Application.OpenURL(PWApp.CONF.SupportLink);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show review option
|
||||
/// </summary>
|
||||
[MenuItem("Window/" + PWConst.COMMON_MENU + "/Gaia/Please Review Gaia...", false, 62)]
|
||||
public static void ShowProductAssetStore()
|
||||
{
|
||||
Application.OpenURL(PWApp.CONF.ASLink);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the welcome screen for this app
|
||||
/// </summary>
|
||||
[MenuItem("Window/" + PWConst.COMMON_MENU + "/Gaia/Show Gaia Welcome...", false, 63)]
|
||||
public static void ShowProductWelcome()
|
||||
{
|
||||
PWWelcome.ShowWelcome(PWApp.CONF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84a46eb4c993d064fa7b34c8e8b50b94
|
||||
timeCreated: 1539857255
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
public enum GaiaStopwatchOrderBy { FirstStart,Name,TotalDuration }
|
||||
|
||||
|
||||
[CustomEditor(typeof(GaiaStopwatchControl))]
|
||||
public class GaiaStopwatchControlEditor : PWEditor, IPWEditor
|
||||
{
|
||||
private GaiaStopwatchControl m_gaiastopwatchControl;
|
||||
private EditorUtils m_editorUtils;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
m_gaiastopwatchControl = (GaiaStopwatchControl)target;
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
m_gaiastopwatchControl.transform.name = GaiaConstants.gaiaStopWatchDataObject;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
#if GAIA_DEBUG
|
||||
if (m_editorUtils.Button("DisableStopwatch"))
|
||||
{
|
||||
bool isChanged = false;
|
||||
string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (currBuildSettings.Contains("GAIA_DEBUG"))
|
||||
{
|
||||
currBuildSettings = currBuildSettings.Replace("GAIA_DEBUG;", "");
|
||||
currBuildSettings = currBuildSettings.Replace("GAIA_DEBUG", "");
|
||||
isChanged = true;
|
||||
}
|
||||
if (isChanged)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings);
|
||||
}
|
||||
}
|
||||
if (!GaiaStopwatch.m_isEnabled)
|
||||
{
|
||||
if (m_editorUtils.Button("StartStopwatch"))
|
||||
{
|
||||
GaiaStopwatch.m_isEnabled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_editorUtils.Button("StopStopwatch"))
|
||||
{
|
||||
GaiaStopwatch.Stop();
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (m_editorUtils.Button("EnableStopwatch"))
|
||||
{
|
||||
bool isChanged = false;
|
||||
string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (!currBuildSettings.Contains("GAIA_DEBUG"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(currBuildSettings))
|
||||
{
|
||||
currBuildSettings = "GAIA_DEBUG";
|
||||
}
|
||||
else
|
||||
{
|
||||
currBuildSettings += ";GAIA_DEBUG";
|
||||
}
|
||||
isChanged = true;
|
||||
}
|
||||
if (isChanged)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings);
|
||||
}
|
||||
}
|
||||
|
||||
GUI.enabled = false;
|
||||
m_editorUtils.Button("StartStopwatch");
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83bc99fe0ae7fea418bc7c80b0364b86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,112 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(GaiaStopwatchDataset))]
|
||||
public class GaiaStopwatchDatasetEditor : PWEditor, IPWEditor
|
||||
{
|
||||
private GaiaStopwatchDataset m_gaiastopwatchDataset;
|
||||
private EditorUtils m_editorUtils;
|
||||
private bool m_eventsActivated;
|
||||
private Func<GaiaStopWatchEvent, object> m_orderByLambda;
|
||||
[SerializeField]
|
||||
private bool[] m_unfoldedStates;
|
||||
[SerializeField]
|
||||
private GaiaStopwatchOrderBy m_orderBy = GaiaStopwatchOrderBy.TotalDuration;
|
||||
[SerializeField]
|
||||
private bool m_orderbyDescending = true;
|
||||
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
m_gaiastopwatchDataset = (GaiaStopwatchDataset)target;
|
||||
m_unfoldedStates = new bool[m_gaiastopwatchDataset.m_events.Count];
|
||||
//Init editor utils
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
m_orderBy = (GaiaStopwatchOrderBy)m_editorUtils.EnumPopup("OrderBy", m_orderBy);
|
||||
m_orderbyDescending = m_editorUtils.Toggle("Descending", m_orderbyDescending);
|
||||
switch (m_orderBy)
|
||||
{
|
||||
case GaiaStopwatchOrderBy.FirstStart:
|
||||
m_orderByLambda = x => x.m_firstStartTimeStamp;
|
||||
break;
|
||||
case GaiaStopwatchOrderBy.Name:
|
||||
m_orderByLambda = x => x.m_name;
|
||||
break;
|
||||
case GaiaStopwatchOrderBy.TotalDuration:
|
||||
m_orderByLambda = x => x.m_accumulatedTime;
|
||||
break;
|
||||
}
|
||||
|
||||
List<GaiaStopWatchEvent> relevantEvents;
|
||||
|
||||
if (m_orderbyDescending)
|
||||
{
|
||||
relevantEvents = m_gaiastopwatchDataset.m_events.FindAll(x => x.m_parent == "" || x.m_parent ==null).OrderByDescending(m_orderByLambda).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
relevantEvents = m_gaiastopwatchDataset.m_events.FindAll(x => x.m_parent == "" || x.m_parent == null).OrderBy(m_orderByLambda).ToList();
|
||||
}
|
||||
|
||||
foreach (GaiaStopWatchEvent stopWatchEvent in relevantEvents)
|
||||
{
|
||||
DrawStopwatchEvent(stopWatchEvent);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void DrawStopwatchEvent(GaiaStopWatchEvent stopWatchEvent)
|
||||
{
|
||||
int id = m_gaiastopwatchDataset.m_events.FindIndex(x => x == stopWatchEvent);
|
||||
m_unfoldedStates[id] = m_editorUtils.Foldout(m_unfoldedStates[id], new GUIContent(stopWatchEvent.m_name));
|
||||
if (m_unfoldedStates[id])
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
m_editorUtils.LabelField("FirstStart", new GUIContent(stopWatchEvent.m_firstStartTimeStamp.ToString()));
|
||||
m_editorUtils.LabelField("TotalDuration", new GUIContent(stopWatchEvent.m_accumulatedTime.ToString()));
|
||||
m_editorUtils.LabelField("Calls", new GUIContent(stopWatchEvent.m_callCount.ToString()));
|
||||
m_editorUtils.LabelField("DurationPerCall", new GUIContent(stopWatchEvent.m_durationPerCall.ToString()));
|
||||
|
||||
|
||||
List<GaiaStopWatchEvent> relevantEvents;
|
||||
|
||||
if (m_orderbyDescending)
|
||||
{
|
||||
relevantEvents = m_gaiastopwatchDataset.m_events.FindAll(x => x.m_parent == stopWatchEvent.m_name).OrderByDescending(m_orderByLambda).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
relevantEvents = m_gaiastopwatchDataset.m_events.FindAll(x => x.m_parent == stopWatchEvent.m_name).OrderBy(m_orderByLambda).ToList();
|
||||
}
|
||||
|
||||
foreach (GaiaStopWatchEvent subEvent in relevantEvents)
|
||||
{
|
||||
DrawStopwatchEvent(subEvent);
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df3612c88c089214389122839ffe890d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cca80ca2bd78784e881aafba6188f09
|
||||
timeCreated: 1524547112
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,115 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
public class GaiaTerrainHeightAdjuster : EditorWindow
|
||||
{
|
||||
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private float m_terrainHeight = 0f;
|
||||
private float m_maxTerrainHeight = 1000f;
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("Gaia Terrain Height Adjuster", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("The terrain height adjuster allows you to set the height of the terrains in your scene to the given height.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
Terrain terrain = Gaia.TerrainHelper.GetActiveTerrain();
|
||||
if (terrain != null)
|
||||
{
|
||||
m_maxTerrainHeight = terrain.terrainData.size.y;
|
||||
}
|
||||
|
||||
m_terrainHeight = EditorGUILayout.Slider(GetLabel("New Terrain Height (m)"), m_terrainHeight, 0f, m_maxTerrainHeight);
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (DisplayButton(GetLabel("Adjust Terrain Heights")))
|
||||
{
|
||||
if (terrain == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("OOPS!", "You must have at least one active terrain in your scene to use this feature!", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);
|
||||
mgr.LoadFromWorld();
|
||||
mgr.SetHeightWU(m_terrainHeight);
|
||||
mgr.SaveToWorld();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a button that takes editor indentation into account
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
bool DisplayButton(GUIContent content)
|
||||
{
|
||||
TextAnchor oldalignment = GUI.skin.button.alignment;
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
Rect btnR = EditorGUILayout.BeginHorizontal();
|
||||
btnR.xMin += (EditorGUI.indentLevel * 18f);
|
||||
btnR.height += 20f;
|
||||
btnR.width -= 4f;
|
||||
bool result = GUI.Button(btnR, content);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space(22);
|
||||
GUI.skin.button.alignment = oldalignment;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Execution Mode", "The way this spawner runs. Design time : At design time only. Runtime Interval : At run time on a timed interval. Runtime Triggered Interval : At run time on a timed interval, and only when the tagged game object is closer than the trigger range from the center of the spawner." },
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a88c9144ec543e44ca2012e675e651ea
|
||||
timeCreated: 1456017095
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,917 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
#if UPPipeline
|
||||
using UnityEngine.Rendering.Universal;
|
||||
#endif
|
||||
using System.Collections;
|
||||
using UnityEditor.SceneManagement;
|
||||
using ProceduralWorlds.WaterSystem;
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
#endif
|
||||
using System.Collections.Generic;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Gaia.Pipeline.URP
|
||||
{
|
||||
/// <summary>
|
||||
/// Static class that handles all the LWRP setup in Gaia
|
||||
/// </summary>
|
||||
public static class GaiaURPPipelineUtils
|
||||
{
|
||||
public static float m_waitTimer1 = 1f;
|
||||
public static float m_waitTimer2 = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Configures project for LWRP
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
private static void ConfigureSceneToURP(UnityPipelineProfile profile)
|
||||
{
|
||||
try
|
||||
{
|
||||
GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings();
|
||||
if (gaiaSettings.m_currentRenderer != GaiaConstants.EnvironmentRenderer.Universal)
|
||||
{
|
||||
Debug.LogError("Unable to configure your scene/project to URP as the current render inside of gaia does not equal Universal as it's active render pipeline. This process [GaiaLWRPPipelineUtils.ConfigureSceneToURP()] will now exit.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.m_setUPPipelineProfile)
|
||||
{
|
||||
SetPipelineAsset(profile);
|
||||
}
|
||||
|
||||
if (profile.m_UPAutoConfigureCamera)
|
||||
{
|
||||
ConfigureCamera();
|
||||
}
|
||||
|
||||
if (gaiaSettings.m_gaiaLightingProfile.m_enablePostProcessing)
|
||||
{
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
if (gaiaSettings.m_gaiaLightingProfile.m_selectedLightingProfileValuesIndex <= gaiaSettings.m_gaiaLightingProfile.m_lightingProfiles.Count - 1)
|
||||
{
|
||||
ApplyURPPostProcessing(gaiaSettings.m_gaiaLightingProfile.m_lightingProfiles[gaiaSettings.m_gaiaLightingProfile.m_selectedLightingProfileValuesIndex], GaiaGlobal.Instance.SceneProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (profile.m_UPAutoConfigureLighting)
|
||||
{
|
||||
ConfigureLighting();
|
||||
}
|
||||
|
||||
if (profile.m_UPAutoConfigureWater)
|
||||
{
|
||||
ConfigureWater(profile, gaiaSettings);
|
||||
}
|
||||
|
||||
if (profile.m_UPAutoConfigureProbes)
|
||||
{
|
||||
GaiaURPRuntimeUtils.ConfigureReflectionProbes();
|
||||
}
|
||||
|
||||
if (profile.m_UPAutoConfigureTerrain)
|
||||
{
|
||||
GaiaURPRuntimeUtils.ConfigureTerrain(profile);
|
||||
}
|
||||
|
||||
if (profile.m_UPAutoConfigureBiomePostFX)
|
||||
{
|
||||
UpdateBiomePostFX();
|
||||
}
|
||||
|
||||
FinalizeURP(profile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Configures scripting defines in the project
|
||||
/// </summary>
|
||||
public static void SetScriptingDefines(UnityPipelineProfile profile)
|
||||
{
|
||||
bool isChanged = false;
|
||||
string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (!currBuildSettings.Contains("UPPipeline"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(currBuildSettings))
|
||||
{
|
||||
currBuildSettings = "UPPipeline";
|
||||
}
|
||||
else
|
||||
{
|
||||
currBuildSettings += ";UPPipeline";
|
||||
}
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (currBuildSettings.Contains("HDPipeline"))
|
||||
{
|
||||
currBuildSettings = currBuildSettings.Replace("HDPipeline;", "");
|
||||
currBuildSettings = currBuildSettings.Replace("HDPipeline", "");
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (currBuildSettings.Contains("LWPipeline"))
|
||||
{
|
||||
currBuildSettings = currBuildSettings.Replace("LWPipeline;", "");
|
||||
currBuildSettings = currBuildSettings.Replace("LWPipeline", "");
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the pipeline asset to the procedural worlds asset if the profile is set yo change it
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
public static void SetPipelineAsset(UnityPipelineProfile profile)
|
||||
{
|
||||
try
|
||||
{
|
||||
GaiaPackageVersion unityVersion = GaiaManagerEditor.GetPackageVersion();
|
||||
UnityVersionPipelineAsset mapping = profile.m_universalPipelineProfiles.Find(x => x.m_unityVersion == unityVersion);
|
||||
string pipelineAssetName = "";
|
||||
if (mapping != null)
|
||||
{
|
||||
pipelineAssetName = mapping.m_pipelineAssetName;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Could not determine the correct render pipeline settings asset for this unity version / rendering pipeline!");
|
||||
return;
|
||||
}
|
||||
|
||||
GraphicsSettings.renderPipelineAsset = AssetDatabase.LoadAssetAtPath<RenderPipelineAsset>(GaiaUtils.GetAssetPath(pipelineAssetName + GaiaConstants.gaiaFileFormatAsset));
|
||||
profile.m_pipelineSwitchUpdates = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the pipeline asset depth/opaque settings
|
||||
/// </summary>
|
||||
/// <param name="updateDepth"></param>
|
||||
/// <param name="updateOpaque"></param>
|
||||
public static void UpdateURPPipelineSettings(bool updateDepth, bool updateOpaque)
|
||||
{
|
||||
#if UPPipeline
|
||||
UniversalRenderPipelineAsset pipelineAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
|
||||
if (pipelineAsset != null)
|
||||
{
|
||||
if (updateDepth)
|
||||
{
|
||||
pipelineAsset.supportsCameraDepthTexture = false;
|
||||
pipelineAsset.supportsCameraDepthTexture = true;
|
||||
}
|
||||
|
||||
if (updateOpaque)
|
||||
{
|
||||
pipelineAsset.supportsCameraOpaqueTexture = false;
|
||||
pipelineAsset.supportsCameraOpaqueTexture = true;
|
||||
}
|
||||
|
||||
QualitySettings.renderPipeline = pipelineAsset;
|
||||
pipelineAsset.OnAfterDeserialize();
|
||||
EditorUtility.SetDirty(pipelineAsset);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// Configures camera to LWRP
|
||||
/// </summary>
|
||||
private static void ConfigureCamera()
|
||||
{
|
||||
try
|
||||
{
|
||||
Camera camera = GaiaUtils.GetCamera();
|
||||
if (camera == null)
|
||||
{
|
||||
Debug.LogWarning("[GaiaUPRPPipelineUtils.ConfigureCamera()] A camera could not be found to upgrade in your scene.");
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UPPipeline
|
||||
UniversalAdditionalCameraData cameraData = GaiaURPRuntimeUtils.GetUPCameraData(camera);
|
||||
cameraData.renderShadows = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Configures lighting to LWRP
|
||||
/// </summary>
|
||||
private static void ConfigureLighting()
|
||||
{
|
||||
try
|
||||
{
|
||||
#if UPPipeline
|
||||
Light[] lights = Object.FindObjectsOfType<Light>();
|
||||
if (lights.Length > 0)
|
||||
{
|
||||
foreach (Light data in lights)
|
||||
{
|
||||
GaiaURPRuntimeUtils.GetUPLightData(data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the sun intensity
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <param name="volumeProfile"></param>
|
||||
public static void SetSunSettings(GaiaLightingProfileValues profile)
|
||||
{
|
||||
try
|
||||
{
|
||||
Light light = GaiaUtils.GetMainDirectionalLight();
|
||||
if (light != null)
|
||||
{
|
||||
light.color = profile.m_lWSunColor;
|
||||
light.intensity = profile.m_lWSunIntensity;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Configures water to URP
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
private static void ConfigureWater(UnityPipelineProfile profile, GaiaSettings gaiaSettings)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (gaiaSettings == null)
|
||||
{
|
||||
Debug.LogError("Gaia settings could not be found. Please make sure gaia settings is import into your project");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (profile.m_underwaterHorizonMaterial != null)
|
||||
{
|
||||
profile.m_underwaterHorizonMaterial.shader = Shader.Find(profile.m_universalHorizonObjectShader);
|
||||
}
|
||||
|
||||
GameObject waterObject = GameObject.Find(gaiaSettings.m_gaiaWaterProfile.m_waterPrefab.name);
|
||||
if (waterObject != null)
|
||||
{
|
||||
Material waterMat = GaiaWater.GetGaiaOceanMaterial();
|
||||
if (waterMat != null)
|
||||
{
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaWater.GetProfile(gaiaSettings.m_gaiaWaterProfile.m_selectedWaterProfileValuesIndex, waterMat, GaiaGlobal.Instance.SceneProfile, true, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Material could not be found");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Apply URP post fx
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <param name="lightingProfile"></param>
|
||||
public static GameObject ApplyURPPostProcessing(GaiaLightingProfileValues profile, SceneProfile lightingProfile)
|
||||
{
|
||||
try
|
||||
{
|
||||
GameObject volumeObject = null;
|
||||
#if UPPipeline
|
||||
if (lightingProfile.m_enablePostProcessing)
|
||||
{
|
||||
volumeObject = GameObject.Find("Global Post Processing");
|
||||
if (volumeObject == null)
|
||||
{
|
||||
volumeObject = new GameObject("Global Post Processing");
|
||||
}
|
||||
|
||||
GameObject parentObject = GaiaLighting.GetOrCreateParentObject(GaiaConstants.gaiaLightingObject, true);
|
||||
if (parentObject != null)
|
||||
{
|
||||
volumeObject.transform.SetParent(parentObject.transform);
|
||||
}
|
||||
volumeObject.layer = 0;
|
||||
|
||||
Volume volume = volumeObject.GetComponent<Volume>();
|
||||
if (volume == null)
|
||||
{
|
||||
volume = volumeObject.AddComponent<Volume>();
|
||||
}
|
||||
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
SceneProfile sceneProfile = GaiaGlobal.Instance.SceneProfile;
|
||||
if (sceneProfile != null)
|
||||
{
|
||||
if (sceneProfile.m_lightingEditSettings || profile.m_userCustomProfile)
|
||||
{
|
||||
sceneProfile.m_universalPostFXProfile = profile.PostProcessProfileURP;
|
||||
}
|
||||
else
|
||||
{
|
||||
CreatePostFXProfileInstance(sceneProfile, profile);
|
||||
}
|
||||
|
||||
volume.sharedProfile = sceneProfile.m_universalPostFXProfile;
|
||||
|
||||
Camera camera = GaiaUtils.GetCamera();
|
||||
if (camera != null)
|
||||
{
|
||||
UniversalAdditionalCameraData cameraData = camera.GetComponent<UniversalAdditionalCameraData>();
|
||||
if (cameraData == null)
|
||||
{
|
||||
cameraData = camera.gameObject.AddComponent<UniversalAdditionalCameraData>();
|
||||
}
|
||||
|
||||
cameraData.renderPostProcessing = true;
|
||||
GaiaLighting.ConfigureAntiAliasing(sceneProfile, GaiaConstants.EnvironmentRenderer.Universal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
volumeObject = GameObject.Find("Global Post Processing");
|
||||
if (volumeObject != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(volumeObject);
|
||||
}
|
||||
|
||||
Camera camera = GaiaUtils.GetCamera();
|
||||
if (camera != null)
|
||||
{
|
||||
UniversalAdditionalCameraData cameraData = camera.GetComponent<UniversalAdditionalCameraData>();
|
||||
if (cameraData == null)
|
||||
{
|
||||
cameraData = camera.gameObject.AddComponent<UniversalAdditionalCameraData>();
|
||||
}
|
||||
|
||||
cameraData.renderPostProcessing = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
PostProcessLayer postProcessLayer = GameObject.FindObjectOfType<PostProcessLayer>();
|
||||
if (postProcessLayer != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(postProcessLayer);
|
||||
}
|
||||
|
||||
PostProcessVolume postProcessVolume = GameObject.FindObjectOfType<PostProcessVolume>();
|
||||
if (postProcessVolume != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(postProcessVolume);
|
||||
}
|
||||
#endif
|
||||
|
||||
return volumeObject;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Crate post processing instance profile
|
||||
/// </summary>
|
||||
/// <param name="sceneProfile"></param>
|
||||
public static void CreatePostFXProfileInstance(SceneProfile sceneProfile, GaiaLightingProfileValues profile)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sceneProfile == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if UPPipeline
|
||||
VolumeProfile volumeProfile = AssetDatabase.LoadAssetAtPath<VolumeProfile>(GaiaUtils.GetAssetPath("URP Global Post Processing Profile.asset"));
|
||||
if (profile.PostProcessProfileURP != null)
|
||||
{
|
||||
volumeProfile = profile.PostProcessProfileURP;
|
||||
}
|
||||
if (volumeProfile == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GaiaSessionManager session = GaiaSessionManager.GetSessionManager();
|
||||
if (session != null)
|
||||
{
|
||||
string path = GaiaDirectories.GetSceneProfilesFolderPath(session.m_session);
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
if (EditorSceneManager.GetActiveScene() != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(EditorSceneManager.GetActiveScene().path))
|
||||
{
|
||||
path = path + "/" + EditorSceneManager.GetActiveScene().name + " " + volumeProfile.name + " Profile.asset";
|
||||
}
|
||||
else
|
||||
{
|
||||
path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
|
||||
}
|
||||
|
||||
if (sceneProfile.m_universalPostFXProfile != null)
|
||||
{
|
||||
if (!sceneProfile.m_isUserProfileSet)
|
||||
{
|
||||
if (!sceneProfile.m_universalPostFXProfile.name.Contains(volumeProfile.name))
|
||||
{
|
||||
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(sceneProfile.m_universalPostFXProfile));
|
||||
sceneProfile.m_universalPostFXProfile = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (AssetDatabase.LoadAssetAtPath<VolumeProfile>(path) == null)
|
||||
{
|
||||
FileUtil.CopyFileOrDirectory(AssetDatabase.GetAssetPath(volumeProfile), path);
|
||||
AssetDatabase.ImportAsset(path);
|
||||
}
|
||||
|
||||
sceneProfile.m_universalPostFXProfile = AssetDatabase.LoadAssetAtPath<VolumeProfile>(path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Update the shadow distance
|
||||
/// </summary>
|
||||
private static void UpdateShadowDistance()
|
||||
{
|
||||
#if UPPipeline
|
||||
UniversalRenderPipelineAsset asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
|
||||
if (asset != null)
|
||||
{
|
||||
bool setDirty = false;
|
||||
if (asset.shadowDistance != QualitySettings.shadowDistance)
|
||||
{
|
||||
asset.shadowDistance = QualitySettings.shadowDistance;
|
||||
setDirty = true;
|
||||
}
|
||||
|
||||
if (asset.shadowCascadeOption != ShadowCascadesOption.FourCascades)
|
||||
{
|
||||
asset.shadowCascadeOption = ShadowCascadesOption.FourCascades;
|
||||
setDirty = true;
|
||||
}
|
||||
|
||||
if (setDirty)
|
||||
{
|
||||
EditorUtility.SetDirty(asset);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// Finalizes the LWRP setup for your project
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
private static void FinalizeURP(UnityPipelineProfile profile)
|
||||
{
|
||||
try
|
||||
{
|
||||
MarkSceneDirty(true);
|
||||
EditorUtility.SetDirty(profile);
|
||||
profile.m_activePipelineInstalled = GaiaConstants.EnvironmentRenderer.Universal;
|
||||
UpdateURPPipelineSettings(true, true);
|
||||
|
||||
Debug.Log("Finalized URP");
|
||||
|
||||
GaiaManagerEditor manager = EditorWindow.GetWindow<Gaia.GaiaManagerEditor>(false, "Gaia Manager");
|
||||
if (manager != null)
|
||||
{
|
||||
manager.GaiaManagerStatusCheck(true);
|
||||
manager.CheckForSetupIssues();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the biome post fx to SRP volume profile
|
||||
/// </summary>
|
||||
private static void UpdateBiomePostFX()
|
||||
{
|
||||
try
|
||||
{
|
||||
GaiaPostProcessBiome[] gaiaPostProcessBiomes = GameObject.FindObjectsOfType<GaiaPostProcessBiome>();
|
||||
if (gaiaPostProcessBiomes.Length > 0)
|
||||
{
|
||||
foreach (GaiaPostProcessBiome biome in gaiaPostProcessBiomes)
|
||||
{
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
PostProcessVolume processVolume = biome.GetComponent<PostProcessVolume>();
|
||||
if (processVolume != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(processVolume);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UPPipeline
|
||||
Volume volumeComp = biome.GetComponent<Volume>();
|
||||
if (volumeComp == null)
|
||||
{
|
||||
volumeComp = biome.gameObject.AddComponent<Volume>();
|
||||
volumeComp.sharedProfile = AssetDatabase.LoadAssetAtPath<VolumeProfile>(GaiaUtils.GetAssetPath("UP " + biome.PostProcessingFileName + ".asset"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
UpdateShadowDistance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Cleans up LWRP components in the scene
|
||||
/// </summary>
|
||||
public static void CleanUpURP(UnityPipelineProfile profile, GaiaSettings gaiaSettings)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if UPPipeline
|
||||
UniversalAdditionalCameraData[] camerasData = GameObject.FindObjectsOfType<UniversalAdditionalCameraData>();
|
||||
GaiaURPRuntimeUtils.ClearUPCameraData(camerasData);
|
||||
|
||||
UniversalAdditionalLightData[] lightsData = GameObject.FindObjectsOfType<UniversalAdditionalLightData>();
|
||||
GaiaURPRuntimeUtils.ClearUPLightData(lightsData);
|
||||
|
||||
GameObject volumeObject = GameObject.Find("Global Post Processing");
|
||||
if (volumeObject != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(volumeObject);
|
||||
}
|
||||
|
||||
Camera camera = GaiaUtils.GetCamera();
|
||||
if (camera != null)
|
||||
{
|
||||
UniversalAdditionalCameraData cameraData = camera.GetComponent<UniversalAdditionalCameraData>();
|
||||
if (cameraData == null)
|
||||
{
|
||||
cameraData = camera.gameObject.AddComponent<UniversalAdditionalCameraData>();
|
||||
}
|
||||
|
||||
cameraData.renderPostProcessing = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (profile.m_underwaterHorizonMaterial != null)
|
||||
{
|
||||
profile.m_underwaterHorizonMaterial.shader = Shader.Find(profile.m_builtInHorizonObjectShader);
|
||||
}
|
||||
|
||||
GameObject waterPrefab = GameObject.Find(gaiaSettings.m_gaiaWaterProfile.m_waterPrefab.name);
|
||||
if (waterPrefab != null)
|
||||
{
|
||||
//reverting default water mesh quality
|
||||
gaiaSettings.m_gaiaWaterProfile.m_customMeshQuality = 2;
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaWater.UpdateWaterMeshQuality(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_gaiaWaterProfile.m_waterPrefab);
|
||||
}
|
||||
|
||||
PWS_WaterSystem reflection = waterPrefab.GetComponent<PWS_WaterSystem>();
|
||||
if (reflection == null)
|
||||
{
|
||||
reflection = waterPrefab.AddComponent<PWS_WaterSystem>();
|
||||
}
|
||||
}
|
||||
|
||||
Terrain[] terrains = Terrain.activeTerrains;
|
||||
if (terrains != null)
|
||||
{
|
||||
foreach (Terrain terrain in terrains)
|
||||
{
|
||||
#if !UNITY_2019_2_OR_NEWER
|
||||
terrain.materialType = Terrain.MaterialType.BuiltInStandard;
|
||||
#else
|
||||
terrain.materialTemplate = profile.m_builtInTerrainMaterial;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Terrain terrainDetail = Terrain.activeTerrain;
|
||||
if (terrainDetail != null)
|
||||
{
|
||||
if (terrainDetail.detailObjectDensity == 0f)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Detail Density Disabled!", "Details density is disabled on your terrain would you like to activate it?", "Yes", "No"))
|
||||
{
|
||||
terrainDetail.detailObjectDensity = 0.3f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameObject LWRPReflections = GameObject.Find("URP Water Reflection Probe");
|
||||
if (LWRPReflections != null)
|
||||
{
|
||||
Object.DestroyImmediate(LWRPReflections);
|
||||
}
|
||||
|
||||
GraphicsSettings.renderPipelineAsset = null;
|
||||
QualitySettings.renderPipeline = null;
|
||||
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
//GaiaUtils.GetRuntimeSceneObject();
|
||||
if (GaiaGlobal.Instance.SceneProfile != null && GaiaGlobal.Instance.SceneProfile.m_lightingProfiles.Count>0)
|
||||
{
|
||||
GaiaLighting.GetProfile(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_pipelineProfile, GaiaConstants.EnvironmentRenderer.BuiltIn);
|
||||
}
|
||||
}
|
||||
|
||||
//Clean up the UPR post processing objects in the underwater effects
|
||||
//We need to look for transform instead of GameObjects, since the GOs can be disabled and won't be found then
|
||||
GameObject uwe = GameObject.Find(GaiaConstants.underwaterEffectsName);
|
||||
if (uwe != null)
|
||||
{
|
||||
|
||||
Transform utoTransform = uwe.transform.Find(GaiaConstants.underwaterTransitionObjectName);
|
||||
if (utoTransform != null)
|
||||
{
|
||||
Object.DestroyImmediate(utoTransform.gameObject);
|
||||
}
|
||||
|
||||
Transform uppTransform = uwe.transform.Find(GaiaConstants.underwaterPostProcessingName);
|
||||
if (uppTransform != null)
|
||||
{
|
||||
Object.DestroyImmediate(uppTransform.gameObject);
|
||||
}
|
||||
|
||||
Transform horizonTransform = uwe.transform.Find(GaiaConstants.underwaterHorizonName);
|
||||
if (horizonTransform != null)
|
||||
{
|
||||
Object.DestroyImmediate(horizonTransform.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (waterPrefab != null)
|
||||
{
|
||||
Material waterMat = GaiaWater.GetGaiaOceanMaterial();
|
||||
if (waterMat != null)
|
||||
{
|
||||
if (GaiaGlobal.Instance != null)
|
||||
{
|
||||
GaiaWater.GetProfile(gaiaSettings.m_gaiaWaterProfile.m_selectedWaterProfileValuesIndex, waterMat, GaiaGlobal.Instance.SceneProfile, true, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Material could not be found");
|
||||
}
|
||||
}
|
||||
|
||||
MarkSceneDirty(false);
|
||||
EditorUtility.SetDirty(profile);
|
||||
profile.m_activePipelineInstalled = GaiaConstants.EnvironmentRenderer.BuiltIn;
|
||||
|
||||
GaiaManagerEditor manager = EditorWindow.GetWindow<Gaia.GaiaManagerEditor>(false, "Gaia Manager");
|
||||
if (manager != null)
|
||||
{
|
||||
manager.GaiaManagerStatusCheck(true);
|
||||
}
|
||||
|
||||
bool isChanged = false;
|
||||
string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (currBuildSettings.Contains("UPPipeline"))
|
||||
{
|
||||
currBuildSettings = currBuildSettings.Replace("UPPipeline;", "");
|
||||
currBuildSettings = currBuildSettings.Replace("UPPipeline", "");
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Enables or disables motion blur
|
||||
/// </summary>
|
||||
/// <param name="enabled"></param>
|
||||
private static void SetMotionBlurPostFX(bool enabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
//Create profile list
|
||||
List<PostProcessProfile> postProcessProfiles = new List<PostProcessProfile>();
|
||||
//Clear List
|
||||
postProcessProfiles.Clear();
|
||||
|
||||
//All volumes in scene
|
||||
PostProcessVolume[] postProcessVolumes = Object.FindObjectsOfType<PostProcessVolume>();
|
||||
if (postProcessVolumes != null)
|
||||
{
|
||||
foreach(PostProcessVolume volume in postProcessVolumes)
|
||||
{
|
||||
//Check it has a profile
|
||||
if (volume.sharedProfile != null)
|
||||
{
|
||||
//Add the profile to array
|
||||
postProcessProfiles.Add(volume.sharedProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (postProcessProfiles != null)
|
||||
{
|
||||
//Motion blur
|
||||
foreach (PostProcessProfile profile in postProcessProfiles)
|
||||
{
|
||||
//Check if profile has setting
|
||||
if (profile.TryGetSettings(out UnityEngine.Rendering.PostProcessing.MotionBlur motionBlur))
|
||||
{
|
||||
|
||||
EditorUtility.SetDirty(profile);
|
||||
//Set ture/false based on input
|
||||
motionBlur.active = enabled;
|
||||
motionBlur.enabled.value = enabled;
|
||||
|
||||
Debug.Log(profile.name + ": Motion blur has been disabled in this profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the AA mode ont he camera
|
||||
/// </summary>
|
||||
/// <param name="antiAliasingMode"></param>
|
||||
private static void SetAntiAliasingMode(GaiaConstants.GaiaProAntiAliasingMode antiAliasingMode)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
PostProcessLayer processLayer = Object.FindObjectOfType<PostProcessLayer>();
|
||||
if (processLayer != null)
|
||||
{
|
||||
Camera camera = Camera.main;
|
||||
switch (antiAliasingMode)
|
||||
{
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.None:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.None;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.FXAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.FastApproximateAntialiasing;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.MSAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.None;
|
||||
camera.allowMSAA = true;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.SMAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
case GaiaConstants.GaiaProAntiAliasingMode.TAA:
|
||||
processLayer.antialiasingMode = PostProcessLayer.Antialiasing.TemporalAntialiasing;
|
||||
camera.allowMSAA = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Starts the LWRP Setup
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerator StartURPSetup(UnityPipelineProfile profile)
|
||||
{
|
||||
if (profile == null)
|
||||
{
|
||||
Debug.LogError("UnityPipelineProfile is empty");
|
||||
yield return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Installing Universal", "Updating scripting defines", 0.5f);
|
||||
m_waitTimer1 -= Time.deltaTime;
|
||||
if (m_waitTimer1 < 0)
|
||||
{
|
||||
SetScriptingDefines(profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
while (EditorApplication.isCompiling)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
EditorUtility.DisplayProgressBar("Installing Universal", "Updating scene to Universal", 0.75f);
|
||||
m_waitTimer2 -= Time.deltaTime;
|
||||
if (m_waitTimer2 < 0)
|
||||
{
|
||||
ConfigureSceneToURP(profile);
|
||||
profile.m_pipelineSwitchUpdates = false;
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Save the assets and marks scene as dirty
|
||||
/// </summary>
|
||||
/// <param name="saveAlso"></param>
|
||||
private static void MarkSceneDirty(bool saveAlso)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
if (saveAlso)
|
||||
{
|
||||
if (EditorSceneManager.GetActiveScene().isDirty)
|
||||
{
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5013abddf9d615144b2d5f82ede21959
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,133 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Scripting.APIUpdating;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Export current terrain as a water flow map
|
||||
/// </summary>
|
||||
public class GaiaWaterflowMapEditor : EditorWindow
|
||||
{
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private string m_maskName;
|
||||
private WaterFlowMap m_waterFlowMap = new WaterFlowMap();
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.fontStyle = FontStyle.Normal;
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("Gaia WaterFlow Mask Exporter", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("The Gaia waterflow exporter allows you to calculate and export a water flow mask from your terrain.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (string.IsNullOrEmpty(m_maskName))
|
||||
{
|
||||
m_maskName = string.Format("TerrainWaterFlow-{0:yyyyMMdd-HHmmss}", DateTime.Now);
|
||||
}
|
||||
m_maskName = EditorGUILayout.TextField(GetLabel("Mask Name"), m_maskName);
|
||||
|
||||
m_waterFlowMap.m_dropletVolume = EditorGUILayout.Slider(GetLabel("Droplet Volume"), m_waterFlowMap.m_dropletVolume, 0.1f, 2f);
|
||||
m_waterFlowMap.m_dropletAbsorbtionRate = EditorGUILayout.Slider(GetLabel("Droplet Absorbtion Rate"), m_waterFlowMap.m_dropletAbsorbtionRate, 0.01f, 1f);
|
||||
m_waterFlowMap.m_waterflowSmoothIterations = EditorGUILayout.IntSlider(GetLabel("Smooth Iterations"), m_waterFlowMap.m_waterflowSmoothIterations, 0, 10);
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (DisplayButton(GetLabel("Create Mask")))
|
||||
{
|
||||
Terrain terrain = Gaia.TerrainHelper.GetActiveTerrain();
|
||||
if (terrain == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("OOPS!", "You must have a valid terrain!!", "OK");
|
||||
return;
|
||||
}
|
||||
GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();
|
||||
string path = GaiaDirectories.GetExportDirectory(gsm.m_session);
|
||||
|
||||
path = Path.Combine(path, PWCommon4.Utils.FixFileName(m_maskName));
|
||||
|
||||
m_waterFlowMap.CreateWaterFlowMap(terrain);
|
||||
m_waterFlowMap.ExportWaterMapToPath(path);
|
||||
|
||||
|
||||
GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);
|
||||
mgr.LoadFromWorld();
|
||||
|
||||
path += "WaterFlow";
|
||||
mgr.ExportWaterflowMapAsPng(m_waterFlowMap.m_waterflowSmoothIterations, path);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.DisplayDialog("Done!", "Your mask is available at " + path, "OK");
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a button that takes editor indentation into account
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
bool DisplayButton(GUIContent content)
|
||||
{
|
||||
TextAnchor oldalignment = GUI.skin.button.alignment;
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
Rect btnR = EditorGUILayout.BeginHorizontal();
|
||||
btnR.xMin += (EditorGUI.indentLevel * 18f);
|
||||
btnR.height += 20f;
|
||||
btnR.width -= 4f;
|
||||
bool result = GUI.Button(btnR, content);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space(22);
|
||||
GUI.skin.button.alignment = oldalignment;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Execution Mode", "The way this spawner runs. Design time : At design time only. Runtime Interval : At run time on a timed interval. Runtime Triggered Interval : At run time on a timed interval, and only when the tagged game object is closer than the trigger range from the center of the spawner." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d4e395c6ecfb754c86c01111713e0d5
|
||||
timeCreated: 1454543640
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
public class GaiaWelcome : CustomWelcome
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
|
||||
public override AppConfig AppConfig { get { return PWApp.CONF; } }
|
||||
|
||||
public override bool PositionChecked { get; set; }
|
||||
|
||||
public GaiaWelcome()
|
||||
{
|
||||
}
|
||||
|
||||
~GaiaWelcome()
|
||||
{
|
||||
if (m_editorUtils != null)
|
||||
{
|
||||
m_editorUtils.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void WelcomeGUI()
|
||||
{
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
m_editorUtils.Initialize();
|
||||
m_editorUtils.GUIHeader();
|
||||
|
||||
m_editorUtils.Title("Welcome title");
|
||||
|
||||
EditorGUILayout.Space();
|
||||
m_editorUtils.Text("Welcome message");
|
||||
|
||||
GUILayout.Space(10f);
|
||||
if (m_editorUtils.ButtonCentered("Open Quick Start Button", GUILayout.Width(250f)))
|
||||
{
|
||||
Application.OpenURL("http://www.procedural-worlds.com/gaia/?section=tutorials");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 280800929fd33d74ca0bda371deb9899
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright © 2018 Procedural Worlds Pty Limited. All Rights Reserved.
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using PWCommon4;
|
||||
|
||||
namespace Gaia.Internal
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public static class PWApp
|
||||
{
|
||||
private const string CONF_NAME = "Gaia";
|
||||
|
||||
private static AppConfig m_conf;
|
||||
public static AppConfig CONF
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_conf != null)
|
||||
{
|
||||
return m_conf;
|
||||
}
|
||||
|
||||
m_conf = AssetUtils.GetConfig(CONF_NAME);
|
||||
if (m_conf != null)
|
||||
{
|
||||
Prod.Checkin(m_conf);
|
||||
}
|
||||
|
||||
return m_conf;
|
||||
}
|
||||
}
|
||||
|
||||
static PWApp()
|
||||
{
|
||||
// Need to wait for things to import before creating the common menu - Using delegates and only check menu when something gets imported
|
||||
AssetDatabase.importPackageCompleted -= OnImportPackageCompleted;
|
||||
AssetDatabase.importPackageCompleted += OnImportPackageCompleted;
|
||||
|
||||
AssetDatabase.importPackageCancelled -= OnImportPackageCancelled;
|
||||
AssetDatabase.importPackageCancelled += OnImportPackageCancelled;
|
||||
|
||||
AssetDatabase.importPackageFailed -= OnImportPackageFailed;
|
||||
AssetDatabase.importPackageFailed += OnImportPackageFailed;
|
||||
|
||||
m_conf = AssetUtils.GetConfig(CONF_NAME, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a package import is Completed.
|
||||
/// </summary>
|
||||
private static void OnImportPackageCompleted(string packageName)
|
||||
{
|
||||
#if PW_DEBUG
|
||||
Debug.LogFormat("[C.Prod]: '{0}' Import Completed", packageName);
|
||||
#endif
|
||||
OnPackageImport();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a package import is Cancelled.
|
||||
/// </summary>
|
||||
private static void OnImportPackageCancelled(string packageName)
|
||||
{
|
||||
Debug.LogWarningFormat("'{0}' Import was Cancelled.", packageName);
|
||||
OnPackageImport();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a package import fails.
|
||||
/// </summary>
|
||||
private static void OnImportPackageFailed(string packageName, string error)
|
||||
{
|
||||
Debug.LogErrorFormat("'{0}' Import Failed with error message: '{1}'.", packageName, error);
|
||||
OnPackageImport();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to run things after a package was imported.
|
||||
/// </summary>
|
||||
private static void OnPackageImport()
|
||||
{
|
||||
if (m_conf == null)
|
||||
{
|
||||
m_conf = AssetUtils.GetConfig(CONF_NAME);
|
||||
}
|
||||
Prod.Checkin(m_conf);
|
||||
|
||||
// No need for these anymore
|
||||
AssetDatabase.importPackageCompleted -= OnImportPackageCompleted;
|
||||
AssetDatabase.importPackageCancelled -= OnImportPackageCancelled;
|
||||
AssetDatabase.importPackageFailed -= OnImportPackageFailed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an editor utils object that can be used for common Editor stuff - DO make sure to Dispose() the instance.
|
||||
/// </summary>
|
||||
/// <param name="editorObj">The class that uses the utils. Just pass in "this".</param>
|
||||
/// <param name="customUpdateMethod">(Optional) The method to be called when the GUI needs to be updated. (Repaint will always be called.)</param>
|
||||
/// <param name="customNewsURL">(Optional) Custom News URL to fetch the news messages from (will default to the News URL in app config if none provided)</param>
|
||||
/// <param name="overrideParameters">A custom set of URL Parameters to use when fetching news data. If left empty, the default set of parameters will be used</param>
|
||||
/// <returns>Editor Utils</returns>
|
||||
public static EditorUtils GetEditorUtils(IPWEditor editorObj, System.Action customUpdateMethod = null, string customNewsURL = null, URLParameters overrideParameters = null)
|
||||
{
|
||||
return new EditorUtils(CONF, editorObj, null, customUpdateMethod, customNewsURL, overrideParameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef2b9244d6f3ff64bb30fe51af77f644
|
||||
timeCreated: 1537200527
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,583 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Gaia;
|
||||
using System;
|
||||
using System.IO;
|
||||
using PWCommon4;
|
||||
using Gaia.Pipeline;
|
||||
using System.Linq;
|
||||
using Gaia.ShaderUtilities;
|
||||
using UnityEditor.Rendering;
|
||||
|
||||
namespace ProceduralWorlds.Gaia.PackageSystem
|
||||
{
|
||||
public class PackageInstallerUtils
|
||||
{
|
||||
//Public
|
||||
public static bool m_installShaders = false;
|
||||
public static float m_timer;
|
||||
//Private
|
||||
private static List<string> m_foldersToProcess = new List<string>();
|
||||
private static ShaderMappingEntry[] m_materialLibrary;
|
||||
private static float m_progressTimer;
|
||||
private static GaiaConstants.EnvironmentRenderer m_renderPipeline;
|
||||
private static string m_unityVersion;
|
||||
private static UnityPipelineProfile m_gaiaPipelineProfile;
|
||||
|
||||
//Private const strings
|
||||
|
||||
public static void StartInstallation(string unityVersion, GaiaConstants.EnvironmentRenderer renderPipeline, ShaderMappingEntry[] materialLibrary, UnityPipelineProfile pipelineProfile, bool showDialog = true)
|
||||
{
|
||||
//Set settings
|
||||
m_materialLibrary = materialLibrary;
|
||||
m_progressTimer = m_timer;
|
||||
m_renderPipeline = renderPipeline;
|
||||
m_unityVersion = unityVersion;
|
||||
m_gaiaPipelineProfile = pipelineProfile;
|
||||
|
||||
//Checks if the material library is empty
|
||||
if (m_materialLibrary.Length == 0)
|
||||
{
|
||||
Debug.LogError("Material Library is empty. Please check the pipeline profile that it contains the necessary information");
|
||||
FinishInstallingPackages();
|
||||
return;
|
||||
}
|
||||
|
||||
//Popup dialog to proceed
|
||||
if (showDialog)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Importing Shaders and Materials", "You are about to install new shaders and materials to targeted pipeline and unity version. Please make sure you're using the correct SRP before you proceed. Are you sure you want to proceed?", "Yes", "No"))
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Preparing Installation", "Preparing shader directories...", 0.5f);
|
||||
|
||||
StartInstallingPackage();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Finish and exit
|
||||
FinishInstallingPackages();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Preparing Installation", "Preparing shader directories...", 0.5f);
|
||||
|
||||
StartInstallingPackage();
|
||||
}
|
||||
|
||||
var manager = EditorWindow.GetWindow<GaiaManagerEditor>(false, "Gaia Manager");
|
||||
//Manager can be null if the dependency package installation is started upon opening the manager window.
|
||||
if (manager != null)
|
||||
{
|
||||
//Perform the status check in the manager again to update the UI to the (hopefully successful) installation
|
||||
manager.GaiaManagerStatusCheck(true);
|
||||
}
|
||||
m_installShaders = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start install process
|
||||
/// </summary>
|
||||
private static void StartInstallingPackage2()
|
||||
{
|
||||
var manager = EditorWindow.GetWindow<GaiaManagerEditor>(false, "Gaia Manager");
|
||||
//Manager can be null if the dependency package installation is started upon opening the manager window.
|
||||
if (manager != null)
|
||||
{
|
||||
manager.Close();
|
||||
}
|
||||
m_installShaders = false;
|
||||
EditorApplication.update += EditorUpdate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finish and exit installation
|
||||
/// </summary>
|
||||
private static void FinishInstallingPackages()
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
m_installShaders = false;
|
||||
|
||||
var manager = EditorWindow.GetWindow<GaiaManagerEditor>(false, "Gaia Manager");
|
||||
//Manager can be null if the dependency package installation is started upon opening the manager window.
|
||||
if (manager != null)
|
||||
{
|
||||
manager.Show();
|
||||
manager.CheckForSetupIssues();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start installation
|
||||
/// </summary>
|
||||
private static void StartInstallingPackage()
|
||||
{
|
||||
//bool updatesChanges = false;
|
||||
//string shaderRootFolder = GaiaDirectories.GetShaderDirectory();
|
||||
//if (m_gaiaPipelineProfile == null)
|
||||
//{
|
||||
// m_gaiaPipelineProfile = GetPipelineProfile();
|
||||
//}
|
||||
|
||||
////Add Shader setup here
|
||||
//string[] folderPaths = Directory.GetDirectories(shaderRootFolder, ".", SearchOption.AllDirectories);
|
||||
//foreach (string folderPath in folderPaths)
|
||||
//{
|
||||
// CleanUpFolder(folderPath);
|
||||
//}
|
||||
|
||||
//AssetDatabase.Refresh();
|
||||
|
||||
//m_unityVersion = Application.unityVersion;
|
||||
//m_unityVersion = m_unityVersion.Remove(m_unityVersion.LastIndexOf(".")).Replace(".", "_0");
|
||||
//string keyWordToSearch = "";
|
||||
//if (m_installShaders)
|
||||
//{
|
||||
// if (m_renderPipeline == GaiaConstants.EnvironmentRenderer.BuiltIn)
|
||||
// {
|
||||
// keyWordToSearch = GaiaConstants.builtInKeyWord;
|
||||
// }
|
||||
// else if (m_renderPipeline == GaiaConstants.EnvironmentRenderer.Lightweight)
|
||||
// {
|
||||
// keyWordToSearch = GaiaConstants.lightweightKeyWord;
|
||||
// }
|
||||
// else if (m_renderPipeline == GaiaConstants.EnvironmentRenderer.Universal)
|
||||
// {
|
||||
// keyWordToSearch = GaiaConstants.universalKeyWord;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// keyWordToSearch = GaiaConstants.highDefinitionKeyWord;
|
||||
// }
|
||||
|
||||
// int numberOfFolders = folderPaths.Length;
|
||||
// int currentFolder = 1;
|
||||
|
||||
// foreach (string folderpath in folderPaths)
|
||||
// {
|
||||
// //try
|
||||
// //{
|
||||
// // EditorUtility.DisplayProgressBar("Processing Shader Library", "Processing Library Folder " + currentFolder.ToString() + " of " + numberOfFolders.ToString(), (float)currentFolder / (float)numberOfFolders);
|
||||
|
||||
// // string finalFolderName = "";
|
||||
|
||||
// // if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.LinuxEditor)
|
||||
// // finalFolderName = folderpath.Substring(folderpath.LastIndexOf("/"));
|
||||
// // else
|
||||
// // finalFolderName = folderpath.Substring(folderpath.LastIndexOf("\\"));
|
||||
|
||||
// // if (!folderpath.EndsWith("PWSF Functions") && !folderpath.EndsWith("PWS Procedural") && !folderpath.EndsWith("PWS Water Pro"))
|
||||
// // {
|
||||
// // if (finalFolderName.Contains(keyWordToSearch + " " + m_unityVersion))
|
||||
// // {
|
||||
// // updatesChanges = RemoveFileSuffix(folderpath);
|
||||
// // foreach (MaterialLibraryEntry entry in m_materialLibrary)
|
||||
// // {
|
||||
// // if (folderpath.Contains(entry.m_folderKeyWord))
|
||||
// // {
|
||||
// // entry.m_shaderToInstall = GetShaderFile(folderpath, entry.m_shaderKeyWord);
|
||||
// // break;
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // updatesChanges = AddFileSuffix(folderpath);
|
||||
// // }
|
||||
// // }
|
||||
// //}
|
||||
// //catch (Exception ex)
|
||||
// //{
|
||||
// // Debug.LogError("Exception while processing the Shader Library Folders, folder path: '" + folderpath + "'. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
|
||||
// //}
|
||||
|
||||
// //currentFolder++;
|
||||
// }
|
||||
|
||||
// if (updatesChanges)
|
||||
// {
|
||||
// AssetDatabase.Refresh();
|
||||
// }
|
||||
|
||||
// StartInstallingPackage2();
|
||||
//}
|
||||
|
||||
//if (m_installMaterials)
|
||||
//{
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
|
||||
bool updateChanges = false;
|
||||
bool promptRenderPipelineMaterialUpdate = false;
|
||||
|
||||
if (m_materialLibrary == null)
|
||||
{
|
||||
Debug.LogError("Unable to load the Material Library");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Change all materials in the library to the correct shader each
|
||||
|
||||
try
|
||||
{
|
||||
int numberOfEntries = m_materialLibrary.Length;
|
||||
int currentEntry = 1;
|
||||
|
||||
|
||||
Shader builtInShader1 = Shader.Find(PWShaderNameUtility.ShaderName[1]);
|
||||
Shader builtInShader2 = Shader.Find(PWShaderNameUtility.ShaderName[2]);
|
||||
|
||||
if (builtInShader1 == null || builtInShader2 == null)
|
||||
{
|
||||
Debug.LogWarning($"One of the standard built in shaders ({ShaderIDs.PW_General_Forward.ToString()},{ShaderIDs.PW_General_Deferred.ToString()}) for shader mapping could not be found!");
|
||||
}
|
||||
|
||||
Shader[] specialBuiltInShaders = new Shader[3] { null, builtInShader1, builtInShader2 };
|
||||
|
||||
foreach (ShaderMappingEntry entry in m_materialLibrary)
|
||||
{
|
||||
string targetShaderName = entry.m_builtInShaderName;
|
||||
string searchShaderName1 = "";
|
||||
string searchShaderName2 = "";
|
||||
switch (m_renderPipeline)
|
||||
{
|
||||
case GaiaConstants.EnvironmentRenderer.BuiltIn:
|
||||
targetShaderName = entry.m_builtInShaderName;
|
||||
searchShaderName1 = entry.m_URPReplacementShaderName;
|
||||
searchShaderName2 = entry.m_HDRPReplacementShaderName;
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.Lightweight:
|
||||
//not supported anymore
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.Universal:
|
||||
targetShaderName = entry.m_URPReplacementShaderName;
|
||||
searchShaderName1 = entry.m_builtInShaderName;
|
||||
searchShaderName2 = entry.m_HDRPReplacementShaderName;
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.HighDefinition:
|
||||
targetShaderName = entry.m_HDRPReplacementShaderName;
|
||||
searchShaderName1 = entry.m_builtInShaderName;
|
||||
searchShaderName2 = entry.m_URPReplacementShaderName;
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Processing Shader Mapping", "Shader Mapping Entry " + currentEntry.ToString() + " of " + numberOfEntries.ToString(), (float)currentEntry / (float)numberOfEntries);
|
||||
|
||||
Shader targetShader = Shader.Find(targetShaderName);
|
||||
|
||||
if (targetShader == null)
|
||||
{
|
||||
Debug.LogError($"The target shader with the name {targetShaderName} from the shader mapping entry {entry.m_builtInShaderName} could not be found!");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Object shaderObject = null;
|
||||
switch (m_renderPipeline)
|
||||
{
|
||||
case GaiaConstants.EnvironmentRenderer.BuiltIn:
|
||||
shaderObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(GaiaUtils.GetAssetPath(targetShaderName + ".shader"));
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.Universal:
|
||||
shaderObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(GaiaUtils.GetAssetPath(targetShaderName + ".shadergraph"));
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.HighDefinition:
|
||||
shaderObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(GaiaUtils.GetAssetPath(targetShaderName + ".shadergraph"));
|
||||
break;
|
||||
}
|
||||
|
||||
if (shaderObject != null)
|
||||
{
|
||||
if (shaderObject.name.Contains("PW"))
|
||||
{
|
||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(shaderObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Get all the materials that currently use the shaders we want to migrate from
|
||||
Shader searchShader1 = Shader.Find(searchShaderName1);
|
||||
Shader searchShader2 = Shader.Find(searchShaderName2);
|
||||
|
||||
List<Material> affectedMaterials = GaiaUtils.FindMaterialsByShader(searchShader1).Concat(GaiaUtils.FindMaterialsByShader(searchShader2)).ToList();
|
||||
|
||||
foreach (Material material in affectedMaterials)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (material != null)
|
||||
{
|
||||
|
||||
switch (m_renderPipeline)
|
||||
{
|
||||
case GaiaConstants.EnvironmentRenderer.BuiltIn:
|
||||
bool mappedToSpecialShaders = false;
|
||||
if (material.HasProperty("_PW_ShaderID"))
|
||||
{
|
||||
float shaderID = material.GetFloat("_PW_ShaderID");
|
||||
if (shaderID >= 1)
|
||||
{
|
||||
material.shader = specialBuiltInShaders[(int)shaderID];
|
||||
EditorUtility.SetDirty(material);
|
||||
updateChanges = true;
|
||||
mappedToSpecialShaders = true;
|
||||
}
|
||||
}
|
||||
if (!mappedToSpecialShaders)
|
||||
{
|
||||
material.shader = targetShader;
|
||||
EditorUtility.SetDirty(material);
|
||||
updateChanges = true;
|
||||
}
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.Lightweight:
|
||||
//not supported
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.Universal:
|
||||
material.shader = targetShader;
|
||||
EditorUtility.SetDirty(material);
|
||||
updateChanges = true;
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.HighDefinition:
|
||||
bool isSolid = false;
|
||||
if (material.HasProperty("_PW_ShaderMode"))
|
||||
{
|
||||
if (material.GetFloat("_PW_ShaderMode") == 0)
|
||||
{
|
||||
isSolid = true;
|
||||
}
|
||||
}
|
||||
material.shader = targetShader;
|
||||
if (isSolid)
|
||||
{
|
||||
if (material.HasProperty("_AlphaCutoffEnable"))
|
||||
{
|
||||
material.SetFloat("_AlphaCutoffEnable", 0);
|
||||
}
|
||||
}
|
||||
EditorUtility.SetDirty(material);
|
||||
updateChanges = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
Debug.LogError("Exception while processing the Shader Mapping, Material: '" + material.name + "'. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Exception while processing the Shader Mapping, material is null! ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
Debug.LogError("Exception while processing the Material Library, entry: '" + entry.m_builtInShaderName + "'. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Exception while processing the Material Library. Entry is null! ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
|
||||
}
|
||||
}
|
||||
currentEntry++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError("Exception while processing the Material Library. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
Terrain[] terrains = Terrain.activeTerrains;
|
||||
if (terrains != null)
|
||||
{
|
||||
foreach (Terrain terrain in terrains)
|
||||
{
|
||||
terrain.UpdateGIMaterials();
|
||||
terrain.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
if (updateChanges)
|
||||
{
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
if (promptRenderPipelineMaterialUpdate)
|
||||
{
|
||||
GaiaUtils.DisplayDialogNoEditor("Please run the Pipeline Material upgrade process", "This project contains materials using the Unity Standard Shader. Please make sure to also run the Render Pipeline Material upgrade process to update those standard shaders. All shaders that are not updated via this process will not be displayed correctly in HDRP. Please look for the entry 'Upgrade Project Materials to High Definition Materials' under 'Edit > Render Pipelines' in your Window menu.", "OK", null);
|
||||
}
|
||||
|
||||
FinishInstallingPackages();
|
||||
|
||||
}
|
||||
|
||||
private static void CleanUpFolder(string folderPath)
|
||||
{
|
||||
if (!folderPath.EndsWith("PWSF Functions") && !folderPath.EndsWith("PWS Procedural") && !folderPath.EndsWith("PWS Water Pro"))
|
||||
{
|
||||
string finalFolderName = "";
|
||||
|
||||
if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.LinuxEditor)
|
||||
finalFolderName = folderPath.Substring(folderPath.LastIndexOf("/"));
|
||||
else
|
||||
finalFolderName = folderPath.Substring(folderPath.LastIndexOf("\\"));
|
||||
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
|
||||
var files = dirInfo.GetFiles();
|
||||
|
||||
bool isSRPFolder = finalFolderName.Contains("Vegetation HD") ||
|
||||
finalFolderName.Contains("Vegetation LW") ||
|
||||
finalFolderName.Contains("Vegetation UP") ||
|
||||
finalFolderName.Contains("Ocean Pro HD") ||
|
||||
finalFolderName.Contains("Ocean Pro LW") ||
|
||||
finalFolderName.Contains("Ocean Pro UP");
|
||||
List<FileInfo> deletionCandidates = new List<FileInfo>();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
if (!file.Name.EndsWith("meta"))
|
||||
{
|
||||
List<FileInfo> duplicates = files.Where(x => !x.Name.EndsWith("meta") && x.Name.Remove(x.Name.LastIndexOf(x.Extension)) == file.Name.Remove(file.Name.LastIndexOf(file.Extension))).ToList();
|
||||
if (duplicates.Count() > 1)
|
||||
{
|
||||
foreach (FileInfo duplicateFile in duplicates)
|
||||
{
|
||||
if (isSRPFolder && !duplicateFile.Extension.EndsWith("file"))
|
||||
{
|
||||
deletionCandidates.Add(duplicateFile);
|
||||
}
|
||||
if (!isSRPFolder && duplicateFile.Extension.EndsWith("file"))
|
||||
{
|
||||
deletionCandidates.Add(duplicateFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < deletionCandidates.Count(); i++)
|
||||
{
|
||||
FileUtil.DeleteFileOrDirectory(deletionCandidates[i].FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void EditorUpdate()
|
||||
{
|
||||
m_timer -= Time.deltaTime;
|
||||
if (m_timer < 0)
|
||||
{
|
||||
StartInstallingPackage();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Preparing Materials", "Preparing to upgrade material shaders...", m_progressTimer / m_timer);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes Suffix in file formats required
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
private static bool RemoveFileSuffix(string path)
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
var files = dirInfo.GetFiles();
|
||||
bool changes = false;
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
if (file.Extension.EndsWith("file"))
|
||||
{
|
||||
string fileName = file.FullName;
|
||||
File.Move(fileName, fileName.Remove(fileName.Length - 4, 4));
|
||||
changes = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changes)
|
||||
{
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes Suffix in file formats required
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
private static bool AddFileSuffix(string path)
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
var files = dirInfo.GetFiles();
|
||||
bool changes = false;
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
if (!file.Extension.EndsWith("file") && !file.Extension.EndsWith("meta"))
|
||||
{
|
||||
string fileName = file.FullName;
|
||||
File.Move(fileName, fileName.Replace(fileName, fileName + "file"));
|
||||
changes = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changes)
|
||||
{
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the shader
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="seachPattern"></param>
|
||||
/// <returns></returns>
|
||||
public static Shader GetShaderFile(string path, string seachPattern)
|
||||
{
|
||||
Shader returningShader = null;
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
var files = dirInfo.GetFiles();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
if (file.Extension.EndsWith("shader") && file.Name.Contains(seachPattern))
|
||||
{
|
||||
returningShader = AssetDatabase.LoadAssetAtPath<Shader>(GaiaUtils.GetAssetPath(file.Name));
|
||||
return returningShader;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the pipeline profile
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static UnityPipelineProfile GetPipelineProfile()
|
||||
{
|
||||
UnityPipelineProfile profile = null;
|
||||
|
||||
GaiaSettings settings = GaiaUtils.GetGaiaSettings();
|
||||
if (settings != null)
|
||||
{
|
||||
profile = settings.m_pipelineProfile;
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ac0c51e4d90b5849b036a7d3ef145cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,313 @@
|
||||
//using UnityEngine;
|
||||
//using UnityEditor;
|
||||
//using System.Collections.Generic;
|
||||
|
||||
//namespace Gaia
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// Editor for reource visualiser
|
||||
// /// </summary>
|
||||
// [CustomEditor(typeof(ResourceVisualiser))]
|
||||
// public class ResourceVisualiserEditor : Editor
|
||||
// {
|
||||
// GUIStyle m_boxStyle;
|
||||
// GUIStyle m_wrapStyle;
|
||||
// ResourceVisualiser m_visualiser;
|
||||
// private float m_seaLevel = 0f;
|
||||
|
||||
// void OnEnable()
|
||||
// {
|
||||
// //Grab the active terrain height map
|
||||
// if (Gaia.TerrainHelper.GetActiveTerrain() != null)
|
||||
// {
|
||||
// //Get sea level
|
||||
// GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo();
|
||||
// m_seaLevel = sceneInfo.m_seaLevel;
|
||||
|
||||
// //Get our manager
|
||||
// m_visualiser = (ResourceVisualiser)target;
|
||||
// m_visualiser.Initialise();
|
||||
// m_visualiser.Visualise();
|
||||
|
||||
// //Update resource sea level
|
||||
// m_visualiser.m_resources.ChangeSeaLevel(m_seaLevel);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public override void OnInspectorGUI()
|
||||
// {
|
||||
// //Get our manager
|
||||
// m_visualiser = (ResourceVisualiser)target;
|
||||
|
||||
// //Set up the box style
|
||||
// if (m_boxStyle == null)
|
||||
// {
|
||||
// m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
// m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
// m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
// m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
// }
|
||||
|
||||
// //Setup the wrap style
|
||||
// if (m_wrapStyle == null)
|
||||
// {
|
||||
// m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
// m_wrapStyle.wordWrap = true;
|
||||
// }
|
||||
|
||||
// //Create a nice text intro
|
||||
// GUILayout.BeginVertical("Resource Visualiser", m_boxStyle);
|
||||
// GUILayout.Space(20);
|
||||
// EditorGUILayout.LabelField("The resource visualiser allows you to visualise and edit your resources spawn criteria. Visualiser is CPU intensive, so make range smaller, and resolution larger if you suffer from lag.", m_wrapStyle);
|
||||
// GUILayout.EndVertical();
|
||||
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
|
||||
// DrawDefaultInspector();
|
||||
|
||||
// if (m_visualiser.m_resources == null)
|
||||
// {
|
||||
// GUILayout.BeginVertical("ERROR!!!", m_boxStyle);
|
||||
// GUILayout.Space(20);
|
||||
// EditorGUILayout.LabelField("You must select a resources file to use the Visualiser!!", m_wrapStyle);
|
||||
// GUILayout.EndVertical();
|
||||
// EditorGUI.EndChangeCheck();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //Create a nice text intro
|
||||
// GUILayout.BeginVertical("Resource Editor", m_boxStyle);
|
||||
// GUILayout.Space(20);
|
||||
// EditorGUILayout.LabelField("Select and edit your resource and its spawn criteria here. Changes will show in real time.", m_wrapStyle);
|
||||
// GUILayout.EndVertical();
|
||||
|
||||
// m_visualiser.m_selectedResourceType = (Gaia.GaiaConstants.SpawnerResourceType)EditorGUILayout.EnumPopup(GetLabel("Resource Type"), m_visualiser.m_selectedResourceType);
|
||||
|
||||
// GUIContent[] assetChoices;
|
||||
// switch (m_visualiser.m_selectedResourceType)
|
||||
// {
|
||||
// case GaiaConstants.SpawnerResourceType.TerrainTexture:
|
||||
// {
|
||||
// assetChoices = new GUIContent[m_visualiser.m_resources.m_texturePrototypes.Length];
|
||||
// for (int assetIdx = 0; assetIdx < m_visualiser.m_resources.m_texturePrototypes.Length; assetIdx++)
|
||||
// {
|
||||
// assetChoices[assetIdx] = new GUIContent(m_visualiser.m_resources.m_texturePrototypes[assetIdx].m_name);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// case GaiaConstants.SpawnerResourceType.TerrainDetail:
|
||||
// {
|
||||
// assetChoices = new GUIContent[m_visualiser.m_resources.m_detailPrototypes.Length];
|
||||
// for (int assetIdx = 0; assetIdx < m_visualiser.m_resources.m_detailPrototypes.Length; assetIdx++)
|
||||
// {
|
||||
// assetChoices[assetIdx] = new GUIContent(m_visualiser.m_resources.m_detailPrototypes[assetIdx].m_name);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// case GaiaConstants.SpawnerResourceType.TerrainTree:
|
||||
// {
|
||||
// assetChoices = new GUIContent[m_visualiser.m_resources.m_treePrototypes.Length];
|
||||
// for (int assetIdx = 0; assetIdx < m_visualiser.m_resources.m_treePrototypes.Length; assetIdx++)
|
||||
// {
|
||||
// assetChoices[assetIdx] = new GUIContent(m_visualiser.m_resources.m_treePrototypes[assetIdx].m_name);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// default:
|
||||
// {
|
||||
// assetChoices = new GUIContent[m_visualiser.m_resources.m_gameObjectPrototypes.Length];
|
||||
// for (int assetIdx = 0; assetIdx < m_visualiser.m_resources.m_gameObjectPrototypes.Length; assetIdx++)
|
||||
// {
|
||||
// assetChoices[assetIdx] = new GUIContent(m_visualiser.m_resources.m_gameObjectPrototypes[assetIdx].m_name);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// if (assetChoices.Length > 0)
|
||||
// {
|
||||
// m_visualiser.m_selectedResourceIdx = EditorGUILayout.Popup(GetLabel("Selected Resource"), m_visualiser.m_selectedResourceIdx, assetChoices);
|
||||
|
||||
// //Then select and display the editor
|
||||
// switch (m_visualiser.m_selectedResourceType)
|
||||
// {
|
||||
// case GaiaConstants.SpawnerResourceType.TerrainTexture:
|
||||
// {
|
||||
// if (m_visualiser.m_selectedResourceIdx >= m_visualiser.m_resources.m_texturePrototypes.Length)
|
||||
// {
|
||||
// m_visualiser.m_selectedResourceIdx = 0;
|
||||
// }
|
||||
// ResourceProtoTextureSO so = ScriptableObject.CreateInstance<ResourceProtoTextureSO>();
|
||||
// so.m_texture = m_visualiser.m_resources.m_texturePrototypes[m_visualiser.m_selectedResourceIdx];
|
||||
// var ed = Editor.CreateEditor(so);
|
||||
// ed.OnInspectorGUI();
|
||||
// break;
|
||||
// }
|
||||
// case GaiaConstants.SpawnerResourceType.TerrainDetail:
|
||||
// {
|
||||
// //Fix up indexes
|
||||
// if (m_visualiser.m_selectedResourceIdx >= m_visualiser.m_resources.m_detailPrototypes.Length)
|
||||
// {
|
||||
// m_visualiser.m_selectedResourceIdx = 0;
|
||||
// }
|
||||
// ResourceProtoDetailSO so = ScriptableObject.CreateInstance<ResourceProtoDetailSO>();
|
||||
// so.m_detail = m_visualiser.m_resources.m_detailPrototypes[m_visualiser.m_selectedResourceIdx];
|
||||
// var ed = Editor.CreateEditor(so);
|
||||
// ed.OnInspectorGUI();
|
||||
// break;
|
||||
// }
|
||||
// case GaiaConstants.SpawnerResourceType.TerrainTree:
|
||||
// {
|
||||
// //Fix up indexes
|
||||
// if (m_visualiser.m_selectedResourceIdx >= m_visualiser.m_resources.m_treePrototypes.Length)
|
||||
// {
|
||||
// m_visualiser.m_selectedResourceIdx = 0;
|
||||
// }
|
||||
// ResourceProtoTreeSO so = ScriptableObject.CreateInstance<ResourceProtoTreeSO>();
|
||||
// so.m_tree = m_visualiser.m_resources.m_treePrototypes[m_visualiser.m_selectedResourceIdx];
|
||||
// var ed = Editor.CreateEditor(so);
|
||||
// ed.OnInspectorGUI();
|
||||
// break;
|
||||
// }
|
||||
// default:
|
||||
// {
|
||||
// //Fix up indexes
|
||||
// if (m_visualiser.m_selectedResourceIdx >= m_visualiser.m_resources.m_gameObjectPrototypes.Length)
|
||||
// {
|
||||
// m_visualiser.m_selectedResourceIdx = 0;
|
||||
// }
|
||||
// ResourceProtoGameObjectSO so = ScriptableObject.CreateInstance<ResourceProtoGameObjectSO>();
|
||||
// so.m_gameObject = m_visualiser.m_resources.m_gameObjectPrototypes[m_visualiser.m_selectedResourceIdx];
|
||||
// var ed = Editor.CreateEditor(so);
|
||||
// ed.OnInspectorGUI();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //Check for changes, make undo record, make changes and let editor know we are dirty
|
||||
// if (EditorGUI.EndChangeCheck())
|
||||
// {
|
||||
// Undo.RecordObject(m_visualiser.m_resources, "Made resource changes");
|
||||
// EditorUtility.SetDirty(m_visualiser.m_resources);
|
||||
// }
|
||||
|
||||
// //Update some key fields in the spawner
|
||||
// m_visualiser.m_spawner.m_settings.m_resources = m_visualiser.m_resources;
|
||||
// m_visualiser.m_spawner.m_spawnCollisionLayers = m_visualiser.m_fitnessCollisionLayers;
|
||||
// m_visualiser.m_spawner.m_settings.m_spawnRange = m_visualiser.m_range;
|
||||
|
||||
// //Terrain info
|
||||
// //Create a nice text intro
|
||||
// GUILayout.BeginVertical("Terrain Info", m_boxStyle);
|
||||
// GUILayout.Space(20);
|
||||
// EditorGUILayout.LabelField("Hit control key to view detailed information at current mouse position - mouse must be over the visualiser to register data.", m_wrapStyle);
|
||||
// GUILayout.EndVertical();
|
||||
|
||||
// EditorGUILayout.Vector3Field(GetLabel("Location"), m_visualiser.m_lastHitPoint);
|
||||
|
||||
// EditorGUILayout.Toggle(GetLabel("Virgin"), m_visualiser.m_lastHitWasVirgin);
|
||||
// if (!string.IsNullOrEmpty(m_visualiser.m_lastHitObjectname))
|
||||
// {
|
||||
// EditorGUILayout.TextField(GetLabel("Hit Object"), m_visualiser.m_lastHitObjectname);
|
||||
// }
|
||||
// EditorGUILayout.FloatField(GetLabel("Hit Height"), m_visualiser.m_lastHitHeight);
|
||||
// EditorGUILayout.FloatField(GetLabel("Terrain Height"), m_visualiser.m_lastHitTerrainHeight);
|
||||
// EditorGUILayout.FloatField(GetLabel("Height Above Sea"), m_visualiser.m_lastHitTerrainRelativeHeight);
|
||||
// EditorGUILayout.FloatField(GetLabel("Terrain Slope"), m_visualiser.m_lastHitTerrainSlope);
|
||||
// EditorGUILayout.FloatField(GetLabel("Area Slope"), m_visualiser.m_lastHitAreaSlope);
|
||||
// EditorGUILayout.FloatField(GetLabel("Fitness"), m_visualiser.m_lastHitFitness);
|
||||
// }
|
||||
|
||||
// void OnSceneGUI()
|
||||
// {
|
||||
// if (Event.current.control == true)
|
||||
// {
|
||||
// //Work out where the mouse is and get fitness
|
||||
// Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
|
||||
// RaycastHit hitInfo;
|
||||
// if (Physics.Raycast(ray, out hitInfo, 10000f))
|
||||
// {
|
||||
// if (hitInfo.point != m_visualiser.m_lastHitPoint)
|
||||
// {
|
||||
// m_visualiser.m_lastHitPoint = hitInfo.point;
|
||||
// SpawnInfo spawnInfo = m_visualiser.GetSpawnInfo(hitInfo.point);
|
||||
|
||||
// if (!spawnInfo.m_outOfBounds)
|
||||
// {
|
||||
// m_visualiser.m_lastHitObjectname = spawnInfo.m_hitObject.name;
|
||||
// m_visualiser.m_lastHitFitness = spawnInfo.m_fitness;
|
||||
// m_visualiser.m_lastHitHeight = spawnInfo.m_hitLocationWU.y;
|
||||
// m_visualiser.m_lastHitTerrainHeight = spawnInfo.m_terrainHeightWU;
|
||||
// m_visualiser.m_lastHitTerrainRelativeHeight = m_visualiser.m_lastHitTerrainHeight - GaiaSessionManager.GetSessionManager(false).GetSeaLevel();
|
||||
// m_visualiser.m_lastHitTerrainSlope = spawnInfo.m_terrainSlopeWU;
|
||||
// m_visualiser.m_lastHitAreaSlope = spawnInfo.m_areaAvgSlopeWU;
|
||||
// m_visualiser.m_lastHitWasVirgin = spawnInfo.m_wasVirginTerrain;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_visualiser.m_lastHitPoint = spawnInfo.m_hitLocationWU;
|
||||
// m_visualiser.m_lastHitObjectname = "Out of BOUNDS";
|
||||
// m_visualiser.m_lastHitFitness = 0f;
|
||||
// m_visualiser.m_lastHitHeight = 0f;
|
||||
// m_visualiser.m_lastHitTerrainHeight = 0f;
|
||||
// m_visualiser.m_lastHitTerrainRelativeHeight = 0f;
|
||||
// m_visualiser.m_lastHitTerrainSlope = 0f;
|
||||
// m_visualiser.m_lastHitAreaSlope = 0f;
|
||||
// m_visualiser.m_lastHitWasVirgin = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_visualiser.m_lastHitPoint = ray.origin;
|
||||
// m_visualiser.m_lastHitObjectname = "Out of BOUNDS";
|
||||
// m_visualiser.m_lastHitFitness = 0f;
|
||||
// m_visualiser.m_lastHitHeight = 0f;
|
||||
// m_visualiser.m_lastHitTerrainHeight = 0f;
|
||||
// m_visualiser.m_lastHitTerrainRelativeHeight = 0f;
|
||||
// m_visualiser.m_lastHitTerrainSlope = 0f;
|
||||
// m_visualiser.m_lastHitAreaSlope = 0f;
|
||||
// m_visualiser.m_lastHitWasVirgin = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Get a content label - look the tooltip up if possible
|
||||
// /// </summary>
|
||||
// /// <param name="name"></param>
|
||||
// /// <returns></returns>
|
||||
// GUIContent GetLabel(string name)
|
||||
// {
|
||||
// string tooltip = "";
|
||||
// if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
// {
|
||||
// return new GUIContent(name, tooltip);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return new GUIContent(name);
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// The tooltips
|
||||
// /// </summary>
|
||||
// static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
// {
|
||||
// { "Location", "Location in world units where the raycast hit occurred." },
|
||||
// { "Virgin", "True when only terrain is detected at this location. False if any other object with a collider is hit." },
|
||||
// { "Hit Object", "The name of the object that was detected at this location." },
|
||||
// { "Hit Height", "The height at which the hit was detected in world units." },
|
||||
// { "Terrain Height", "The terrain height at this locaiton world units." },
|
||||
// { "Height Above Sea", "The terrain height relative to sea level at which the hit was detected in world units." },
|
||||
// { "Terrain Slope", "The terrain slope at this location - 0 == flat, 90 == vertical." },
|
||||
// { "Area Slope", "The average terrain slope across the bounded area at this location based on bounds radius in the objects dna when bounded area check selected - 0 == flat, 90 == vertical." },
|
||||
// { "Fitness", "Fitness at this location." },
|
||||
// };
|
||||
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18ccf5ebb3f411047a911477685034ee
|
||||
timeCreated: 1439535401
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,424 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(Scanner))]
|
||||
public class ScannerEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
[SerializeField] private GaiaConstants.RawByteOrder m_rawByteOrder;
|
||||
[SerializeField] private GaiaConstants.RawBitDepth m_rawBitDepth = GaiaConstants.RawBitDepth.Sixteen;
|
||||
private Scanner m_scanner;
|
||||
private GUIStyle m_boxStyle;
|
||||
private GUIStyle m_dropBoxStyle;
|
||||
private GUIStyle m_wrapStyle;
|
||||
private Color m_redGUI = new Color(0.500f, 0.0f, 0.0f, 1f);
|
||||
private Color m_greenGUI = new Color(0.696f, 0.905f, 0.397f, 1f);
|
||||
private string m_rawFilePath;
|
||||
private int m_assumedRawRes = 0;
|
||||
private string m_infoMessage = "";
|
||||
private string m_scanMessage = "No object scanned yet - Drag and drop a raw file, texture or terrain on the box above to begin!";
|
||||
|
||||
|
||||
// The below are used so GUI update doesn't happen at wrong times causing layout mismatches
|
||||
private bool m_showRawInfo = false;
|
||||
private bool m_showBitDepthWarning = false;
|
||||
private GaiaSettings m_settings;
|
||||
private readonly GUIContent BYTE_ORDER_LABEL = new GUIContent("Raw File Byte Order", "The byte order used when creating from RAW files. Try changing this if your stamp comes out flat.");
|
||||
private readonly GUIContent BIT_DEPTH_LABEL = new GUIContent("Raw File Bit Depth", "The bit depth used when creating from RAW files. Try changing this if the processing resolution is double, or half of what you expected.\n\n" + "NOTE: 8-bit RAW files have very poor precision and result in terraced stamps.");
|
||||
private readonly GUIContent[] BIT_DEPTHS_LABELS = new GUIContent[]
|
||||
{
|
||||
new GUIContent("16-bit (Recommended)", "16-bit RAW files can contain higher precision data."),
|
||||
new GUIContent("8-bit", "8-bit RAW files have low precision and result in terraced stamps/terrains."),
|
||||
};
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_scanner = (Scanner)target;
|
||||
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
UpdateMaterial();
|
||||
m_infoMessage = "";
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
m_scanner = (Scanner)target;
|
||||
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(EditorStyles.helpBox)
|
||||
{
|
||||
normal = { textColor = GUI.skin.label.normal.textColor },
|
||||
fontStyle = FontStyle.Bold,
|
||||
fontSize = GUI.skin.label.fontSize,
|
||||
alignment = TextAnchor.UpperLeft
|
||||
};
|
||||
}
|
||||
|
||||
if (m_dropBoxStyle == null)
|
||||
{
|
||||
m_dropBoxStyle = new GUIStyle(GUI.skin.box)
|
||||
{
|
||||
fontStyle = FontStyle.Bold,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
fontStyle = FontStyle.Normal, wordWrap = true
|
||||
};
|
||||
}
|
||||
|
||||
m_editorUtils.Panel("GlobalSettings", GlobalPanel, true);
|
||||
}
|
||||
|
||||
private void GlobalPanel(bool helpEnabled)
|
||||
{
|
||||
//Text intro
|
||||
GUILayout.BeginVertical("Gaia Scanner", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("The Gaia Scanner allows you to create new stamps from Windows R16, Windows 16 bit RAW, Mac 16 bit RAW, Terrains, Textures or Meshes. Just drag and drop the file or object onto the area below to scan it.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
DropAreaGUI();
|
||||
|
||||
bool originalGUIState = GUI.enabled;
|
||||
|
||||
if (!m_scanner.m_objectScanned)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
|
||||
//DrawDefaultInspector();
|
||||
GUILayout.BeginVertical("Setup", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
m_editorUtils.Heading("GlobalSettings");
|
||||
m_scanner.m_previewMaterial = (Material)m_editorUtils.ObjectField("PreviewMaterial", m_scanner.m_previewMaterial, typeof(Material), false, helpEnabled);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_scanner.m_exportFolder = m_editorUtils.TextField("ExportPath", m_scanner.m_exportFolder);
|
||||
|
||||
if (m_editorUtils.Button("ExportDirectoryOpen", GUILayout.Width(80)))
|
||||
{
|
||||
string path = EditorUtility.SaveFolderPanel(m_editorUtils.GetTextValue("ExportDirectoryWindowTitle"), GaiaDirectories.GetUserStampDirectory(), GaiaDirectories.SCANNER_EXPORT_DIRECTORY.Replace("/",""));
|
||||
if (path.Contains(Application.dataPath))
|
||||
{
|
||||
m_scanner.m_exportFolder = GaiaDirectories.GetPathStartingAtAssetsFolder(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("Path outside the Assets folder", "The selected path needs to be inside the Assets folder of the project. Please select an appropiate path.", "OK");
|
||||
m_scanner.m_exportFolder = GaiaDirectories.GetScannerExportDirectory();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
m_editorUtils.InlineHelp("ExportPath", helpEnabled);
|
||||
m_scanner.m_exportFileName = m_editorUtils.TextField("ExportFilename", m_scanner.m_exportFileName, helpEnabled);
|
||||
|
||||
float oldBaseLevel = m_scanner.m_baseLevel;
|
||||
m_scanner.m_baseLevel = m_editorUtils.Slider("BaseLevel", m_scanner.m_baseLevel, 0f, 1f, helpEnabled);
|
||||
if (oldBaseLevel != m_scanner.m_baseLevel)
|
||||
{
|
||||
SceneView.lastActiveSceneView.Repaint();
|
||||
}
|
||||
EditorGUILayout.Space(10f);
|
||||
m_editorUtils.Heading("ObjectTypeSettings");
|
||||
if (m_scanner.m_scannerObjectType == ScannerObjectType.Mesh)
|
||||
{
|
||||
m_scanner.m_scanResolution = m_editorUtils.Slider("ScanResolution", m_scanner.m_scanResolution, 0.0001f, 1f, helpEnabled);
|
||||
if (m_scanner.m_lastScanResolution != m_scanner.m_scanResolution)
|
||||
{
|
||||
if(m_editorUtils.Button("RefreshScan"))
|
||||
{
|
||||
m_scanner.LoadGameObject(m_scanner.m_lastScannedMesh);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (m_scanner.m_scannerObjectType == ScannerObjectType.Raw)
|
||||
{
|
||||
//Drop Options section
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
EditorGUILayout.PrefixLabel(BYTE_ORDER_LABEL);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
{
|
||||
m_rawByteOrder = (GaiaConstants.RawByteOrder)GUILayout.Toolbar((int)m_rawByteOrder, new string[] { "IBM PC", "Macintosh" });
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
ReloadRawFile();
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
m_editorUtils.InlineHelp("RawFileByteOrder", helpEnabled);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
{
|
||||
m_rawBitDepth = (GaiaConstants.RawBitDepth)EditorGUILayout.Popup(BIT_DEPTH_LABEL, (int)m_rawBitDepth, BIT_DEPTHS_LABELS);
|
||||
m_editorUtils.InlineHelp("RawFileBitDepth", helpEnabled);
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
ReloadRawFile();
|
||||
}
|
||||
GUILayout.BeginVertical();
|
||||
if (m_showRawInfo)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Assumed " + (m_rawBitDepth == GaiaConstants.RawBitDepth.Sixteen ? "16-bit" : "8-bit") + " RAW " + m_assumedRawRes + " x " + m_assumedRawRes, MessageType.Info);
|
||||
}
|
||||
if (m_showBitDepthWarning)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("8BitWarning"), MessageType.Warning);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.Space(10f);
|
||||
|
||||
|
||||
|
||||
m_editorUtils.Heading("ExportSettings");
|
||||
//m_scanner.m_textureExportResolution = (GaiaConstants.GaiaProWaterReflectionsQuality) EditorGUILayout.EnumPopup(new GUIContent("Export Resolution", "Sets the export resolution of the texture generated"), m_scanner.m_textureExportResolution);
|
||||
m_scanner.m_normalize = m_editorUtils.Toggle("Normalize", m_scanner.m_normalize, helpEnabled);
|
||||
m_scanner.m_exportTextureAlso = m_editorUtils.Toggle("ExportPNG", m_scanner.m_exportTextureAlso, helpEnabled);
|
||||
//m_scanner.m_exportBytesData = m_editorUtils.Toggle("ExportBytesData", m_scanner.m_exportBytesData, helpEnabled);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//Terraform section
|
||||
GUILayout.BeginVertical("Scanner Controller", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
if (!string.IsNullOrEmpty(m_infoMessage))
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_infoMessage, MessageType.Info);
|
||||
}
|
||||
if (m_scanner.m_scanMap == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("NoScanDataInfo"), MessageType.Info);
|
||||
GUI.enabled = false;
|
||||
}
|
||||
GUILayout.BeginHorizontal();
|
||||
Color normalBGColor = GUI.backgroundColor;
|
||||
if (m_settings == null)
|
||||
{
|
||||
m_settings = GaiaUtils.GetGaiaSettings();
|
||||
}
|
||||
|
||||
GUI.backgroundColor = m_settings.GetActionButtonColor();
|
||||
if (m_editorUtils.Button("SaveScan"))
|
||||
{
|
||||
string path = m_scanner.SaveScan();
|
||||
AssetDatabase.Refresh();
|
||||
path += ".exr";
|
||||
Object exportedTexture = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
|
||||
if (exportedTexture != null)
|
||||
{
|
||||
m_infoMessage = "Scan exported to: " + path;
|
||||
Debug.Log(m_infoMessage);
|
||||
EditorGUIUtility.PingObject(exportedTexture);
|
||||
}
|
||||
|
||||
}
|
||||
GUI.backgroundColor = normalBGColor;
|
||||
GUI.enabled = true;
|
||||
if (m_editorUtils.Button("Clear"))
|
||||
{
|
||||
m_scanner.Clear();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(5);
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(5f);
|
||||
|
||||
m_showRawInfo = m_assumedRawRes > 0;
|
||||
m_showBitDepthWarning = m_rawBitDepth == GaiaConstants.RawBitDepth.Eight;
|
||||
|
||||
GUI.enabled = originalGUIState;
|
||||
}
|
||||
|
||||
private void DropAreaGUI()
|
||||
{
|
||||
//Ok - set up for drag and drop
|
||||
Event evt = Event.current;
|
||||
Rect drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));
|
||||
GUI.Box(drop_area, ">> Drop Objects Here To Scan <<", m_dropBoxStyle);
|
||||
EditorGUILayout.HelpBox(m_scanMessage, MessageType.Info);
|
||||
|
||||
switch (evt.type)
|
||||
{
|
||||
case EventType.DragUpdated:
|
||||
case EventType.DragPerform:
|
||||
{
|
||||
if (!drop_area.Contains(evt.mousePosition))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||
|
||||
if (evt.type == EventType.DragPerform)
|
||||
{
|
||||
DragAndDrop.AcceptDrag();
|
||||
m_rawFilePath = null;
|
||||
m_assumedRawRes = 0;
|
||||
|
||||
//Is it a saved file - only raw files are processed this way
|
||||
if (DragAndDrop.paths.Length > 0)
|
||||
{
|
||||
string filePath = DragAndDrop.paths[0];
|
||||
|
||||
//Update in case unity has messed with it
|
||||
if (filePath.StartsWith("Assets"))
|
||||
{
|
||||
filePath = Path.Combine(Application.dataPath, filePath.Substring(7)).Replace('\\', '/');
|
||||
}
|
||||
|
||||
//Check file type and process as we can
|
||||
string fileType = Path.GetExtension(filePath).ToLower();
|
||||
|
||||
//Handle raw files
|
||||
if (fileType == ".r16" || fileType == ".raw")
|
||||
{
|
||||
m_scanMessage = "Dropped Object recognized as a raw file";
|
||||
m_scanner.m_scannerObjectType = ScannerObjectType.Raw;
|
||||
m_scanner.m_objectScanned = true;
|
||||
m_rawFilePath = filePath;
|
||||
m_scanner.LoadRawFile(filePath, m_rawByteOrder, ref m_rawBitDepth, ref m_assumedRawRes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Is it something that unity knows about - may or may not have been saved
|
||||
bool finished = false;
|
||||
if (DragAndDrop.objectReferences.Length > 0)
|
||||
{
|
||||
switch (DragAndDrop.objectReferences[0])
|
||||
{
|
||||
//Check for textures
|
||||
case Texture2D _:
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Processing Texture", "Processing texture to mask texture", 0.5f);
|
||||
GaiaUtils.MakeTextureReadable(DragAndDrop.objectReferences[0] as Texture2D);
|
||||
GaiaUtils.MakeTextureUncompressed(DragAndDrop.objectReferences[0] as Texture2D);
|
||||
m_scanner.LoadTextureFile(DragAndDrop.objectReferences[0] as Texture2D);
|
||||
m_scanMessage = "Dropped Object recognized as a texture";
|
||||
m_scanner.m_scannerObjectType = ScannerObjectType.Texture;
|
||||
finished = true;
|
||||
EditorUtility.ClearProgressBar();
|
||||
break;
|
||||
}
|
||||
//Check for terrains
|
||||
case GameObject _:
|
||||
{
|
||||
GameObject go = DragAndDrop.objectReferences[0] as GameObject;
|
||||
Terrain t = go.GetComponentInChildren<Terrain>();
|
||||
//Handle a terrain
|
||||
if (t != null)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Processing Terrain", "Processing terrain to mask texture", 0.5f);
|
||||
m_scanner.LoadTerain(t);
|
||||
m_scanMessage = "Dropped Object recognized as terrain";
|
||||
m_scanner.m_scannerObjectType = ScannerObjectType.Terrain;
|
||||
finished = true;
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
//Check for a mesh - this means we can scan it
|
||||
if (!finished)
|
||||
{
|
||||
MeshFilter[] filters = go.GetComponentsInChildren<MeshFilter>();
|
||||
for (int idx = 0; idx < filters.Length; idx++)
|
||||
{
|
||||
if (filters[idx].sharedMesh != null)
|
||||
{
|
||||
m_scanMessage = "Dropped Object recognized as mesh";
|
||||
m_scanner.m_scannerObjectType = ScannerObjectType.Mesh;
|
||||
m_scanner.m_lastScannedMesh = go;
|
||||
m_scanner.LoadGameObject(go);
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If we got to here then we couldnt process it
|
||||
if (!finished)
|
||||
{
|
||||
Debug.LogWarning("Object type not supported by scanner. Ignored");
|
||||
m_scanMessage = "Object type not supported by scanner.";
|
||||
m_scanner.m_scannerObjectType = ScannerObjectType.Unkown;
|
||||
m_scanner.m_objectScanned = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_scanner.m_objectScanned = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadRawFile()
|
||||
{
|
||||
if (string.IsNullOrEmpty(m_rawFilePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_assumedRawRes = 0;
|
||||
m_scanner.LoadRawFile(m_rawFilePath, m_rawByteOrder, ref m_rawBitDepth, ref m_assumedRawRes);
|
||||
}
|
||||
|
||||
private void UpdateMaterial()
|
||||
{
|
||||
if (m_scanner != null)
|
||||
{
|
||||
if (m_scanner.m_previewMaterial != null)
|
||||
{
|
||||
GaiaConstants.EnvironmentRenderer renderPipeline = GaiaUtils.GetActivePipeline();
|
||||
Texture2D texture = m_scanner.m_previewMaterial.GetTexture("_MainTex") as Texture2D;
|
||||
if (texture == null)
|
||||
{
|
||||
texture = m_scanner.m_previewMaterial.GetTexture("_BaseMap") as Texture2D;
|
||||
}
|
||||
|
||||
switch (renderPipeline)
|
||||
{
|
||||
case GaiaConstants.EnvironmentRenderer.BuiltIn:
|
||||
m_scanner.m_previewMaterial.shader = Shader.Find("Standard");
|
||||
m_scanner.m_previewMaterial.SetTexture("_MainTex", texture);
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.Universal:
|
||||
m_scanner.m_previewMaterial.shader = Shader.Find("Universal Render Pipeline/Lit");
|
||||
m_scanner.m_previewMaterial.SetTexture("_BaseMap", texture);
|
||||
break;
|
||||
case GaiaConstants.EnvironmentRenderer.HighDefinition:
|
||||
m_scanner.m_previewMaterial.shader = Shader.Find("HDRP/Lit");
|
||||
m_scanner.m_previewMaterial.SetTexture("_BaseMap", texture);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a973deb4ccbc9bf4f938d874e115f409
|
||||
timeCreated: 1442645673
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(ScreenShotter))]
|
||||
public class ScreenShotterEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
private ScreenShotter m_profile;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//Get Gaia Lighting Profile object
|
||||
m_profile = (ScreenShotter)target;
|
||||
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup on destroy
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (m_editorUtils != null)
|
||||
{
|
||||
m_editorUtils.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Initialization
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
m_editorUtils.Panel("GlobalSettings", GlobalSettings, false, true, true);
|
||||
}
|
||||
|
||||
private void GlobalSettings(bool helpEnabled)
|
||||
{
|
||||
m_editorUtils.Heading("ScreenshotSetup");
|
||||
EditorGUI.indentLevel++;
|
||||
m_profile.m_mainCamera = (Camera)m_editorUtils.ObjectField("MainCamera", m_profile.m_mainCamera, typeof(Camera), true, helpEnabled);
|
||||
m_profile.m_watermark = (Texture2D)m_editorUtils.ObjectField("Watermark", m_profile.m_watermark, typeof(Texture2D), true, helpEnabled, GUILayout.MaxHeight(16f));
|
||||
m_profile.m_targetDirectory = m_editorUtils.TextField("TargetDirectory", m_profile.m_targetDirectory, helpEnabled);
|
||||
m_profile.m_screenShotKey = (KeyCode)m_editorUtils.EnumPopup("ScreenshotKey", m_profile.m_screenShotKey, helpEnabled);
|
||||
m_profile.m_imageFormat = (GaiaConstants.ImageFileType)m_editorUtils.EnumPopup("ImageFormat", m_profile.m_imageFormat, helpEnabled);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
m_editorUtils.Heading("ScreenshotResolutionSetup");
|
||||
EditorGUI.indentLevel++;
|
||||
m_profile.m_useScreenSize = m_editorUtils.Toggle("UseScreenSize", m_profile.m_useScreenSize, helpEnabled);
|
||||
if (!m_profile.m_useScreenSize)
|
||||
{
|
||||
GaiaConstants.ScreenshotResolution screenshotResolution = m_profile.m_screenshotResolution;
|
||||
screenshotResolution = (GaiaConstants.ScreenshotResolution)m_editorUtils.EnumPopup("ScreenshotResolution", screenshotResolution, helpEnabled);
|
||||
if (screenshotResolution != m_profile.m_screenshotResolution)
|
||||
{
|
||||
m_profile.m_screenshotResolution = screenshotResolution;
|
||||
m_profile.UpdateScreenshotResolution(m_profile.m_screenshotResolution);
|
||||
}
|
||||
|
||||
if (screenshotResolution == GaiaConstants.ScreenshotResolution.Custom)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
m_profile.m_targetWidth = m_editorUtils.IntField("TargetWidth", m_profile.m_targetWidth, helpEnabled);
|
||||
m_profile.m_targetHeight = m_editorUtils.IntField("TargetHeight", m_profile.m_targetHeight, helpEnabled);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2a518d030014134ca32f92888876751
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,174 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Editor for shoreline masker
|
||||
/// </summary>
|
||||
public class ShorelineMaskerEditor : EditorWindow
|
||||
{
|
||||
|
||||
GUIStyle m_boxStyle;
|
||||
GUIStyle m_wrapStyle;
|
||||
public float m_seaLevel = 50f;
|
||||
public int m_maskSize = 20;
|
||||
public float m_aboveWaterStrength = 1f;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Create a nice text intro
|
||||
GUILayout.BeginVertical("Shoreline Masker", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("Use this tool to make a mask of the active terrain at the height provided. The mask will be created in the assets directory.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
m_seaLevel = EditorGUILayout.FloatField("Sea Level", m_seaLevel);
|
||||
m_maskSize = EditorGUILayout.IntField("Mask Size", m_maskSize);
|
||||
m_aboveWaterStrength = EditorGUILayout.Slider("Above Water Value", m_aboveWaterStrength, 0f, 1f);
|
||||
|
||||
if (GUILayout.Button("Create ShoreLine Mask"))
|
||||
{
|
||||
CreateMask();
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.FocusProjectWindow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create the mask and put it in the root assets directory
|
||||
/// </summary>
|
||||
public void CreateMask()
|
||||
{
|
||||
// Check to see if we have an active terrain
|
||||
if (Terrain.activeTerrain == null)
|
||||
{
|
||||
Debug.LogError("You need an active terrain!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the terrain
|
||||
UnityHeightMap hm = new UnityHeightMap(Terrain.activeTerrain);
|
||||
|
||||
// Create a heightmap for the mask
|
||||
HeightMap maskHm = new HeightMap(hm.Width(), hm.Depth());
|
||||
|
||||
//Iterate though our terrain, at the resolution of the heightmap and pick up the height
|
||||
float testHeight;
|
||||
float nrmSeaLevel = m_seaLevel / Terrain.activeTerrain.terrainData.size.y;
|
||||
|
||||
for (int x = 0; x < hm.Width(); x++)
|
||||
{
|
||||
for (int z = 0; z < hm.Depth(); z++)
|
||||
{
|
||||
testHeight = hm[x, z];
|
||||
if (testHeight < nrmSeaLevel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (Gaia.GaiaUtils.Math_ApproximatelyEqual(testHeight, nrmSeaLevel))
|
||||
{
|
||||
//We have a shoreline, lets mask it
|
||||
maskHm[x, z] = m_aboveWaterStrength;
|
||||
MakeMask(x, z, nrmSeaLevel, m_maskSize, hm, maskHm);
|
||||
}
|
||||
else
|
||||
{
|
||||
maskHm[x, z] = m_aboveWaterStrength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maskHm.Flip();
|
||||
//maskHm.Smooth(1);
|
||||
string path = GaiaDirectories.GetExportDirectory();
|
||||
path = Path.Combine(path, PWCommon4.Utils.FixFileName(string.Format("TerrainShoreLineMask-{0:yyyyMMdd-HHmmss}", DateTime.Now)));
|
||||
Gaia.GaiaUtils.CompressToSingleChannelFileImage(maskHm.Heights(), path, TextureFormat.RGBA32, false, true);
|
||||
|
||||
EditorUtility.DisplayDialog("Shoreline Masker", "Your shorline mask has been created at " + path, "OK");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Make a mask by iterating out from this location
|
||||
/// </summary>
|
||||
/// <param name="startX"></param>
|
||||
/// <param name="startZ"></param>
|
||||
/// <param name="waterHeight"></param>
|
||||
/// <param name="maskSize"></param>
|
||||
/// <param name="hm"></param>
|
||||
/// <param name="maskHm"></param>
|
||||
private void MakeMask(int startX, int startZ, float waterHeight, int maskSize, HeightMap hm, HeightMap maskHm)
|
||||
{
|
||||
int width = hm.Width();
|
||||
int depth = hm.Depth();
|
||||
int minX = startX - maskSize;
|
||||
int maxX = startX + maskSize;
|
||||
int minZ = startZ - maskSize;
|
||||
int maxZ = startZ + maskSize;
|
||||
float strength;
|
||||
|
||||
if (minX < 0)
|
||||
{
|
||||
minX = 0;
|
||||
}
|
||||
if (maxX >= width)
|
||||
{
|
||||
maxX = width;
|
||||
}
|
||||
if (minZ < 0)
|
||||
{
|
||||
minZ = 0;
|
||||
}
|
||||
if (maxZ >= depth)
|
||||
{
|
||||
maxZ = depth;
|
||||
}
|
||||
|
||||
//Make the mask if height is below sea level
|
||||
for (int x = minX; x < maxX; x++)
|
||||
{
|
||||
for (int z = minZ; z < maxZ; z++)
|
||||
{
|
||||
if (hm[x, z] <= waterHeight)
|
||||
{
|
||||
strength = Gaia.GaiaUtils.Math_Distance(startX, startZ, x, z) / (float)maskSize;
|
||||
if (strength <= 1f)
|
||||
{
|
||||
strength = 1f - strength;
|
||||
if (strength > maskHm[x, z])
|
||||
{
|
||||
maskHm[x, z] = strength;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5bc5bbdd634ede4b8d4b45c785793d8
|
||||
timeCreated: 1443389539
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(SimpleCameraLayerCulling))]
|
||||
public class SimpleCameraLayerCullingEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
private SimpleCameraLayerCulling m_simpleCameraLayerCulling;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
m_simpleCameraLayerCulling = (SimpleCameraLayerCulling)target;
|
||||
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
m_simpleCameraLayerCulling.Initialize();
|
||||
ApplyToSceneCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyToSceneCamera()
|
||||
{
|
||||
if (m_simpleCameraLayerCulling.m_applyToSceneCamera)
|
||||
{
|
||||
foreach (var sceneCamera in SceneView.GetAllSceneCameras())
|
||||
{
|
||||
sceneCamera.layerCullDistances = m_simpleCameraLayerCulling.m_profile.m_layerDistances;
|
||||
}
|
||||
m_simpleCameraLayerCulling.ApplyToDirectionalLight();
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] layerCulls = new float[32];
|
||||
for (int i = 0; i < layerCulls.Length; i++)
|
||||
{
|
||||
layerCulls[i] = 0f;
|
||||
}
|
||||
foreach (var sceneCamera in SceneView.GetAllSceneCameras())
|
||||
{
|
||||
sceneCamera.layerCullDistances = layerCulls;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Initialization
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
m_editorUtils.Panel("SimpleLayerCulling", SimpleLayerCulling, true);
|
||||
|
||||
}
|
||||
|
||||
private void SimpleLayerCulling(bool helpEnabled)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_simpleCameraLayerCulling.m_applyToGameCamera = m_editorUtils.Toggle("ApplyToGameCamera", m_simpleCameraLayerCulling.m_applyToGameCamera);
|
||||
m_simpleCameraLayerCulling.m_applyToSceneCamera = m_editorUtils.Toggle("ApplyToSceneCamera", m_simpleCameraLayerCulling.m_applyToSceneCamera);
|
||||
|
||||
if (m_simpleCameraLayerCulling.m_profile != null)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
m_editorUtils.LabelField("ObjectCullingSettings", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
m_editorUtils.InlineHelp("ObjectCullingSettings", helpEnabled);
|
||||
for (int i = 0; i < m_simpleCameraLayerCulling.m_profile.m_layerDistances.Length; i++)
|
||||
{
|
||||
string layerName = LayerMask.LayerToName(i);
|
||||
if (!string.IsNullOrEmpty(layerName))
|
||||
{
|
||||
m_simpleCameraLayerCulling.m_profile.m_layerDistances[i] = EditorGUILayout.FloatField(string.Format("[{0}] {1}", i, layerName), m_simpleCameraLayerCulling.m_profile.m_layerDistances[i]);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
if (m_editorUtils.Button("RevertCullingToDefaults"))
|
||||
{
|
||||
GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings();
|
||||
m_simpleCameraLayerCulling.m_profile.UpdateCulling(gaiaSettings);
|
||||
EditorUtility.SetDirty(m_simpleCameraLayerCulling.m_profile);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
m_editorUtils.LabelField("ShadowCullingSettings", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
m_editorUtils.InlineHelp("ShadowCullingSettings", helpEnabled);
|
||||
for (int i = 0; i < m_simpleCameraLayerCulling.m_profile.m_shadowLayerDistances.Length; i++)
|
||||
{
|
||||
string layerName = LayerMask.LayerToName(i);
|
||||
if (!string.IsNullOrEmpty(layerName))
|
||||
{
|
||||
m_simpleCameraLayerCulling.m_profile.m_shadowLayerDistances[i] = EditorGUILayout.FloatField(string.Format("[{0}] {1}", i, layerName), m_simpleCameraLayerCulling.m_profile.m_shadowLayerDistances[i]);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
if (m_editorUtils.Button("RevertShadowToDefaults"))
|
||||
{
|
||||
m_simpleCameraLayerCulling.m_profile.UpdateShadow();
|
||||
EditorUtility.SetDirty(m_simpleCameraLayerCulling.m_profile);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorUtility.SetDirty(m_simpleCameraLayerCulling);
|
||||
ApplyToSceneCamera();
|
||||
m_simpleCameraLayerCulling.ApplyToGameCamera();
|
||||
m_simpleCameraLayerCulling.ResetDirectionalLight();
|
||||
SceneView.RepaintAll();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38cff2b1a94f1e54c9e4fe687d880e3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e15911bb06bc20b459620dcba5ea09ce
|
||||
timeCreated: 1433041891
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,255 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(SpawnerGroup))]
|
||||
public class SpawnerGroupEditor : Editor
|
||||
{
|
||||
GUIStyle m_boxStyle;
|
||||
GUIStyle m_wrapStyle;
|
||||
SpawnerGroup m_spawnerGroup;
|
||||
DateTime m_timeSinceLastUpdate = DateTime.Now;
|
||||
bool m_startedUpdates = false;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
m_spawnerGroup = (SpawnerGroup)target;
|
||||
StartEditorUpdates();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start editor updates
|
||||
/// </summary>
|
||||
public void StartEditorUpdates()
|
||||
{
|
||||
if (!m_startedUpdates)
|
||||
{
|
||||
m_startedUpdates = true;
|
||||
EditorApplication.update += EditorUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop editor updates
|
||||
/// </summary>
|
||||
public void StopEditorUpdates()
|
||||
{
|
||||
if (m_startedUpdates)
|
||||
{
|
||||
m_startedUpdates = false;
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used just to force the editor to repaint itself
|
||||
/// </summary>
|
||||
void EditorUpdate()
|
||||
{
|
||||
if (m_spawnerGroup != null)
|
||||
{
|
||||
if (m_spawnerGroup.m_updateCoroutine != null)
|
||||
{
|
||||
if ((DateTime.Now - m_timeSinceLastUpdate).TotalMilliseconds > 500)
|
||||
{
|
||||
m_timeSinceLastUpdate = DateTime.Now;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((DateTime.Now - m_timeSinceLastUpdate).TotalSeconds > 5)
|
||||
{
|
||||
m_timeSinceLastUpdate = DateTime.Now;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Get our spawner
|
||||
m_spawnerGroup = (SpawnerGroup)target;
|
||||
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
//Setup the wrap style
|
||||
if (m_wrapStyle == null)
|
||||
{
|
||||
m_wrapStyle = new GUIStyle(GUI.skin.label);
|
||||
m_wrapStyle.wordWrap = true;
|
||||
}
|
||||
|
||||
//Fix up names if necessary
|
||||
m_spawnerGroup.FixNames();
|
||||
|
||||
//Create a nice text intro
|
||||
GUILayout.BeginVertical("Spawner Group", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUILayout.LabelField("A Spawner Group allows you to chain a set of spawners together. The command buttons you run will be run on all sub spawners. It may take a little while so be patient.", m_wrapStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//Disable if spawning
|
||||
if (m_spawnerGroup.m_updateCoroutine != null)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
GUILayout.BeginVertical("Terrain Helper", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button(GetLabel("Flatten")))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Flatten Terrain tiles ?", "Are you sure you want to flatten all terrain tiles - this can not be undone ?", "Yes", "No"))
|
||||
{
|
||||
TerrainHelper.Flatten();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button(GetLabel("Smooth")))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Smooth Terrain tiles ?", "Are you sure you want to smooth all terrain tiles - this can not be undone ?", "Yes", "No"))
|
||||
{
|
||||
TerrainHelper.Smooth(1);
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button(GetLabel("Clear Trees")))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Clear Terrain trees ?", "Are you sure you want to clear all terrain trees - this can not be undone ?", "Yes", "No"))
|
||||
{
|
||||
//outdated
|
||||
//TerrainHelper.ClearTrees();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button(GetLabel("Clear Details")))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Clear Terrain details ?", "Are you sure you want to clear all terrain details - this can not be undone ?", "Yes", "No"))
|
||||
{
|
||||
//outdated
|
||||
//TerrainHelper.ClearDetails();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(5);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//Re-enable
|
||||
GUI.enabled = true;
|
||||
|
||||
//Display progress
|
||||
if (m_spawnerGroup.m_updateCoroutine != null)
|
||||
{
|
||||
GUILayout.BeginVertical("Spawner Controller", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(GetLabel("Cancel")))
|
||||
{
|
||||
m_spawnerGroup.CancelSpawn();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(5);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//Draw the various progress bars
|
||||
for (int idx = 0; idx < m_spawnerGroup.m_spawners.Count; idx++)
|
||||
{
|
||||
//Display progress
|
||||
if (m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress > 0f && m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress < 1f)
|
||||
{
|
||||
ProgressBar(string.Format("{0} ({1:0.0}%)", m_spawnerGroup.m_spawners[idx].m_name, m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress * 100f), m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.BeginVertical("Spawner Controller", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(GetLabel("Reset")))
|
||||
{
|
||||
m_spawnerGroup.ResetSpawner();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(GetLabel("Spawn")))
|
||||
{
|
||||
//Check that they have a single selected terrain
|
||||
if (Gaia.TerrainHelper.GetActiveTerrainCount() != 1)
|
||||
{
|
||||
EditorUtility.DisplayDialog("OOPS!", "You must have only one active terrain in order to use a Spawner Group. Please either add a terrain, or deactivate all but one terrain.", "OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_spawnerGroup.RunSpawnerIteration();
|
||||
StartEditorUpdates();
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(5f);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw a progress bar
|
||||
/// </summary>
|
||||
/// <param name="label"></param>
|
||||
/// <param name="value"></param>
|
||||
void ProgressBar(string label, float value)
|
||||
{
|
||||
// Get a rect for the progress bar using the same margins as a textfield:
|
||||
Rect rect = GUILayoutUtility.GetRect(18, 18, "TextField");
|
||||
EditorGUI.ProgressBar(rect, value, label);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a content label - look the tooltip up if possible
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
GUIContent GetLabel(string name)
|
||||
{
|
||||
string tooltip = "";
|
||||
if (m_tooltips.TryGetValue(name, out tooltip))
|
||||
{
|
||||
return new GUIContent(name, tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GUIContent(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tooltips
|
||||
/// </summary>
|
||||
static Dictionary<string, string> m_tooltips = new Dictionary<string, string>
|
||||
{
|
||||
{ "Reset", "Reset the spawner back to its initial state. Starting spawn again will generate exact same result provided that nothing else in the terrain has changed." },
|
||||
{ "Spawn", "Run a single spawn interation." },
|
||||
{ "Flatten", "Flatten the entire terrain - use with care!" },
|
||||
{ "Smooth", "Smooth the entire terrain - removes jaggies and increases frame rate - run multiple times to increase effect - use with care!" },
|
||||
{ "Clear Trees", "Clear trees from entire terrain - use with care!" },
|
||||
{ "Clear Details", "Clear details / grass from entire terrain - use with care!" },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5799b08366ab9eb4989b937a6d528052
|
||||
timeCreated: 1437940910
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0876f5a4f4aedb4286bc82edadd8d18
|
||||
timeCreated: 1431402318
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,140 @@
|
||||
using UnityEngine;
|
||||
using PWCommon4;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEditor;
|
||||
using Gaia.Internal;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(TerrainDetailOverwrite))]
|
||||
public class TerrainDetailOverwriteEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
private string m_version;
|
||||
private Color defaultBackground;
|
||||
private TerrainDetailOverwrite m_profile;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//Get Gaia Lighting Profile object
|
||||
m_profile = (TerrainDetailOverwrite)target;
|
||||
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
|
||||
m_version = PWApp.CONF.Version;
|
||||
|
||||
if (m_profile.m_terrain == null)
|
||||
{
|
||||
m_profile.m_terrain = m_profile.GetComponent<Terrain>();
|
||||
}
|
||||
|
||||
m_profile.m_detailDistance = (int)m_profile.m_terrain.detailObjectDistance;
|
||||
m_profile.m_detailDensity = m_profile.m_terrain.detailObjectDensity;
|
||||
|
||||
if (m_profile.m_terrain.terrainData.detailResolutionPerPatch == 2)
|
||||
{
|
||||
m_profile.m_detailQuality = GaiaConstants.TerrainDetailQuality.Ultra2;
|
||||
}
|
||||
else if (m_profile.m_terrain.terrainData.detailResolutionPerPatch == 4)
|
||||
{
|
||||
m_profile.m_detailQuality = GaiaConstants.TerrainDetailQuality.VeryHigh4;
|
||||
}
|
||||
else if (m_profile.m_terrain.terrainData.detailResolutionPerPatch == 8)
|
||||
{
|
||||
m_profile.m_detailQuality = GaiaConstants.TerrainDetailQuality.High8;
|
||||
}
|
||||
else if (m_profile.m_terrain.terrainData.detailResolutionPerPatch == 16)
|
||||
{
|
||||
m_profile.m_detailQuality = GaiaConstants.TerrainDetailQuality.Medium16;
|
||||
}
|
||||
else if (m_profile.m_terrain.terrainData.detailResolutionPerPatch == 32)
|
||||
{
|
||||
m_profile.m_detailQuality = GaiaConstants.TerrainDetailQuality.Low32;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_profile.m_detailQuality = GaiaConstants.TerrainDetailQuality.VeryLow64;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Initialization
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
m_profile.GetResolutionPatches();
|
||||
|
||||
EditorGUILayout.LabelField("Version: " + m_version);
|
||||
|
||||
m_editorUtils.Panel("DetailDistanceSettings", DetailTerrainDistance, true);
|
||||
}
|
||||
|
||||
private void DetailTerrainDistance(bool helpEnabled)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
m_editorUtils.Text("DetailInfo");
|
||||
EditorGUILayout.Space();
|
||||
|
||||
//switch (m_profile.m_detailQuality)
|
||||
//{
|
||||
// case GaiaConstants.TerrainDetailQuality.Ultra2:
|
||||
// EditorGUILayout.LabelField(m_editorUtils.GetTextValue("DetailPatchResolution") + "Ultra");
|
||||
// break;
|
||||
// case GaiaConstants.TerrainDetailQuality.VeryHigh4:
|
||||
// EditorGUILayout.LabelField(m_editorUtils.GetTextValue("DetailPatchResolution") + "Very High");
|
||||
// break;
|
||||
// case GaiaConstants.TerrainDetailQuality.High8:
|
||||
// EditorGUILayout.LabelField(m_editorUtils.GetTextValue("DetailPatchResolution") + "High");
|
||||
// break;
|
||||
// case GaiaConstants.TerrainDetailQuality.Medium16:
|
||||
// EditorGUILayout.LabelField(m_editorUtils.GetTextValue("DetailPatchResolution") + "Medium");
|
||||
// break;
|
||||
// case GaiaConstants.TerrainDetailQuality.Low32:
|
||||
// EditorGUILayout.LabelField(m_editorUtils.GetTextValue("DetailPatchResolution") + "Low");
|
||||
// break;
|
||||
// case GaiaConstants.TerrainDetailQuality.VeryLow64:
|
||||
// EditorGUILayout.LabelField(m_editorUtils.GetTextValue("DetailPatchResolution") + "Very Low");
|
||||
// break;
|
||||
//}
|
||||
//EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("DetailPatchResolutionHelp"), MessageType.Info);
|
||||
|
||||
m_profile.m_detailDistance = m_editorUtils.IntField("DetailDistance", m_profile.m_detailDistance, helpEnabled);
|
||||
if (m_profile.m_detailDistance < 0)
|
||||
{
|
||||
m_profile.m_detailDistance = 0;
|
||||
}
|
||||
if (m_profile.m_detailDistance > 250)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("DetailDistanceHelp"), MessageType.Info);
|
||||
}
|
||||
|
||||
m_profile.m_detailDensity = m_editorUtils.Slider("DetailDensity", m_profile.m_detailDensity, 0f, 1f, helpEnabled);
|
||||
if (m_profile.m_detailDistance > 250 && m_profile.m_detailDensity > 0.5f)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("DetailDensityHelp"), MessageType.Info);
|
||||
}
|
||||
|
||||
if (m_editorUtils.Button("ApplyToAll"))
|
||||
{
|
||||
m_profile.ApplySettings(true);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(m_profile, "Made changes");
|
||||
EditorUtility.SetDirty(m_profile);
|
||||
m_profile.ApplySettings(false);
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1958f1d983bcd9f459a25d01ec53c1b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(TerrainHelper))]
|
||||
public class TerrainHelperEditor : Editor
|
||||
{
|
||||
GUIStyle m_boxStyle;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box);
|
||||
m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
m_boxStyle.fontStyle = FontStyle.Bold;
|
||||
m_boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
|
||||
GUILayout.Space(10f);
|
||||
|
||||
//Terraform section
|
||||
GUILayout.BeginVertical("Terrain Controller", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
var helper = Selection.activeGameObject.GetComponent<TerrainHelper>();
|
||||
|
||||
if (GUILayout.Button("Flatten"))
|
||||
{
|
||||
TerrainHelper.Flatten();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Smooth"))
|
||||
{
|
||||
helper.Smooth();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Stitch"))
|
||||
{
|
||||
TerrainHelper.Stitch();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear Trees"))
|
||||
{
|
||||
//TerrainHelper.ClearTrees();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear Details"))
|
||||
{
|
||||
//TerrainHelper.ClearDetails();
|
||||
}
|
||||
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(5);
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 196117876818e6c419e7ba870ed6b03f
|
||||
timeCreated: 1431461531
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,115 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
|
||||
public delegate void ImageSelectedHandler(Texture2D imageName);
|
||||
|
||||
public class TexturePickerEditor : EditorWindow
|
||||
{
|
||||
public List<Texture2D> images = new List<Texture2D>();
|
||||
|
||||
/// <summary>
|
||||
/// A flag to indicate if the editor window has been setup or not.
|
||||
/// </summary>
|
||||
private bool m_isSetup = false;
|
||||
|
||||
private ImageSelectedHandler m_handler;
|
||||
|
||||
#region Setup
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to setup the editor by reading in textures from specified path.
|
||||
/// </summary>
|
||||
/// <param name='path'>
|
||||
/// Path to load images from.
|
||||
/// </param>
|
||||
public void Setup(string path, ImageSelectedHandler functionHandler)
|
||||
{
|
||||
string[] paths = new string[] { path };
|
||||
Setup(paths, functionHandler);
|
||||
} // eo Setup
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to setup the editor by reading in all textures specified
|
||||
/// by the various paths. Supports multiple paths of textures.
|
||||
/// </summary>
|
||||
/// <param name='paths'>
|
||||
/// Paths of textures to read in.
|
||||
/// </param>
|
||||
public void Setup(string[] paths, ImageSelectedHandler functionHandler)
|
||||
{
|
||||
m_isSetup = true;
|
||||
ReadInAllTextures(paths);
|
||||
m_handler = functionHandler;
|
||||
} // eo Setup
|
||||
|
||||
#endregion Setup
|
||||
|
||||
#region GUI
|
||||
|
||||
Vector2 m_scrollPosition = Vector2.zero;
|
||||
void OnGUI()
|
||||
{
|
||||
if (!m_isSetup)
|
||||
return;
|
||||
|
||||
m_scrollPosition = EditorGUILayout.BeginScrollView(m_scrollPosition);
|
||||
|
||||
// create a button for each image loaded in, 4 buttons in width
|
||||
// calls the handler when a new image is selected.
|
||||
int counter = 0;
|
||||
foreach (Texture2D img in images)
|
||||
{
|
||||
if (counter % 4 == 0 || counter == 0)
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
++counter;
|
||||
|
||||
if (GUILayout.Button(img, GUILayout.Height(100), GUILayout.Width(100)))
|
||||
{
|
||||
// tell handler about new image, close selection window
|
||||
m_handler(img);
|
||||
EditorWindow.focusedWindow.Close();
|
||||
}
|
||||
|
||||
if (counter % 4 == 0)
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
#endregion GUI
|
||||
|
||||
#region Utility
|
||||
|
||||
/// <summary>
|
||||
/// Reads the in all textures from the paths.
|
||||
/// </summary>
|
||||
/// <param name='paths'>
|
||||
/// The paths to read images from.
|
||||
/// </param>
|
||||
void ReadInAllTextures(string[] paths)
|
||||
{
|
||||
foreach (string path in paths)
|
||||
{
|
||||
string[] allFilesInPath = Directory.GetFiles(path);
|
||||
foreach (string filePath in allFilesInPath)
|
||||
{
|
||||
Texture2D obj = (Texture2D)AssetDatabase.LoadAssetAtPath(filePath, typeof(Texture2D));
|
||||
if (obj is Texture2D)
|
||||
{
|
||||
images.Add(obj as Texture2D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Utility
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c58898a38c12ed541a71c6ecc1a8ed75
|
||||
timeCreated: 1440805245
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,224 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using PWCommon4;
|
||||
using Gaia.Internal;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using ProceduralWorlds.Gaia.PackageSystem;
|
||||
|
||||
namespace Gaia.Pipeline
|
||||
{
|
||||
[CustomEditor(typeof(UnityPipelineProfile))]
|
||||
public class UnityPipelineProfileEditor : PWEditor
|
||||
{
|
||||
private GUIStyle m_boxStyle;
|
||||
private EditorUtils m_editorUtils;
|
||||
private UnityPipelineProfile m_profile;
|
||||
private string m_version;
|
||||
private bool[] m_shaderMappingLibraryFoldouts;
|
||||
private GUIStyle m_matlibButtonStyle;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//Initialization
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
|
||||
//Get Gaia Lighting Profile object
|
||||
m_profile = (UnityPipelineProfile)target;
|
||||
|
||||
m_version = PWApp.CONF.Version;
|
||||
|
||||
m_shaderMappingLibraryFoldouts = new bool[m_profile.m_ShaderMappingLibrary.Length];
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Initialization
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box)
|
||||
{
|
||||
normal = {textColor = GUI.skin.label.normal.textColor},
|
||||
fontStyle = FontStyle.Bold,
|
||||
alignment = TextAnchor.UpperLeft
|
||||
};
|
||||
}
|
||||
|
||||
//Monitor for changes
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.LabelField("Profile Version: " + m_version);
|
||||
|
||||
bool enableEditMode = System.IO.Directory.Exists(GaiaUtils.GetAssetPath("Dev Utilities"));
|
||||
if (enableEditMode)
|
||||
{
|
||||
m_profile.m_editorUpdates = EditorGUILayout.ToggleLeft("Use Procedural Worlds Editor Settings", m_profile.m_editorUpdates);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_profile.m_editorUpdates = false;
|
||||
}
|
||||
|
||||
if (m_profile.m_editorUpdates)
|
||||
{
|
||||
m_editorUtils.Panel("ProfileSettings", ProfileSettingsEnabled, false);
|
||||
}
|
||||
|
||||
//Check for changes, make undo record, make changes and let editor know we are dirty
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(m_profile, "Made changes");
|
||||
EditorUtility.SetDirty(m_profile);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProfileSettingsEnabled(bool helpEnabled)
|
||||
{
|
||||
GUILayout.BeginVertical("Pipeline Profile Settings", m_boxStyle);
|
||||
GUILayout.Space(20);
|
||||
EditorGUI.indentLevel++;
|
||||
DrawDefaultInspector();
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
if (m_matlibButtonStyle == null)
|
||||
{
|
||||
m_matlibButtonStyle = new GUIStyle(GUI.skin.button);
|
||||
m_matlibButtonStyle.margin = new RectOffset(40, m_matlibButtonStyle.margin.right, m_matlibButtonStyle.margin.top, m_matlibButtonStyle.margin.bottom);
|
||||
}
|
||||
|
||||
//Draw the Material library settings
|
||||
EditorGUILayout.LabelField("Shader Mapping");
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i=0; i < m_profile.m_ShaderMappingLibrary.Length; i++)
|
||||
{
|
||||
ShaderMappingEntry entry = m_profile.m_ShaderMappingLibrary[i];
|
||||
//int materialCount = entry.m_materials == null ? 0 : entry.m_materials.Count;
|
||||
m_shaderMappingLibraryFoldouts[i] = EditorGUILayout.Foldout(m_shaderMappingLibraryFoldouts[i], entry.m_builtInShaderName);
|
||||
if (m_shaderMappingLibraryFoldouts[i])
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
string oldbuiltInShader = entry.m_builtInShaderName;
|
||||
//entry.m_name = EditorGUILayout.TextField("Name", entry.m_name);
|
||||
entry.m_builtInShaderName = EditorGUILayout.TextField("Builtin Shader", entry.m_builtInShaderName);
|
||||
//if (oldbuiltInShader != entry.m_builtInShaderName)
|
||||
//{
|
||||
// entry.m_name = entry.m_builtInShaderName;
|
||||
//}
|
||||
entry.m_URPReplacementShaderName = EditorGUILayout.TextField("URP Shader", entry.m_URPReplacementShaderName);
|
||||
entry.m_HDRPReplacementShaderName = EditorGUILayout.TextField("HDRP Shader", entry.m_HDRPReplacementShaderName);
|
||||
//EditorGUI.indentLevel++;
|
||||
//entry.m_supportUnitypackages = EditorGUILayout.Toggle("Support Unity Packages", entry.m_supportUnitypackages);
|
||||
//if (entry.m_supportUnitypackages)
|
||||
//{
|
||||
// EditorGUI.indentLevel++;
|
||||
// entry.m_builtInMaterialUnitypackage = EditorGUILayout.TextField("Builtin Material Package", entry.m_builtInMaterialUnitypackage);
|
||||
// entry.m_URPMaterialUnitypackage = EditorGUILayout.TextField("URP Material Package", entry.m_URPMaterialUnitypackage);
|
||||
// entry.m_HDRPMaterialUnitypackage = EditorGUILayout.TextField("HDRP Material Package", entry.m_HDRPMaterialUnitypackage);
|
||||
// EditorGUI.indentLevel--;
|
||||
//}
|
||||
//entry.m_floatChecksFoldedOut = EditorGUILayout.Foldout(entry.m_floatChecksFoldedOut, "Float Checks [" + entry.m_floatChecks.Count.ToString() + "]");
|
||||
//int floatCheckDeleteIndex = -99;
|
||||
//if (entry.m_floatChecksFoldedOut)
|
||||
//{
|
||||
// EditorGUI.indentLevel++;
|
||||
// for (int j = 0; j < entry.m_floatChecks.Count; j++)
|
||||
// {
|
||||
// Color regularColor = GUI.color;
|
||||
// if (String.IsNullOrEmpty(entry.m_floatChecks[j].m_floatValue) || String.IsNullOrEmpty(entry.m_floatChecks[j].m_shaderKeyWord))
|
||||
// {
|
||||
// GUI.color = Color.red;
|
||||
// }
|
||||
// Rect rect = EditorGUILayout.GetControlRect();
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.LabelField("Float", GUILayout.MinWidth(rect.width/5f));
|
||||
// entry.m_floatChecks[j].m_floatValue = EditorGUILayout.TextField(entry.m_floatChecks[j].m_floatValue, GUILayout.MinWidth(rect.width / 5f));
|
||||
// EditorGUILayout.LabelField("KeyWord", GUILayout.MinWidth(rect.width / 5f));
|
||||
// entry.m_floatChecks[j].m_shaderKeyWord = EditorGUILayout.TextField(entry.m_floatChecks[j].m_shaderKeyWord, GUILayout.MinWidth(rect.width / 5f));
|
||||
// if (GUILayout.Button("Delete", m_matlibButtonStyle, GUILayout.MaxWidth(50)))
|
||||
// {
|
||||
// floatCheckDeleteIndex = j;
|
||||
// }
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
// GUI.color = regularColor;
|
||||
|
||||
// }
|
||||
// if (floatCheckDeleteIndex != -99)
|
||||
// {
|
||||
// entry.m_floatChecks.RemoveAt(floatCheckDeleteIndex);
|
||||
// }
|
||||
// if (GUILayout.Button("Add new Float Check", m_matlibButtonStyle))
|
||||
// {
|
||||
// entry.m_floatChecks.Add(new ShaderFloatCheck());
|
||||
// }
|
||||
|
||||
//EditorGUI.indentLevel--;
|
||||
}
|
||||
//EditorGUI.indentLevel--;
|
||||
|
||||
//EditorGUI.indentLevel++;
|
||||
//entry.m_materialsFoldedOut = EditorGUILayout.Foldout(entry.m_materialsFoldedOut, "Materials [" + materialCount.ToString() +"]");
|
||||
//if (entry.m_materialsFoldedOut)
|
||||
//{
|
||||
// EditorGUI.indentLevel++;
|
||||
// for (int j = 0; j < entry.m_materials.Count; j++)
|
||||
// {
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// Color regularColor = GUI.color;
|
||||
// if (entry.m_materials[j] == null)
|
||||
// {
|
||||
// GUI.color = Color.red;
|
||||
// }
|
||||
// entry.m_materials[j] = (Material)EditorGUILayout.ObjectField("Material " + j.ToString(), entry.m_materials[j], typeof(Material),false);
|
||||
// if (GUILayout.Button("-", GUILayout.MaxWidth(30f)))
|
||||
// {
|
||||
// entry.m_materials.RemoveAt(j);
|
||||
// }
|
||||
// GUI.color = regularColor;
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
// }
|
||||
// EditorGUI.indentLevel--;
|
||||
//}
|
||||
//if (GUILayout.Button("Load Materials for " + entry.m_name, m_matlibButtonStyle))
|
||||
//{
|
||||
// LoadMaterials(entry);
|
||||
//}
|
||||
if (GUILayout.Button("Remove " + entry.m_builtInShaderName, m_matlibButtonStyle))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Delete Shader Mapping Entry", "Are you sure you want to delete the entire entry for '" + entry.m_builtInShaderName + "' ?", "OK", "Cancel"))
|
||||
{
|
||||
m_profile.m_ShaderMappingLibrary = GaiaUtils.RemoveArrayIndexAt(m_profile.m_ShaderMappingLibrary, i);
|
||||
m_shaderMappingLibraryFoldouts = GaiaUtils.RemoveArrayIndexAt(m_shaderMappingLibraryFoldouts, i);
|
||||
}
|
||||
|
||||
}
|
||||
if (GUILayout.Button("Insert entry below", m_matlibButtonStyle))
|
||||
{
|
||||
m_profile.m_ShaderMappingLibrary = GaiaUtils.InsertElementInArray(m_profile.m_ShaderMappingLibrary, new ShaderMappingEntry() { m_builtInShaderName = "New Entry" } ,i+1);
|
||||
m_shaderMappingLibraryFoldouts = GaiaUtils.InsertElementInArray(m_shaderMappingLibraryFoldouts, true, i+1);
|
||||
|
||||
}
|
||||
//EditorGUI.indentLevel--;
|
||||
//EditorGUI.indentLevel--;
|
||||
|
||||
}
|
||||
if (GUILayout.Button("Add new Material Library entry"))
|
||||
{
|
||||
m_profile.m_ShaderMappingLibrary = GaiaUtils.AddElementToArray(m_profile.m_ShaderMappingLibrary, new ShaderMappingEntry() { m_builtInShaderName = "New Entry" });
|
||||
m_shaderMappingLibraryFoldouts = GaiaUtils.AddElementToArray(m_shaderMappingLibraryFoldouts, true);
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29f3461eb920f8a4ba0fd1557c3a10e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,136 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
#if UNITY_POST_PROCESSING_STACK_V2
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
#endif
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Editor for Biome Preset settings, only offers a text & a button to create the spawner in the scene
|
||||
/// If the user wants to edit or create new spawner settings, they can do so by saving a spawner settings file from a spawner directly.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(UserFiles))]
|
||||
public class UserFilesEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
private UserFiles m_userFiles;
|
||||
private UnityEditorInternal.ReorderableList m_spawnerPresetList;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_userFiles = (UserFiles)target;
|
||||
//Init editor utils
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
m_editorUtils.Panel("UserFiles",DrawUserFiles,true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void DrawUserFiles(bool helpEnabled)
|
||||
{
|
||||
m_userFiles.m_autoAddNewFiles = m_editorUtils.Toggle("AutoAddNewFiles", m_userFiles.m_autoAddNewFiles, helpEnabled);
|
||||
m_userFiles.m_updateFilesWithGaiaUpdate = m_editorUtils.Toggle("UpdateWithGaia", m_userFiles.m_updateFilesWithGaiaUpdate, helpEnabled);
|
||||
GUILayout.Space(10);
|
||||
if (m_editorUtils.Button("AddDefaults"))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Add Gaia Default Biomes?", "This will add the default Biomes & Spawners of Gaia back to the lists in case they are missing. Continue?", "Add Defaults", "Cancel"))
|
||||
{
|
||||
GaiaUtils.ResetBiomePresets(true);
|
||||
}
|
||||
}
|
||||
GUILayout.Space(10);
|
||||
m_editorUtils.Heading("BiomePresetHeading");
|
||||
m_editorUtils.InlineHelp("BiomePresetHeading", helpEnabled);
|
||||
|
||||
float deleteButtonWidth = 50;
|
||||
|
||||
for (int i = 0; i < m_userFiles.m_gaiaManagerBiomePresets.Count; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
m_userFiles.m_gaiaManagerBiomePresets[i] = (BiomePreset)EditorGUILayout.ObjectField(m_userFiles.m_gaiaManagerBiomePresets[i], typeof(BiomePreset), false);
|
||||
if (m_editorUtils.Button("DeleteBiomePreset", GUILayout.Width(deleteButtonWidth)))
|
||||
{
|
||||
m_userFiles.m_gaiaManagerBiomePresets.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
if (m_editorUtils.Button("AddBiomePreset"))
|
||||
{
|
||||
m_userFiles.m_gaiaManagerBiomePresets.Add(null);
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(10);
|
||||
m_editorUtils.Heading("SpawnerSettingsHeading");
|
||||
m_editorUtils.InlineHelp("SpawnerSettingsHeading", helpEnabled);
|
||||
for (int i = 0; i < m_userFiles.m_gaiaManagerSpawnerSettings.Count; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
m_userFiles.m_gaiaManagerSpawnerSettings[i] = (SpawnerSettings)EditorGUILayout.ObjectField(m_userFiles.m_gaiaManagerSpawnerSettings[i], typeof(SpawnerSettings), false);
|
||||
if (m_editorUtils.Button("DeleteSpawnerSettings", GUILayout.Width(deleteButtonWidth)))
|
||||
{
|
||||
m_userFiles.m_gaiaManagerSpawnerSettings.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
if (m_editorUtils.Button("AddSpawnerSettings"))
|
||||
{
|
||||
m_userFiles.m_gaiaManagerSpawnerSettings.Add(null);
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(10);
|
||||
m_editorUtils.Heading("ExportTerrainSettingsHeading");
|
||||
m_editorUtils.InlineHelp("ExportTerrainSettingsHeading", helpEnabled);
|
||||
for (int i = 0; i < m_userFiles.m_exportTerrainSettings.Count; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
m_userFiles.m_exportTerrainSettings[i] = (ExportTerrainSettings)EditorGUILayout.ObjectField(m_userFiles.m_exportTerrainSettings[i], typeof(ExportTerrainSettings), false);
|
||||
if (m_editorUtils.Button("DeleteExportTerrainSettings", GUILayout.Width(deleteButtonWidth)))
|
||||
{
|
||||
m_userFiles.m_exportTerrainSettings.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
if (m_editorUtils.Button("AddExportTerrainSettings"))
|
||||
{
|
||||
m_userFiles.m_exportTerrainSettings.Add(null);
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5073d6e52e114c4b99a9d757ad8c4f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using Gaia.Internal;
|
||||
using UnityEditor;
|
||||
using PWCommon4;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(WindManager))]
|
||||
public class WindManagerEditor : PWEditor
|
||||
{
|
||||
public EditorUtils m_editorUtils;
|
||||
private WindManager m_manager;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
}
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
m_editorUtils.Initialize();
|
||||
if (m_manager == null)
|
||||
{
|
||||
m_manager = (WindManager)target;
|
||||
}
|
||||
|
||||
m_editorUtils.Panel("GlobalSettings", GlobalPanel, true);
|
||||
}
|
||||
private void GlobalPanel(bool helpEnabled)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("WindManagerInfo"), MessageType.Info);
|
||||
m_manager.windGlobalMaxDist = m_editorUtils.Slider("GlobalWindDistance", m_manager.windGlobalMaxDist, 100f, 10000f, helpEnabled);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
m_editorUtils.Heading("WindSettings");
|
||||
m_manager.m_useWindAudio = m_editorUtils.Toggle("UseWindAudio", m_manager.m_useWindAudio, helpEnabled);
|
||||
if (m_manager.m_useWindAudio)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
m_manager.m_windTransitionTime = m_editorUtils.FloatField("WindTransitionTime", m_manager.m_windTransitionTime, helpEnabled);
|
||||
if (m_manager.m_windTransitionTime < 0.1f)
|
||||
{
|
||||
m_manager.m_windTransitionTime = 0.1f;
|
||||
}
|
||||
m_manager.m_windAudioClip = (AudioClip)m_editorUtils.ObjectField("WindAudioClip", m_manager.m_windAudioClip, typeof(AudioClip), false, helpEnabled);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d363c3f4538e0844b80b08c7279278f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user