Initial commit

This commit is contained in:
gunnbr committed 2021-01-11 22:20:43 -08:00
1 parent ee9615239e
commit 16feac691f
4093 files changed
+1030491

No files matched your search

@@ -0,0 +1,237 @@
using PWCommon4;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace Gaia
{
//This class is not a full editor class by itself, but used to collect reusable methods
//for editing collision masks in a reorderable list.
public class CollisionMaskListEditor : PWEditor, IPWEditor
{
public static float OnElementHeight(int index, CollisionMask[] collisionMasks)
{
return EditorGUIUtility.singleLineHeight ;
}
public static CollisionMask[] OnRemoveMaskListEntry(CollisionMask[] oldList, int index)
{
if (index < 0 || index >= oldList.Length)
return null;
CollisionMask toRemove = oldList[index];
CollisionMask[] newList = new CollisionMask[oldList.Length - 1];
for (int i = 0; i < newList.Length; ++i)
{
if (i < index)
{
newList[i] = oldList[i];
}
else if (i >= index)
{
newList[i] = oldList[i + 1];
}
}
return newList;
}
public static CollisionMask[] OnAddMaskListEntry(CollisionMask[] oldList)
{
CollisionMask[] newList = new CollisionMask[oldList.Length + 1];
for (int i = 0; i < oldList.Length; ++i)
{
newList[i] = oldList[i];
}
newList[newList.Length - 1] = new CollisionMask();
return newList;
}
public static bool DrawFilterListHeader(Rect rect, bool currentFoldOutState, CollisionMask[] maskList, EditorUtils editorUtils)
{
int oldIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
rect.xMin += 8f;
bool newFoldOutState = EditorGUI.Foldout(rect, currentFoldOutState, PropertyCount("MaskRespectedCollisions", maskList, editorUtils), true);
EditorGUI.indentLevel = oldIndent;
return newFoldOutState;
}
public static void DrawMaskList(ref bool listExpanded, ReorderableList list, EditorUtils editorUtils, Rect rect)
{
Rect maskRect;
if (listExpanded)
{
maskRect = rect;
list.DoList(maskRect);
}
else
{
int oldIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 1;
listExpanded = EditorGUI.Foldout(rect,listExpanded, PropertyCount("MaskRespectedCollisions", (CollisionMask[])list.list, editorUtils), true);
maskRect = rect;
EditorGUI.indentLevel = oldIndent;
}
//editorUtils.Panel("MaskBaking", DrawMaskBaking, false);
}
public static void DrawMaskListElement(Rect rect, int index, CollisionMask collisionMask, EditorUtils m_editorUtils, Terrain currentTerrain, GaiaConstants.FeatureOperation operation)
{
int oldIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
//Active Label
Rect fieldRect = new Rect(rect.x, rect.y, rect.width * 0.1f, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(fieldRect, m_editorUtils.GetContent("MaskActive"));
//Active Checkbox
fieldRect.x += rect.width * 0.1f;
fieldRect.width = rect.width * 0.05f;
collisionMask.m_active = EditorGUI.Toggle(fieldRect, collisionMask.m_active);
//Invert Label
fieldRect.x += rect.width * 0.05f;
fieldRect.width = rect.width * 0.1f;
EditorGUI.LabelField(fieldRect, m_editorUtils.GetContent("MaskInvert"));
//Invert Checkbox
fieldRect.x += rect.width * 0.1f;
fieldRect.width = rect.width * 0.05f;
collisionMask.m_invert = EditorGUI.Toggle(fieldRect, collisionMask.m_invert);
//Type dropdown
fieldRect.x += rect.width * 0.05f;
fieldRect.width = rect.width * 0.2f;
BakedMaskType oldType = collisionMask.m_type;
collisionMask.m_type = (BakedMaskType)EditorGUI.EnumPopup(fieldRect, collisionMask.m_type);
EditorGUI.LabelField(fieldRect, m_editorUtils.GetContent("CollisionMaskTypeTooltip"));
switch (collisionMask.m_type)
{
case BakedMaskType.RadiusTree:
//Tree dropdown
string oldTreeId = collisionMask.m_treeSpawnRuleGUID;
fieldRect.x += rect.width * 0.2f;
int selectedGUIDIndex = 0;
if (collisionMask.m_treeSpawnRuleGUID != "")
{
SpawnRule selectedRule = CollisionMask.m_allTreeSpawnRules.FirstOrDefault(x => x.GUID == collisionMask.m_treeSpawnRuleGUID);
if (selectedRule != null)
{
selectedGUIDIndex = Array.IndexOf(CollisionMask.m_allTreeSpawnRules, selectedRule);
}
}
selectedGUIDIndex = EditorGUI.IntPopup(fieldRect, selectedGUIDIndex, CollisionMask.m_allTreeSpawnRuleNames, CollisionMask.m_allTreeSpawnRuleIndices);
if (selectedGUIDIndex >= 0 && selectedGUIDIndex < CollisionMask.m_allTreeSpawnRules.Length)
{
collisionMask.m_treeSpawnRuleGUID = CollisionMask.m_allTreeSpawnRules[selectedGUIDIndex].GUID;
}
if (oldType != collisionMask.m_type || oldTreeId != collisionMask.m_treeSpawnRuleGUID)
{
SpawnRule selectedRule = CollisionMask.m_allTreeSpawnRules.FirstOrDefault(x => x.GUID == collisionMask.m_treeSpawnRuleGUID);
if (selectedRule != null)
{
Spawner spawner = CollisionMask.m_allTreeSpawners.FirstOrDefault(x => x.m_settings.m_spawnerRules.Contains(selectedRule));
if (spawner != null)
{
GameObject treePrefab = spawner.m_settings.m_resources.m_treePrototypes[selectedRule.m_resourceIdx].m_desktopPrefab;
collisionMask.m_Radius = GaiaUtils.GetTreeRadius(treePrefab);
}
}
}
fieldRect.x += rect.width * 0.2f;
fieldRect.width = rect.width * 0.1f;
collisionMask.m_Radius = EditorGUI.FloatField(fieldRect, collisionMask.m_Radius);
fieldRect.x += rect.width * 0.1f;
fieldRect.width = rect.width * 0.2f;
break;
case BakedMaskType.RadiusTag:
//Tree dropdown
fieldRect.x += rect.width * 0.2f;
////Building up a value array of incrementing ints of the size of the available tags this array will then match the displayed string selection in the popup
//int[] tagValueArray = Enumerable
// .Repeat(0, (int)((currentTerrain.terrainData.treePrototypes.Length - 0) / 1) + 1)
// .Select((tr, ti) => tr + (1 * ti))
// .ToArray();
string oldTag = collisionMask.m_tag;
collisionMask.m_tag = EditorGUI.TagField(fieldRect, collisionMask.m_tag);
if (oldType != collisionMask.m_type || oldTag != collisionMask.m_tag)
{
collisionMask.m_Radius = GaiaUtils.GetBoundsForTaggedObject(collisionMask.m_tag);
}
fieldRect.x += rect.width * 0.2f;
fieldRect.width = rect.width * 0.1f;
collisionMask.m_Radius = EditorGUI.FloatField(fieldRect, collisionMask.m_Radius);
fieldRect.x += rect.width * 0.1f;
fieldRect.width = rect.width * 0.2f;
break;
case (BakedMaskType.LayerGameObject):
//Layer mask selection
fieldRect.x += rect.width * 0.2f;
EditorGUI.BeginChangeCheck();
collisionMask.m_layerMask = GaiaEditorUtils.LayerMaskFieldRect(fieldRect, new GUIContent(""), collisionMask.m_layerMask);
if (EditorGUI.EndChangeCheck())
{
collisionMask.m_layerMaskLayerNames = GaiaUtils.LayerMaskToString(collisionMask.m_layerMask);
}
EditorGUI.LabelField(fieldRect, m_editorUtils.GetContent("CollisionMaskLayerSelectionTooltip"));
fieldRect.x += rect.width * 0.2f;
fieldRect.width = rect.width * 0.1f;
collisionMask.m_growShrinkDistance = EditorGUI.FloatField(fieldRect, collisionMask.m_growShrinkDistance);
EditorGUI.LabelField(fieldRect, m_editorUtils.GetContent("CollisionMaskGrowShrinkDistanceTooltip"));
fieldRect.x += rect.width * 0.1f;
fieldRect.width = rect.width * 0.2f;
break;
case (BakedMaskType.LayerTree):
//Layer mask selection
fieldRect.x += rect.width * 0.2f;
EditorGUI.BeginChangeCheck();
collisionMask.m_layerMask = GaiaEditorUtils.LayerMaskFieldRect(fieldRect, new GUIContent(""), collisionMask.m_layerMask);
if (EditorGUI.EndChangeCheck())
{
collisionMask.m_layerMaskLayerNames = GaiaUtils.LayerMaskToString(collisionMask.m_layerMask);
}
EditorGUI.LabelField(fieldRect, m_editorUtils.GetContent("CollisionMaskLayerSelectionTooltip"));
fieldRect.x += rect.width * 0.2f;
fieldRect.width = rect.width * 0.1f;
collisionMask.m_growShrinkDistance = EditorGUI.FloatField(fieldRect, collisionMask.m_growShrinkDistance);
EditorGUI.LabelField(fieldRect, m_editorUtils.GetContent("CollisionMaskGrowShrinkDistanceTooltip"));
fieldRect.x += rect.width * 0.1f;
fieldRect.width = rect.width * 0.2f;
break;
}
if (GUI.Button(fieldRect, m_editorUtils.GetContent("MaskCollisionBake")))
{
switch (collisionMask.m_type)
{
case BakedMaskType.RadiusTree:
GaiaSessionManager.GetSessionManager().m_bakedMaskCache.BakeAllTreeCollisions(collisionMask.m_treeSpawnRuleGUID, collisionMask.m_Radius);
break;
case BakedMaskType.RadiusTag:
GaiaSessionManager.GetSessionManager().m_bakedMaskCache.BakeAllTagCollisions(collisionMask.m_tag, collisionMask.m_Radius);
break;
case BakedMaskType.LayerGameObject:
GaiaSessionManager.GetSessionManager().m_bakedMaskCache.BakeAllLayerGameObjectCollisions(collisionMask.m_layerMask, collisionMask.m_growShrinkDistance); //, collisionMask.m_Radius);
break;
case BakedMaskType.LayerTree:
GaiaSessionManager.GetSessionManager().m_bakedMaskCache.BakeAllLayerTreeCollisions(collisionMask.m_layerMask, collisionMask.m_growShrinkDistance); //, collisionMask.m_Radius);
break;
}
}
EditorGUI.indentLevel = oldIndent;
}
public static GUIContent PropertyCount(string key, Array array, EditorUtils editorUtils)
{
GUIContent content = editorUtils.GetContent(key);
content.text += " [" + array.Length + "]";
return content;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: db0b58152ca78de4d8733e0d6d9e96a6
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,11 @@
fileFormatVersion: 2
guid: 77f4b550e21df70459ad255efe76efc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
using Gaia.Internal;
using PWCommon4;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Gaia
{
/// <summary>
/// Editor for Spawner 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(MaskMapExportSettings))]
public class MaskMapExportSettingsEditor : PWEditor
{
private EditorUtils m_editorUtils;
private MaskMapExportSettings m_maskMapExportSettings;
private void OnEnable()
{
//Init editor utils
if (m_editorUtils == null)
{
// Get editor utils for this
m_editorUtils = PWApp.GetEditorUtils(this);
}
}
public override void OnInspectorGUI()
{
#if GAIA_PRO_PRESENT
m_editorUtils.Initialize(); // Do not remove this!
m_maskMapExportSettings = (MaskMapExportSettings)target;
string message = m_editorUtils.GetTextValue("Intro"); ;
EditorGUILayout.HelpBox(message, MessageType.Info, true);
if (m_editorUtils.Button("AddToScene"))
{
GameObject sessionTempObj = GaiaUtils.GetTempSessionToolsObject();
GameObject maskMapExporterObj = new GameObject("Mask Map Exporter");
maskMapExporterObj.transform.parent = sessionTempObj.transform;
MaskMapExport maskMapExport = maskMapExporterObj.AddComponent<MaskMapExport>();
maskMapExport.LoadSettings(m_maskMapExportSettings);
}
m_editorUtils.Heading("Stored Settings");
DrawDefaultInspector();
// Update is called once per frame
#else
string message = m_editorUtils.GetTextValue("GaiaProInfo"); ;
EditorGUILayout.HelpBox(message, MessageType.Info, true);
#endif
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 30ba11a1990dc644fa9dff1a136e2cdc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: