Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Fixed some issues with the controller popup window (#151)
Browse files Browse the repository at this point in the history
* Fixed some issues with the controller popup window

* revert

* Update XRTK-Core/Packages/com.xrtk.core/Inspectors/ControllerPopupWindow.cs

* Update XRTK-Core/Packages/com.xrtk.core/Inspectors/ControllerPopupWindow.cs
  • Loading branch information
StephenHodgson authored May 2, 2019
1 parent bb8a551 commit df8d010
Show file tree
Hide file tree
Showing 2 changed files with 685 additions and 14 deletions.
54 changes: 41 additions & 13 deletions Inspectors/ControllerPopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public class ControllerPopupWindow : EditorWindow
private bool isLocked = false;
private SerializedProperty currentInteractionList;

private ControllerPopupWindow thisWindow;

private Handedness currentHandedness;
private SupportedControllerType currentControllerType;

Expand Down Expand Up @@ -199,7 +197,6 @@ public static void Show(SupportedControllerType controllerType, SerializedProper
window = (ControllerPopupWindow)GetWindow(typeof(ControllerPopupWindow));
window.Close();
window = (ControllerPopupWindow)CreateInstance(typeof(ControllerPopupWindow));
window.thisWindow = window;
var handednessTitleText = handedness != Handedness.None ? $"{handedness} Hand " : string.Empty;
window.titleContent = new GUIContent($"{controllerType} {handednessTitleText}Input Action Assignment");
window.currentControllerType = controllerType;
Expand All @@ -226,7 +223,7 @@ public static void Show(SupportedControllerType controllerType, SerializedProper
}
};

AssetDatabase.CreateAsset(new TextAsset(string.Empty), EditorWindowOptionsPath);
File.WriteAllText(Path.GetFullPath(EditorWindowOptionsPath), JsonUtility.ToJson(empty, true));
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}
else
Expand All @@ -237,10 +234,17 @@ public static void Show(SupportedControllerType controllerType, SerializedProper
{
window.currentControllerOption = controllerInputActionOptions.Controllers.FirstOrDefault(option => option.Controller == controllerType && option.Handedness == handedness);

if (window.currentControllerOption != null && window.currentControllerOption.IsLabelFlipped == null)
if (window.currentControllerOption != null &&
window.currentControllerOption.IsLabelFlipped == null)
{
window.currentControllerOption.IsLabelFlipped = new bool[interactionsList.arraySize];
}

if (window.currentControllerOption != null &&
window.currentControllerOption.InputLabelPositions == null)
{
window.currentControllerOption.InputLabelPositions = new Vector2[interactionsList.arraySize];
}
}
}

Expand Down Expand Up @@ -283,22 +287,47 @@ private void OnGUI()
{
RenderInteractionList(currentInteractionList, IsCustomController);
}
catch (Exception)
catch (Exception e)
{
thisWindow.Close();
Debug.LogError($"{e.Message}\n{e.StackTrace}");
}
}

private void RenderInteractionList(SerializedProperty interactionList, bool useCustomInteractionMapping)
{
GUI.enabled = !isLocked;
if (interactionList == null) { throw new Exception(); }
if (interactionList == null) { throw new Exception("No interaction list found!"); }


bool noInteractions = interactionList.arraySize == 0;

if (currentControllerOption != null && (currentControllerOption.IsLabelFlipped == null || currentControllerOption.IsLabelFlipped.Length != interactionList.arraySize))
if (currentControllerOption != null)
{
currentControllerOption.IsLabelFlipped = new bool[interactionList.arraySize];
if (currentControllerOption.IsLabelFlipped == null ||
currentControllerOption.IsLabelFlipped.Length != interactionList.arraySize)
{
var newArray = new bool[interactionList.arraySize];

for (int i = 0; i < currentControllerOption.IsLabelFlipped.Length; i++)
{
newArray[i] = currentControllerOption.IsLabelFlipped[i];
}

currentControllerOption.IsLabelFlipped = newArray;
}

if (currentControllerOption.InputLabelPositions == null ||
currentControllerOption.InputLabelPositions.Length != interactionList.arraySize)
{
var newArray = new Vector2[interactionList.arraySize];

for (int i = 0; i < currentControllerOption.InputLabelPositions.Length; i++)
{
newArray[i] = currentControllerOption.InputLabelPositions[i];
}

currentControllerOption.InputLabelPositions = newArray;
}
}

GUILayout.BeginVertical();
Expand Down Expand Up @@ -342,8 +371,7 @@ private void RenderInteractionList(SerializedProperty interactionList, bool useC
{
if (!editInputActionPositions)
{
AssetDatabase.DeleteAsset(EditorWindowOptionsPath);
AssetDatabase.CreateAsset(new TextAsset(JsonUtility.ToJson(controllerInputActionOptions)), EditorWindowOptionsPath);
File.WriteAllText(Path.GetFullPath(EditorWindowOptionsPath), JsonUtility.ToJson(controllerInputActionOptions, true));
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}
else
Expand All @@ -369,7 +397,7 @@ private void RenderInteractionList(SerializedProperty interactionList, bool useC
}

AssetDatabase.DeleteAsset(EditorWindowOptionsPath);
AssetDatabase.CreateAsset(new TextAsset(JsonUtility.ToJson(controllerInputActionOptions)), EditorWindowOptionsPath);
File.WriteAllText(Path.GetFullPath(EditorWindowOptionsPath), JsonUtility.ToJson(controllerInputActionOptions, true));
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}
}
Expand Down
Loading

0 comments on commit df8d010

Please sign in to comment.