-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the notion of an EventHandler abstract.
HandleEvent previously required you to modify the event receiving code. Now, the event receiver will just pass new events to an abstract UdonBehaviour with the correct var names and event name.
- Loading branch information
1 parent
1eff887
commit 88a0212
Showing
3 changed files
with
50 additions
and
49 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Example Handler | ||
using UdonSharp; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using VRC.SDKBase; | ||
using VRC.Udon; | ||
using VRC.Udon.Common.Interfaces; | ||
|
||
/// <Summary>An example handler for events.</Summary> | ||
public class ChatEventHandler : UdonSharpBehaviour | ||
{ | ||
public UdonLogger logger; | ||
|
||
private string characterName; | ||
private string newEvent; | ||
|
||
public void Handle() | ||
{ | ||
bool ownerOfGame = true; | ||
if (Networking.LocalPlayer != null) | ||
{ | ||
ownerOfGame = Networking.LocalPlayer.IsOwner(gameObject); | ||
} | ||
|
||
// As it stands, hard-code your events in this function. | ||
// This is pretty basic. Once maps and lists exist in Udon, this can be improved. | ||
string[] e = newEvent.Split(','); | ||
Debug.Log("Got an event named " + e[0] + " with payload " + newEvent); | ||
switch (e[0]) | ||
{ | ||
case "ChatMessage": | ||
string message = characterName + ": " + e[1]; | ||
message = message.Replace("|", ","); | ||
logger.Notice(message); | ||
break; | ||
default: | ||
logger.Notice("Got an event named " + e[0] + " but didn't know what to do with it."); | ||
break; | ||
} | ||
} | ||
|
||
} |
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
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