Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for overriding RequiresConstantRepaint in custom inspectors #65

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,54 @@ void DrawDefaultUdonSharpInspector()
UdonSharpGUI.DrawPublicVariables(behaviour, udonSharpProgramAsset, ref dirty);
}

// Force repaint for variable update in play mode
public override bool RequiresConstantRepaint()
{
return Application.isPlaying;
// Force repaint for variable update in play mode
bool requiresConstantRepaintDefaultReturnValue = Application.isPlaying;

if (PrefabUtility.IsPartOfPrefabAsset(target))
return requiresConstantRepaintDefaultReturnValue;

UdonBehaviour behaviour = target as UdonBehaviour;

if (behaviour.programSource == null ||
!(behaviour.programSource is UdonSharpProgramAsset udonSharpProgram) ||
udonSharpProgram.sourceCsScript == null)
return requiresConstantRepaintDefaultReturnValue;

System.Type customEditorType = null;
System.Type inspectedType = udonSharpProgram.sourceCsScript.GetClass();
if (inspectedType != null)
customEditorType = UdonSharpCustomEditorManager.GetInspectorEditorType(inspectedType);

if (customEditorType == null)
return requiresConstantRepaintDefaultReturnValue;

MethodInfo requiresConstantRepaintMethod = customEditorType.GetMethod("RequiresConstantRepaint", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null);

if (requiresConstantRepaintMethod == null)
return requiresConstantRepaintDefaultReturnValue;

udonSharpProgram.UpdateProgram();

if (baseEditor != null && baseEditor.GetType() != customEditorType)
{
DestroyImmediate(baseEditor);
baseEditor = null;
}

UdonSharpBehaviour inspectorTarget = UdonSharpEditorUtility.GetProxyBehaviour(behaviour, ProxySerializationPolicy.All);
inspectorTarget.enabled = false;

Editor.CreateCachedEditorWithContext(inspectorTarget, this, customEditorType, ref baseEditor);

baseEditor.serializedObject.Update();

bool requiresConstantRepaintReturnValue = (bool)requiresConstantRepaintMethod.Invoke(baseEditor, null);

UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All);

return requiresConstantRepaintReturnValue;
}
}
}