I’m creating a cutscene where the choices pop up during playback and the player chooses a response from three.
To achieve this, I wrote the code for the response marker and marker receiver as shown below, and placed a custom marker on the signal track(placed object has signal receiver and custom marker receiver).
In order to give feedback to each response, I wrote Response [ ] in the argument of the custom marker.
[System.Serializable, DisplayName("ResponseMarker")]
public class ResponseMarker : Marker, INotification
{
public Response[] Responses;
public PropertyName id
{
get
{
return new PropertyName("method");
}
}
public class ResponseMarkerReciever : MonoBehaviour, INotificationReceiver
{
MissionScript mission;
private void Awake()
{
mission = GetComponent<MissionScript>();
}
public void OnNotify(Playable origin, INotification notification, object context)
{
var element = notification as ResponseMarker;
if (element == null)
return;
mission.Response(element.Responses);
}
}
The problem is this object field, which doesn’t allow me to select objects in the scene from custom markers.
How can I access the objects in the scene from the custom marker response event?
I tired to make Response as ExposedReference like:
public ExposedReference<Response>[] Responses;
But received this compile error:
The type 'Response' cannot be used as type parameter 'T' in the generic type or method 'ExposedReference<T>'. There is no implicit reference conversion from 'Response' to 'UnityEngine.Object'.
Seems like only classes inherit Object can be exposed.
I took a video because it’s hard to explain what I’m trying to make.
When the Response marker is reached, the timeline is paused from the Mission Script side.
Select one of the three options to resume.
The reason I don’t use signals is that I can only give one Signal Emitter the same role in the timeline.
It is inefficient and difficult to manage to issue a new signal emitter each time it appears many times on the timeline and calls a different function each time.
Sorry, I forgot to show how my Response class is composed.
public class Response
{
public string ResponseKey;
public UnityEvent ResponseEvent = new UnityEvent();
}
ResponseKey is used to search any response dialogue text from CSV.
ResponseEvent is for the callbacks on each responses(ex: Increase the favorability of the character).
Exposing UnityEvent doesn’t look so easy,
but I somehow managed my Response class exposed by inheriting MonoBehaviour.
public class Response : MonoBehaviour
{
public string ResponseKey;
public UnityEvent ResponseEvent = new UnityEvent();
}
public class ResponseMarker : Marker, INotification
{
public ExposedReference<Response> Responses;
public PropertyName id
{
get
{
return new PropertyName("method");
}
}
}
I thought this will be fine, but when I try to access the member ResponseKey this error comes in: 'ExposedReference<Response>' does not contain a definition for 'ResponseKey'
Frankly, I don’t understand the concept of Exposed Reference intuitively, so I need to find an implementation that can be used as a reference from somewhere.
Alternatively, I think that it is also a way to handle only the ResponseKey string with the custom marker,
and prepare the corresponding UnityEvent on the MissionScript inspector of the object on the scene.