safety checks

This commit is contained in:
Glence 2023-03-26 20:38:03 +08:00
parent 0f9afc2a18
commit 2abb1ce697
2 changed files with 65 additions and 66 deletions

View File

@ -36,9 +36,10 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
[NonSerialized] [NonSerialized]
public IEnumerable<Transform> patrolPointPool; public IEnumerable<Transform> patrolPointPool;
private Transform transform;
public void Reset() public void Reset()
{ {
Transform transform = GetComponent<Transform>();
StateMachine machine = GetScript<StateMachine>(); StateMachine machine = GetScript<StateMachine>();
if (transform && machine) if (transform && machine)
{ {
@ -68,11 +69,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
AudioHandler.audioClipHandlers["HO_footsteps"] = SHADE.Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps"); AudioHandler.audioClipHandlers["HO_footsteps"] = SHADE.Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps");
patrolPointPool = patrolPointParent.GetComponentsInChildren<Transform>(); patrolPointPool = patrolPointParent.GetComponentsInChildren<Transform>();
Transform transform = GetComponent<Transform>(); transform = GetComponent<Transform>();
if (transform)
{
startPos = transform.GlobalPosition;
}
atk = false; atk = false;
@ -81,6 +78,8 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
protected override void start() protected override void start()
{ {
//attackHitbox.SetActive(false); //attackHitbox.SetActive(false);
if (transform)
startPos = transform.GlobalPosition;
} }

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace SHADE_Scripting.UI namespace SHADE_Scripting.UI
{ {
public class SingleScaleBounce: Script public class SingleScaleBounce : Script
{ {
[NonSerialized] [NonSerialized]
TweenThread thread; TweenThread thread;
@ -23,10 +23,12 @@ namespace SHADE_Scripting.UI
[NonSerialized] [NonSerialized]
private bool scaleUp = false; private bool scaleUp = false;
private Transform trans;
protected override void awake() protected override void awake()
{ {
Transform trans = GetComponent<Transform>(); trans = GetComponent<Transform>();
if(trans != null) if (trans != null)
{ {
defaultScale = trans.LocalScale; defaultScale = trans.LocalScale;
} }
@ -35,15 +37,16 @@ namespace SHADE_Scripting.UI
protected override void start() protected override void start()
{ {
thread = TweenManager.CreateTweenThread(0.0f,1.0f,1.0f,EASING_METHOD.EASE_IN_SINE); if(thread != null)
thread = TweenManager.CreateTweenThread(0.0f, 1.0f, 1.0f, EASING_METHOD.EASE_IN_SINE);
} }
protected override void update() protected override void update()
{ {
if(scaleUp) if (scaleUp)
{ {
if(thread.IsCompleted()) if (thread != null && thread.IsCompleted())
{ {
scaleUp = false; scaleUp = false;
thread.duration = durationDown; thread.duration = durationDown;
@ -51,22 +54,19 @@ namespace SHADE_Scripting.UI
} }
} }
Transform trans = GetComponent<Transform>(); if (trans && thread != null)
if(trans != null)
{
trans.LocalScale = defaultScale * thread.GetValue(); trans.LocalScale = defaultScale * thread.GetValue();
} }
}
public void ScaleBounceOnce() public void ScaleBounceOnce()
{ {
scaleUp = true; scaleUp = true;
if (thread != null)
{
thread.duration = durationUp; thread.duration = durationUp;
thread.Reset(1.0f, scaleSize); thread.Reset(1.0f, scaleSize);
} }
}
} }