Big Events Thread

Discuss Daggerfall Unity and Daggerfall Tools for Unity.
User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Big Events Thread

Post by Interkarma »

I'm adding a whole swag of events to next DFTFU Developer Preview, version 1.3.12. Hopefully this will assist contributors by allowing them to subscribe to events, rather than modify library code. This list is just a first pass! I am completely open to ideas, so please let me know if there is somewhere you would like an event to fire and what kind of data would be useful to you at that moment. Here's the list so far.

DaggerfallUnity
OnReady

Demo/PlayerEnterExit
OnTransitionInterior
OnTransitionExterior
OnTransitionDungeonInterior
OnTransitionDungeonExterior
OnMovePlayerToDungeonStart


Demo/WeatherManager
OnSetRainOvercast
OnSetSnowOvercast
OnClearOvercast
OnStartRaining
OnStartStorming
OnStopRaining
OnStartSnowing
OnStopSnowing


Demo/AmbientEffectsPlayer
OnPlayEffect

Demo/ShowTitleScreen
OnStartDisplayTitleScreen
OnEndDisplayTitleScreen


Utility/FloatingOrigin
OnPositionUpdate

Internal/PlayerGPS
OnMapPixelChanged
OnClimateChanged
OnRegionChanged
OnEnterLocationRect
OnExitLocationRect


Internal/WorldTime
OnMidnight
OnMidday
OnDawn
OnDusk
OnCityLightsOn
OnCityLightsOff
OnNewYear
OnNewMonth


Terrain/StreamingWorld
OnTeleportToCoordinates
OnInitWorld
OnUpdateTerrainsStart
OnUpdateTerrainsEnd
OnClearStreamingWorld
OnCreateLocationGameObject
OnReady


Terrain/DaggerfallTerrain
OnInstantiateTerrain
OnPromoteTerrainData


Terrain/TerrainHelper
OnGenerateSamplesStart
OnNewSmallHeightSamples
OnNewLargeHeightSamples
OnGenerateSamplesEnd

User avatar
LypyL
Posts: 512
Joined: Sun Mar 22, 2015 3:48 am

Re: Big Events Thread

Post by LypyL »

Looks good! How about one for Dfunity that triggers when Setup() finishes?

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Big Events Thread

Post by Nystul »

i like it ;)

edit:
I would like to have a StreamingWorld isReadyEvent (after initialization is finished)

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Big Events Thread

Post by Interkarma »

Thanks guys, I've added an OnReady event to both DaggerfallUnity and StreamingWorld that fires when isReady flag is raised on setup completion.

I also wanted to talk about using static events. I normally avoid static events because they cause a few problems (mainly no instance partitioning and need to unsubscribe for GC to clean up references properly). However in this scenario, I think many of the classes will benefit from the simplicity of using static events considering they are either a singleton, attached to a singleton, or designed to be instantiated once for entire lifetime of the scene.

For example, DaggerfallUnity, WorldTime, StreamingWorld, and WeatherManager should exist only once in scene and persist for entire lifetime of scene. This means both the partitioning and reference issues are pretty much moot. Using static events here is simpler for programmers, letting them multicast events without having to explicitly set or find the instance - handy when a component can be used in one of several ways. It also avoids the drama of event subscriptions being lost when parent GameObject is disabled then enabled again.

For more dynamic objects (e.g. enemies), objects with a short lifetime (e.g. blood splashes), or objects that are created at runtime and pooled (e.g. terrains), I will continue to use non-static events. The programmer must find the correct instance to subscribe to its events. I will provide means to help locate instances (such as custom EventArgs) as required.

Let me know your thoughts on static vs. non-static. I'm fairly happy we're using static events for the right reasons in these cases, but I wanted to be sure nobody had any objections or suggestions.

User avatar
LypyL
Posts: 512
Joined: Sun Mar 22, 2015 3:48 am

Re: Big Events Thread

Post by LypyL »

