Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

46 行
1.3 KiB

using System.Collections.Generic;
namespace GameplayIngredients.Interactions
{
public static class InteractionManager
{
public static IEnumerable<Interactive> interactives { get { return s_Interactives; } }
static List<Interactive> s_Interactives = new List<Interactive>();
public static void RegisterInteractive(Interactive interactive)
{
s_Interactives.Add(interactive);
}
public static void RemoveInteractive(Interactive interactive)
{
s_Interactives.Remove(interactive);
}
public static void Interact(InteractiveUser user)
{
foreach(var interactive in GetCandidates(user))
{
if (interactive.Interact(user))
break;
}
}
public static Interactive[] GetCandidates(InteractiveUser user)
{
List<Interactive> candidates = new List<Interactive>();
foreach(var interactive in s_Interactives)
{
// Filter interactives at user's reach
if (interactive.CanInteract(user))
candidates.Add(interactive);
}
return user.SortCandidates(candidates.ToArray());
}
}
}