112 lines
2.3 KiB
C#
112 lines
2.3 KiB
C#
using BehaviorDesigner.Runtime;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using UnityEngine;
|
|
|
|
public class FishCheckDirectionBoilie : Action
|
|
{
|
|
private Fish fish;
|
|
|
|
private float nextDirectionChange;
|
|
|
|
public SharedGameObject target;
|
|
|
|
private Vector3 selectedPoint;
|
|
|
|
private Boilie boilie;
|
|
|
|
[HideInInspector]
|
|
public new Transform transform;
|
|
|
|
public override void OnStart()
|
|
{
|
|
transform = GetComponent<Transform>();
|
|
base.OnStart();
|
|
fish = transform.GetComponent<Fish>();
|
|
nextDirectionChange = 0f;
|
|
boilie = target.Value.GetComponentInParent<Boilie>();
|
|
boilie.fishCounter++;
|
|
}
|
|
|
|
public override void OnEnd()
|
|
{
|
|
if ((bool)boilie)
|
|
{
|
|
boilie.fishCounter--;
|
|
}
|
|
boilie = null;
|
|
base.OnEnd();
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (Time.timeScale == 0f)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
if (Fish.disableLogic2)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
IsInTrigger();
|
|
if (fish.IsUnderGround() || (!fish.isFighting && fish.TerrainCollision()))
|
|
{
|
|
if (fish.debugLog)
|
|
{
|
|
Debug.Log("dir change");
|
|
}
|
|
fish.targetDirection = (fish.Origin - transform.position).normalized;
|
|
nextDirectionChange = Time.time + Random.Range(1f, 2f);
|
|
}
|
|
else if (Time.time > nextDirectionChange && !fish.isSeeingBait)
|
|
{
|
|
SelectBoilieDirection();
|
|
nextDirectionChange = Time.time + Random.Range(1f, 2f);
|
|
fish.UpdateTargetSpeed();
|
|
}
|
|
if (fish.isInBoilieTrigger)
|
|
{
|
|
boilie.Eat(0.09f * Time.deltaTime);
|
|
}
|
|
if (target.Value == null)
|
|
{
|
|
boilie = null;
|
|
return TaskStatus.Failure;
|
|
}
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
public void IsInTrigger()
|
|
{
|
|
if (boilie == null)
|
|
{
|
|
fish.isInBoilieTrigger = false;
|
|
}
|
|
else
|
|
{
|
|
fish.isInBoilieTrigger = boilie.attractCollider.bounds.Contains(fish.transform.position);
|
|
}
|
|
}
|
|
|
|
private void SelectBoilieDirection()
|
|
{
|
|
if (target.Value == null)
|
|
{
|
|
Debug.Log("no target");
|
|
}
|
|
else if ((bool)boilie.attractCollider)
|
|
{
|
|
selectedPoint = boilie.transform.position + new Vector3(0f, 1f, 0f);
|
|
Vector3 normalized = (selectedPoint - fish.transform.position).normalized;
|
|
if (fish.debugLog)
|
|
{
|
|
Debug.Log("change dir from " + fish.targetDirection.ToString() + " to " + normalized.ToString() + " p: " + selectedPoint.ToString() + " f: " + fish.transform.position.ToString());
|
|
}
|
|
fish.targetDirection = normalized;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("no collider in boilie obj");
|
|
}
|
|
}
|
|
}
|