浏览代码

Base code for interactives (not working atm)

/main
Thomas ICHÉ 6 年前
当前提交
d1141af9
共有 12 个文件被更改,包括 201 次插入0 次删除
  1. 8
      Runtime/Interactive.meta
  2. 18
      Runtime/Interactive/BasicInteractive.cs
  3. 11
      Runtime/Interactive/BasicInteractive.cs.meta
  4. 19
      Runtime/Interactive/BasicInteractiveUser.cs
  5. 11
      Runtime/Interactive/BasicInteractiveUser.cs.meta
  6. 39
      Runtime/Interactive/Interactive.cs
  7. 11
      Runtime/Interactive/Interactive.cs.meta
  8. 46
      Runtime/Interactive/InteractiveManager.cs
  9. 11
      Runtime/Interactive/InteractiveManager.cs.meta
  10. 16
      Runtime/Interactive/InteractiveUser.cs
  11. 11
      Runtime/Interactive/InteractiveUser.cs.meta

8
Runtime/Interactive.meta


fileFormatVersion: 2
guid: a70103260c37cf14586e9ce8b679f0bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

18
Runtime/Interactive/BasicInteractive.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Interactive
{
public class BasicInteractive : Interactive
{
[Header("Settings")]
public float Distance = 1.0f;
public Collider Collider;
protected override bool CanInteract(InteractiveUser user)
{
return Vector3.Distance(user.transform.position, this.transform.position) < Distance;
}
}
}

11
Runtime/Interactive/BasicInteractive.cs.meta


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

19
Runtime/Interactive/BasicInteractiveUser.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Interactive
{
public class BasicInteractiveUser : InteractiveUser
{
public Camera Camera;
public float InteractionAngle = 60.0f;
public override bool CanInteract(Interactive interactive)
{
Vector3 toInteractive = (interactive.transform.position - Camera.transform.position).normalized;
return Mathf.Acos(Vector3.Dot(toInteractive, Camera.transform.forward)) < InteractionAngle;
}
}
}

11
Runtime/Interactive/BasicInteractiveUser.cs.meta


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

39
Runtime/Interactive/Interactive.cs


using GameplayIngredients.Events;
using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Interactive
{
public abstract class Interactive : EventBase
{
[Header("Events")]
[SerializeField, ReorderableList]
protected Callable OnInteract;
protected virtual void OnEnable()
{
Manager.Get<InteractiveManager>().RegisterInteractive(this);
}
protected virtual void OnDisable()
{
Manager.Get<InteractiveManager>().RemoveInteractive(this);
}
public bool Interact(InteractiveUser user)
{
if (user.CanInteract(this) && CanInteract(user))
{
Callable.Call(OnInteract);
return true;
}
else
return false;
}
protected abstract bool CanInteract(InteractiveUser user);
}
}

11
Runtime/Interactive/Interactive.cs.meta


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

46
Runtime/Interactive/InteractiveManager.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Interactive
{
public class InteractiveManager : Manager
{
List<Interactive> m_Interactives;
private void Awake()
{
m_Interactives = new List<Interactive>();
}
public void RegisterInteractive(Interactive interactive)
{
m_Interactives.Add(interactive);
}
public void RemoveInteractive(Interactive interactive)
{
m_Interactives.Remove(interactive);
}
public void Interact(InteractiveUser user)
{
foreach(var interactive in GetCandidates(user))
{
if (interactive.Interact(user))
break;
}
}
private Interactive[] GetCandidates(InteractiveUser user)
{
List<Interactive> candidates = new List<Interactive>();
foreach(var interactive in m_Interactives)
{
if (user.CanInteract(interactive))
candidates.Add(interactive);
}
return candidates.ToArray();
}
}
}

11
Runtime/Interactive/InteractiveManager.cs.meta


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

16
Runtime/Interactive/InteractiveUser.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Interactive
{
public abstract class InteractiveUser : MonoBehaviour
{
public abstract bool CanInteract(Interactive interactive);
protected void Interact()
{
Manager.Get<InteractiveManager>().Interact(this);
}
}
}

11
Runtime/Interactive/InteractiveUser.cs.meta


fileFormatVersion: 2
guid: 3aead24411f706b4dab50dabfcdc79d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存