IGvrEventExecutor.cs
3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//-----------------------------------------------------------------------
// <copyright file="IGvrEventExecutor.cs" company="Google Inc.">
// Copyright 2017 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-----------------------------------------------------------------------
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>Provides an interface for executing events for `IEventSystemHandler`.</summary>
public interface IGvrEventExecutor
{
/// <summary>Execute the event of type `T : IEventSystemHandler` on the game object.</summary>
/// <remarks>
/// The event will be executed on all components on the game object that can handle it.
/// </remarks>
/// <param name="target">Target game object.</param>
/// <param name="eventData">Data associated with the executing event.</param>
/// <param name="functor">Function to execute on the game object components.</param>
/// <typeparam name="T">An interface with methods for handling events.</typeparam>
/// <returns>A value indicating whether the delegate successfully executed.</returns>
bool Execute<T>(GameObject target,
BaseEventData eventData,
ExecuteEvents.EventFunction<T> functor)
where T : IEventSystemHandler;
/// <summary>
/// Recurse up the hierarchy calling `Execute` until there is a game object that can handle the
/// event.
/// </summary>
/// <remarks>
/// See https://docs.unity3d.com/2017.4/Documentation/ScriptReference/EventSystems.ExecuteEvents.ExecuteHierarchy.html.
/// </remarks>
/// <param name="root">Start game object for search.</param>
/// <param name="eventData">Data associated with the executing event.</param>
/// <param name="callbackFunction">Function to execute on the game object components.</param>
/// <typeparam name="T">An interface with methods for handling events.</typeparam>
/// <returns>GameObject Game object that handled the event.</returns>
GameObject ExecuteHierarchy<T>(GameObject root,
BaseEventData eventData,
ExecuteEvents.EventFunction<T> callbackFunction)
where T : IEventSystemHandler;
/// @note Traversal is performed upwards from the target object, not down.
/// <summary>
/// Traverse the object hierarchy starting at root, and return the game object which implements
/// the event handler of type `T`.
/// </summary>
/// <param name="root">The root object to which to send event triggers.</param>
/// <typeparam name="T">An interface with methods for handling events.</typeparam>
/// <returns>The event handler.</returns>
GameObject GetEventHandler<T>(GameObject root)
where T : IEventSystemHandler;
}