浏览代码

Added Events (#46)

/main
GitHub 4 年前
当前提交
22e24a82
共有 5 个文件被更改,包括 105 次插入0 次删除
  1. 1
      CHANGELOG.md
  2. 41
      Runtime/LevelScripting/Events/OnCollider2DEvent.cs
  3. 11
      Runtime/LevelScripting/Events/OnCollider2DEvent.cs.meta
  4. 41
      Runtime/LevelScripting/Events/OnTrigger2DEvent.cs
  5. 11
      Runtime/LevelScripting/Events/OnTrigger2DEvent.cs.meta

1
CHANGELOG.md


#### Added
* Added 2D On Collider/Trigger Events : `OnCollider2DEvent` / `OnTrigger2DEvent`
* Handle Drop in Callable Reorderable Lists : Dropped Callables components are added to the list. Dropped Game Objects will prompt a menu to select which callable to add.
#### Fixed

41
Runtime/LevelScripting/Events/OnCollider2DEvent.cs


using NaughtyAttributes;
using UnityEngine;
namespace GameplayIngredients.Events
{
[AddComponentMenu(ComponentMenu.eventsPath + "On Collider 2D Event")]
[RequireComponent(typeof(Collider2D))]
public class OnCollider2DEvent : EventBase
{
public Callable[] onCollisionEnter;
public Callable[] onCollisionExit;
public bool OnlyInteractWithTag = false;
[EnableIf("OnlyInteractWithTag")]
public string Tag = "Player";
private void OnCollisionEnter2D(Collision2D other)
{
if (OnlyInteractWithTag && other.collider.tag == Tag)
{
Callable.Call(onCollisionEnter, other.collider.gameObject);
}
if (!OnlyInteractWithTag)
{
Callable.Call(onCollisionEnter, other.collider.gameObject);
}
}
private void OnCollisionExit2D(Collision2D other)
{
if (OnlyInteractWithTag && other.collider.tag == Tag)
{
Callable.Call(onCollisionExit, other.collider.gameObject);
}
if (!OnlyInteractWithTag)
{
Callable.Call(onCollisionExit, other.collider.gameObject);
}
}
}
}

11
Runtime/LevelScripting/Events/OnCollider2DEvent.cs.meta


fileFormatVersion: 2
guid: 2a43a8b9fe55fc4488fc1a260b967a75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

41
Runtime/LevelScripting/Events/OnTrigger2DEvent.cs


using NaughtyAttributes;
using UnityEngine;
namespace GameplayIngredients.Events
{
[AddComponentMenu(ComponentMenu.eventsPath + "On Trigger 2D Event")]
[AdvancedHierarchyIcon("Packages/net.peeweek.gameplay-ingredients/Icons/Events/ic-event-trigger.png")]
public class OnTrigger2DEvent : EventBase
{
public Callable[] onTriggerEnter;
public Callable[] onTriggerExit;
public bool OnlyInteractWithTag = true;
[EnableIf("OnlyInteractWithTag")]
public string Tag = "Player";
private void OnTriggerEnter2D(Collider2D other)
{
if (OnlyInteractWithTag && other.tag == Tag )
{
Callable.Call(onTriggerEnter, other.gameObject);
}
if (!OnlyInteractWithTag)
{
Callable.Call(onTriggerEnter, other.gameObject);
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (OnlyInteractWithTag && other.tag == Tag )
{
Callable.Call(onTriggerExit, other.gameObject);
}
if (!OnlyInteractWithTag)
{
Callable.Call(onTriggerExit, other.gameObject);
}
}
}
}

11
Runtime/LevelScripting/Events/OnTrigger2DEvent.cs.meta


fileFormatVersion: 2
guid: 9ccd65356bce12944a7c235682457c21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6059a3dad39232d428c4045188ba78a7, type: 3}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存