This commit is contained in:
2025-05-13 05:19:58 +03:00
parent 853edaf0b4
commit 472b2aee18
1034 changed files with 41844 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
using UnityEngine;
using System.Collections;
public class AiWaypoint : MonoBehaviour {
public float radius = 0.4f;
public Color color = new Color(0.2f, 0.2f, 1, 0.6f);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnDrawGizmos() {
AdvancedGizmo.DrawCircle(transform.position, Vector3.forward, radius, color);
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 11879864f36973b4b9097cbfd448b2db
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: fc00ec05a89da4ff695a4273715cd5ce, type: 3}
userData:
assetBundleName:
+6
View File
@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: d18f032676b70b845b5d1f39535e9f6b
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
@@ -0,0 +1,42 @@
using UnityEngine;
using System.Collections;
public enum BehaviorStatus {
Invalid,
Success,
Fail,
Running
};
public abstract class AiBehavior : MonoBehaviour {
public string behaviorName;
protected virtual void OnBegin(AiBlackboard blackboard) { }
protected virtual void OnEnd(AiBlackboard blackboard) { }
protected abstract BehaviorStatus OnExecute(AiBlackboard blackboard);
private BehaviorStatus _state = BehaviorStatus.Invalid;
public BehaviorStatus State {
get { return _state; }
}
public bool Running {
get { return _state == BehaviorStatus.Running; }
}
public BehaviorStatus Tick(AiBlackboard blackboard) {
if (_state != BehaviorStatus.Running) {
OnBegin(blackboard);
}
_state = OnExecute(blackboard);
if (_state == BehaviorStatus.Running) {
_state = BehaviorStatus.Success;
}
if (_state != BehaviorStatus.Running) {
OnEnd(blackboard);
}
return _state;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ac3489aca4eaca1438c296121ea6606f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,47 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class BlackboardVariables {
public static string LastEnemyPosition = "lastEnemyPosition";
public static string LastSound = "lastSound";
public static string LastSuspiciousTime = "lastSuspTime";
public static string Enemy = "enemy";
}
public class AiBlackboard : MonoBehaviour {
private Dictionary<string, object> _values = new Dictionary<string, object>();
public GameObject Obj {
get {
return (GameObject)_values["gameobject"];
}
}
public void SetValue(string key, object val) {
_values[key] = val;
}
/*public bool GetValue(string key, out object val) {
if (_values.ContainsKey(key)) {
val = _values[key];
return true;
}
val = null;
return false;
}*/
public bool GetValue<T>(string key, out T obj) {
if (_values.ContainsKey(key)) {
obj = (T)_values[key];
return true;
}
obj = default(T);
return false;
}
public bool RemoveValue(string key) {
return _values.Remove(key);
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b64878cdefd0e5b409d5bb0cbd88f2b0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class AiBlackboardDecorator : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8fda99ed7265d9447a016da7ea552c0a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,18 @@
using System;
using UnityEngine;
using System.Collections;
public abstract class AiComposite : AiBehavior {
public AiBehavior[] children;
public void Add(AiBehavior behavior) {
if (children == null || children.Length == 0) {
children = new AiBehavior[1];
children[0] = behavior;
}
else {
Array.Resize(ref children, children.Length + 1);
children[children.Length - 1] = behavior;
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7ff17649812f35546970a12bf331b117
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,6 @@
using UnityEngine;
using System.Collections;
public abstract class AiDecorator : AiBehavior {
public AiBehavior child;
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d5bf7cefe7649b64aa3bfba8a2240871
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;
public class AiInverter : AiDecorator {
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var result = child.Tick(blackboard);
if (result == BehaviorStatus.Success) {
return BehaviorStatus.Fail;
} else if (result == BehaviorStatus.Fail) {
return BehaviorStatus.Success;
} else {
return result;
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 393988bfa4e415c498546e68a6e1ff46
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 50453c57d72f4764f91cac3e9da6775d, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,45 @@
using UnityEngine;
using System.Collections;
public enum AiParallelPolicy {
Any,
All
}
public class AiParallel : AiComposite {
public AiParallelPolicy successPolicy = AiParallelPolicy.Any;
public AiParallelPolicy failurePolicy = AiParallelPolicy.All;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
int failCount = 0;
int successCount = 0;
foreach (var behavior in children) {
//if (behavior.Running) {
behavior.Tick(blackboard);
//}
if (behavior.State == BehaviorStatus.Success) {
++successCount;
if (successPolicy == AiParallelPolicy.Any) {
return BehaviorStatus.Success;
}
}
else if (behavior.State == BehaviorStatus.Fail) {
++failCount;
if (failurePolicy == AiParallelPolicy.Any) {
return BehaviorStatus.Fail;
}
}
}
if (failurePolicy == AiParallelPolicy.All && failCount == children.Length) {
return BehaviorStatus.Fail;
}
if (successPolicy == AiParallelPolicy.All && successCount == children.Length) {
return BehaviorStatus.Fail;
}
return BehaviorStatus.Running;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e69523706cb2fa24d94ca0a2ba3cfc83
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: c9ec39ec3da62a64d941014c71e7f028, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,32 @@
using UnityEngine;
using System.Collections;
public class AiRepeatDecorator : AiDecorator {
public int count = 1;
private int _counter;
public bool repeatForever;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
_counter = 0;
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var state = child.Tick(blackboard);
if (state == BehaviorStatus.Success) {
if (repeatForever) {
return BehaviorStatus.Running;
}
else {
_counter++;
if (_counter == count) {
return BehaviorStatus.Success;
} else {
return BehaviorStatus.Running;
}
}
}
return state;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a02e2a8ad2091bd48b7acd45fff4b3c6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d5935485dc5991449b53931f8c2e312, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections;
public class AiReturnFailure : AiDecorator {
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var childStatus = child.Tick(blackboard);
return (childStatus == BehaviorStatus.Fail || childStatus == BehaviorStatus.Success)
? BehaviorStatus.Fail
: childStatus;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d998bba05cd11ab4087e0ddf80721c8a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: b3ecdd4f2d60e5149ba02592143f517b, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,12 @@
using UnityEngine;
using System.Collections;
public class AiReturnSuccess : AiDecorator {
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var childStatus = child.Tick(blackboard);
return (childStatus == BehaviorStatus.Fail || childStatus == BehaviorStatus.Success)
? BehaviorStatus.Success
: childStatus;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 94bfc6ef33c4fa74dbad429a88d561d9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 72f177c027d95ac438d85c3a968f00e3, type: 3}
userData:
assetBundleName:
+28
View File
@@ -0,0 +1,28 @@
using UnityEngine;
using System.Collections;
public class AiRoot : AiBehavior {
public AiBehavior child;
public AiBlackboard blackboard;
private Health _health;
void Start() {
blackboard.SetValue("gameobject", gameObject);
_health = GetComponent<Health>();
}
void FixedUpdate() {
OnExecute(blackboard);
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (enabled && (_health == null || !_health.Dead)) {
if (child == null) {
Debug.LogWarning("AiRoot: child is null");
return BehaviorStatus.Invalid;
}
return child.Tick(blackboard);
}
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8e18ffee70d70d64a8dd9750b2751d89
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: ded096a5301fa644e8891d1f6101b751, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,32 @@
using UnityEngine;
using System.Collections;
public class AiSelector : AiComposite {
private int _currentId = 0;
protected override void OnBegin(AiBlackboard blackboard) {
_currentId = 0;
}
protected override void OnEnd(AiBlackboard blackboard) {
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (children == null || children.Length == 0) {
Debug.LogError("Broken behavior! No children!");
return BehaviorStatus.Invalid;
}
while(_currentId < children.Length) {
var current = children[_currentId];
var result = current.Tick(blackboard);
if (result != BehaviorStatus.Fail) {
return result;
}
_currentId++;
}
return BehaviorStatus.Fail;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e5804a06425c3ad4a8d15d809813993a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: bcabd2f1888c8f14ca23cb37f12fefb2, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,31 @@
using UnityEngine;
using System.Collections;
public class AiSequence : AiComposite {
private int _currentId = 0;
protected override void OnBegin(AiBlackboard blackboard) {
_currentId = 0;
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (children == null || children.Length == 0) {
Debug.LogError("Broken behavior! No children!");
return BehaviorStatus.Invalid;
}
//Debug.Log("Sequence: " + behaviorName);
while(_currentId < children.Length) {
var current = children[_currentId];
var result = current.Tick(blackboard);
if (result != BehaviorStatus.Success) {
return result;
}
_currentId++;
}
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: cbc50ac62b293274197389809d6f729c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 8acfd1a7d74af514c9cfa3c24b4744a8, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,9 @@
using UnityEngine;
using System.Collections;
public class AiUntilFailure : AiDecorator {
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var childStatus = child.Tick(blackboard);
return childStatus == BehaviorStatus.Fail ? BehaviorStatus.Success : BehaviorStatus.Running;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3d664e3d1f23ea647bbf57eb52207ad1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6f3711f476005504c9f518040eab635a, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,10 @@
using UnityEngine;
using System.Collections;
public class AiUntilSuccess : AiDecorator {
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var childStatus = child.Tick(blackboard);
return childStatus == BehaviorStatus.Success ? BehaviorStatus.Success : BehaviorStatus.Running;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7156873ba7e0ded4282c752529bc401b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: bbde1a7d7d1792a46937e629e84df4e0, type: 3}
userData:
assetBundleName:
+6
View File
@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: 091298dbbffdc354dacc39cb6f2fc17f
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
+19
View File
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
public class AiAim : AiBehavior {
private GameObject obj;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
obj = blackboard.Obj;
selfController = obj.GetComponent<HumanController>();
}
return selfController.PrepareItem() ? BehaviorStatus.Success : BehaviorStatus.Fail;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 703aed8d891f45d4a891c457267df9cb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+72
View File
@@ -0,0 +1,72 @@
using System.Linq;
using UnityEngine;
using System.Collections;
public class AiCanHitEnemy : AiBehavior {
private GameObject obj;
private Inventory inventory;
private HumanController selfController;
public LayerMask skipRaycast;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
blackboard.GetValue<GameObject>("gameobject", out obj);
inventory = obj.GetComponent<Inventory>();
selfController = obj.GetComponent<HumanController>();
}
PlayerController enemy;
blackboard.GetValue("enemy", out enemy);
if (enemy == null) {
return BehaviorStatus.Fail;
}
Vector3 right = obj.transform.localToWorldMatrix.MultiplyVector(Vector3.right).normalized;
var raycastDir = Mathf.Abs(enemy.transform.position.x - obj.transform.position.x) * right;
var p0 = obj.transform.position + Vector3.up * selfController.ArmsStandOffset;
var p1 = obj.transform.position + Vector3.up * selfController.ArmsCrouchOffset;
string crouchingName = "crouchToShoot";
if ( RaycastEnemy(p0, raycastDir, enemy)) {
blackboard.SetValue(crouchingName, false);
Debug.Log("WTF1");
return BehaviorStatus.Success;
} else if (RaycastEnemy(p1, raycastDir, enemy)) {
Debug.Log("WTF2");
blackboard.SetValue(crouchingName, true);
return BehaviorStatus.Success;
}
return BehaviorStatus.Fail;
}
private bool RaycastEnemy(Vector3 from, Vector3 d, PlayerController enemy) {
var hits = Physics2D.RaycastAll(from, d, 100, Physics2D.DefaultRaycastLayers & ~skipRaycast.value);
Debug.Log("Hits: " + hits.Length);
//find first collision which is not inside player head
int firstOutsideId = -1;
for (int i = 0; i < hits.Length; ++i) {
if (hits[i].fraction > 0.0f) {
firstOutsideId = i;
break;
}
}
Debug.Log("Hits name: " + hits[firstOutsideId].transform.name);
if (firstOutsideId >= 0) {
var hit = hits[firstOutsideId];
var g = hit.collider.GetComponent<PlayerController>();
if (g != null && g == enemy) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e63b0fdce85d3e24dafa3251136a3f0c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+24
View File
@@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
public class AiCancelAim : AiBehavior {
private GameObject obj;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
obj = blackboard.Obj;
selfController = obj.GetComponent<HumanController>();
}
if (!selfController.GunArmed) {
return BehaviorStatus.Fail;
}
selfController.UnprepareItem();
selfController.Crouch = false;
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b9f8f06b1ce7868419b3244bd9bd7b07
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+67
View File
@@ -0,0 +1,67 @@
using UnityEngine;
using System.Collections;
public class AiChase : AiBehavior {
public float chaseTimeout = 5;
private GameObject _obj;
private HumanController _selfController;
private bool _chasing;
public RandomSoundPlayer endChasingSound;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
if (_obj == null) {
_obj = blackboard.Obj;
_selfController = _obj.GetComponent<HumanController>();
}
}
private void OnEndChasing() {
Debug.Log("Begin chasing");
if (endChasingSound != null) {
endChasingSound.Play();
}
}
private void OnBeginChasing() {
Debug.Log("End chasing");
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
float time;
if (!blackboard.GetValue(BlackboardVariables.LastSuspiciousTime, out time)) {
return BehaviorStatus.Fail;
}
//check if chasing too long
if (Time.time - time >= chaseTimeout) {
if (_chasing) {
_chasing = false;
OnEndChasing();
}
return BehaviorStatus.Fail;
}
//do chase!
if (!_chasing) {
_chasing = true;
OnBeginChasing();
}
Vector3 chaseTarget;
if (blackboard.GetValue(BlackboardVariables.LastEnemyPosition, out chaseTarget)) {
if (_selfController != null) {
float dir = Mathf.Sign(chaseTarget.x - _obj.transform.position.x);
if (Mathf.Abs(chaseTarget.x - _obj.transform.position.x) > 0.3f) {
_selfController.UpdateMovement(dir * _selfController.maxWalkSpeed);
}
}
}
return BehaviorStatus.Success;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f00beff876f03384e8d2938e1e37b74f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
+16
View File
@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections;
public class AiDelay : AiBehavior {
public float delay = 1;
private float _startTime;
protected override void OnBegin(AiBlackboard blackboard) {
_startTime = Time.time;
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
return (_startTime + delay) > Time.time ? BehaviorStatus.Running : BehaviorStatus.Success;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f55a86bc81f2e5447b675e80b521b328
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 75cff1be3576d61429363834ca95e010, type: 3}
userData:
assetBundleName:
+30
View File
@@ -0,0 +1,30 @@
using UnityEngine;
using System.Collections;
public class AiEquipGun : AiBehavior {
private GameObject obj;
private Inventory inventory;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
blackboard.GetValue<GameObject>("gameobject", out obj);
inventory = obj.GetComponent<Inventory>();
selfController = obj.GetComponent<HumanController>();
}
if (selfController.GetSocket(ItemSocketType.Hands).AttachedItem == null) {
var weapon = inventory.QueryItem(null, "Gun", null);
if (weapon != null) {
//Debug.LogFormat("Character {0} equipped weapon {1}", obj.name, weapon.description.Name);
inventory.EquipItem(weapon);
}
else {
return BehaviorStatus.Fail;
}
}
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6ad8bdf70f1755c44b33fb4286544f22
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+75
View File
@@ -0,0 +1,75 @@
using System.Linq;
using UnityEngine;
using System.Collections;
public class AiFindEnemy : AiBehavior {
private GameObject obj;
private PlayerSensor sensor;
private HumanController selfController;
public LayerMask skipMask;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
if (obj == null) {
obj = blackboard.Obj;
sensor = obj.GetComponent<HumanoidAI>().viewSensor;
selfController = obj.GetComponent<HumanController>();
}
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
bool playerInCone = sensor.Player != null;
if (playerInCone) {
var enemyEyes = sensor.Player.eyes.transform.position;
var selfEyes = selfController.eyes.transform.position;
var from = new Vector3[] { selfEyes, selfEyes };
var to = new Vector3[] { enemyEyes, sensor.Player.transform.position };
for (int i = 0; i < 2; ++i) {
Debug.DrawLine(from[i], to[i], Color.gray);
}
for (int i = 0; i < 2; ++i) {
if (RaycastEnemy(from[i], to[i])) {
blackboard.SetValue(BlackboardVariables.Enemy, sensor.Player);
blackboard.SetValue(BlackboardVariables.LastEnemyPosition, sensor.Player.transform.position);
//Debug.Log("Raycast OK");
return BehaviorStatus.Success;
}
}
// Debug.Log("Raycast FAIL");
}
blackboard.SetValue(BlackboardVariables.Enemy, null);
return BehaviorStatus.Fail;
}
private bool RaycastEnemy(Vector3 from, Vector3 to) {
var hits = Physics2D.RaycastAll(from, (to - from).normalized, 100, (Physics2D.DefaultRaycastLayers & (~skipMask.value)));
//find first collision which is not inside player head
int firstOutsideId = -1;
for (int i = 0; i < hits.Length; ++i) {
if (hits[i].fraction > 0.0f) {
firstOutsideId = i;
break;
}
}
if (firstOutsideId >= 0) {
var hit = hits[firstOutsideId];
var g = hit.collider.GetComponent<PlayerController>();
if (g != null) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0a8a0b982bd08a5488a7c4999040b3e2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+15
View File
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class AiHitDetector : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4ff1b2e8d41c5ab46bfc53c0c3cb1252
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+29
View File
@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;
public class AiListenSounds : AiBehavior {
private AiSoundListener _listener;
private GameObject _obj;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
if (_obj == null) {
_obj = blackboard.Obj;
_listener = _obj.GetComponent<AiSoundListener>();
}
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var sound = _listener.LatestSound;
blackboard.SetValue(BlackboardVariables.LastSound, sound);
if (sound != null) {
blackboard.SetValue(BlackboardVariables.LastEnemyPosition, sound.transform.position);
blackboard.SetValue(BlackboardVariables.LastSuspiciousTime, Time.time);
}
return sound == null ? BehaviorStatus.Fail : BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7e1f1556b659a8f458973a7c12bdc793
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+37
View File
@@ -0,0 +1,37 @@
using UnityEngine;
using System.Collections;
public class AiPatrol : AiBehavior {
public AiWaypoint[] patrolPoints;
private int _targetPoint;
private GameObject targetObject;
private HumanController controller;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
//_targetPoint = 0;
blackboard.GetValue("gameobject", out targetObject);
controller = targetObject.GetComponent<HumanController>();
}
private void NextPoint() {
_targetPoint = (_targetPoint + 1)%patrolPoints.Length;
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var point = patrolPoints[_targetPoint];
var dir = (Vector2) point.transform.position - (Vector2) controller.transform.position;
if (controller.GetComponent<Health>().Dead) {
return BehaviorStatus.Success;
}
if (Mathf.Abs(dir.x) < 0.1f) {
NextPoint();
} else {
controller.UpdateMovement(Mathf.Sign(dir.x) * controller.maxWalkSpeed);
}
return BehaviorStatus.Running;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0689ea7abd9f480449a528cc05fb0c0c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
public class AiSaySomethingOnSound : AiBehavior {
public RandomSoundPlayer player;
private AiSound _lastSound;
private float _lastSloundTime;
public float minDelay = 3;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
AiSound sound;
blackboard.GetValue(BlackboardVariables.LastSound, out sound);
if (sound == null) {
return BehaviorStatus.Fail;
}
if (Time.time - _lastSloundTime >= minDelay) {
player.Play();
_lastSloundTime = Time.time;
Debug.Log("Saying!");
}
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 05fb3d4c5b2994e48a8d5836b3d82b3f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
+29
View File
@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;
public class AiUseItem : AiBehavior {
private GameObject obj;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
obj = blackboard.Obj;
selfController = obj.GetComponent<HumanController>();
}
var item = selfController.GetSocket(ItemSocketType.Hands).AttachedItem;
if (item == null) {
return BehaviorStatus.Fail;
}
bool shouldCrouch = false;
blackboard.GetValue<bool>("crouchToShoot", out shouldCrouch);
selfController.Crouch = shouldCrouch;
item.OnBeginUse();
item.OnEndUse();
return BehaviorStatus.Success;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4e969b77faa0f304abbd0a3faa55a3f2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName: