Skip to content

Commit

Permalink
fix(samples): Add project settings validation wizard
Browse files Browse the repository at this point in the history
Summary: Add a project settings validation wizard to ensure that the correct project settings are applied. Remove old project validation files. Updated merge github workflow and added a cleanup workflow.

Reviewed By: sohailshafiiWk

Differential Revision: D41091947

fbshipit-source-id: 51c41a003d2a8951ff213671397d705b61dab25c
  • Loading branch information
Andrew Kim authored and facebook-github-bot committed Nov 8, 2022
1 parent f4cc1c2 commit b2f5005
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 1,547 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Cleanup deleted files from dev in main

on:
workflow_dispatch:

jobs:
merge-branch:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: main
- name: Set Git config
run: |
git config --local user.email "actions@github.com"
git config --local user.name "Github Actions"
- name: Merge dev to main
run: |
git pull
git merge --allow-unrelated-histories $(git commit-tree -p main -m "[Automated] Cleanup" origin/dev^{tree})
- name: Use CHANGELOG and package.json from main
run: |
git checkout HEAD~2 CHANGELOG.md
git checkout HEAD~2 package.json
git commit --amend --no-edit
- name: Push
run: |
git push
5 changes: 5 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
run: |
git pull
git merge --no-ff --allow-unrelated-histories -X theirs origin/dev -m "[Automated] Merged dev into main"
- name: Use CHANGELOG and package.json from main
run: |
git checkout HEAD~1 CHANGELOG.md
git checkout HEAD~1 package.json
git commit --amend --no-edit
- name: Push
run: |
git push
130 changes: 130 additions & 0 deletions Editor/Utils/ProjectValidation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;

namespace Oculus.Movement.Utils
{
/// <summary>
/// Validates various project settings for the samples to work correctly.
/// </summary>
[InitializeOnLoad]
public class ProjectValidation
{
private static readonly string[] _expectedLayers = { "Character", "MirroredCharacter", "HiddenMesh" };

static ProjectValidation()
{
if (!ShouldShowWindow())
{
return;
}

ProjectValidationWindow.ShowProjectValidationWindow();
}

/// <summary>
/// If all expected layers are in the project, returns true.
/// </summary>
/// <returns>True if all expected layers are in the project.</returns>
public static bool TestLayers()
{
bool allLayersArePresent = true;
foreach (var expectedLayer in _expectedLayers)
{
if (LayerMask.NameToLayer(expectedLayer) == -1)
{
allLayersArePresent = false;
break;
}
}
return allLayersArePresent;
}

/// <summary>
/// If the project is using URP, returns true if vulkan is set.
/// </summary>
/// <returns>True if vulkan is set and the project requires URP.</returns>
public static bool TestVulkan()
{
bool vulkanFoundOrNotRequired = GraphicsSettings.renderPipelineAsset == null
|| SystemInfo.graphicsDeviceType == GraphicsDeviceType.Vulkan
|| SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11;
return vulkanFoundOrNotRequired;
}

private static bool ShouldShowWindow()
{
return !TestLayers() || !TestVulkan();
}
}

/// <summary>
/// Editor window that displays information about configuring the project.
/// </summary>
public class ProjectValidationWindow : EditorWindow
{
private static ProjectValidationWindow _projectValidationWindow;

/// <summary>
/// Shows the project validation window.
/// </summary>
public static void ShowProjectValidationWindow()
{
if (!HasOpenInstances<ProjectValidationWindow>())
{
_projectValidationWindow = GetWindow<ProjectValidationWindow>();
_projectValidationWindow.titleContent = new GUIContent("Movement Validation");
_projectValidationWindow.Focus();
}
}

private void OnEnable()
{
EditorWindow editorWindow = this;

Vector2 windowSize = new Vector2(600, 200);
editorWindow.minSize = windowSize;
editorWindow.maxSize = windowSize;
}

private void OnGUI()
{
bool layersValid = ProjectValidation.TestLayers();
bool vulkanValid = ProjectValidation.TestVulkan();
GUIStyle labelStyle = new GUIStyle (EditorStyles.label);
labelStyle.richText = true;
labelStyle.wordWrap = true;

GUILayout.BeginVertical();
{
GUI.enabled = !layersValid;
GUILayout.BeginVertical(EditorStyles.helpBox);
{
GUILayout.Label("Layers", EditorStyles.boldLabel);
GUILayout.Label(
"For the sample scenes, the following layers must be present in the project: <b>Character (layer index 10), MirroredCharacter (layer index 11), and HiddenMesh</b>. \n\nImport the Layers preset in <b>Edit -> Project Settings -> Tags and Layers</b> by selecting the tiny settings icon located at the top right corner and choosing the <b>Layers</b> preset located in the <b>Samples/Shared/Presets</b> folder.",
labelStyle);
GUILayout.Space(5);
}
GUILayout.EndVertical();
GUI.enabled = true;

GUI.enabled = !vulkanValid;
GUILayout.BeginVertical(EditorStyles.helpBox);
{
GUILayout.Label("Vulkan", EditorStyles.boldLabel);
GUILayout.Label(
"Set the primary graphics API to Vulkan in <b>Edit -> Project Settings -> Player -> Other Settings -> Graphics API</b>.",
labelStyle);
GUILayout.Space(5);
}
GUILayout.EndVertical();
GUI.enabled = true;
}
GUILayout.EndVertical();
GUILayout.Space(5);
}
}
}

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Then, bring this package into the project.
- In Package Manager, click on the add button below the window title and select **Add package from git URL…**, using this URL: https://github.com/oculus-samples/Unity-Movement.git
- Alternatively, in package manager, click on the add button below the window title and select **Add package from disk...**, using the package.json located after unzipping one of the releases here: https://github.com/oculus-samples/Unity-Movement/releases

The sample scenes are located under the **Samples/../Scenes** folders.
The sample scenes are located under the **Samples/../Scenes** folders. The Character (layer index 10), the MirroredCharacter (layer index 11), and the HiddenMesh layers must be present in the project.

## Samples
The project contains several sample scenes. For more information about the samples, read [Aura Sample](https://developer.oculus.com/documentation/unity/move-sample-aura/), [Hip Pinning Sample](https://developer.oculus.com/documentation/unity/move-sample-hip-pinning/), and [High Fidelity Sample](https://developer.oculus.com/documentation/unity/move-high-fidelity/).
Expand Down
8 changes: 0 additions & 8 deletions Runtime/Scripts/Validation.meta

This file was deleted.

83 changes: 0 additions & 83 deletions Runtime/Scripts/Validation/LayerAndVulkanValidation.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Runtime/Scripts/Validation/LayerAndVulkanValidation.cs.meta

This file was deleted.

Loading

0 comments on commit b2f5005

Please sign in to comment.