浏览代码

Base Work on State Machines + Added LookAt Rig

/main
Thomas ICHÉ 6 年前
当前提交
8613be5e
共有 9 个文件被更改,包括 140 次插入20 次删除
  1. 41
      Runtime/Rigs/FollowPositionRig.cs
  2. 18
      Runtime/Rigs/LookAtRig.cs
  3. 11
      Runtime/Rigs/LookAtRig.cs.meta
  4. 8
      Runtime/StateMachine.meta
  5. 17
      Runtime/StateMachine/State.cs
  6. 11
      Runtime/StateMachine/State.cs.meta
  7. 43
      Runtime/StateMachine/StateMachine.cs
  8. 11
      Runtime/StateMachine/StateMachine.cs.meta

41
Runtime/Rigs/FollowPositionRig.cs


using System.Collections;
using System.Collections.Generic;
public class FollowPositionRig : MonoBehaviour
namespace NaughtyAttributes.Rigs
public Transform target => m_Target;
public class FollowPositionRig : MonoBehaviour
{
public Transform target => m_Target;
[SerializeField]
protected Transform m_Target;
public float Dampen = 1.0f;
public float MaximumVelocity = 1.0f;
[SerializeField]
protected Transform m_Target;
public float Dampen = 1.0f;
public float MaximumVelocity = 1.0f;
void Update()
{
if(m_Target != null)
{
var transform = gameObject.transform;
var delta = m_Target.position - transform.position;
var speed = Time.deltaTime * Mathf.Min((Dampen * delta.magnitude), MaximumVelocity);
gameObject.transform.position += delta.normalized * speed;
}
}
void Update()
{
if(m_Target != null)
public void SetTarget(Transform target)
var transform = gameObject.transform;
var delta = m_Target.position - transform.position;
var speed = Time.deltaTime * Mathf.Min((Dampen * delta.magnitude), MaximumVelocity);
gameObject.transform.position += delta.normalized * speed;
m_Target = target;
}
public void SetTarget(Transform target)
{
m_Target = target;
}

18
Runtime/Rigs/LookAtRig.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NaughtyAttributes.Rigs
{
public class LookAtRig : MonoBehaviour
{
public Transform LookAtTarget;
public Vector3 UpVector = Vector3.up;
void Update()
{
if (LookAtTarget != null)
transform.LookAt(LookAtTarget, UpVector);
}
}
}

11
Runtime/Rigs/LookAtRig.cs.meta


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

8
Runtime/StateMachine.meta


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

17
Runtime/StateMachine/State.cs


using NaughtyAttributes;
using UnityEngine;
namespace GameplayIngredients.StateMachines
{
public class State : MonoBehaviour
{
public string StateName = "State";
[ReorderableList]
public Callable[] OnStateEnter;
[ReorderableList]
public Callable[] OnStateExit;
[ReorderableList]
public Callable[] OnStateUpdate;
}
}

11
Runtime/StateMachine/State.cs.meta


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

43
Runtime/StateMachine/StateMachine.cs


using NaughtyAttributes;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.StateMachines
{
public class StateMachine : MonoBehaviour
{
public State DefaultState;
[ReorderableList]
public State[] States;
State m_CurrentState;
void Start()
{
SetState(DefaultState.StateName);
}
public void SetState(string stateName)
{
State newState = States.First(o => o.StateName == stateName);
if(newState != null)
{
if (m_CurrentState != null)
Callable.Call(m_CurrentState.OnStateExit, gameObject);
m_CurrentState = newState;
Callable.Call(m_CurrentState.OnStateEnter, gameObject);
}
}
public void Update()
{
if (m_CurrentState != null)
Callable.Call(m_CurrentState.OnStateUpdate, this.gameObject);
}
}
}

11
Runtime/StateMachine/StateMachine.cs.meta


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