Created
February 22, 2023 15:47
-
-
Save CodeSmile-0000011110110111/b41f9f51b3dfef5c24b8a5c4de624b0a to your computer and use it in GitHub Desktop.
Fixing the "unsaved" random seed by changing the serializedObject's property and ApplyModifiedProperties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void OnInspectorGUI() | |
{ | |
DrawDefaultInspector(); | |
var script = (RandomMeshSelector)target; | |
if (GUILayout.Button("Change Random Seed")) | |
{ | |
serializedObject.FindProperty("m_RandomSeed").intValue = script.GenerateNewRandomSeed(); | |
serializedObject.ApplyModifiedProperties(); | |
script.SetRandomMeshIndex(); | |
script.SelectMesh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method now needs to return the seed, or generate it in the editor script:
script.GenerateNewRandomSeed();
A slightly more involved solution is in the below repository. With that you can just pick one of the meshes rather than having to rely on the desired one to randomly pop up. It requires changing the MB script so that it persists a "current mesh index" rather than generating it 'randomly'.
https://github.com/CodeSmile-0000011110110111/CodeSmile-Twitch-Public/blob/main/HowToDoStuff/Assets/Scripts/Editor/RandomMeshSelectorEditor.cs
https://github.com/CodeSmile-0000011110110111/CodeSmile-Twitch-Public/blob/main/HowToDoStuff/Assets/Scripts/RandomMeshSelector.cs