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: d482b667a0c0a914f83089767158a560
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+425
@@ -0,0 +1,425 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Gaia.Internal;
|
||||
using PWCommon4;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
public class LocationManagerEditor : EditorWindow, IPWEditor
|
||||
{
|
||||
private EditorUtils m_editorUtils;
|
||||
private LocationSystem m_profile;
|
||||
private Vector2 scrollPosition;
|
||||
private GUIStyle m_boxStyle;
|
||||
|
||||
public bool PositionChecked { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Show Gaia Manager editor window
|
||||
/// </summary>
|
||||
public static void ShowLocationManager()
|
||||
{
|
||||
try
|
||||
{
|
||||
var manager = EditorWindow.GetWindow<Gaia.LocationManagerEditor>(false, "Location Manager");
|
||||
//Show manager if not null
|
||||
if (manager != null)
|
||||
{
|
||||
Vector2 initialSize = new Vector2(600f, 400f);
|
||||
manager.position = new Rect(new Vector2(Screen.currentResolution.width / 2f - initialSize.x / 2f, Screen.currentResolution.height / 2f - initialSize.y / 2f), initialSize);
|
||||
manager.Show();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.Message == "")
|
||||
{ }
|
||||
}
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
m_profile = GetLocationSystem();
|
||||
|
||||
if (m_editorUtils == null)
|
||||
{
|
||||
// Get editor utils for this
|
||||
m_editorUtils = PWApp.GetEditorUtils(this);
|
||||
}
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (GaiaUtils.CheckIfSceneProfileExists())
|
||||
{
|
||||
m_profile.m_locationProfile.m_currentControllerType = GaiaGlobal.Instance.SceneProfile.m_controllerType;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Setup on destroy
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
m_editorUtils?.Dispose();
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
//Initialization
|
||||
m_editorUtils.Initialize(); // Do not remove this!
|
||||
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height));
|
||||
|
||||
//Set up the box style
|
||||
if (m_boxStyle == null)
|
||||
{
|
||||
m_boxStyle = new GUIStyle(GUI.skin.box)
|
||||
{
|
||||
normal = {textColor = GUI.skin.label.normal.textColor},
|
||||
fontStyle = FontStyle.Bold,
|
||||
alignment = TextAnchor.UpperLeft
|
||||
};
|
||||
}
|
||||
|
||||
if (m_profile == null)
|
||||
{
|
||||
m_profile = GetLocationSystem();
|
||||
}
|
||||
|
||||
m_editorUtils.Panel("GlobalSettings", GlobalPanel, true);
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
private void GlobalPanel(bool helpEnabled)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (GaiaUtils.CheckIfSceneProfileExists())
|
||||
{
|
||||
if (m_profile.m_locationProfile.m_currentControllerType != GaiaGlobal.Instance.SceneProfile.m_controllerType)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("ControllerHasChanged"), MessageType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_profile == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Location manager allows you to track camera position at runtime and create bookmarks to load locations", MessageType.Info);
|
||||
if (m_editorUtils.Button("AddLocationManager"))
|
||||
{
|
||||
m_profile = AddLocationSystem();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
m_editorUtils.Panel("Setup", Setup);
|
||||
if (m_profile.m_locationProfile != null)
|
||||
{
|
||||
GUI.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
m_editorUtils.Panel("Controls", RuntimeControls);
|
||||
m_editorUtils.Panel("BookmarkSetup", BookmarkSetup, true);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorUtility.SetDirty(m_profile);
|
||||
if (m_profile.m_locationProfile != null)
|
||||
{
|
||||
EditorUtility.SetDirty(m_profile.m_locationProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void RuntimeControls(bool helpEnabled)
|
||||
{
|
||||
m_editorUtils.Heading("Controls");
|
||||
if (m_profile.m_locationProfile != null)
|
||||
{
|
||||
m_profile.m_locationProfile.m_mainKey = (KeyCode)m_editorUtils.EnumPopup("MasterKey", m_profile.m_locationProfile.m_mainKey, helpEnabled);
|
||||
m_profile.m_locationProfile.m_addBookmarkKey = (KeyCode)m_editorUtils.EnumPopup("AddNewBookmark", m_profile.m_locationProfile.m_addBookmarkKey, helpEnabled);
|
||||
m_profile.m_locationProfile.m_prevBookmark = (KeyCode)m_editorUtils.EnumPopup("PreviousBookmark", m_profile.m_locationProfile.m_prevBookmark, helpEnabled);
|
||||
m_profile.m_locationProfile.m_nextBookmark = (KeyCode)m_editorUtils.EnumPopup("NextBookmark", m_profile.m_locationProfile.m_nextBookmark, helpEnabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("No location profile provided. Please add one.", MessageType.Info);
|
||||
}
|
||||
}
|
||||
private void Setup(bool helpEnabled)
|
||||
{
|
||||
m_profile.m_locationProfile = (LocationSystemScriptableObject)m_editorUtils.ObjectField("LocationProfile", m_profile.m_locationProfile, typeof(LocationSystemScriptableObject), false, helpEnabled);
|
||||
if (m_profile.m_locationProfile == null)
|
||||
{
|
||||
m_profile.m_locationProfile = AssetDatabase.LoadAssetAtPath<LocationSystemScriptableObject>(GaiaUtils.GetAssetPath("Location Profile.asset"));
|
||||
}
|
||||
|
||||
if (m_profile.m_camera == null)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_profile.m_camera = (Transform)m_editorUtils.ObjectField("Camera", m_profile.m_camera, typeof(Transform), true, helpEnabled);
|
||||
if (m_editorUtils.Button("FindCamera", GUILayout.MaxWidth(50f)))
|
||||
{
|
||||
Camera locatedCam = GaiaUtils.GetCamera();
|
||||
if (locatedCam != null)
|
||||
{
|
||||
m_profile.m_camera = locatedCam.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("No camera could be found in your scene please add one from the GameObject/Camera in the top toolbar.");
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.HelpBox("A camera transform must be provided for Location Manager to work. You can press 'Find' button to quickly locate the camera in the scene.", MessageType.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_profile.m_camera = (Transform)m_editorUtils.ObjectField("Camera", m_profile.m_camera, typeof(Transform), true, helpEnabled);
|
||||
}
|
||||
|
||||
m_profile.m_player = (Transform)m_editorUtils.ObjectField("Player", m_profile.m_player, typeof(Transform), true, helpEnabled);
|
||||
|
||||
m_profile.m_trackPlayer = m_editorUtils.Toggle("TrackPlayer", m_profile.m_trackPlayer, helpEnabled);
|
||||
}
|
||||
private void BookmarkSetup(bool helpEnabled)
|
||||
{
|
||||
if (m_profile.m_locationProfile != null)
|
||||
{
|
||||
m_editorUtils.Heading("BookmarkSetup");
|
||||
m_profile.m_locationProfile.m_autoLoad = m_editorUtils.Toggle("AutoLoad", m_profile.m_locationProfile.m_autoLoad, helpEnabled);
|
||||
if (m_profile.m_locationProfile.m_bookmarkedLocationNames.Count > 0)
|
||||
{
|
||||
int selected = m_profile.m_selectedBookmark;
|
||||
for (int i = 0; i < m_profile.m_locationProfile.m_bookmarkedLocationNames.Count; i++)
|
||||
{
|
||||
if (m_profile.m_locationProfile.m_bookmarkedLocationNames[i] == m_profile.m_bookmarkName)
|
||||
{
|
||||
m_profile.m_bookmarkName = ObjectNames.GetUniqueName(m_profile.m_locationProfile.m_bookmarkedLocationNames.ToArray(), m_profile.m_bookmarkName);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_profile.m_bookmarkName = m_editorUtils.TextField("BookmarkName", m_profile.m_bookmarkName);
|
||||
if (m_editorUtils.Button("AddBookmark", GUILayout.MaxWidth(60f)))
|
||||
{
|
||||
m_profile.m_locationProfile.AddNewBookmark(m_profile);
|
||||
selected = m_profile.m_locationProfile.m_bookmarkedLocationNames.Count - 1;
|
||||
m_profile.m_selectedBookmark = m_profile.m_locationProfile.m_bookmarkedLocationNames.Count - 1;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
m_editorUtils.InlineHelp("BookmarkName", helpEnabled);
|
||||
|
||||
if (!m_profile.m_rename)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
selected = EditorGUILayout.Popup(new GUIContent(m_editorUtils.GetTextValue("SelectedBookmark"), m_editorUtils.GetTooltip("SelectedBookmark")), selected, m_profile.m_locationProfile.m_bookmarkedLocationNames.ToArray());
|
||||
if (selected != m_profile.m_selectedBookmark)
|
||||
{
|
||||
m_profile.m_selectedBookmark = selected;
|
||||
if (m_profile.m_locationProfile.m_autoLoad)
|
||||
{
|
||||
m_profile.m_locationProfile.LoadBookmark(m_profile);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_editorUtils.Button("Rename", GUILayout.MaxWidth(60f)))
|
||||
{
|
||||
m_profile.m_savedName = m_profile.m_locationProfile.m_bookmarkedLocationNames[m_profile.m_selectedBookmark];
|
||||
m_profile.m_rename = true;
|
||||
}
|
||||
|
||||
if (m_editorUtils.Button("Override", GUILayout.MaxWidth(60f)))
|
||||
{
|
||||
m_profile.m_locationProfile.OverrideBookmark(m_profile);
|
||||
}
|
||||
if (!m_profile.m_locationProfile.m_autoLoad)
|
||||
{
|
||||
if (m_editorUtils.Button("LoadBookmark", GUILayout.MaxWidth(60f)))
|
||||
{
|
||||
m_profile.m_locationProfile.LoadBookmark(m_profile);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
m_editorUtils.InlineHelp("SelectedBookmark", helpEnabled);
|
||||
if (m_profile.m_locationProfile.m_bookmarkedLocationNames.Count > 0)
|
||||
{
|
||||
EditorGUILayout.LabelField("Current Bookmark Controller Type Used: " + m_profile.m_locationProfile.m_bookmarkedSettings[selected].m_controllerUsed, EditorStyles.boldLabel);
|
||||
}
|
||||
|
||||
EditorGUILayout.LabelField("Current Bookmark Was Created In Scene: " + m_profile.m_locationProfile.m_bookmarkedSettings[selected].m_sceneName, EditorStyles.boldLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_profile.m_savedName = m_editorUtils.TextField("BookmarkRename", m_profile.m_savedName);
|
||||
if (m_editorUtils.Button("Save", GUILayout.MaxWidth(55f)))
|
||||
{
|
||||
m_profile.m_locationProfile.m_bookmarkedLocationNames[m_profile.m_selectedBookmark] = m_profile.m_savedName;
|
||||
m_profile.m_rename = false;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
m_editorUtils.InlineHelp("BookmarkRename", helpEnabled);
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (m_editorUtils.Button("RemoveBookmark"))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Removing Bookmark", "Are you sure you want to remove " + m_profile.m_locationProfile.m_bookmarkedLocationNames[selected] + " bookmark?", "Yes", "No"))
|
||||
{
|
||||
m_profile.m_locationProfile.RemoveBookmark(m_profile.m_selectedBookmark, m_profile);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_editorUtils.Button("RemoveAllBookmark"))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Removing All Bookmarks", "Are you sure you want to remove all the bookmarks?", "Yes", "No"))
|
||||
{
|
||||
m_profile.m_locationProfile.RemoveAllBookmarks();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_profile.m_selectedBookmark = 0;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_profile.m_bookmarkName = m_editorUtils.TextField("BookmarkName", m_profile.m_bookmarkName);
|
||||
if (m_editorUtils.Button("AddBookmark", GUILayout.MaxWidth(55f)))
|
||||
{
|
||||
m_profile.m_locationProfile.AddNewBookmark(m_profile);
|
||||
m_profile.m_selectedBookmark = m_profile.m_locationProfile.m_bookmarkedLocationNames.Count - 1;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.HelpBox("No bookmarks added to use bookmark features please press 'Add Bookmark'", MessageType.Info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("No location profile provided. Please add one.", MessageType.Info);
|
||||
}
|
||||
}
|
||||
private static LocationSystem GetLocationSystem()
|
||||
{
|
||||
LocationSystem locationSystem = FindObjectOfType<LocationSystem>();
|
||||
return locationSystem;
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds the system to the scene and sets it up
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static LocationSystem AddLocationSystem()
|
||||
{
|
||||
LocationSystem system = null;
|
||||
GameObject mainCam = GameObject.Find("Main Camera");
|
||||
if (mainCam != null)
|
||||
{
|
||||
system = mainCam.gameObject.GetComponent<LocationSystem>();
|
||||
if (system == null)
|
||||
{
|
||||
system = mainCam.gameObject.AddComponent<LocationSystem>();
|
||||
system.m_camera = mainCam.transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mainCam = GameObject.Find("Camera");
|
||||
if (mainCam != null)
|
||||
{
|
||||
system = mainCam.gameObject.GetComponent<LocationSystem>();
|
||||
if (system == null)
|
||||
{
|
||||
system = mainCam.gameObject.AddComponent<LocationSystem>();
|
||||
system.m_camera = mainCam.transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mainCam = GameObject.Find("FlyCam");
|
||||
if (mainCam != null)
|
||||
{
|
||||
system = mainCam.gameObject.GetComponent<LocationSystem>();
|
||||
if (system == null)
|
||||
{
|
||||
system = mainCam.gameObject.AddComponent<LocationSystem>();
|
||||
system.m_camera = mainCam.transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mainCam = GameObject.Find("FirstPersonCharacter");
|
||||
if (mainCam != null)
|
||||
{
|
||||
system = mainCam.gameObject.GetComponent<LocationSystem>();
|
||||
if (system == null)
|
||||
{
|
||||
system = mainCam.gameObject.AddComponent<LocationSystem>();
|
||||
system.m_camera = mainCam.transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mainCam = GameObject.FindGameObjectWithTag("MainCamera");
|
||||
if (mainCam != null)
|
||||
{
|
||||
system = mainCam.gameObject.GetComponent<LocationSystem>();
|
||||
if (system == null)
|
||||
{
|
||||
system = mainCam.gameObject.AddComponent<LocationSystem>();
|
||||
system.m_camera = mainCam.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GameObject firstPersonController = GameObject.Find("FPSController");
|
||||
if (firstPersonController != null)
|
||||
{
|
||||
if (system != null)
|
||||
{
|
||||
system.m_player = firstPersonController.transform;
|
||||
return system;
|
||||
}
|
||||
}
|
||||
GameObject thirdPersonController = GameObject.Find("ThirdPersonController");
|
||||
if (thirdPersonController != null)
|
||||
{
|
||||
if (system != null)
|
||||
{
|
||||
system.m_player = thirdPersonController.transform;
|
||||
return system;
|
||||
}
|
||||
}
|
||||
GameObject fpsController = GameObject.Find("Player");
|
||||
if (fpsController != null)
|
||||
{
|
||||
if (system != null)
|
||||
{
|
||||
system.m_player = fpsController.transform;
|
||||
return system;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the location system
|
||||
/// </summary>
|
||||
public static void RemoveLocationSystem()
|
||||
{
|
||||
LocationSystem system = GameObject.FindObjectOfType<LocationSystem>();
|
||||
if (system != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(system);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 255a81e4bcf277142b696133d9a8600f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[CustomEditor(typeof(LocationSystem))]
|
||||
public class LocationSystemEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("The location manager allows you to create bookmark locations to allow you to quickly jump from bookmark to bookmark to help navigate around the scene.", MessageType.Info);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Open Location Manager", "Opens the location manager window")))
|
||||
{
|
||||
LocationManagerEditor.ShowLocationManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6ba9ae158e06df47b1b72161b4fd7e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 914692587b938174fb90c1d420593b7d, type: 3}
|
||||
m_Name: Location Profile
|
||||
m_EditorClassIdentifier:
|
||||
m_savedCameraPosition: {x: 159.91113, y: 35.282097, z: 229.74411}
|
||||
m_savedCameraRotation: {x: 0.0010679468, y: 0.99893147, z: 0.03210823, w: -0.0332253}
|
||||
m_savedPlayerPosition: {x: 0, y: 0, z: 0}
|
||||
m_savedPlayerRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_hasBeenSaved: 0
|
||||
m_bookmarkedLocationNames: []
|
||||
m_bookmarkedSettings: []
|
||||
m_autoLoad: 1
|
||||
m_mainKey: 304
|
||||
m_addBookmarkKey: 98
|
||||
m_prevBookmark: 276
|
||||
m_nextBookmark: 275
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fe1b315b70710248ae17a5cd139c1fc
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class LocationSystem : MonoBehaviour
|
||||
{
|
||||
[HideInInspector]
|
||||
public LocationSystemScriptableObject m_locationProfile;
|
||||
[HideInInspector]
|
||||
public Transform m_camera;
|
||||
[HideInInspector]
|
||||
public Transform m_player;
|
||||
[HideInInspector]
|
||||
public bool m_trackPlayer = false;
|
||||
[HideInInspector]
|
||||
public LocationBookmarkSettings m_bookmarkSettings;
|
||||
[HideInInspector]
|
||||
public int m_selectedBookmark;
|
||||
[HideInInspector]
|
||||
public string m_bookmarkName = "My New Location Name";
|
||||
[HideInInspector]
|
||||
public bool m_rename = false;
|
||||
[HideInInspector]
|
||||
public string m_savedName;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Initilize();
|
||||
if (m_locationProfile == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_locationProfile.HasBeenSaved())
|
||||
{
|
||||
if (m_trackPlayer)
|
||||
{
|
||||
m_locationProfile.LoadLocation(m_camera, m_player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (m_camera == null || m_locationProfile == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_trackPlayer)
|
||||
{
|
||||
m_locationProfile.SaveLocation(m_camera, m_player);
|
||||
}
|
||||
|
||||
if (Input.GetKey(m_locationProfile.m_mainKey) && Input.GetKeyDown(m_locationProfile.m_prevBookmark))
|
||||
{
|
||||
m_selectedBookmark--;
|
||||
if (m_selectedBookmark < 0)
|
||||
{
|
||||
m_selectedBookmark = m_locationProfile.m_bookmarkedLocationNames.Count - 1;
|
||||
}
|
||||
|
||||
m_locationProfile.LoadBookmark(this);
|
||||
}
|
||||
|
||||
if (Input.GetKey(m_locationProfile.m_mainKey) && Input.GetKeyDown(m_locationProfile.m_nextBookmark))
|
||||
{
|
||||
m_selectedBookmark++;
|
||||
if (m_selectedBookmark > m_locationProfile.m_bookmarkedLocationNames.Count - 1)
|
||||
{
|
||||
m_selectedBookmark = 0;
|
||||
}
|
||||
|
||||
m_locationProfile.LoadBookmark(this);
|
||||
}
|
||||
|
||||
if (Input.GetKey(m_locationProfile.m_mainKey) && Input.GetKeyDown(m_locationProfile.m_addBookmarkKey))
|
||||
{
|
||||
LocationBookmarkSettings settings = LocationSystemScriptableObject.GetCurrentLocation(this);
|
||||
string name = "Bookmark " + " Position(" + settings.m_savedCameraPosition.x + ", " +
|
||||
settings.m_savedCameraPosition.y + ", " +
|
||||
settings.m_savedCameraPosition.z + ")";
|
||||
|
||||
m_locationProfile.AddNewBookmark(this, name);
|
||||
m_selectedBookmark = m_locationProfile.m_bookmarkedLocationNames.Count - 1;
|
||||
Debug.Log("New Bookmark: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Initilize()
|
||||
{
|
||||
if (m_locationProfile == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
m_locationProfile = UnityEditor.AssetDatabase.LoadAssetAtPath<LocationSystemScriptableObject>(GaiaUtils.GetAssetPath("Location Profile.asset"));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f31c048ddcf46df42bd7fd342231d47b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+402
@@ -0,0 +1,402 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Gaia
|
||||
{
|
||||
[System.Serializable]
|
||||
public class LocationBookmarkSettings
|
||||
{
|
||||
public Vector3 m_savedCameraPosition = Vector3.zero;
|
||||
public Quaternion m_savedCameraRotation = Quaternion.identity;
|
||||
public Vector3 m_savedPlayerPosition = Vector3.zero;
|
||||
public Quaternion m_savedPlayerRotation = Quaternion.identity;
|
||||
public string m_controllerUsed = "Not Been Set";
|
||||
public string m_sceneName = "Not Been Set";
|
||||
}
|
||||
|
||||
public class LocationSystemScriptableObject : ScriptableObject
|
||||
{
|
||||
[HideInInspector]
|
||||
public GaiaConstants.EnvironmentControllerType m_currentControllerType = GaiaConstants.EnvironmentControllerType.FlyingCamera;
|
||||
[HideInInspector]
|
||||
public Vector3 m_savedCameraPosition = Vector3.zero;
|
||||
[HideInInspector]
|
||||
public Quaternion m_savedCameraRotation = Quaternion.identity;
|
||||
[HideInInspector]
|
||||
public Vector3 m_savedPlayerPosition = Vector3.zero;
|
||||
[HideInInspector]
|
||||
public Quaternion m_savedPlayerRotation = Quaternion.identity;
|
||||
[HideInInspector]
|
||||
public bool m_hasBeenSaved = false;
|
||||
[HideInInspector]
|
||||
public List<string> m_bookmarkedLocationNames = new List<string>();
|
||||
//[HideInInspector]
|
||||
public List<LocationBookmarkSettings> m_bookmarkedSettings = new List<LocationBookmarkSettings>();
|
||||
[HideInInspector]
|
||||
public bool m_autoLoad = true;
|
||||
|
||||
[HideInInspector]
|
||||
public KeyCode m_mainKey = KeyCode.LeftShift;
|
||||
[HideInInspector]
|
||||
public KeyCode m_addBookmarkKey = KeyCode.B;
|
||||
[HideInInspector]
|
||||
public KeyCode m_prevBookmark = KeyCode.LeftArrow;
|
||||
[HideInInspector]
|
||||
public KeyCode m_nextBookmark = KeyCode.RightArrow;
|
||||
|
||||
public static GaiaSettings m_gaiaSettings;
|
||||
|
||||
public bool HasBeenSaved()
|
||||
{
|
||||
return m_hasBeenSaved;
|
||||
}
|
||||
|
||||
public void SaveLocation(Transform camera, Transform player = null)
|
||||
{
|
||||
if (camera == null)
|
||||
{
|
||||
Debug.LogError("No camera transform provided");
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
if (SceneView.lastActiveSceneView != null)
|
||||
{
|
||||
if (SceneView.lastActiveSceneView.camera == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
m_savedCameraPosition = camera.position;
|
||||
m_savedCameraRotation = camera.rotation;
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
m_savedPlayerPosition = player.position;
|
||||
m_savedPlayerRotation = player.rotation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
m_savedCameraPosition = SceneView.lastActiveSceneView.camera.transform.position;
|
||||
m_savedCameraRotation = SceneView.lastActiveSceneView.camera.transform.rotation;
|
||||
#endif
|
||||
}
|
||||
|
||||
m_hasBeenSaved = true;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.SetDirty(this);
|
||||
#endif
|
||||
}
|
||||
public void LoadLocation(Transform camera, Transform player = null)
|
||||
{
|
||||
if (camera == null)
|
||||
{
|
||||
Debug.LogError("No camera transform provided");
|
||||
return;
|
||||
}
|
||||
|
||||
camera.position = m_savedCameraPosition;
|
||||
camera.rotation = m_savedCameraRotation;
|
||||
if (player != null)
|
||||
{
|
||||
player.position = m_savedPlayerPosition;
|
||||
player.rotation = m_savedPlayerRotation;
|
||||
}
|
||||
|
||||
m_hasBeenSaved = false;
|
||||
}
|
||||
public void AddNewBookmark(LocationSystem locationSystem, string overrideName = null)
|
||||
{
|
||||
bool addBookmark = true;
|
||||
for (int i = 0; i < m_bookmarkedLocationNames.Count; i++)
|
||||
{
|
||||
if (overrideName != null)
|
||||
{
|
||||
if (m_bookmarkedLocationNames[i] == overrideName)
|
||||
{
|
||||
addBookmark = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_bookmarkedLocationNames[i] == locationSystem.m_bookmarkName)
|
||||
{
|
||||
addBookmark = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addBookmark)
|
||||
{
|
||||
if (overrideName != null)
|
||||
{
|
||||
m_bookmarkedLocationNames.Add(overrideName);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bookmarkedLocationNames.Add(locationSystem.m_bookmarkName);
|
||||
}
|
||||
|
||||
m_bookmarkedSettings.Add(GetCurrentLocation(locationSystem));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.SetDirty(locationSystem);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Location name " + locationSystem.m_bookmarkName + " already exists please change the name then add bookmark again.");
|
||||
}
|
||||
}
|
||||
public void OverrideBookmark(LocationSystem locationSystem)
|
||||
{
|
||||
if (locationSystem != null)
|
||||
{
|
||||
GaiaUtils.CopyFields(GetCurrentLocation(locationSystem), m_bookmarkedSettings[locationSystem.m_selectedBookmark]);
|
||||
}
|
||||
}
|
||||
public void RemoveAllBookmarks()
|
||||
{
|
||||
m_bookmarkedLocationNames.Clear();
|
||||
m_bookmarkedSettings.Clear();
|
||||
}
|
||||
public void RemoveBookmark(int index, LocationSystem locationSystem)
|
||||
{
|
||||
if (locationSystem.m_selectedBookmark == m_bookmarkedLocationNames.Count - 1)
|
||||
{
|
||||
locationSystem.m_selectedBookmark--;
|
||||
}
|
||||
m_bookmarkedLocationNames.RemoveAt(index);
|
||||
m_bookmarkedSettings.RemoveAt(index);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.SetDirty(locationSystem);
|
||||
#endif
|
||||
}
|
||||
public void LoadBookmark(LocationSystem locationSystem)
|
||||
{
|
||||
if (m_bookmarkedSettings.Count < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
LocationBookmarkSettings settings = m_bookmarkedSettings[locationSystem.m_selectedBookmark];
|
||||
if (settings != null)
|
||||
{
|
||||
if (locationSystem.m_camera != null)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (GaiaUtils.CheckIfSceneProfileExists())
|
||||
{
|
||||
if (settings.m_controllerUsed == GaiaConstants.EnvironmentControllerType.FirstPerson.ToString())
|
||||
{
|
||||
switch (GaiaGlobal.Instance.SceneProfile.m_controllerType)
|
||||
{
|
||||
case GaiaConstants.EnvironmentControllerType.FirstPerson:
|
||||
CharacterController controller = FindObjectOfType<CharacterController>();
|
||||
if (controller != null)
|
||||
{
|
||||
controller.enabled = false;
|
||||
locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
|
||||
}
|
||||
controller.enabled = true;
|
||||
}
|
||||
break;
|
||||
case GaiaConstants.EnvironmentControllerType.Custom:
|
||||
locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
|
||||
}
|
||||
break;
|
||||
case GaiaConstants.EnvironmentControllerType.FlyingCamera:
|
||||
locationSystem.m_camera.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
|
||||
}
|
||||
break;
|
||||
case GaiaConstants.EnvironmentControllerType.ThirdPerson:
|
||||
locationSystem.m_camera.SetPositionAndRotation(new Vector3(0f, 100f, 0f), settings.m_savedCameraRotation);
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (settings.m_controllerUsed == "Scene View (Editor)")
|
||||
{
|
||||
switch (GaiaGlobal.Instance.SceneProfile.m_controllerType)
|
||||
{
|
||||
case GaiaConstants.EnvironmentControllerType.FirstPerson:
|
||||
CharacterController controller = FindObjectOfType<CharacterController>();
|
||||
if (controller != null)
|
||||
{
|
||||
controller.enabled = false;
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
|
||||
}
|
||||
controller.enabled = true;
|
||||
}
|
||||
break;
|
||||
case GaiaConstants.EnvironmentControllerType.Custom:
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
|
||||
}
|
||||
break;
|
||||
case GaiaConstants.EnvironmentControllerType.FlyingCamera:
|
||||
locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
|
||||
}
|
||||
break;
|
||||
case GaiaConstants.EnvironmentControllerType.ThirdPerson:
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (SceneView.lastActiveSceneView != null)
|
||||
{
|
||||
if (SceneView.lastActiveSceneView.camera != null)
|
||||
{
|
||||
Camera target = SceneView.lastActiveSceneView.camera;
|
||||
Transform temp = target.transform;
|
||||
if (settings.m_controllerUsed == GaiaConstants.EnvironmentControllerType.FirstPerson.ToString())
|
||||
{
|
||||
temp.position = settings.m_savedPlayerPosition;
|
||||
temp.rotation = settings.m_savedPlayerRotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.position = settings.m_savedCameraPosition;
|
||||
temp.rotation = settings.m_savedCameraRotation;
|
||||
}
|
||||
|
||||
SceneView.lastActiveSceneView.AlignViewToObject(temp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static LocationBookmarkSettings GetCurrentLocation(LocationSystem locationSystem)
|
||||
{
|
||||
LocationBookmarkSettings settings = new LocationBookmarkSettings();
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (locationSystem.m_camera != null)
|
||||
{
|
||||
settings.m_savedCameraPosition = locationSystem.m_camera.localPosition;
|
||||
settings.m_savedCameraRotation = locationSystem.m_camera.localRotation;
|
||||
}
|
||||
|
||||
if (locationSystem.m_player != null)
|
||||
{
|
||||
settings.m_savedPlayerPosition = locationSystem.m_player.localPosition;
|
||||
settings.m_savedPlayerRotation = locationSystem.m_player.localRotation;
|
||||
}
|
||||
|
||||
if (GaiaUtils.CheckIfSceneProfileExists())
|
||||
{
|
||||
settings.m_controllerUsed = GaiaGlobal.Instance.SceneProfile.m_controllerType.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (SceneView.lastActiveSceneView != null)
|
||||
{
|
||||
if (SceneView.lastActiveSceneView.camera != null)
|
||||
{
|
||||
settings.m_savedCameraPosition = SceneView.lastActiveSceneView.camera.transform.localPosition;
|
||||
settings.m_savedCameraRotation = SceneView.lastActiveSceneView.camera.transform.localRotation;
|
||||
settings.m_controllerUsed = "Scene View (Editor)";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (SceneManager.GetActiveScene() != null)
|
||||
{
|
||||
settings.m_sceneName = SceneManager.GetActiveScene().name;
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.m_sceneName = "Untitled (Recommend Saving Your Scene Then Override This Bookmark)";
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
private static GaiaConstants.EnvironmentControllerType GetCharacterControllerType()
|
||||
{
|
||||
if (m_gaiaSettings == null)
|
||||
{
|
||||
m_gaiaSettings = GaiaUtils.GetGaiaSettings();
|
||||
}
|
||||
|
||||
if (m_gaiaSettings != null)
|
||||
{
|
||||
return m_gaiaSettings.m_currentController;
|
||||
}
|
||||
|
||||
return GaiaConstants.EnvironmentControllerType.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create sky profile asset
|
||||
/// </summary>
|
||||
#if UNITY_EDITOR
|
||||
[MenuItem("Assets/Create/Procedural Worlds/Gaia/Location Profile")]
|
||||
public static void CreateLocationProfiles()
|
||||
{
|
||||
LocationSystemScriptableObject asset = ScriptableObject.CreateInstance<LocationSystemScriptableObject>();
|
||||
AssetDatabase.CreateAsset(asset, "Assets/Location Profile.asset");
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = asset;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 914692587b938174fb90c1d420593b7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user