浏览代码

Added ReachPositionRig Local Space option / StateMachine button to generate Set State Actions

/main
Thomas ICHÉ 4 年前
当前提交
c43c36fa
共有 3 个文件被更改,包括 47 次插入2 次删除
  1. 2
      CHANGELOG.md
  2. 19
      Runtime/Ingredients/Rigs/ReachPositionRig.cs
  3. 28
      Runtime/Ingredients/StateMachine/StateMachine.cs

2
CHANGELOG.md


- Added API Access to the Link Game View Camera object
- Added Valid/Invalid paths for Platform Logic
- Added Local Space control for ReachPositionRig
- Added "Update SetStateAction" Button in State Machine components to populate the game object with Set State Actions
#### Fixed

19
Runtime/Ingredients/Rigs/ReachPositionRig.cs


[Header("Target")]
[SerializeField]
[InfoBox("Target needs to have the same parent as the current game object", InfoBoxType.Warning, "warnLocalParent")]
public bool inLocalSpace = false;
[Header("On Reach Position")]
[ReorderableList]

bool m_PositionReached = false;
bool warnLocalParent()
{
return m_Target != null && m_Target.transform.parent != transform.parent;
}
if(Vector3.Distance(transform.position , m_Target.position) < ReachSnapDistance)
Vector3 position = inLocalSpace ? transform.localPosition : transform.position;
Vector3 targetPosition = inLocalSpace ? m_Target.localPosition : m_Target.position;
if (Vector3.Distance(position, targetPosition) < ReachSnapDistance)
transform.position = m_Target.position;
if(inLocalSpace)
transform.localPosition = targetPosition;
else
transform.position = targetPosition;
if(!m_PositionReached)
{
Callable.Call(OnReachPosition, this.gameObject);

28
Runtime/Ingredients/StateMachine/StateMachine.cs


using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using GameplayIngredients.Actions;
namespace GameplayIngredients.StateMachines
{

foreach(var state in States)
{
state.gameObject.SetActive(state == States.FirstOrDefault(o => o.StateName == DefaultState));
}
}
[Button("Create/Update SetStateAction Components")]
private void UpdateSetStateActionComponents()
{
var components = this.GetComponents<SetStateAction>();
foreach (var state in States)
{
if (!components.Any(o => o.state == state.StateName))
{
var action = gameObject.AddComponent<SetStateAction>();
action.state = state.StateName;
action.StateMachine = this;
}
}
var todelete = GetComponents<SetStateAction>().Where(a => !States.Any(s => s.StateName == a.state)).ToArray();
for (int i = 0; i < todelete.Length; i++)
{
DestroyImmediate(todelete[i]);
}
components = this.GetComponents<SetStateAction>();
foreach(var action in components)
{
action.Name = $"Set State {action.state}";
}
}

正在加载...
取消
保存