Skip to content

Commit

Permalink
[SDK-374] - move webgl under core samples (#119)
Browse files Browse the repository at this point in the history
Move WebGL sample under the Core package sample.
  • Loading branch information
rk132 authored Sep 8, 2023
2 parents d6ff6ac + 577b270 commit 70e4582
Show file tree
Hide file tree
Showing 77 changed files with 2,530 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Samples~/WebGLExample.meta

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

8 changes: 8 additions & 0 deletions Samples~/WebGLExample/Editor.meta

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

8 changes: 8 additions & 0 deletions Samples~/WebGLExample/Editor/EditorWindows.meta

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

120 changes: 120 additions & 0 deletions Samples~/WebGLExample/Editor/EditorWindows/ExampleSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System.Collections.Generic;
using System.IO;
using JetBrains.Annotations;
using ReadyPlayerMe.Core;
using ReadyPlayerMe.Samples;
using UnityEditor;
using UnityEngine;

namespace ReadyPlayerMe.Samples
{
public static class ExampleSetup
{
private const string TAG = nameof(ExampleSetup);
private static string WINDOW_TITLE = "RPM WebGL Example";
private static string DESCRIPTION =
"This example includes a WebGL template that can be used for WebGL builds. To use the template it needs to be moved inside WebGLTemplates folder and set in the player settings. Would you like to move it automatically?";
private const string CONFIRM_BUTTON_TEXT = "Ok";
private const string CANCEL_BUTTON_TEXT = "Cancel";

private static readonly string RPM_WEBGL_SCREEN_SHOWN_KEY = "rpm-webgl-screen-shown";

private static readonly string TEMPLATE_PATH = "/WebGLTemplates/RPMTemplate";
private static readonly string FILE_NAME = "ExampleSetup.cs";
private static readonly string ROOT_PATH = "/Assets";

[InitializeOnLoadMethod]
private static void InitializeOnLoad()
{
if (ProjectPrefs.GetBool(RPM_WEBGL_SCREEN_SHOWN_KEY))
{
return;
}

ProjectPrefs.SetBool(RPM_WEBGL_SCREEN_SHOWN_KEY, true);
EditorApplication.update += ShowWebGLScreen;
}

private static void ShowWebGLScreen()
{
var shouldUpdate = EditorUtility.DisplayDialogComplex(WINDOW_TITLE,
DESCRIPTION,
CONFIRM_BUTTON_TEXT,
CANCEL_BUTTON_TEXT,
"");

switch (shouldUpdate)
{
// Update
case 0:
OnConfirm();
break;
}
EditorApplication.update -= ShowWebGLScreen;
}

private static void OnConfirm()
{
var templatePaths = GetTemplatePaths();

if (templatePaths == null)
{
Debug.LogWarning("Failed to set source and destination paths. No changes were done to project");
return;
}
Copy(templatePaths[0], templatePaths[1]);
SetWebGLTemplate();
}

private static List<string> GetTemplatePaths()
{
string[] res = Directory.GetFiles(Application.dataPath, FILE_NAME, SearchOption.AllDirectories);
if (res.Length == 0)
{
return null;
}
string path = res[0].Replace(FILE_NAME, "").Replace("\\", "/");
var sourcePath = path.Substring(0, path.IndexOf("/Editor/")) + TEMPLATE_PATH;
var destinationPath = path.Substring(0, path.IndexOf(ROOT_PATH)) + ROOT_PATH;
return new List<string>() { sourcePath, destinationPath };
}

private static void Copy(string sourcePath, string destinationPath)
{
foreach (string sourceFile in Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories))
{
if (sourceFile.EndsWith(".meta"))
{
continue;
}

var sourceFilePath = sourceFile.Replace("\\", "/");

if (File.Exists(sourceFilePath))
{
string destination = destinationPath + sourceFilePath.Substring(sourceFilePath.IndexOf(TEMPLATE_PATH)).Replace("\\", "/");

if (!Directory.Exists(destination.Substring(0, destination.LastIndexOf("/"))))
{
Directory.CreateDirectory(destination.Substring(0, destination.LastIndexOf("/")));
}

File.Copy(sourceFilePath, destination, true);
}
else
{
Debug.LogError("Source file does not exist: " + sourceFilePath);
}
}
Debug.Log("Copied RPMTemplate to the WebGLTemplate folder in the root path of Assets");
AssetDatabase.Refresh();
}


private static void SetWebGLTemplate()
{
PlayerSettings.WebGL.template = "PROJECT:RPMTemplate";
Debug.Log("Updated player settings to use RPMTemplate");
}
}
}

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
@@ -0,0 +1,16 @@
{
"name": "ReadyPlayerMe.Core.WebGLExample.Editor",
"rootNamespace": "",
"references": ["GUID:36f486ff968bbf4439cd840e8fca87ea"],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

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

8 changes: 8 additions & 0 deletions Samples~/WebGLExample/Prefabs.meta

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

169 changes: 169 additions & 0 deletions Samples~/WebGLExample/Prefabs/DebugPanel.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2169272630008489445
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2169272630008489442}
- component: {fileID: 2169272630008489440}
- component: {fileID: 2169272630008489443}
- component: {fileID: 2169272630008489441}
m_Layer: 5
m_Name: DebugPanel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2169272630008489442
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2169272630008489445}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2169272630561590028}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 100}
m_Pivot: {x: 0.5, y: 0}
--- !u!222 &2169272630008489440
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2169272630008489445}
m_CullTransparentMesh: 1
--- !u!114 &2169272630008489443
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2169272630008489445}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.392}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &2169272630008489441
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2169272630008489445}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c41050fe3b94d4f41a0a95a6fd0f33fc, type: 3}
m_Name:
m_EditorClassIdentifier:
debugText: {fileID: 2169272630561590029}
--- !u!1 &2169272630561590031
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2169272630561590028}
- component: {fileID: 2169272630561590026}
- component: {fileID: 2169272630561590029}
m_Layer: 5
m_Name: DebugText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2169272630561590028
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2169272630561590031}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2169272630008489442}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2169272630561590026
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2169272630561590031}
m_CullTransparentMesh: 1
--- !u!114 &2169272630561590029
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2169272630561590031}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 34
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: ---
7 changes: 7 additions & 0 deletions Samples~/WebGLExample/Prefabs/DebugPanel.prefab.meta

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

8 changes: 8 additions & 0 deletions Samples~/WebGLExample/Ready Player Me.meta

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

8 changes: 8 additions & 0 deletions Samples~/WebGLExample/Ready Player Me/Resources.meta

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

8 changes: 8 additions & 0 deletions Samples~/WebGLExample/Ready Player Me/Resources/Settings.meta

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

Loading

0 comments on commit 70e4582

Please sign in to comment.