Initial commit
This commit is contained in:
1 parent
ee9615239e
commit
16feac691f
4093 files changed
+1030491
No files matched your search
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3ae944fad6abd8469882f430c17e29c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
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 Stamper Auto Mask Exporters in a reorderable list.
|
||||
public class StamperAutoMaskExportListEditor : PWEditor, IPWEditor
|
||||
{
|
||||
|
||||
public static float OnElementHeight()
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
|
||||
public static List<AutoMaskExport> OnRemoveListEntry(List<AutoMaskExport> oldList, int index)
|
||||
{
|
||||
oldList.RemoveAt(index);
|
||||
return oldList;
|
||||
}
|
||||
|
||||
public static List<AutoMaskExport> OnAddListEntry(List<AutoMaskExport> oldList)
|
||||
{
|
||||
oldList.Add(new AutoMaskExport { isActive=true });
|
||||
return oldList;
|
||||
}
|
||||
|
||||
public static bool DrawListHeader(Rect rect, bool currentFoldOutState, bool currentToggleAllState, List<AutoMaskExport> autoMaskList, EditorUtils editorUtils, ref GaiaConstants.AutoSpawnerArea autoSpawnerArea)
|
||||
{
|
||||
int oldIndent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
//rect.xMin += 0f;
|
||||
|
||||
|
||||
Rect dropdownRect = new Rect(rect);
|
||||
dropdownRect.width = 50;
|
||||
dropdownRect.height = 15;
|
||||
dropdownRect.y += 2;
|
||||
dropdownRect.x = rect.x + rect.width - 2 - dropdownRect.width;
|
||||
|
||||
GUIStyle dropdownStyle = new GUIStyle(GUI.skin.button);
|
||||
dropdownStyle.fixedHeight = 15;
|
||||
|
||||
Rect label2Rect = new Rect(rect);
|
||||
label2Rect.width = 30;
|
||||
label2Rect.x = dropdownRect.x - 5 - label2Rect.width;
|
||||
|
||||
|
||||
Rect label1Rect = new Rect(rect);
|
||||
label1Rect.x += 35;
|
||||
label1Rect.width = rect.width - label2Rect.width - 35 - dropdownRect.width - 5 - 10;
|
||||
|
||||
|
||||
Rect toggleAllRect = new Rect(rect);
|
||||
toggleAllRect.x += 15;
|
||||
toggleAllRect.width = 12;
|
||||
|
||||
bool oldToggleOldState = currentToggleAllState;
|
||||
currentToggleAllState = EditorGUI.Toggle(toggleAllRect, currentToggleAllState);
|
||||
EditorGUI.LabelField(toggleAllRect, editorUtils.GetContent("AutoToggleAllTooltip"));
|
||||
|
||||
if (currentToggleAllState != oldToggleOldState)
|
||||
{
|
||||
foreach (AutoMaskExport entry in autoMaskList)
|
||||
{
|
||||
entry.isActive = currentToggleAllState;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.LabelField(label1Rect, editorUtils.GetContent("AutoMaskMapExportHeader"));
|
||||
EditorGUI.LabelField(label2Rect, editorUtils.GetContent("AutoMaskMapExportAreaLabel"));
|
||||
|
||||
autoSpawnerArea = (GaiaConstants.AutoSpawnerArea)EditorGUI.EnumPopup(dropdownRect, autoSpawnerArea, dropdownStyle);
|
||||
EditorGUI.LabelField(dropdownRect, editorUtils.GetContent("AutoMaskMapExportAreaTooltip"));
|
||||
|
||||
//bool newFoldOutState = EditorGUI.Foldout(rect, currentFoldOutState, PropertyCount("SpawnerAdded", spawnerList, editorUtils), true);
|
||||
EditorGUI.indentLevel = oldIndent;
|
||||
//return newFoldOutState;
|
||||
|
||||
|
||||
return currentToggleAllState;
|
||||
}
|
||||
|
||||
public static void DrawList(ReorderableList list, EditorUtils editorUtils)
|
||||
{
|
||||
Rect maskRect;
|
||||
maskRect = EditorGUILayout.GetControlRect(true, list.GetHeight());
|
||||
list.DoList(maskRect);
|
||||
}
|
||||
|
||||
public static void DrawListElement(Rect rect, ref AutoMaskExport listEntry, EditorUtils m_editorUtils)
|
||||
{
|
||||
int oldIndent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
//EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width * 0.1f, EditorGUIUtility.singleLineHeight), m_editorUtils.GetContent("AutoSpawnerActive"));
|
||||
listEntry.isActive = EditorGUI.Toggle(new Rect(rect.x, rect.y, 20, EditorGUIUtility.singleLineHeight), listEntry.isActive);
|
||||
//switch (listEntry.status)
|
||||
//{
|
||||
// case AutoSpawnerStatus.Spawning:
|
||||
// EditorGUI.LabelField(new Rect(rect.x + rect.width * 0.2f, rect.y, rect.width * 0.2f, EditorGUIUtility.singleLineHeight), String.Format("{0:f0}", listEntry.spawner.m_spawnProgress * 100));
|
||||
// break;
|
||||
// default:
|
||||
// EditorGUI.LabelField(new Rect(rect.x + rect.width * 0.2f, rect.y, rect.width * 0.2f, EditorGUIUtility.singleLineHeight), listEntry.status.ToString());
|
||||
// break;
|
||||
//}
|
||||
bool currentGUIState = GUI.enabled;
|
||||
GUI.enabled = listEntry.isActive;
|
||||
#if GAIA_PRO_PRESENT
|
||||
listEntry.maskMapExport = (MaskMapExport)EditorGUI.ObjectField(new Rect(rect.x + 20, rect.y, rect.width - 20, EditorGUIUtility.singleLineHeight), listEntry.maskMapExport, typeof(MaskMapExport), true);
|
||||
#endif
|
||||
GUI.enabled = currentGUIState;
|
||||
EditorGUI.indentLevel = oldIndent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static GUIContent PropertyCount(string key, List<AutoMaskExport> list, EditorUtils editorUtils)
|
||||
{
|
||||
GUIContent content = editorUtils.GetContent(key);
|
||||
content.text += " [" + list.Count + "]";
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 610f3026297b7cf4d99a80c4a697d913
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
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 Stamper Auto Spawners in a reorderable list.
|
||||
public class StamperAutoSpawnerListEditor : PWEditor, IPWEditor
|
||||
{
|
||||
|
||||
public static float OnElementHeight()
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
|
||||
public static List<AutoSpawner> OnRemoveListEntry(List<AutoSpawner> oldList, int index)
|
||||
{
|
||||
//if (index < 0 || index >= oldList.Length)
|
||||
// return null;
|
||||
//SpawnerPresetListEntry toRemove = oldList[index];
|
||||
//SpawnerPresetListEntry[] newList = new SpawnerPresetListEntry[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];
|
||||
// }
|
||||
//}
|
||||
oldList.RemoveAt(index);
|
||||
return oldList;
|
||||
}
|
||||
|
||||
public static List<AutoSpawner> OnAddListEntry(List<AutoSpawner> oldList)
|
||||
{
|
||||
oldList.Add(new AutoSpawner() { isActive = true, status= AutoSpawnerStatus.Initial });
|
||||
return oldList;
|
||||
}
|
||||
|
||||
public static bool DrawListHeader(Rect rect, bool currentFoldOutState, bool currentToggleAllState, List<AutoSpawner> spawnerList, EditorUtils editorUtils, ref GaiaConstants.AutoSpawnerArea autoSpawnerArea)
|
||||
{
|
||||
int oldIndent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
//rect.xMin += 0f;
|
||||
|
||||
|
||||
Rect dropdownRect = new Rect(rect);
|
||||
dropdownRect.width = 50;
|
||||
dropdownRect.height = 15;
|
||||
dropdownRect.y += 2;
|
||||
dropdownRect.x = rect.x + rect.width - 2- dropdownRect.width;
|
||||
|
||||
GUIStyle dropdownStyle = new GUIStyle(GUI.skin.button);
|
||||
dropdownStyle.fixedHeight = 15;
|
||||
|
||||
Rect label2Rect = new Rect(rect);
|
||||
label2Rect.width = 30;
|
||||
label2Rect.x = dropdownRect.x - 5 - label2Rect.width;
|
||||
|
||||
|
||||
Rect label1Rect = new Rect(rect);
|
||||
label1Rect.x += 35;
|
||||
label1Rect.width = rect.width - label2Rect.width - 35 - dropdownRect.width - 5 - 10;
|
||||
|
||||
|
||||
Rect toggleAllRect = new Rect(rect);
|
||||
toggleAllRect.x += 15;
|
||||
toggleAllRect.width = 12;
|
||||
|
||||
bool oldToggleOldState = currentToggleAllState;
|
||||
currentToggleAllState = EditorGUI.Toggle(toggleAllRect, currentToggleAllState);
|
||||
EditorGUI.LabelField(toggleAllRect, editorUtils.GetContent("AutoToggleAllTooltip"));
|
||||
|
||||
if (currentToggleAllState != oldToggleOldState)
|
||||
{
|
||||
foreach (AutoSpawner entry in spawnerList)
|
||||
{
|
||||
entry.isActive = currentToggleAllState;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.LabelField(label1Rect, editorUtils.GetContent("AutoSpawnerHeader"));
|
||||
EditorGUI.LabelField(label2Rect, editorUtils.GetContent("AutoSpawnerAreaLabel"));
|
||||
|
||||
autoSpawnerArea = (GaiaConstants.AutoSpawnerArea)EditorGUI.EnumPopup(dropdownRect, autoSpawnerArea, dropdownStyle);
|
||||
EditorGUI.LabelField(dropdownRect, editorUtils.GetContent("AutoSpawnerAreaTooltip"));
|
||||
|
||||
//bool newFoldOutState = EditorGUI.Foldout(rect, currentFoldOutState, PropertyCount("SpawnerAdded", spawnerList, editorUtils), true);
|
||||
EditorGUI.indentLevel = oldIndent;
|
||||
//return newFoldOutState;
|
||||
|
||||
|
||||
return currentToggleAllState;
|
||||
}
|
||||
|
||||
public static void DrawList(ReorderableList list, EditorUtils editorUtils)
|
||||
{
|
||||
Rect maskRect;
|
||||
//if (listExpanded)
|
||||
//{
|
||||
maskRect = EditorGUILayout.GetControlRect(true, list.GetHeight());
|
||||
list.DoList(maskRect);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// int oldIndent = EditorGUI.indentLevel;
|
||||
// EditorGUI.indentLevel = 1;
|
||||
// listExpanded = EditorGUILayout.Foldout(listExpanded, PropertyCount("SpawnerAdded", (List<SpawnerPresetListEntry>)list.list, editorUtils), true);
|
||||
// maskRect = GUILayoutUtility.GetLastRect();
|
||||
// EditorGUI.indentLevel = oldIndent;
|
||||
//}
|
||||
|
||||
//editorUtils.Panel("MaskBaking", DrawMaskBaking, false);
|
||||
}
|
||||
|
||||
public static void DrawListElement(Rect rect, AutoSpawner listEntry, ref bool changesMade)
|
||||
{
|
||||
int oldIndent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
//EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width * 0.1f, EditorGUIUtility.singleLineHeight), m_editorUtils.GetContent("AutoSpawnerActive"));
|
||||
EditorGUI.BeginChangeCheck();
|
||||
listEntry.isActive = EditorGUI.Toggle(new Rect(rect.x, rect.y, 20, EditorGUIUtility.singleLineHeight), listEntry.isActive);
|
||||
//switch (listEntry.status)
|
||||
//{
|
||||
// case AutoSpawnerStatus.Spawning:
|
||||
// EditorGUI.LabelField(new Rect(rect.x + rect.width * 0.2f, rect.y, rect.width * 0.2f, EditorGUIUtility.singleLineHeight), String.Format("{0:f0}", listEntry.spawner.m_spawnProgress * 100));
|
||||
// break;
|
||||
// default:
|
||||
// EditorGUI.LabelField(new Rect(rect.x + rect.width * 0.2f, rect.y, rect.width * 0.2f, EditorGUIUtility.singleLineHeight), listEntry.status.ToString());
|
||||
// break;
|
||||
//}
|
||||
bool currentGUIState = GUI.enabled;
|
||||
GUI.enabled = listEntry.isActive;
|
||||
listEntry.spawner = (Spawner)EditorGUI.ObjectField(new Rect(rect.x + 20, rect.y, rect.width - 20, EditorGUIUtility.singleLineHeight), listEntry.spawner, typeof(Spawner), true);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
changesMade = true;
|
||||
}
|
||||
GUI.enabled = currentGUIState;
|
||||
EditorGUI.indentLevel = oldIndent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static GUIContent PropertyCount(string key, List<AutoSpawner> list, EditorUtils editorUtils)
|
||||
{
|
||||
GUIContent content = editorUtils.GetContent(key);
|
||||
content.text += " [" + list.Count + "]";
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d6633d4a76ffff4195b07958f018135
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,300 @@
|
||||
// Copyright © 2018 Procedural Worlds Pty Limited. All Rights Reserved.
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AnimatedValues;
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
|
||||
/*
|
||||
* Custom Editor for Sequence assets
|
||||
*/
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
//[CustomPropertyDrawer(typeof(StamperSettings.ClipData))]
|
||||
//public class StamperSettingsClipDataEditor : PropertyDrawer
|
||||
//{
|
||||
// public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
// {
|
||||
// return EditorGUIUtility.singleLineHeight;
|
||||
// }
|
||||
// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
// {
|
||||
// position.width -= 120f;
|
||||
// SerializedProperty clip = property.FindPropertyRelative("m_clip");
|
||||
// SerializedProperty volume = property.FindPropertyRelative("m_volume");
|
||||
// EditorGUI.ObjectField(position, clip, GUIContent.none);
|
||||
// position.xMin = position.xMax;
|
||||
// position.xMax += 120f;
|
||||
// EditorGUI.Slider(position, volume, 0f, 1f, GUIContent.none);
|
||||
// }
|
||||
//}
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(StamperSettings))]
|
||||
public class StamperSettingsEditor : PWEditor, IPWEditor
|
||||
{
|
||||
/// <summary> Reference to EditorUtils for GUI functions </summary>
|
||||
private EditorUtils m_editorUtils;
|
||||
|
||||
//Properties of Sequence asset
|
||||
SerializedProperty m_requirements;
|
||||
SerializedProperty m_clipData;
|
||||
SerializedProperty m_volume;
|
||||
SerializedProperty m_playbackSpeed;
|
||||
SerializedProperty m_randomizeOrder;
|
||||
SerializedProperty m_crossFade;
|
||||
SerializedProperty m_trackFadeTime;
|
||||
SerializedProperty m_volumeFadeTime;
|
||||
SerializedProperty m_playbackSpeedFadeTime;
|
||||
SerializedProperty m_delayChance;
|
||||
SerializedProperty m_delayFadeTime;
|
||||
SerializedProperty m_minMaxDelay;
|
||||
SerializedProperty m_valuesMix;
|
||||
SerializedProperty m_values;
|
||||
SerializedProperty m_eventsMix;
|
||||
SerializedProperty m_events;
|
||||
SerializedProperty m_randomVolume;
|
||||
SerializedProperty m_minMaxVolume;
|
||||
SerializedProperty m_randomPlaybackSpeed;
|
||||
SerializedProperty m_minMaxPlaybackSpeed;
|
||||
SerializedProperty m_modifiers;
|
||||
SerializedProperty m_outputType;
|
||||
SerializedProperty m_outputPrefab;
|
||||
SerializedProperty m_outputDirect;
|
||||
SerializedProperty m_outputDistance;
|
||||
SerializedProperty m_outputVerticalAngle;
|
||||
SerializedProperty m_outputHorizontalAngle;
|
||||
SerializedProperty m_syncGroup;
|
||||
SerializedProperty m_syncType;
|
||||
SerializedProperty m_eventsWhilePlaying;
|
||||
//SerializedProperty m_outputFollowPosition = null;
|
||||
//SerializedProperty m_outputFollowRotation = null;
|
||||
//SerializedProperty m_OnPlayClip = null;
|
||||
//SerializedProperty m_OnStopClip = null;
|
||||
|
||||
/// <summary> Animated Boolean for if Output Distance should be shown </summary>
|
||||
AnimBool outputGroup;
|
||||
/// <summary> Animated Boolean for if Sliders should be displayed </summary>
|
||||
AnimBool slidersGroup;
|
||||
/// <summary> Animated Boolean for if Events should be displayed </summary>
|
||||
AnimBool eventsGroup;
|
||||
/// <summary> Animated Boolean for if OutputDirect is true </summary>
|
||||
AnimBool directGroup;
|
||||
/// <summary> Animated Boolean for if we are in a SyncGroup </summary>
|
||||
AnimBool syncGroup;
|
||||
UnityEditorInternal.ReorderableList m_eventsReorderable;
|
||||
UnityEditorInternal.ReorderableList m_valuesReorderable;
|
||||
bool m_clipsExpanded = true;
|
||||
UnityEditorInternal.ReorderableList m_clipsReorderable;
|
||||
|
||||
UnityEditorInternal.ReorderableList m_modifiersReorderable;
|
||||
UnityEditorInternal.ReorderableList m_eventsWhilePlayingReorderable;
|
||||
|
||||
/// <summary> Destructor to release references </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (m_editorUtils != null)
|
||||
{
|
||||
m_editorUtils.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary> Constructor to set up references for editor </summary>
|
||||
void OnEnable()
|
||||
{
|
||||
m_clipData = serializedObject.FindProperty("m_clipData");
|
||||
m_volume = serializedObject.FindProperty("m_volume");
|
||||
m_playbackSpeed = serializedObject.FindProperty("m_playbackSpeed");
|
||||
m_randomizeOrder = serializedObject.FindProperty("m_randomizeOrder");
|
||||
m_crossFade = serializedObject.FindProperty("m_crossFade");
|
||||
m_trackFadeTime = serializedObject.FindProperty("m_trackFadeTime");
|
||||
m_volumeFadeTime = serializedObject.FindProperty("m_volumeFadeTime");
|
||||
m_playbackSpeedFadeTime = serializedObject.FindProperty("m_playbackSpeedFadeTime");
|
||||
|
||||
m_clipsReorderable = new UnityEditorInternal.ReorderableList(serializedObject, m_clipData, true, false, true, true);
|
||||
m_clipsReorderable.elementHeight = EditorGUIUtility.singleLineHeight;
|
||||
m_clipsReorderable.drawElementCallback = DrawClipElement;
|
||||
m_clipsReorderable.drawHeaderCallback = DrawClipHeader;
|
||||
m_clipsReorderable.onAddCallback = OnAddClip;
|
||||
|
||||
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
}
|
||||
|
||||
void OnAddClip(UnityEditorInternal.ReorderableList list)
|
||||
{
|
||||
int idx = m_clipData.arraySize;
|
||||
m_clipData.InsertArrayElementAtIndex(idx);
|
||||
if (idx == 0)
|
||||
m_clipData.GetArrayElementAtIndex(idx).FindPropertyRelative("m_volume").floatValue = 1f;
|
||||
}
|
||||
void DrawClipElement(Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
int oldIndent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUI.PropertyField(rect, m_clipData.GetArrayElementAtIndex(index), GUIContent.none);
|
||||
EditorGUI.indentLevel = oldIndent;
|
||||
}
|
||||
void DrawClipHeader(Rect rect)
|
||||
{
|
||||
int oldIndent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
rect.xMin += 8f;
|
||||
m_clipsExpanded = EditorGUI.Foldout(rect, m_clipsExpanded, PropertyCount("mClips", m_clipData), true);
|
||||
EditorGUI.indentLevel = oldIndent;
|
||||
}
|
||||
|
||||
/// <summary> Main GUI Function </summary>
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
// serializedObject.Update();
|
||||
|
||||
// m_editorUtils.Initialize(); // Do not remove this!
|
||||
// m_editorUtils.GUIHeader();
|
||||
// m_editorUtils.TitleNonLocalized(m_editorUtils.GetContent("SequenceDataHeader").text + serializedObject.targetObject.name);
|
||||
|
||||
// m_editorUtils.Panel("ClipsPanel", ClipsPanel, true);
|
||||
|
||||
// //m_editorUtils.GUIFooter();
|
||||
// serializedObject.ApplyModifiedProperties();
|
||||
//}
|
||||
}
|
||||
/// <summary> Panel to show "Clip" options of Sequence </summary>
|
||||
/// <param name="inlineHelp">Should help be displayed?</param>
|
||||
public void ClipsPanel(bool inlineHelp)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Rect clipsRect;
|
||||
if (m_clipsExpanded)
|
||||
{
|
||||
clipsRect = EditorGUILayout.GetControlRect(true, m_clipsReorderable.GetHeight());
|
||||
m_clipsReorderable.DoList(clipsRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
int oldIndent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 1;
|
||||
m_clipsExpanded = EditorGUILayout.Foldout(m_clipsExpanded, PropertyCount("mClips", m_clipData), true);
|
||||
clipsRect = GUILayoutUtility.GetLastRect();
|
||||
EditorGUI.indentLevel = oldIndent;
|
||||
}
|
||||
if (Event.current.type == EventType.DragUpdated)
|
||||
{
|
||||
bool isValid = false;
|
||||
for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i)
|
||||
if (DragAndDrop.objectReferences[i] is AudioClip)
|
||||
{
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
if (isValid)
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Link;
|
||||
else
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
|
||||
}
|
||||
else if (Event.current.type == EventType.DragPerform)
|
||||
{
|
||||
for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i)
|
||||
{
|
||||
if (!(DragAndDrop.objectReferences[i] is AudioClip))
|
||||
continue;
|
||||
int idx = m_clipData.arraySize;
|
||||
m_clipData.InsertArrayElementAtIndex(idx);
|
||||
SerializedProperty clipData = m_clipData.GetArrayElementAtIndex(idx);
|
||||
clipData.FindPropertyRelative("m_volume").floatValue = 1f;
|
||||
clipData.FindPropertyRelative("m_clip").objectReferenceValue = DragAndDrop.objectReferences[i];
|
||||
}
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
m_editorUtils.InlineHelp("mClips", inlineHelp);
|
||||
//PropertyCountField("mClips", true, m_clips, ((Sequence)target).m_clips.Length, inlineHelp);
|
||||
//int badClipCount = 0;
|
||||
//for (int x = 0; x < m_clipData.arraySize; ++x)
|
||||
//{
|
||||
// AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip;
|
||||
// if (clip != null)
|
||||
// {
|
||||
// if (clip.loadType != AudioClipLoadType.DecompressOnLoad)
|
||||
// {
|
||||
// ++badClipCount;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//if (badClipCount > 0)
|
||||
//{
|
||||
// EditorGUILayout.HelpBox(m_editorUtils.GetContent("InvalidClipMessage").text, MessageType.Warning, true);
|
||||
// if (m_editorUtils.ButtonRight("InvalidClipButton"))
|
||||
// {
|
||||
// GUIContent progressBarContent = m_editorUtils.GetContent("InvalidClipPopup");
|
||||
// for (int x = 0; x < m_clipData.arraySize; ++x)
|
||||
// {
|
||||
// AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip;
|
||||
// EditorUtility.DisplayProgressBar(progressBarContent.text, progressBarContent.tooltip + clip.name, x / (float)badClipCount);
|
||||
// if (clip != null)
|
||||
// {
|
||||
// if (clip.loadType != AudioClipLoadType.DecompressOnLoad)
|
||||
// {
|
||||
// AudioImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(clip)) as AudioImporter;
|
||||
// AudioImporterSampleSettings sampleSettings = importer.defaultSampleSettings;
|
||||
// sampleSettings.loadType = AudioClipLoadType.DecompressOnLoad;
|
||||
// importer.defaultSampleSettings = sampleSettings;
|
||||
// if (importer.ContainsSampleSettingsOverride("Standalone"))
|
||||
// {
|
||||
// sampleSettings = importer.GetOverrideSampleSettings("Standalone");
|
||||
// sampleSettings.loadType = AudioClipLoadType.DecompressOnLoad;
|
||||
// importer.SetOverrideSampleSettings("Standalone", sampleSettings);
|
||||
// }
|
||||
// importer.SaveAndReimport();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// EditorUtility.ClearProgressBar();
|
||||
// }
|
||||
//}
|
||||
|
||||
//m_editorUtils.PropertyField("mTrackFadeTime", m_trackFadeTime, inlineHelp);
|
||||
//if (m_trackFadeTime.floatValue < 0f)
|
||||
// m_trackFadeTime.floatValue = 0f;
|
||||
//m_editorUtils.PropertyField("mVolume", m_volume, inlineHelp);
|
||||
//m_editorUtils.PropertyField("mVolumeFadeTime", m_volumeFadeTime, inlineHelp);
|
||||
//if (m_volumeFadeTime.floatValue < 0f)
|
||||
// m_volumeFadeTime.floatValue = 0f;
|
||||
////EditorGUI.BeginDisabledGroup(syncGroup.target && ((SyncType)System.Enum.GetValues(typeof(SyncType)).GetValue(m_syncType.enumValueIndex) & SyncType.FIT) > 0);
|
||||
////{
|
||||
//// m_editorUtils.PropertyField("mPlaybackSpeed", m_playbackSpeed, inlineHelp);
|
||||
//// if (m_playbackSpeed.floatValue < 0f)
|
||||
//// m_playbackSpeed.floatValue = 0f;
|
||||
////}
|
||||
////EditorGUI.EndDisabledGroup();
|
||||
//EditorGUI.BeginDisabledGroup(syncGroup.target);
|
||||
//{
|
||||
// m_editorUtils.PropertyField("mPlaybackSpeedFadeTime", m_playbackSpeedFadeTime, inlineHelp);
|
||||
// if (m_playbackSpeedFadeTime.floatValue < 0f)
|
||||
// m_playbackSpeedFadeTime.floatValue = 0f;
|
||||
// m_editorUtils.PropertyField("mCrossFade", m_crossFade, inlineHelp);
|
||||
// if (m_crossFade.floatValue < 0f)
|
||||
// m_crossFade.floatValue = 0f;
|
||||
//}
|
||||
//EditorGUI.EndDisabledGroup();
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
/// <summary> Panel to display Output options </summary>
|
||||
/// <param name="inlineHelp">Should help be displayed?</param>
|
||||
|
||||
|
||||
private GUIContent PropertyCount(string key, SerializedProperty property)
|
||||
{
|
||||
GUIContent content = m_editorUtils.GetContent(key);
|
||||
content.text += " [" + property.arraySize + "]";
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c1325bdc2ae35d4283337daec61b386
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,114 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
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(WorldMap))]
|
||||
public class WorldMapEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
WorldMap m_worldMap;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_worldMap = (WorldMap)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_worldMap = (WorldMap)target;
|
||||
serializedObject.Update();
|
||||
|
||||
if (m_worldMap.m_worldMapTerrain == null)
|
||||
{
|
||||
m_editorUtils.Panel("CreateWorldMap", CreateWorldMap, true);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_editorUtils.Panel("CreateWorldMap", CreateWorldMap, false);
|
||||
m_editorUtils.Panel("EditWorldMap", DrawEditWorldMap, true);
|
||||
m_editorUtils.Panel("SyncHeightmap", DrawSyncHeightmap, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void CreateWorldMap(bool obj)
|
||||
{
|
||||
if (m_worldMap.m_worldMapTerrain == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("TerrainMissing"), MessageType.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("CreateTerrainInfo"), MessageType.Info);
|
||||
}
|
||||
m_worldMap.m_worldMapTileSize = (GaiaConstants.EnvironmentSize)m_editorUtils.EnumPopup("TileSize", m_worldMap.m_worldMapTileSize);
|
||||
m_worldMap.m_heightmapResolution = (GaiaConstants.HeightmapResolution)m_editorUtils.EnumPopup("HeightmapResolution", m_worldMap.m_heightmapResolution);
|
||||
if (m_editorUtils.ButtonAutoIndent("CreateTerrainButton"))
|
||||
{
|
||||
m_worldMap.CreateWorldMapTerrain();
|
||||
m_worldMap.LookAtWorldMap();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private void DrawEditWorldMap(bool obj)
|
||||
{
|
||||
if (m_editorUtils.Button("RandomTerrainGeneration"))
|
||||
{
|
||||
WorldMap.ShowWorldMapStampSpawner();
|
||||
}
|
||||
//if (m_editorUtils.Button("DefineWorldMapMasks"))
|
||||
//{
|
||||
// WorldMap.ShowWorldBiomeMasksSpawner();
|
||||
//}
|
||||
if (m_editorUtils.Button("StampWorldMap"))
|
||||
{
|
||||
GameObject stamperObj = WorldMap.GetOrCreateWorldMapStamper();
|
||||
#if UNITY_EDITOR
|
||||
Selection.activeGameObject = stamperObj;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void DrawSyncHeightmap(bool obj)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
if (m_editorUtils.Button("SyncWorldMapToTerrain"))
|
||||
{
|
||||
m_worldMap.SyncWorldMapToLocalMap();
|
||||
}
|
||||
if (m_editorUtils.Button("SyncTerrainToWorldMap"))
|
||||
{
|
||||
m_worldMap.SyncLocalMapToWorldMap();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06bf9c1cbdf1923499e25461bacf0e4f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
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(WorldMapStampToken))]
|
||||
public class WorldMapStampTokenEditor : PWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
WorldMapStampToken m_stampToken;
|
||||
|
||||
private GaiaSessionManager m_sessionManager;
|
||||
private GaiaSessionManager SessionManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_sessionManager == null)
|
||||
{
|
||||
m_sessionManager = GaiaSessionManager.GetSessionManager(false);
|
||||
}
|
||||
return m_sessionManager;
|
||||
}
|
||||
}
|
||||
|
||||
public EditorUtils EditorUtils { get => m_editorUtils; set => m_editorUtils = value; }
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_stampToken = (WorldMapStampToken)target;
|
||||
//Init editor utils
|
||||
if (EditorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
EditorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
|
||||
m_stampToken.ReloadLocalStamper();
|
||||
m_stampToken.ReloadWorldStamper();
|
||||
|
||||
m_stampToken.m_isSelected = true;
|
||||
m_stampToken.UpdateGizmoPos();
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
if (m_stampToken.m_syncedLocalStamper != null)
|
||||
{
|
||||
#if GAIA_PRO_PRESENT
|
||||
m_stampToken.m_syncedLocalStamper.TerrainLoader.m_isSelected = false;
|
||||
#endif
|
||||
}
|
||||
m_stampToken.m_isSelected = false;
|
||||
|
||||
if (m_stampToken.m_connectedStamperSettings != null)
|
||||
{
|
||||
m_stampToken.m_connectedStamperSettings.ClearImageMaskTextures();
|
||||
}
|
||||
m_stampToken.m_syncedLocalStamper.m_settings.ClearImageMaskTextures();
|
||||
m_stampToken.m_syncedLocalStamper.m_settings.ClearImageMaskTextures();
|
||||
}
|
||||
|
||||
private void OnSceneGUI()
|
||||
{
|
||||
if (m_stampToken.m_syncedLocalStamper != null)
|
||||
{
|
||||
Handles.BeginGUI();
|
||||
bool currentGUIState = GUI.enabled;
|
||||
if (!GaiaUtils.HasTerrains())
|
||||
{
|
||||
GUI.enabled = false;
|
||||
if (GUI.Button(new Rect(Screen.width - 275, Screen.height - 110, 250, 25), new GUIContent("Edit Stamp (Terrain not created yet!)","This Button allows you to edit the stamp on your actual terrain - it only becomes available after you export the terrain from the world designer.")))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUI.Button(new Rect(Screen.width - 275, Screen.height - 110, 250, 25), new GUIContent("Edit Stamp on Terrain", "This Button will close the world map view to edit the stamp on your actual terrain.")))
|
||||
{
|
||||
EditStamp();
|
||||
}
|
||||
}
|
||||
|
||||
GUI.enabled = currentGUIState;
|
||||
|
||||
if (GUI.Button(new Rect(Screen.width - 275, Screen.height - 75, 250, 25), new GUIContent("Return to World Designer","Closes the stamp preview to return to the World Designer.")))
|
||||
{
|
||||
TerrainLoaderManager.Instance.SwitchToWorldMap();
|
||||
GameObject worldmapObject = GaiaUtils.GetOrCreateWorldDesigner();
|
||||
Selection.activeObject = worldmapObject;
|
||||
}
|
||||
Handles.EndGUI();
|
||||
}
|
||||
|
||||
// dont render preview if this isnt a repaint. losing performance if we do
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Prefer to show the world map stamper
|
||||
if (TerrainLoaderManager.Instance.ShowWorldMapTerrain)
|
||||
{
|
||||
if (m_stampToken.m_syncedWorldMapStamper != null)
|
||||
{
|
||||
m_stampToken.SyncWorldMapStamper();
|
||||
m_stampToken.m_syncedWorldMapStamper.DrawStampPreview();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TerrainLoaderManager.Instance.ShowLocalTerrain)
|
||||
{
|
||||
if (m_stampToken.m_syncedLocalStamper != null)
|
||||
{
|
||||
m_stampToken.SyncLocalStamper(m_stampToken.m_syncedLocalStamper);
|
||||
m_stampToken.m_syncedLocalStamper.UpdateTerrainLoader();
|
||||
m_stampToken.m_syncedLocalStamper.DrawStampPreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void EditStamp()
|
||||
{
|
||||
TerrainLoaderManager.Instance.SwitchToLocalMap();
|
||||
if (GaiaUtils.HasDynamicLoadedTerrains())
|
||||
{
|
||||
Vector3Double origin = TerrainLoaderManager.Instance.GetOrigin();
|
||||
TerrainLoaderManager.Instance.SetOrigin(new Vector3Double(((m_stampToken.transform.position.x + origin.x) / TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize) , 0, ((m_stampToken.transform.position.z+ origin.z) / TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize)));
|
||||
//position the stamper at 0,Y,0 - we just shifted the origin to there, so we can set the stamper to origin.
|
||||
m_stampToken.m_syncedLocalStamper.transform.position = new Vector3(0f, m_stampToken.m_syncedLocalStamper.transform.position.y, 0f);
|
||||
m_stampToken.m_syncedLocalStamper.m_openedFromTerrainGenerator = true;
|
||||
}
|
||||
Selection.activeGameObject = m_stampToken.m_syncedLocalStamper.gameObject;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorUtils.Initialize(); // Do not remove this!
|
||||
m_stampToken = (WorldMapStampToken)target;
|
||||
serializedObject.Update();
|
||||
m_stampToken.SyncLocationToStamperSettings();
|
||||
m_stampToken.UpdateGizmoPos();
|
||||
m_editorUtils.Panel("StamperControls", DrawStamperControls, true);
|
||||
}
|
||||
|
||||
private void DrawStamperControls(bool helpEnabled)
|
||||
{
|
||||
//m_stampToken.m_previewOnWorldMap = m_editorUtils.Toggle("PreviewOnWorldMap", m_stampToken.m_previewOnWorldMap, helpEnabled);
|
||||
//m_stampToken.m_previewOnLocalMap = m_editorUtils.Toggle("PreviewOnLocalMap", m_stampToken.m_previewOnLocalMap, helpEnabled);
|
||||
bool currentGUIState = GUI.enabled;
|
||||
|
||||
if (!GaiaUtils.HasTerrains())
|
||||
{
|
||||
GUI.enabled = false;
|
||||
m_editorUtils.ButtonAutoIndent("EditStampDisabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_editorUtils.ButtonAutoIndent("EditStamp"))
|
||||
{
|
||||
if (m_stampToken.m_syncedLocalStamper != null)
|
||||
{
|
||||
EditStamp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUI.enabled = currentGUIState;
|
||||
|
||||
if (m_editorUtils.ButtonAutoIndent("ReturnToGenerator"))
|
||||
{
|
||||
WorldMap.ShowWorldMapStampSpawner();
|
||||
}
|
||||
|
||||
if (m_stampToken.m_previewOnLocalMap && m_stampToken.m_syncedLocalStamper == null)
|
||||
{
|
||||
Stamper stamper = WorldMapStampToken.GetOrCreateSyncedStamper(GaiaConstants.worldMapLocalStamper);
|
||||
//load settings and don't instantiate - the stamper should be able to modify thses settings on the local map if the user wishes to!
|
||||
m_stampToken.LoadStamperSettings(stamper, false);
|
||||
m_stampToken.m_syncedLocalStamper = stamper;
|
||||
stamper.UpdateMinMaxHeight();
|
||||
stamper.m_stampDirty = true;
|
||||
}
|
||||
|
||||
if (m_stampToken.m_previewOnWorldMap && m_stampToken.m_syncedWorldMapStamper == null)
|
||||
{
|
||||
Stamper stamper = WorldMapStampToken.GetOrCreateSyncedStamper(GaiaConstants.worldMapWorldStamper);
|
||||
|
||||
//load settings and instantiate - the stamper should not modify the settings as it is just a scaled preview on the world map
|
||||
m_stampToken.LoadStamperSettings(stamper, true);
|
||||
//important - stamper must be marked as world map stamper to work with the world map terrain!
|
||||
stamper.m_settings.m_isWorldmapStamper = true;
|
||||
stamper.UpdateMinMaxHeight();
|
||||
stamper.m_stampDirty = true;
|
||||
m_stampToken.m_syncedWorldMapStamper = stamper;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e2b2f69cfa9acf4d96e58d7d8ccb09a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,125 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary>
|
||||
/// Runtime stamper sample - the stamp to be loaded and stamped my be stored in the resources directory
|
||||
/// </summary>
|
||||
public class RuntimeStamper : MonoBehaviour
|
||||
{
|
||||
//Show the gui
|
||||
public bool m_showGUI = true;
|
||||
|
||||
//Show debug
|
||||
public bool m_showDebug = true;
|
||||
|
||||
//Resource to be used as a stamp
|
||||
public string m_stampAddress = @"Gaia/Stamps/RuggedHills 1810 4";
|
||||
|
||||
//Current progress
|
||||
public string m_currentProgress = "";
|
||||
|
||||
//Current position
|
||||
#pragma warning disable 649
|
||||
private Rect m_currentPosition;
|
||||
#pragma warning restore 649
|
||||
|
||||
//Stamper
|
||||
private Stamper m_stamper;
|
||||
|
||||
//Set things up for first time execution
|
||||
void Awake()
|
||||
{
|
||||
//Dimensions of current position
|
||||
m_currentPosition.height = 20f;
|
||||
m_currentPosition.width = 300f;
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
//Create the stamper
|
||||
CreateStamper();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void LateUpdate()
|
||||
{
|
||||
m_currentPosition.center = new Vector2(Screen.width / 2f, Screen.height - 20f);
|
||||
|
||||
if (m_stamper != null)
|
||||
{
|
||||
m_currentProgress = string.Format("Stamp progress: " + m_stamper.m_stampProgress.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//Display a GUI
|
||||
void OnGUI()
|
||||
{
|
||||
if (!m_showGUI)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_showGUI)
|
||||
{
|
||||
GUI.Label(m_currentPosition, m_currentProgress);
|
||||
}
|
||||
}
|
||||
|
||||
//Create a stamper
|
||||
void CreateStamper()
|
||||
{
|
||||
string path = m_stampAddress;
|
||||
path = path.Replace("\\", "/");
|
||||
|
||||
//Load the stamp
|
||||
TextAsset stamp = Resources.Load<TextAsset>(path);
|
||||
if (stamp == null)
|
||||
{
|
||||
m_currentProgress = "Failed to load stamp at " + path;
|
||||
if (m_showDebug)
|
||||
{
|
||||
Debug.Log(m_currentProgress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentProgress = "Loaded stamp at " + stamp.name;
|
||||
if (m_showDebug)
|
||||
{
|
||||
if (m_showDebug)
|
||||
{
|
||||
Debug.Log(m_currentProgress);
|
||||
}
|
||||
|
||||
GameObject stamper = new GameObject("Runtime Stamper");
|
||||
m_stamper = stamper.AddComponent<Stamper>();
|
||||
if (m_stamper.LoadRuntimeStamp(stamp) == true)
|
||||
{
|
||||
m_currentProgress = "Loaded Stamp";
|
||||
m_stamper.FlattenTerrain();
|
||||
m_stamper.FitToTerrain();
|
||||
m_stamper.m_settings.m_height = 6f;
|
||||
m_stamper.m_distanceMask = AnimationCurve.Linear(0f, 1f, 1f, 0f);
|
||||
m_stamper.m_settings.m_rotation = 0f;
|
||||
m_stamper.m_updateTimeAllowed = 1 / 15f;
|
||||
m_stamper.UpdateStamp();
|
||||
m_stamper.Stamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentProgress = "Failed to load stamp";
|
||||
}
|
||||
|
||||
if (m_showDebug)
|
||||
{
|
||||
Debug.Log(m_currentProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66f7687156e79c442ba262841c9312a2
|
||||
timeCreated: 1450840456
|
||||
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: 7a6de5e15bbf726429ed2f777b34dc8b
|
||||
timeCreated: 1431402328
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,237 @@
|
||||
// Copyright © 2018 Procedural Worlds Pty Limited. All Rights Reserved.
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
/*
|
||||
* Scriptable Object containing settings for a stamper
|
||||
*/
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
/// <summary> Contains information about a Sequence of clips to play and how </summary>
|
||||
[CreateAssetMenu(menuName = "Procedural Worlds/Gaia/Stamper Settings")]
|
||||
[System.Serializable]
|
||||
public class StamperSettings : ScriptableObject, ISerializationCallbackReceiver
|
||||
{
|
||||
|
||||
#region Public Variables
|
||||
|
||||
/// <summary>
|
||||
/// Stamp x location - done this way to expose in the editor as a simple slider
|
||||
/// </summary>
|
||||
public double m_x = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Stamp y location - done this way to expose in the editor as a simple slider
|
||||
/// </summary>
|
||||
public double m_y = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Stamp z location - done this way to expose in the editor as a simple slider
|
||||
/// </summary>
|
||||
public double m_z = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Are these stamper settings folded out when viewed in an editor?
|
||||
/// </summary>
|
||||
public bool m_isFoldedOut;
|
||||
|
||||
/// <summary>
|
||||
/// Stamp width - this is the horizontal scaling factor - applied to both x & z
|
||||
/// </summary>
|
||||
public float m_width = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// Stamp height - this is the vertical scaling factor
|
||||
/// </summary>
|
||||
public float m_height = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// The absolute added / subtracted height for add / subtract height operations
|
||||
/// </summary>
|
||||
public float m_absoluteHeightValue;
|
||||
|
||||
/// <summary>
|
||||
/// Stamp rotation
|
||||
/// </summary>
|
||||
public float m_rotation = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Is this stamper intended to be used on world map terrains?
|
||||
/// </summary>
|
||||
public bool m_isWorldmapStamper = false;
|
||||
|
||||
/// <summary>
|
||||
/// The current operation that the stamper will perform on the terrain when pressing the stamp button
|
||||
/// </summary>
|
||||
public GaiaConstants.FeatureOperation m_operation = GaiaConstants.FeatureOperation.RaiseHeight;
|
||||
|
||||
/// <summary>
|
||||
/// The ground / base level - value in 0..1 that determines where the base of the stamp is as a % pf overall stamp height.
|
||||
/// Initially loaded from scanned value stored in the stamp, but can be overridden.
|
||||
/// </summary>
|
||||
public float m_baseLevel = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to draw any portion of the stamp below the base level of the stamp
|
||||
/// </summary>
|
||||
public bool m_drawStampBase = true;
|
||||
|
||||
/// <summary>
|
||||
/// Should the base level adapt itself to the existing shape of the terrain?
|
||||
/// </summary>
|
||||
public bool m_adaptiveBase = false;
|
||||
|
||||
/// <summary>
|
||||
/// size of the increased features when using Effects>Contrast
|
||||
/// </summary>
|
||||
public float m_contrastFeatureSize = 10;
|
||||
|
||||
/// <summary>
|
||||
/// strength of the contrast effect when using Effects>Contrast
|
||||
/// </summary>
|
||||
public float m_contrastStrength = 2;
|
||||
|
||||
/// <summary>
|
||||
/// size of the features being included in a terrace when using Effects>Terraces
|
||||
/// </summary>
|
||||
public float m_terraceCount = 100f;
|
||||
|
||||
/// <summary>
|
||||
/// Added Jitter when using Effects>Terraces
|
||||
/// </summary>
|
||||
public float m_terraceJitterCount = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Bevel Amount when using Effects>Terraces
|
||||
/// </summary>
|
||||
public float m_terraceBevelAmountInterior;
|
||||
|
||||
/// <summary>
|
||||
/// Sharpness when using Effects>Sharpen Ridges
|
||||
/// </summary>
|
||||
public float m_sharpenRidgesMixStrength = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Erosion Amount when using Effects>Sharpen Ridges
|
||||
/// </summary>
|
||||
public float m_sharpenRidgesIterations = 16f;
|
||||
|
||||
public float m_powerOf;
|
||||
public float m_smoothVerticality = 0f;
|
||||
public float m_smoothBlurRadius = 10f;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A fixed Image masked used as input for some of the operations.
|
||||
/// </summary>
|
||||
public ImageMask m_stamperInputImageMask = new ImageMask();
|
||||
|
||||
/// <summary>
|
||||
/// The mix level of the stamp for the mix height operation.
|
||||
/// </summary>
|
||||
public float m_mixMidPoint = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// The strength of the mix height operation.
|
||||
/// </summary>
|
||||
public float m_mixHeightStrength = 0.5f;
|
||||
|
||||
public GaiaConstants.AutoSpawnerArea m_autoSpawnerArea = GaiaConstants.AutoSpawnerArea.Local;
|
||||
public GaiaConstants.AutoSpawnerArea m_autoMaskExportArea = GaiaConstants.AutoSpawnerArea.Local;
|
||||
|
||||
/// <summary>
|
||||
/// height transform curve when using Effects > Height Transform
|
||||
/// </summary>
|
||||
public AnimationCurve m_heightTransformCurve = ImageMask.NewAnimCurveStraightUpwards();
|
||||
|
||||
|
||||
#region Erosion Settings
|
||||
public float m_erosionSimScale = 0.5f;
|
||||
public float m_erosionHydroTimeDelta = 0.07f;
|
||||
public int m_erosionHydroIterations = 10;
|
||||
public float m_erosionThermalTimeDelta = 0.01f;
|
||||
public int m_erosionThermalIterations = 8;
|
||||
public int m_erosionThermalReposeAngle = 80;
|
||||
public float m_erosionPrecipRate = 0.5f;
|
||||
public float m_erosionEvaporationRate = 0.5f;
|
||||
public float m_erosionFlowRate = 0.5f;
|
||||
public float m_erosionSedimentCapacity = 0.5f;
|
||||
public float m_erosionSedimentDepositRate = 0.8f;
|
||||
public float m_erosionSedimentDissolveRate = 0.5f;
|
||||
public float m_erosionRiverBankDepositRate = 7.0f;
|
||||
public float m_erosionRiverBankDissolveRate = 5.0f;
|
||||
public float m_erosionRiverBedDepositRate = 5.0f;
|
||||
public float m_erosionRiverBedDissolveRate = 5.0f;
|
||||
#endregion
|
||||
|
||||
|
||||
//<summary>All image filters that are being applied in this stamping process</summary>
|
||||
public ImageMask[] m_imageMasks = new ImageMask[0];
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Removes References to Texture2Ds in Image masks. The image mask will still remember the GUID of that texture to load it when needed.
|
||||
/// Call this when you are "done" with the stamper settings to free up memory caused by these references.
|
||||
/// </summary>
|
||||
public void ClearImageMaskTextures()
|
||||
{
|
||||
m_stamperInputImageMask.FreeTextureReferences();
|
||||
if (m_imageMasks != null)
|
||||
{
|
||||
foreach (ImageMask im in m_imageMasks)
|
||||
{
|
||||
im.FreeTextureReferences();
|
||||
}
|
||||
}
|
||||
Resources.UnloadUnusedAssets();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearImageMaskTextures();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
#region Serialization
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
//if (m_clipData != null && m_clipData.Length > 0)
|
||||
//{
|
||||
// m_clipData = new ClipData[m_clips.Length];
|
||||
// for (int i = 0; i < m_clips.Length; ++i)
|
||||
// {
|
||||
// m_clipData[i] = new ClipData(m_clips[i], 1f);
|
||||
// }
|
||||
// m_clips = null;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the correct stamper scale for an add / subtract operation to add or subtract X meters from the terrain
|
||||
/// </summary>
|
||||
/// <param name="terrain">The terrain the stamp operation is being performed on</param>
|
||||
/// <param name="heightValueInMeter">The height value in meter that needs to be added or subtracted.</param>
|
||||
/// <returns></returns>
|
||||
public float GetStampScaleByMeter(Terrain terrain, float heightValueInMeter)
|
||||
{
|
||||
//exception for height = 0, we can't put 0 as y-scale on the stamper.
|
||||
if (heightValueInMeter == 0)
|
||||
{
|
||||
return 0.0000001f;
|
||||
}
|
||||
return Mathf.Lerp(0f, 50f, Mathf.InverseLerp(0f, terrain.terrainData.size.y, Mathf.Abs(heightValueInMeter)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac1e25b4c6f8f7749a44f2459af0eb7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,467 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
public class WorldMap : MonoBehaviour
|
||||
{
|
||||
public Terrain m_worldMapTerrain;
|
||||
public GaiaConstants.EnvironmentSize m_worldMapTileSize = GaiaConstants.EnvironmentSize.Is2048MetersSq;
|
||||
public GaiaConstants.HeightmapResolution m_heightmapResolution = GaiaConstants.HeightmapResolution._2049;
|
||||
WorldCreationSettings m_currentWorldCreationSettings;
|
||||
float m_localHeightmapRes = 1;
|
||||
float m_localTileSize = 0;
|
||||
|
||||
|
||||
public void CreateWorldMapTerrain()
|
||||
{
|
||||
//Remove old world map terrain, if any
|
||||
Terrain oldWMTerrain = TerrainHelper.GetWorldMapTerrain();
|
||||
if (oldWMTerrain != null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (EditorUtility.DisplayDialog("Delete old world map?", "You are about to create a new world map in this scene. This will delete the existing world map and the stamp tokens on it. This will only affect the small world map terrain, the actual full scene terrain tiles will not be removed. Continue?", "Continue", "Cancel"))
|
||||
{
|
||||
DestroyImmediate(oldWMTerrain.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
#else
|
||||
Destroy(oldWMTerrain.gameObject);
|
||||
#endif
|
||||
}
|
||||
|
||||
GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings();
|
||||
GaiaDefaults currentDefaults = gaiaSettings.m_currentDefaults;
|
||||
GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();
|
||||
|
||||
//Collect some info from the existing world, if any.
|
||||
|
||||
//We need the average height from the terrains to create the height of the worldmap accordingly in scale
|
||||
double averageHeight = currentDefaults.m_terrainHeight;
|
||||
//We need the heightmap resolution and terrain size stored in the session
|
||||
//To properly scale between world map and local map even when one of the two is not loaded at the moment
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (Terrain t in Terrain.activeTerrains)
|
||||
{
|
||||
averageHeight += t.terrainData.size.y;
|
||||
if (!TerrainHelper.IsWorldMapTerrain(t))
|
||||
{
|
||||
m_localHeightmapRes = t.terrainData.heightmapResolution;
|
||||
m_localTileSize = t.terrainData.size.x;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
//}
|
||||
//only calculate an average if there is at least one placeholder or terrain
|
||||
if (count > 0)
|
||||
{
|
||||
averageHeight /= count;
|
||||
}
|
||||
|
||||
|
||||
BoundsDouble bounds = new BoundsDouble();
|
||||
TerrainHelper.GetTerrainBounds(ref bounds);
|
||||
//Collect the new world settings for world creation
|
||||
WorldCreationSettings worldCreationSettings = ScriptableObject.CreateInstance<WorldCreationSettings>();
|
||||
worldCreationSettings.m_xTiles = 1;
|
||||
worldCreationSettings.m_zTiles = 1;
|
||||
worldCreationSettings.m_tileSize = (count > 0) ? Mathd.RoundToInt(bounds.size.x) : gaiaSettings.m_tilesX * currentDefaults.m_terrainSize;
|
||||
worldCreationSettings.m_tileHeight = currentDefaults.m_terrainHeight;
|
||||
worldCreationSettings.m_createInScene = false;
|
||||
worldCreationSettings.m_autoUnloadScenes = false;
|
||||
worldCreationSettings.m_applyFloatingPointFix = false;
|
||||
worldCreationSettings.m_applyFloatingPointFix = false;
|
||||
worldCreationSettings.m_centerOffset = Vector3.zero; //(count > 0) ? new Vector2Double(bounds.center.x + bounds.extents.x + worldCreationSettings.m_tileSize, bounds.center.z) : Vector2Double.zero;
|
||||
worldCreationSettings.m_isWorldMap = true;
|
||||
//clone defaults so we can inject our custom heightmap resolution for the worldmap
|
||||
GaiaDefaults clonedDefaults = Instantiate(currentDefaults);
|
||||
clonedDefaults.m_heightmapResolution = (int)m_heightmapResolution;
|
||||
|
||||
worldCreationSettings.m_gaiaDefaults = clonedDefaults;
|
||||
|
||||
m_currentWorldCreationSettings = worldCreationSettings;
|
||||
GaiaSessionManager.OnWorldCreated -= OnWorldMapCreate;
|
||||
GaiaSessionManager.OnWorldCreated += OnWorldMapCreate;
|
||||
GaiaSessionManager.CreateWorld(worldCreationSettings);
|
||||
}
|
||||
|
||||
public void OnWorldMapCreate()
|
||||
{
|
||||
m_worldMapTerrain = TerrainHelper.GetWorldMapTerrain();
|
||||
GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings();
|
||||
GaiaDefaults currentDefaults = gaiaSettings.m_currentDefaults;
|
||||
|
||||
TerrainLoaderManager.Instance.TerrainSceneStorage.m_hasWorldMap = true;
|
||||
|
||||
float worldheightmapRes = m_worldMapTerrain.terrainData.heightmapResolution / m_worldMapTerrain.terrainData.size.x;
|
||||
|
||||
BoundsDouble bounds = new BoundsDouble();
|
||||
TerrainHelper.GetTerrainBounds(ref bounds);
|
||||
if (bounds.size.x > 0)
|
||||
{
|
||||
TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize = (float)m_currentWorldCreationSettings.m_tileSize / (float)bounds.size.x;
|
||||
TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMapRelativeHeightmapPixels = (((float)bounds.size.x / m_localTileSize) * m_localHeightmapRes / m_localHeightmapRes);
|
||||
}
|
||||
else
|
||||
{
|
||||
//no bounds size means no real terrains (yet) - set these parameters according to the current settings/defaults then
|
||||
TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize = (float)m_currentWorldCreationSettings.m_tileSize / (gaiaSettings.m_tilesX * currentDefaults.m_terrainSize);
|
||||
TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMapRelativeHeightmapPixels = ((gaiaSettings.m_tilesX * currentDefaults.m_terrainSize) / currentDefaults.m_terrainSize) * currentDefaults.m_heightmapResolution / currentDefaults.m_heightmapResolution;
|
||||
}
|
||||
SyncLocalMapToWorldMap();
|
||||
ShowWorldMapStampSpawner();
|
||||
GaiaSessionManager.OnWorldCreated -= OnWorldMapCreate;
|
||||
}
|
||||
|
||||
public void DeactivateWorldMap()
|
||||
{
|
||||
foreach (Transform t in transform)
|
||||
{
|
||||
t.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ActivateWorldMap()
|
||||
{
|
||||
foreach (Transform t in transform)
|
||||
{
|
||||
t.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void LookAtWorldMap()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
//Adjust the scene view so you can see the terrain
|
||||
if (SceneView.lastActiveSceneView != null)
|
||||
{
|
||||
if (m_worldMapTerrain != null)
|
||||
{
|
||||
SceneView.lastActiveSceneView.LookAtDirect(new Vector3(m_worldMapTerrain.transform.position.x + (m_worldMapTerrain.terrainData.size.x / 2f), 300f, -1f * (m_worldMapTerrain.terrainData.size.x / 2f)), Quaternion.Euler(30f, 0f, 0f));
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Syncs the heightmap of the world map to the local terrain tiles, preserving correct height scale, heightmap resolution, etc.
|
||||
/// </summary>
|
||||
/// <param name="validLocalTerrainNames">A list of local terrain tile names that are valid to change for the sync operation. If the list is null, all tiles will be assumed valid.</param>
|
||||
public void SyncWorldMapToLocalMap(List<string> validLocalTerrainNames = null)
|
||||
{
|
||||
BoundsDouble bounds = new BoundsDouble();
|
||||
TerrainHelper.GetTerrainBounds(ref bounds);
|
||||
if (GaiaUtils.HasDynamicLoadedTerrains())
|
||||
{
|
||||
Action<Terrain> act = (t) => CopyWorldMapToLocalMap(bounds, t);
|
||||
GaiaUtils.CallFunctionOnDynamicLoadedTerrains(act, false, validLocalTerrainNames);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Terrain t in Terrain.activeTerrains)
|
||||
{
|
||||
if (t != m_worldMapTerrain)
|
||||
{
|
||||
if (validLocalTerrainNames == null || validLocalTerrainNames.Contains(t.name))
|
||||
{
|
||||
CopyWorldMapToLocalMap(bounds, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SyncLocalMapToWorldMap()
|
||||
{
|
||||
BoundsDouble bounds = new BoundsDouble();
|
||||
TerrainHelper.GetTerrainBounds(ref bounds);
|
||||
if (GaiaUtils.HasDynamicLoadedTerrains())
|
||||
{
|
||||
Action<Terrain> act = (t) => CopyLocalMapToWorldMap(bounds, t);
|
||||
GaiaUtils.CallFunctionOnDynamicLoadedTerrains(act, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Terrain t in Terrain.activeTerrains)
|
||||
{
|
||||
if (t != m_worldMapTerrain)
|
||||
{
|
||||
CopyLocalMapToWorldMap(bounds, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyWorldMapToLocalMap(BoundsDouble bounds, Terrain t)
|
||||
{
|
||||
//make sure we have a world map terrain first
|
||||
if (m_worldMapTerrain == null)
|
||||
{
|
||||
m_worldMapTerrain = TerrainHelper.GetWorldMapTerrain();
|
||||
}
|
||||
|
||||
if (m_worldMapTerrain == null)
|
||||
{
|
||||
Debug.LogError("Can't export world map to local terrains - world map terrain is missing!");
|
||||
return;
|
||||
}
|
||||
|
||||
RenderTexture chunkContent = RenderTexture.GetTemporary(t.terrainData.heightmapTexture.descriptor);
|
||||
//FilterMode oldFilterMode = m_worldMapTerrain.terrainData.heightmapTexture.filterMode;
|
||||
//m_worldMapTerrain.terrainData.heightmapTexture.filterMode = FilterMode.Trilinear;
|
||||
//t.terrainData.heightmapTexture.filterMode = FilterMode.Trilinear;
|
||||
//chunkContent.filterMode = FilterMode.Trilinear;
|
||||
int maxTilesX = Mathf.RoundToInt((float)bounds.size.x / t.terrainData.size.x);
|
||||
int maxTilesZ = Mathf.RoundToInt((float)bounds.size.z / t.terrainData.size.z);
|
||||
int currentTileX = Mathf.RoundToInt((t.transform.position.x - (float)bounds.min.x) / t.terrainData.size.x);
|
||||
int currentTileZ = Mathf.RoundToInt((t.transform.position.z - (float)bounds.min.z) / t.terrainData.size.z);
|
||||
float res = (t.terrainData.heightmapResolution) / ((float)bounds.size.x / t.terrainData.bounds.size.x * (t.terrainData.heightmapResolution-1));
|
||||
|
||||
|
||||
Bounds worldSpaceBounds = t.terrainData.bounds;
|
||||
worldSpaceBounds.center = new Vector3(worldSpaceBounds.center.x + t.transform.position.x, worldSpaceBounds.center.y + t.transform.position.y, worldSpaceBounds.center.z + t.transform.position.z);
|
||||
float xPos = ((float)currentTileX * t.terrainData.heightmapResolution) / (maxTilesX * t.terrainData.heightmapResolution);
|
||||
float zPos = ((float)currentTileZ * t.terrainData.heightmapResolution) / (maxTilesZ * t.terrainData.heightmapResolution);
|
||||
Vector2 pos = new Vector2(xPos, zPos);
|
||||
|
||||
|
||||
|
||||
Graphics.Blit(m_worldMapTerrain.terrainData.heightmapTexture, chunkContent, new Vector2(res, res), pos);
|
||||
//m_worldMapTerrain.terrainData.heightmapTexture.filterMode = oldFilterMode;
|
||||
RenderTexture previousRT = RenderTexture.active;
|
||||
RenderTexture.active = chunkContent;
|
||||
t.terrainData.CopyActiveRenderTextureToHeightmap(new RectInt(0, 0, t.terrainData.heightmapResolution, t.terrainData.heightmapResolution), new Vector2Int(0, 0), t.drawInstanced ? TerrainHeightmapSyncControl.None : TerrainHeightmapSyncControl.HeightOnly);
|
||||
RenderTexture.active = previousRT;
|
||||
t.terrainData.SyncHeightmap();
|
||||
t.editorRenderFlags = TerrainRenderFlags.All;
|
||||
|
||||
RenderTexture.ReleaseTemporary(chunkContent);
|
||||
chunkContent = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void CopyLocalMapToWorldMap(BoundsDouble bounds, Terrain t)
|
||||
{
|
||||
RenderTextureDescriptor rtDesc = t.terrainData.heightmapTexture.descriptor;
|
||||
rtDesc.width = Mathf.CeilToInt(m_worldMapTerrain.terrainData.heightmapResolution / ((float)bounds.size.x / t.terrainData.bounds.size.x));
|
||||
rtDesc.height = rtDesc.width;
|
||||
|
||||
RenderTexture chunkContent = RenderTexture.GetTemporary(rtDesc);
|
||||
float res = t.terrainData.heightmapResolution / rtDesc.width;
|
||||
|
||||
Bounds worldSpaceBounds = t.terrainData.bounds;
|
||||
worldSpaceBounds.center = new Vector3(worldSpaceBounds.center.x + t.transform.position.x, worldSpaceBounds.center.y + t.transform.position.y, worldSpaceBounds.center.z + t.transform.position.z);
|
||||
Vector2 pos = new Vector2(Mathf.InverseLerp(0, (float)bounds.size.x, Mathf.Abs((float)bounds.min.x - worldSpaceBounds.min.x)), Mathf.InverseLerp(0, (float)bounds.size.z, Mathf.Abs((float)bounds.min.z - worldSpaceBounds.min.z)));
|
||||
|
||||
Graphics.Blit(t.terrainData.heightmapTexture, chunkContent, new Vector2(1, 1), new Vector2(0, 0));
|
||||
|
||||
RenderTexture previousRT = RenderTexture.active;
|
||||
RenderTexture.active = chunkContent;
|
||||
m_worldMapTerrain.terrainData.CopyActiveRenderTextureToHeightmap(new RectInt(0, 0, rtDesc.width, rtDesc.height), new Vector2Int(Mathf.FloorToInt(pos.x * m_worldMapTerrain.terrainData.heightmapResolution), Mathf.FloorToInt(pos.y * m_worldMapTerrain.terrainData.heightmapResolution)), t.drawInstanced ? TerrainHeightmapSyncControl.None : TerrainHeightmapSyncControl.HeightOnly);
|
||||
RenderTexture.active = previousRT;
|
||||
m_worldMapTerrain.terrainData.SyncHeightmap();
|
||||
m_worldMapTerrain.editorRenderFlags = TerrainRenderFlags.All;
|
||||
|
||||
RenderTexture.ReleaseTemporary(chunkContent);
|
||||
chunkContent = null;
|
||||
|
||||
}
|
||||
|
||||
public static void ShowWorldMapStampSpawner()
|
||||
{
|
||||
|
||||
Terrain worldMapTerrain = TerrainHelper.GetWorldMapTerrain();
|
||||
|
||||
if (worldMapTerrain == null)
|
||||
{
|
||||
Debug.LogError("No world map created yet! Please create a world map first before opening the random terrain generator");
|
||||
return;
|
||||
}
|
||||
|
||||
GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false);
|
||||
|
||||
//Get the Gaia Settings
|
||||
GaiaSettings settings = GaiaUtils.GetGaiaSettings();
|
||||
|
||||
//Create or find the stamper
|
||||
GameObject spawnerObj = GaiaUtils.GetOrCreateWorldDesigner();
|
||||
Spawner spawner = spawnerObj.GetComponent<WorldDesigner>();
|
||||
if (spawner == null)
|
||||
{
|
||||
spawner = spawnerObj.AddComponent<WorldDesigner>();
|
||||
if (settings != null)
|
||||
{
|
||||
if (settings.m_defaultStampSpawnSettings != null)
|
||||
{
|
||||
spawner.LoadSettings(settings.m_defaultStampSpawnSettings);
|
||||
}
|
||||
}
|
||||
spawner.m_settings.m_isWorldmapSpawner = true;
|
||||
spawner.m_worldMapTerrain = worldMapTerrain;
|
||||
|
||||
//set up the export settings with the current Gaia Settings / defaults
|
||||
spawner.m_worldCreationSettings.m_targeSizePreset = settings.m_targeSizePreset;
|
||||
spawner.m_worldCreationSettings.m_xTiles = settings.m_tilesX;
|
||||
spawner.m_worldCreationSettings.m_zTiles = settings.m_tilesZ;
|
||||
spawner.m_worldTileSize = GaiaUtils.IntToEnvironmentSize(settings.m_currentDefaults.m_terrainSize);
|
||||
spawner.m_worldCreationSettings.m_tileSize = settings.m_currentDefaults.m_terrainSize;
|
||||
spawner.m_worldCreationSettings.m_tileHeight = settings.m_currentDefaults.m_terrainHeight;
|
||||
spawner.m_worldCreationSettings.m_createInScene = settings.m_createTerrainScenes;
|
||||
spawner.m_worldCreationSettings.m_autoUnloadScenes = settings.m_unloadTerrainScenes;
|
||||
spawner.m_worldCreationSettings.m_applyFloatingPointFix = settings.m_floatingPointFix;
|
||||
spawner.m_worldCreationSettings.m_qualityPreset = settings.m_currentEnvironment;
|
||||
if (spawner.m_worldCreationSettings.m_gaiaDefaults == null)
|
||||
{
|
||||
spawner.m_worldCreationSettings.m_gaiaDefaults = settings.m_currentDefaults;
|
||||
}
|
||||
|
||||
spawner.StoreWorldSize();
|
||||
//spawner.StoreHeightmapResolution();
|
||||
|
||||
//Check if we do have an existing terrain already, if yes, we would want to re-use it for the world map -> terrain export
|
||||
if (GaiaUtils.HasTerrains())
|
||||
{
|
||||
spawner.m_useExistingTerrainForWorldMapExport = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//No terrains yet - set up the terrain tiles in the session according to the current world creation settings
|
||||
//so that the stamp previews will come out right.
|
||||
TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesX = settings.m_tilesX;
|
||||
TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesZ = settings.m_tilesZ;
|
||||
|
||||
}
|
||||
|
||||
spawner.FitToTerrain();
|
||||
spawner.UpdateMinMaxHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
spawner.m_settings.m_isWorldmapSpawner = true;
|
||||
spawner.m_worldMapTerrain = worldMapTerrain;
|
||||
spawner.FitToTerrain();
|
||||
spawner.UpdateMinMaxHeight();
|
||||
}
|
||||
gsm.m_session.m_worldBiomeMaskSettings = spawner.m_settings;
|
||||
TerrainLoaderManager.Instance.SwitchToWorldMap();
|
||||
#if UNITY_EDITOR
|
||||
Selection.activeGameObject = spawnerObj;
|
||||
#endif
|
||||
}
|
||||
|
||||
// public static void ShowWorldBiomeMasksSpawner()
|
||||
// {
|
||||
|
||||
// Terrain worldMapTerrain = TerrainHelper.GetWorldMapTerrain();
|
||||
|
||||
// if (worldMapTerrain == null)
|
||||
// {
|
||||
// Debug.LogError("No world map created yet! Please create a world map first before opening the Biome Masks setup!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false);
|
||||
|
||||
// //Get the Gaia Settings
|
||||
// GaiaSettings settings = GaiaUtils.GetGaiaSettings();
|
||||
|
||||
// //Create or find the stamper
|
||||
// GameObject spawnerObj = GameObject.Find(GaiaConstants.worldBiomeMasks);
|
||||
// if (spawnerObj == null)
|
||||
// {
|
||||
// spawnerObj = new GameObject(GaiaConstants.worldBiomeMasks);
|
||||
// GameObject worldMapObj = GaiaUtils.GetOrCreateWorldDesigner();
|
||||
// spawnerObj.transform.parent = worldMapObj.transform;
|
||||
// Spawner spawner = spawnerObj.AddComponent<WorldBiomeMasks>();
|
||||
// //Existing settings for world mask biomes in session? -> Take those!
|
||||
// if (gsm.m_session.m_worldBiomeMaskSettings != null)
|
||||
// {
|
||||
// spawner.LoadSettings(gsm.m_session.m_worldBiomeMaskSettings);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //No session settings? Use default setup from Gaia settings then
|
||||
// if (settings != null)
|
||||
// {
|
||||
// if (settings.m_defaultBiomeMaskSettings != null)
|
||||
// {
|
||||
// spawner.LoadSettings(settings.m_defaultBiomeMaskSettings);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// spawner.m_settings.m_isWorldmapSpawner = true;
|
||||
// spawner.m_settings.m_worldmapSpawnerType = WorldmapSpawnerType.WorldBiomeMasks;
|
||||
// spawner.m_worldMapTerrain = worldMapTerrain;
|
||||
// spawner.FitToTerrain();
|
||||
// spawner.UpdateMinMaxHeight();
|
||||
// gsm.m_session.m_worldBiomeMaskSettings = spawner.m_settings;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Spawner spawner = spawnerObj.GetComponent<Spawner>();
|
||||
// spawner.m_settings.m_isWorldmapSpawner = true;
|
||||
// spawner.m_worldMapTerrain = worldMapTerrain;
|
||||
// spawner.FitToTerrain();
|
||||
// spawner.UpdateMinMaxHeight();
|
||||
// gsm.m_session.m_worldBiomeMaskSettings = spawner.m_settings;
|
||||
// }
|
||||
|
||||
// gsm.SwitchToWorldMap();
|
||||
//#if UNITY_EDITOR
|
||||
// Selection.activeGameObject = spawnerObj;
|
||||
//#endif
|
||||
// }
|
||||
|
||||
|
||||
public static GameObject GetOrCreateWorldMapStamper()
|
||||
{
|
||||
//Create or find the stamper
|
||||
GameObject stamperObj = GameObject.Find(GaiaConstants.worldMapStamper);
|
||||
if (stamperObj == null)
|
||||
{
|
||||
stamperObj = new GameObject(GaiaConstants.worldMapStamper);
|
||||
GameObject worldMapObj = GaiaUtils.GetOrCreateWorldDesigner();
|
||||
stamperObj.transform.parent = worldMapObj.transform;
|
||||
Stamper stamper = stamperObj.AddComponent<Stamper>();
|
||||
stamper.m_settings = ScriptableObject.CreateInstance<StamperSettings>();
|
||||
stamper.m_settings.m_isWorldmapStamper = true;
|
||||
stamper.m_recordUndo = false;
|
||||
stamper.UpdateMinMaxHeight();
|
||||
//stamper.m_seaLevel = m_settings.m_currentDefaults.m_seaLevel;
|
||||
stamper.FitToTerrain();
|
||||
}
|
||||
else
|
||||
{
|
||||
Stamper stamper = stamperObj.GetComponent<Stamper>();
|
||||
stamper.m_settings.m_isWorldmapStamper = true;
|
||||
stamper.m_recordUndo = false;
|
||||
stamper.UpdateMinMaxHeight();
|
||||
//stamper.m_seaLevel = m_settings.m_currentDefaults.m_seaLevel;
|
||||
stamper.FitToTerrain();
|
||||
}
|
||||
Terrain worldMapTerrain = TerrainHelper.GetWorldMapTerrain();
|
||||
if (worldMapTerrain != null)
|
||||
{
|
||||
stamperObj.transform.position = worldMapTerrain.transform.position + worldMapTerrain.terrainData.size / 2f;
|
||||
}
|
||||
return stamperObj;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac03f3492a295864eaf17f49a2ba05cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright © 2018 Procedural Worlds Pty Limited. All Rights Reserved.
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/*
|
||||
* Scriptable Object containing settings for a world map
|
||||
*/
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[System.Serializable]
|
||||
public class WorldMapSettings : ScriptableObject, ISerializationCallbackReceiver
|
||||
{
|
||||
|
||||
#region Public Variables
|
||||
|
||||
/// <summary>
|
||||
/// Stamp x location - done this way to expose in the editor as a simple slider
|
||||
/// </summary>
|
||||
public float m_x = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Stamp y location - done this way to expose in the editor as a simple slider
|
||||
/// </summary>
|
||||
public float m_y = 50f;
|
||||
|
||||
/// <summary>
|
||||
/// Stamp z location - done this way to expose in the editor as a simple slider
|
||||
/// </summary>
|
||||
public float m_z = 0f;
|
||||
#endregion
|
||||
|
||||
#region Serialization
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
//if (m_clipData != null && m_clipData.Length > 0)
|
||||
//{
|
||||
// m_clipData = new ClipData[m_clips.Length];
|
||||
// for (int i = 0; i < m_clips.Length; ++i)
|
||||
// {
|
||||
// m_clipData[i] = new ClipData(m_clips[i], 1f);
|
||||
// }
|
||||
// m_clips = null;
|
||||
//}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e048dd5bd582afa478495bc4694c091f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,257 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
|
||||
public class WorldMapStampToken : MonoBehaviour
|
||||
{
|
||||
public bool m_previewOnWorldMap = true;
|
||||
public bool m_previewOnLocalMap = true;
|
||||
public string m_featureType;
|
||||
public StamperSettings m_connectedStamperSettings;
|
||||
public bool m_isSelected;
|
||||
public Stamper m_syncedLocalStamper;
|
||||
public Stamper m_syncedWorldMapStamper;
|
||||
public Color m_gizmoColor = Color.white;
|
||||
|
||||
//store the position of the gizmo separatedly, needs still to be painted on the terrain when the stamp is located below
|
||||
private Vector3 m_gizmoPos;
|
||||
|
||||
private GaiaSessionManager m_sessionManager;
|
||||
private GaiaSessionManager SessionManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_sessionManager == null)
|
||||
{
|
||||
m_sessionManager = GaiaSessionManager.GetSessionManager(false);
|
||||
}
|
||||
return m_sessionManager;
|
||||
}
|
||||
}
|
||||
|
||||
private Terrain m_worldMapTerrain;
|
||||
|
||||
private Terrain WorldMapTerrain
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_worldMapTerrain == null)
|
||||
{
|
||||
m_worldMapTerrain = TerrainHelper.GetWorldMapTerrain();
|
||||
}
|
||||
return m_worldMapTerrain;
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (m_connectedStamperSettings != null)
|
||||
{
|
||||
m_connectedStamperSettings.ClearImageMaskTextures();
|
||||
}
|
||||
m_syncedLocalStamper.m_settings.ClearImageMaskTextures();
|
||||
m_syncedLocalStamper.m_settings.ClearImageMaskTextures();
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
//Only draw gizmos all over the world map when the random world generator or another stamp token is selected.
|
||||
if (Selection.activeGameObject!=null)
|
||||
{
|
||||
Spawner spawner = Selection.activeGameObject.GetComponent<Spawner>();
|
||||
WorldMapStampToken token = Selection.activeGameObject.GetComponent<WorldMapStampToken>();
|
||||
if (spawner != null || token != null)
|
||||
{
|
||||
if (token != null || spawner.m_settings.m_isWorldmapSpawner)
|
||||
{
|
||||
if (!m_isSelected || !m_previewOnWorldMap)
|
||||
{
|
||||
if (Camera.current != null && Vector3.Distance(transform.position, Camera.current.transform.position) < 10000)
|
||||
{
|
||||
Gizmos.color = m_gizmoColor;
|
||||
Gizmos.DrawSphere(m_gizmoPos, m_connectedStamperSettings.m_width /2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void UpdateGizmoPos()
|
||||
{
|
||||
float scalarX = Mathf.InverseLerp(0,WorldMapTerrain.terrainData.size.x, transform.position.x - WorldMapTerrain.transform.position.x);
|
||||
float scalarZ = Mathf.InverseLerp(0, WorldMapTerrain.terrainData.size.z, transform.position.z - WorldMapTerrain.transform.position.z);
|
||||
float sampledYPos = WorldMapTerrain.terrainData.GetInterpolatedHeight(scalarX,scalarZ);
|
||||
if (sampledYPos > transform.position.y)
|
||||
{
|
||||
m_gizmoPos = new Vector3(transform.position.x, sampledYPos, transform.position.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_gizmoPos = transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public void SyncLocationToStamperSettings()
|
||||
{
|
||||
Vector3 newPos = GetLocalStamperPosition();
|
||||
|
||||
m_connectedStamperSettings.m_x = newPos.x;
|
||||
m_connectedStamperSettings.m_z = newPos.z;
|
||||
m_connectedStamperSettings.m_y = newPos.y;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SyncLocationFromStamperSettings()
|
||||
{
|
||||
BoundsDouble b = new BoundsDouble();
|
||||
TerrainHelper.GetTerrainBounds(ref b);
|
||||
Transform worldmapTransform = transform.parent.parent;
|
||||
Terrain worldMapTerrain = worldmapTransform.GetComponent<Terrain>();
|
||||
//TODO: review if this needs to be in double precision
|
||||
|
||||
Vector3Double origin = TerrainLoaderManager.Instance.GetOrigin();
|
||||
|
||||
float relativeX = (float)(m_connectedStamperSettings.m_x - b.min.x + origin.x / TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize) / (float)b.size.x;
|
||||
float relativeY = (float)m_connectedStamperSettings.m_y * TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize;
|
||||
float relativeZ = (float)(m_connectedStamperSettings.m_z - b.min.z + origin.z / TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize) / (float)b.size.z;
|
||||
|
||||
//float relativeX = (float)(m_connectedStamperSettings.m_x - b.min.x) / (float)b.size.x;
|
||||
//float relativeY = (float) m_connectedStamperSettings.m_y * SessionManager.m_session.m_worldMaprelativeSize;
|
||||
//float relativeZ = (float)(m_connectedStamperSettings.m_z - b.min.z) / (float)b.size.z;
|
||||
|
||||
float newX = worldmapTransform.position.x + worldMapTerrain.terrainData.size.x * relativeX;
|
||||
float newZ = worldmapTransform.position.z + worldMapTerrain.terrainData.size.z * relativeZ;
|
||||
|
||||
transform.position = new Vector3(newX, relativeY, newZ);
|
||||
}
|
||||
|
||||
public void ReloadLocalStamper()
|
||||
{
|
||||
if (m_syncedLocalStamper != null)
|
||||
{
|
||||
#if GAIA_PRO_PRESENT
|
||||
m_syncedLocalStamper.TerrainLoader.m_isSelected = true;
|
||||
#endif
|
||||
LoadStamperSettings(m_syncedLocalStamper, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReloadWorldStamper()
|
||||
{
|
||||
if (m_syncedWorldMapStamper != null)
|
||||
{
|
||||
LoadStamperSettings(m_syncedWorldMapStamper, true);
|
||||
//important - stamper must be marked as world map stamper to work with the world map terrain!
|
||||
m_syncedWorldMapStamper.m_settings.m_isWorldmapStamper = true;
|
||||
m_syncedWorldMapStamper.m_stampDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void SyncLocalStamper(Stamper stamper)
|
||||
{
|
||||
stamper.transform.position = GetLocalStamperPosition();
|
||||
}
|
||||
|
||||
public void SyncWorldMapStamper()
|
||||
{
|
||||
if (m_syncedWorldMapStamper != null)
|
||||
{
|
||||
m_syncedWorldMapStamper.transform.position = transform.position;
|
||||
m_syncedWorldMapStamper.m_settings.m_width = m_connectedStamperSettings.m_width / TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesX;
|
||||
m_syncedWorldMapStamper.m_settings.m_height = m_connectedStamperSettings.m_height;
|
||||
m_syncedWorldMapStamper.transform.localScale = new Vector3(m_syncedWorldMapStamper.m_settings.m_width, m_syncedWorldMapStamper.m_settings.m_height, m_syncedWorldMapStamper.m_settings.m_width);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetLocalStamperPosition()
|
||||
{
|
||||
BoundsDouble b = new BoundsDouble();
|
||||
TerrainHelper.GetTerrainBounds(ref b);
|
||||
Transform worldmapTransform = transform.parent.parent;
|
||||
Terrain worldMapTerrain = worldmapTransform.GetComponent<Terrain>();
|
||||
float relativeX = (transform.position.x - worldmapTransform.position.x) / worldMapTerrain.terrainData.size.x;
|
||||
float relativeZ = (transform.position.z - worldmapTransform.position.z) / worldMapTerrain.terrainData.size.z;
|
||||
float relativeY = transform.position.y / TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize;
|
||||
|
||||
//TODO: Check if double precision required
|
||||
float newX = (float)b.min.x + (float)b.size.x * relativeX;
|
||||
float newZ = (float)b.min.z + (float)b.size.z * relativeZ;
|
||||
|
||||
return new Vector3(newX, relativeY, newZ);
|
||||
}
|
||||
|
||||
public static Stamper GetOrCreateSyncedStamper(string stamperName)
|
||||
{
|
||||
Stamper stamper = null;
|
||||
//No stamper passed in, does a session Stamper exist?
|
||||
if (stamper == null)
|
||||
{
|
||||
GameObject stamperObj = GameObject.Find(stamperName);
|
||||
if (stamperObj == null)
|
||||
{
|
||||
GameObject wmeTempTools = GaiaUtils.GetOrCreateWorldMapTempTools();
|
||||
stamperObj = new GameObject(stamperName);
|
||||
stamperObj.transform.parent = wmeTempTools.transform;
|
||||
}
|
||||
if (stamperObj.GetComponent<Stamper>() == null)
|
||||
{
|
||||
stamper = stamperObj.AddComponent<Stamper>();
|
||||
#if GAIA_PRO_PRESENT
|
||||
if (GaiaUtils.HasDynamicLoadedTerrains())
|
||||
{
|
||||
//We got placeholders, activate terrain loading
|
||||
stamper.m_loadTerrainMode = LoadMode.EditorSelected;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
stamper = stamperObj.GetComponent<Stamper>();
|
||||
}
|
||||
|
||||
return stamper;
|
||||
}
|
||||
|
||||
public void LoadStamperSettings(Stamper stamper, bool instantiateSettings)
|
||||
{
|
||||
stamper.LoadSettings(m_connectedStamperSettings, instantiateSettings);
|
||||
stamper.m_worldMapStampToken = this;
|
||||
#if GAIA_PRO_PRESENT
|
||||
if (GaiaUtils.HasDynamicLoadedTerrains())
|
||||
{
|
||||
//We got placeholders, activate terrain loading
|
||||
stamper.m_loadTerrainMode = LoadMode.EditorSelected;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void DrawWorldMapPreview()
|
||||
{
|
||||
if (m_syncedWorldMapStamper != null)
|
||||
{
|
||||
SyncWorldMapStamper();
|
||||
m_syncedWorldMapStamper.DrawStampPreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b824f690ac1078345a3235fb56071c55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user