Event Types In Unity Scripting - unity3d

i just wanna start to codding more clean and dynamic codes and i start to learn "events" but im so confused about events because all videos show different things 0.0 did i understand wrong or there are three types of events ? i mean
c# event
unity events
game events
if i understand true this all different event systems right ? and i can use which i want, and i should spesific.
i hope i understand right can someone explain shortly ? if i understand right just can say yes :)

There are UnityEvents. Usually AddListener(YourFunction)
There are Unity Events (meta, haha!)
There is an official Unity Tutorial on C# Events. Usually with the += operator: .OnClicked += YourFunction;
There is an Event System for the "Unity UI 1.0.0" Package, but there is also still the old Event System for Ui/Canvas interaction (until Unity 2018?).
There is the Event System for UI inside of Unity, if you want to build an Editor Tool, to paint prefabs in the Scene for example.
The "old" Input System (Input.GetKeyDown("Space")) is also an Event System.
But there is also a still optional, new Input System Package that handles local Coop (multiple Controllers) a bit better. You can only use one at a time. (You have to switch form one to the other in Settings)
As you can see, there a a lot of Event Systems. You can write your own, if that is required for a Task. Event Systems are a general way to handle changes without polling and comparing values every frame, but listening to changes and occurances.

Related

Changing control schemes between camera views?

I am a beginner gamedev and trying to figure out how to go about implementing my game's inventory management system. I am developing a third person RPG, with heavy emphasis on inventory and crafting, and so it needs to be done right.
I essentially have a tablet device the player will be able to use to access statistics about themselves and should also be their method of ascertaining crafting recipe. An example scenario is as follows: player obtains three recipe items, Apple, Leaf, and Ash. They want to craft a healing poultice in the field. They remove their backpack, which serves as both inventory and a less powerful crafting station, and the camera moves to focus on the backpack as if it were an inventory screen, allowing the player to arrange their ingredients as necessary and then craft.
My problem is I haven't figured out how to manage the control switch. Ideally the player shouldn't be able to walk around and do normal traversal while crafting. Indeed having WASD usable as menu manipulation controls would be preferable. The game is of the type that realtime usage of inventory is part of the experience, so I dont want a static pause screen. What avenue do I need to pursue in my research for this?
I've looked into Cinemachine and state switching/statemachines but I'm still fairly puzzled by that whole affair. I can switch to a state so far, but only sometimes get out of it. I'm away from my computer at the moment so I don't have an example but this concept has been nagging me for hours.

Rewind of Players death in Unreal engine

Can anybody suggest me how to make the Gears of war style like death? i.e, when players dies they show the rewind of how the player dies.
Unreal has a very handy tool called Replay System that allows exactly this. You can check the official documentation here.
Though Multiplayer is not technically required, your game must support replication. This system supports Streamers who want to be able to use those replays to generate content, but you can stop the recording when the player dies, use the last 10 seconds (for example) and then discard it.
The commands you're looking for are UGameInstance::StartRecordingReplay, UGameInstance::StopRecordingReplay and UGameInstance::PlayReplay.
Basicly, you're doing some Client-Side demo recording.
Please let us know how it goes!

How to add an Event object to Unity's EventSystem

If I have an event from Event.current and I want to 'replay' it by making the event system process it again, how do I do that? Can I access the scripts responsible for raising events?
You might be able to track down how events are created using IL Spy then use reflection to invoke that, but unfortunately there is no public API for creating events manually.
I found a neat C# library which simulates input called Windows Input Simulator which does a good job of raising all the keyboard events I needed. Looks like it also works for things like mouse input!

Unity3d onSomeEvent() vs update() performance

I've been using Unity3D lately, and soon I discovered thorugh multiple topics online that using OnMouseUp event is much slower than checking for mouse clicks on the update() function. Can someone explain why is that?
Is that also valid for other on functions like OnTriggerExit2D and others? As a design pattern, should I abandon the on() functions completely and only catch events on Update()?
I prefer neither of them but use the 'new' (since 4.6) Unity Event system when possible. In short you have to implement the appropriate handler interface like IPointerClickHandler.
I recommend to have a look at the Events tutorials, for example UI Events and Event Triggers. Note that although this tutorial is focussed on 2D, you can use the event system in 3D as well. You just need to add a Raycaster to your camera.
Agreed with the previous answer but as a reason to WHY the "On" functions are so much more inefficient lies in how they function.
How does unity know that an "OnMouseUp" event has fired? The mouse object would need to have an event handler attached to it that knows to fire the OnMouseUp event. Beyond that something would need to listen every single frame for that event and then run the required code. Also the OnEvent functions tend to get very dispersed because you could in theory have the same event in multiple different functions/classes.
I think the update method in general is a more efficient way to check, because there is a lot less overhead involved when you handle these things yourself.
tldr: There's more overhead involved in using the "On" events instead of in "Update"

Scripting structure for unity with airconsole

I've looked at the examples that come with the airconsole plugin, and in both of the examples the "meat" of the code is in one script.
I am interested in trying to make a multiplayer game, is it possible to split the control of each character into 4 scripts, which each are applied on a different player object rather than having one script control all 4 objects from one single script?
If so, how do you go about doing it, just by including the libraries in each control script? like so:
using NDream.AirConsole;
or do i have to do some kind of special structure?
It's possible to have various different scripts that use the NDream.AirConsole namespace, yes.
Be aware however that if you have 4 scripts in a scene that all listen for the OnMessage event, for instance, you will likely end up using a lot more performance than if you just have one "AirConsole script" in a scene, where you receive and filter the messages and then relay to the right player.
Better to have one AirConsole script that listens for the event, check for device id/player number in the OnMessage (or whichever) event and then send the relevant information to the player script in question.
That's how we do it for our multiplayer games in Unity.