Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
using System.Collections.Generic;
using UnityEngine;
namespace Unity.Extensions
{
public static class GameObjectExtensions
{
public static IEnumerable<TComponent> SelectComponents<TComponent>(this IEnumerable<GameObject> source) where TComponent : Component
{
foreach (var go in source)
{
var component = go.GetComponent<TComponent>();
if (component == null)
continue;
yield return component;
}
}
public static TComponent FirstOrDefaultComponent<TComponent>(this IEnumerable<GameObject> source) where TComponent : Component
{
foreach (var go in source)
{
var component = go.GetComponent<TComponent>();
if (component == null)
continue;
return component;
}
return default(TComponent);
}
}
}
Owner

yKimisaki commented Jan 3, 2016

public void OnDrag(PointerEventData eventData)
{
    var hoges = eventData.hovered.SelectComponents<HogeBehaviour>();
    // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment