Browse Source

added searchlight chase v2

master
Sagittaeri 7 years ago
parent
commit
c0819f5fa6
9 changed files with 351 additions and 0 deletions
  1. +56
    -0
      IronToad_UnityProject/Assets/Scripts/AlertController.cs
  2. +12
    -0
      IronToad_UnityProject/Assets/Scripts/AlertController.cs.meta
  3. +107
    -0
      IronToad_UnityProject/Assets/Scripts/Lighthouse.cs
  4. +12
    -0
      IronToad_UnityProject/Assets/Scripts/Lighthouse.cs.meta
  5. +111
    -0
      IronToad_UnityProject/Assets/Scripts/Searchlight.cs
  6. +12
    -0
      IronToad_UnityProject/Assets/Scripts/Searchlight.cs.meta
  7. +20
    -0
      IronToad_UnityProject/Assets/Scripts/TestMoveController.cs
  8. +12
    -0
      IronToad_UnityProject/Assets/Scripts/TestMoveController.cs.meta
  9. +9
    -0
      IronToad_UnityProject/Assets/Sound.meta

+ 56
- 0
IronToad_UnityProject/Assets/Scripts/AlertController.cs View File

@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AlertController : MonoBehaviour
{
public Text text;
public Slider slider;
public float hideTime = 5f;
private Vector3 originalPos;
private float lastSpotted;
void Start ()
{
NotificationServer.register("spotted boat", spottedBoat);
NotificationServer.register("lost boat", lostBoat);
originalPos = text.rectTransform.anchoredPosition3D;
}
public void spottedBoat()
{
LeanTween.cancel(text.gameObject, false);
LeanTween.cancel(slider.gameObject, false);
lastSpotted = Time.timeSinceLevelLoad;
NotificationServer.notify("show AlertText");
text.text = "hide!";
setTimer(0f);
}
public void lostBoat()
{
LeanTween.cancel(text.gameObject, false);
LeanTween.cancel(slider.gameObject, false);
NotificationServer.notify("show AlertText");
NotificationServer.notify("show AlertTimer");
text.text = "stay hidden";
LeanTween.value(slider.gameObject, 0f, 1f, hideTime).setOnUpdate((float val)=>{
setTimer(val);
}).setOnComplete(()=>{
NotificationServer.notify("hide AlertTimer");
NotificationServer.notify("statechange Searchlight returning");
text.text = "hidden...";
LeanTween.delayedCall(text.gameObject, 2f, ()=>{
NotificationServer.notify("hide AlertText");
});
});
}
public void setTimer(float val)
{
slider.value = val;
}
}

+ 12
- 0
IronToad_UnityProject/Assets/Scripts/AlertController.cs.meta View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 89a715dd2260f413b89b4b9cdb979f3c
timeCreated: 1485005279
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 107
- 0
IronToad_UnityProject/Assets/Scripts/Lighthouse.cs View File

@ -0,0 +1,107 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BansheeGz.BGSpline.Components;
using BansheeGz.BGSpline.Curve;
public class Lighthouse : MonoBehaviour
{
public BGCurve splineCurve;
public List<float> splineDistantPoints = new List<float>();
public float speed = 200f;
public float timePadding = 0.5f;
public float timeBetweenPoints = 3f;
public AnimationCurve animationCurve;
private BGCcCursor splineCursor;
private BGCcCursorObjectTranslate splineObjectTranslate;
private int targetPoint = 0;
private bool reverseDirection = false;
private bool midpoint = false;
void Start()
{
splineCursor = splineCurve.GetComponent<BGCcCursor>();
splineObjectTranslate = splineCurve.GetComponent<BGCcCursorObjectTranslate>();
if (splineDistantPoints == null || splineDistantPoints.Count == 0)
{
splineDistantPoints.Add(0f);
for (int i=1; i<splineCurve.PointsCount; i++)
{
BGCurvePointI point = splineCurve.Points[i];
float distance = 0f;
Vector3 temp = splineCursor.Math.CalcPositionByClosestPoint(point.PositionWorld, out distance);
splineDistantPoints.Add(distance);
}
splineDistantPoints.Add(splineCursor.Math.GetDistance());
}
splineCursor.Distance = 0f;
moveToNextPoint();
NotificationServer.register("statechange Searchlight", searchlightStateChanged);
}
public void moveToNextPoint()
{
LeanTween.delayedCall(gameObject, timeBetweenPoints, ()=>{
if (reverseDirection)
targetPoint--;
else
targetPoint++;
if (targetPoint >= splineDistantPoints.Count)
{
if (splineCurve.Closed)
{
targetPoint = 1;
splineCursor.Distance = 0f;
}
else
{
targetPoint = splineDistantPoints.Count - 2;
reverseDirection = !reverseDirection;
}
}
midpoint = true;
float start = splineCursor.Distance;
float end = splineDistantPoints[targetPoint];
float distance = Mathf.Abs(end - start);
LeanTween.value(gameObject, start, end, distance / speed + timePadding).setOnUpdate((float val)=>{
splineCursor.Distance = val;
}).setEase(animationCurve).setOnComplete(()=>{
midpoint = false;
moveToNextPoint();
});
});
}
public void searchlightStateChanged()
{
LeanTween.cancel(gameObject, false);
if (Searchlight.state == Searchlight.SearchState.Chasing)
{
splineObjectTranslate.enabled = false;
}
else if (Searchlight.state == Searchlight.SearchState.Returning)
{
splineObjectTranslate.enabled = false;
Vector3 start = splineObjectTranslate.ObjectToManipulate.position;
Vector3 end = splineCursor.CalculatePosition();
float distance = (end - start).magnitude;
LeanTween.move(splineObjectTranslate.ObjectToManipulate.gameObject, end, distance / speed + timePadding).setEase(animationCurve).setOnComplete(()=>{
splineObjectTranslate.enabled = true;
if (midpoint)
{
if (reverseDirection)
targetPoint++;
else
targetPoint--;
}
moveToNextPoint();
NotificationServer.notify("statechange Searchlight safe");
});
}
}
}

+ 12
- 0
IronToad_UnityProject/Assets/Scripts/Lighthouse.cs.meta View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e529d146693e04d5983a4fbbb25de5ab
timeCreated: 1484975905
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 111
- 0
IronToad_UnityProject/Assets/Scripts/Searchlight.cs View File

@ -0,0 +1,111 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Searchlight : MonoBehaviour
{
public enum SearchState
{
Spline,
Chasing,
Returning
}
public float speed = 500f;
public float timePadding = 0.5f;
public float timeBetweenChase = 0.5f;
public float randomFactor = 50f;
public AnimationCurve animationCurve;
[HideInInspector]
public bool isTriggering = false;
public static SearchState state = SearchState.Spline;
public static Collider chased;
private static List<Searchlight> instants = new List<Searchlight>();
public static bool isTriggeringAtLeastOne()
{
foreach (Searchlight sl in instants)
{
if (sl.isTriggering)
return true;
}
return false;
}
void Awake()
{
NotificationServer.register("statechange Searchlight", stateChanged);
NotificationServer.register("statechange Searchlight safe", stateSafe);
NotificationServer.register("statechange Searchlight returning", stateReturning);
if (!instants.Contains(this))
instants.Add(this);
}
void OnTriggerEnter(Collider other)
{
chased = other;
isTriggering = true;
if (state != SearchState.Chasing)
{
state = SearchState.Chasing;
NotificationServer.notify("statechange Searchlight");
NotificationServer.notify("chasing boat");
}
NotificationServer.notify("spotted boat");
}
void OnTriggerExit(Collider other)
{
isTriggering = false;
if (state == SearchState.Chasing && !isTriggeringAtLeastOne())
{
// chased = null;
// state = SearchState.Returning;
// NotificationServer.notify("statechange Searchlight");
NotificationServer.notify("lost boat");
}
}
public void stateSafe()
{
state = SearchState.Spline;
// NotificationServer.notify("statechange Searchlight");
}
public void stateReturning()
{
state = SearchState.Returning;
NotificationServer.notify("statechange Searchlight");
}
public void stateChanged()
{
LeanTween.cancel(gameObject, false);
if (state == SearchState.Chasing)
LeanTween.move(gameObject, chased.transform.position, 0.5f).setEase(animationCurve).setOnComplete(chase);
}
public void chase()
{
if (isTriggering)
{
LeanTween.delayedCall(gameObject, timeBetweenChase, chase);
}
else
{
LeanTween.delayedCall(gameObject, timeBetweenChase, ()=>{
Vector3 start = transform.localPosition;
Vector3 end = chased.transform.localPosition
+ Vector3.right * Random.Range(-randomFactor, randomFactor)
+ Vector3.forward * Random.Range(-randomFactor, randomFactor);
float distance = (end - start).magnitude;
LeanTween.value(gameObject, 0f, 1f, distance / speed + timePadding).setOnUpdate((float val)=>{
transform.localPosition = start + (end-start)*val;
}).setEase(animationCurve).setOnComplete(chase);
});
}
}
}

+ 12
- 0
IronToad_UnityProject/Assets/Scripts/Searchlight.cs.meta View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 51b93e628614140229e5d1f43186a375
timeCreated: 1484985371
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 20
- 0
IronToad_UnityProject/Assets/Scripts/TestMoveController.cs View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestMoveController : MonoBehaviour
{
public float speed = 100f;
void Update ()
{
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
transform.Translate(Vector3.back * Time.deltaTime * speed);
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
transform.Translate(Vector3.left * Time.deltaTime * speed);
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
transform.Translate(Vector3.forward * Time.deltaTime * speed);
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
transform.Translate(Vector3.right * Time.deltaTime * speed);
}
}

+ 12
- 0
IronToad_UnityProject/Assets/Scripts/TestMoveController.cs.meta View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 89a55db40871a4d4c920b5f69d6bfc03
timeCreated: 1484997652
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 9
- 0
IronToad_UnityProject/Assets/Sound.meta View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0fbabcae9313543ffbf1429aeac3664d
folderAsset: yes
timeCreated: 1484963877
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save