Thanks guys, I've added an OnReady event to both DaggerfallUnity and StreamingWorld that fires when isReady flag is raised on setup completion.
I'll guess I'll mention it here than start a new thread about it though it's a tad offtopic - it would be useful to have a way to disable player movement / attack / camera input at certain times (like when the player is typing text into an input field, or using the mouse on a menu), and disabling all the various scripts is a pain, and can cause problems. The easiest way I could think of is to add a bool somewhere, like DaggerfallUnity class, and always check if it's true before getting player input.

For more dynamic objects (e.g. enemies), objects with a short lifetime (e.g. blood splashes), or objects that are created at runtime and pooled (e.g. terrains), I will continue to use non-static events. The programmer must find the correct instance to subscribe to its events. I will provide means to help locate instances (such as custom EventArgs) as required.
As an alternative, you could have static events somewhere like an event manager for these and have the dynamic objects trigger events, and pass in a gameobject reference or whatever for the subscribers.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Big Events Thread

Post by Interkarma »

LypyL wrote: I'll guess I'll mention it here than start a new thread about it though it's a tad offtopic - it would be useful to have a way to disable player movement / attack / camera input at certain times (like when the player is typing text into an input field, or using the mouse on a menu), and disabling all the various scripts is a pain, and can cause problems. The easiest way I could think of is to add a bool somewhere, like DaggerfallUnity class, and always check if it's true before getting player input.
The most robust way to handle this is to use game states with an input manager. This way input can be directed by whatever state the game is executing in (e.g. menus, chat, world, etc.). The Demo namespace is really just for showing how to accomplish certain "game-like" tasks with the tools and is missing a lot of features required for more advanced implementations. It's definitely a conversation worth having at some point however. What I'll probably end up doing is expanding some of the Demo classes into a more complete Game framework that devs can use or ignore as desired.

User avatar
LypyL
Posts: 512
Joined: Sun Mar 22, 2015 3:48 am

Re: Big Events Thread

Post by LypyL »

The most robust way to handle this is to use game states with an input manager. This way input can be directed by whatever state the game is executing in (e.g. menus, chat, world, etc.).
Of course, I was actually thinking about doing that myself as I've run into this issue a few times myself now, but I came across a post in the Unity forums from a Unity employee saying they are currently working on overhauling the input manager for unity...though god knows when that will be done :D

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Big Events Thread

Post by Interkarma »

Haha so true. :) No telling when they finally get around to it. There are some great solutions on the asset store, but I haven't been able to find something decent that's also open source. We might just end up having to roll our own at some point after all.

In the meantime, your solution is a pretty good one. Just some kind of state communication between classes would go a long way to clearing up issues. I'll see what I can put in once the events are done.

User avatar
LypyL
Posts: 512
Joined: Sun Mar 22, 2015 3:48 am

Re: Big Events Thread

Post by LypyL »

I think I found a good open source Input Manager - everything in it is under the MIT license.

http://forum.unity3d.com/threads/free-c ... er.223321/

https://github.com/daemon3000/InputManager

Very simple to implement. It has the same public methods and variables as Unity's Input class
Allows you to customize key bindings at runtime
Allows you to create new input configurations at runtime
Allows you to convert touch input to axes and buttons on mobile devices
Save the key bindings to a file, to PlayerPrefs or anywhere else by implementing a simple interface
Seamless transition from keyboard to gamepad with the InputAdapter addon
Works with the new Unity 4.6 UI system

It's very easy to use, basically works just like Unity's Input manager. InputManager.GetKeyDown(), InputManager.GetButton(), InputManager.GetAxis() and so on, and it has editor windows that basically just replace Unity's input manager.

I haven't tried it yet, but from what I gather you can save/load player key bindings and other settings externally - So theoretically, we could do something like have different configurations for different states, while letting players setup their own key-bindings in game and save them.

I made a simple test project if you want to check it out when you have the time. This is the whole thing as I edited some DFTFU files, so just import it into an empty project. I basically just changed the inputs from PlayerMotor, WeaponManager, PlayerMouseLook so it uses InputManager instead - so it's far from polished :D

https://drive.google.com/file/d/0B8_oQw ... sp=sharing

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Big Events Thread

Post by Interkarma »

Very good find! I'll check it out. :D

Post Reply