Mouse Bindings + Action Bar
Implemented mouse bindings for input screen Implemented action bar bindings for input screen
This commit is contained in:
parent
296a7f2958
commit
40c244190b
48 changed files with 538 additions and 93 deletions
|
|
@ -53,6 +53,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
public ActionMapping ActionMapping;
|
||||
public Rect ButtonRect;
|
||||
public UILineRenderer LabelLine;
|
||||
public bool IsActionBarButton;
|
||||
}
|
||||
|
||||
private class ActionMapping
|
||||
|
|
@ -71,13 +72,30 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
void Start()
|
||||
{
|
||||
_canvas = transform.root.GetComponent<Canvas>();
|
||||
var path = Path.Combine(ActionGameManager.GameDataDirectory.CreateSubdirectory("KeyboardLayouts").FullName, $"{LayoutFile.name}.msgpack");
|
||||
var path = Path.Combine(ActionGameManager.GameDataDirectory.CreateSubdirectory("KeyboardLayouts").FullName, $"{LayoutFile.name}.json");
|
||||
// _inputLayout = ParseJson(LayoutFile.text);
|
||||
RegisterResolver.Register();
|
||||
_inputLayout = MessagePackSerializer.Deserialize<InputLayout>(File.ReadAllBytes(path));
|
||||
//RegisterResolver.Register();
|
||||
//_inputLayout = MessagePackSerializer.Deserialize<InputLayout>(File.ReadAllBytes(path));
|
||||
_inputLayout = JsonConvert.DeserializeObject<InputLayout>(File.ReadAllText(path));
|
||||
DisplayLayout(_inputLayout);
|
||||
|
||||
_buttonMappings.Add(MapMouseButton(MouseLeft, "<Mouse>/leftButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseRight, "<Mouse>/rightButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseMiddle, "<Mouse>/middleButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseForward, "<Mouse>/forwardButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseBack, "<Mouse>/backButton"));
|
||||
|
||||
foreach (var buttonMapping in _buttonMappings) _bindButtons[buttonMapping.Button.InputSystemPath] = buttonMapping;
|
||||
|
||||
foreach(var actionBarInput in ActionGameManager.PlayerSettings.InputSettings.ActionBarInputs)
|
||||
{
|
||||
if (!_bindButtons.ContainsKey(actionBarInput)) Debug.LogError($"Unable to find input button for \"{actionBarInput}\"");
|
||||
else
|
||||
{
|
||||
_bindButtons[actionBarInput].IsActionBarButton = true;
|
||||
AssignColor(_bindButtons[actionBarInput]);
|
||||
}
|
||||
}
|
||||
|
||||
// foreach (var key in _inputLayout.GetBindableKeys())
|
||||
// {
|
||||
|
|
@ -121,6 +139,17 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
//StartCoroutine(AssociateInputKeys(_inputLayout));
|
||||
}
|
||||
|
||||
private ButtonMapping MapMouseButton(InputDisplayButton button, string path)
|
||||
{
|
||||
var mapping = new ButtonMapping
|
||||
{
|
||||
Button = new InputLayoutMouseButton {Path = path},
|
||||
DisplayButton = button
|
||||
};
|
||||
AssignUnboundColor(mapping.DisplayButton);
|
||||
return mapping;
|
||||
}
|
||||
|
||||
private void ProcessActions(InputActionAsset input)
|
||||
{
|
||||
var nonUIActions = input.Where(a => a.actionMap.name != "UI").ToArray();
|
||||
|
|
@ -150,7 +179,17 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
|
||||
private void AssignColor(ButtonMapping buttonMapping)
|
||||
{
|
||||
if(buttonMapping.ActionMapping!=null)
|
||||
if (buttonMapping.IsActionBarButton)
|
||||
{
|
||||
var outlineColor = Color.white;
|
||||
var fillColor = Color.white * FillBrightness;
|
||||
fillColor.a = FillAlpha;
|
||||
buttonMapping.DisplayButton.Fill.color = fillColor;
|
||||
buttonMapping.DisplayButton.Outline.gameObject.SetActive(true);
|
||||
buttonMapping.DisplayButton.Outline.color = outlineColor;
|
||||
if (buttonMapping.DisplayButton is InputDisplayKey key) key.MainLabel.color = key.AltLabel.color = outlineColor;
|
||||
}
|
||||
else if(buttonMapping.ActionMapping!=null)
|
||||
{
|
||||
var outlineColor = Color.HSVToRGB(buttonMapping.ActionMapping.Hue, Saturation, 1);
|
||||
var fillColor = Color.HSVToRGB(buttonMapping.ActionMapping.Hue, 1, FillBrightness);
|
||||
|
|
@ -250,7 +289,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
}
|
||||
|
||||
private Rect[] Overlap(Rect rect) => _buttonMappings
|
||||
.Where(b=>b.ActionMapping!=null)
|
||||
.Where(b=>b.IsActionBarButton || b.ActionMapping!=null)
|
||||
.Select(b=>b.ButtonRect)
|
||||
.Concat(_actionMappings
|
||||
.Where(a=>a.LabelRect.width > .1f)
|
||||
|
|
|
|||
8
Assets/Resources/Sprites/Input.meta
Normal file
8
Assets/Resources/Sprites/Input.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 81596aabf7563d043ad5247cd9b7276c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Samples.meta
Normal file
8
Assets/Samples.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d212fb3caec18e64b9b7b59d61fe2506
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Samples/Localization.meta
Normal file
8
Assets/Samples/Localization.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5a58b667f710c354ca97fb0a0e34d8a9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Samples/Localization/0.11.1-preview.meta
Normal file
8
Assets/Samples/Localization/0.11.1-preview.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 26575954ddf44b7468a03a25d56928d7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cbb240fb1c454114c826594aa01fe588
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"displayName": "Google Sheets",
|
||||
"description": "These samples show how String Table Collections can be pushed and pulled from one or more Google Sheets with custom data.",
|
||||
"createSeparatePackage": false
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9da122dbee2c7b74fa1443e2bf835bd2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using UnityEditor.Localization.Plugins.Google.Columns;
|
||||
using UnityEngine.Localization;
|
||||
using UnityEngine.Localization.Metadata;
|
||||
using UnityEngine.Localization.Tables;
|
||||
|
||||
namespace UnityEditor.Localization.Samples.Google
|
||||
{
|
||||
[Serializable]
|
||||
[DisplayName("Custom Data")]
|
||||
[Metadata(AllowedTypes = MetadataType.StringTableEntry)]
|
||||
public class MyCustomDataMetadata : IMetadata
|
||||
{
|
||||
public string someValue;
|
||||
public string someNoteValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LocaleMetadataColumn is a version of SheetColumn just for handling Metadata.
|
||||
/// This can now be added to the Column Mappings for any Push or Pull request.
|
||||
/// </summary>
|
||||
public class MyCustomColumn : LocaleMetadataColumn<MyCustomDataMetadata>
|
||||
{
|
||||
public override PushFields PushFields => PushFields.ValueAndNote; // For our example we use both value and note.
|
||||
|
||||
public override void PullMetadata(StringTableEntry entry, MyCustomDataMetadata metadata, string cellValue, string cellNote)
|
||||
{
|
||||
// Metadata will be null if the entry does not already contain any.
|
||||
if (metadata == null)
|
||||
{
|
||||
metadata = new MyCustomDataMetadata();
|
||||
entry.AddMetadata(metadata);
|
||||
}
|
||||
|
||||
metadata.someValue = cellValue;
|
||||
metadata.someNoteValue = cellNote;
|
||||
}
|
||||
|
||||
public override void PushHeader(StringTableCollection collection, out string header, out string headerNote)
|
||||
{
|
||||
// The title of the Google Sheet column
|
||||
header = "My Custom Data";
|
||||
headerNote = null;
|
||||
}
|
||||
|
||||
public override void PushMetadata(MyCustomDataMetadata metadata, out string value, out string note)
|
||||
{
|
||||
// Metadata will never be null as this is only called if the entry contains a metadata entry.
|
||||
value = metadata.someValue;
|
||||
note = metadata.someNoteValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d0765d08e4fd3554ebe929de5f151003
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,245 @@
|
|||
using System.Linq;
|
||||
using UnityEditor.Localization.Plugins.Google;
|
||||
using UnityEditor.Localization.Plugins.Google.Columns;
|
||||
using UnityEditor.Localization.Reporting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.Localization.Samples.Google
|
||||
{
|
||||
/// <summary>
|
||||
/// These examples show various ways to sync a String Table Collection with Google Sheets.
|
||||
/// These examples are illustrative and will not work as they are without correct Google Sheets credentials and String Table data.
|
||||
/// </summary>
|
||||
public class GoogleSheetsExamples
|
||||
{
|
||||
static SheetsServiceProvider GetServiceProvider()
|
||||
{
|
||||
// The Sheets service provider performs the authentication and keeps track of the
|
||||
// authentication tokens so that we do not need to authenticate each time.
|
||||
// It is recommended to have a SheetsServiceProvider asset pre-configured for
|
||||
// use however in this example we will create a new one.
|
||||
var sheetServiceProvider = ScriptableObject.CreateInstance<SheetsServiceProvider>();
|
||||
|
||||
// OAuth is required when making changes. See the docs for info setting up OAuth credentials.
|
||||
sheetServiceProvider.SetOAuthCrendtials("some-client-id", "some-client-secret");
|
||||
return sheetServiceProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// It is possible for a String Table Collection to exist over several Google Sheets, for example one per Locale.
|
||||
/// This example shows how you could push 1 of those Locales
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Push English")]
|
||||
public static void PushEnglish()
|
||||
{
|
||||
// Setup the connection to Google
|
||||
var sheetServiceProvider = GetServiceProvider();
|
||||
var googleSheets = new GoogleSheets(sheetServiceProvider);
|
||||
googleSheets.SpreadSheetId = "My spread sheet id"; // We need to provide the Spreadsheet id. This can be found in the url. See docs for further info.
|
||||
|
||||
// Prepare the data we want to push.
|
||||
// You should provide your String Table Collection name here
|
||||
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
|
||||
|
||||
// We need configure what each column will contain in the sheet
|
||||
var columnMappings = new SheetColumn[]
|
||||
{
|
||||
// Column A will contain the Key
|
||||
new KeyColumn { Column = "A" },
|
||||
|
||||
// Column B will contain any shared comments. These are Comment Metadata in the Shared category.
|
||||
new KeyCommentColumn { Column = "B" },
|
||||
|
||||
// Column C will contain the English Locale and any comments that are just for this Locale.
|
||||
new LocaleColumn { Column = "C", LocaleIdentifier = "en", IncludeComments = true },
|
||||
};
|
||||
|
||||
int mySheetId = 123456; // This it the id of the sheet in the Google Spreadsheet. it will be in the url after `gid=`.
|
||||
|
||||
// Now send the update.
|
||||
googleSheets.PushStringTableCollection(mySheetId, tableCollection, columnMappings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// It is possible for a String Table Collection to exist over several Google Sheets, for example one per Locale.
|
||||
/// This example shows how you could pull 1 of those Locales into a String Table Collection.
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Pull English")]
|
||||
public static void PullEnglish()
|
||||
{
|
||||
// Setup the connection to Google
|
||||
var sheetServiceProvider = GetServiceProvider();
|
||||
var googleSheets = new GoogleSheets(sheetServiceProvider);
|
||||
googleSheets.SpreadSheetId = "My spread sheet id"; // We need to provide the Spreadsheet id. This can be found in the url. See docs for further info.
|
||||
|
||||
// You should provide your String Table Collection name here
|
||||
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
|
||||
|
||||
// We need configure what each column contains in the sheet
|
||||
var columnMappings = new SheetColumn[]
|
||||
{
|
||||
// Column A contains the Key
|
||||
new KeyColumn { Column = "A" },
|
||||
|
||||
// Column B contains any shared comments. These are Comment Metadata in the Shared category.
|
||||
new KeyCommentColumn { Column = "B" },
|
||||
|
||||
// Column C contains the English Locale and any comments that are just for this Locale.
|
||||
new LocaleColumn { Column = "C", LocaleIdentifier = "en", IncludeComments = true },
|
||||
};
|
||||
|
||||
int mySheetId = 123456; // This it the id of the sheet in the Google Spreadsheet. it will be in the url after `gid=`.
|
||||
googleSheets.PullIntoStringTableCollection(mySheetId, tableCollection, columnMappings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This example shows how you can Push all the Locales in your project by using the ColumnMapper to generate the ColumnMapping data for you.
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Push Project Locales")]
|
||||
public static void PushProjectLocales()
|
||||
{
|
||||
// Setup the connection to Google
|
||||
var sheetServiceProvider = GetServiceProvider();
|
||||
var googleSheets = new GoogleSheets(sheetServiceProvider);
|
||||
googleSheets.SpreadSheetId = "My spread sheet id"; // We need to provide the Spreadsheet id. This can be found in the url. See docs for further info.
|
||||
|
||||
// Prepare the data we want to push.
|
||||
// You should provide your String Table Collection name here
|
||||
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
|
||||
|
||||
// CreateDefaultMapping will create a KeyColumn and a LocaleColumn for each Locale in the project.
|
||||
var columnMappings = ColumnMapping.CreateDefaultMapping();
|
||||
int mySheetId = 123456; // This it the id of the sheet in the Google Spreadsheet. it will be in the url after `gid=`.
|
||||
|
||||
// Now send the update. We can pass in an optional ProgressBarReporter so that we can see updates in the Editor.
|
||||
googleSheets.PushStringTableCollection(mySheetId, tableCollection, columnMappings, new ProgressBarReporter());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This example shows how you can Pull all the Locales in your project by using the ColumnMapper to generate the ColumnMapping data for you.
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Pull Project Locales")]
|
||||
public static void PullProjectLocales()
|
||||
{
|
||||
// Setup the connection to Google
|
||||
var sheetServiceProvider = GetServiceProvider();
|
||||
var googleSheets = new GoogleSheets(sheetServiceProvider);
|
||||
googleSheets.SpreadSheetId = "My spread sheet id"; // We need to provide the Spreadsheet id. This can be found in the url. See docs for further info.
|
||||
|
||||
// You should provide your String Table Collection name here
|
||||
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
|
||||
|
||||
// CreateDefaultMapping will create a KeyColumn and a LocaleColumn for each Locale in the project.
|
||||
// This assumes that the table was created and pushed to using the same column mappings.
|
||||
var columnMappings = ColumnMapping.CreateDefaultMapping();
|
||||
int mySheetId = 123456; // This it the id of the sheet in the Google Spreadsheet. it will be in the url after `gid=`.
|
||||
|
||||
// Now pull.
|
||||
// removeMissingEntries will remove any Keys that we have in the String Table Collection that do not exist in the Pull update.
|
||||
// reporter is an optional reporter that can be used to povide feedback in the editor during the Pull.
|
||||
googleSheets.PullIntoStringTableCollection(mySheetId, tableCollection, columnMappings, removeMissingEntries: true, reporter: new ProgressBarReporter());
|
||||
}
|
||||
|
||||
static void PushExtension(GoogleSheetsExtension googleExtension)
|
||||
{
|
||||
// Setup the connection to Google
|
||||
var googleSheets = new GoogleSheets(googleExtension.SheetsServiceProvider);
|
||||
googleSheets.SpreadSheetId = googleExtension.SpreadsheetId;
|
||||
|
||||
// Now send the update. We can pass in an optional ProgressBarReporter so that we can updates in the Editor.
|
||||
googleSheets.PushStringTableCollection(googleExtension.SheetId, googleExtension.TargetCollection as StringTableCollection, googleExtension.Columns, new ProgressBarReporter());
|
||||
}
|
||||
|
||||
static void PullExtension(GoogleSheetsExtension googleExtension)
|
||||
{
|
||||
// Setup the connection to Google
|
||||
var googleSheets = new GoogleSheets(googleExtension.SheetsServiceProvider);
|
||||
googleSheets.SpreadSheetId = googleExtension.SpreadsheetId;
|
||||
|
||||
// Now update the collection. We can pass in an optional ProgressBarReporter so that we can updates in the Editor.
|
||||
googleSheets.PullIntoStringTableCollection(googleExtension.SheetId, googleExtension.TargetCollection as StringTableCollection, googleExtension.Columns, reporter: new ProgressBarReporter());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// In this example we use the data that was configured in the Google Sheets extension to perform a Push.
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Push With Google Extension")]
|
||||
public static void PushWithExtension()
|
||||
{
|
||||
// You should provide your String Table Collection name here
|
||||
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
|
||||
var googleExtension = tableCollection.Extensions.FirstOrDefault(e => e is GoogleSheetsExtension) as GoogleSheetsExtension;
|
||||
if (googleExtension == null)
|
||||
{
|
||||
Debug.LogError($"String Table Collection {tableCollection.TableCollectionName} Does not contain a Google Sheets Extension.");
|
||||
return;
|
||||
}
|
||||
|
||||
PushExtension(googleExtension);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// In this example we use the data that was configured in the Google Sheets extension to perform a Pull.
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Pull With Google Extension")]
|
||||
public static void PullWithExtension()
|
||||
{
|
||||
// You should provide your String Table Collection name here
|
||||
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
|
||||
var googleExtension = tableCollection.Extensions.FirstOrDefault(e => e is GoogleSheetsExtension) as GoogleSheetsExtension;
|
||||
if (googleExtension == null)
|
||||
{
|
||||
Debug.LogError($"String Table Collection {tableCollection.TableCollectionName} Does not contain a Google Sheets Extension.");
|
||||
return;
|
||||
}
|
||||
|
||||
PullExtension(googleExtension);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This example shows how we can push every String Table Collection that contains a Google Sheets extension.
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Push All Google Sheets Extensions")]
|
||||
public static void PushAllExtensions()
|
||||
{
|
||||
// Get every String Table Collection
|
||||
var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
|
||||
|
||||
foreach (var collection in stringTableCollections)
|
||||
{
|
||||
// Its possible a String Table Collection may have more than one GoogleSheetsExtension.
|
||||
// For example if each Locale we pushed/pulled from a different sheet.
|
||||
foreach (var extension in collection.Extensions)
|
||||
{
|
||||
if (extension is GoogleSheetsExtension googleExtension)
|
||||
{
|
||||
PushExtension(googleExtension);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This example shows how we can push every String Table Collection that contains a Google Sheets extension.
|
||||
/// </summary>
|
||||
[MenuItem("Localization Samples/Google Sheets/Pull All Google Sheets Extensions")]
|
||||
public static void PullAllExtensions()
|
||||
{
|
||||
// Get every String Table Collection
|
||||
var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
|
||||
|
||||
foreach (var collection in stringTableCollections)
|
||||
{
|
||||
// Its possible a String Table Collection may have more than one GoogleSheetsExtension.
|
||||
// For example if each Locale we pushed/pulled from a different sheet.
|
||||
foreach (var extension in collection.Extensions)
|
||||
{
|
||||
if (extension is GoogleSheetsExtension googleExtension)
|
||||
{
|
||||
PullExtension(googleExtension);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8e27e36d32022f242a3738ca5165e2c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
using UnityEditor.Localization.Plugins.Google.Columns;
|
||||
using UnityEngine.Localization;
|
||||
using UnityEngine.Localization.Metadata;
|
||||
using UnityEngine.Localization.Tables;
|
||||
|
||||
namespace UnityEditor.Localization.Samples.Google
|
||||
{
|
||||
/// <summary>
|
||||
/// This is an example of how the Smart String property can be synchronized.
|
||||
/// Any value in the column will cause the value to be marked as smart and leaving the field empty will indicate it should not be smart.
|
||||
/// </summary>
|
||||
public class SmartStringColumn : LocaleMetadataColumn<SmartFormatTag>
|
||||
{
|
||||
public override PushFields PushFields => PushFields.Value;
|
||||
|
||||
public override void PullMetadata(StringTableEntry entry, SmartFormatTag metadata, string cellValue, string cellNote)
|
||||
{
|
||||
entry.IsSmart = !string.IsNullOrEmpty(cellValue);
|
||||
}
|
||||
|
||||
public override void PushHeader(StringTableCollection collection, out string header, out string headerNote)
|
||||
{
|
||||
header = $"{LocaleIdentifier.ToString()} - Is Smart String";
|
||||
headerNote = null;
|
||||
}
|
||||
|
||||
public override void PushMetadata(SmartFormatTag metadata, out string value, out string note)
|
||||
{
|
||||
value = "x"; // We mark here with an x but it could be anything.
|
||||
note = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1426cca1300da3b49896c46599354d6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -96,7 +96,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
get => _playerSettings ??= File.Exists(_playerSettingsFilePath)
|
||||
? MessagePackSerializer.Deserialize<PlayerSettings>(File.ReadAllBytes(_playerSettingsFilePath))
|
||||
: new PlayerSettings {Name = Environment.UserName};
|
||||
: GetDefaultPlayerSettings();
|
||||
}
|
||||
private static string _playerSettingsFilePath => Path.Combine(GameDataDirectory.FullName, "PlayerSettings.msgpack");
|
||||
public static void SavePlayerSettings()
|
||||
|
|
@ -104,6 +104,18 @@ public class ActionGameManager : MonoBehaviour
|
|||
File.WriteAllBytes(_playerSettingsFilePath, MessagePackSerializer.Serialize(_playerSettings));
|
||||
}
|
||||
|
||||
private static PlayerSettings GetDefaultPlayerSettings()
|
||||
{
|
||||
var settings = new PlayerSettings();
|
||||
settings.Name = Environment.UserName;
|
||||
settings.InputSettings.ActionBarInputs.Add("<Keyboard>/leftShift");
|
||||
settings.InputSettings.ActionBarInputs.Add("<Mouse>/leftButton");
|
||||
settings.InputSettings.ActionBarInputs.Add("<Mouse>/rightButton");
|
||||
settings.InputSettings.ActionBarInputs.Add("<Mouse>/middleButton");
|
||||
for (int i = 1; i < 6; i++) settings.InputSettings.ActionBarInputs.Add($"<Keyboard>/{i}");
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static Sector CurrentSector;
|
||||
public static bool IsTutorial;
|
||||
|
||||
|
|
@ -122,12 +134,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
public PostProcessVolume SevereHeatstrokePP;
|
||||
public PostProcessVolume SevereHypothermiaPP;
|
||||
|
||||
[Header("Input Icons")]
|
||||
public Sprite ShiftIcon;
|
||||
public Sprite MouseLeftIcon;
|
||||
public Sprite MouseRightIcon;
|
||||
public Sprite MouseMiddleIcon;
|
||||
|
||||
[Header("Scene Links")]
|
||||
public Transform ActionBar;
|
||||
public ActionBarSlot ActionBarSlot;
|
||||
|
|
@ -420,6 +426,19 @@ public class ActionGameManager : MonoBehaviour
|
|||
action.started += context => slot.Binding?.Activate();
|
||||
action.canceled += context => slot.Binding?.Deactivate();
|
||||
|
||||
var shortName = controlPath.Substring(controlPath.LastIndexOf('/') + 1);
|
||||
var sprite = Resources.Load<Sprite>($"Sprites/Input/{shortName}");
|
||||
if (sprite != null)
|
||||
{
|
||||
slot.InputIcon.sprite = sprite;
|
||||
slot.InputLabel.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.InputLabel.text = shortName;
|
||||
slot.InputIcon.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
slot.PointerEnterTrigger.OnPointerEnterAsObservable().Subscribe(_ =>
|
||||
{
|
||||
//Debug.Log($"Pointer entered action bar slot {controlPath}");
|
||||
|
|
@ -453,29 +472,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
return slot;
|
||||
}
|
||||
|
||||
var shift = createBinding("<Keyboard>/leftShift");
|
||||
shift.InputIcon.sprite = ShiftIcon;
|
||||
shift.InputLabel.gameObject.SetActive(false);
|
||||
|
||||
var left = createBinding("<Mouse>/leftButton");
|
||||
left.InputIcon.sprite = MouseLeftIcon;
|
||||
left.InputLabel.gameObject.SetActive(false);
|
||||
|
||||
var right = createBinding("<Mouse>/rightButton");
|
||||
right.InputIcon.sprite = MouseRightIcon;
|
||||
right.InputLabel.gameObject.SetActive(false);
|
||||
|
||||
var middle = createBinding("<Mouse>/middleButton");
|
||||
middle.InputIcon.sprite = MouseMiddleIcon;
|
||||
middle.InputLabel.gameObject.SetActive(false);
|
||||
foreach (var actionBarInput in PlayerSettings.InputSettings.ActionBarInputs) createBinding(actionBarInput);
|
||||
|
||||
for (int i = 1; i < 6; i++)
|
||||
{
|
||||
var num = createBinding($"<Keyboard>/{i}");
|
||||
num.InputIcon.gameObject.SetActive(false);
|
||||
num.InputLabel.text = i.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ public class PlayerSettings
|
|||
[Key(1)] public SavedGame SavedRun;
|
||||
[Key(2)] public bool TutorialPassed;
|
||||
[Key(3)] public Dictionary<string, string> HashedStoryFiles = new Dictionary<string, string>();
|
||||
[Key(4)] public PlayerGameplaySettings GameplaySettings;
|
||||
[Key(5)] public PlayerInputSettings InputSettings;
|
||||
[Key(4)] public PlayerGameplaySettings GameplaySettings = new PlayerGameplaySettings();
|
||||
[Key(5)] public PlayerInputSettings InputSettings = new PlayerInputSettings();
|
||||
|
||||
public string FormatTemperature(float t)
|
||||
{
|
||||
|
|
@ -19,7 +19,7 @@ public class PlayerSettings
|
|||
{
|
||||
TemperatureUnit.Kelvin => $"{Format(t)}°K",
|
||||
TemperatureUnit.Celsius => $"{Format(t - 273.15f)}°C",
|
||||
TemperatureUnit.Fahrenheit => $"{Format((t - 273.15f) * (9f / 5) + 32)}°F",
|
||||
TemperatureUnit.Fahrenheit => $"{Format(t * (9f / 5) - 459.67f)}°F",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
|
@ -58,5 +58,6 @@ public class PlayerGameplaySettings
|
|||
public class PlayerInputSettings
|
||||
{
|
||||
[Key(0)] public Dictionary<string, string> InputActionMap = new Dictionary<string, string>();
|
||||
[Key(1)] public bool FiveButtonMouse;
|
||||
[Key(1)] public List<string> ActionBarInputs = new List<string>();
|
||||
[Key(2)] public bool FiveButtonMouse;
|
||||
}
|
||||
Loading…
Reference in a new issue