Skip to content

Commit

Permalink
Merge pull request #56 from eviltwo/1.1.1-dev
Browse files Browse the repository at this point in the history
1.1.1 dev
  • Loading branch information
eviltwo committed Jul 24, 2024
2 parents aa9edc8 + 3668a29 commit 8b04a44
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 37 deletions.
4 changes: 4 additions & 0 deletions InputGlyphs/Assets/InputGlyphs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.1.1] - 2024-07-24
### Changed
- Changed the glyph image generation to use GlyphLayoutData struct instead of GlyphLayout.

## [1.1.0] - 2024-07-16
### Changed
- [GlyphLoader](https://github.com/eviltwo/UnitySteamInputGlyphLoader) package has been integrated into this package.
Expand Down
32 changes: 24 additions & 8 deletions InputGlyphs/Assets/InputGlyphs/Samples/DuoPlayerSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@ MonoBehaviour:
InputActionReferences:
- {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
- {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &275803797
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -694,7 +696,9 @@ MonoBehaviour:
SpriteRenderer: {fileID: 284746040}
PlayerInput: {fileID: 1837572673}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!212 &284746040
SpriteRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -795,7 +799,9 @@ MonoBehaviour:
SpriteRenderer: {fileID: 303118346}
PlayerInput: {fileID: 1847320111}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!212 &303118346
SpriteRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1009,7 +1015,9 @@ MonoBehaviour:
Image: {fileID: 456206386}
PlayerInput: {fileID: 1837572673}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!114 &456206386
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1861,7 +1869,9 @@ MonoBehaviour:
Image: {fileID: 1086219417}
PlayerInput: {fileID: 1837572673}
InputActionReference: {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!114 &1086219417
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2122,7 +2132,9 @@ MonoBehaviour:
Image: {fileID: 1347461810}
PlayerInput: {fileID: 1847320111}
InputActionReference: {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &1830157632
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2215,7 +2227,9 @@ MonoBehaviour:
Image: {fileID: 1830157634}
PlayerInput: {fileID: 1847320111}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &1837572672
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2413,7 +2427,9 @@ MonoBehaviour:
InputActionReferences:
- {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
- {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!114 &1878454138
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class InputCheckSample : MonoBehaviour
private List<InputControl> _controlBuffer = new List<InputControl>();
private List<InputDevice> _deviceBuffer = new List<InputDevice>();
private List<string> _pathBuffer = new List<string>();
private readonly GlyphsLayoutData _layoutData = new GlyphsLayoutData
{
Layout = GlyphsLayout.Horizontal,
MaxCount = 4,
};

private void Start()
{
Expand Down Expand Up @@ -51,7 +56,7 @@ private void DrawGlyphs(IReadOnlyList<InputControl> controls)
_pathBuffer.Add(control.path);
}

if (DisplayGlyphTextureGenerator.GenerateGlyphTexture(_texture, _deviceBuffer, _pathBuffer, GlyphsLayout.Horizontal))
if (DisplayGlyphTextureGenerator.GenerateGlyphTexture(_texture, _deviceBuffer, _pathBuffer, _layoutData))
{
Destroy(_spriteRenderer.sprite);
_spriteRenderer.sprite = Sprite.Create(_texture, new Rect(0, 0, _texture.width, _texture.height), new Vector2(0.5f, 0.5f), Mathf.Min(_texture.width, _texture.height));
Expand Down
20 changes: 15 additions & 5 deletions InputGlyphs/Assets/InputGlyphs/Samples/SoloPlayerSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ MonoBehaviour:
InputActionReferences:
- {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
- {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &275803797
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -692,7 +694,9 @@ MonoBehaviour:
SpriteRenderer: {fileID: 303118346}
PlayerInput: {fileID: 1847320111}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!212 &303118346
SpriteRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1172,7 +1176,9 @@ MonoBehaviour:
InputActionReferences:
- {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
- {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &933883783
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1624,7 +1630,9 @@ MonoBehaviour:
Image: {fileID: 1347461810}
PlayerInput: {fileID: 1847320111}
InputActionReference: {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &1830157632
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1717,7 +1725,9 @@ MonoBehaviour:
Image: {fileID: 1830157634}
PlayerInput: {fileID: 1847320111}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &1847320110
GameObject:
m_ObjectHideFlags: 0
Expand Down
16 changes: 12 additions & 4 deletions InputGlyphs/Assets/InputGlyphs/Samples/SteamworksSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ MonoBehaviour:
InputActionReferences:
- {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
- {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!114 &278394324
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -552,7 +554,9 @@ MonoBehaviour:
SpriteRenderer: {fileID: 643438429}
PlayerInput: {fileID: 1795501703}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!212 &643438429
SpriteRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -882,7 +886,9 @@ MonoBehaviour:
Image: {fileID: 989226477}
PlayerInput: {fileID: 1795501703}
InputActionReference: {fileID: -6609880655223600665, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!1 &1411641333
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1401,7 +1407,9 @@ MonoBehaviour:
Image: {fileID: 1576210592}
PlayerInput: {fileID: 1795501703}
InputActionReference: {fileID: 1942945179757384036, guid: 1b9bb0cc544975040b6fa735b8e5fcf7, type: 3}
GlyphsLayout: 2
GlyphsLayoutData:
Layout: 2
MaxCount: 4
--- !u!114 &1576210592
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using UnityEditor;
using UnityEngine;

namespace InputGlyphs.Display.Editor
{
[CustomPropertyDrawer(typeof(GlyphsLayoutData))]
public class GlyphsLayoutDataDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
using (new EditorGUI.PropertyScope(position, label, property))
{
var rect = position;
rect.height = EditorGUIUtility.singleLineHeight;

var layoutProperty = property.FindPropertyRelative(nameof(GlyphsLayoutData.Layout));
EditorGUI.PropertyField(rect, layoutProperty, new GUIContent($"Glyphs {layoutProperty.displayName}"));
rect.y += EditorGUIUtility.singleLineHeight;

var layout = (GlyphsLayout)layoutProperty.intValue;
if (layout == GlyphsLayout.Horizontal)
{
var maxCountProperty = property.FindPropertyRelative(nameof(GlyphsLayoutData.MaxCount));
EditorGUI.PropertyField(rect, maxCountProperty, new GUIContent($"Glyphs {maxCountProperty.displayName}"));
}
}
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var layoutProperty = property.FindPropertyRelative(nameof(GlyphsLayoutData.Layout));
var layout = (GlyphsLayout)layoutProperty.intValue;
var lineCount = layout == GlyphsLayout.Horizontal ? 2 : 1;
return EditorGUIUtility.singleLineHeight * lineCount;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class DisplayGlyphTextureGenerator
/// <summary>
/// Generates glyph texture for the specified inputLayoutPaths and writes it to the texture. The glyph textures are arranged according to the layout.
/// </summary>
public static bool GenerateGlyphTexture(Texture2D texture, IReadOnlyList<InputDevice> activeDevices, IReadOnlyList<string> inputLayoutPaths, GlyphsLayout layout)
public static bool GenerateGlyphTexture(Texture2D texture, IReadOnlyList<InputDevice> activeDevices, IReadOnlyList<string> inputLayoutPaths, GlyphsLayoutData layoutData)
{
if (texture == null)
{
Expand All @@ -29,13 +29,13 @@ public static bool GenerateGlyphTexture(Texture2D texture, IReadOnlyList<InputDe
return false;
}

if (inputLayoutPaths.Count == 1 || layout == GlyphsLayout.Single)
if (layoutData.Layout == GlyphsLayout.Single)
{
return GenerateSingleGlyphTexture(texture, activeDevices, inputLayoutPaths);
}
else
{
return GenerateMultipleGlyphsTexture(texture, activeDevices, inputLayoutPaths);
return GenerateMultipleGlyphsTexture(texture, activeDevices, inputLayoutPaths, layoutData.MaxCount);
}
}

Expand All @@ -52,15 +52,26 @@ private static bool GenerateSingleGlyphTexture(Texture2D texture, IReadOnlyList<
return false;
}

private static bool GenerateMultipleGlyphsTexture(Texture2D texture, IReadOnlyList<InputDevice> activeDevices, IReadOnlyList<string> inputLayoutPaths)
private static bool GenerateMultipleGlyphsTexture(Texture2D texture, IReadOnlyList<InputDevice> activeDevices, IReadOnlyList<string> inputLayoutPaths, int maxCount)
{
if (inputLayoutPaths.Count == 1)
{
return GenerateSingleGlyphTexture(texture, activeDevices, inputLayoutPaths);
}

_textureBuffer.Clear();
var loadedCount = 0;
for (int i = 0; i < inputLayoutPaths.Count; i++)
{
var texTemp = new Texture2D(2, 2);
if (InputGlyphManager.LoadGlyph(texTemp, activeDevices, inputLayoutPaths[i]))
{
_textureBuffer.Add(texTemp);
loadedCount++;
if (loadedCount >= maxCount)
{
break;
}
}
else
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace InputGlyphs.Display
{
[Serializable]
public struct GlyphsLayoutData
{
public GlyphsLayout Layout;
public int MaxCount;

public static GlyphsLayoutData Default => new GlyphsLayoutData
{
Layout = GlyphsLayout.Horizontal,
MaxCount = 4,
};
}

public enum GlyphsLayout
{
Single = 1,
Horizontal = 2,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class InputGlyphSprite : MonoBehaviour
public InputActionReference InputActionReference = null;

[SerializeField]
public GlyphsLayout GlyphsLayout = GlyphsLayout.Horizontal;
public GlyphsLayoutData GlyphsLayoutData = GlyphsLayoutData.Default;

private PlayerInput _lastPlayerInput;
private List<string> _pathBuffer = new List<string>();
Expand Down Expand Up @@ -138,7 +138,7 @@ private void UpdateGlyphs(PlayerInput playerInput)

if (InputLayoutPathUtility.TryGetActionBindingPath(InputActionReference?.action, PlayerInput.currentControlScheme, _pathBuffer))
{
if (DisplayGlyphTextureGenerator.GenerateGlyphTexture(_texture, devices, _pathBuffer, GlyphsLayout))
if (DisplayGlyphTextureGenerator.GenerateGlyphTexture(_texture, devices, _pathBuffer, GlyphsLayoutData))
{
Destroy(SpriteRenderer.sprite);
SpriteRenderer.sprite = Sprite.Create(_texture, new Rect(0, 0, _texture.width, _texture.height), new Vector2(0.5f, 0.5f), Mathf.Min(_texture.width, _texture.height));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class InputGlyphText : MonoBehaviour
public InputActionReference[] InputActionReferences = null;

[SerializeField]
public GlyphsLayout GlyphsLayout = GlyphsLayout.Horizontal;
public GlyphsLayoutData GlyphsLayoutData = GlyphsLayoutData.Default;

private PlayerInput _lastPlayerInput;
private List<string> _pathBuffer = new List<string>();
Expand Down Expand Up @@ -178,7 +178,7 @@ private void UpdateGlyphs(PlayerInput playerInput)
texture = new Texture2D(2, 2);
_actionTextureBuffer.Add(texture);
}
if (DisplayGlyphTextureGenerator.GenerateGlyphTexture(texture, devices, _pathBuffer, GlyphsLayout))
if (DisplayGlyphTextureGenerator.GenerateGlyphTexture(texture, devices, _pathBuffer, GlyphsLayoutData))
{
_actionTextureIndexes.Add(Tuple.Create(actionReference.action.name, i));
}
Expand Down
Loading

0 comments on commit 8b04a44

Please sign in to comment.