Skip to content

Commit

Permalink
Merge pull request #9 from DerpyNewbie/add-role-manager-preprocess
Browse files Browse the repository at this point in the history
Add RoleManager preprocessing to prevent runtime crashes
  • Loading branch information
DerpyNewbie authored Jun 12, 2023
2 parents ab60e5d + a9fdf25 commit 1fa71aa
Show file tree
Hide file tree
Showing 9 changed files with 1,080 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "DerpyNewbie.Common.Editor",
"references": ["GUID:849b8c6574848ed44b9f0ccd066aff2b"],
"references": [
"GUID:99835874ee819da44948776e0df4ff1d",
"GUID:84265b35cca3905448e623ef3903f0ff",
"GUID:849b8c6574848ed44b9f0ccd066aff2b"
],
"includePlatforms": [
"Editor",
"PS5"
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
Expand Down
3 changes: 3 additions & 0 deletions Packages/dev.derpynewbie.common/Editor/Inspector.meta

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

651 changes: 651 additions & 0 deletions Packages/dev.derpynewbie.common/Editor/Inspector/RoleManagerEditor.cs

Large diffs are not rendered by default.

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

56 changes: 56 additions & 0 deletions Packages/dev.derpynewbie.common/Editor/Issue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using UnityEditor;

namespace DerpyNewbie.Common.Editor
{
public readonly struct Issue
{
public string Message { get; }
public MessageType MessageType { get; }
public Action AutoFixAction { get; }
public Action SelectAction { get; }

public Issue(string message, MessageType messageType, Action autoFixAction = null, Action selectAction = null)
{
Message = message;
MessageType = messageType;
AutoFixAction = autoFixAction;
SelectAction = selectAction;
}

public void HelpBoxWithButton(float buttonWidth = 100F)
{
if (AutoFixAction != null && SelectAction != null)
{
NewbieCommonsEditorUtil.HelpBoxWithButton(
Message, MessageType,
"Select", SelectAction,
"Auto Fix", AutoFixAction,
buttonWidth
);
}
else if (AutoFixAction != null)
{
NewbieCommonsEditorUtil.HelpBoxWithButton(
Message, MessageType,
"Auto Fix", AutoFixAction,
buttonWidth: buttonWidth
);
}
else if (SelectAction != null)
{
NewbieCommonsEditorUtil.HelpBoxWithButton(
Message, MessageType,
"Select", SelectAction,
buttonWidth: buttonWidth
);
}
else
{
NewbieCommonsEditorUtil.HelpBoxWithButton(
Message, MessageType
);
}
}
}
}
3 changes: 3 additions & 0 deletions Packages/dev.derpynewbie.common/Editor/Issue.cs.meta

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
@@ -1,4 +1,6 @@
using UnityEditor;
using DerpyNewbie.Common.Editor.Inspector;
using UnityEditor;
using UnityEngine;
using VRC.SDKBase.Editor.BuildPipeline;

namespace DerpyNewbie.Common.Editor
Expand All @@ -14,17 +16,25 @@ static NewbieCommonsBuildPreprocessor()
private static void PlayModeStateChanged(PlayModeStateChange change)
{
var isBuilding = BuildPipeline.isBuildingPlayer ||
UnityEngine.Object.FindObjectOfType<PipelineSaver>() != null ||
Object.FindObjectOfType<PipelineSaver>() != null ||
change != PlayModeStateChange.ExitingEditMode;
if (isBuilding)
return;

RoleManagerEditor.DoPreBuildCheck();
NewbieInjectProcessor.DoPrePlayInject(change);
}

public int callbackOrder => 2048;

public bool OnBuildRequested(VRCSDKRequestedBuildType requestedBuildType)
{
if (!RoleManagerEditor.DoPreBuildCheck())
{
Debug.LogError("[NewbieCommonsBuildPreprocessor] RoleManager pre build check failed");
return false;
}

NewbieInjectProcessor.DoPreBuildInject(requestedBuildType);
return true;
}
Expand Down
39 changes: 34 additions & 5 deletions Packages/dev.derpynewbie.common/Editor/NewbieCommonsEditorUtil.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
using UnityEngine;
using System;
using UnityEditor;
using UnityEngine;

namespace DerpyNewbie.Common.Editor
{
public static class NewbieCommonsEditorUtil
{
public static void Log(object message)
public static void Log(object message, UnityEngine.Object context = null)
{
Debug.Log($"[NewbieCommons] {message}");
Debug.Log($"[NewbieCommons] {message}", context);
}

public static void LogError(object message)
public static void LogError(object message, UnityEngine.Object context = null)
{
Debug.LogError($"[NewbieCommons] {message}");
Debug.LogError($"[NewbieCommons] {message}", context);
}

public static void HelpBoxWithButton(
string message, MessageType type,
string button1Label = null, Action button1Action = null,
string button2Label = null, Action button2Action = null,
float buttonWidth = 100F)
{
if (button1Label != null)
EditorGUILayout.BeginHorizontal();
EditorGUILayout.HelpBox(message, type, true);

if (button2Label != null)
EditorGUILayout.BeginVertical(GUILayout.Width(buttonWidth));

if (button1Label != null &&
GUILayout.Button(button1Label, GUILayout.Width(buttonWidth), GUILayout.ExpandHeight(button2Label == null)))
button1Action?.Invoke();

if (button2Label != null && GUILayout.Button(button2Label))
button2Action?.Invoke();

if (button2Label != null)
EditorGUILayout.EndVertical();

if (button1Label != null)
EditorGUILayout.EndHorizontal();
}
}
}
Loading

0 comments on commit 1fa71aa

Please sign in to comment.