add ckg
plantilla base para movimiento básico
This commit is contained in:
9
Assets/Game Kit Controller/Scripts/AI.meta
Normal file
9
Assets/Game Kit Controller/Scripts/AI.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 354c1d19c726cc34f9ccc38562b35e6a
|
||||
folderAsset: yes
|
||||
timeCreated: 1484578862
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
614
Assets/Game Kit Controller/Scripts/AI/AIAroundManager.cs
Normal file
614
Assets/Game Kit Controller/Scripts/AI/AIAroundManager.cs
Normal file
@@ -0,0 +1,614 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AIAroundManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool AIManagerEnabled = true;
|
||||
|
||||
public float maxDistanceToSetStateOnAI;
|
||||
|
||||
public bool onlyStoreAIAndIgnoreToSetStates;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Management Settings")]
|
||||
[Space]
|
||||
|
||||
public float timeToAssignAttackToNextAI;
|
||||
|
||||
[Space]
|
||||
[Header ("Dynamic Obstacle Detection Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useDynamicObstacleDetection;
|
||||
|
||||
public bool useRandomWalkEnabled;
|
||||
|
||||
public float minObstacleRotation = 45;
|
||||
public float mediumObstacleRotation = 65;
|
||||
public float maximumObstacleRotation = 85;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool sendInfoToTurnBasedCombatSystemEnabled;
|
||||
public string mainTurnBasedCombatSystemPanelName = "Turn Combat System";
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool pauseAttacksOnAllAIAround;
|
||||
|
||||
public bool AIManagerActive;
|
||||
|
||||
public int currentTargetsAmount;
|
||||
|
||||
public int lastAIAttackAssignedIndex = -1;
|
||||
|
||||
public List<Transform> charactersAround = new List<Transform> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Events")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnTargetsChange;
|
||||
public UnityEvent eventOnTargetsDetected;
|
||||
public UnityEvent eventOnTargetsRemoved;
|
||||
|
||||
public bool useEventOnFirstTargetDetected;
|
||||
public UnityEvent eventOnFirstTargetDetected;
|
||||
|
||||
public bool useEventOnLastTargetRemoved;
|
||||
public UnityEvent eventOnLastTargetRemoved;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public turnBasedCombatSystem mainTurnBasedCombatSystem;
|
||||
|
||||
bool mainTurnBasedCombatSystemLocated;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
List<findObjectivesSystem> findObjectivesSystemList = new List<findObjectivesSystem> ();
|
||||
|
||||
float lastTimeAttackStateAssigned;
|
||||
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (Time.time > lastTimeAttackStateAssigned + timeToAssignAttackToNextAI) {
|
||||
updateAttackAssignState ();
|
||||
|
||||
lastTimeAttackStateAssigned = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
void updateAttackAssignState ()
|
||||
{
|
||||
bool indexSelected = false;
|
||||
|
||||
int randomAIIndexToUse = -1;
|
||||
|
||||
int counter = 0;
|
||||
|
||||
while (!indexSelected) {
|
||||
randomAIIndexToUse = Random.Range (0, (currentTargetsAmount));
|
||||
|
||||
if (lastAIAttackAssignedIndex == -1 || lastAIAttackAssignedIndex != randomAIIndexToUse) {
|
||||
indexSelected = true;
|
||||
|
||||
lastAIAttackAssignedIndex = randomAIIndexToUse;
|
||||
}
|
||||
|
||||
if (findObjectivesSystemList [lastAIAttackAssignedIndex].isIgnoreWaitToAttackWithOtherAIAroundEnabled ()) {
|
||||
indexSelected = false;
|
||||
}
|
||||
|
||||
counter++;
|
||||
|
||||
if (counter > 100) {
|
||||
if (showDebugPrint) {
|
||||
print ("COUNTER LOOP");
|
||||
|
||||
}
|
||||
|
||||
indexSelected = true;
|
||||
|
||||
randomAIIndexToUse = 0;
|
||||
}
|
||||
}
|
||||
|
||||
currentTargetsAmount = charactersAround.Count;
|
||||
|
||||
for (int i = charactersAround.Count - 1; i >= 0; i--) {
|
||||
if (charactersAround [i] != null) {
|
||||
if (applyDamage.checkIfDead (charactersAround [i].gameObject) || charactersAround [i] == null) {
|
||||
charactersAround.RemoveAt (i);
|
||||
|
||||
if (findObjectivesSystemList.Count > i) {
|
||||
findObjectivesSystemList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentTargetsAmount = charactersAround.Count;
|
||||
|
||||
if (currentTargetsAmount > 1) {
|
||||
|
||||
for (int i = 0; i < currentTargetsAmount; i++) {
|
||||
if (findObjectivesSystemList.Count > i) {
|
||||
findObjectivesSystem currentFindObjectivesSystem = findObjectivesSystemList [i];
|
||||
|
||||
if (randomAIIndexToUse == i) {
|
||||
if (!pauseAttacksOnAllAIAround) {
|
||||
currentFindObjectivesSystem.setWaitToActivateAttackActiveState (false);
|
||||
}
|
||||
|
||||
if (useRandomWalkEnabled) {
|
||||
currentFindObjectivesSystem.setOriginalUseRandomWalkEnabledState ();
|
||||
}
|
||||
} else {
|
||||
if (!currentFindObjectivesSystem.isIgnoreWaitToAttackWithOtherAIAroundEnabled ()) {
|
||||
currentFindObjectivesSystem.setWaitToActivateAttackActiveState (true);
|
||||
|
||||
if (useRandomWalkEnabled) {
|
||||
currentFindObjectivesSystem.setUseRandomWalkEnabledState (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useDynamicObstacleDetection) {
|
||||
if (!currentFindObjectivesSystem.isIgnoreWaitToAttackWithOtherAIAroundEnabled ()) {
|
||||
currentFindObjectivesSystem.AINavMeshManager.setUseDynamicObstacleDetectionState (true);
|
||||
|
||||
currentFindObjectivesSystem.AINavMeshManager.setMinObstacleRotation (minObstacleRotation);
|
||||
currentFindObjectivesSystem.AINavMeshManager.setMediumObstacleRotation (mediumObstacleRotation);
|
||||
currentFindObjectivesSystem.AINavMeshManager.setMaximumObstacleRotation (maximumObstacleRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTargetsAmount <= 1) {
|
||||
if (AIManagerActive) {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
AIManagerActive = false;
|
||||
}
|
||||
|
||||
if (currentTargetsAmount == 1) {
|
||||
resumeRegularStateOnCharacter (charactersAround [0], false);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("only 1 target, resume state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (charactersAround.Count == 0) {
|
||||
checkEventsOnTargetsChange (false);
|
||||
|
||||
checkEventOnLastTargetRemoved ();
|
||||
|
||||
lastTimeAttackStateAssigned = 0;
|
||||
|
||||
lastAIAttackAssignedIndex = -1;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("AI to attack selected " + randomAIIndexToUse.ToString ());
|
||||
}
|
||||
}
|
||||
|
||||
public void addCharacterAround (Transform newCharacter)
|
||||
{
|
||||
if (!AIManagerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!charactersAround.Contains (newCharacter)) {
|
||||
charactersAround.Add (newCharacter);
|
||||
|
||||
checkRemoveEmptyObjects ();
|
||||
|
||||
if (charactersAround.Count == 1) {
|
||||
checkEventOnFirstTargetDetected ();
|
||||
}
|
||||
|
||||
checkEventsOnTargetsChange (true);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Adding target " + newCharacter.name);
|
||||
}
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = newCharacter.GetComponent<playerComponentsManager> ();
|
||||
|
||||
findObjectivesSystem currentFindObjectivesSystem = null;
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
currentFindObjectivesSystem = currentPlayerComponentsManager.getFindObjectivesSystem ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
findObjectivesSystemList.Add (currentFindObjectivesSystem);
|
||||
}
|
||||
}
|
||||
|
||||
currentTargetsAmount = charactersAround.Count;
|
||||
|
||||
if (onlyStoreAIAndIgnoreToSetStates) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AIManagerActive) {
|
||||
if (charactersAround.Count >= 2) {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
|
||||
AIManagerActive = true;
|
||||
}
|
||||
} else {
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
if (!currentFindObjectivesSystem.isIgnoreWaitToAttackWithOtherAIAroundEnabled ()) {
|
||||
currentFindObjectivesSystem.setWaitToActivateAttackActiveState (true);
|
||||
|
||||
if (useDynamicObstacleDetection) {
|
||||
currentFindObjectivesSystem.AINavMeshManager.setUseDynamicObstacleDetectionState (true);
|
||||
|
||||
currentFindObjectivesSystem.AINavMeshManager.setMinObstacleRotation (minObstacleRotation);
|
||||
currentFindObjectivesSystem.AINavMeshManager.setMediumObstacleRotation (mediumObstacleRotation);
|
||||
currentFindObjectivesSystem.AINavMeshManager.setMaximumObstacleRotation (maximumObstacleRotation);
|
||||
}
|
||||
|
||||
if (useRandomWalkEnabled) {
|
||||
currentFindObjectivesSystem.setUseRandomWalkEnabledState (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCharacterAround (Transform newCharacter)
|
||||
{
|
||||
if (!AIManagerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (charactersAround.Contains (newCharacter)) {
|
||||
charactersAround.Remove (newCharacter);
|
||||
|
||||
checkRemoveEmptyObjects ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Removing target " + newCharacter.name);
|
||||
}
|
||||
}
|
||||
|
||||
resumeRegularStateOnCharacter (newCharacter, true);
|
||||
|
||||
currentTargetsAmount = charactersAround.Count;
|
||||
|
||||
if (currentTargetsAmount <= 1) {
|
||||
if (AIManagerActive) {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
AIManagerActive = false;
|
||||
}
|
||||
|
||||
if (currentTargetsAmount == 1) {
|
||||
resumeRegularStateOnCharacter (charactersAround [0], false);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("only 1 target, resume state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("number of targets " + currentTargetsAmount);
|
||||
}
|
||||
|
||||
lastTimeAttackStateAssigned = 0;
|
||||
|
||||
lastAIAttackAssignedIndex = -1;
|
||||
|
||||
if (charactersAround.Count == 0) {
|
||||
checkEventsOnTargetsChange (false);
|
||||
|
||||
checkEventOnLastTargetRemoved ();
|
||||
}
|
||||
}
|
||||
|
||||
void resumeRegularStateOnCharacter (Transform newCharacter, bool removeCharacterFromFindObjectivesSystemList)
|
||||
{
|
||||
playerComponentsManager currentPlayerComponentsManager = newCharacter.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
findObjectivesSystem currentFindObjectivesSystem = currentPlayerComponentsManager.getFindObjectivesSystem ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
if (!onlyStoreAIAndIgnoreToSetStates) {
|
||||
if (!pauseAttacksOnAllAIAround) {
|
||||
currentFindObjectivesSystem.setWaitToActivateAttackActiveState (false);
|
||||
}
|
||||
|
||||
if (useDynamicObstacleDetection) {
|
||||
currentFindObjectivesSystem.AINavMeshManager.setOriginalUseDynamicObstacleDetection ();
|
||||
}
|
||||
|
||||
if (useRandomWalkEnabled) {
|
||||
currentFindObjectivesSystem.setOriginalUseRandomWalkEnabledState ();
|
||||
}
|
||||
}
|
||||
|
||||
if (removeCharacterFromFindObjectivesSystemList) {
|
||||
if (findObjectivesSystemList.Contains (currentFindObjectivesSystem)) {
|
||||
findObjectivesSystemList.Remove (currentFindObjectivesSystem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCharactersAround ()
|
||||
{
|
||||
if (!AIManagerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkRemoveEmptyObjects ();
|
||||
|
||||
currentTargetsAmount = charactersAround.Count;
|
||||
|
||||
for (int i = 0; i < currentTargetsAmount; i++) {
|
||||
playerComponentsManager currentPlayerComponentsManager = charactersAround [i].GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
findObjectivesSystem currentFindObjectivesSystem = currentPlayerComponentsManager.getFindObjectivesSystem ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
if (!onlyStoreAIAndIgnoreToSetStates) {
|
||||
if (!pauseAttacksOnAllAIAround) {
|
||||
currentFindObjectivesSystem.setWaitToActivateAttackActiveState (false);
|
||||
}
|
||||
|
||||
if (useDynamicObstacleDetection) {
|
||||
currentFindObjectivesSystem.AINavMeshManager.setOriginalUseDynamicObstacleDetection ();
|
||||
}
|
||||
|
||||
if (useRandomWalkEnabled) {
|
||||
currentFindObjectivesSystem.setOriginalUseRandomWalkEnabledState ();
|
||||
}
|
||||
}
|
||||
|
||||
if (findObjectivesSystemList.Contains (currentFindObjectivesSystem)) {
|
||||
findObjectivesSystemList.Remove (currentFindObjectivesSystem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
charactersAround.Clear ();
|
||||
|
||||
currentTargetsAmount = charactersAround.Count;
|
||||
|
||||
if (currentTargetsAmount <= 1) {
|
||||
if (AIManagerActive) {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
AIManagerActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
lastTimeAttackStateAssigned = 0;
|
||||
|
||||
lastAIAttackAssignedIndex = -1;
|
||||
|
||||
if (charactersAround.Count == 0) {
|
||||
checkEventsOnTargetsChange (false);
|
||||
|
||||
checkEventOnLastTargetRemoved ();
|
||||
}
|
||||
}
|
||||
|
||||
void checkEventsOnTargetsChange (bool state)
|
||||
{
|
||||
if (useEventsOnTargetsChange) {
|
||||
if (state) {
|
||||
eventOnTargetsDetected.Invoke ();
|
||||
} else {
|
||||
eventOnTargetsRemoved.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
if (sendInfoToTurnBasedCombatSystemEnabled) {
|
||||
if (!mainTurnBasedCombatSystemLocated) {
|
||||
mainTurnBasedCombatSystemLocated = mainTurnBasedCombatSystem != null;
|
||||
|
||||
if (!mainTurnBasedCombatSystemLocated) {
|
||||
mainTurnBasedCombatSystem = turnBasedCombatSystem.Instance;
|
||||
|
||||
mainTurnBasedCombatSystemLocated = mainTurnBasedCombatSystem != null;
|
||||
}
|
||||
|
||||
if (!mainTurnBasedCombatSystemLocated) {
|
||||
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (mainTurnBasedCombatSystemPanelName, typeof (turnBasedCombatSystem), true);
|
||||
|
||||
mainTurnBasedCombatSystem = turnBasedCombatSystem.Instance;
|
||||
|
||||
mainTurnBasedCombatSystemLocated = mainTurnBasedCombatSystem != null;
|
||||
}
|
||||
|
||||
if (!mainTurnBasedCombatSystemLocated) {
|
||||
|
||||
mainTurnBasedCombatSystem = FindObjectOfType<turnBasedCombatSystem> ();
|
||||
|
||||
mainTurnBasedCombatSystemLocated = mainTurnBasedCombatSystem != null;
|
||||
}
|
||||
}
|
||||
|
||||
if (mainTurnBasedCombatSystemLocated) {
|
||||
if (state) {
|
||||
mainTurnBasedCombatSystem.enableWaitTimeToActivateTurnBasedCombat ();
|
||||
} else {
|
||||
mainTurnBasedCombatSystem.disableWaitTimeToActivateTurnBasedCombat ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkEventOnFirstTargetDetected ()
|
||||
{
|
||||
if (useEventOnFirstTargetDetected) {
|
||||
eventOnFirstTargetDetected.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
void checkEventOnLastTargetRemoved ()
|
||||
{
|
||||
if (useEventOnLastTargetRemoved) {
|
||||
eventOnLastTargetRemoved.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
void checkRemoveEmptyObjects ()
|
||||
{
|
||||
for (int i = charactersAround.Count - 1; i >= 0; i--) {
|
||||
if (charactersAround [i] == null) {
|
||||
charactersAround.RemoveAt (i);
|
||||
|
||||
if (findObjectivesSystemList.Count > i) {
|
||||
findObjectivesSystemList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Transform> getCharactersAround ()
|
||||
{
|
||||
return charactersAround;
|
||||
}
|
||||
|
||||
public bool characterDetectedByAIAround ()
|
||||
{
|
||||
int findObjectivesSystemListCount = findObjectivesSystemList.Count;
|
||||
|
||||
for (int i = 0; i < findObjectivesSystemListCount; i++) {
|
||||
if (findObjectivesSystemList [i] != null) {
|
||||
if (findObjectivesSystemList [i].isOnSpotted ()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool checkIfPlayerDetectedByAIAround (GameObject mainPlayerGameObject)
|
||||
{
|
||||
if (mainPlayerGameObject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int findObjectivesSystemListCount = findObjectivesSystemList.Count;
|
||||
|
||||
if (findObjectivesSystemListCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < findObjectivesSystemListCount; i++) {
|
||||
if (findObjectivesSystemList [i] != null) {
|
||||
if (findObjectivesSystemList [i].isOnSpotted () &&
|
||||
findObjectivesSystemList [i].getCurrentTargetToAttack () == mainPlayerGameObject) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getMinDistanceToPlayer (Transform playerTransform, bool ignoreIfPlayerIsCurrentTarget)
|
||||
{
|
||||
if (playerTransform == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int findObjectivesSystemListCount = findObjectivesSystemList.Count;
|
||||
|
||||
if (findObjectivesSystemListCount == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
float minDistance = Mathf.Infinity;
|
||||
|
||||
bool distanceFound = false;
|
||||
|
||||
Vector3 playerPosition = playerTransform.position;
|
||||
|
||||
for (int i = 0; i < findObjectivesSystemListCount; i++) {
|
||||
if (findObjectivesSystemList [i] != null) {
|
||||
if (findObjectivesSystemList [i].isOnSpotted ()) {
|
||||
if (ignoreIfPlayerIsCurrentTarget) {
|
||||
float currentDistance = GKC_Utils.distance (findObjectivesSystemList [i].transform.position, playerPosition);
|
||||
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
distanceFound = true;
|
||||
}
|
||||
} else {
|
||||
if (findObjectivesSystemList [i].getCurrentTargetToAttack () == playerTransform.gameObject) {
|
||||
|
||||
float currentDistance = GKC_Utils.distance (findObjectivesSystemList [i].transform.position, playerPosition);
|
||||
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
distanceFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (distanceFound) {
|
||||
return minDistance;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab158885b1a03ad48a60bd8deda74b91
|
||||
timeCreated: 1666561991
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AIAroundManager.cs
|
||||
uploadId: 814740
|
||||
14
Assets/Game Kit Controller/Scripts/AI/AIHealtSliderInfo.cs
Normal file
14
Assets/Game Kit Controller/Scripts/AI/AIHealtSliderInfo.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AIHealtSliderInfo : MonoBehaviour
|
||||
{
|
||||
public Slider healthSlider;
|
||||
public Text nameText;
|
||||
public Image sliderBackground;
|
||||
|
||||
public Slider shieldSlider;
|
||||
|
||||
public Image circleHealthSlider;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6ca8a8a2fd78984c9ea8286919d5b08
|
||||
timeCreated: 1503759857
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AIHealtSliderInfo.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class AIHidePositionsManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
public List<Transform> hidePositionList = new List<Transform> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public float gizmoRadius;
|
||||
|
||||
|
||||
//add a new waypoint
|
||||
public void addNewWayPoint ()
|
||||
{
|
||||
Vector3 newPosition = transform.position;
|
||||
|
||||
if (hidePositionList.Count > 0) {
|
||||
newPosition = hidePositionList [hidePositionList.Count - 1].position + hidePositionList [hidePositionList.Count - 1].forward;
|
||||
}
|
||||
|
||||
GameObject newWayPoint = new GameObject ();
|
||||
newWayPoint.transform.SetParent (transform);
|
||||
newWayPoint.transform.position = newPosition;
|
||||
newWayPoint.name = (hidePositionList.Count + 1).ToString ();
|
||||
|
||||
hidePositionList.Add (newWayPoint.transform);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Added new position to hide ", gameObject);
|
||||
}
|
||||
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
for (int i = 0; i < hidePositionList.Count; i++) {
|
||||
if (hidePositionList [i] != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (hidePositionList [i].position, gizmoRadius);
|
||||
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (hidePositionList [i].position, transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71bded77200cd4749962eb8f74326f9c
|
||||
timeCreated: 1479920281
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AIHidePositionsManager.cs
|
||||
uploadId: 814740
|
||||
2365
Assets/Game Kit Controller/Scripts/AI/AINavMesh.cs
Normal file
2365
Assets/Game Kit Controller/Scripts/AI/AINavMesh.cs
Normal file
File diff suppressed because it is too large
Load Diff
19
Assets/Game Kit Controller/Scripts/AI/AINavMesh.cs.meta
Normal file
19
Assets/Game Kit Controller/Scripts/AI/AINavMesh.cs.meta
Normal file
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: deffe8fd103031c48b546719fe46ada2
|
||||
timeCreated: 1602384841
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: ffb5f1a4e41e7d34fa4db4ef073331e9, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AINavMesh.cs
|
||||
uploadId: 814740
|
||||
15
Assets/Game Kit Controller/Scripts/AI/AINavMeshMoveInfo.cs
Normal file
15
Assets/Game Kit Controller/Scripts/AI/AINavMeshMoveInfo.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class AINavMeshMoveInfo
|
||||
{
|
||||
public Vector3 moveInput;
|
||||
public bool crouchInput;
|
||||
public bool jumpInput;
|
||||
public bool lookAtTarget;
|
||||
|
||||
public bool strafeModeActive;
|
||||
public bool AIEnableInputMovementOnStrafe;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f86a4a5f0eb95ec4ab795153bc4b7712
|
||||
timeCreated: 1528283089
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AINavMeshMoveInfo.cs
|
||||
uploadId: 814740
|
||||
496
Assets/Game Kit Controller/Scripts/AI/AIPatrolSystem.cs
Normal file
496
Assets/Game Kit Controller/Scripts/AI/AIPatrolSystem.cs
Normal file
@@ -0,0 +1,496 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using static AIWayPointPatrol;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AIPatrolSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool paused;
|
||||
public float minDistanceToNextPoint = 0.6f;
|
||||
public float patrolSpeed = 0.2f;
|
||||
public float returnToPatrolSpeed = 1;
|
||||
|
||||
public bool moveOnReversePatrolDirectionEnabled;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useCurrentPatrolIndexOnStart;
|
||||
public int currentPatrolIndex = 0;
|
||||
|
||||
[Space]
|
||||
[Header ("Patrol Time Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useGeneralWaitTime = true;
|
||||
public float generalWaitTimeBetweenPoints;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool moveBetweenPatrolsInOrder = true;
|
||||
|
||||
public float fixedTimeToChangeBetweenPatrols;
|
||||
|
||||
[Space]
|
||||
[Header ("Random Patrol Settings")]
|
||||
[Space]
|
||||
|
||||
public bool changeBetweenPointRandomly = true;
|
||||
[Range (0, 10)] public int changeRandomlyProbability = 1;
|
||||
public bool useTimeToChangeBetweenPointRandomly;
|
||||
|
||||
public bool useRandomTimeToChangePatrol;
|
||||
public Vector2 randomTimeLimits;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool returningToPatrol;
|
||||
public bool AIIsDestroyed;
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public float gizmoRadius;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnPatrolWait;
|
||||
public UnityEvent eventsOnPatrolWait;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
[Tooltip ("An AIWayPointPatrol path in your scene that this AI should follow. To create one add a GameObject with AIWayPointPatrol component and edit the Way Points then drag the GameObject here.")]
|
||||
public AIWayPointPatrol patrolPath;
|
||||
|
||||
public Transform AICharacter;
|
||||
public AINavMesh mainAINavmesh;
|
||||
|
||||
bool patrolAssigned;
|
||||
|
||||
Transform currentWayPoint;
|
||||
|
||||
int currentWaypointIndex = 0;
|
||||
Coroutine movement;
|
||||
bool settingNextPoint;
|
||||
float lastTimeChanged;
|
||||
float distanceToPoint;
|
||||
|
||||
Transform closestWaypointTransform;
|
||||
|
||||
List<patrolElementInfo> patrolList = new List<patrolElementInfo> ();
|
||||
|
||||
bool patrolListAssigned;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (AICharacter == null) {
|
||||
AICharacter = transform;
|
||||
}
|
||||
|
||||
if (mainAINavmesh == null) {
|
||||
mainAINavmesh = AICharacter.GetComponent<AINavMesh> ();
|
||||
}
|
||||
|
||||
checkPatrolListAssigned ();
|
||||
|
||||
if (patrolPath != null) {
|
||||
setClosestWayPoint ();
|
||||
}
|
||||
}
|
||||
|
||||
void checkPatrolListAssigned ()
|
||||
{
|
||||
if (!patrolListAssigned) {
|
||||
if (patrolPath != null) {
|
||||
patrolList = patrolPath.patrolList;
|
||||
|
||||
patrolListAssigned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (!paused && patrolAssigned && !settingNextPoint) {
|
||||
|
||||
if (AIIsDestroyed) {
|
||||
enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mainAINavmesh.isPatrolPaused ()) {
|
||||
if (AICharacter == null) {
|
||||
AIIsDestroyed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
distanceToPoint = GKC_Utils.distance (AICharacter.position, currentWayPoint.position);
|
||||
|
||||
if (distanceToPoint < minDistanceToNextPoint) {
|
||||
if (returningToPatrol) {
|
||||
mainAINavmesh.setPatrolSpeed (patrolSpeed);
|
||||
|
||||
returningToPatrol = false;
|
||||
}
|
||||
|
||||
bool setRandomWayPoint = false;
|
||||
|
||||
if (changeBetweenPointRandomly) {
|
||||
int changeOrNotBool = Random.Range (0, (changeRandomlyProbability + 1));
|
||||
|
||||
if (changeOrNotBool == 0) {
|
||||
setRandomWayPoint = true;
|
||||
//print ("random waypoint");
|
||||
}
|
||||
}
|
||||
|
||||
if (setRandomWayPoint) {
|
||||
setNextRandomWaypoint ();
|
||||
} else {
|
||||
setNextWaypoint ();
|
||||
//print ("in order");
|
||||
}
|
||||
}
|
||||
|
||||
if (changeBetweenPointRandomly) {
|
||||
if (useTimeToChangeBetweenPointRandomly) {
|
||||
if (useRandomTimeToChangePatrol) {
|
||||
|
||||
} else {
|
||||
if (Time.time > fixedTimeToChangeBetweenPatrols + lastTimeChanged) {
|
||||
lastTimeChanged = Time.time;
|
||||
|
||||
setNextRandomWaypoint ();
|
||||
//print ("random waypoint");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseOrPlayPatrol (bool state)
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("patrol paused state " + state);
|
||||
}
|
||||
|
||||
paused = state;
|
||||
}
|
||||
|
||||
public bool isPatrolPaused ()
|
||||
{
|
||||
return paused;
|
||||
}
|
||||
|
||||
public Transform closestWaypoint (Vector3 currentPosition)
|
||||
{
|
||||
float distance = Mathf.Infinity;
|
||||
|
||||
int patrolListCount = patrolList.Count;
|
||||
|
||||
if (useCurrentPatrolIndexOnStart) {
|
||||
int wayPointsCount = patrolList [currentPatrolIndex].wayPoints.Count;
|
||||
|
||||
for (int j = 0; j < wayPointsCount; j++) {
|
||||
float currentDistance = GKC_Utils.distance (currentPosition, patrolList [currentPatrolIndex].wayPoints [j].position);
|
||||
|
||||
if (currentDistance < distance) {
|
||||
distance = currentDistance;
|
||||
currentWaypointIndex = j;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < patrolListCount; i++) {
|
||||
|
||||
int wayPointsCount = patrolList [i].wayPoints.Count;
|
||||
|
||||
for (int j = 0; j < wayPointsCount; j++) {
|
||||
float currentDistance = GKC_Utils.distance (currentPosition, patrolList [i].wayPoints [j].position);
|
||||
|
||||
if (currentDistance < distance) {
|
||||
distance = currentDistance;
|
||||
currentPatrolIndex = i;
|
||||
currentWaypointIndex = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closestWaypointTransform = patrolList [currentPatrolIndex].wayPoints [currentWaypointIndex];
|
||||
|
||||
return closestWaypointTransform;
|
||||
}
|
||||
|
||||
public void setNextPatrolList ()
|
||||
{
|
||||
currentPatrolIndex++;
|
||||
|
||||
if (currentPatrolIndex > patrolList.Count - 1) {
|
||||
currentPatrolIndex = 0;
|
||||
}
|
||||
|
||||
settingNextPoint = false;
|
||||
|
||||
Vector3 currentPosition = AICharacter.position;
|
||||
|
||||
float distance = Mathf.Infinity;
|
||||
|
||||
int wayPointsCount = patrolList [currentPatrolIndex].wayPoints.Count;
|
||||
|
||||
for (int j = 0; j < wayPointsCount; j++) {
|
||||
float currentDistance = GKC_Utils.distance (currentPosition, patrolList [currentPatrolIndex].wayPoints [j].position);
|
||||
|
||||
if (currentDistance < distance) {
|
||||
distance = currentDistance;
|
||||
currentWaypointIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
currentWayPoint = patrolList [currentPatrolIndex].wayPoints [currentWaypointIndex];
|
||||
|
||||
setCurrentPatrolTarget (currentWayPoint);
|
||||
}
|
||||
|
||||
public void setNextWaypoint ()
|
||||
{
|
||||
if (movement != null) {
|
||||
StopCoroutine (movement);
|
||||
}
|
||||
|
||||
settingNextPoint = false;
|
||||
|
||||
if (mainAINavmesh.isPatrolPaused ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkPatrolListAssigned ();
|
||||
|
||||
movement = StartCoroutine (setNextWayPointCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator setNextWayPointCoroutine ()
|
||||
{
|
||||
mainAINavmesh.removeTarget ();
|
||||
|
||||
settingNextPoint = true;
|
||||
|
||||
if (useEventsOnPatrolWait) {
|
||||
eventsOnPatrolWait.Invoke ();
|
||||
}
|
||||
|
||||
if (useGeneralWaitTime) {
|
||||
WaitForSeconds delay = new WaitForSeconds (generalWaitTimeBetweenPoints);
|
||||
|
||||
yield return delay;
|
||||
} else {
|
||||
WaitForSeconds delay = new WaitForSeconds (patrolPath.waitTimeBetweenPoints);
|
||||
|
||||
yield return delay;
|
||||
}
|
||||
|
||||
if (!mainAINavmesh.isPatrolPaused ()) {
|
||||
if (moveOnReversePatrolDirectionEnabled) {
|
||||
currentWaypointIndex--;
|
||||
|
||||
if (currentWaypointIndex < 0) {
|
||||
currentWaypointIndex = patrolList [currentPatrolIndex].wayPoints.Count - 1;
|
||||
|
||||
if (moveBetweenPatrolsInOrder) {
|
||||
currentPatrolIndex++;
|
||||
|
||||
if (currentPatrolIndex > patrolList.Count - 1) {
|
||||
currentPatrolIndex = 0;
|
||||
}
|
||||
|
||||
currentWaypointIndex = patrolList [currentPatrolIndex].wayPoints.Count - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentWaypointIndex++;
|
||||
|
||||
if (currentWaypointIndex > patrolList [currentPatrolIndex].wayPoints.Count - 1) {
|
||||
currentWaypointIndex = 0;
|
||||
|
||||
if (moveBetweenPatrolsInOrder) {
|
||||
currentPatrolIndex++;
|
||||
|
||||
if (currentPatrolIndex > patrolList.Count - 1) {
|
||||
currentPatrolIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentWayPoint = patrolList [currentPatrolIndex].wayPoints [currentWaypointIndex];
|
||||
|
||||
setCurrentPatrolTarget (currentWayPoint);
|
||||
}
|
||||
|
||||
settingNextPoint = false;
|
||||
}
|
||||
|
||||
public void setNextRandomWaypoint ()
|
||||
{
|
||||
if (movement != null) {
|
||||
StopCoroutine (movement);
|
||||
}
|
||||
|
||||
settingNextPoint = false;
|
||||
|
||||
if (mainAINavmesh.isPatrolPaused ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkPatrolListAssigned ();
|
||||
|
||||
movement = StartCoroutine (setNextRandomWayPointCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator setNextRandomWayPointCoroutine ()
|
||||
{
|
||||
mainAINavmesh.removeTarget ();
|
||||
|
||||
settingNextPoint = true;
|
||||
|
||||
if (useGeneralWaitTime) {
|
||||
WaitForSeconds delay = new WaitForSeconds (generalWaitTimeBetweenPoints);
|
||||
|
||||
yield return delay;
|
||||
} else {
|
||||
WaitForSeconds delay = new WaitForSeconds (patrolPath.waitTimeBetweenPoints);
|
||||
|
||||
yield return delay;
|
||||
}
|
||||
|
||||
if (!mainAINavmesh.isPatrolPaused ()) {
|
||||
|
||||
int currentWaypointIndexCopy = currentWaypointIndex;
|
||||
int currentPatrolIndexCopy = currentPatrolIndex;
|
||||
int checkLoop = 0;
|
||||
|
||||
if (patrolList.Count > 1) {
|
||||
while (currentPatrolIndexCopy == currentPatrolIndex) {
|
||||
currentPatrolIndex = Random.Range (0, patrolList.Count);
|
||||
|
||||
checkLoop++;
|
||||
|
||||
if (checkLoop > 100) {
|
||||
// print ("loop error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkLoop = 0;
|
||||
|
||||
while (currentWaypointIndexCopy == currentWaypointIndex) {
|
||||
currentWaypointIndex = Random.Range (0, patrolList [currentPatrolIndex].wayPoints.Count);
|
||||
|
||||
checkLoop++;
|
||||
|
||||
if (checkLoop > 100) {
|
||||
//print ("loop error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//print ("Next patrol: " + (currentPatrolIndex+1) + " and next waypoint: " + (currentWaypointIndex+1));
|
||||
currentWayPoint = patrolList [currentPatrolIndex].wayPoints [currentWaypointIndex];
|
||||
|
||||
setCurrentPatrolTarget (currentWayPoint);
|
||||
}
|
||||
|
||||
settingNextPoint = false;
|
||||
}
|
||||
|
||||
public void setClosestWayPoint ()
|
||||
{
|
||||
if (paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkPatrolListAssigned ();
|
||||
|
||||
patrolAssigned = true;
|
||||
|
||||
currentWayPoint = closestWaypoint (AICharacter.position);
|
||||
|
||||
setCurrentPatrolTarget (currentWayPoint);
|
||||
|
||||
mainAINavmesh.setPatrolSpeed (patrolSpeed);
|
||||
}
|
||||
|
||||
public void setCurrentPatrolTarget (Transform newTarget)
|
||||
{
|
||||
mainAINavmesh.setPatrolTarget (newTarget);
|
||||
|
||||
mainAINavmesh.setPatrolState (true);
|
||||
}
|
||||
|
||||
public void setReturningToPatrolState (bool state)
|
||||
{
|
||||
returningToPatrol = true;
|
||||
|
||||
if (returningToPatrol) {
|
||||
mainAINavmesh.setPatrolSpeed (returnToPatrolSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
public void resumePatrolStateOnAI ()
|
||||
{
|
||||
pauseOrPlayPatrol (false);
|
||||
|
||||
setClosestWayPoint ();
|
||||
}
|
||||
|
||||
public void pausePatrolStateOnAI ()
|
||||
{
|
||||
pauseOrPlayPatrol (true);
|
||||
|
||||
mainAINavmesh.setPatrolState (false);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
if (patrolList.Count > 0) {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawSphere (patrolList [currentPatrolIndex].wayPoints [currentWaypointIndex].transform.position, gizmoRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
19
Assets/Game Kit Controller/Scripts/AI/AIPatrolSystem.cs.meta
Normal file
19
Assets/Game Kit Controller/Scripts/AI/AIPatrolSystem.cs.meta
Normal file
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f76bd71ba35ad2a43aa7d167a3a34db7
|
||||
timeCreated: 1474733153
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AIPatrolSystem.cs
|
||||
uploadId: 814740
|
||||
140
Assets/Game Kit Controller/Scripts/AI/AIViewTriggerSystem.cs
Normal file
140
Assets/Game Kit Controller/Scripts/AI/AIViewTriggerSystem.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AIViewTriggerSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkTriggerEnabled = true;
|
||||
|
||||
public bool onTriggerEnter;
|
||||
public bool onTriggerExit;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool sendDetectedObjectAsSuspectOnEnter = true;
|
||||
public bool removeDetectedObjectAsSuspectOnExit = true;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool sendDetectedObjectAsTargetToCheckOnEnter;
|
||||
public bool removeDetectedObjectAsTargetToCheckOnExit;
|
||||
|
||||
[Space]
|
||||
[Header ("Regular Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEvents;
|
||||
|
||||
public UnityEvent onTriggerEnterEvent = new UnityEvent ();
|
||||
public UnityEvent onTriggerExitEvent = new UnityEvent ();
|
||||
|
||||
[Space]
|
||||
[Header ("Events With Objects Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useOnTriggerEnterEventWithObject;
|
||||
public eventParameters.eventToCallWithGameObject onTriggerEnterEventWithObject;
|
||||
|
||||
public bool useOnTriggerExitEventWithObject;
|
||||
public eventParameters.eventToCallWithGameObject onTriggerExitEventWithObject;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
if (!checkTriggerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkTrigger (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
if (!checkTriggerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkTrigger (col, false);
|
||||
}
|
||||
|
||||
public void checkTrigger (Collider col, bool isEnter)
|
||||
{
|
||||
if (isEnter) {
|
||||
if (onTriggerEnter) {
|
||||
|
||||
if (useEvents) {
|
||||
callEvent (onTriggerEnterEvent);
|
||||
|
||||
if (useOnTriggerEnterEventWithObject) {
|
||||
callEventWithObject (onTriggerEnterEventWithObject, col.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (sendDetectedObjectAsSuspectOnEnter) {
|
||||
mainFindObjectivesSystem.checkSuspect (col.gameObject);
|
||||
}
|
||||
|
||||
if (sendDetectedObjectAsTargetToCheckOnEnter) {
|
||||
mainFindObjectivesSystem.checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("checking detected object on trigger enter " + col.gameObject.name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (onTriggerExit) {
|
||||
|
||||
if (useEvents) {
|
||||
callEvent (onTriggerExitEvent);
|
||||
|
||||
if (useOnTriggerExitEventWithObject) {
|
||||
callEventWithObject (onTriggerExitEventWithObject, col.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (removeDetectedObjectAsSuspectOnExit) {
|
||||
mainFindObjectivesSystem.cancelCheckSuspect (col.gameObject);
|
||||
}
|
||||
|
||||
if (removeDetectedObjectAsTargetToCheckOnExit) {
|
||||
mainFindObjectivesSystem.checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("checking detected object on trigger exit " + col.gameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void callEvent (UnityEvent eventToCall)
|
||||
{
|
||||
eventToCall.Invoke ();
|
||||
}
|
||||
|
||||
public void callEventWithObject (eventParameters.eventToCallWithGameObject eventToCall, GameObject objectToSend)
|
||||
{
|
||||
eventToCall.Invoke (objectToSend);
|
||||
}
|
||||
|
||||
public void setCheckTriggerEnabledState (bool state)
|
||||
{
|
||||
checkTriggerEnabled = state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3861154bc4190e43b604e0dde00b486
|
||||
timeCreated: 1616898028
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AIViewTriggerSystem.cs
|
||||
uploadId: 814740
|
||||
230
Assets/Game Kit Controller/Scripts/AI/AIWalkToPosition.cs
Normal file
230
Assets/Game Kit Controller/Scripts/AI/AIWalkToPosition.cs
Normal file
@@ -0,0 +1,230 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class AIWalkToPosition : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool walkToPositionEnabled = true;
|
||||
|
||||
public float maxWalkSpeed = 1;
|
||||
|
||||
public Transform walkPositionTransform;
|
||||
|
||||
public bool activateDynamicObstacleDetection;
|
||||
|
||||
public bool assignPartnerIfFoundOnPositionReached;
|
||||
|
||||
public bool removePartnerIfFoundOnPositionReached;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool walkToPositionInProcess;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform characterTransform;
|
||||
|
||||
public AINavMesh mainAINavmesh;
|
||||
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public playerController mainPlayerController;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
bool dynamicObstacleDetectionChecked = false;
|
||||
bool dynamicObstacleActiveChecked = false;
|
||||
|
||||
float lastTimeWalkToPositionActive;
|
||||
|
||||
public void activateWalkToPosition ()
|
||||
{
|
||||
if (!walkToPositionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("start walk");
|
||||
}
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
pauseAIState ();
|
||||
|
||||
dynamicObstacleDetectionChecked = false;
|
||||
dynamicObstacleActiveChecked = false;
|
||||
|
||||
lastTimeWalkToPositionActive = Time.time;
|
||||
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
}
|
||||
|
||||
public void stopActivateWalkPosition ()
|
||||
{
|
||||
if (walkToPositionInProcess) {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
resumeAIState ();
|
||||
|
||||
walkToPositionInProcess = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
float currentDistanceToTarget = GKC_Utils.distance (walkPositionTransform.position, characterTransform.position);
|
||||
|
||||
if (currentDistanceToTarget < 2) {
|
||||
if (!dynamicObstacleDetectionChecked) {
|
||||
if (activateDynamicObstacleDetection) {
|
||||
mainAINavmesh.setUseDynamicObstacleDetectionState (false);
|
||||
}
|
||||
|
||||
dynamicObstacleDetectionChecked = true;
|
||||
}
|
||||
} else {
|
||||
if (!dynamicObstacleActiveChecked) {
|
||||
if (activateDynamicObstacleDetection) {
|
||||
mainAINavmesh.setUseDynamicObstacleDetectionState (true);
|
||||
}
|
||||
|
||||
dynamicObstacleActiveChecked = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
if (Time.time > lastTimeWalkToPositionActive + 0.2f) {
|
||||
if (!mainAINavmesh.isFollowingTarget ()) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
if (currentDistanceToTarget < 0.2f) {
|
||||
targetReached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mainPlayerController.isPlayerDead ()) {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
walkToPositionInProcess = false;
|
||||
|
||||
resetStatesOnDeadAI ();
|
||||
}
|
||||
|
||||
if (targetReached) {
|
||||
|
||||
resumeAIState ();
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
}
|
||||
|
||||
void pauseAIState ()
|
||||
{
|
||||
walkToPositionInProcess = true;
|
||||
|
||||
mainPlayerController.setActionActiveState (true);
|
||||
|
||||
mainAINavmesh.pauseAI (true);
|
||||
|
||||
mainAINavmesh.pauseAI (false);
|
||||
|
||||
mainFindObjectivesSystem.checkPauseOrResumePatrolStateDuringActionActive (true);
|
||||
|
||||
mainAINavmesh.enableCustomNavMeshSpeed (maxWalkSpeed);
|
||||
|
||||
mainAINavmesh.setTarget (walkPositionTransform);
|
||||
mainAINavmesh.setTargetType (false, true);
|
||||
|
||||
mainAINavmesh.enableCustomMinDistance (0.22f);
|
||||
|
||||
mainFindObjectivesSystem.setSearchingObjectState (true);
|
||||
|
||||
mainFindObjectivesSystem.disableStrafeModeIfActive ();
|
||||
}
|
||||
|
||||
void resumeAIState ()
|
||||
{
|
||||
mainAINavmesh.removeTarget ();
|
||||
|
||||
mainAINavmesh.disableCustomNavMeshSpeed ();
|
||||
|
||||
mainAINavmesh.disableCustomMinDistance ();
|
||||
|
||||
mainAINavmesh.pauseAI (true);
|
||||
|
||||
mainAINavmesh.pauseAI (false);
|
||||
|
||||
mainPlayerController.setActionActiveState (false);
|
||||
|
||||
if (assignPartnerIfFoundOnPositionReached && mainAINavmesh.isPartnerLocated ()) {
|
||||
mainAINavmesh.setTarget (mainAINavmesh.getCurrentPartner ());
|
||||
|
||||
mainAINavmesh.setTargetType (true, false);
|
||||
} else {
|
||||
if (removePartnerIfFoundOnPositionReached) {
|
||||
if (mainAINavmesh.isPartnerLocated ()) {
|
||||
mainFindObjectivesSystem.removePartner ();
|
||||
|
||||
mainFindObjectivesSystem.checkIfResumeAfterRemovingPartner ();
|
||||
}
|
||||
}
|
||||
|
||||
mainFindObjectivesSystem.checkPauseOrResumePatrolStateDuringActionActive (false);
|
||||
}
|
||||
|
||||
if (activateDynamicObstacleDetection) {
|
||||
mainAINavmesh.setOriginalUseDynamicObstacleDetection ();
|
||||
}
|
||||
|
||||
mainFindObjectivesSystem.setSearchingObjectState (false);
|
||||
|
||||
walkToPositionInProcess = false;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("end walk");
|
||||
}
|
||||
}
|
||||
|
||||
void resetStatesOnDeadAI ()
|
||||
{
|
||||
mainAINavmesh.disableCustomNavMeshSpeed ();
|
||||
|
||||
mainAINavmesh.disableCustomMinDistance ();
|
||||
|
||||
mainPlayerController.setActionActiveState (false);
|
||||
|
||||
if (activateDynamicObstacleDetection) {
|
||||
mainAINavmesh.setOriginalUseDynamicObstacleDetection ();
|
||||
}
|
||||
|
||||
mainFindObjectivesSystem.setSearchingObjectState (false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cacc4007c0eb8e41a881d7d27d50ef9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AIWalkToPosition.cs
|
||||
uploadId: 814740
|
||||
237
Assets/Game Kit Controller/Scripts/AI/AIWayPointPatrol.cs
Normal file
237
Assets/Game Kit Controller/Scripts/AI/AIWayPointPatrol.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class AIWayPointPatrol : MonoBehaviour
|
||||
{
|
||||
public List<patrolElementInfo> patrolList = new List<patrolElementInfo> ();
|
||||
public patrolElementInfo currentPatrol;
|
||||
public float waitTimeBetweenPoints;
|
||||
|
||||
public LayerMask layerMask;
|
||||
public Vector3 newWaypointOffset;
|
||||
public float surfaceAdjusmentOffset = 0.1f;
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoLabelColor;
|
||||
public float gizmoRadius;
|
||||
public bool useHandleForVertex;
|
||||
|
||||
public bool useFreeHandle;
|
||||
|
||||
public float handleRadius;
|
||||
public Color handleGizmoColor;
|
||||
|
||||
Coroutine movement;
|
||||
int currentPlatformIndex;
|
||||
int i, j;
|
||||
bool inside;
|
||||
bool moving;
|
||||
|
||||
public void addNewPatrol ()
|
||||
{
|
||||
Vector3 newPosition = transform.position;
|
||||
|
||||
if (patrolList.Count > 0) {
|
||||
newPosition = patrolList [patrolList.Count - 1].patrolTransform.position +
|
||||
patrolList [patrolList.Count - 1].patrolTransform.right * newWaypointOffset.x +
|
||||
patrolList [patrolList.Count - 1].patrolTransform.up * newWaypointOffset.y +
|
||||
patrolList [patrolList.Count - 1].patrolTransform.forward * newWaypointOffset.z;
|
||||
}
|
||||
|
||||
patrolElementInfo newPatrol = new patrolElementInfo ();
|
||||
|
||||
GameObject newPatrolTransform = new GameObject ();
|
||||
newPatrolTransform.transform.SetParent (transform);
|
||||
newPatrolTransform.transform.position = newPosition;
|
||||
|
||||
newPatrolTransform.transform.localRotation = Quaternion.identity;
|
||||
newPatrol.name = "Patrol " + (patrolList.Count + 1);
|
||||
newPatrol.patrolTransform = newPatrolTransform.transform;
|
||||
newPatrolTransform.name = "Patrol_" + (patrolList.Count + 1);
|
||||
patrolList.Add (newPatrol);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void clearPatrolList ()
|
||||
{
|
||||
for (i = 0; i < patrolList.Count; i++) {
|
||||
clearWayPoint (i);
|
||||
Destroy (patrolList [i].patrolTransform.gameObject);
|
||||
}
|
||||
|
||||
patrolList.Clear ();
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
//add a new waypoint
|
||||
public void addNewWayPoint (int index)
|
||||
{
|
||||
Vector3 newPosition = patrolList [index].patrolTransform.position;
|
||||
|
||||
if (patrolList [index].wayPoints.Count > 0) {
|
||||
newPosition = patrolList [index].wayPoints [patrolList [index].wayPoints.Count - 1].position +
|
||||
patrolList [index].wayPoints [patrolList [index].wayPoints.Count - 1].right * newWaypointOffset.x +
|
||||
patrolList [index].wayPoints [patrolList [index].wayPoints.Count - 1].up * newWaypointOffset.y +
|
||||
patrolList [index].wayPoints [patrolList [index].wayPoints.Count - 1].forward * newWaypointOffset.z;
|
||||
}
|
||||
|
||||
GameObject newWayPoint = new GameObject ();
|
||||
|
||||
newWayPoint.transform.SetParent (patrolList [index].patrolTransform);
|
||||
newWayPoint.transform.position = newPosition;
|
||||
newWayPoint.transform.localRotation = Quaternion.identity;
|
||||
newWayPoint.name = (patrolList [index].wayPoints.Count + 1).ToString ();
|
||||
patrolList [index].wayPoints.Add (newWayPoint.transform);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void removeWaypoint (int patrolIndex, int waypointIndex)
|
||||
{
|
||||
Transform currentWaypoint = patrolList [patrolIndex].wayPoints [waypointIndex];
|
||||
|
||||
if (currentWaypoint != null) {
|
||||
DestroyImmediate (currentWaypoint.gameObject);
|
||||
}
|
||||
|
||||
patrolList [patrolIndex].wayPoints.RemoveAt (waypointIndex);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void clearWayPoint (int index)
|
||||
{
|
||||
for (i = 0; i < patrolList [index].wayPoints.Count; i++) {
|
||||
DestroyImmediate (patrolList [index].wayPoints [i].gameObject);
|
||||
}
|
||||
|
||||
DestroyImmediate (patrolList [index].patrolTransform.gameObject);
|
||||
|
||||
patrolList [index].wayPoints.Clear ();
|
||||
patrolList.RemoveAt (index);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void adjustWayPoints ()
|
||||
{
|
||||
RaycastHit hit;
|
||||
|
||||
for (i = 0; i < patrolList.Count; i++) {
|
||||
for (j = 0; j < patrolList [i].wayPoints.Count; j++) {
|
||||
if (Physics.Raycast (patrolList [i].wayPoints [j].position, -patrolList [i].wayPoints [j].up, out hit, Mathf.Infinity, layerMask)) {
|
||||
patrolList [i].wayPoints [j].position = hit.point + patrolList [i].wayPoints [j].up * surfaceAdjusmentOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void invertPath ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update AI Waypoint patrol info", gameObject);
|
||||
}
|
||||
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
int patrolListCount = patrolList.Count;
|
||||
for (i = 0; i < patrolListCount; i++) {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawSphere (patrolList [i].patrolTransform.position, gizmoRadius);
|
||||
|
||||
int wayPointsCount = patrolList [i].wayPoints.Count;
|
||||
|
||||
for (j = 0; j < wayPointsCount; j++) {
|
||||
Transform currentWaypoint = patrolList [i].wayPoints [j];
|
||||
|
||||
if (currentWaypoint != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (currentWaypoint.position, gizmoRadius);
|
||||
|
||||
if (j + 1 < patrolList [i].wayPoints.Count && patrolList [i].wayPoints [j + 1] != null) {
|
||||
Gizmos.color = Color.white;
|
||||
|
||||
Vector3 initialPosition = currentWaypoint.position;
|
||||
Vector3 targetPosition = patrolList [i].wayPoints [j + 1].position;
|
||||
Gizmos.DrawLine (initialPosition, targetPosition);
|
||||
|
||||
Vector3 arrowDirection = (targetPosition - initialPosition).normalized;
|
||||
GKC_Utils.drawGizmoArrow (initialPosition, arrowDirection, Color.green, 1, 20);
|
||||
}
|
||||
|
||||
if (j == patrolList [i].wayPoints.Count - 1) {
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (currentWaypoint.position, patrolList [i].wayPoints [0].position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (patrolList.Count > 1) {
|
||||
if (i + 1 < patrolList.Count) {
|
||||
if (patrolList [i].wayPoints.Count > 0) {
|
||||
if (patrolList [i + 1].wayPoints.Count > 0) {
|
||||
if (patrolList [i].wayPoints [patrolList [i].wayPoints.Count - 1] && patrolList [i + 1].wayPoints [0] != null) {
|
||||
Gizmos.color = Color.blue;
|
||||
|
||||
Vector3 initialPosition = patrolList [i].wayPoints [patrolList [i].wayPoints.Count - 1].position;
|
||||
Vector3 targetPosition = patrolList [i + 1].wayPoints [0].position;
|
||||
Gizmos.DrawLine (initialPosition, targetPosition);
|
||||
|
||||
Vector3 arrowDirection = (targetPosition - initialPosition).normalized;
|
||||
GKC_Utils.drawGizmoArrow (initialPosition, arrowDirection, Color.red, 2, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i == patrolList.Count - 1) {
|
||||
if (patrolList [0].wayPoints.Count > 0 && patrolList [patrolList.Count - 1].wayPoints.Count > 0) {
|
||||
if (patrolList [patrolList.Count - 1].wayPoints [patrolList [patrolList.Count - 1].wayPoints.Count - 1]) {
|
||||
Gizmos.color = Color.blue;
|
||||
|
||||
Gizmos.DrawLine (patrolList [0].wayPoints [0].position,
|
||||
patrolList [patrolList.Count - 1].wayPoints [patrolList [patrolList.Count - 1].wayPoints.Count - 1].position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class patrolElementInfo
|
||||
{
|
||||
public string name;
|
||||
public Transform patrolTransform;
|
||||
public List<Transform> wayPoints = new List<Transform> ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 167faf55f0ff51048ba66a444d7e4f66
|
||||
timeCreated: 1474390600
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/AIWayPointPatrol.cs
|
||||
uploadId: 814740
|
||||
9
Assets/Game Kit Controller/Scripts/AI/Close Combat.meta
Normal file
9
Assets/Game Kit Controller/Scripts/AI/Close Combat.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6f2722aa5415f8408aad62acaefae05
|
||||
folderAsset: yes
|
||||
timeCreated: 1614635932
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 533dbae790a003346a16176c9654b11a
|
||||
timeCreated: 1610946875
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Close Combat/AICloseCombatSystemBrain.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f35b4535cf5e7884bb73234ff6cf82a2
|
||||
folderAsset: yes
|
||||
timeCreated: 1602881052
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,247 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AIBehaviorInfo : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool behaviorEnabled = true;
|
||||
|
||||
public virtual void activateAIBehavior ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void deactivateAIBehavior ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateAI ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateAIBehaviorState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateAIAttackState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateInsideRangeDistance (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateAIBehaviorState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setDrawOrHolsterWeaponState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setAimWeaponState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setShootWeaponState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setHoldShootWeaponState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void dropWeapon ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkIfDrawWeaponsWhenResumingAI ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void resetBehaviorStates ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void resetAttackState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void stopAim ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void disableOnSpottedState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateWeaponsAvailableState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setBehaviorStatesPausedState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setSystemActiveState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool carryingWeapon ()
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void updateIfCarryingWeapon ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual void setUseRandomWalkEnabledState (bool state)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual void setOriginalUseRandomWalkEnabledState ()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual bool isAIBehaviorAttackInProcess ()
|
||||
{
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void checkNoWeaponsAvailableState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkIfDisableCurrentWeaponToChangeAttackMode (string newModeName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void changeCurrentAttackMode (string newModeName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setIsCurrentCharacterTurn (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setAIOnPlayerTeamState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setCurrentCharacterTurnTarget (GameObject newTarget)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void stopCurrentAttackInProcess ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setTurnBasedCombatActionActiveState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkStateOnCharacterDead ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkAIBehaviorStateOnCharacterSpawn ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkAIBehaviorStateOnCharacterDespawn ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void stopAttackState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setAttackEnabledState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setAttackEnabledStateFromEditor (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateCurrentTargetSelectedInfo ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateAIPassengerBehavior ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void getOffFromVehicle ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void removeStateOnVehicle ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setAICharacterOnVehicle (GameObject newVehicle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setCurrentPlayerControllerPartner (playerController newPlayerController)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ffa02f5dd4f9b340ae20bc74e509eba
|
||||
timeCreated: 1602681429
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/AI Behavior
|
||||
Info.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,950 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AIAbilitiesSystemBrain : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool systemEnabled = true;
|
||||
|
||||
public float currentMinDistanceToAttack = 7;
|
||||
|
||||
[Space]
|
||||
[Header ("Attack Settings")]
|
||||
[Space]
|
||||
|
||||
public bool attackEnabled;
|
||||
|
||||
public Vector2 randomAttackRangeRate;
|
||||
|
||||
[Space]
|
||||
[Header ("Abilities Settings")]
|
||||
[Space]
|
||||
|
||||
public bool changeAbilityAfterTimeEnabled;
|
||||
|
||||
public bool changeAbilityRandomly;
|
||||
|
||||
public Vector2 randomChangeAbilityRate;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useCustomListToChangeAbility;
|
||||
|
||||
public List<string> customListToChangeAbility = new List<string> ();
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useCustomListToChangeAbilityInfoList;
|
||||
|
||||
public List<customListToChangeAbilityInfo> customListToChangeAbilityInfoList = new List<customListToChangeAbilityInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Abilities List")]
|
||||
[Space]
|
||||
|
||||
public int currentAbilityIndex;
|
||||
|
||||
[Space]
|
||||
|
||||
public List<AIAbilityInfo> AIAbilityInfoList = new List<AIAbilityInfo> ();
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public int currentAbilityStateIndex;
|
||||
|
||||
[Space]
|
||||
|
||||
public List<AIAbilityStatesInfo> AIAbilityStatesInfoList = new List<AIAbilityStatesInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool changeWaitToActivateAttackEnabled = true;
|
||||
|
||||
public bool useWaitToActivateAttackActiveCounter;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool systemActive;
|
||||
|
||||
public bool waitingForAttackActive;
|
||||
float currentRandomTimeToAttack;
|
||||
|
||||
public bool canUseAttackActive;
|
||||
|
||||
public bool attackStatePaused;
|
||||
|
||||
public bool insideMinDistanceToAttack;
|
||||
|
||||
public float currentAttackRate;
|
||||
|
||||
public bool abilityInProcess;
|
||||
|
||||
public bool onSpotted;
|
||||
|
||||
public bool checkingToChangeAbilityActive;
|
||||
|
||||
public bool waitToActivateAttackActive;
|
||||
|
||||
public int waitToActivateAttackActiveCounter = 0;
|
||||
|
||||
public bool turnBasedCombatActionActive;
|
||||
|
||||
public float currentPathDistanceToTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnCombatActive;
|
||||
public UnityEvent eventOnCombatActive;
|
||||
public UnityEvent eventOnCombatDeactivate;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public AINavMesh mainAINavmeshManager;
|
||||
public playerAbilitiesSystem mainPlayerAbilitiesSystem;
|
||||
public playerController mainPlayerController;
|
||||
|
||||
|
||||
float lastTimeAttack;
|
||||
|
||||
int currentAttackTypeIndex;
|
||||
|
||||
int currentAttackIndex;
|
||||
|
||||
int currentAttackTypeToAlternateIndex;
|
||||
|
||||
float currentPauseAttackStateDuration;
|
||||
float lastTimeAttackPauseWithDuration;
|
||||
|
||||
float randomWaitTime;
|
||||
|
||||
float lastTimeAttackActivated;
|
||||
|
||||
bool AIPaused;
|
||||
|
||||
AIAbilityInfo currentAIAbilityInfo;
|
||||
|
||||
bool currentAIAbilityInfoAssigned;
|
||||
|
||||
Coroutine abilityCoroutine;
|
||||
Coroutine pauseMainBehaviorCoroutine;
|
||||
|
||||
float lastTimeChangeAbility;
|
||||
|
||||
float timeToChangeAbility;
|
||||
|
||||
AIAbilityStatesInfo currentAIAbilityStatesInfo;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (systemActive) {
|
||||
systemActive = false;
|
||||
|
||||
setSystemActiveState (true);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAI ()
|
||||
{
|
||||
if (systemActive) {
|
||||
AIPaused = mainFindObjectivesSystem.isAIPaused ();
|
||||
|
||||
if (!AIPaused) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetStates ()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void updateInsideMinDistance (bool newInsideMinDistanceToAttack)
|
||||
{
|
||||
insideMinDistanceToAttack = newInsideMinDistanceToAttack;
|
||||
|
||||
if (insideMinDistanceToAttack) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBehavior ()
|
||||
{
|
||||
if (!systemActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (AIPaused) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (turnBasedCombatActionActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkAttackState ();
|
||||
}
|
||||
|
||||
public void checkAttackState ()
|
||||
{
|
||||
if (!attackEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
insideMinDistanceToAttack = mainFindObjectivesSystem.insideMinDistanceToAttack;
|
||||
|
||||
if (!insideMinDistanceToAttack && currentAIAbilityInfoAssigned && !currentAIAbilityInfo.ignoreInsideMinDistanceToAttackTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPauseAttackStateDuration > 0) {
|
||||
if (Time.time > currentPauseAttackStateDuration + lastTimeAttackPauseWithDuration) {
|
||||
|
||||
attackStatePaused = false;
|
||||
|
||||
currentPauseAttackStateDuration = 0;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (waitToActivateAttackActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (turnBasedCombatActionActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canUseAttackActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainFindObjectivesSystem.isOnSpotted ()) {
|
||||
if (!onSpotted) {
|
||||
lastTimeAttackActivated = Time.time;
|
||||
|
||||
onSpotted = true;
|
||||
}
|
||||
} else {
|
||||
if (onSpotted) {
|
||||
|
||||
onSpotted = false;
|
||||
|
||||
checkingToChangeAbilityActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (onSpotted) {
|
||||
if (changeAbilityAfterTimeEnabled && !abilityInProcess) {
|
||||
if (!checkingToChangeAbilityActive) {
|
||||
lastTimeChangeAbility = Time.time;
|
||||
|
||||
checkingToChangeAbilityActive = true;
|
||||
|
||||
timeToChangeAbility = Random.Range (randomChangeAbilityRate.x, randomChangeAbilityRate.y);
|
||||
} else {
|
||||
if (Time.time > lastTimeChangeAbility + timeToChangeAbility) {
|
||||
setNextAbility ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Time.time > currentAttackRate + lastTimeAttackActivated && !abilityInProcess) {
|
||||
bool checkDistanceConditionResult = false;
|
||||
|
||||
mainFindObjectivesSystem.updateCurrentPathDistanceToTargetValue ();
|
||||
|
||||
currentPathDistanceToTarget = mainFindObjectivesSystem.currentPathDistanceToTarget;
|
||||
|
||||
if (currentPathDistanceToTarget < 1) {
|
||||
currentPathDistanceToTarget = mainFindObjectivesSystem.getDistanceToTarget ();
|
||||
}
|
||||
|
||||
if (currentPathDistanceToTarget <= currentMinDistanceToAttack) {
|
||||
if (currentAIAbilityInfo.checkVerticalDistanceToTarget) {
|
||||
float verticalDistanceToCurrentEnemyPosition = mainFindObjectivesSystem.getVerticalDistanceToCurrentEnemyPosition ();
|
||||
|
||||
if (verticalDistanceToCurrentEnemyPosition != 0) {
|
||||
if (verticalDistanceToCurrentEnemyPosition < currentAIAbilityInfo.maxVerticalDistanceToTarget) {
|
||||
checkDistanceConditionResult = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
checkDistanceConditionResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool checkUseAbilityConditionResult = false;
|
||||
|
||||
if (checkDistanceConditionResult) {
|
||||
if (mainFindObjectivesSystem.checkIfMinimumAngleToAttack () &&
|
||||
!mainPlayerController.isActionActive () &&
|
||||
mainPlayerController.canPlayerMove ()) {
|
||||
|
||||
checkUseAbilityConditionResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkUseAbilityConditionResult) {
|
||||
|
||||
bool canActivateAbilityResult = true;
|
||||
|
||||
if (currentAIAbilityInfo.useCustomAbilityDistance) {
|
||||
if (currentPathDistanceToTarget > currentAIAbilityInfo.customAbilityDistance) {
|
||||
canActivateAbilityResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAbilityResult) {
|
||||
if (mainFindObjectivesSystem.isAIBehaviorAttackInProcess ()) {
|
||||
if (showDebugPrint) {
|
||||
print ("attack in process in current main behavior, cancelling ability action");
|
||||
}
|
||||
|
||||
canActivateAbilityResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAbilityResult) {
|
||||
if (mainFindObjectivesSystem.isAIPaused ()) {
|
||||
canActivateAbilityResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAbilityResult) {
|
||||
if (currentAIAbilityInfo.sendSignalToActivateAbilityEnabled) {
|
||||
if (mainPlayerAbilitiesSystem.checkIfAbilitiesOnUseOrCooldown (currentAIAbilityInfo.Name)) {
|
||||
canActivateAbilityResult = false;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("current ability to use is on cool down, cancelling its usage " + currentAIAbilityInfo.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAbilityResult) {
|
||||
if (showDebugPrint) {
|
||||
print (currentPathDistanceToTarget + " " + mainAINavmeshManager.getCurrentTarget ().name);
|
||||
}
|
||||
|
||||
if (currentAIAbilityInfo.useProbabilityToUseAbility) {
|
||||
float currentProbability = Random.Range (0, 100);
|
||||
|
||||
if (currentProbability > currentAIAbilityInfo.probabilityToUseAbility) {
|
||||
lastTimeAttackActivated = Time.time;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("probability to activate ability failed, cancelling");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
attackTarget ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("activate ability attack " + currentAttackRate);
|
||||
}
|
||||
|
||||
if (currentAIAbilityInfo.useCustomRandomAttackRangeRate) {
|
||||
currentAttackRate = Random.Range (currentAIAbilityInfo.customRandomAttackRangeRate.x, currentAIAbilityInfo.customRandomAttackRangeRate.y);
|
||||
} else {
|
||||
currentAttackRate = Random.Range (randomAttackRangeRate.x, randomAttackRangeRate.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setChangeAbilityAfterTimeEnabledState (bool state)
|
||||
{
|
||||
changeAbilityAfterTimeEnabled = state;
|
||||
}
|
||||
|
||||
public void setNextAbility ()
|
||||
{
|
||||
bool newAbilityIndexFound = false;
|
||||
|
||||
int previuosAbilityIndex = currentAbilityIndex;
|
||||
|
||||
int newAbilityIndex = -1;
|
||||
|
||||
int loopCount = 0;
|
||||
|
||||
if (changeAbilityRandomly) {
|
||||
while (!newAbilityIndexFound) {
|
||||
|
||||
if (useCustomListToChangeAbility) {
|
||||
if (useCustomListToChangeAbilityInfoList) {
|
||||
int currentIndex = customListToChangeAbilityInfoList.FindIndex (s => s.isCustomListActive == true);
|
||||
|
||||
if (currentIndex > -1) {
|
||||
newAbilityIndex = Random.Range (0, customListToChangeAbilityInfoList [currentIndex].customListToChangeAbility.Count);
|
||||
|
||||
string temporalAbilityName = customListToChangeAbilityInfoList [currentIndex].customListToChangeAbility [newAbilityIndex];
|
||||
|
||||
newAbilityIndex = AIAbilityInfoList.FindIndex (s => s.Name.Equals (temporalAbilityName));
|
||||
|
||||
if (newAbilityIndex < 0) {
|
||||
newAbilityIndex = 0;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setting new ability index " + newAbilityIndex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newAbilityIndex = Random.Range (0, customListToChangeAbility.Count);
|
||||
|
||||
string temporalAbilityName = customListToChangeAbility [newAbilityIndex];
|
||||
|
||||
newAbilityIndex = AIAbilityInfoList.FindIndex (s => s.Name.Equals (temporalAbilityName));
|
||||
|
||||
if (newAbilityIndex < 0) {
|
||||
newAbilityIndex = 0;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setting new ability index " + newAbilityIndex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newAbilityIndex = Random.Range (0, AIAbilityInfoList.Count);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setting new ability index " + newAbilityIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (newAbilityIndex != currentAbilityIndex) {
|
||||
if (AIAbilityInfoList [newAbilityIndex].useAbilityEnabled) {
|
||||
newAbilityIndexFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
loopCount++;
|
||||
|
||||
if (loopCount > AIAbilityInfoList.Count * 4) {
|
||||
newAbilityIndexFound = true;
|
||||
|
||||
newAbilityIndex = previuosAbilityIndex;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newAbilityIndex = currentAbilityIndex;
|
||||
|
||||
while (!newAbilityIndexFound) {
|
||||
newAbilityIndex++;
|
||||
|
||||
if (newAbilityIndex >= AIAbilityInfoList.Count) {
|
||||
newAbilityIndex = 0;
|
||||
}
|
||||
|
||||
if (AIAbilityInfoList [newAbilityIndex].useAbilityEnabled) {
|
||||
newAbilityIndexFound = true;
|
||||
}
|
||||
|
||||
loopCount++;
|
||||
|
||||
if (loopCount > AIAbilityInfoList.Count * 4) {
|
||||
newAbilityIndexFound = true;
|
||||
|
||||
newAbilityIndex = previuosAbilityIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newAbilityIndex > -1) {
|
||||
setNewAbilityByName (AIAbilityInfoList [newAbilityIndex].Name);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("changing ability to " + AIAbilityInfoList [newAbilityIndex].Name);
|
||||
}
|
||||
}
|
||||
|
||||
checkingToChangeAbilityActive = false;
|
||||
}
|
||||
|
||||
public void updateAIAttackState (bool newCanUseAttackActiveState)
|
||||
{
|
||||
canUseAttackActive = newCanUseAttackActiveState;
|
||||
}
|
||||
|
||||
public void setSystemEnabledState (bool state)
|
||||
{
|
||||
if (systemEnabled == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
systemEnabled = state;
|
||||
|
||||
setSystemActiveState (systemEnabled);
|
||||
}
|
||||
|
||||
public void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!systemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (systemActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
systemActive = state;
|
||||
|
||||
if (systemActive) {
|
||||
lastTimeAttackActivated = Time.time;
|
||||
|
||||
setNewAbilityByName (AIAbilityInfoList [currentAbilityIndex].Name);
|
||||
|
||||
setNewAbilityStateByName (AIAbilityStatesInfoList [currentAbilityStateIndex].Name);
|
||||
|
||||
if (currentAIAbilityInfo.useCustomRandomAttackRangeRate) {
|
||||
currentAttackRate = Random.Range (currentAIAbilityInfo.customRandomAttackRangeRate.x, currentAIAbilityInfo.customRandomAttackRangeRate.y);
|
||||
} else {
|
||||
currentAttackRate = Random.Range (randomAttackRangeRate.x, randomAttackRangeRate.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onSpotted = false;
|
||||
|
||||
checkingToChangeAbilityActive = false;
|
||||
|
||||
checkEventsOnCombatStateChange (systemActive);
|
||||
|
||||
waitToActivateAttackActive = false;
|
||||
|
||||
waitToActivateAttackActiveCounter = 0;
|
||||
}
|
||||
|
||||
void checkEventsOnCombatStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnCombatActive) {
|
||||
if (state) {
|
||||
eventOnCombatActive.Invoke ();
|
||||
} else {
|
||||
eventOnCombatDeactivate.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseAttackDuringXTime (float newDuration)
|
||||
{
|
||||
currentPauseAttackStateDuration = newDuration;
|
||||
|
||||
lastTimeAttackPauseWithDuration = Time.time;
|
||||
|
||||
attackStatePaused = true;
|
||||
}
|
||||
|
||||
public void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
if (!changeWaitToActivateAttackEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useWaitToActivateAttackActiveCounter) {
|
||||
if (state) {
|
||||
waitToActivateAttackActiveCounter++;
|
||||
} else {
|
||||
waitToActivateAttackActiveCounter--;
|
||||
|
||||
if (waitToActivateAttackActiveCounter < 0) {
|
||||
waitToActivateAttackActiveCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (waitToActivateAttackActiveCounter > 0) {
|
||||
if (waitToActivateAttackActive) {
|
||||
return;
|
||||
} else {
|
||||
state = true;
|
||||
}
|
||||
} else {
|
||||
if (!waitToActivateAttackActive) {
|
||||
return;
|
||||
} else {
|
||||
state = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
waitToActivateAttackActive = state;
|
||||
}
|
||||
|
||||
public void resetBehaviorStates ()
|
||||
{
|
||||
resetStates ();
|
||||
|
||||
waitingForAttackActive = false;
|
||||
|
||||
|
||||
|
||||
insideMinDistanceToAttack = false;
|
||||
}
|
||||
|
||||
public void attackTarget ()
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("activate ability attack");
|
||||
}
|
||||
|
||||
stopPauseMainAttackBehaviorCoroutine ();
|
||||
|
||||
pauseMainBehaviorCoroutine = StartCoroutine (pauseMainAttackBehaviorCoroutine ());
|
||||
|
||||
abilityInProcess = true;
|
||||
|
||||
if (currentAIAbilityInfo.abilityInputHoldType || currentAIAbilityInfo.abilityInputToggleType) {
|
||||
stopAbilityInputHoldCoroutine ();
|
||||
|
||||
abilityCoroutine = StartCoroutine (abilityInputHoldCoroutine ());
|
||||
} else {
|
||||
if (currentAIAbilityInfo.sendSignalToActivateAbilityEnabled) {
|
||||
mainPlayerAbilitiesSystem.inputSelectAndPressDownNewAbility (currentAIAbilityInfo.Name);
|
||||
}
|
||||
|
||||
if (currentAIAbilityInfo.useEventsOnAbility) {
|
||||
currentAIAbilityInfo.eventOnAbilityStart.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stopAbilityInputHoldCoroutine ()
|
||||
{
|
||||
if (abilityCoroutine != null) {
|
||||
StopCoroutine (abilityCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator abilityInputHoldCoroutine ()
|
||||
{
|
||||
if (currentAIAbilityInfo.sendSignalToActivateAbilityEnabled) {
|
||||
mainPlayerAbilitiesSystem.inputSelectAndPressDownNewSeparatedAbility (currentAIAbilityInfo.Name);
|
||||
}
|
||||
|
||||
if (currentAIAbilityInfo.useEventsOnAbility) {
|
||||
currentAIAbilityInfo.eventOnAbilityStart.Invoke ();
|
||||
}
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (currentAIAbilityInfo.timeToHoldAndReleaseAbilityInput);
|
||||
|
||||
yield return delay;
|
||||
|
||||
if (currentAIAbilityInfo.sendSignalToActivateAbilityEnabled) {
|
||||
if (currentAIAbilityInfo.abilityInputHoldType) {
|
||||
mainPlayerAbilitiesSystem.inputSelectAndPressUpNewSeparatedAbility ();
|
||||
}
|
||||
|
||||
if (currentAIAbilityInfo.abilityInputToggleType) {
|
||||
mainPlayerAbilitiesSystem.inputSelectAndPressDownNewSeparatedAbility (currentAIAbilityInfo.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentAIAbilityInfo.useEventsOnAbility) {
|
||||
currentAIAbilityInfo.eventOnAbilityEnd.Invoke ();
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
void stopPauseMainAttackBehaviorCoroutine ()
|
||||
{
|
||||
if (pauseMainBehaviorCoroutine != null) {
|
||||
StopCoroutine (pauseMainBehaviorCoroutine);
|
||||
}
|
||||
|
||||
mainFindObjectivesSystem.setBehaviorStatesPausedState (false);
|
||||
|
||||
lastTimeAttackActivated = Time.time;
|
||||
|
||||
abilityInProcess = false;
|
||||
}
|
||||
|
||||
IEnumerator pauseMainAttackBehaviorCoroutine ()
|
||||
{
|
||||
mainFindObjectivesSystem.setBehaviorStatesPausedState (true);
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (currentAIAbilityInfo.abilityDuration);
|
||||
|
||||
yield return delay;
|
||||
|
||||
mainFindObjectivesSystem.setBehaviorStatesPausedState (false);
|
||||
|
||||
abilityInProcess = false;
|
||||
|
||||
lastTimeAttackActivated = Time.time;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void resetAttackState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void disableOnSpottedState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void setAndActivateAbilityByName (string abilityName)
|
||||
{
|
||||
setNewAbilityByName (abilityName);
|
||||
|
||||
attackTarget ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("activate ability attack " + currentAttackRate);
|
||||
}
|
||||
|
||||
if (currentAIAbilityInfo.useCustomRandomAttackRangeRate) {
|
||||
currentAttackRate = Random.Range (currentAIAbilityInfo.customRandomAttackRangeRate.x, currentAIAbilityInfo.customRandomAttackRangeRate.y);
|
||||
} else {
|
||||
currentAttackRate = Random.Range (randomAttackRangeRate.x, randomAttackRangeRate.y);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewAbilityByName (string abilityName)
|
||||
{
|
||||
if (!systemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newAbilityIndex = AIAbilityInfoList.FindIndex (s => s.Name.Equals (abilityName));
|
||||
|
||||
if (newAbilityIndex > -1) {
|
||||
if (currentAIAbilityInfo != null) {
|
||||
currentAIAbilityInfo.isCurrentAbility = false;
|
||||
}
|
||||
|
||||
currentAIAbilityInfo = AIAbilityInfoList [newAbilityIndex];
|
||||
|
||||
currentAIAbilityInfo.isCurrentAbility = true;
|
||||
|
||||
currentAIAbilityInfoAssigned = true;
|
||||
|
||||
currentAbilityIndex = newAbilityIndex;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setting current ability index " + currentAbilityIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewMinDistanceToAttack (float newValue)
|
||||
{
|
||||
currentMinDistanceToAttack = newValue;
|
||||
}
|
||||
|
||||
public void setNewAbilityStateByName (string abilityStateName)
|
||||
{
|
||||
if (!systemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newAbilityStateIndex = AIAbilityStatesInfoList.FindIndex (s => s.Name.Equals (abilityStateName));
|
||||
|
||||
if (newAbilityStateIndex > -1) {
|
||||
if (currentAIAbilityStatesInfo != null) {
|
||||
currentAIAbilityStatesInfo.isCurrentState = false;
|
||||
}
|
||||
|
||||
currentAIAbilityStatesInfo = AIAbilityStatesInfoList [newAbilityStateIndex];
|
||||
|
||||
currentAIAbilityStatesInfo.isCurrentState = true;
|
||||
|
||||
currentMinDistanceToAttack = currentAIAbilityStatesInfo.minDistanceToAttack;
|
||||
|
||||
currentAbilityStateIndex = newAbilityStateIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopCurrentAttackInProcess ()
|
||||
{
|
||||
if (abilityInProcess) {
|
||||
stopPauseMainAttackBehaviorCoroutine ();
|
||||
|
||||
stopAbilityInputHoldCoroutine ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTurnBasedCombatActionActiveState (bool state)
|
||||
{
|
||||
turnBasedCombatActionActive = state;
|
||||
}
|
||||
|
||||
public bool isAbilityInProcess ()
|
||||
{
|
||||
return abilityInProcess;
|
||||
}
|
||||
|
||||
public void checkAIBehaviorStateOnCharacterSpawn ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void checkAIBehaviorStateOnCharacterDespawn ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void setChangeAbilityRandomlyState (bool state)
|
||||
{
|
||||
changeAbilityRandomly = state;
|
||||
}
|
||||
|
||||
public void setUseCustomListToChangeAbilityState (bool state)
|
||||
{
|
||||
useCustomListToChangeAbility = state;
|
||||
}
|
||||
|
||||
public void setCustomListToChangeAbility (List<string> newList)
|
||||
{
|
||||
customListToChangeAbility = newList;
|
||||
}
|
||||
|
||||
public void setUseCustomListToChangeAbilityInfoListState (bool state)
|
||||
{
|
||||
useCustomListToChangeAbilityInfoList = state;
|
||||
}
|
||||
|
||||
public void setCustomListToChangeAbilityInfoListByName (string newName)
|
||||
{
|
||||
for (int i = 0; i < customListToChangeAbilityInfoList.Count; i++) {
|
||||
if (customListToChangeAbilityInfoList [i].Name.Equals (newName)) {
|
||||
customListToChangeAbilityInfoList [i].isCustomListActive = true;
|
||||
} else {
|
||||
customListToChangeAbilityInfoList [i].isCustomListActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAttackEnabledState (bool state)
|
||||
{
|
||||
attackEnabled = state;
|
||||
}
|
||||
|
||||
public void setAttackEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setAttackEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update AI Abilities Brain " + gameObject.name, gameObject);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class AIAbilityInfo
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
|
||||
public bool useAbilityEnabled = true;
|
||||
|
||||
public bool isCurrentAbility;
|
||||
|
||||
public bool sendSignalToActivateAbilityEnabled = true;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useProbabilityToUseAbility;
|
||||
[Range (0, 100)] public float probabilityToUseAbility;
|
||||
|
||||
[Space]
|
||||
[Header ("Distance Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useCustomAbilityDistance;
|
||||
public float customAbilityDistance;
|
||||
|
||||
public bool checkVerticalDistanceToTarget;
|
||||
public float maxVerticalDistanceToTarget;
|
||||
|
||||
public bool ignoreInsideMinDistanceToAttackTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Ability Settings")]
|
||||
[Space]
|
||||
|
||||
public bool abilityInputHoldType;
|
||||
|
||||
public bool abilityInputToggleType;
|
||||
|
||||
public float timeToHoldAndReleaseAbilityInput;
|
||||
|
||||
public float abilityDuration;
|
||||
|
||||
[Space]
|
||||
[Header ("Custom Random Attack Range Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useCustomRandomAttackRangeRate;
|
||||
|
||||
public Vector2 customRandomAttackRangeRate;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnAbility;
|
||||
|
||||
public UnityEvent eventOnAbilityStart;
|
||||
|
||||
public UnityEvent eventOnAbilityEnd;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class AIAbilityStatesInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public float minDistanceToAttack = 7;
|
||||
|
||||
public bool isCurrentState;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class customListToChangeAbilityInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public bool isCustomListActive;
|
||||
|
||||
public List<string> customListToChangeAbility = new List<string> ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d5e45b268828c3499ed6c35d1ce8818
|
||||
timeCreated: 1647942690
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/AIAbilitiesSystemBrain.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,297 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AIAimRotationManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool AIAimRotationEnabled = true;
|
||||
|
||||
public bool setAIAimRotationStateOnAwake;
|
||||
|
||||
public string AIAimRotationStateOnAwakeName;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Aim Rotation States List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<AIAimRotationInfo> AIAimRotationInfoList = new List<AIAimRotationInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool randomAimPositionOffsetActive;
|
||||
public string currentAIAimRotationInfoName;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerCamera mainPlayerCamera;
|
||||
public playerController mainPlayerController;
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
|
||||
|
||||
float lastTimeRandomAimPositionOffsetActive = 0;
|
||||
|
||||
float currentWaitTimeRandomAimPositionOffset;
|
||||
float currentRandomAimPositionOffset;
|
||||
float currentRandomAimPositionOffsetDuration;
|
||||
|
||||
float currentMinRandomAimPositionOffset;
|
||||
|
||||
bool currentUseMinRandomAimPositionOffset;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
Vector2 randomAimPositionOffsetRange;
|
||||
Vector2 randomAimPositionOffsetDurationRange;
|
||||
Vector2 randomAimPositionOffsetWaitRange;
|
||||
|
||||
void Awake ()
|
||||
{
|
||||
if (setAIAimRotationStateOnAwake) {
|
||||
setAIAImRotationState (AIAimRotationStateOnAwakeName);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
|
||||
randomAimPositionOffsetActive = false;
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (!randomAimPositionOffsetActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mainFindObjectivesSystem.isOnSpotted ()) {
|
||||
if (currentWaitTimeRandomAimPositionOffset != 0) {
|
||||
if (showDebugPrint) {
|
||||
print ("character is not attacking a target, reseting random aim position offset state");
|
||||
}
|
||||
|
||||
disableAndResetRandomAimPositionValues ();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentWaitTimeRandomAimPositionOffset == 0) {
|
||||
currentWaitTimeRandomAimPositionOffset = Random.Range (randomAimPositionOffsetWaitRange.x, randomAimPositionOffsetWaitRange.y);
|
||||
|
||||
currentRandomAimPositionOffset = Random.Range (randomAimPositionOffsetRange.x, randomAimPositionOffsetRange.y);
|
||||
|
||||
if (currentUseMinRandomAimPositionOffset) {
|
||||
if (currentMinRandomAimPositionOffset != 0) {
|
||||
if (currentRandomAimPositionOffset > 0) {
|
||||
if (currentRandomAimPositionOffset < currentMinRandomAimPositionOffset) {
|
||||
currentRandomAimPositionOffset = currentMinRandomAimPositionOffset;
|
||||
}
|
||||
} else {
|
||||
if (Mathf.Abs (currentRandomAimPositionOffset) < currentMinRandomAimPositionOffset) {
|
||||
currentRandomAimPositionOffset = -currentMinRandomAimPositionOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastTimeRandomAimPositionOffsetActive = Time.time;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("select wait time " + currentWaitTimeRandomAimPositionOffset);
|
||||
}
|
||||
} else {
|
||||
if (Time.time > lastTimeRandomAimPositionOffsetActive + currentWaitTimeRandomAimPositionOffset) {
|
||||
if (currentRandomAimPositionOffsetDuration == 0) {
|
||||
currentRandomAimPositionOffsetDuration = Random.Range (randomAimPositionOffsetDurationRange.x, randomAimPositionOffsetDurationRange.y);
|
||||
|
||||
mainFindObjectivesSystem.addLookDirectionToTargetOffset (currentRandomAimPositionOffset);
|
||||
|
||||
lastTimeRandomAimPositionOffsetActive = Time.time;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("select offset duration " + currentRandomAimPositionOffsetDuration);
|
||||
|
||||
print ("current random position offset " + currentRandomAimPositionOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentRandomAimPositionOffsetDuration != 0) {
|
||||
if (Time.time > lastTimeRandomAimPositionOffsetActive + currentRandomAimPositionOffsetDuration) {
|
||||
disableAndResetRandomAimPositionValues ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void disableAndResetRandomAimPositionValues ()
|
||||
{
|
||||
mainFindObjectivesSystem.addLookDirectionToTargetOffset (0);
|
||||
|
||||
lastTimeRandomAimPositionOffsetActive = Time.time;
|
||||
|
||||
currentWaitTimeRandomAimPositionOffset = 0;
|
||||
|
||||
currentRandomAimPositionOffsetDuration = 0;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("reset values");
|
||||
}
|
||||
}
|
||||
|
||||
public void setAIAImRotationState (string stateName)
|
||||
{
|
||||
if (!AIAimRotationEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newIndex = AIAimRotationInfoList.FindIndex (s => s.Name.Equals (stateName));
|
||||
|
||||
if (newIndex > -1) {
|
||||
AIAimRotationInfo currentInfo = AIAimRotationInfoList [newIndex];
|
||||
|
||||
if (currentInfo.stateEnabled) {
|
||||
currentAIAimRotationInfoName = currentInfo.Name;
|
||||
|
||||
mainPlayerCamera.changeRotationSpeedValue (currentInfo.verticalAimRotationSpeed, currentInfo.horizontalAimRotationSpeed);
|
||||
|
||||
mainPlayerCamera.updateOriginalRotationSpeedValues ();
|
||||
|
||||
if (currentInfo.setRotateDirectlyTowardCameraOnStrafe) {
|
||||
mainPlayerController.setRotateDirectlyTowardCameraOnStrafeState (currentInfo.rotateDirectlyTowardCameraOnStrafe);
|
||||
}
|
||||
|
||||
if (currentInfo.setLookAtTargetSpeed) {
|
||||
mainFindObjectivesSystem.setLookAtTargetSpeedValue (currentInfo.lookAtTargetSpeed);
|
||||
}
|
||||
|
||||
if (currentInfo.setAutoTurnSpeed) {
|
||||
mainPlayerController.setAutoTurnSpeed (currentInfo.autoTurnSpeed);
|
||||
}
|
||||
|
||||
if (currentInfo.setAimTurnSpeed) {
|
||||
mainPlayerController.setAimTurnSpeed (currentInfo.aimTurnSpeed);
|
||||
}
|
||||
|
||||
if (randomAimPositionOffsetActive) {
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
|
||||
if (currentInfo.addRandomAimPositionOffset) {
|
||||
randomAimPositionOffsetActive = true;
|
||||
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
|
||||
randomAimPositionOffsetRange = currentInfo.randomAimPositionOffsetRange;
|
||||
randomAimPositionOffsetDurationRange = currentInfo.randomAimPositionOffsetDurationRange;
|
||||
randomAimPositionOffsetWaitRange = currentInfo.randomAimPositionOffsetWaitRange;
|
||||
|
||||
currentMinRandomAimPositionOffset = currentInfo.minRandomAimPositionOffset;
|
||||
|
||||
currentUseMinRandomAimPositionOffset = currentInfo.useMinRandomAimPositionOffset;
|
||||
|
||||
lastTimeRandomAimPositionOffsetActive = 0;
|
||||
|
||||
currentWaitTimeRandomAimPositionOffset = 0;
|
||||
} else {
|
||||
mainFindObjectivesSystem.addLookDirectionToTargetOffset (0);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setting aim state " + currentAIAimRotationInfoName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAIAimRotationEnabledState (bool state)
|
||||
{
|
||||
AIAimRotationEnabled = state;
|
||||
}
|
||||
|
||||
public void setAIAimRotationEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setAIAimRotationEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update AI Aim Rotation Manager " + gameObject.name, gameObject);
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class AIAimRotationInfo
|
||||
{
|
||||
[Header ("Aiming Rotation Speed Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
public bool stateEnabled = true;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setAimRotationSpeed;
|
||||
public float verticalAimRotationSpeed;
|
||||
public float horizontalAimRotationSpeed;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setRotateDirectlyTowardCameraOnStrafe;
|
||||
public bool rotateDirectlyTowardCameraOnStrafe;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setLookAtTargetSpeed;
|
||||
public float lookAtTargetSpeed;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setAutoTurnSpeed;
|
||||
public float autoTurnSpeed;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setAimTurnSpeed;
|
||||
public float aimTurnSpeed;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool addRandomAimPositionOffset;
|
||||
public Vector2 randomAimPositionOffsetDurationRange;
|
||||
public Vector2 randomAimPositionOffsetWaitRange;
|
||||
|
||||
[Space]
|
||||
|
||||
public Vector2 randomAimPositionOffsetRange;
|
||||
|
||||
public bool useMinRandomAimPositionOffset;
|
||||
public float minRandomAimPositionOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8ff7c64b9614fb40b7e893bfe0a7d4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/AIAimRotationManager.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a211c0e08aff4084091a706dc1375518
|
||||
timeCreated: 1620622963
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/AIFireWeaponsSystemBrain.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 654eeb5ecbdc8874bb991b0b9d93bde9
|
||||
timeCreated: 1647925717
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/AIPowersSystemBrain.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,888 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AITurnBasedCombatSystemBrain : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool systemEnabled = true;
|
||||
|
||||
|
||||
public bool checkDistanceToTargetEnabled;
|
||||
|
||||
public float currentMinDistanceToAttack = 7;
|
||||
|
||||
public float defaultMatchOffset = 1;
|
||||
|
||||
[Space]
|
||||
[Header ("Attack Settings")]
|
||||
[Space]
|
||||
|
||||
public bool attackEnabled;
|
||||
|
||||
public float minWaitToActivateAttack = 0.5f;
|
||||
|
||||
public bool useProbabilityToUseAttack;
|
||||
[Range (0, 100)] public float probabilityToUseAttack;
|
||||
|
||||
public bool ignoreProbabilityToCheckCategory;
|
||||
public bool ignoreProbabilityToUseAttack;
|
||||
|
||||
public bool ignoreUseStatToUseAction;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool ignoreIfLastCategoryPreviouslySelected;
|
||||
|
||||
public bool ignoreIfLastAttackPreviouslySelected;
|
||||
|
||||
[Space]
|
||||
|
||||
public List<turnBasedCombatAttackCategoryInfo> turnBasedCombatAttackCategoryInfoList = new List<turnBasedCombatAttackCategoryInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool systemActive;
|
||||
|
||||
public bool isCurrentCharacterTurn;
|
||||
|
||||
public bool AIOnPlayerTeam;
|
||||
|
||||
[Space]
|
||||
|
||||
public int lastAttackUsedIndex = -1;
|
||||
|
||||
public int lastCategoryIndex = -1;
|
||||
|
||||
public bool currentAttackInProcess;
|
||||
|
||||
public bool delayToActiveteAttackInProcess;
|
||||
|
||||
public string currentCommandName;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool waitingForAttackActive;
|
||||
float currentRandomTimeToAttack;
|
||||
|
||||
public bool canUseAttackActive;
|
||||
|
||||
public bool attackStatePaused;
|
||||
|
||||
public bool insideMinDistanceToAttack;
|
||||
|
||||
// public float currentAttackRate;
|
||||
|
||||
// public bool onSpotted;
|
||||
|
||||
public bool waitToActivateAttackActive;
|
||||
|
||||
public bool blockActive;
|
||||
|
||||
public GameObject currentTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnCombatActive;
|
||||
public UnityEvent eventOnCombatActive;
|
||||
public UnityEvent eventOnCombatDeactivate;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useEventIfBlockActiveOnCurrentTurn;
|
||||
public UnityEvent eventIfBlockActiveOnCurrentTurn;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public AINavMesh mainAINavmeshManager;
|
||||
|
||||
public playerController mainPlayerController;
|
||||
|
||||
public characterToReceiveOrders mainCharacterToReceiveOrders;
|
||||
|
||||
public turnBasedCombatActionsSystem mainTurnBasedCombatActionsSystem;
|
||||
|
||||
public matchPlayerToTargetSystem mainMatchPlayerToTargetSystem;
|
||||
|
||||
public playerStatsSystem mainPlayerStatsSystem;
|
||||
|
||||
public health mainHealth;
|
||||
|
||||
|
||||
float lastTimeAttack;
|
||||
|
||||
int currentAttackTypeIndex;
|
||||
|
||||
int currentAttackIndex;
|
||||
|
||||
int currentAttackTypeToAlternateIndex;
|
||||
|
||||
float currentPauseAttackStateDuration;
|
||||
float lastTimeAttackPauseWithDuration;
|
||||
|
||||
float randomWaitTime;
|
||||
|
||||
float lastTimeAttackActivated;
|
||||
|
||||
float currentPathDistanceToTarget;
|
||||
|
||||
bool AIPaused;
|
||||
|
||||
turnBasedCombatAttackInfo currentTurnBasedCombatAttackInfo;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (systemActive) {
|
||||
systemActive = false;
|
||||
|
||||
setSystemActiveState (true);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAI ()
|
||||
{
|
||||
if (systemActive) {
|
||||
AIPaused = mainFindObjectivesSystem.isAIPaused ();
|
||||
|
||||
if (!AIPaused) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkStateOnCharacterDead ()
|
||||
{
|
||||
if (systemActive) {
|
||||
if (isCurrentCharacterTurn) {
|
||||
if (mainPlayerController.checkIfPlayerDeadFromHealthComponent ()) {
|
||||
if (showDebugPrint) {
|
||||
print ("current character in turn has dead, moving turn to next character");
|
||||
}
|
||||
|
||||
setNextTurn ();
|
||||
|
||||
currentAttackInProcess = false;
|
||||
|
||||
isCurrentCharacterTurn = false;
|
||||
|
||||
delayToActiveteAttackInProcess = false;
|
||||
}
|
||||
} else {
|
||||
mainTurnBasedCombatActionsSystem.checkTeamsDeadStateAfterCharacterDeath ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetStates ()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void updateInsideMinDistance (bool newInsideMinDistanceToAttack)
|
||||
{
|
||||
insideMinDistanceToAttack = newInsideMinDistanceToAttack;
|
||||
|
||||
if (insideMinDistanceToAttack) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBehavior ()
|
||||
{
|
||||
if (!systemActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (AIPaused) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentPathDistanceToTarget = mainFindObjectivesSystem.currentPathDistanceToTarget;
|
||||
|
||||
checkAttackState ();
|
||||
}
|
||||
|
||||
public void checkAttackState ()
|
||||
{
|
||||
if (!attackEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkDistanceToTargetEnabled) {
|
||||
insideMinDistanceToAttack = mainFindObjectivesSystem.insideMinDistanceToAttack;
|
||||
|
||||
if (!insideMinDistanceToAttack) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentPauseAttackStateDuration > 0) {
|
||||
if (Time.time > currentPauseAttackStateDuration + lastTimeAttackPauseWithDuration) {
|
||||
|
||||
attackStatePaused = false;
|
||||
|
||||
currentPauseAttackStateDuration = 0;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (waitToActivateAttackActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!canUseAttackActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (mainFindObjectivesSystem.isOnSpotted ()) {
|
||||
// if (!onSpotted) {
|
||||
// lastTimeAttackActivated = Time.time;
|
||||
//
|
||||
// onSpotted = true;
|
||||
// }
|
||||
// } else {
|
||||
// if (onSpotted) {
|
||||
//
|
||||
// onSpotted = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (onSpotted) {
|
||||
|
||||
if (AIOnPlayerTeam) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isCurrentCharacterTurn) {
|
||||
if (currentAttackInProcess) {
|
||||
if (!delayToActiveteAttackInProcess) {
|
||||
if (!mainCharacterToReceiveOrders.isOrderInProcess ()) {
|
||||
setNextTurn ();
|
||||
|
||||
currentAttackInProcess = false;
|
||||
|
||||
isCurrentCharacterTurn = false;
|
||||
|
||||
delayToActiveteAttackInProcess = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Time.time > minWaitToActivateAttack + lastTimeAttackActivated) {
|
||||
if (!mainPlayerController.isActionActive () || blockActive) {
|
||||
bool canActivateAttackResult = true;
|
||||
|
||||
if (checkDistanceToTargetEnabled) {
|
||||
if (!mainPlayerController.canPlayerMove () || currentPathDistanceToTarget > currentMinDistanceToAttack ||
|
||||
!mainFindObjectivesSystem.checkIfMinimumAngleToAttack ()) {
|
||||
canActivateAttackResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAttackResult) {
|
||||
if (mainFindObjectivesSystem.isAIBehaviorAttackInProcess ()) {
|
||||
if (showDebugPrint) {
|
||||
print ("attack in process in current main behavior, cancelling action");
|
||||
}
|
||||
|
||||
canActivateAttackResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAttackResult) {
|
||||
if (mainFindObjectivesSystem.isAIPaused ()) {
|
||||
canActivateAttackResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAttackResult) {
|
||||
if (mainTurnBasedCombatActionsSystem.isAdjustingCharacterPositionInProcess ()) {
|
||||
canActivateAttackResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateAttackResult) {
|
||||
if (useProbabilityToUseAttack) {
|
||||
float currentProbability = Random.Range (0, 100);
|
||||
|
||||
if (currentProbability > probabilityToUseAttack) {
|
||||
lastTimeAttackActivated = Time.time;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("probability to activate attack failed, cancelling");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
attackTarget ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAIAttackState (bool newCanUseAttackActiveState)
|
||||
{
|
||||
canUseAttackActive = newCanUseAttackActiveState;
|
||||
}
|
||||
|
||||
public void setSystemEnabledState (bool state)
|
||||
{
|
||||
if (systemEnabled == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
systemEnabled = state;
|
||||
|
||||
setSystemActiveState (systemEnabled);
|
||||
}
|
||||
|
||||
public void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!systemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (systemActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
systemActive = state;
|
||||
|
||||
if (systemActive) {
|
||||
|
||||
|
||||
} else {
|
||||
isCurrentCharacterTurn = false;
|
||||
|
||||
currentAttackInProcess = false;
|
||||
|
||||
delayToActiveteAttackInProcess = false;
|
||||
|
||||
blockActive = false;
|
||||
}
|
||||
|
||||
// onSpotted = false;
|
||||
|
||||
checkEventsOnCombatStateChange (systemActive);
|
||||
}
|
||||
|
||||
void checkEventsOnCombatStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnCombatActive) {
|
||||
if (state) {
|
||||
eventOnCombatActive.Invoke ();
|
||||
} else {
|
||||
eventOnCombatDeactivate.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseAttackDuringXTime (float newDuration)
|
||||
{
|
||||
currentPauseAttackStateDuration = newDuration;
|
||||
|
||||
lastTimeAttackPauseWithDuration = Time.time;
|
||||
|
||||
attackStatePaused = true;
|
||||
}
|
||||
|
||||
public void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
waitToActivateAttackActive = state;
|
||||
}
|
||||
|
||||
public void resetBehaviorStates ()
|
||||
{
|
||||
resetStates ();
|
||||
|
||||
waitingForAttackActive = false;
|
||||
|
||||
|
||||
|
||||
insideMinDistanceToAttack = false;
|
||||
}
|
||||
|
||||
public void attackTarget ()
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("activate attack");
|
||||
}
|
||||
|
||||
|
||||
int randomAttackCategoryIndex = Random.Range (0, turnBasedCombatAttackCategoryInfoList.Count);
|
||||
|
||||
turnBasedCombatAttackCategoryInfo currentTurnBasedCombatAttackCategoryInfo = turnBasedCombatAttackCategoryInfoList [randomAttackCategoryIndex];
|
||||
|
||||
bool checkCategoryResult = false;
|
||||
|
||||
if (!ignoreIfLastCategoryPreviouslySelected) {
|
||||
if (lastCategoryIndex == randomAttackCategoryIndex) {
|
||||
checkCategoryResult = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("category selected on previous attack, selecting new one");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentTurnBasedCombatAttackCategoryInfo.attackCategoryEnabled) {
|
||||
checkCategoryResult = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("category not enabled, selecting new index " + currentTurnBasedCombatAttackCategoryInfo.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreProbabilityToCheckCategory) {
|
||||
if (currentTurnBasedCombatAttackCategoryInfo.useProbabilityToCheckCategory) {
|
||||
float currentProbability = Random.Range (0, 100);
|
||||
|
||||
if (currentProbability > currentTurnBasedCombatAttackCategoryInfo.probabilityToCheckCategory) {
|
||||
checkCategoryResult = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("category probability not reached, selecting new index " + currentProbability);
|
||||
}
|
||||
} else {
|
||||
if (showDebugPrint) {
|
||||
print ("category probability reached, selecting command in category " + currentTurnBasedCombatAttackCategoryInfo.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (checkCategoryResult) {
|
||||
bool nextIndexFound = false;
|
||||
|
||||
int loopCount = 0;
|
||||
|
||||
while (!nextIndexFound) {
|
||||
randomAttackCategoryIndex = Random.Range (0, turnBasedCombatAttackCategoryInfoList.Count);
|
||||
|
||||
currentTurnBasedCombatAttackCategoryInfo = turnBasedCombatAttackCategoryInfoList [randomAttackCategoryIndex];
|
||||
|
||||
if (currentTurnBasedCombatAttackCategoryInfo.attackCategoryEnabled) {
|
||||
if (ignoreProbabilityToCheckCategory) {
|
||||
nextIndexFound = true;
|
||||
} else {
|
||||
if (currentTurnBasedCombatAttackCategoryInfo.useProbabilityToCheckCategory) {
|
||||
float currentProbability = Random.Range (0, 100);
|
||||
|
||||
if (currentProbability < currentTurnBasedCombatAttackCategoryInfo.probabilityToCheckCategory) {
|
||||
nextIndexFound = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("category probability reached");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nextIndexFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loopCount++;
|
||||
|
||||
if (loopCount > 100) {
|
||||
nextIndexFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lastCategoryIndex != randomAttackCategoryIndex) {
|
||||
if (showDebugPrint) {
|
||||
print ("selecting new category, reseting las attack used index");
|
||||
}
|
||||
|
||||
if (lastAttackUsedIndex != -1) {
|
||||
lastAttackUsedIndex = -1;
|
||||
}
|
||||
|
||||
lastCategoryIndex = randomAttackCategoryIndex;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("category selected " + currentTurnBasedCombatAttackCategoryInfo.Name);
|
||||
}
|
||||
|
||||
int turnBasedCombatAttackInfoListCount = currentTurnBasedCombatAttackCategoryInfo.turnBasedCombatAttackInfoList.Count;
|
||||
|
||||
int randomAttackIndex = Random.Range (0, turnBasedCombatAttackInfoListCount);
|
||||
|
||||
currentTurnBasedCombatAttackInfo = currentTurnBasedCombatAttackCategoryInfo.turnBasedCombatAttackInfoList [randomAttackIndex];
|
||||
|
||||
bool checkAttackIndexResult = true;
|
||||
|
||||
if (!ignoreIfLastAttackPreviouslySelected) {
|
||||
if (randomAttackIndex == lastAttackUsedIndex) {
|
||||
checkAttackIndexResult = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("already used on last command " + currentTurnBasedCombatAttackInfo.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentTurnBasedCombatAttackInfo.attackEnabled) {
|
||||
checkAttackIndexResult = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("command not enabled " + currentTurnBasedCombatAttackInfo.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreProbabilityToUseAttack) {
|
||||
if (currentTurnBasedCombatAttackInfo.useProbabilityToUseAttack) {
|
||||
float currentProbability = Random.Range (0, 100);
|
||||
|
||||
if (currentProbability > currentTurnBasedCombatAttackInfo.probabilityToUseAttack) {
|
||||
checkAttackIndexResult = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("command probability not reached " + currentTurnBasedCombatAttackInfo.Name + " " + currentProbability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (checkAttackIndexResult) {
|
||||
bool nextIndexFound = false;
|
||||
|
||||
int loopCount = 0;
|
||||
|
||||
while (!nextIndexFound) {
|
||||
|
||||
randomAttackIndex = Random.Range (0, turnBasedCombatAttackInfoListCount);
|
||||
|
||||
if (randomAttackIndex != lastAttackUsedIndex) {
|
||||
currentTurnBasedCombatAttackInfo = currentTurnBasedCombatAttackCategoryInfo.turnBasedCombatAttackInfoList [randomAttackIndex];
|
||||
|
||||
if (currentTurnBasedCombatAttackInfo.attackEnabled) {
|
||||
if (ignoreProbabilityToUseAttack) {
|
||||
bool canActivateCommandResult = true;
|
||||
|
||||
if (!ignoreUseStatToUseAction) {
|
||||
if (currentTurnBasedCombatAttackInfo.useStatToUseAction) {
|
||||
if (mainPlayerStatsSystem.getStatValue (currentTurnBasedCombatAttackInfo.statNameToUseAction) <
|
||||
currentTurnBasedCombatAttackInfo.statAmountToUseAction) {
|
||||
canActivateCommandResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateCommandResult) {
|
||||
lastAttackUsedIndex = randomAttackIndex;
|
||||
|
||||
nextIndexFound = true;
|
||||
}
|
||||
} else {
|
||||
if (currentTurnBasedCombatAttackInfo.useProbabilityToUseAttack) {
|
||||
float currentProbability = Random.Range (0, 100);
|
||||
|
||||
if (currentProbability < currentTurnBasedCombatAttackCategoryInfo.probabilityToCheckCategory) {
|
||||
bool canActivateCommandResult = true;
|
||||
|
||||
if (!ignoreUseStatToUseAction) {
|
||||
if (currentTurnBasedCombatAttackInfo.useStatToUseAction) {
|
||||
if (mainPlayerStatsSystem.getStatValue (currentTurnBasedCombatAttackInfo.statNameToUseAction) <
|
||||
currentTurnBasedCombatAttackInfo.statAmountToUseAction) {
|
||||
canActivateCommandResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateCommandResult) {
|
||||
lastAttackUsedIndex = randomAttackIndex;
|
||||
|
||||
nextIndexFound = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("command probability reached " + currentProbability);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bool canActivateCommandResult = true;
|
||||
|
||||
if (!ignoreUseStatToUseAction) {
|
||||
if (currentTurnBasedCombatAttackInfo.useStatToUseAction) {
|
||||
if (mainPlayerStatsSystem.getStatValue (currentTurnBasedCombatAttackInfo.statNameToUseAction) <
|
||||
currentTurnBasedCombatAttackInfo.statAmountToUseAction) {
|
||||
canActivateCommandResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateCommandResult) {
|
||||
lastAttackUsedIndex = randomAttackIndex;
|
||||
|
||||
nextIndexFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loopCount++;
|
||||
|
||||
if (loopCount > 100) {
|
||||
lastAttackUsedIndex = randomAttackIndex;
|
||||
|
||||
nextIndexFound = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lastAttackUsedIndex = randomAttackIndex;
|
||||
}
|
||||
|
||||
currentTurnBasedCombatAttackInfo = currentTurnBasedCombatAttackCategoryInfo.turnBasedCombatAttackInfoList [lastAttackUsedIndex];
|
||||
|
||||
activateAttack ();
|
||||
}
|
||||
|
||||
void activateAttack ()
|
||||
{
|
||||
if (!ignoreUseStatToUseAction) {
|
||||
if (currentTurnBasedCombatAttackInfo.useStatToUseAction) {
|
||||
mainPlayerStatsSystem.usePlayerStat (currentTurnBasedCombatAttackInfo.statNameToUseAction,
|
||||
currentTurnBasedCombatAttackInfo.statAmountToUseAction);
|
||||
|
||||
mainTurnBasedCombatActionsSystem.updateAllCharacterStatsUIValue ();
|
||||
}
|
||||
}
|
||||
|
||||
currentCommandName = currentTurnBasedCombatAttackInfo.Name;
|
||||
|
||||
mainTurnBasedCombatActionsSystem.setCurrentCommandNameUsed (currentCommandName);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("current command selected " + currentCommandName);
|
||||
}
|
||||
|
||||
if (currentTurnBasedCombatAttackInfo.useMatchPositionSystem) {
|
||||
activateMatchPosition (currentTurnBasedCombatAttackInfo.matchPositionOffset);
|
||||
}
|
||||
|
||||
delayToActiveteAttackInProcess = false;
|
||||
|
||||
if (currentTurnBasedCombatAttackInfo.useDelayToActivateAttack) {
|
||||
stopDelaytToActivateAttackCoroutine ();
|
||||
|
||||
activateAttackCoroutine = StartCoroutine (delaytToActivateAttackCoroutine (currentTurnBasedCombatAttackInfo.delayToActivateAttack));
|
||||
} else {
|
||||
mainCharacterToReceiveOrders.activateOrder (currentCommandName);
|
||||
}
|
||||
|
||||
currentAttackInProcess = true;
|
||||
}
|
||||
|
||||
Coroutine activateAttackCoroutine;
|
||||
|
||||
IEnumerator delaytToActivateAttackCoroutine (float currentDelay)
|
||||
{
|
||||
delayToActiveteAttackInProcess = true;
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (currentDelay);
|
||||
|
||||
yield return delay;
|
||||
|
||||
mainCharacterToReceiveOrders.activateOrder (currentCommandName);
|
||||
|
||||
delayToActiveteAttackInProcess = false;
|
||||
}
|
||||
|
||||
void stopDelaytToActivateAttackCoroutine ()
|
||||
{
|
||||
if (activateAttackCoroutine != null) {
|
||||
StopCoroutine (activateAttackCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
public void activateAttackByName (string attackName)
|
||||
{
|
||||
int turnBasedCombatAttackCategoryInfoListCount = turnBasedCombatAttackCategoryInfoList.Count;
|
||||
|
||||
for (int i = 0; i < turnBasedCombatAttackCategoryInfoListCount; i++) {
|
||||
if (turnBasedCombatAttackCategoryInfoList [i].attackCategoryEnabled) {
|
||||
int turnBasedCombatAttackInfoListCount = turnBasedCombatAttackCategoryInfoList [i].turnBasedCombatAttackInfoList.Count;
|
||||
|
||||
for (int j = 0; j < turnBasedCombatAttackInfoListCount; j++) {
|
||||
if (turnBasedCombatAttackCategoryInfoList [i].turnBasedCombatAttackInfoList [j].attackEnabled) {
|
||||
if (turnBasedCombatAttackCategoryInfoList [i].turnBasedCombatAttackInfoList [j].Name.Equals (attackName)) {
|
||||
currentTurnBasedCombatAttackInfo = turnBasedCombatAttackCategoryInfoList [i].turnBasedCombatAttackInfoList [j];
|
||||
|
||||
lastAttackUsedIndex = j;
|
||||
lastCategoryIndex = i;
|
||||
|
||||
activateAttack ();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlockActiveState (bool state)
|
||||
{
|
||||
blockActive = state;
|
||||
}
|
||||
|
||||
public void resetAttackState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void disableOnSpottedState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void setNewMinDistanceToAttack (float newValue)
|
||||
{
|
||||
currentMinDistanceToAttack = newValue;
|
||||
}
|
||||
|
||||
public void setAIOnPlayerTeamState (bool state)
|
||||
{
|
||||
AIOnPlayerTeam = state;
|
||||
}
|
||||
|
||||
public void setIsCurrentCharacterTurn (bool state)
|
||||
{
|
||||
isCurrentCharacterTurn = state;
|
||||
|
||||
if (isCurrentCharacterTurn) {
|
||||
mainFindObjectivesSystem.setAIPausedState (false);
|
||||
|
||||
mainFindObjectivesSystem.setPossibleTargetForTurnBasedCombatSystem (currentTarget);
|
||||
|
||||
lastTimeAttackActivated = Time.time;
|
||||
} else {
|
||||
mainFindObjectivesSystem.setAIPausedState (true);
|
||||
|
||||
mainFindObjectivesSystem.setPossibleTargetForTurnBasedCombatSystem (null);
|
||||
}
|
||||
|
||||
if (isCurrentCharacterTurn) {
|
||||
if (useEventIfBlockActiveOnCurrentTurn) {
|
||||
blockActive = mainHealth.isBlockDamageActiveState ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("block was active, calling event to disable state to activate turn combat attack");
|
||||
}
|
||||
|
||||
if (blockActive) {
|
||||
eventIfBlockActiveOnCurrentTurn.Invoke ();
|
||||
|
||||
blockActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentCharacterTurnTarget (GameObject newTarget)
|
||||
{
|
||||
currentTarget = newTarget;
|
||||
}
|
||||
|
||||
public void setNextTurn ()
|
||||
{
|
||||
if (systemActive && isCurrentCharacterTurn) {
|
||||
mainTurnBasedCombatActionsSystem.setNextTurn ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentTurnBasedCombatAttackComplete ()
|
||||
{
|
||||
setNextTurn ();
|
||||
}
|
||||
|
||||
public void activateMatchPosition (float customMatchOffset)
|
||||
{
|
||||
float currentMatchOffset = defaultMatchOffset;
|
||||
|
||||
if (customMatchOffset > 0) {
|
||||
currentMatchOffset = customMatchOffset;
|
||||
}
|
||||
|
||||
mainMatchPlayerToTargetSystem.activateMatchPosition (currentMatchOffset);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class turnBasedCombatAttackCategoryInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public bool attackCategoryEnabled = true;
|
||||
|
||||
public bool useProbabilityToCheckCategory;
|
||||
[Range (0, 100)] public float probabilityToCheckCategory;
|
||||
|
||||
[Space]
|
||||
|
||||
public List<turnBasedCombatAttackInfo> turnBasedCombatAttackInfoList = new List<turnBasedCombatAttackInfo> ();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class turnBasedCombatAttackInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
[Space]
|
||||
public bool attackEnabled = true;
|
||||
|
||||
public float duration;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useProbabilityToUseAttack;
|
||||
[Range (0, 100)] public float probabilityToUseAttack;
|
||||
|
||||
[Space]
|
||||
|
||||
public float minDistanceToUseAttack;
|
||||
|
||||
public bool isAttackFromDistance;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useDelayToActivateAttack;
|
||||
public float delayToActivateAttack;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useMatchPositionSystem;
|
||||
public float matchPositionOffset = 1;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool useStatToUseAction;
|
||||
public string statNameToUseAction;
|
||||
public float statAmountToUseAction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 218d50b0abc0621409abcda448fe64ab
|
||||
timeCreated: 1697125492
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/AITurnBasedCombatSystemBrain.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class abilitiesAIBehavior : AIBehaviorInfo
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public AIAbilitiesSystemBrain mainAIAbilitiesSystemBrain;
|
||||
|
||||
public override void updateAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIAbilitiesSystemBrain.updateAI ();
|
||||
}
|
||||
|
||||
public override void updateAIBehaviorState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIAbilitiesSystemBrain.updateBehavior ();
|
||||
}
|
||||
|
||||
public override void updateAIAttackState (bool canUseAttack)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIAbilitiesSystemBrain.updateAIAttackState (canUseAttack);
|
||||
}
|
||||
|
||||
public override void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIAbilitiesSystemBrain.setSystemActiveState (state);
|
||||
}
|
||||
|
||||
public override void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
mainAIAbilitiesSystemBrain.setWaitToActivateAttackActiveState (state);
|
||||
}
|
||||
|
||||
public override void stopCurrentAttackInProcess ()
|
||||
{
|
||||
mainAIAbilitiesSystemBrain.stopCurrentAttackInProcess ();
|
||||
}
|
||||
|
||||
public override void setTurnBasedCombatActionActiveState (bool state)
|
||||
{
|
||||
mainAIAbilitiesSystemBrain.setTurnBasedCombatActionActiveState (state);
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterSpawn ()
|
||||
{
|
||||
mainAIAbilitiesSystemBrain.checkAIBehaviorStateOnCharacterSpawn ();
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterDespawn ()
|
||||
{
|
||||
mainAIAbilitiesSystemBrain.checkAIBehaviorStateOnCharacterDespawn ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0fec04c27195a649912f295c8b1f95e
|
||||
timeCreated: 1647925282
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/abilitiesAIBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,130 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class closeCombatAIBehavior : AIBehaviorInfo
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public AICloseCombatSystemBrain mainAICloseCombatSystemBrain;
|
||||
|
||||
public override void updateAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAICloseCombatSystemBrain.updateAI ();
|
||||
}
|
||||
|
||||
public override void updateAIBehaviorState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAICloseCombatSystemBrain.updateMainCloseCombatBehavior ();
|
||||
}
|
||||
|
||||
public override void updateAIAttackState (bool canUseAttack)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAICloseCombatSystemBrain.updateMainCloseCombatAttack (canUseAttack);
|
||||
}
|
||||
|
||||
public override void updateInsideRangeDistance (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAICloseCombatSystemBrain.updateInsideMinDistance (state);
|
||||
}
|
||||
|
||||
public override void resetBehaviorStates ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAICloseCombatSystemBrain.resetBehaviorStates ();
|
||||
}
|
||||
|
||||
public override void setBehaviorStatesPausedState (bool state)
|
||||
{
|
||||
mainAICloseCombatSystemBrain.setBehaviorStatesPausedState (state);
|
||||
}
|
||||
|
||||
public override void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAICloseCombatSystemBrain.setCloseCombatSystemActiveState (state);
|
||||
}
|
||||
|
||||
public override void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
mainAICloseCombatSystemBrain.setWaitToActivateAttackActiveState (state);
|
||||
}
|
||||
|
||||
public override void setUseRandomWalkEnabledState (bool state)
|
||||
{
|
||||
mainAICloseCombatSystemBrain.setUseRandomWalkEnabledState (state);
|
||||
}
|
||||
|
||||
public override void setOriginalUseRandomWalkEnabledState ()
|
||||
{
|
||||
mainAICloseCombatSystemBrain.setOriginalUseRandomWalkEnabledState ();
|
||||
}
|
||||
|
||||
public override bool isAIBehaviorAttackInProcess ()
|
||||
{
|
||||
return mainAICloseCombatSystemBrain.isAIBehaviorAttackInProcess ();
|
||||
}
|
||||
|
||||
public override void stopCurrentAttackInProcess ()
|
||||
{
|
||||
mainAICloseCombatSystemBrain.stopCurrentAttackInProcess ();
|
||||
}
|
||||
|
||||
public override void setTurnBasedCombatActionActiveState (bool state)
|
||||
{
|
||||
mainAICloseCombatSystemBrain.setTurnBasedCombatActionActiveState (state);
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterSpawn ()
|
||||
{
|
||||
mainAICloseCombatSystemBrain.checkAIBehaviorStateOnCharacterSpawn ();
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterDespawn ()
|
||||
{
|
||||
mainAICloseCombatSystemBrain.checkAIBehaviorStateOnCharacterDespawn ();
|
||||
}
|
||||
|
||||
public override void changeCurrentAttackMode (string newModeName)
|
||||
{
|
||||
mainAICloseCombatSystemBrain.changeCurrentAttackMode (newModeName);
|
||||
}
|
||||
|
||||
public override void stopAttackState ()
|
||||
{
|
||||
mainAICloseCombatSystemBrain.stopAttackState ();
|
||||
}
|
||||
|
||||
public override void setAttackEnabledState (bool state)
|
||||
{
|
||||
mainAICloseCombatSystemBrain.setAttackEnabledState (state);
|
||||
}
|
||||
|
||||
public override void setAttackEnabledStateFromEditor (bool state)
|
||||
{
|
||||
mainAICloseCombatSystemBrain.setAttackEnabledStateFromEditor (state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9554527b49ffe2f4aafeba3c158d0a90
|
||||
timeCreated: 1602696760
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/closeCombatAIBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,785 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class handleVehicleAIBehavior : AIBehaviorInfo
|
||||
{
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool characterOnVehicle;
|
||||
|
||||
[Space]
|
||||
[Header ("Custom Driver Settings")]
|
||||
[Space]
|
||||
|
||||
public bool searchVehicleEnabled = true;
|
||||
|
||||
public bool startGameSearchingForVehicle;
|
||||
|
||||
public bool setVehicleToStart;
|
||||
public GameObject vehicleToStart;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useMaxDistanceToGetVehicle;
|
||||
|
||||
public float maxDistanceToGetVehicle;
|
||||
|
||||
public float minDistanceToGetOnCurrentVehicle = 3.5f;
|
||||
|
||||
public bool ignoreCheckVehicleIfTargetToAttackFound;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool stopBehaviorUpdateOnGetOffFromVehicle = true;
|
||||
public bool stopBehaviorUpdateOnVehicleReached = true;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Driver Debug Info")]
|
||||
[Space]
|
||||
|
||||
public bool searchingVehicle;
|
||||
public bool vehicleToReachFound;
|
||||
|
||||
public bool currentVehicleAINavmeshLocated;
|
||||
|
||||
public bool getOffFromVehicleOnDestinyReached;
|
||||
|
||||
[Space]
|
||||
|
||||
public Transform currentVehicleToGet;
|
||||
public vehicleAINavMesh currentVehicleAINavMesh;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnNoVehicleToPickFromScene;
|
||||
public UnityEvent eventOnNoVehicleToPickFromScene;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
[Space]
|
||||
[Header ("Custom Passenger Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkAIPassengerStateEnabled = true;
|
||||
|
||||
public bool ignoreCheckPartnerOnVehicle;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Passenger Debug Info")]
|
||||
[Space]
|
||||
|
||||
public vehicleHUDManager currentVehicleHUDManager;
|
||||
public vehicleHUDManager currentVehicleToAttack;
|
||||
public GameObject currentVehicle;
|
||||
public playerController playerControllerPartner;
|
||||
|
||||
public bool AICharacterWasntAbleToEnterOnPartnerVehicle;
|
||||
public bool partnerFound;
|
||||
|
||||
public bool followingPartnerDrivingOnFoot;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform AITransform;
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public AINavMesh mainAINavmeshManager;
|
||||
public playerController mainPlayerController;
|
||||
public usingDevicesSystem usingDevicesManager;
|
||||
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
bool followingTargetPreviously;
|
||||
|
||||
bool isVehicleFull = false;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (searchVehicleEnabled) {
|
||||
if (startGameSearchingForVehicle) {
|
||||
StartCoroutine (startGameSearchingForVehicleCoroutine ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
//DRIVER FUNCTIONS
|
||||
//------------------------------------------------------------
|
||||
|
||||
IEnumerator startGameSearchingForVehicleCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (0.3f);
|
||||
|
||||
activateAIBehavior ();
|
||||
}
|
||||
|
||||
public override void activateAIBehavior ()
|
||||
{
|
||||
if (searchVehicleEnabled) {
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
public override void deactivateAIBehavior ()
|
||||
{
|
||||
if (searchVehicleEnabled) {
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForSecondsRealtime (0.0001f);
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void setGetOffFromVehicleOnDestinyReachedState (bool state)
|
||||
{
|
||||
getOffFromVehicleOnDestinyReached = state;
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (characterOnVehicle) {
|
||||
if (currentVehicleAINavmeshLocated) {
|
||||
if (currentVehicleAINavMesh.isFollowingTarget ()) {
|
||||
followingTargetPreviously = true;
|
||||
} else {
|
||||
if (followingTargetPreviously) {
|
||||
getOffFromVehicle ();
|
||||
|
||||
if (stopBehaviorUpdateOnGetOffFromVehicle) {
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
|
||||
setCharacterOnVehicleState (false);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (searchingVehicle) {
|
||||
bool vehicleReached = false;
|
||||
|
||||
if (currentVehicleToGet != null) {
|
||||
if (GKC_Utils.distance (mainAINavmeshManager.transform.position, currentVehicleToGet.position) < minDistanceToGetOnCurrentVehicle) {
|
||||
if (showDebugPrint) {
|
||||
print ("picking vehicle " + currentVehicleToGet.name);
|
||||
}
|
||||
|
||||
vehicleHUDManager currentVehicleHUDManager = currentVehicleToGet.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManager != null) {
|
||||
IKDrivingSystem currentIKDrivingSystem = currentVehicleHUDManager.getIKDrivingSystem ();
|
||||
|
||||
if (currentIKDrivingSystem != null) {
|
||||
currentIKDrivingSystem.setDriverExternally (AITransform.gameObject);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("sending character to vehicle");
|
||||
}
|
||||
|
||||
mainAINavmeshManager.removeTarget ();
|
||||
}
|
||||
} else {
|
||||
GKCSimpleRiderSystem currentGKCSimpleRiderSystem = currentVehicleToGet.GetComponent<GKCSimpleRiderSystem> ();
|
||||
|
||||
if (currentGKCSimpleRiderSystem != null) {
|
||||
currentGKCSimpleRiderSystem.setDriverExternally (AITransform.gameObject);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("sending character to vehicle");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vehicleReached = true;
|
||||
}
|
||||
} else {
|
||||
vehicleReached = true;
|
||||
}
|
||||
|
||||
if (vehicleReached) {
|
||||
mainFindObjectivesSystem.setSearchingObjectState (false);
|
||||
|
||||
searchingVehicle = false;
|
||||
|
||||
currentVehicleToGet = null;
|
||||
|
||||
mainFindObjectivesSystem.setIgnoreVisionRangeActiveState (true);
|
||||
|
||||
mainFindObjectivesSystem.resetAITargets ();
|
||||
|
||||
mainFindObjectivesSystem.setIgnoreVisionRangeActiveState (false);
|
||||
|
||||
mainFindObjectivesSystem.setOriginalWanderEnabled ();
|
||||
|
||||
setCharacterOnVehicleState (true);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("vehicle picked, resuming state on AI");
|
||||
}
|
||||
|
||||
if (stopBehaviorUpdateOnVehicleReached) {
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
checkToFindVehicle ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkToFindVehicle ()
|
||||
{
|
||||
if (characterOnVehicle) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ignoreCheckVehicleIfTargetToAttackFound) {
|
||||
if (mainFindObjectivesSystem.isOnSpotted ()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setCharacterOnVehicleState (false);
|
||||
|
||||
bool vehicleFound = false;
|
||||
|
||||
bool ignoreSearchVehicleResult = false;
|
||||
|
||||
if (setVehicleToStart) {
|
||||
if (vehicleToStart != null) {
|
||||
Transform vehicleToStartTransform = null;
|
||||
|
||||
vehicleHUDManager currentVehicleHUDManager = vehicleToStart.GetComponentInChildren<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManager != null) {
|
||||
vehicleToStartTransform = currentVehicleHUDManager.transform;
|
||||
|
||||
if (mainAINavmeshManager.updateCurrentNavMeshPath (vehicleToStartTransform.position)) {
|
||||
setVehicleToReachToDrive (vehicleToStartTransform);
|
||||
|
||||
ignoreSearchVehicleResult = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreSearchVehicleResult) {
|
||||
vehicleHUDManager [] vehicleHUDManagerList = FindObjectsOfType (typeof (vehicleHUDManager)) as vehicleHUDManager [];
|
||||
|
||||
List<Transform> vehiclesDetected = new List<Transform> ();
|
||||
|
||||
if (vehicleHUDManagerList.Length > 0) {
|
||||
for (int i = 0; i < vehicleHUDManagerList.Length; i++) {
|
||||
bool checkObjectResult = true;
|
||||
|
||||
if (vehicleHUDManagerList [i].getCurrentDriver () != null) {
|
||||
checkObjectResult = false;
|
||||
}
|
||||
|
||||
if (useMaxDistanceToGetVehicle) {
|
||||
float distance = GKC_Utils.distance (vehicleHUDManagerList [i].transform.position, AITransform.position);
|
||||
|
||||
if (distance > maxDistanceToGetVehicle) {
|
||||
checkObjectResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkObjectResult) {
|
||||
vehiclesDetected.Add (vehicleHUDManagerList [i].transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GKCSimpleRiderSystem [] GKCSimpleRiderSystemList = FindObjectsOfType (typeof (GKCSimpleRiderSystem)) as GKCSimpleRiderSystem [];
|
||||
|
||||
if (GKCSimpleRiderSystemList.Length > 0) {
|
||||
for (int i = 0; i < GKCSimpleRiderSystemList.Length; i++) {
|
||||
bool checkObjectResult = true;
|
||||
|
||||
if (GKCSimpleRiderSystemList [i].getCurrentDriver () != null) {
|
||||
checkObjectResult = false;
|
||||
}
|
||||
|
||||
if (useMaxDistanceToGetVehicle) {
|
||||
float distance = GKC_Utils.distance (GKCSimpleRiderSystemList [i].transform.position, AITransform.position);
|
||||
|
||||
if (distance > maxDistanceToGetVehicle) {
|
||||
checkObjectResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkObjectResult) {
|
||||
vehiclesDetected.Add (GKCSimpleRiderSystemList [i].transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vehiclesDetected.Count == 0) {
|
||||
if (showDebugPrint) {
|
||||
print ("no vehicles detected");
|
||||
}
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
|
||||
if (vehiclesDetected.Count > 0) {
|
||||
|
||||
vehiclesDetected.Sort (delegate (Transform a, Transform b) {
|
||||
return Vector3.Distance (AITransform.position, a.transform.position).CompareTo (Vector3.Distance (AITransform.position, b.transform.position));
|
||||
});
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("vehicles found on scene " + vehiclesDetected.Count);
|
||||
}
|
||||
|
||||
for (int i = 0; i < vehiclesDetected.Count; i++) {
|
||||
if (!vehicleFound) {
|
||||
|
||||
if (showDebugPrint) {
|
||||
vehicleHUDManager currentVehicleHUDManager = vehiclesDetected [i].GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManager != null) {
|
||||
print ("checking if vehicle with name " + currentVehicleHUDManager.getVehicleName () + " can be used");
|
||||
} else {
|
||||
GKCSimpleRiderSystem currentGKCSimpleRiderSystem = vehiclesDetected [i].GetComponent<GKCSimpleRiderSystem> ();
|
||||
|
||||
if (currentGKCSimpleRiderSystem != null) {
|
||||
print ("checking if vehicle with name " + currentGKCSimpleRiderSystem.getVehicleName () + " can be used");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mainAINavmeshManager.updateCurrentNavMeshPath (vehiclesDetected [i].transform.position)) {
|
||||
setVehicleToReachToDrive (vehiclesDetected [i]);
|
||||
|
||||
vehicleFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (showDebugPrint) {
|
||||
print ("no vehicles found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!vehicleFound) {
|
||||
if (showDebugPrint) {
|
||||
print ("vehicles found can't be reached, cancelling search");
|
||||
}
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
if (useEventOnNoVehicleToPickFromScene) {
|
||||
eventOnNoVehicleToPickFromScene.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setVehicleToReachToDrive (Transform vehicleTransform)
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("vehicle to reach found ");
|
||||
}
|
||||
|
||||
mainFindObjectivesSystem.setDrawOrHolsterWeaponState (false);
|
||||
|
||||
mainFindObjectivesSystem.setSearchingObjectState (true);
|
||||
|
||||
mainFindObjectivesSystem.setWanderEnabledState (false);
|
||||
|
||||
currentVehicleToGet = vehicleTransform;
|
||||
|
||||
vehicleHUDManager currentVehicleHUDManager = currentVehicleToGet.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManager != null) {
|
||||
currentVehicleAINavMesh = currentVehicleHUDManager.getAIVehicleNavmesh ();
|
||||
|
||||
currentVehicleAINavmeshLocated = currentVehicleAINavMesh != null;
|
||||
}
|
||||
|
||||
mainAINavmeshManager.setTarget (vehicleTransform);
|
||||
|
||||
mainAINavmeshManager.setTargetType (false, true);
|
||||
|
||||
followingTargetPreviously = false;
|
||||
|
||||
mainAINavmeshManager.lookAtTaget (false);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("vehicle to use located, setting searching vehicle state on AI");
|
||||
}
|
||||
|
||||
searchingVehicle = true;
|
||||
}
|
||||
|
||||
public override void updateAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void updateAIBehaviorState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void updateAIAttackState (bool canUseAttack)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
//PASSENGER FUNCTIONS
|
||||
//------------------------------------------------------------
|
||||
|
||||
public override void updateAIPassengerBehavior ()
|
||||
{
|
||||
if (!checkAIPassengerStateEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!partnerFound) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerControllerPartner == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mainAINavmeshManager.isCharacterWaiting ()) {
|
||||
if (ignoreCheckPartnerOnVehicle) {
|
||||
if (playerControllerPartner.isPlayerDriving ()) {
|
||||
if (!followingPartnerDrivingOnFoot) {
|
||||
currentVehicle = playerControllerPartner.getCurrentVehicle ();
|
||||
|
||||
vehicleHUDManager currentVehicleHUDManagerToGetOn = currentVehicle.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManagerToGetOn != null) {
|
||||
mainFindObjectivesSystem.setExtraMinDistanceState (true, currentVehicleHUDManagerToGetOn.getVehicleRadius ());
|
||||
|
||||
mainAINavmeshManager.setExtraMinDistanceState (true, currentVehicleHUDManagerToGetOn.getVehicleRadius ());
|
||||
} else {
|
||||
GKCSimpleRiderSystem currentGKCSimpleRiderSystemToGetOn = currentVehicle.GetComponent<GKCSimpleRiderSystem> ();
|
||||
|
||||
if (currentGKCSimpleRiderSystemToGetOn != null) {
|
||||
|
||||
mainFindObjectivesSystem.setExtraMinDistanceState (true, currentGKCSimpleRiderSystemToGetOn.getVehicleRadius ());
|
||||
|
||||
mainAINavmeshManager.setExtraMinDistanceState (true, currentGKCSimpleRiderSystemToGetOn.getVehicleRadius ());
|
||||
}
|
||||
}
|
||||
|
||||
followingPartnerDrivingOnFoot = true;
|
||||
} else {
|
||||
if (mainAINavmeshManager.isCharacterAttacking ()) {
|
||||
removeStateOnVehicle ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (followingPartnerDrivingOnFoot) {
|
||||
removeStateOnVehicle ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (playerControllerPartner.isPlayerDriving ()) {
|
||||
if (!characterOnVehicle && !mainAINavmeshManager.isCharacterAttacking ()) {
|
||||
|
||||
if (currentVehicle == null) {
|
||||
|
||||
isVehicleFull = false;
|
||||
|
||||
currentVehicle = playerControllerPartner.getCurrentVehicle ();
|
||||
|
||||
vehicleHUDManager currentVehicleHUDManagerToGetOn = currentVehicle.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManagerToGetOn != null) {
|
||||
|
||||
mainFindObjectivesSystem.setExtraMinDistanceState (true, currentVehicleHUDManagerToGetOn.getVehicleRadius ());
|
||||
|
||||
mainAINavmeshManager.setExtraMinDistanceState (true, currentVehicleHUDManagerToGetOn.getVehicleRadius ());
|
||||
|
||||
mainFindObjectivesSystem.addNotEnemy (playerControllerPartner.gameObject);
|
||||
|
||||
isVehicleFull = currentVehicleHUDManagerToGetOn.isVehicleFull ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("partner is driving a GKC vehicle and the vehicle full result is " + isVehicleFull);
|
||||
}
|
||||
} else {
|
||||
GKCSimpleRiderSystem currentGKCSimpleRiderSystemToGetOn = currentVehicle.GetComponent<GKCSimpleRiderSystem> ();
|
||||
|
||||
print (currentGKCSimpleRiderSystemToGetOn != null);
|
||||
|
||||
if (currentGKCSimpleRiderSystemToGetOn != null) {
|
||||
|
||||
mainFindObjectivesSystem.setExtraMinDistanceState (true, currentGKCSimpleRiderSystemToGetOn.getVehicleRadius ());
|
||||
|
||||
mainAINavmeshManager.setExtraMinDistanceState (true, currentGKCSimpleRiderSystemToGetOn.getVehicleRadius ());
|
||||
|
||||
mainFindObjectivesSystem.addNotEnemy (playerControllerPartner.gameObject);
|
||||
|
||||
isVehicleFull = currentGKCSimpleRiderSystemToGetOn.isVehicleFull () ||
|
||||
currentGKCSimpleRiderSystemToGetOn.isVehicleOnlyForOnePlayerActive ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("partner is driving a GKC rider and the vehicle full result is " + isVehicleFull);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mainAINavmeshManager.isFollowingTarget ()) {
|
||||
if (!AICharacterWasntAbleToEnterOnPartnerVehicle) {
|
||||
if (mainPlayerController.canCharacterGetOnVehicles ()) {
|
||||
if (isVehicleFull) {
|
||||
AICharacterWasntAbleToEnterOnPartnerVehicle = true;
|
||||
} else {
|
||||
enterOnVehicle (currentVehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mainAINavmeshManager.isCharacterAttacking ()) {
|
||||
getOffFromVehicle ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (characterOnVehicle) {
|
||||
getOffFromVehicle ();
|
||||
} else if (AICharacterWasntAbleToEnterOnPartnerVehicle) {
|
||||
removeStateOnVehicle ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setIgnoreCheckPartnerOnVehicleState (bool state)
|
||||
{
|
||||
ignoreCheckPartnerOnVehicle = state;
|
||||
}
|
||||
|
||||
public void setCheckAIPassengerStateEnabledState (bool state)
|
||||
{
|
||||
checkAIPassengerStateEnabled = state;
|
||||
}
|
||||
|
||||
public void enterOnVehicle (GameObject newVehicleObject)
|
||||
{
|
||||
if (AICharacterWasntAbleToEnterOnPartnerVehicle) {
|
||||
if (showDebugPrint) {
|
||||
print ("AI wasn't able to enter on vehicle, cancelling");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("characterOnVehicle " + true);
|
||||
}
|
||||
|
||||
mainAINavmeshManager.pauseAI (true);
|
||||
|
||||
usingDevicesManager.addDeviceToList (newVehicleObject);
|
||||
|
||||
usingDevicesManager.getclosestDevice (false, false);
|
||||
|
||||
usingDevicesManager.setCurrentVehicle (newVehicleObject);
|
||||
|
||||
usingDevicesManager.useCurrentDevice (newVehicleObject);
|
||||
|
||||
if (mainPlayerController.isPlayerDriving ()) {
|
||||
setCharacterOnVehicleState (true);
|
||||
|
||||
AICharacterWasntAbleToEnterOnPartnerVehicle = false;
|
||||
} else {
|
||||
setCharacterOnVehicleState (false);
|
||||
|
||||
AICharacterWasntAbleToEnterOnPartnerVehicle = true;
|
||||
|
||||
mainAINavmeshManager.pauseAI (false);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (gameObject.name + " " + mainPlayerController.isPlayerDriving () + " " + characterOnVehicle);
|
||||
}
|
||||
}
|
||||
|
||||
public override void getOffFromVehicle ()
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("getOffFromVehicle " + gameObject.name);
|
||||
}
|
||||
|
||||
if (characterOnVehicle) {
|
||||
if (mainPlayerController.canCharacterGetOnVehicles ()) {
|
||||
if (currentVehicle != null) {
|
||||
usingDevicesManager.clearDeviceList ();
|
||||
|
||||
usingDevicesManager.addDeviceToList (currentVehicle);
|
||||
|
||||
usingDevicesManager.getclosestDevice (false, false);
|
||||
|
||||
usingDevicesManager.setCurrentVehicle (currentVehicle);
|
||||
|
||||
usingDevicesManager.useCurrentDevice (currentVehicle);
|
||||
} else {
|
||||
usingDevicesManager.useDevice ();
|
||||
}
|
||||
|
||||
mainAINavmeshManager.pauseAI (false);
|
||||
}
|
||||
|
||||
removeStateOnVehicle ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("remove AI from vehicle " + gameObject.name);
|
||||
}
|
||||
} else {
|
||||
if (AICharacterWasntAbleToEnterOnPartnerVehicle) {
|
||||
removeStateOnVehicle ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("remove state on vehicle " + gameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setCharacterOnVehicleState (bool state)
|
||||
{
|
||||
characterOnVehicle = state;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (gameObject.name + " " + mainPlayerController.isPlayerDriving () + " " + characterOnVehicle);
|
||||
}
|
||||
}
|
||||
|
||||
public override void removeStateOnVehicle ()
|
||||
{
|
||||
currentVehicle = null;
|
||||
|
||||
setCharacterOnVehicleState (false);
|
||||
|
||||
followingPartnerDrivingOnFoot = false;
|
||||
|
||||
mainFindObjectivesSystem.setExtraMinDistanceState (false, 0);
|
||||
|
||||
mainAINavmeshManager.setExtraMinDistanceState (false, 0);
|
||||
|
||||
AICharacterWasntAbleToEnterOnPartnerVehicle = false;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("removeStateOnVehicle " + gameObject.name);
|
||||
}
|
||||
}
|
||||
|
||||
public override void setAICharacterOnVehicle (GameObject newVehicle)
|
||||
{
|
||||
if (characterOnVehicle) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentVehicle = newVehicle;
|
||||
|
||||
bool isVehicleFull = false;
|
||||
|
||||
float vehicleRadius = 0;
|
||||
|
||||
vehicleHUDManager currentVehicleHUDManagerToGetOn = currentVehicle.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManagerToGetOn != null) {
|
||||
isVehicleFull = currentVehicleHUDManagerToGetOn.isVehicleFull ();
|
||||
|
||||
vehicleRadius = currentVehicleHUDManagerToGetOn.getVehicleRadius ();
|
||||
} else {
|
||||
GKCSimpleRiderSystem currentGKCSimpleRiderSystem = currentVehicle.GetComponent<GKCSimpleRiderSystem> ();
|
||||
|
||||
if (currentGKCSimpleRiderSystem != null) {
|
||||
isVehicleFull = currentGKCSimpleRiderSystem.isVehicleFull () ||
|
||||
currentGKCSimpleRiderSystem.isVehicleOnlyForOnePlayerActive ();
|
||||
|
||||
vehicleRadius = currentGKCSimpleRiderSystem.getVehicleRadius ();
|
||||
}
|
||||
}
|
||||
|
||||
mainFindObjectivesSystem.setExtraMinDistanceState (true, vehicleRadius);
|
||||
|
||||
mainAINavmeshManager.setExtraMinDistanceState (true, vehicleRadius);
|
||||
|
||||
if (!isVehicleFull) {
|
||||
if (mainPlayerController.canCharacterGetOnVehicles ()) {
|
||||
enterOnVehicle (currentVehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isCharacterOnVehicle ()
|
||||
{
|
||||
return characterOnVehicle;
|
||||
}
|
||||
|
||||
public override void setCurrentPlayerControllerPartner (playerController newPlayerController)
|
||||
{
|
||||
playerControllerPartner = newPlayerController;
|
||||
|
||||
partnerFound = playerControllerPartner != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8ae889d28a01d04b9bd99f4bf7ecabe
|
||||
timeCreated: 1685693567
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/handleVehicleAIBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,163 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class meleeAIBehavior : AIBehaviorInfo
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public AIMeleeCombatSystemBrain mainAIMeleeCombatSystemBrain;
|
||||
|
||||
public override void updateAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIMeleeCombatSystemBrain.updateAI ();
|
||||
}
|
||||
|
||||
public override void updateAIBehaviorState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIMeleeCombatSystemBrain.updateMainMeleeBehavior ();
|
||||
}
|
||||
|
||||
public override void updateAIAttackState (bool canUseAttack)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIMeleeCombatSystemBrain.updateMainMeleeAttack (canUseAttack);
|
||||
}
|
||||
|
||||
public override void updateInsideRangeDistance (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIMeleeCombatSystemBrain.updateInsideMinDistance (state);
|
||||
}
|
||||
|
||||
public override void resetBehaviorStates ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIMeleeCombatSystemBrain.resetBehaviorStates ();
|
||||
}
|
||||
|
||||
public override void dropWeapon ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIMeleeCombatSystemBrain.dropWeapon ();
|
||||
}
|
||||
|
||||
public override void setBehaviorStatesPausedState (bool state)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setBehaviorStatesPausedState (state);
|
||||
}
|
||||
|
||||
public override void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIMeleeCombatSystemBrain.setCombatSystemActiveState (state);
|
||||
}
|
||||
|
||||
public override bool carryingWeapon ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mainAIMeleeCombatSystemBrain.isWeaponEquiped ();
|
||||
}
|
||||
|
||||
public override void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setWaitToActivateAttackActiveState (state);
|
||||
}
|
||||
|
||||
public override void setUseRandomWalkEnabledState (bool state)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setUseRandomWalkEnabledState (state);
|
||||
}
|
||||
|
||||
public override void setOriginalUseRandomWalkEnabledState ()
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setOriginalUseRandomWalkEnabledState ();
|
||||
}
|
||||
|
||||
public override bool isAIBehaviorAttackInProcess ()
|
||||
{
|
||||
return mainAIMeleeCombatSystemBrain.isAIBehaviorAttackInProcess ();
|
||||
}
|
||||
|
||||
public override void checkNoWeaponsAvailableState ()
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.checkNoMeleeWeaponsAvailableState ();
|
||||
}
|
||||
|
||||
public override void setDrawOrHolsterWeaponState (bool state)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setDrawOrHolsterWeaponState (state);
|
||||
}
|
||||
|
||||
public override void stopCurrentAttackInProcess ()
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.stopCurrentAttackInProcess ();
|
||||
}
|
||||
|
||||
public override void setTurnBasedCombatActionActiveState (bool state)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setTurnBasedCombatActionActiveState (state);
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterSpawn ()
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.checkAIBehaviorStateOnCharacterSpawn ();
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterDespawn ()
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.checkAIBehaviorStateOnCharacterDespawn ();
|
||||
}
|
||||
|
||||
public override void checkIfDisableCurrentWeaponToChangeAttackMode (string newModeName)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.checkIfDisableCurrentWeaponToChangeAttackMode (newModeName);
|
||||
}
|
||||
|
||||
public override void changeCurrentAttackMode (string newModeName)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.changeCurrentAttackMode (newModeName);
|
||||
}
|
||||
|
||||
public override void stopAttackState ()
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.stopAttackState ();
|
||||
}
|
||||
|
||||
public override void setAttackEnabledState (bool state)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setAttackEnabledState (state);
|
||||
}
|
||||
|
||||
public override void setAttackEnabledStateFromEditor (bool state)
|
||||
{
|
||||
mainAIMeleeCombatSystemBrain.setAttackEnabledStateFromEditor (state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81cf24bd116a6d449a07c6403799938e
|
||||
timeCreated: 1602681548
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/meleeAIBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,147 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class powersAIBehavior : AIBehaviorInfo
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public AIPowersSystemBrain mainAIPowersSystemBrain;
|
||||
|
||||
public override void updateAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.updateAI ();
|
||||
}
|
||||
|
||||
public override void updateAIBehaviorState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.updateBehavior ();
|
||||
}
|
||||
|
||||
public override void updateAIAttackState (bool canUseAttack)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.updateAIAttackState (canUseAttack);
|
||||
}
|
||||
|
||||
public override void updateInsideRangeDistance (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.updateInsideMinDistance (state);
|
||||
}
|
||||
|
||||
public override void resetBehaviorStates ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.resetBehaviorStates ();
|
||||
}
|
||||
|
||||
public override void resetAttackState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.resetAttackState ();
|
||||
}
|
||||
|
||||
public override void stopAim ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.stopAim ();
|
||||
}
|
||||
|
||||
public override void disableOnSpottedState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.disableOnSpottedState ();
|
||||
}
|
||||
|
||||
public override void setBehaviorStatesPausedState (bool state)
|
||||
{
|
||||
mainAIPowersSystemBrain.setBehaviorStatesPausedState (state);
|
||||
}
|
||||
|
||||
public override void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIPowersSystemBrain.setSystemActiveState (state);
|
||||
}
|
||||
|
||||
public override void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
mainAIPowersSystemBrain.setWaitToActivateAttackActiveState (state);
|
||||
}
|
||||
|
||||
public override void stopCurrentAttackInProcess ()
|
||||
{
|
||||
mainAIPowersSystemBrain.stopCurrentAttackInProcess ();
|
||||
}
|
||||
|
||||
public override void setTurnBasedCombatActionActiveState (bool state)
|
||||
{
|
||||
mainAIPowersSystemBrain.setTurnBasedCombatActionActiveState (state);
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterSpawn ()
|
||||
{
|
||||
mainAIPowersSystemBrain.checkAIBehaviorStateOnCharacterSpawn ();
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterDespawn ()
|
||||
{
|
||||
mainAIPowersSystemBrain.checkAIBehaviorStateOnCharacterDespawn ();
|
||||
}
|
||||
|
||||
public override void checkIfDisableCurrentWeaponToChangeAttackMode (string newModeName)
|
||||
{
|
||||
mainAIPowersSystemBrain.checkIfDisableCurrentWeaponToChangeAttackMode (newModeName);
|
||||
}
|
||||
|
||||
public override void changeCurrentAttackMode (string newModeName)
|
||||
{
|
||||
mainAIPowersSystemBrain.changeCurrentAttackMode (newModeName);
|
||||
}
|
||||
|
||||
public override void stopAttackState ()
|
||||
{
|
||||
mainAIPowersSystemBrain.stopAttackState ();
|
||||
}
|
||||
|
||||
public override void setAttackEnabledState (bool state)
|
||||
{
|
||||
mainAIPowersSystemBrain.setAttackEnabledState (state);
|
||||
}
|
||||
|
||||
public override void setAttackEnabledStateFromEditor (bool state)
|
||||
{
|
||||
mainAIPowersSystemBrain.setAttackEnabledStateFromEditor (state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47fcc7f83ae851a418a51ce7cafa2017
|
||||
timeCreated: 1602696153
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/powersAIBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,167 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class shootBowSimpleAIAction : simpleAIAction
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public float shootWeaponDuration = 2;
|
||||
|
||||
public bool useAmountOfProjectilesToShoot;
|
||||
|
||||
public int amountOfProjectilesToShoot;
|
||||
|
||||
public bool useFireRate;
|
||||
public float fireRate;
|
||||
|
||||
// public string quickModeActionName = "Fire Arrow Bow Attack";
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool aimingWeapon;
|
||||
public bool shootingWeapon;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
// public quickPlayerModeChangeSystem mainQuickPlayerModeChangeSystem;
|
||||
public bowSystem mainBowSystem;
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
float lastTimeAiming;
|
||||
float lastTimeShoot;
|
||||
|
||||
|
||||
public override void startAIAction ()
|
||||
{
|
||||
base.startAIAction ();
|
||||
|
||||
if (actionActive) {
|
||||
if (actionUsedByPlayer) {
|
||||
|
||||
} else {
|
||||
mainFindObjectivesSystem.setPossibleTargetForTurnBasedCombatSystemAsCustomTargetToLook ();
|
||||
|
||||
mainFindObjectivesSystem.setIgnoreLookAtDirectionActiveState (true);
|
||||
}
|
||||
|
||||
mainPlayerCamera.pauseOrPlayCamera (true);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (true);
|
||||
|
||||
|
||||
if (useAmountOfProjectilesToShoot) {
|
||||
mainBowSystem.resetLastAmountOfFiredProjectiles ();
|
||||
}
|
||||
|
||||
mainBowSystem.setArrowsManagedByInventoryState (false);
|
||||
|
||||
mainBowSystem.inputSetAimBowState (true);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("aim bow");
|
||||
}
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.lookAtTemporalObjectToLookAtTarget ();
|
||||
}
|
||||
|
||||
lastTimeAiming = Time.time;
|
||||
|
||||
aimingWeapon = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateSystem ()
|
||||
{
|
||||
if (!actionActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aimingWeapon) {
|
||||
if (shootingWeapon) {
|
||||
if (useAmountOfProjectilesToShoot) {
|
||||
if (mainBowSystem.getLastAmountOfFiredProjectiles () >= amountOfProjectilesToShoot) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (Time.time > lastTimeAiming + shootWeaponDuration) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useFireRate) {
|
||||
if (Time.time > lastTimeShoot + fireRate) {
|
||||
setShootWeaponState (true);
|
||||
|
||||
lastTimeShoot = Time.time;
|
||||
}
|
||||
} else {
|
||||
setShootWeaponState (true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!actionUsedByPlayer) {
|
||||
mainFindObjectivesSystem.lookAtCurrentPlaceToShoot ();
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (true);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setShootWeaponState (bool state)
|
||||
{
|
||||
// mainQuickPlayerModeChangeSystem.inputActivateMode (quickModeActionName);
|
||||
|
||||
mainBowSystem.inputFireArrow ();
|
||||
|
||||
shootingWeapon = state;
|
||||
}
|
||||
|
||||
public override void resetStatesOnActionEnd ()
|
||||
{
|
||||
if (shootingWeapon) {
|
||||
shootingWeapon = false;
|
||||
|
||||
// mainQuickPlayerModeChangeSystem.inputActiveModePressUp (quickModeActionName);
|
||||
|
||||
mainBowSystem.inputSetAimBowState (false);
|
||||
|
||||
if (mainBowSystem.isAimingBowActive ()) {
|
||||
mainBowSystem.cancelBowLoadedStateIfActive ();
|
||||
}
|
||||
}
|
||||
|
||||
mainBowSystem.setOriginalArrowsManagedByInventoryState ();
|
||||
|
||||
shootingWeapon = false;
|
||||
|
||||
aimingWeapon = false;
|
||||
|
||||
mainPlayerCamera.pauseOrPlayCamera (false);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (false);
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.setLookAtTargetStateInput (false);
|
||||
} else {
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (false);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
|
||||
mainFindObjectivesSystem.setIgnoreLookAtDirectionActiveState (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b98ed6677a8ccbf4fbc510d0e33f6443
|
||||
timeCreated: 1697852319
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/shootBowSimpleAIAction.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,177 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class shootFireWeaponSimpleAIAction : simpleAIAction
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public float shootWeaponDuration = 2;
|
||||
|
||||
public bool useAmountOfProjectilesToShoot;
|
||||
|
||||
public int amountOfProjectilesToShoot;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool aimingWeapon;
|
||||
public bool shootingWeapon;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerWeaponsManager mainPlayerWeaponsManager;
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
float lastTimeShooting;
|
||||
|
||||
|
||||
public override void startAIAction ()
|
||||
{
|
||||
base.startAIAction ();
|
||||
|
||||
if (actionActive) {
|
||||
if (actionUsedByPlayer) {
|
||||
|
||||
} else {
|
||||
mainFindObjectivesSystem.setPossibleTargetForTurnBasedCombatSystemAsCustomTargetToLook ();
|
||||
}
|
||||
|
||||
mainPlayerCamera.pauseOrPlayCamera (true);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (true);
|
||||
|
||||
|
||||
if (useAmountOfProjectilesToShoot) {
|
||||
mainPlayerWeaponsManager.resetLastAmountOfFiredProjectiles ();
|
||||
}
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerWeaponsManager.inputAimWeapon ();
|
||||
} else {
|
||||
mainPlayerWeaponsManager.aimCurrentWeaponWhenItIsReady (true);
|
||||
}
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.lookAtTemporalObjectToLookAtTarget ();
|
||||
}
|
||||
|
||||
aimingWeapon = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateSystem ()
|
||||
{
|
||||
if (!actionActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aimingWeapon) {
|
||||
if (shootingWeapon) {
|
||||
if (useAmountOfProjectilesToShoot) {
|
||||
if (mainPlayerWeaponsManager.getLastAmountOfFiredProjectiles () >= amountOfProjectilesToShoot) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (Time.time > lastTimeShooting + shootWeaponDuration) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!mainPlayerWeaponsManager.currentWeaponIsMoving () &&
|
||||
mainPlayerWeaponsManager.reloadingActionNotActive () &&
|
||||
mainPlayerWeaponsManager.isPlayerCarringWeapon () &&
|
||||
|
||||
!mainPlayerWeaponsManager.isActionActiveInPlayer () &&
|
||||
mainPlayerWeaponsManager.canPlayerMove ()) {
|
||||
|
||||
setShootWeaponState (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!actionUsedByPlayer) {
|
||||
mainFindObjectivesSystem.lookAtCurrentPlaceToShoot ();
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (true);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setShootWeaponState (bool state)
|
||||
{
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerWeaponsManager.inputHoldOrReleaseShootWeapon (true);
|
||||
} else {
|
||||
mainPlayerWeaponsManager.shootWeapon (state);
|
||||
}
|
||||
|
||||
shootingWeapon = state;
|
||||
|
||||
if (shootingWeapon) {
|
||||
lastTimeShooting = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
public override void resetStatesOnActionEnd ()
|
||||
{
|
||||
if (shootingWeapon) {
|
||||
shootingWeapon = false;
|
||||
|
||||
mainPlayerWeaponsManager.inputHoldOrReleaseShootWeapon (false);
|
||||
|
||||
if (mainPlayerWeaponsManager.isCharacterShooting ()) {
|
||||
mainPlayerWeaponsManager.resetWeaponFiringAndAimingIfPlayerDisabled ();
|
||||
|
||||
mainPlayerWeaponsManager.setHoldShootWeaponState (false);
|
||||
}
|
||||
}
|
||||
|
||||
if (aimingWeapon) {
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerWeaponsManager.inputAimWeapon ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (mainPlayerWeaponsManager.isAimingWeapons ());
|
||||
}
|
||||
|
||||
if (mainPlayerWeaponsManager.isAimingWeapons ()) {
|
||||
mainPlayerWeaponsManager.setAimWeaponState (false);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (mainPlayerWeaponsManager.isAimingWeapons ());
|
||||
}
|
||||
} else {
|
||||
mainPlayerWeaponsManager.aimCurrentWeaponWhenItIsReady (false);
|
||||
mainPlayerWeaponsManager.stopAimCurrentWeaponWhenItIsReady (true);
|
||||
}
|
||||
}
|
||||
|
||||
shootingWeapon = false;
|
||||
|
||||
aimingWeapon = false;
|
||||
|
||||
mainPlayerCamera.pauseOrPlayCamera (false);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (false);
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.setLookAtTargetStateInput (false);
|
||||
} else {
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (false);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 239553e2cc120f94f990ab1a8b4f2e39
|
||||
timeCreated: 1697774223
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/shootFireWeaponSimpleAIAction.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,145 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class shootPowerSimpleAIAction : simpleAIAction
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public float shootPowerDuration = 2;
|
||||
|
||||
public bool useAmountOfProjectilesToShoot;
|
||||
|
||||
public int amountOfProjectilesToShoot;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool aimingPower;
|
||||
public bool shootingPower;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public otherPowers mainOtherPowers;
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
float lastTimeAiming;
|
||||
|
||||
|
||||
public override void startAIAction ()
|
||||
{
|
||||
base.startAIAction ();
|
||||
|
||||
if (actionActive) {
|
||||
if (actionUsedByPlayer) {
|
||||
|
||||
} else {
|
||||
mainFindObjectivesSystem.setPossibleTargetForTurnBasedCombatSystemAsCustomTargetToLook ();
|
||||
}
|
||||
|
||||
mainPlayerCamera.pauseOrPlayCamera (true);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (true);
|
||||
|
||||
|
||||
if (useAmountOfProjectilesToShoot) {
|
||||
mainOtherPowers.resetLastAmountOfFiredProjectiles ();
|
||||
}
|
||||
|
||||
if (!mainOtherPowers.isAimingPower ()) {
|
||||
mainOtherPowers.inputSetAimPowerState (true);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("aim power");
|
||||
}
|
||||
}
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.lookAtTemporalObjectToLookAtTarget ();
|
||||
}
|
||||
|
||||
lastTimeAiming = Time.time;
|
||||
|
||||
aimingPower = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void updateSystem ()
|
||||
{
|
||||
if (!actionActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aimingPower) {
|
||||
if (shootingPower) {
|
||||
if (useAmountOfProjectilesToShoot) {
|
||||
if (mainOtherPowers.getLastAmountOfFiredProjectiles () >= amountOfProjectilesToShoot) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (Time.time > lastTimeAiming + shootPowerDuration) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setShootWeaponState (true);
|
||||
}
|
||||
|
||||
if (!actionUsedByPlayer) {
|
||||
mainFindObjectivesSystem.lookAtCurrentPlaceToShoot ();
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (true);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setShootWeaponState (bool state)
|
||||
{
|
||||
mainOtherPowers.inputHoldOrReleaseShootPower (true);
|
||||
mainOtherPowers.inputHoldShootPower ();
|
||||
mainOtherPowers.inputHoldOrReleaseShootPower (false);
|
||||
|
||||
shootingPower = state;
|
||||
}
|
||||
|
||||
public override void resetStatesOnActionEnd ()
|
||||
{
|
||||
if (shootingPower) {
|
||||
shootingPower = false;
|
||||
|
||||
mainOtherPowers.inputHoldOrReleaseShootPower (false);
|
||||
}
|
||||
|
||||
if (aimingPower) {
|
||||
mainOtherPowers.inputSetAimPowerState (false);
|
||||
}
|
||||
|
||||
shootingPower = false;
|
||||
|
||||
aimingPower = false;
|
||||
|
||||
mainPlayerCamera.pauseOrPlayCamera (false);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (false);
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.setLookAtTargetStateInput (false);
|
||||
} else {
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (false);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8cb91008317460c42837ec7cc2329854
|
||||
timeCreated: 1697852180
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/shootPowerSimpleAIAction.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,130 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class simpleAIAction : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool actionEnabled = true;
|
||||
|
||||
public bool actionUsedByPlayer;
|
||||
|
||||
public float actionDuration;
|
||||
|
||||
public bool useUpdateSystemCoroutine;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool actionActive;
|
||||
|
||||
public Transform currentTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnStartAction;
|
||||
public UnityEvent eventOnStartAction;
|
||||
|
||||
public bool useEventOnEndAction;
|
||||
public UnityEvent eventOnEndAction;
|
||||
|
||||
[HideInInspector] public Coroutine actionCoroutine;
|
||||
|
||||
|
||||
public virtual void startAIAction ()
|
||||
{
|
||||
if (actionEnabled) {
|
||||
activateCoroutine ();
|
||||
|
||||
actionActive = true;
|
||||
|
||||
if (useEventOnStartAction) {
|
||||
eventOnStartAction.Invoke ();
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("startAIAction");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void endAIAction ()
|
||||
{
|
||||
if (actionEnabled) {
|
||||
if (actionActive) {
|
||||
if (useEventOnEndAction) {
|
||||
eventOnEndAction.Invoke ();
|
||||
}
|
||||
|
||||
actionActive = false;
|
||||
|
||||
stopActionCoroutine ();
|
||||
|
||||
resetStatesOnActionEnd ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("endAIAction");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void stopActionCoroutine ()
|
||||
{
|
||||
if (actionCoroutine != null) {
|
||||
StopCoroutine (actionCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void activateCoroutine ()
|
||||
{
|
||||
if (useUpdateSystemCoroutine) {
|
||||
actionCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
} else {
|
||||
actionCoroutine = StartCoroutine (updateActionCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateActionCoroutine ()
|
||||
{
|
||||
WaitForSeconds delay = new WaitForSeconds (actionDuration);
|
||||
|
||||
yield return delay;
|
||||
|
||||
endAIAction ();
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void updateSystem ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void resetStatesOnActionEnd ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setCustomTarget (Transform newTarget)
|
||||
{
|
||||
currentTarget = newTarget;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6bc013e2b7fa79448156f8558f8c7c3
|
||||
timeCreated: 1697766910
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/simpleAIAction.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class turnBasedCombatAIBehavior : AIBehaviorInfo
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public AITurnBasedCombatSystemBrain mainAITurnBasedCombatSystemBrain;
|
||||
|
||||
public override void updateAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAITurnBasedCombatSystemBrain.updateAI ();
|
||||
}
|
||||
|
||||
public override void updateAIBehaviorState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAITurnBasedCombatSystemBrain.updateBehavior ();
|
||||
}
|
||||
|
||||
public override void updateAIAttackState (bool canUseAttack)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAITurnBasedCombatSystemBrain.updateAIAttackState (canUseAttack);
|
||||
}
|
||||
|
||||
public override void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAITurnBasedCombatSystemBrain.setSystemActiveState (state);
|
||||
}
|
||||
|
||||
public override void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
mainAITurnBasedCombatSystemBrain.setWaitToActivateAttackActiveState (state);
|
||||
}
|
||||
|
||||
public override void setIsCurrentCharacterTurn (bool state)
|
||||
{
|
||||
mainAITurnBasedCombatSystemBrain.setIsCurrentCharacterTurn (state);
|
||||
}
|
||||
|
||||
public override void setCurrentCharacterTurnTarget (GameObject newTarget)
|
||||
{
|
||||
mainAITurnBasedCombatSystemBrain.setCurrentCharacterTurnTarget (newTarget);
|
||||
}
|
||||
|
||||
public override void checkStateOnCharacterDead ()
|
||||
{
|
||||
mainAITurnBasedCombatSystemBrain.checkStateOnCharacterDead ();
|
||||
}
|
||||
|
||||
public override void setAIOnPlayerTeamState (bool state)
|
||||
{
|
||||
mainAITurnBasedCombatSystemBrain.setAIOnPlayerTeamState (state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b03a21007268c64893be5e402637954
|
||||
timeCreated: 1697125565
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/turnBasedCombatAIBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class useAbilitySimpleAIAction : simpleAIAction
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public string currentAbilityName;
|
||||
|
||||
public float minWaitTimeToFinishAbility = 0.4f;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool abilityInProcess;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public AIAbilitiesSystemBrain mainAIAbilitiesSystemBrain;
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
float lastTimeAbilityUsed;
|
||||
|
||||
|
||||
public void setCurrentAbilityName (string abilityName)
|
||||
{
|
||||
currentAbilityName = abilityName;
|
||||
}
|
||||
|
||||
public void setCurrentAbilityNameAndStartAIAction (string abilityName)
|
||||
{
|
||||
setCurrentAbilityName (abilityName);
|
||||
|
||||
startAIAction ();
|
||||
}
|
||||
|
||||
public override void startAIAction ()
|
||||
{
|
||||
base.startAIAction ();
|
||||
|
||||
if (actionActive) {
|
||||
if (actionUsedByPlayer) {
|
||||
|
||||
} else {
|
||||
mainFindObjectivesSystem.setPossibleTargetForTurnBasedCombatSystemAsCustomTargetToLook ();
|
||||
|
||||
mainFindObjectivesSystem.setIgnoreLookAtDirectionActiveState (true);
|
||||
}
|
||||
|
||||
mainPlayerCamera.pauseOrPlayCamera (true);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (true);
|
||||
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.lookAtTemporalObjectToLookAtTarget ();
|
||||
}
|
||||
|
||||
lastTimeAbilityUsed = Time.time;
|
||||
|
||||
mainAIAbilitiesSystemBrain.setAndActivateAbilityByName (currentAbilityName);
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateSystem ()
|
||||
{
|
||||
if (!actionActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!mainAIAbilitiesSystemBrain.isAbilityInProcess () && Time.time > minWaitTimeToFinishAbility + lastTimeAbilityUsed) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!actionUsedByPlayer) {
|
||||
mainFindObjectivesSystem.lookAtCurrentPlaceToShoot ();
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (true);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void resetStatesOnActionEnd ()
|
||||
{
|
||||
mainPlayerCamera.pauseOrPlayCamera (false);
|
||||
|
||||
mainPlayerCamera.changeCameraRotationState (false);
|
||||
|
||||
if (actionUsedByPlayer) {
|
||||
mainPlayerCamera.setLookAtTargetStateInput (false);
|
||||
} else {
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (false);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
|
||||
mainFindObjectivesSystem.setIgnoreLookAtDirectionActiveState (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e07e1a8339d07154f91d18eec901c732
|
||||
timeCreated: 1698491769
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/useAbilitySimpleAIAction.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,154 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class useCustomAbilitySimpleAIAction : simpleAIAction
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public string currentAbilityName;
|
||||
|
||||
public float minWaitTimeToFinishAbility = 0.4f;
|
||||
|
||||
public float waitTimeToUseAbility = 0.5f;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setMoveNavMeshPaused;
|
||||
public float moveNamveshPausedDuration;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool abilityInProcess;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public AIAbilitiesSystemBrain mainAIAbilitiesSystemBrain;
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public AINavMesh mainAINavmesh;
|
||||
|
||||
|
||||
float lastTimeAbilityUsed;
|
||||
|
||||
bool targetInfoAssigned;
|
||||
|
||||
bool abilityActivated;
|
||||
|
||||
Coroutine setMoveNavMeshPausedCoroutine;
|
||||
|
||||
|
||||
public void setCurrentAbilityName (string abilityName)
|
||||
{
|
||||
currentAbilityName = abilityName;
|
||||
}
|
||||
|
||||
public void setCurrentAbilityNameAndStartAIAction (string abilityName)
|
||||
{
|
||||
setCurrentAbilityName (abilityName);
|
||||
|
||||
startAIAction ();
|
||||
}
|
||||
|
||||
public override void startAIAction ()
|
||||
{
|
||||
base.startAIAction ();
|
||||
|
||||
if (actionActive) {
|
||||
abilityActivated = false;
|
||||
|
||||
targetInfoAssigned = false;
|
||||
|
||||
lastTimeAbilityUsed = Time.time;
|
||||
|
||||
abilityInProcess = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateSystem ()
|
||||
{
|
||||
if (!actionActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!mainAIAbilitiesSystemBrain.isAbilityInProcess () && Time.time > minWaitTimeToFinishAbility + lastTimeAbilityUsed) {
|
||||
endAIAction ();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (setMoveNavMeshPaused) {
|
||||
mainAINavmesh.setMoveNavMeshPausedDuringActionState (true);
|
||||
|
||||
if (moveNamveshPausedDuration > 0) {
|
||||
if (setMoveNavMeshPausedCoroutine != null) {
|
||||
StopCoroutine (setMoveNavMeshPausedCoroutine);
|
||||
}
|
||||
|
||||
setMoveNavMeshPausedCoroutine = StartCoroutine (updateSetMoveNavMeshPausedCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
if (targetInfoAssigned) {
|
||||
|
||||
mainFindObjectivesSystem.lookAtCurrentPlaceToShoot ();
|
||||
|
||||
mainAINavmesh.lookAtTaget (true);
|
||||
|
||||
mainAINavmesh.moveNavMesh (Vector3.zero, false, false);
|
||||
} else {
|
||||
if (currentTarget != null) {
|
||||
mainFindObjectivesSystem.setCustomTargetToLook (currentTarget.gameObject);
|
||||
|
||||
targetInfoAssigned = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!abilityActivated) {
|
||||
if (Time.time > waitTimeToUseAbility + lastTimeAbilityUsed) {
|
||||
mainAIAbilitiesSystemBrain.setAndActivateAbilityByName (currentAbilityName);
|
||||
|
||||
abilityActivated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void resetStatesOnActionEnd ()
|
||||
{
|
||||
mainAIAbilitiesSystemBrain.setAndActivateAbilityByName (currentAbilityName);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.lookAtTaget (false);
|
||||
|
||||
mainFindObjectivesSystem.AINavMeshManager.moveNavMesh (Vector3.zero, false, false);
|
||||
|
||||
mainFindObjectivesSystem.resetAITargets ();
|
||||
|
||||
if (setMoveNavMeshPaused) {
|
||||
if (moveNamveshPausedDuration <= 0) {
|
||||
mainAINavmesh.setMoveNavMeshPausedDuringActionState (false);
|
||||
}
|
||||
}
|
||||
|
||||
abilityInProcess = false;
|
||||
|
||||
currentTarget = null;
|
||||
|
||||
abilityActivated = false;
|
||||
}
|
||||
|
||||
IEnumerator updateSetMoveNavMeshPausedCoroutine ()
|
||||
{
|
||||
WaitForSeconds delay = new WaitForSeconds (moveNamveshPausedDuration);
|
||||
|
||||
yield return delay;
|
||||
|
||||
mainAINavmesh.setMoveNavMeshPausedDuringActionState (false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94efe0c995040aa48a6388b55a8c5ee5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/useCustomAbilitySimpleAIAction.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,218 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class weaponsAIBehavior : AIBehaviorInfo
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public AIFireWeaponsSystemBrain mainAIFireWeaponsSystemBrain;
|
||||
|
||||
public override void updateAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.updateAI ();
|
||||
}
|
||||
|
||||
public override void updateAIBehaviorState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.updateMainFireWeaponsBehavior ();
|
||||
}
|
||||
|
||||
public override void updateAIAttackState (bool canUseAttack)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.updateMainFireWeaponsAttack (canUseAttack);
|
||||
}
|
||||
|
||||
public override void updateInsideRangeDistance (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.updateInsideMinDistance (state);
|
||||
}
|
||||
|
||||
public override void resetBehaviorStates ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.resetBehaviorStates ();
|
||||
}
|
||||
|
||||
public override void dropWeapon ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.dropWeapon ();
|
||||
}
|
||||
|
||||
public override void resetAttackState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.resetAttackState ();
|
||||
}
|
||||
|
||||
public override void stopAim ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.stopAim ();
|
||||
}
|
||||
|
||||
public override void checkIfDrawWeaponsWhenResumingAI ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.checkIfDrawWeaponsWhenResumingAI ();
|
||||
}
|
||||
|
||||
public override void disableOnSpottedState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.disableOnSpottedState ();
|
||||
}
|
||||
|
||||
public override void updateWeaponsAvailableState ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.updateWeaponsAvailableState ();
|
||||
}
|
||||
|
||||
public override void setBehaviorStatesPausedState (bool state)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setBehaviorStatesPausedState (state);
|
||||
}
|
||||
|
||||
public override void setSystemActiveState (bool state)
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.setWeaponsSystemActiveState (state);
|
||||
}
|
||||
|
||||
public override bool carryingWeapon ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mainAIFireWeaponsSystemBrain.isWeaponEquiped ();
|
||||
}
|
||||
|
||||
public override void updateIfCarryingWeapon ()
|
||||
{
|
||||
if (!behaviorEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAIFireWeaponsSystemBrain.updateIfCarryingWeapon ();
|
||||
}
|
||||
|
||||
public override void setWaitToActivateAttackActiveState (bool state)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setWaitToActivateAttackActiveState (state);
|
||||
}
|
||||
|
||||
public override void setUseRandomWalkEnabledState (bool state)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setUseRandomWalkEnabledState (state);
|
||||
}
|
||||
|
||||
public override void setOriginalUseRandomWalkEnabledState ()
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setOriginalUseRandomWalkEnabledState ();
|
||||
}
|
||||
|
||||
public override void checkNoWeaponsAvailableState ()
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.checkNoFireWeaponsAvailableState ();
|
||||
}
|
||||
|
||||
public override void setDrawOrHolsterWeaponState (bool state)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setDrawOrHolsterWeaponState (state);
|
||||
}
|
||||
|
||||
public override void stopCurrentAttackInProcess ()
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.stopCurrentAttackInProcess ();
|
||||
}
|
||||
|
||||
public override void setTurnBasedCombatActionActiveState (bool state)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setTurnBasedCombatActionActiveState (state);
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterSpawn ()
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.checkAIBehaviorStateOnCharacterSpawn ();
|
||||
}
|
||||
|
||||
public override void checkAIBehaviorStateOnCharacterDespawn ()
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.checkAIBehaviorStateOnCharacterDespawn ();
|
||||
}
|
||||
|
||||
public override void checkIfDisableCurrentWeaponToChangeAttackMode (string newModeName)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.checkIfDisableCurrentWeaponToChangeAttackMode (newModeName);
|
||||
}
|
||||
|
||||
public override void changeCurrentAttackMode (string newModeName)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.changeCurrentAttackMode (newModeName);
|
||||
}
|
||||
|
||||
public override void stopAttackState ()
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.stopAttackState ();
|
||||
}
|
||||
|
||||
public override void setAttackEnabledState (bool state)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setAttackEnabledState (state);
|
||||
}
|
||||
|
||||
public override void updateCurrentTargetSelectedInfo ()
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.updateCurrentTargetSelectedInfo ();
|
||||
}
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public override void setAttackEnabledStateFromEditor (bool state)
|
||||
{
|
||||
mainAIFireWeaponsSystemBrain.setAttackEnabledStateFromEditor (state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d48a5d443c77d3644a079d8e69b1569b
|
||||
timeCreated: 1602683372
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom AI Behavior/weaponsAIBehavior.cs
|
||||
uploadId: 814740
|
||||
9
Assets/Game Kit Controller/Scripts/AI/Custom Orders.meta
Normal file
9
Assets/Game Kit Controller/Scripts/AI/Custom Orders.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df216d0c06ff12044b9a39b789b86a34
|
||||
folderAsset: yes
|
||||
timeCreated: 1671165348
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,165 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class characterToReceiveOrders : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool receiveOrdersEnabled = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Order Info Settings")]
|
||||
[Space]
|
||||
|
||||
public List<characterOrderInfo> characterOrderInfoList = new List<characterOrderInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool orderInProcess;
|
||||
|
||||
public Transform currentTarget;
|
||||
|
||||
|
||||
|
||||
characterOrderInfo newCharacterOrderInfo;
|
||||
|
||||
Coroutine orderActionCoroutine;
|
||||
|
||||
|
||||
public bool containsOrderName (string orderName)
|
||||
{
|
||||
int orderIndex = characterOrderInfoList.FindIndex (a => a.Name.Equals (orderName));
|
||||
|
||||
if (orderIndex > -1) {
|
||||
if (!characterOrderInfoList [orderIndex].orderEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void activateOrder (string orderName)
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("order to Check " + orderName);
|
||||
}
|
||||
|
||||
int orderIndex = characterOrderInfoList.FindIndex (a => a.Name.Equals (orderName));
|
||||
|
||||
if (orderIndex > -1) {
|
||||
newCharacterOrderInfo = characterOrderInfoList [orderIndex];
|
||||
|
||||
if (!newCharacterOrderInfo.orderEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("order activated " + orderName);
|
||||
}
|
||||
|
||||
if (newCharacterOrderInfo.useEventOnOrderReceived) {
|
||||
newCharacterOrderInfo.eventOnOrderReceived.Invoke ();
|
||||
}
|
||||
|
||||
if (newCharacterOrderInfo.useOrderActionDuration) {
|
||||
stopOrderActionCoroutine ();
|
||||
|
||||
orderActionCoroutine = StartCoroutine (updateOrderActionCoroutine ());
|
||||
}
|
||||
|
||||
if (newCharacterOrderInfo.useSimpleAIAction) {
|
||||
newCharacterOrderInfo.mainSimpleAIAction.startAIAction ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stopOrderActionCoroutine ()
|
||||
{
|
||||
if (orderActionCoroutine != null) {
|
||||
StopCoroutine (orderActionCoroutine);
|
||||
}
|
||||
|
||||
orderInProcess = false;
|
||||
}
|
||||
|
||||
IEnumerator updateOrderActionCoroutine ()
|
||||
{
|
||||
orderInProcess = true;
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (newCharacterOrderInfo.orderActionDuration);
|
||||
|
||||
yield return delay;
|
||||
|
||||
newCharacterOrderInfo.eventOnOrderActionComplete.Invoke ();
|
||||
|
||||
orderInProcess = false;
|
||||
}
|
||||
|
||||
public void setCustomTarget (Transform newTarget)
|
||||
{
|
||||
currentTarget = newTarget;
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (newCharacterOrderInfo != null) {
|
||||
if (newCharacterOrderInfo.useEventToSendTarget) {
|
||||
newCharacterOrderInfo.eventToSendTarget.Invoke (currentTarget);
|
||||
}
|
||||
|
||||
if (newCharacterOrderInfo.sendTargetOnSimpleAIAction) {
|
||||
if (newCharacterOrderInfo.useSimpleAIAction) {
|
||||
newCharacterOrderInfo.mainSimpleAIAction.setCustomTarget (newTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isOrderInProcess ()
|
||||
{
|
||||
return orderInProcess;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class characterOrderInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public bool orderEnabled = true;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useEventOnOrderReceived;
|
||||
|
||||
public UnityEvent eventOnOrderReceived;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useOrderActionDuration;
|
||||
public float orderActionDuration;
|
||||
|
||||
public UnityEvent eventOnOrderActionComplete;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useEventToSendTarget;
|
||||
public eventParameters.eventToCallWithTransform eventToSendTarget;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useSimpleAIAction;
|
||||
|
||||
public simpleAIAction mainSimpleAIAction;
|
||||
|
||||
public bool sendTargetOnSimpleAIAction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92b0043822e534e42a9e44846dc7cdb6
|
||||
timeCreated: 1670890122
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/characterToReceiveOrders.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class customOrderBehavior : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool orderEnabled = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public Transform currentTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventToSendTarget;
|
||||
public eventParameters.eventToCallWithTransform eventToSendTarget;
|
||||
|
||||
public virtual void activateOrder (Transform character)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void activateOrder (Transform character, Transform orderOwner)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual Transform getCustomTarget (Transform character, Transform orderOwner)
|
||||
{
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void setCustomTarget (Transform newTarget)
|
||||
{
|
||||
currentTarget = newTarget;
|
||||
|
||||
if (useEventToSendTarget) {
|
||||
if (currentTarget != null) {
|
||||
eventToSendTarget.Invoke (currentTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool checkConditionToShowOrderButton (Transform character)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dd1f0331b876354686b6cdd67ec16d2
|
||||
timeCreated: 1670783147
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,409 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToAttack : customOrderBehavior
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public List<string> tagToLocate = new List<string> ();
|
||||
|
||||
public bool checkIfTargetOnLockOnViewEnabled = true;
|
||||
|
||||
public bool sendPlayerAsTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Target Detection Settings")]
|
||||
[Space]
|
||||
|
||||
public bool getClosestTargetToCameraViewIfNoLockOnActive;
|
||||
|
||||
public float maxDistanceToFindTarget = 300;
|
||||
|
||||
public bool searchPointToLookComponents = true;
|
||||
|
||||
public bool lookOnlyIfTargetOnScreen;
|
||||
|
||||
public bool checkObstaclesToTarget;
|
||||
|
||||
public LayerMask layerToLook;
|
||||
|
||||
public LayerMask pointToLookComponentsLayer;
|
||||
|
||||
public bool getClosestToCameraCenter;
|
||||
|
||||
public bool useMaxDistanceToCameraCenter;
|
||||
|
||||
public float maxDistanceToCameraCenter = 200;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showCameraGizmo;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform mainCameraTransform;
|
||||
public Transform playerCameraTransform;
|
||||
public playerCamera mainPlayerCamera;
|
||||
public Camera mainCamera;
|
||||
|
||||
public override void activateOrder (Transform character)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override Transform getCustomTarget (Transform character, Transform orderOwner)
|
||||
{
|
||||
if (sendPlayerAsTarget) {
|
||||
return orderOwner;
|
||||
}
|
||||
|
||||
if (canAIAttack (character)) {
|
||||
|
||||
if (checkIfTargetOnLockOnViewEnabled) {
|
||||
playerComponentsManager currentPlayerComponentsManager = orderOwner.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
playerCamera currentPlayerCamera = currentPlayerComponentsManager.getPlayerCamera ();
|
||||
|
||||
if (currentPlayerCamera != null) {
|
||||
if (currentPlayerCamera.isPlayerLookingAtTarget ()) {
|
||||
Transform currentTarget = currentPlayerCamera.getLastCharacterToLook ();
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (applyDamage.isCharacter (currentTarget.gameObject)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
} else {
|
||||
if (applyDamage.getCharacterFromPlaceToShoot (currentTarget)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getClosestTargetToCameraViewIfNoLockOnActive) {
|
||||
Transform currentTarget = getClosestEnemyToScreenView ();
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (applyDamage.isCharacter (currentTarget.gameObject)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getClosestEnemy (orderOwner);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool canAIAttack (Transform AIFriend)
|
||||
{
|
||||
bool canAttack = false;
|
||||
|
||||
findObjectivesSystem currentFindObjectivesSystem = AIFriend.GetComponentInChildren<findObjectivesSystem> ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
if (currentFindObjectivesSystem.attackType != findObjectivesSystem.AIAttackType.none) {
|
||||
canAttack = true;
|
||||
}
|
||||
}
|
||||
|
||||
return canAttack;
|
||||
}
|
||||
|
||||
public Transform getClosestEnemy (Transform centerPointTransform)
|
||||
{
|
||||
Vector3 centerPosition = centerPointTransform.position;
|
||||
|
||||
List<GameObject> fullEnemyList = new List<GameObject> ();
|
||||
|
||||
GameObject closestEnemy;
|
||||
|
||||
for (int i = 0; i < tagToLocate.Count; i++) {
|
||||
GameObject [] enemiesList = GameObject.FindGameObjectsWithTag (tagToLocate [i]);
|
||||
|
||||
fullEnemyList.AddRange (enemiesList);
|
||||
}
|
||||
|
||||
List<GameObject> closestEnemyList = new List<GameObject> ();
|
||||
|
||||
for (int j = 0; j < fullEnemyList.Count; j++) {
|
||||
if (!applyDamage.checkIfDead (fullEnemyList [j])) {
|
||||
closestEnemyList.Add (fullEnemyList [j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (closestEnemyList.Count > 0) {
|
||||
float distance = Mathf.Infinity;
|
||||
|
||||
int index = -1;
|
||||
|
||||
for (int j = 0; j < closestEnemyList.Count; j++) {
|
||||
float currentDistance = GKC_Utils.distance (closestEnemyList [j].transform.position, centerPosition);
|
||||
|
||||
if (currentDistance < distance) {
|
||||
distance = currentDistance;
|
||||
index = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != -1) {
|
||||
closestEnemy = closestEnemyList [index];
|
||||
|
||||
return closestEnemy.transform;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public Transform getClosestEnemyToScreenView ()
|
||||
{
|
||||
List<Collider> targetsListCollider = new List<Collider> ();
|
||||
|
||||
List<GameObject> targetList = new List<GameObject> ();
|
||||
List<GameObject> fullTargetList = new List<GameObject> ();
|
||||
|
||||
List<Transform> targetsListToLookTransform = new List<Transform> ();
|
||||
|
||||
int tagToLocateCount = tagToLocate.Count;
|
||||
|
||||
for (int i = 0; i < tagToLocateCount; i++) {
|
||||
GameObject [] enemiesList = GameObject.FindGameObjectsWithTag (tagToLocate [i]);
|
||||
targetList.AddRange (enemiesList);
|
||||
}
|
||||
|
||||
int targetListCount = targetList.Count;
|
||||
|
||||
for (int i = 0; i < targetListCount; i++) {
|
||||
float distance = GKC_Utils.distance (targetList [i].transform.position, playerCameraTransform.position);
|
||||
|
||||
if (distance < maxDistanceToFindTarget) {
|
||||
fullTargetList.Add (targetList [i]);
|
||||
}
|
||||
}
|
||||
|
||||
List<GameObject> pointToLookComponentList = new List<GameObject> ();
|
||||
|
||||
if (searchPointToLookComponents) {
|
||||
targetsListCollider.Clear ();
|
||||
|
||||
targetsListCollider.AddRange (Physics.OverlapSphere (playerCameraTransform.position, maxDistanceToFindTarget, pointToLookComponentsLayer));
|
||||
|
||||
int targetsListColliderCount = targetsListCollider.Count;
|
||||
|
||||
for (int i = 0; i < targetsListColliderCount; i++) {
|
||||
if (targetsListCollider [i].isTrigger) {
|
||||
pointToLook currentPointToLook = targetsListCollider [i].GetComponent<pointToLook> ();
|
||||
|
||||
if (currentPointToLook != null) {
|
||||
if (currentPointToLook.isPointToLookEnabled ()) {
|
||||
GameObject currenTargetToLook = currentPointToLook.getPointToLookTransform ().gameObject;
|
||||
|
||||
fullTargetList.Add (currenTargetToLook);
|
||||
|
||||
pointToLookComponentList.Add (currenTargetToLook);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isUsingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
|
||||
|
||||
float screenWidth = Screen.width;
|
||||
float screenHeight = Screen.height;
|
||||
|
||||
Vector3 screenPoint;
|
||||
|
||||
bool targetOnScreen;
|
||||
|
||||
int fullTargetListCount = fullTargetList.Count;
|
||||
|
||||
RaycastHit hit = new RaycastHit ();
|
||||
|
||||
for (int i = 0; i < fullTargetListCount; i++) {
|
||||
if (fullTargetList [i] != null) {
|
||||
GameObject currentTarget = fullTargetList [i];
|
||||
|
||||
if (tagToLocate.Contains (currentTarget.tag) || pointToLookComponentList.Contains (currentTarget)) {
|
||||
bool objectVisible = false;
|
||||
bool obstacleDetected = false;
|
||||
|
||||
Vector3 targetPosition = currentTarget.transform.position;
|
||||
|
||||
if (lookOnlyIfTargetOnScreen) {
|
||||
Transform currentTargetPlaceToShoot = applyDamage.getPlaceToShoot (currentTarget);
|
||||
|
||||
if (currentTargetPlaceToShoot != null) {
|
||||
targetPosition = currentTargetPlaceToShoot.position;
|
||||
}
|
||||
|
||||
if (isUsingScreenSpaceCamera) {
|
||||
screenPoint = mainCamera.WorldToViewportPoint (targetPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
|
||||
} else {
|
||||
screenPoint = mainCamera.WorldToScreenPoint (targetPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
|
||||
}
|
||||
|
||||
//the target is visible in the screen
|
||||
if (targetOnScreen) {
|
||||
objectVisible = true;
|
||||
}
|
||||
} else {
|
||||
objectVisible = true;
|
||||
}
|
||||
|
||||
if (objectVisible && checkObstaclesToTarget) {
|
||||
//for every target in front of the camera, use a raycast, if it finds an obstacle between the target and the camera, the target is removed from the list
|
||||
Vector3 temporaltargetPosition = targetPosition;
|
||||
|
||||
Transform temporalPlaceToShoot = applyDamage.getPlaceToShoot (currentTarget);
|
||||
|
||||
if (temporalPlaceToShoot != null) {
|
||||
temporaltargetPosition = temporalPlaceToShoot.position;
|
||||
}
|
||||
|
||||
Vector3 direction = temporaltargetPosition - mainCameraTransform.position;
|
||||
|
||||
direction = direction / direction.magnitude;
|
||||
|
||||
float distance = GKC_Utils.distance (temporaltargetPosition, mainCameraTransform.position);
|
||||
|
||||
if (Physics.Raycast (temporaltargetPosition, -direction, out hit, distance, layerToLook)) {
|
||||
obstacleDetected = true;
|
||||
|
||||
if (showCameraGizmo) {
|
||||
Debug.DrawLine (temporaltargetPosition, hit.point, Color.white, 4);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("obstacle detected " + hit.collider.name + " " + currentTarget.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (objectVisible && !obstacleDetected) {
|
||||
targetsListToLookTransform.Add (currentTarget.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finally, get the target closest to the player
|
||||
float minDistance = Mathf.Infinity;
|
||||
|
||||
Vector3 centerScreen = mainPlayerCamera.getScreenCenter ();
|
||||
|
||||
int targetsListToLookTransformCount = targetsListToLookTransform.Count;
|
||||
|
||||
Transform placeToShoot;
|
||||
|
||||
bool targetFound = false;
|
||||
|
||||
Transform targetToLook = null;
|
||||
|
||||
for (int i = 0; i < targetsListToLookTransformCount; i++) {
|
||||
|
||||
//find closes element to center screen
|
||||
if (getClosestToCameraCenter) {
|
||||
Vector3 targetPosition = targetsListToLookTransform [i].position;
|
||||
|
||||
placeToShoot = applyDamage.getPlaceToShoot (targetsListToLookTransform [i].gameObject);
|
||||
|
||||
if (placeToShoot != null) {
|
||||
targetPosition = placeToShoot.position;
|
||||
}
|
||||
|
||||
screenPoint = mainCamera.WorldToScreenPoint (targetPosition);
|
||||
|
||||
// print (screenPoint + " " + centerScreen);
|
||||
|
||||
float currentDistance = GKC_Utils.distance (screenPoint, centerScreen);
|
||||
|
||||
bool canBeChecked = false;
|
||||
|
||||
if (useMaxDistanceToCameraCenter) {
|
||||
if (currentDistance < maxDistanceToCameraCenter) {
|
||||
canBeChecked = true;
|
||||
}
|
||||
} else {
|
||||
canBeChecked = true;
|
||||
}
|
||||
|
||||
if (canBeChecked) {
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
targetToLook = targetsListToLookTransform [i];
|
||||
|
||||
targetFound = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
float currentDistance = GKC_Utils.distance (targetsListToLookTransform [i].position, playerCameraTransform.position);
|
||||
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
targetToLook = targetsListToLookTransform [i];
|
||||
|
||||
targetFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetFound) {
|
||||
//check if the object to check is too far from screen center in case the llok at body parts on characters is active and no body part is found or is close enough to screen center
|
||||
if (useMaxDistanceToCameraCenter && getClosestToCameraCenter) {
|
||||
placeToShoot = applyDamage.getPlaceToShoot (targetToLook.gameObject);
|
||||
|
||||
if (placeToShoot == null) {
|
||||
placeToShoot = targetToLook;
|
||||
}
|
||||
|
||||
screenPoint = mainCamera.WorldToScreenPoint (placeToShoot.position);
|
||||
|
||||
float currentDistance = GKC_Utils.distance (screenPoint, centerScreen);
|
||||
|
||||
if (currentDistance > maxDistanceToCameraCenter) {
|
||||
targetToLook = null;
|
||||
targetFound = false;
|
||||
|
||||
//print ("cancel look at target");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
if (targetFound) {
|
||||
print ("target found " + targetToLook.name);
|
||||
}
|
||||
}
|
||||
|
||||
return targetToLook;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b44a371b3f0a5e249bc325eb6e598546
|
||||
timeCreated: 1670784274
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToAttack.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,122 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToBorrowWeapon : customOrderBehavior
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public ForceMode dropForceMode;
|
||||
public float extraForceAmount = 5;
|
||||
|
||||
public bool useParableSpeed;
|
||||
|
||||
public bool pickWeaponDirectlyOnPlayer;
|
||||
|
||||
public override void activateOrder (Transform character, Transform orderOwner)
|
||||
{
|
||||
if (!orderEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (character == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = character.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
findObjectivesSystem currentFindObjectivesSystem = currentPlayerComponentsManager.getFindObjectivesSystem ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
|
||||
GameObject lastWeaponDroppedObject = null;
|
||||
|
||||
playerWeaponsManager currentPlayerWeaponsManager = currentPlayerComponentsManager.getPlayerWeaponsManager ();
|
||||
|
||||
if (currentPlayerWeaponsManager != null) {
|
||||
if (currentPlayerWeaponsManager.isWeaponsModeActive ()) {
|
||||
// currentPlayerWeaponsManager.dropCurrentWeaponExternally ();
|
||||
|
||||
if (currentPlayerWeaponsManager.isUsingWeapons ()) {
|
||||
currentFindObjectivesSystem.dropWeapon ();
|
||||
|
||||
lastWeaponDroppedObject = currentPlayerWeaponsManager.getLastWeaponDroppedObject ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("dropping fire weapon");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
meleeWeaponsGrabbedManager currentMeleeWeaponsGrabbedManager = currentPlayerComponentsManager.getMeleeWeaponsGrabbedManager ();
|
||||
|
||||
if (currentMeleeWeaponsGrabbedManager != null) {
|
||||
Transform currentWeaponTransform = currentMeleeWeaponsGrabbedManager.getCurrentGrabbedObjectTransform ();
|
||||
|
||||
if (currentWeaponTransform != null) {
|
||||
lastWeaponDroppedObject = currentWeaponTransform.gameObject;
|
||||
|
||||
currentFindObjectivesSystem.dropWeapon ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("dropping melee weapon");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (lastWeaponDroppedObject != null) {
|
||||
if (showDebugPrint) {
|
||||
print ("weapon dropped located");
|
||||
}
|
||||
|
||||
Rigidbody weaponRigidbody = lastWeaponDroppedObject.GetComponent<Rigidbody> ();
|
||||
|
||||
if (weaponRigidbody != null) {
|
||||
if (useParableSpeed) {
|
||||
Vector3 newVel = GKC_Utils.getParableSpeed (weaponRigidbody.position, orderOwner.position, character.forward,
|
||||
character, true, false, 0);
|
||||
|
||||
if (newVel == -Vector3.one) {
|
||||
newVel = character.forward * 100;
|
||||
}
|
||||
|
||||
weaponRigidbody.AddForce (newVel, ForceMode.VelocityChange);
|
||||
} else {
|
||||
|
||||
Vector3 forceDirection = orderOwner.position - weaponRigidbody.position;
|
||||
|
||||
float distance = forceDirection.magnitude;
|
||||
forceDirection = forceDirection / distance;
|
||||
|
||||
weaponRigidbody.AddForce (forceDirection * extraForceAmount, dropForceMode);
|
||||
}
|
||||
}
|
||||
|
||||
if (pickWeaponDirectlyOnPlayer) {
|
||||
playerComponentsManager orderOwnerPlayerComponentsManager = orderOwner.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (orderOwnerPlayerComponentsManager != null) {
|
||||
playerController ownerPlayerController = orderOwnerPlayerComponentsManager.getPlayerController ();
|
||||
|
||||
if (ownerPlayerController != null) {
|
||||
if (!ownerPlayerController.playerIsBusy ()) {
|
||||
simpleActionButton currentSimpleActionButton = lastWeaponDroppedObject.GetComponentInChildren<simpleActionButton> ();
|
||||
|
||||
if (currentSimpleActionButton != null) {
|
||||
lastWeaponDroppedObject = currentSimpleActionButton.gameObject;
|
||||
}
|
||||
|
||||
GKC_Utils.useObjectExternally (orderOwner.gameObject, lastWeaponDroppedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de069a3bcfa2df44c9fe82ff302e54a9
|
||||
timeCreated: 1671165527
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToBorrowWeapon.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,421 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToFollow : customOrderBehavior
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public List<string> tagToLocate = new List<string> ();
|
||||
|
||||
public bool checkIfTargetOnLockOnViewEnabled = true;
|
||||
|
||||
public bool sendPlayerAsTarget = true;
|
||||
|
||||
public bool ignoreToGetClosestEnemy;
|
||||
|
||||
[Space]
|
||||
[Header ("Target Detection Settings")]
|
||||
[Space]
|
||||
|
||||
public bool getClosestTargetToCameraViewIfNoLockOnActive;
|
||||
|
||||
public float maxDistanceToFindTarget = 300;
|
||||
|
||||
public bool searchPointToLookComponents = true;
|
||||
|
||||
public bool lookOnlyIfTargetOnScreen;
|
||||
|
||||
public bool checkObstaclesToTarget;
|
||||
|
||||
public LayerMask layerToLook;
|
||||
|
||||
public LayerMask pointToLookComponentsLayer;
|
||||
|
||||
public bool getClosestToCameraCenter;
|
||||
|
||||
public bool useMaxDistanceToCameraCenter;
|
||||
|
||||
public float maxDistanceToCameraCenter = 200;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showCameraGizmo;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform mainCameraTransform;
|
||||
public Transform playerCameraTransform;
|
||||
public playerCamera mainPlayerCamera;
|
||||
public Camera mainCamera;
|
||||
|
||||
public override void activateOrder (Transform character)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override Transform getCustomTarget (Transform character, Transform orderOwner)
|
||||
{
|
||||
if (sendPlayerAsTarget) {
|
||||
return orderOwner;
|
||||
}
|
||||
|
||||
if (canAIAttack (character)) {
|
||||
|
||||
if (checkIfTargetOnLockOnViewEnabled) {
|
||||
playerComponentsManager currentPlayerComponentsManager = orderOwner.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
playerCamera currentPlayerCamera = currentPlayerComponentsManager.getPlayerCamera ();
|
||||
|
||||
if (currentPlayerCamera != null) {
|
||||
if (currentPlayerCamera.isPlayerLookingAtTarget ()) {
|
||||
Transform currentTarget = currentPlayerCamera.getLastCharacterToLook ();
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (applyDamage.isCharacter (currentTarget.gameObject)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
} else {
|
||||
if (applyDamage.getCharacterFromPlaceToShoot (currentTarget)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getClosestTargetToCameraViewIfNoLockOnActive) {
|
||||
Transform currentTarget = getClosestEnemyToScreenView ();
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (applyDamage.isCharacter (currentTarget.gameObject)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreToGetClosestEnemy) {
|
||||
return orderOwner;
|
||||
}
|
||||
|
||||
Transform target = getClosestEnemy (orderOwner);
|
||||
|
||||
if (target == null) {
|
||||
target = orderOwner;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool canAIAttack (Transform AIFriend)
|
||||
{
|
||||
bool canAttack = false;
|
||||
|
||||
findObjectivesSystem currentFindObjectivesSystem = AIFriend.GetComponentInChildren<findObjectivesSystem> ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
if (currentFindObjectivesSystem.attackType != findObjectivesSystem.AIAttackType.none) {
|
||||
canAttack = true;
|
||||
}
|
||||
}
|
||||
|
||||
return canAttack;
|
||||
}
|
||||
|
||||
public Transform getClosestEnemy (Transform centerPointTransform)
|
||||
{
|
||||
Vector3 centerPosition = centerPointTransform.position;
|
||||
|
||||
List<GameObject> fullEnemyList = new List<GameObject> ();
|
||||
|
||||
GameObject closestEnemy;
|
||||
|
||||
for (int i = 0; i < tagToLocate.Count; i++) {
|
||||
GameObject [] enemiesList = GameObject.FindGameObjectsWithTag (tagToLocate [i]);
|
||||
|
||||
fullEnemyList.AddRange (enemiesList);
|
||||
}
|
||||
|
||||
List<GameObject> closestEnemyList = new List<GameObject> ();
|
||||
|
||||
for (int j = 0; j < fullEnemyList.Count; j++) {
|
||||
if (!applyDamage.checkIfDead (fullEnemyList [j])) {
|
||||
closestEnemyList.Add (fullEnemyList [j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (closestEnemyList.Count > 0) {
|
||||
float distance = Mathf.Infinity;
|
||||
|
||||
int index = -1;
|
||||
|
||||
for (int j = 0; j < closestEnemyList.Count; j++) {
|
||||
float currentDistance = GKC_Utils.distance (closestEnemyList [j].transform.position, centerPosition);
|
||||
|
||||
if (currentDistance < distance) {
|
||||
distance = currentDistance;
|
||||
index = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != -1) {
|
||||
closestEnemy = closestEnemyList [index];
|
||||
|
||||
return closestEnemy.transform;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public Transform getClosestEnemyToScreenView ()
|
||||
{
|
||||
List<Collider> targetsListCollider = new List<Collider> ();
|
||||
|
||||
List<GameObject> targetList = new List<GameObject> ();
|
||||
List<GameObject> fullTargetList = new List<GameObject> ();
|
||||
|
||||
List<Transform> targetsListToLookTransform = new List<Transform> ();
|
||||
|
||||
int tagToLocateCount = tagToLocate.Count;
|
||||
|
||||
for (int i = 0; i < tagToLocateCount; i++) {
|
||||
GameObject [] enemiesList = GameObject.FindGameObjectsWithTag (tagToLocate [i]);
|
||||
targetList.AddRange (enemiesList);
|
||||
}
|
||||
|
||||
int targetListCount = targetList.Count;
|
||||
|
||||
for (int i = 0; i < targetListCount; i++) {
|
||||
float distance = GKC_Utils.distance (targetList [i].transform.position, playerCameraTransform.position);
|
||||
|
||||
if (distance < maxDistanceToFindTarget) {
|
||||
fullTargetList.Add (targetList [i]);
|
||||
}
|
||||
}
|
||||
|
||||
List<GameObject> pointToLookComponentList = new List<GameObject> ();
|
||||
|
||||
if (searchPointToLookComponents) {
|
||||
targetsListCollider.Clear ();
|
||||
|
||||
targetsListCollider.AddRange (Physics.OverlapSphere (playerCameraTransform.position, maxDistanceToFindTarget, pointToLookComponentsLayer));
|
||||
|
||||
int targetsListColliderCount = targetsListCollider.Count;
|
||||
|
||||
for (int i = 0; i < targetsListColliderCount; i++) {
|
||||
if (targetsListCollider [i].isTrigger) {
|
||||
pointToLook currentPointToLook = targetsListCollider [i].GetComponent<pointToLook> ();
|
||||
|
||||
if (currentPointToLook != null) {
|
||||
if (currentPointToLook.isPointToLookEnabled ()) {
|
||||
GameObject currenTargetToLook = currentPointToLook.getPointToLookTransform ().gameObject;
|
||||
|
||||
fullTargetList.Add (currenTargetToLook);
|
||||
|
||||
pointToLookComponentList.Add (currenTargetToLook);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isUsingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
|
||||
|
||||
float screenWidth = Screen.width;
|
||||
float screenHeight = Screen.height;
|
||||
|
||||
Vector3 screenPoint;
|
||||
|
||||
bool targetOnScreen;
|
||||
|
||||
int fullTargetListCount = fullTargetList.Count;
|
||||
|
||||
RaycastHit hit = new RaycastHit ();
|
||||
|
||||
for (int i = 0; i < fullTargetListCount; i++) {
|
||||
if (fullTargetList [i] != null) {
|
||||
GameObject currentTarget = fullTargetList [i];
|
||||
|
||||
if (tagToLocate.Contains (currentTarget.tag) || pointToLookComponentList.Contains (currentTarget)) {
|
||||
bool objectVisible = false;
|
||||
bool obstacleDetected = false;
|
||||
|
||||
Vector3 targetPosition = currentTarget.transform.position;
|
||||
|
||||
if (lookOnlyIfTargetOnScreen) {
|
||||
Transform currentTargetPlaceToShoot = applyDamage.getPlaceToShoot (currentTarget);
|
||||
|
||||
if (currentTargetPlaceToShoot != null) {
|
||||
targetPosition = currentTargetPlaceToShoot.position;
|
||||
}
|
||||
|
||||
if (isUsingScreenSpaceCamera) {
|
||||
screenPoint = mainCamera.WorldToViewportPoint (targetPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
|
||||
} else {
|
||||
screenPoint = mainCamera.WorldToScreenPoint (targetPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
|
||||
}
|
||||
|
||||
//the target is visible in the screen
|
||||
if (targetOnScreen) {
|
||||
objectVisible = true;
|
||||
}
|
||||
} else {
|
||||
objectVisible = true;
|
||||
}
|
||||
|
||||
if (objectVisible && checkObstaclesToTarget) {
|
||||
//for every target in front of the camera, use a raycast, if it finds an obstacle between the target and the camera, the target is removed from the list
|
||||
Vector3 temporaltargetPosition = targetPosition;
|
||||
|
||||
Transform temporalPlaceToShoot = applyDamage.getPlaceToShoot (currentTarget);
|
||||
|
||||
if (temporalPlaceToShoot != null) {
|
||||
temporaltargetPosition = temporalPlaceToShoot.position;
|
||||
}
|
||||
|
||||
Vector3 direction = temporaltargetPosition - mainCameraTransform.position;
|
||||
|
||||
direction = direction / direction.magnitude;
|
||||
|
||||
float distance = GKC_Utils.distance (temporaltargetPosition, mainCameraTransform.position);
|
||||
|
||||
if (Physics.Raycast (temporaltargetPosition, -direction, out hit, distance, layerToLook)) {
|
||||
obstacleDetected = true;
|
||||
|
||||
if (showCameraGizmo) {
|
||||
Debug.DrawLine (temporaltargetPosition, hit.point, Color.white, 4);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("obstacle detected " + hit.collider.name + " " + currentTarget.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (objectVisible && !obstacleDetected) {
|
||||
targetsListToLookTransform.Add (currentTarget.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finally, get the target closest to the player
|
||||
float minDistance = Mathf.Infinity;
|
||||
|
||||
Vector3 centerScreen = mainPlayerCamera.getScreenCenter ();
|
||||
|
||||
int targetsListToLookTransformCount = targetsListToLookTransform.Count;
|
||||
|
||||
Transform placeToShoot;
|
||||
|
||||
bool targetFound = false;
|
||||
|
||||
Transform targetToLook = null;
|
||||
|
||||
for (int i = 0; i < targetsListToLookTransformCount; i++) {
|
||||
|
||||
//find closes element to center screen
|
||||
if (getClosestToCameraCenter) {
|
||||
Vector3 targetPosition = targetsListToLookTransform [i].position;
|
||||
|
||||
placeToShoot = applyDamage.getPlaceToShoot (targetsListToLookTransform [i].gameObject);
|
||||
|
||||
if (placeToShoot != null) {
|
||||
targetPosition = placeToShoot.position;
|
||||
}
|
||||
|
||||
screenPoint = mainCamera.WorldToScreenPoint (targetPosition);
|
||||
|
||||
// print (screenPoint + " " + centerScreen);
|
||||
|
||||
float currentDistance = GKC_Utils.distance (screenPoint, centerScreen);
|
||||
|
||||
bool canBeChecked = false;
|
||||
|
||||
if (useMaxDistanceToCameraCenter) {
|
||||
if (currentDistance < maxDistanceToCameraCenter) {
|
||||
canBeChecked = true;
|
||||
}
|
||||
} else {
|
||||
canBeChecked = true;
|
||||
}
|
||||
|
||||
if (canBeChecked) {
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
targetToLook = targetsListToLookTransform [i];
|
||||
|
||||
targetFound = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
float currentDistance = GKC_Utils.distance (targetsListToLookTransform [i].position, playerCameraTransform.position);
|
||||
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
targetToLook = targetsListToLookTransform [i];
|
||||
|
||||
targetFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetFound) {
|
||||
//check if the object to check is too far from screen center in case the look at body parts on characters is active and no body part is found or is close enough to screen center
|
||||
if (useMaxDistanceToCameraCenter && getClosestToCameraCenter) {
|
||||
placeToShoot = applyDamage.getPlaceToShoot (targetToLook.gameObject);
|
||||
|
||||
if (placeToShoot == null) {
|
||||
placeToShoot = targetToLook;
|
||||
}
|
||||
|
||||
screenPoint = mainCamera.WorldToScreenPoint (placeToShoot.position);
|
||||
|
||||
float currentDistance = GKC_Utils.distance (screenPoint, centerScreen);
|
||||
|
||||
if (currentDistance > maxDistanceToCameraCenter) {
|
||||
targetToLook = null;
|
||||
targetFound = false;
|
||||
|
||||
//print ("cancel look at target");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
if (targetFound) {
|
||||
print ("target found " + targetToLook.name);
|
||||
}
|
||||
}
|
||||
|
||||
return targetToLook;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8bc796590ead5343ae61b786283d45d
|
||||
timeCreated: 1670784966
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToFollow.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToHide : customOrderBehavior
|
||||
{
|
||||
AIHidePositionsManager mainAIHidePositionsManager;
|
||||
|
||||
public override void activateOrder (Transform character)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override Transform getCustomTarget (Transform character, Transform orderOwner)
|
||||
{
|
||||
return getClosestHidePosition (character);
|
||||
}
|
||||
|
||||
public Transform getClosestHidePosition (Transform AIFriend)
|
||||
{
|
||||
if (mainAIHidePositionsManager == null) {
|
||||
mainAIHidePositionsManager = FindObjectOfType<AIHidePositionsManager> ();
|
||||
}
|
||||
|
||||
if (mainAIHidePositionsManager != null) {
|
||||
if (mainAIHidePositionsManager.hidePositionList.Count > 0) {
|
||||
float distance = Mathf.Infinity;
|
||||
|
||||
int index = -1;
|
||||
|
||||
for (int j = 0; j < mainAIHidePositionsManager.hidePositionList.Count; j++) {
|
||||
float currentDistance = GKC_Utils.distance (AIFriend.position, mainAIHidePositionsManager.hidePositionList [j].position);
|
||||
|
||||
if (currentDistance < distance) {
|
||||
distance = currentDistance;
|
||||
|
||||
index = j;
|
||||
}
|
||||
}
|
||||
|
||||
return mainAIHidePositionsManager.hidePositionList [index];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 406fae6ed14cd4a45b2b364bb6f8b117
|
||||
timeCreated: 1670785201
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToHide.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToShapeShiftCharacter : customOrderBehavior
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool changeEnabled = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Generic Character Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setRegularCharacter;
|
||||
|
||||
public string customCharacterNameToConfigure;
|
||||
|
||||
public override void activateOrder (Transform character)
|
||||
{
|
||||
if (!changeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (character == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = character.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
customCharacterControllerManager currentCustomCharacterControllerManager = currentPlayerComponentsManager.getCustomCharacterControllerManager ();
|
||||
|
||||
if (currentCustomCharacterControllerManager != null) {
|
||||
if (setRegularCharacter) {
|
||||
if (currentCustomCharacterControllerManager.isCustomCharacterControllerActive ()) {
|
||||
currentCustomCharacterControllerManager.disableCustomCharacterControllerState ();
|
||||
}
|
||||
} else {
|
||||
currentCustomCharacterControllerManager.setCustomCharacterControllerState (customCharacterNameToConfigure);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d805e13fb596bb47877b174f1f8f55b
|
||||
timeCreated: 1671037082
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToShapeShiftCharacter.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToSwitchCharacter : customOrderBehavior
|
||||
{
|
||||
public playerCharactersManager mainPlayerCharactersManager;
|
||||
|
||||
public override void activateOrder (Transform character)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override Transform getCustomTarget (Transform character, Transform orderOwner)
|
||||
{
|
||||
return character;
|
||||
}
|
||||
|
||||
|
||||
public override bool checkConditionToShowOrderButton (Transform character)
|
||||
{
|
||||
if (character == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mainPlayerCharactersManager.isCharacterInList (character.gameObject)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b955bdf66c7f7b74591933612a5a82c8
|
||||
timeCreated: 1670785395
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToSwitchCharacter.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,408 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToUseAbility : customOrderBehavior
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public List<string> tagToLocate = new List<string> ();
|
||||
|
||||
public bool checkIfTargetOnLockOnViewEnabled = true;
|
||||
|
||||
public bool sendPlayerAsTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Target Detection Settings")]
|
||||
[Space]
|
||||
|
||||
public bool getClosestTargetToCameraViewIfNoLockOnActive;
|
||||
|
||||
public float maxDistanceToFindTarget = 300;
|
||||
|
||||
public bool searchPointToLookComponents = true;
|
||||
|
||||
public bool lookOnlyIfTargetOnScreen;
|
||||
|
||||
public bool checkObstaclesToTarget;
|
||||
|
||||
public LayerMask layerToLook;
|
||||
|
||||
public LayerMask pointToLookComponentsLayer;
|
||||
|
||||
public bool getClosestToCameraCenter;
|
||||
|
||||
public bool useMaxDistanceToCameraCenter;
|
||||
|
||||
public float maxDistanceToCameraCenter = 200;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showCameraGizmo;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform mainCameraTransform;
|
||||
public Transform playerCameraTransform;
|
||||
public playerCamera mainPlayerCamera;
|
||||
public Camera mainCamera;
|
||||
|
||||
|
||||
public override void activateOrder (Transform character)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override Transform getCustomTarget (Transform character, Transform orderOwner)
|
||||
{
|
||||
if (sendPlayerAsTarget) {
|
||||
return orderOwner;
|
||||
}
|
||||
|
||||
if (canAIAttack (character)) {
|
||||
|
||||
if (checkIfTargetOnLockOnViewEnabled) {
|
||||
playerComponentsManager currentPlayerComponentsManager = orderOwner.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
playerCamera currentPlayerCamera = currentPlayerComponentsManager.getPlayerCamera ();
|
||||
|
||||
if (currentPlayerCamera != null) {
|
||||
if (currentPlayerCamera.isPlayerLookingAtTarget ()) {
|
||||
Transform currentTarget = currentPlayerCamera.getLastCharacterToLook ();
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (applyDamage.isCharacter (currentTarget.gameObject)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
} else {
|
||||
if (applyDamage.getCharacterFromPlaceToShoot (currentTarget)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getClosestTargetToCameraViewIfNoLockOnActive) {
|
||||
Transform currentTarget = getClosestEnemyToScreenView ();
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (applyDamage.isCharacter (currentTarget.gameObject)) {
|
||||
if (showDebugPrint) {
|
||||
print ("target located " + currentTarget.name);
|
||||
}
|
||||
|
||||
return currentTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getClosestEnemy (orderOwner);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool canAIAttack (Transform AIFriend)
|
||||
{
|
||||
bool canAttack = false;
|
||||
|
||||
findObjectivesSystem currentFindObjectivesSystem = AIFriend.GetComponentInChildren<findObjectivesSystem> ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
if (currentFindObjectivesSystem.attackType != findObjectivesSystem.AIAttackType.none) {
|
||||
canAttack = true;
|
||||
}
|
||||
}
|
||||
|
||||
return canAttack;
|
||||
}
|
||||
|
||||
public Transform getClosestEnemy (Transform centerPointTransform)
|
||||
{
|
||||
Vector3 centerPosition = centerPointTransform.position;
|
||||
|
||||
List<GameObject> fullEnemyList = new List<GameObject> ();
|
||||
|
||||
GameObject closestEnemy;
|
||||
|
||||
for (int i = 0; i < tagToLocate.Count; i++) {
|
||||
GameObject [] enemiesList = GameObject.FindGameObjectsWithTag (tagToLocate [i]);
|
||||
|
||||
fullEnemyList.AddRange (enemiesList);
|
||||
}
|
||||
|
||||
List<GameObject> closestEnemyList = new List<GameObject> ();
|
||||
|
||||
for (int j = 0; j < fullEnemyList.Count; j++) {
|
||||
if (!applyDamage.checkIfDead (fullEnemyList [j])) {
|
||||
closestEnemyList.Add (fullEnemyList [j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (closestEnemyList.Count > 0) {
|
||||
float distance = Mathf.Infinity;
|
||||
|
||||
int index = -1;
|
||||
|
||||
for (int j = 0; j < closestEnemyList.Count; j++) {
|
||||
float currentDistance = GKC_Utils.distance (closestEnemyList [j].transform.position, centerPosition);
|
||||
|
||||
if (currentDistance < distance) {
|
||||
distance = currentDistance;
|
||||
index = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != -1) {
|
||||
closestEnemy = closestEnemyList [index];
|
||||
|
||||
return closestEnemy.transform;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public Transform getClosestEnemyToScreenView ()
|
||||
{
|
||||
List<Collider> targetsListCollider = new List<Collider> ();
|
||||
|
||||
List<GameObject> targetList = new List<GameObject> ();
|
||||
List<GameObject> fullTargetList = new List<GameObject> ();
|
||||
|
||||
List<Transform> targetsListToLookTransform = new List<Transform> ();
|
||||
|
||||
int tagToLocateCount = tagToLocate.Count;
|
||||
|
||||
for (int i = 0; i < tagToLocateCount; i++) {
|
||||
GameObject [] enemiesList = GameObject.FindGameObjectsWithTag (tagToLocate [i]);
|
||||
targetList.AddRange (enemiesList);
|
||||
}
|
||||
|
||||
int targetListCount = targetList.Count;
|
||||
|
||||
for (int i = 0; i < targetListCount; i++) {
|
||||
float distance = GKC_Utils.distance (targetList [i].transform.position, playerCameraTransform.position);
|
||||
|
||||
if (distance < maxDistanceToFindTarget) {
|
||||
fullTargetList.Add (targetList [i]);
|
||||
}
|
||||
}
|
||||
|
||||
List<GameObject> pointToLookComponentList = new List<GameObject> ();
|
||||
|
||||
if (searchPointToLookComponents) {
|
||||
targetsListCollider.Clear ();
|
||||
|
||||
targetsListCollider.AddRange (Physics.OverlapSphere (playerCameraTransform.position, maxDistanceToFindTarget, pointToLookComponentsLayer));
|
||||
|
||||
int targetsListColliderCount = targetsListCollider.Count;
|
||||
|
||||
for (int i = 0; i < targetsListColliderCount; i++) {
|
||||
if (targetsListCollider [i].isTrigger) {
|
||||
pointToLook currentPointToLook = targetsListCollider [i].GetComponent<pointToLook> ();
|
||||
|
||||
if (currentPointToLook != null) {
|
||||
if (currentPointToLook.isPointToLookEnabled ()) {
|
||||
GameObject currenTargetToLook = currentPointToLook.getPointToLookTransform ().gameObject;
|
||||
|
||||
fullTargetList.Add (currenTargetToLook);
|
||||
|
||||
pointToLookComponentList.Add (currenTargetToLook);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isUsingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
|
||||
|
||||
float screenWidth = Screen.width;
|
||||
float screenHeight = Screen.height;
|
||||
|
||||
Vector3 screenPoint;
|
||||
|
||||
bool targetOnScreen;
|
||||
|
||||
int fullTargetListCount = fullTargetList.Count;
|
||||
|
||||
RaycastHit hit = new RaycastHit ();
|
||||
|
||||
for (int i = 0; i < fullTargetListCount; i++) {
|
||||
if (fullTargetList [i] != null) {
|
||||
GameObject currentTarget = fullTargetList [i];
|
||||
|
||||
if (tagToLocate.Contains (currentTarget.tag) || pointToLookComponentList.Contains (currentTarget)) {
|
||||
bool objectVisible = false;
|
||||
bool obstacleDetected = false;
|
||||
|
||||
Vector3 targetPosition = currentTarget.transform.position;
|
||||
|
||||
if (lookOnlyIfTargetOnScreen) {
|
||||
Transform currentTargetPlaceToShoot = applyDamage.getPlaceToShoot (currentTarget);
|
||||
|
||||
if (currentTargetPlaceToShoot != null) {
|
||||
targetPosition = currentTargetPlaceToShoot.position;
|
||||
}
|
||||
|
||||
if (isUsingScreenSpaceCamera) {
|
||||
screenPoint = mainCamera.WorldToViewportPoint (targetPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
|
||||
} else {
|
||||
screenPoint = mainCamera.WorldToScreenPoint (targetPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
|
||||
}
|
||||
|
||||
//the target is visible in the screen
|
||||
if (targetOnScreen) {
|
||||
objectVisible = true;
|
||||
}
|
||||
} else {
|
||||
objectVisible = true;
|
||||
}
|
||||
|
||||
if (objectVisible && checkObstaclesToTarget) {
|
||||
//for every target in front of the camera, use a raycast, if it finds an obstacle between the target and the camera, the target is removed from the list
|
||||
Vector3 temporaltargetPosition = targetPosition;
|
||||
|
||||
Transform temporalPlaceToShoot = applyDamage.getPlaceToShoot (currentTarget);
|
||||
|
||||
if (temporalPlaceToShoot != null) {
|
||||
temporaltargetPosition = temporalPlaceToShoot.position;
|
||||
}
|
||||
|
||||
Vector3 direction = temporaltargetPosition - mainCameraTransform.position;
|
||||
|
||||
direction = direction / direction.magnitude;
|
||||
|
||||
float distance = GKC_Utils.distance (temporaltargetPosition, mainCameraTransform.position);
|
||||
|
||||
if (Physics.Raycast (temporaltargetPosition, -direction, out hit, distance, layerToLook)) {
|
||||
obstacleDetected = true;
|
||||
|
||||
if (showCameraGizmo) {
|
||||
Debug.DrawLine (temporaltargetPosition, hit.point, Color.white, 4);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("obstacle detected " + hit.collider.name + " " + currentTarget.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (objectVisible && !obstacleDetected) {
|
||||
targetsListToLookTransform.Add (currentTarget.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finally, get the target closest to the player
|
||||
float minDistance = Mathf.Infinity;
|
||||
|
||||
Vector3 centerScreen = mainPlayerCamera.getScreenCenter ();
|
||||
|
||||
int targetsListToLookTransformCount = targetsListToLookTransform.Count;
|
||||
|
||||
Transform placeToShoot;
|
||||
|
||||
bool targetFound = false;
|
||||
|
||||
Transform targetToLook = null;
|
||||
|
||||
for (int i = 0; i < targetsListToLookTransformCount; i++) {
|
||||
|
||||
//find closes element to center screen
|
||||
if (getClosestToCameraCenter) {
|
||||
Vector3 targetPosition = targetsListToLookTransform [i].position;
|
||||
|
||||
placeToShoot = applyDamage.getPlaceToShoot (targetsListToLookTransform [i].gameObject);
|
||||
|
||||
if (placeToShoot != null) {
|
||||
targetPosition = placeToShoot.position;
|
||||
}
|
||||
|
||||
screenPoint = mainCamera.WorldToScreenPoint (targetPosition);
|
||||
|
||||
// print (screenPoint + " " + centerScreen);
|
||||
|
||||
float currentDistance = GKC_Utils.distance (screenPoint, centerScreen);
|
||||
|
||||
bool canBeChecked = false;
|
||||
|
||||
if (useMaxDistanceToCameraCenter) {
|
||||
if (currentDistance < maxDistanceToCameraCenter) {
|
||||
canBeChecked = true;
|
||||
}
|
||||
} else {
|
||||
canBeChecked = true;
|
||||
}
|
||||
|
||||
if (canBeChecked) {
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
targetToLook = targetsListToLookTransform [i];
|
||||
|
||||
targetFound = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
float currentDistance = GKC_Utils.distance (targetsListToLookTransform [i].position, playerCameraTransform.position);
|
||||
|
||||
if (currentDistance < minDistance) {
|
||||
minDistance = currentDistance;
|
||||
|
||||
targetToLook = targetsListToLookTransform [i];
|
||||
|
||||
targetFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetFound) {
|
||||
//check if the object to check is too far from screen center in case the look at body parts on characters is active and no body part is found or is close enough to screen center
|
||||
if (useMaxDistanceToCameraCenter && getClosestToCameraCenter) {
|
||||
placeToShoot = applyDamage.getPlaceToShoot (targetToLook.gameObject);
|
||||
|
||||
if (placeToShoot == null) {
|
||||
placeToShoot = targetToLook;
|
||||
}
|
||||
|
||||
screenPoint = mainCamera.WorldToScreenPoint (placeToShoot.position);
|
||||
|
||||
float currentDistance = GKC_Utils.distance (screenPoint, centerScreen);
|
||||
|
||||
if (currentDistance > maxDistanceToCameraCenter) {
|
||||
targetToLook = null;
|
||||
targetFound = false;
|
||||
|
||||
//print ("cancel look at target");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
if (targetFound) {
|
||||
print ("target found " + targetToLook.name);
|
||||
}
|
||||
}
|
||||
|
||||
return targetToLook;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 120cf2735a1c6fb41bbf04a8709c33c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToUseAbility.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customOrderBehaviorToWait : customOrderBehavior
|
||||
{
|
||||
public override void activateOrder (Transform character)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override Transform getCustomTarget (Transform character, Transform orderOwner)
|
||||
{
|
||||
return orderOwner;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6589a678eb5e28f4e898215801a58772
|
||||
timeCreated: 1670785082
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Custom Orders/customOrderBehaviorToWait.cs
|
||||
uploadId: 814740
|
||||
9
Assets/Game Kit Controller/Scripts/AI/Faction.meta
Normal file
9
Assets/Game Kit Controller/Scripts/AI/Faction.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 782e63fe868648a4482fd6f52e5bd18d
|
||||
folderAsset: yes
|
||||
timeCreated: 1522205529
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,363 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class characterFactionManager : MonoBehaviour
|
||||
{
|
||||
public string factionName;
|
||||
public int factionIndex;
|
||||
|
||||
public bool checkForFriendlyFactionAttackers = true;
|
||||
public bool changeFactionRelationWithFriendlyAttackers = true;
|
||||
|
||||
public List<GameObject> currentDetectedEnemyList = new List<GameObject> ();
|
||||
|
||||
public Transform characterTransform;
|
||||
|
||||
public string [] factionStringList;
|
||||
public factionSystem factionManager;
|
||||
|
||||
public bool factionManagerAssigned;
|
||||
|
||||
public bool ignoreCharacterFactionEnabled;
|
||||
|
||||
public bool removeAsTargetIfIgnoreCharacterFactionIsActivated;
|
||||
|
||||
public string mainManagerName = "Faction System";
|
||||
|
||||
|
||||
public bool useEventsOnIgnoreCharacterFactionStateChange;
|
||||
public UnityEvent eventOnIgnoreCharacterFactionEnabled;
|
||||
public UnityEvent eventOnIgnoreCharacterFactionDisabled;
|
||||
|
||||
|
||||
void Awake ()
|
||||
{
|
||||
factionManagerAssigned = false;
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
addCharacterFromFaction ();
|
||||
}
|
||||
|
||||
public void changeCharacterToFaction (string factionToChange)
|
||||
{
|
||||
factionManagerAssigned = false;
|
||||
|
||||
getFactionManager ();
|
||||
|
||||
if (factionManagerAssigned) {
|
||||
int factionListCount = factionManager.factionList.Count;
|
||||
|
||||
for (int i = 0; i < factionListCount; i++) {
|
||||
if (factionManager.factionList [i].Name.Equals (factionToChange)) {
|
||||
factionIndex = i;
|
||||
|
||||
factionName = factionToChange;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isCharacterFriendly (string characterToCheckFacionName)
|
||||
{
|
||||
if (!factionManagerAssigned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return factionManager.isCharacterFriendly (factionIndex, characterToCheckFacionName);
|
||||
}
|
||||
|
||||
public bool isCharacterEnemy (string characterToCheckFacionName)
|
||||
{
|
||||
if (!factionManagerAssigned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return factionManager.isCharacterEnemy (factionIndex, characterToCheckFacionName);
|
||||
}
|
||||
|
||||
public bool isAttackerEnemy (string characterToCheckFacionName)
|
||||
{
|
||||
if (!factionManagerAssigned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return factionManager.isAttackerEnemy (factionIndex, characterToCheckFacionName, checkForFriendlyFactionAttackers, changeFactionRelationWithFriendlyAttackers);
|
||||
}
|
||||
|
||||
public bool isCharacterNeutral (string characterToCheckFacionName)
|
||||
{
|
||||
if (!factionManagerAssigned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return factionManager.isCharacterNeutral (factionIndex, characterToCheckFacionName);
|
||||
}
|
||||
|
||||
public string getFactionName ()
|
||||
{
|
||||
return factionName;
|
||||
}
|
||||
|
||||
public bool checkIfCharacterBelongsToFaction (string factionName, GameObject character)
|
||||
{
|
||||
if (!factionManagerAssigned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return factionManager.checkIfCharacterBelongsToFaction (factionName, character);
|
||||
}
|
||||
|
||||
public void removeCharacterAsTargetOnSameFaction (GameObject characterGameObject)
|
||||
{
|
||||
if (factionManagerAssigned) {
|
||||
factionManager.removeCharacterAsTargetOnSameFaction (characterGameObject, factionIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSignalToRemoveCharacterAsTargetOnSameFaction (GameObject targetToRemove)
|
||||
{
|
||||
characterTransform.SendMessage ("sendSignalToRemoveCharacterAsTarget", targetToRemove, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
public void checkCharactersAround ()
|
||||
{
|
||||
characterTransform.SendMessage ("checkCharactersAroundAI", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
public void alertFaction (GameObject target)
|
||||
{
|
||||
characterTransform.SendMessage ("enemyAlert", target, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
public string [] getFactionStringList ()
|
||||
{
|
||||
return factionStringList;
|
||||
}
|
||||
|
||||
public void addDetectedEnemyFromFaction (GameObject enemy)
|
||||
{
|
||||
if (!currentDetectedEnemyList.Contains (enemy)) {
|
||||
currentDetectedEnemyList.Add (enemy);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDetectedEnemyFromFaction (GameObject enemy)
|
||||
{
|
||||
if (currentDetectedEnemyList.Contains (enemy)) {
|
||||
currentDetectedEnemyList.Remove (enemy);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearDetectedEnemyFromFaction ()
|
||||
{
|
||||
currentDetectedEnemyList.Clear ();
|
||||
}
|
||||
|
||||
public bool isCharacterDetectedAsEnemyByOtherFaction (GameObject characterToCheck)
|
||||
{
|
||||
if (!factionManagerAssigned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return factionManager.isCharacterDetectedAsEnemyByOtherFaction (characterToCheck);
|
||||
}
|
||||
|
||||
public void addCharacterFromFaction ()
|
||||
{
|
||||
factionManagerAssigned = false;
|
||||
|
||||
getFactionManager ();
|
||||
|
||||
if (factionManagerAssigned) {
|
||||
factionManager.addCharacterToList (this);
|
||||
}
|
||||
|
||||
if (characterTransform == null) {
|
||||
characterTransform = transform;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCharacterDeadFromFaction ()
|
||||
{
|
||||
clearDetectedEnemyFromFaction ();
|
||||
|
||||
if (factionManagerAssigned) {
|
||||
factionManager.removeCharacterToList (this);
|
||||
}
|
||||
}
|
||||
|
||||
public void alertFactionOnSpotted (float alertCloseFactionRadius, GameObject target, Vector3 alertPosition)
|
||||
{
|
||||
if (factionManagerAssigned) {
|
||||
factionManager.alertFactionOnSpotted (factionIndex, alertCloseFactionRadius, target, alertPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public Transform getCharacterTransform ()
|
||||
{
|
||||
return characterTransform;
|
||||
}
|
||||
|
||||
public void getFactionManager ()
|
||||
{
|
||||
if (!factionManagerAssigned) {
|
||||
factionManager = factionSystem.Instance;
|
||||
|
||||
factionManagerAssigned = factionManager != null;
|
||||
}
|
||||
|
||||
if (!factionManagerAssigned) {
|
||||
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (factionSystem.getMainManagerName (), typeof (factionSystem), true);
|
||||
|
||||
factionManager = factionSystem.Instance;
|
||||
|
||||
factionManagerAssigned = (factionManager != null);
|
||||
}
|
||||
|
||||
if (!factionManagerAssigned) {
|
||||
factionManager = FindObjectOfType<factionSystem> ();
|
||||
|
||||
factionManagerAssigned = factionManager != null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setNeutralRelationWithFactionByName (string otherFactionName)
|
||||
{
|
||||
changeFactionRelation (otherFactionName, factionSystem.relationInfo.relationType.neutral);
|
||||
|
||||
factionManager.removeEnemiesFromNewFriendFaction (factionIndex);
|
||||
}
|
||||
|
||||
public void setEnemyRelationWithFactionByName (string otherFactionName)
|
||||
{
|
||||
changeFactionRelation (otherFactionName, factionSystem.relationInfo.relationType.enemy);
|
||||
|
||||
factionManager.removeEnemiesFromNewFriendFaction (factionIndex);
|
||||
}
|
||||
|
||||
public void setFriendRelationWithFactionByName (string otherFactionName)
|
||||
{
|
||||
changeFactionRelation (otherFactionName, factionSystem.relationInfo.relationType.friend);
|
||||
|
||||
factionManager.removeEnemiesFromNewFriendFaction (factionIndex);
|
||||
}
|
||||
|
||||
public void changeCharacterToFactionAndCleanTargetListIngame (string factionToChange)
|
||||
{
|
||||
getFactionManager ();
|
||||
|
||||
if (factionManagerAssigned) {
|
||||
int factionListCount = factionManager.factionList.Count;
|
||||
|
||||
for (int i = 0; i < factionListCount; i++) {
|
||||
if (factionManager.factionList [i].Name.Equals (factionToChange)) {
|
||||
factionIndex = i;
|
||||
|
||||
factionName = factionToChange;
|
||||
|
||||
addCharacterFromFaction ();
|
||||
|
||||
factionManager.removeEnemiesFromCharacter (factionIndex, characterTransform);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeFactionRelation (string otherFactionName, factionSystem.relationInfo.relationType relationType)
|
||||
{
|
||||
factionManager.changeFactionRelation (factionIndex, otherFactionName, relationType);
|
||||
}
|
||||
|
||||
public bool isIgnoreCharacterFactionEnabled ()
|
||||
{
|
||||
return ignoreCharacterFactionEnabled;
|
||||
}
|
||||
|
||||
public void setIgnoreCharacterFactionEnabledState (bool state)
|
||||
{
|
||||
ignoreCharacterFactionEnabled = state;
|
||||
|
||||
if (ignoreCharacterFactionEnabled) {
|
||||
if (removeAsTargetIfIgnoreCharacterFactionIsActivated) {
|
||||
factionManager.removeCharacterAsTargetFromEnemies (factionIndex, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
checkEventsOnIgnnoreCharacterFactionStateChange (state);
|
||||
}
|
||||
|
||||
void checkEventsOnIgnnoreCharacterFactionStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnIgnoreCharacterFactionStateChange) {
|
||||
if (state) {
|
||||
eventOnIgnoreCharacterFactionEnabled.Invoke ();
|
||||
} else {
|
||||
eventOnIgnoreCharacterFactionDisabled.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isRemoveAsTargetIfIgnoreCharacterFactionIsActivated ()
|
||||
{
|
||||
return removeAsTargetIfIgnoreCharacterFactionIsActivated;
|
||||
}
|
||||
|
||||
public void toggleIngoreCharacterFactionEnabled ()
|
||||
{
|
||||
setIgnoreCharacterFactionEnabledState (!ignoreCharacterFactionEnabled);
|
||||
}
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public void getFactionListFromEditor ()
|
||||
{
|
||||
if (factionManager == null) {
|
||||
factionManager = FindObjectOfType<factionSystem> ();
|
||||
}
|
||||
|
||||
factionManagerAssigned = false;
|
||||
|
||||
getFactionList ();
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void changeCharacterToFactionFromEditor (string factionToChange)
|
||||
{
|
||||
getFactionListFromEditor ();
|
||||
|
||||
changeCharacterToFaction (factionToChange);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void getFactionList ()
|
||||
{
|
||||
getFactionManager ();
|
||||
|
||||
if (factionManager != null) {
|
||||
factionStringList = new string [factionManager.factionList.Count];
|
||||
|
||||
for (int i = 0; i < factionManager.factionList.Count; i++) {
|
||||
string name = factionManager.factionList [i].Name;
|
||||
factionStringList [i] = name;
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Character Faction", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cb832d9be70d344582b79fc178c4cb4
|
||||
timeCreated: 1520310761
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Faction/characterFactionManager.cs
|
||||
uploadId: 814740
|
||||
583
Assets/Game Kit Controller/Scripts/AI/Faction/factionSystem.cs
Normal file
583
Assets/Game Kit Controller/Scripts/AI/Faction/factionSystem.cs
Normal file
@@ -0,0 +1,583 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class factionSystem : MonoBehaviour
|
||||
{
|
||||
public List<factionInfo> factionList = new List<factionInfo> ();
|
||||
|
||||
public string [] factionStringList;
|
||||
|
||||
public List<characterFactionManager> characterFactionManagerList = new List<characterFactionManager> ();
|
||||
|
||||
|
||||
public const string mainManagerName = "Faction System";
|
||||
|
||||
public static string getMainManagerName ()
|
||||
{
|
||||
return mainManagerName;
|
||||
}
|
||||
|
||||
private static factionSystem _factionSystemInstance;
|
||||
|
||||
public static factionSystem Instance { get { return _factionSystemInstance; } }
|
||||
|
||||
bool instanceInitialized;
|
||||
|
||||
|
||||
public void getComponentInstance ()
|
||||
{
|
||||
if (instanceInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_factionSystemInstance != null && _factionSystemInstance != this) {
|
||||
Destroy (this.gameObject);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_factionSystemInstance = this;
|
||||
|
||||
instanceInitialized = true;
|
||||
}
|
||||
|
||||
void Awake ()
|
||||
{
|
||||
getComponentInstance ();
|
||||
}
|
||||
|
||||
public void addCharacterToList (characterFactionManager character)
|
||||
{
|
||||
characterFactionManagerList.Add (character);
|
||||
}
|
||||
|
||||
public void removeCharacterToList (characterFactionManager character)
|
||||
{
|
||||
characterFactionManagerList.Remove (character);
|
||||
}
|
||||
|
||||
public bool isCharacterFriendly (int ownFactionIndex, string characterToCheckFactionName)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
if (currentFactionInfo.Name.Equals (characterToCheckFactionName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int relationWithFactionsCount = currentFactionInfo.relationWithFactions.Count;
|
||||
|
||||
for (int j = 0; j < relationWithFactionsCount; j++) {
|
||||
|
||||
relationInfo currentRelationInfo = currentFactionInfo.relationWithFactions [j];
|
||||
|
||||
if (currentRelationInfo.factionName.Equals (characterToCheckFactionName)) {
|
||||
if (currentRelationInfo.relation == relationInfo.relationType.friend) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool isCharacterEnemy (int ownFactionIndex, string characterToCheckFacionName)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
if (currentFactionInfo.Name.Equals (characterToCheckFacionName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int relationWithFactionsCount = currentFactionInfo.relationWithFactions.Count;
|
||||
|
||||
for (int j = 0; j < relationWithFactionsCount; j++) {
|
||||
relationInfo currentRelationInfo = currentFactionInfo.relationWithFactions [j];
|
||||
|
||||
if (currentRelationInfo.factionName.Equals (characterToCheckFacionName)) {
|
||||
if (currentRelationInfo.relation == relationInfo.relationType.enemy) {
|
||||
|
||||
// print ("checking relation of " + currentFactionInfo + " with " + currentRelationInfo.factionName);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool isAttackerEnemy (int ownFactionIndex, string characterToCheckFacionName, bool checkForFriendlyFactionAttackers, bool changeFactionRelationWithFriendlyAttackers)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
if (currentFactionInfo.Name.Equals (characterToCheckFacionName)) {
|
||||
if (currentFactionInfo.friendlyFireTurnIntoEnemies) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int relationWithFactionsCount = currentFactionInfo.relationWithFactions.Count;
|
||||
|
||||
for (int j = 0; j < relationWithFactionsCount; j++) {
|
||||
relationInfo currentRelationInfo = currentFactionInfo.relationWithFactions [j];
|
||||
|
||||
if (currentRelationInfo.factionName.Equals (characterToCheckFacionName)) {
|
||||
if (currentRelationInfo.relation == relationInfo.relationType.enemy) {
|
||||
return true;
|
||||
} else {
|
||||
if (checkForFriendlyFactionAttackers && currentFactionInfo.turnToEnemyIfAttack) {
|
||||
if (changeFactionRelationWithFriendlyAttackers) {
|
||||
if (currentFactionInfo.turnFactionToEnemy) {
|
||||
changeFactionRelation (ownFactionIndex, characterToCheckFacionName, relationInfo.relationType.enemy);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool isCharacterNeutral (int ownFactionIndex, string characterToCheckFacionName)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
if (currentFactionInfo.Name.Equals (characterToCheckFacionName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int relationWithFactionsCount = currentFactionInfo.relationWithFactions.Count;
|
||||
|
||||
for (int j = 0; j < relationWithFactionsCount; j++) {
|
||||
relationInfo currentRelationInfo = currentFactionInfo.relationWithFactions [j];
|
||||
|
||||
if (currentRelationInfo.factionName.Equals (characterToCheckFacionName)) {
|
||||
if (currentRelationInfo.relation == relationInfo.relationType.neutral) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void changeFactionRelation (int ownFactionIndex, string otherFactionName, relationInfo.relationType relationType)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
if (!currentFactionInfo.Name.Equals (otherFactionName)) {
|
||||
int relationWithFactionsCount = currentFactionInfo.relationWithFactions.Count;
|
||||
|
||||
for (int j = 0; j < relationWithFactionsCount; j++) {
|
||||
relationInfo currentRelationInfo = currentFactionInfo.relationWithFactions [j];
|
||||
|
||||
if (currentRelationInfo.factionName.Equals (otherFactionName)) {
|
||||
currentRelationInfo.relation = relationType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int characterFactionManagerListCount = characterFactionManagerList.Count;
|
||||
|
||||
for (int i = 0; i < characterFactionManagerListCount; i++) {
|
||||
characterFactionManager currentCharacterFactionManager = characterFactionManagerList [i];
|
||||
|
||||
if (currentCharacterFactionManager.factionName.Equals (currentFactionInfo.Name)) {
|
||||
currentCharacterFactionManager.checkCharactersAround ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEnemiesFromNewFriendFaction (int ownFactionIndex)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
int characterFactionManagerListCount = characterFactionManagerList.Count;
|
||||
|
||||
for (int i = 0; i < characterFactionManagerListCount; i++) {
|
||||
characterFactionManager currentCharacterFactionManager = characterFactionManagerList [i];
|
||||
|
||||
if (currentCharacterFactionManager.factionName.Equals (currentFactionInfo.Name)) {
|
||||
|
||||
GKC_Utils.removeEnemiesFromNewFriendFaction (currentCharacterFactionManager.characterTransform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEnemiesFromCharacter (int ownFactionIndex, Transform characterTransform)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
int characterFactionManagerListCount = characterFactionManagerList.Count;
|
||||
|
||||
for (int i = 0; i < characterFactionManagerListCount; i++) {
|
||||
characterFactionManager currentCharacterFactionManager = characterFactionManagerList [i];
|
||||
|
||||
if (currentCharacterFactionManager.factionName.Equals (currentFactionInfo.Name) && characterTransform == currentCharacterFactionManager.characterTransform) {
|
||||
|
||||
GKC_Utils.removeEnemiesFromNewFriendFaction (currentCharacterFactionManager.characterTransform);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCharacterAsTargetFromEnemies (int ownFactionIndex, GameObject characterToRemove)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
string factionNameToCheck = currentFactionInfo.Name;
|
||||
|
||||
int characterFactionManagerListCount = characterFactionManagerList.Count;
|
||||
|
||||
for (int i = 0; i < characterFactionManagerListCount; i++) {
|
||||
characterFactionManager currentCharacterFactionManager = characterFactionManagerList [i];
|
||||
|
||||
bool characterEnemyOfCharacterToRemove = isCharacterEnemy (currentCharacterFactionManager.factionIndex, factionNameToCheck);
|
||||
|
||||
if (characterEnemyOfCharacterToRemove) {
|
||||
|
||||
//print (currentCharacterFactionManager.characterTransform.gameObject.name + " is enemy of " + characterToRemove.name);
|
||||
|
||||
GKC_Utils.removeTargetFromAICharacter (characterToRemove, currentCharacterFactionManager.characterTransform.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool checkIfCharacterBelongsToFaction (string factionName, GameObject character)
|
||||
{
|
||||
if (character == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
characterFactionManager characterFactionToCheck = character.GetComponent<characterFactionManager> ();
|
||||
|
||||
if (characterFactionToCheck != null) {
|
||||
if (characterFactionToCheck.factionName.Equals (factionName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool isCharacterDetectedAsEnemyByOtherFaction (GameObject characterToCheck)
|
||||
{
|
||||
int characterFactionManagerListCount = characterFactionManagerList.Count;
|
||||
|
||||
for (int i = 0; i < characterFactionManagerListCount; i++) {
|
||||
if (characterFactionManagerList [i].currentDetectedEnemyList.Contains (characterToCheck)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void alertFactionOnSpotted (int ownFactionIndex, float alertCloseFactionRadius, GameObject target, Vector3 alertPosition)
|
||||
{
|
||||
string factionNameToCheck = factionList [ownFactionIndex].Name;
|
||||
|
||||
// print (factionNameToCheck);
|
||||
|
||||
int characterFactionManagerListCount = characterFactionManagerList.Count;
|
||||
|
||||
for (int i = 0; i < characterFactionManagerListCount; i++) {
|
||||
characterFactionManager currentCharacterFactionManager = characterFactionManagerList [i];
|
||||
|
||||
if (currentCharacterFactionManager.factionName.Equals (factionNameToCheck)) {
|
||||
float distance = GKC_Utils.distance (currentCharacterFactionManager.getCharacterTransform ().position, alertPosition);
|
||||
|
||||
// print ("distance to target " + characterFactionManagerList [i].getCharacterTransform ().name + " " + distance);
|
||||
|
||||
if (distance <= alertCloseFactionRadius) {
|
||||
currentCharacterFactionManager.alertFaction (target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCharacterAsTargetOnSameFaction (GameObject characterToCheck, int ownFactionIndex)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [ownFactionIndex];
|
||||
|
||||
string factionNameToCheck = currentFactionInfo.Name;
|
||||
|
||||
int characterFactionManagerListCount = characterFactionManagerList.Count;
|
||||
|
||||
// print ("faction to remove " + factionNameToCheck + " character to remove " + characterToCheck.name);
|
||||
|
||||
for (int i = 0; i < characterFactionManagerListCount; i++) {
|
||||
characterFactionManager currentCharacterFactionManager = characterFactionManagerList [i];
|
||||
|
||||
bool characterEnemyOfNewFaction = isCharacterEnemy (currentCharacterFactionManager.factionIndex, factionNameToCheck);
|
||||
|
||||
// print (characterEnemyOfNewFaction);
|
||||
|
||||
if (currentCharacterFactionManager.factionName.Equals (factionNameToCheck) || !characterEnemyOfNewFaction) {
|
||||
currentCharacterFactionManager.sendSignalToRemoveCharacterAsTargetOnSameFaction (characterToCheck);
|
||||
|
||||
// print ("remove enemy turned into friend or neutral from " + currentCharacterFactionManager.gameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public void addFaction ()
|
||||
{
|
||||
factionInfo newFactionInfo = new factionInfo ();
|
||||
newFactionInfo.Name = "New Faction";
|
||||
factionList.Add (newFactionInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void removeFaction (int factionIndexToRemove)
|
||||
{
|
||||
// print ("Removing " + factionList [factionIndexToRemove].Name + " faction");
|
||||
|
||||
factionList.RemoveAt (factionIndexToRemove);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void updateFactionsList ()
|
||||
{
|
||||
int previousFactionAmount = factionStringList.Length;
|
||||
|
||||
getFactionStringList ();
|
||||
|
||||
int newFactionAmount = factionStringList.Length;
|
||||
|
||||
if (previousFactionAmount > newFactionAmount) {
|
||||
print (previousFactionAmount - newFactionAmount + " factions were removed");
|
||||
} else if (previousFactionAmount < newFactionAmount) {
|
||||
print (newFactionAmount - previousFactionAmount + " factions were added");
|
||||
} else {
|
||||
print ("No factions were added or removed");
|
||||
}
|
||||
|
||||
if (factionList.Count > 1) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
|
||||
print ("Checking for factions removed");
|
||||
|
||||
for (i = 0; i < factionStringList.Length; i++) {
|
||||
if (checkIfFactionExists (factionStringList [i])) {
|
||||
|
||||
} else {
|
||||
print ("faction " + factionStringList [i] + " was removed, removing relation with " + factionList [i].Name);
|
||||
|
||||
for (j = 0; j < factionList.Count; j++) {
|
||||
for (k = factionList [j].relationWithFactions.Count - 1; k >= 0; k--) {
|
||||
if (factionList [j].relationWithFactions [k].factionName.Equals (factionStringList [i])) {
|
||||
factionList [j].relationWithFactions.RemoveAt (k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < factionList.Count; i++) {
|
||||
for (j = factionList [i].relationWithFactions.Count - 1; j >= 0; j--) {
|
||||
if (!checkIfFactionExistsInStringList (factionList [i].relationWithFactions [j].factionName)) {
|
||||
print ("faction " + factionList [i].relationWithFactions [j].factionName + " was removed, removing relation with " + factionList [i].Name);
|
||||
|
||||
factionList [i].relationWithFactions.RemoveAt (j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print ("Updating factions relations index");
|
||||
|
||||
for (i = 0; i < factionList.Count; i++) {
|
||||
for (j = 0; j < factionList [i].relationWithFactions.Count; j++) {
|
||||
int factionIndex = getFactionIndex (factionList [i].relationWithFactions [j].factionName);
|
||||
|
||||
if (factionIndex > -1) {
|
||||
if (factionList [i].relationWithFactions [j].factionIndex > factionIndex) {
|
||||
print ("Updating faction " + factionList [i].Name + " relation index on faction " +
|
||||
factionList [i].relationWithFactions [j].factionName + " with index " + factionIndex);
|
||||
|
||||
factionList [i].relationWithFactions [j].factionIndex = factionIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print ("Updating relations with new factions added");
|
||||
|
||||
for (i = 0; i < factionList.Count; i++) {
|
||||
for (j = 0; j < factionList.Count; j++) {
|
||||
if (!factionList [i].Name.Equals (factionList [j].Name)) {
|
||||
|
||||
bool containsRelation = factionContainsRelation (i, factionStringList [j]);
|
||||
|
||||
if (!containsRelation) {
|
||||
print ("New relation to configure on " + factionList [i].Name + " and " + factionStringList [j] + " has been added");
|
||||
|
||||
relationInfo newRelationInfo = new relationInfo ();
|
||||
newRelationInfo.factionName = factionStringList [j];
|
||||
newRelationInfo.factionIndex = j;
|
||||
factionList [i].relationWithFactions.Add (newRelationInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public int getFactionIndex (string factionName)
|
||||
{
|
||||
int factionListCount = factionList.Count;
|
||||
|
||||
for (int i = 0; i < factionListCount; i++) {
|
||||
if (factionList [i].Name.Equals (factionName)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool checkIfFactionExists (string factionName)
|
||||
{
|
||||
int factionListCount = factionList.Count;
|
||||
|
||||
for (int i = 0; i < factionListCount; i++) {
|
||||
if (factionList [i].Name.Equals (factionName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool checkIfFactionExistsInStringList (string factionName)
|
||||
{
|
||||
int factionStringListLength = factionStringList.Length;
|
||||
|
||||
for (int i = 0; i < factionStringListLength; i++) {
|
||||
if (factionStringList [i].Equals (factionName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool factionContainsRelation (int factionIndex, string factionWithRelation)
|
||||
{
|
||||
factionInfo currentFactionInfo = factionList [factionIndex];
|
||||
|
||||
if (currentFactionInfo.Name.Equals (factionWithRelation)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int relationWithFactionsCount = currentFactionInfo.relationWithFactions.Count;
|
||||
|
||||
for (int j = 0; j < relationWithFactionsCount; j++) {
|
||||
if (currentFactionInfo.relationWithFactions [j].factionName.Equals (factionWithRelation)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setAllRelationsAsFriendOrEnemyOnFaction (int factionIndex, int relationTypeIndex)
|
||||
{
|
||||
if (factionIndex >= factionList.Count) {
|
||||
return;
|
||||
}
|
||||
|
||||
factionInfo currentFactionInfo = factionList [factionIndex];
|
||||
|
||||
int relationWithFactionsCount = currentFactionInfo.relationWithFactions.Count;
|
||||
|
||||
for (int j = 0; j < relationWithFactionsCount; j++) {
|
||||
|
||||
if (relationTypeIndex == 0) {
|
||||
currentFactionInfo.relationWithFactions [j].relation = relationInfo.relationType.friend;
|
||||
}
|
||||
|
||||
if (relationTypeIndex == 1) {
|
||||
currentFactionInfo.relationWithFactions [j].relation = relationInfo.relationType.enemy;
|
||||
}
|
||||
|
||||
if (relationTypeIndex == 2) {
|
||||
currentFactionInfo.relationWithFactions [j].relation = relationInfo.relationType.neutral;
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
public void getFactionStringList ()
|
||||
{
|
||||
factionStringList = new string [factionList.Count];
|
||||
|
||||
for (int i = 0; i < factionList.Count; i++) {
|
||||
string newFactionName = factionList [i].Name;
|
||||
|
||||
factionStringList [i] = newFactionName;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFactionListNames ()
|
||||
{
|
||||
getFactionStringList ();
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Faction System values", gameObject);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class factionInfo
|
||||
{
|
||||
public string Name;
|
||||
public bool turnToEnemyIfAttack;
|
||||
public bool turnFactionToEnemy;
|
||||
public bool friendlyFireTurnIntoEnemies;
|
||||
public List<relationInfo> relationWithFactions = new List<relationInfo> ();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class relationInfo
|
||||
{
|
||||
public string factionName;
|
||||
public int factionIndex;
|
||||
public relationType relation;
|
||||
|
||||
public enum relationType
|
||||
{
|
||||
friend,
|
||||
enemy,
|
||||
neutral
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a2ab348b0b0cec4d8dd236ced5dbc81
|
||||
timeCreated: 1520304216
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Faction/factionSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d818c18aac007b54ebbcab3bfdee3bcc
|
||||
folderAsset: yes
|
||||
timeCreated: 1602570751
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfc098350b4067c40ab7646930b82122
|
||||
timeCreated: 1600342806
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Melee Combat System/AIMeleeCombatSystemBrain.cs
|
||||
uploadId: 814740
|
||||
9
Assets/Game Kit Controller/Scripts/AI/Turret.meta
Normal file
9
Assets/Game Kit Controller/Scripts/AI/Turret.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8041ee3844b63f479287076cfe03ea3
|
||||
folderAsset: yes
|
||||
timeCreated: 1457060185
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
861
Assets/Game Kit Controller/Scripts/AI/Turret/AITurret.cs
Normal file
861
Assets/Game Kit Controller/Scripts/AI/Turret/AITurret.cs
Normal file
@@ -0,0 +1,861 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AITurret : MonoBehaviour
|
||||
{
|
||||
[Header ("Turret Settings")]
|
||||
[Space]
|
||||
|
||||
public LayerMask layer;
|
||||
|
||||
public float rotationSpeed = 10;
|
||||
|
||||
[Space]
|
||||
|
||||
public float inputRotationSpeed = 5;
|
||||
|
||||
public Vector2 rangeAngleX;
|
||||
public float overrideRotationSpeed = 10;
|
||||
|
||||
public float raycastPositionRotationSpeed = 10;
|
||||
|
||||
[Space]
|
||||
[Header ("Sound Settings")]
|
||||
[Space]
|
||||
|
||||
public AudioClip locatedEnemy;
|
||||
public AudioElement locatedEnemyAudioElement;
|
||||
|
||||
[Space]
|
||||
[Header ("Weapons Settings")]
|
||||
[Space]
|
||||
|
||||
public string defaultWeaponActiveName;
|
||||
|
||||
public bool randomWeaponAtStart;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useGeneralLayerToDamage;
|
||||
public LayerMask layerToDamage;
|
||||
|
||||
[Space]
|
||||
|
||||
public List<turretWeaponInfo> turretWeaponInfoList = new List<turretWeaponInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool dead;
|
||||
public bool shootingWeapons;
|
||||
public bool weaponsActive;
|
||||
|
||||
public Transform currentCameraTransformDirection;
|
||||
|
||||
public string currentWeaponName;
|
||||
|
||||
public int currentWeaponIndex;
|
||||
|
||||
[Space]
|
||||
[Header ("Override Elements")]
|
||||
[Space]
|
||||
|
||||
public bool controlOverriden;
|
||||
|
||||
public bool useCustomInputCameraDirection;
|
||||
|
||||
public Transform overridePositionToLook;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public Shader transparent;
|
||||
public LayerMask layerForGravity;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool fadePiecesOnDeath = true;
|
||||
|
||||
public float fadePiecesSpeed = 5;
|
||||
|
||||
public float destroyPiecesWaitTime = 10;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool addForceToTurretPiecesOnDeath = true;
|
||||
|
||||
public float forceAmountToPieces = 500;
|
||||
|
||||
public float radiusAmountToPieces = 50;
|
||||
|
||||
[Space]
|
||||
[Header ("Turret Elements")]
|
||||
[Space]
|
||||
|
||||
public GameObject rayCastPosition;
|
||||
|
||||
public GameObject rotatingBase;
|
||||
public GameObject head;
|
||||
|
||||
public manageAITarget targetManager;
|
||||
public Rigidbody mainRigidbody;
|
||||
|
||||
public AudioSource audioSource;
|
||||
public overrideInputManager overrideInput;
|
||||
|
||||
public GameObject turretAttacker;
|
||||
|
||||
|
||||
Quaternion currentRaycastPositionRotation;
|
||||
|
||||
Vector2 currentLookAngle;
|
||||
Vector2 axisValues;
|
||||
float horizontalInput;
|
||||
float verticalInput;
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
|
||||
List<Renderer> rendererParts = new List<Renderer> ();
|
||||
|
||||
bool kinematicActive;
|
||||
float timer;
|
||||
float shootTimerLimit;
|
||||
|
||||
float orignalRotationSpeed;
|
||||
float speedMultiplier = 1;
|
||||
|
||||
GameObject currentEnemyToShoot;
|
||||
|
||||
float currentRotationSpeed;
|
||||
|
||||
float lastTimeWeaponsActivated;
|
||||
|
||||
string untaggedName = "Untagged";
|
||||
|
||||
Coroutine disableOverrideCoroutine;
|
||||
|
||||
turretWeaponInfo currentTurretWeaponInfo;
|
||||
|
||||
bool weaponInfoAssigned;
|
||||
|
||||
float lastTimeTurretDestroyed;
|
||||
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (locatedEnemy != null) {
|
||||
locatedEnemyAudioElement.clip = locatedEnemy;
|
||||
}
|
||||
|
||||
if (audioSource != null) {
|
||||
locatedEnemyAudioElement.audioSource = audioSource;
|
||||
}
|
||||
|
||||
currentWeaponName = defaultWeaponActiveName;
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (turretAttacker == null) {
|
||||
turretAttacker = gameObject;
|
||||
}
|
||||
|
||||
currentRotationSpeed = rotationSpeed;
|
||||
orignalRotationSpeed = rotationSpeed;
|
||||
|
||||
if (randomWeaponAtStart) {
|
||||
int randomIndex = Random.Range (0, turretWeaponInfoList.Count);
|
||||
|
||||
currentWeaponName = turretWeaponInfoList [randomIndex].Name;
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (dead) {
|
||||
if (fadePiecesOnDeath) {
|
||||
//if the turrets is destroyed, set it to transparent smoothly to disable it from the scene
|
||||
int rendererPartsCount = rendererParts.Count;
|
||||
|
||||
int piecesFadedCounter = 0;
|
||||
|
||||
for (int i = 0; i < rendererPartsCount; i++) {
|
||||
|
||||
Color alpha = rendererParts [i].material.color;
|
||||
|
||||
alpha.a -= Time.deltaTime / fadePiecesSpeed;
|
||||
|
||||
rendererParts [i].material.color = alpha;
|
||||
|
||||
if (alpha.a <= 0) {
|
||||
piecesFadedCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
if (piecesFadedCounter >= rendererPartsCount) {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (destroyPiecesWaitTime > 0) {
|
||||
if (Time.time > destroyPiecesWaitTime + lastTimeTurretDestroyed) {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the turret is not destroyed, or being hacked, or paused by a black hole, then
|
||||
if (!dead && !targetManager.paused) {
|
||||
if (targetManager.onSpotted) {
|
||||
lootAtTurretTarget (targetManager.placeToShoot);
|
||||
|
||||
shootWeapon (targetManager.enemyToShoot, targetManager.placeToShoot, true);
|
||||
|
||||
}
|
||||
//if there are no enemies in the field of view, rotate in Y local axis to check new targets
|
||||
else if (!targetManager.checkingThreat) {
|
||||
rotatingBase.transform.Rotate (0, currentRotationSpeed * Time.deltaTime * 3, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//if the turret has been hacked, the player can grab it, so when he drops it, the turret will be set in the first surface that will touch
|
||||
//also checking if the gravity of the turret has been modified
|
||||
if (tag.Equals (untaggedName)) {
|
||||
if (!mainRigidbody.isKinematic && !mainRigidbody.freezeRotation) {
|
||||
mainRigidbody.freezeRotation = true;
|
||||
|
||||
StartCoroutine (rotateElement (gameObject));
|
||||
}
|
||||
} else {
|
||||
if (mainRigidbody.freezeRotation) {
|
||||
mainRigidbody.freezeRotation = false;
|
||||
kinematicActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
//when the kinematicActive has been enabled, the turret has a regular gravity again, so the first ground surface that will find, will be its new ground
|
||||
//enabling the kinematic rigidbody of the turret
|
||||
if (kinematicActive) {
|
||||
if (Physics.Raycast (transform.position, -Vector3.up, out hit, 1.2f, layerForGravity)) {
|
||||
if (!mainRigidbody.isKinematic && kinematicActive && !GetComponent<artificialObjectGravity> () && !hit.collider.isTrigger) {
|
||||
StartCoroutine (rotateToSurface (hit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (controlOverriden) {
|
||||
|
||||
if (shootingWeapons) {
|
||||
if (Physics.Raycast (rayCastPosition.transform.position, rayCastPosition.transform.forward, out hit, Mathf.Infinity, layer)) {
|
||||
currentEnemyToShoot = hit.collider.gameObject;
|
||||
} else {
|
||||
currentEnemyToShoot = null;
|
||||
}
|
||||
|
||||
shootWeapon (currentEnemyToShoot, overridePositionToLook.transform, false);
|
||||
}
|
||||
|
||||
if (useCustomInputCameraDirection) {
|
||||
currentRaycastPositionRotation = Quaternion.LookRotation (currentCameraTransformDirection.forward);
|
||||
} else {
|
||||
axisValues = overrideInput.getCustomMovementAxis ();
|
||||
horizontalInput = axisValues.x;
|
||||
verticalInput = axisValues.y;
|
||||
|
||||
currentLookAngle.x += horizontalInput * inputRotationSpeed;
|
||||
currentLookAngle.y -= verticalInput * inputRotationSpeed;
|
||||
|
||||
currentLookAngle.y = Mathf.Clamp (currentLookAngle.y, rangeAngleX.x, rangeAngleX.y);
|
||||
|
||||
currentRaycastPositionRotation = Quaternion.Euler (0, currentLookAngle.x, 0);
|
||||
|
||||
currentRaycastPositionRotation *= Quaternion.Euler (currentLookAngle.y, 0, 0);
|
||||
}
|
||||
|
||||
rayCastPosition.transform.rotation = Quaternion.Slerp (rayCastPosition.transform.rotation, currentRaycastPositionRotation, Time.deltaTime * raycastPositionRotationSpeed);
|
||||
|
||||
lootAtTurretTarget (overridePositionToLook);
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseNextWeapon ()
|
||||
{
|
||||
currentWeaponIndex++;
|
||||
|
||||
if (currentWeaponIndex >= turretWeaponInfoList.Count - 1) {
|
||||
currentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
setWeapon (currentWeaponIndex);
|
||||
|
||||
activateWeapon ();
|
||||
}
|
||||
|
||||
public void choosePreviousWeapon ()
|
||||
{
|
||||
currentWeaponIndex--;
|
||||
|
||||
if (currentWeaponIndex < 0) {
|
||||
currentWeaponIndex = turretWeaponInfoList.Count - 1;
|
||||
}
|
||||
|
||||
setWeapon (currentWeaponIndex);
|
||||
|
||||
activateWeapon ();
|
||||
}
|
||||
|
||||
public void enableOrDisableWeapons (bool state)
|
||||
{
|
||||
weaponsActive = state;
|
||||
|
||||
if (weaponsActive) {
|
||||
activateWeapon ();
|
||||
} else {
|
||||
deactivateWeapon ();
|
||||
}
|
||||
}
|
||||
|
||||
void cancelCheckSuspectTurret ()
|
||||
{
|
||||
setOnSpottedState (false);
|
||||
}
|
||||
|
||||
public void setOnSpottedState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
activateWeapon ();
|
||||
} else {
|
||||
StartCoroutine (rotateElement (head));
|
||||
|
||||
deactivateWeapon ();
|
||||
}
|
||||
}
|
||||
|
||||
//active the fire mode
|
||||
void shootWeapon (GameObject enemyToShoot, Transform placeToShoot, bool checkTargetOnRaycast)
|
||||
{
|
||||
//if the current weapon is the machine gun or the cannon, check with a ray if the player is in front of the turret
|
||||
//if the cannon is selected, the time to shoot is 1 second, the machine gun shoots every 0.1 seconds
|
||||
bool canCheckRaycastResult = true;
|
||||
|
||||
if (weaponInfoAssigned) {
|
||||
if (currentTurretWeaponInfo.useWaitTimeToStartShootAfterActivation) {
|
||||
if (Time.time < currentTurretWeaponInfo.waitTimeToStartShootAfterActivation + lastTimeWeaponsActivated) {
|
||||
canCheckRaycastResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canCheckRaycastResult) {
|
||||
if (checkTargetOnRaycast) {
|
||||
if (Physics.Raycast (rayCastPosition.transform.position, rayCastPosition.transform.forward, out hit, Mathf.Infinity, layer)) {
|
||||
Debug.DrawLine (rayCastPosition.transform.position, hit.point, Color.red, 200, true);
|
||||
|
||||
if (hit.collider.gameObject == enemyToShoot || hit.collider.gameObject.transform.IsChildOf (enemyToShoot.transform)) {
|
||||
timer += Time.deltaTime * speedMultiplier;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
timer += Time.deltaTime * speedMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponInfoAssigned) {
|
||||
if (currentTurretWeaponInfo.weaponLookAtTarget) {
|
||||
Vector3 targetDir = placeToShoot.position - currentTurretWeaponInfo.weaponLookAtTargetTransform.position;
|
||||
|
||||
Quaternion qTo = Quaternion.LookRotation (targetDir);
|
||||
|
||||
currentTurretWeaponInfo.weaponLookAtTargetTransform.rotation =
|
||||
Quaternion.Slerp (currentTurretWeaponInfo.weaponLookAtTargetTransform.rotation, qTo, currentRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
//if the timer ends, shoot
|
||||
if (timer >= shootTimerLimit) {
|
||||
timer = 0;
|
||||
|
||||
//if (controlOverriden) {
|
||||
// if (currentCameraTransformDirection != null) {
|
||||
// bool surfaceFound = false;
|
||||
|
||||
// Vector3 raycastDirection = currentCameraTransformDirection.forward;
|
||||
|
||||
// if (Physics.Raycast (currentCameraTransformDirection.position, raycastDirection, out hit, Mathf.Infinity, layer)) {
|
||||
|
||||
// if (hit.collider.gameObject != turretAttacker) {
|
||||
// surfaceFound = true;
|
||||
// } else {
|
||||
// Vector3 raycastPosition = hit.point + 0.2f * raycastDirection;
|
||||
|
||||
// if (Physics.Raycast (raycastPosition, raycastDirection, out hit, Mathf.Infinity, layer)) {
|
||||
// surfaceFound = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (surfaceFound) {
|
||||
// newProjectileGameObject.transform.LookAt (hit.point);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
if (currentTurretWeaponInfo.useAnimationOnWeapon) {
|
||||
currentTurretWeaponInfo.animationOnWeapon.Play (currentTurretWeaponInfo.weaponAnimationName);
|
||||
}
|
||||
|
||||
if (currentTurretWeaponInfo.useSimpleWeaponSystem) {
|
||||
currentTurretWeaponInfo.mainSimpleWeaponSystem.shootWeapon (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//follow the enemy position, to rotate torwards his direction
|
||||
void lootAtTurretTarget (Transform objective)
|
||||
{
|
||||
if (objective != null) {
|
||||
//there are two parts in the turret that move, the head and the middle body
|
||||
Vector3 targetDir = objective.position - rotatingBase.transform.position;
|
||||
|
||||
targetDir = targetDir - transform.InverseTransformDirection (targetDir).y * transform.up;
|
||||
|
||||
targetDir = targetDir.normalized;
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation (targetDir, transform.up);
|
||||
|
||||
rotatingBase.transform.rotation = Quaternion.Slerp (rotatingBase.transform.rotation, targetRotation, currentRotationSpeed * Time.deltaTime);
|
||||
|
||||
Vector3 targetDir2 = objective.position - head.transform.position;
|
||||
|
||||
Quaternion targetRotation2 = Quaternion.LookRotation (targetDir2, transform.up);
|
||||
|
||||
head.transform.rotation = Quaternion.Slerp (head.transform.rotation, targetRotation2, currentRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
//the gravity of the turret is regular again
|
||||
void dropCharacter (bool state)
|
||||
{
|
||||
kinematicActive = state;
|
||||
}
|
||||
|
||||
//when the turret detects a ground surface, will rotate according to the surface normal
|
||||
IEnumerator rotateToSurface (RaycastHit hit)
|
||||
{
|
||||
//it works like the player gravity
|
||||
kinematicActive = false;
|
||||
|
||||
mainRigidbody.useGravity = true;
|
||||
mainRigidbody.isKinematic = true;
|
||||
|
||||
Quaternion rot = transform.rotation;
|
||||
Vector3 myForward = Vector3.Cross (transform.right, hit.normal);
|
||||
Quaternion dstRot = Quaternion.LookRotation (myForward, hit.normal);
|
||||
Vector3 pos = hit.point;
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3;
|
||||
|
||||
transform.rotation = Quaternion.Slerp (rot, dstRot, t);
|
||||
//set also the position of the turret to the hit point
|
||||
|
||||
transform.position = Vector3.MoveTowards (transform.position, pos + 0.5f * transform.up, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
gameObject.layer = 0;
|
||||
}
|
||||
|
||||
//return the head of the turret to its original rotation
|
||||
IEnumerator rotateElement (GameObject element)
|
||||
{
|
||||
Quaternion rot = element.transform.localRotation;
|
||||
|
||||
Vector3 myForward = Vector3.Cross (element.transform.right, Vector3.up);
|
||||
Quaternion dstRot = Quaternion.LookRotation (myForward, Vector3.up);
|
||||
|
||||
dstRot.y = 0;
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3 * speedMultiplier;
|
||||
|
||||
element.transform.localRotation = Quaternion.Slerp (rot, dstRot, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
//if one enemy or more are inside of the turret's trigger, activate the weapon selected in the inspector: machine gun, laser or cannon
|
||||
void activateWeapon ()
|
||||
{
|
||||
if (locatedEnemyAudioElement != null) {
|
||||
AudioPlayer.PlayOneShot (locatedEnemyAudioElement, gameObject, Random.Range (0.8f, 1.2f));
|
||||
}
|
||||
|
||||
setCurrentTurretWeapon (currentWeaponName);
|
||||
|
||||
lastTimeWeaponsActivated = Time.time;
|
||||
}
|
||||
|
||||
//if all the enemies in the trigger of the turret are gone, deactivate the weapons
|
||||
void deactivateWeapon ()
|
||||
{
|
||||
deactivateCurrentWeapon ();
|
||||
}
|
||||
|
||||
//the turret is destroyed, so disable all the triggers, the AI, and add a rigidbody to every object with a render, and add force to them
|
||||
public void setDeathState ()
|
||||
{
|
||||
deactivateWeapon ();
|
||||
|
||||
dead = true;
|
||||
|
||||
lastTimeTurretDestroyed = Time.time;
|
||||
|
||||
Component [] components = GetComponentsInChildren (typeof (Transform));
|
||||
|
||||
int layerToIgnoreIndex = LayerMask.NameToLayer ("Scanner");
|
||||
|
||||
int ignoreRaycastLayerIndex = LayerMask.NameToLayer ("Ignore Raycast");
|
||||
|
||||
foreach (Component c in components) {
|
||||
Renderer currentRenderer = c.GetComponent<Renderer> ();
|
||||
|
||||
if (currentRenderer != null && c.gameObject.layer != layerToIgnoreIndex) {
|
||||
if (fadePiecesOnDeath) {
|
||||
rendererParts.Add (currentRenderer);
|
||||
|
||||
currentRenderer.material.shader = transparent;
|
||||
}
|
||||
|
||||
c.transform.SetParent (transform);
|
||||
|
||||
c.gameObject.layer = ignoreRaycastLayerIndex;
|
||||
|
||||
Rigidbody currentRigidbody = c.gameObject.GetComponent<Rigidbody> ();
|
||||
|
||||
if (currentRigidbody == null) {
|
||||
currentRigidbody = c.gameObject.AddComponent<Rigidbody> ();
|
||||
}
|
||||
|
||||
Collider currentCollider = c.gameObject.GetComponent<Collider> ();
|
||||
|
||||
if (currentCollider == null) {
|
||||
c.gameObject.AddComponent<BoxCollider> ();
|
||||
}
|
||||
|
||||
if (addForceToTurretPiecesOnDeath) {
|
||||
currentRigidbody.AddExplosionForce (forceAmountToPieces, transform.position + transform.up, radiusAmountToPieces, 3);
|
||||
}
|
||||
} else {
|
||||
Collider currentCollider = c.gameObject.GetComponent<Collider> ();
|
||||
|
||||
if (currentCollider != null) {
|
||||
currentCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the player uses the power of slow down, reduces the rotation speed of the turret, the rate fire and the projectile velocity
|
||||
void setReducedVelocity (float speedMultiplierValue)
|
||||
{
|
||||
currentRotationSpeed = speedMultiplierValue;
|
||||
|
||||
speedMultiplier = speedMultiplierValue;
|
||||
}
|
||||
|
||||
//set the turret speed to its normal state
|
||||
void setNormalVelocity ()
|
||||
{
|
||||
currentRotationSpeed = orignalRotationSpeed;
|
||||
|
||||
speedMultiplier = 1;
|
||||
}
|
||||
|
||||
public void setRandomWeapon ()
|
||||
{
|
||||
int random = Random.Range (0, turretWeaponInfoList.Count);
|
||||
|
||||
setWeapon (random);
|
||||
}
|
||||
|
||||
public void setWeapon (int weaponNumber)
|
||||
{
|
||||
setCurrentTurretWeapon (turretWeaponInfoList [weaponNumber].Name);
|
||||
}
|
||||
|
||||
public void startOverride ()
|
||||
{
|
||||
overrideTurretControlState (true);
|
||||
}
|
||||
|
||||
public void stopOverride ()
|
||||
{
|
||||
overrideTurretControlState (false);
|
||||
}
|
||||
|
||||
public void overrideTurretControlState (bool state)
|
||||
{
|
||||
if (controlOverriden == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
currentLookAngle = new Vector2 (rayCastPosition.transform.eulerAngles.y, rayCastPosition.transform.eulerAngles.x);
|
||||
} else {
|
||||
currentLookAngle = Vector2.zero;
|
||||
axisValues = Vector2.zero;
|
||||
shootingWeapons = false;
|
||||
}
|
||||
|
||||
controlOverriden = state;
|
||||
|
||||
targetManager.pauseAI (controlOverriden);
|
||||
|
||||
if (controlOverriden) {
|
||||
currentRotationSpeed = overrideRotationSpeed;
|
||||
} else {
|
||||
currentRotationSpeed = orignalRotationSpeed;
|
||||
|
||||
StartCoroutine (rotateElement (head));
|
||||
|
||||
deactivateWeapon ();
|
||||
}
|
||||
|
||||
stopDisableOverrideAfterDelayCoroutine ();
|
||||
|
||||
for (int i = 0; i < turretWeaponInfoList.Count; i++) {
|
||||
if (turretWeaponInfoList [i].useSimpleWeaponSystem) {
|
||||
if (controlOverriden) {
|
||||
turretWeaponInfoList [i].mainSimpleWeaponSystem.setCustommainCameraTransform (currentCameraTransformDirection);
|
||||
} else {
|
||||
turretWeaponInfoList [i].mainSimpleWeaponSystem.setCustommainCameraTransform (null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableOverrideAfterDelay (float delayDuration)
|
||||
{
|
||||
if (gameObject.activeSelf) {
|
||||
stopDisableOverrideAfterDelayCoroutine ();
|
||||
|
||||
disableOverrideCoroutine = StartCoroutine (updatedDisableOverrideAfterDelayCoroutine (delayDuration));
|
||||
}
|
||||
}
|
||||
|
||||
public void stopDisableOverrideAfterDelayCoroutine ()
|
||||
{
|
||||
if (disableOverrideCoroutine != null) {
|
||||
StopCoroutine (disableOverrideCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updatedDisableOverrideAfterDelayCoroutine (float delayDuration)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime (delayDuration);
|
||||
|
||||
stopOverride ();
|
||||
}
|
||||
|
||||
public void setNewCurrentCameraTransformDirection (Transform newTransform)
|
||||
{
|
||||
currentCameraTransformDirection = newTransform;
|
||||
}
|
||||
|
||||
public void setNewTurretAttacker (GameObject newAttacker)
|
||||
{
|
||||
turretAttacker = newAttacker;
|
||||
}
|
||||
|
||||
|
||||
void setCurrentTurretWeapon (string weaponName)
|
||||
{
|
||||
int currentIndex = turretWeaponInfoList.FindIndex (s => s.Name == weaponName);
|
||||
|
||||
if (currentIndex > -1) {
|
||||
|
||||
//if (turretWeaponInfoList [currentIndex].isCurrentWeapon) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
for (int i = 0; i < turretWeaponInfoList.Count; i++) {
|
||||
|
||||
if (i != currentIndex) {
|
||||
turretWeaponInfo currentInfo = turretWeaponInfoList [i];
|
||||
|
||||
if (currentInfo.isCurrentWeapon) {
|
||||
currentInfo.isCurrentWeapon = false;
|
||||
|
||||
if (currentInfo.useEventOnSelectWeapon) {
|
||||
currentInfo.eventOnDeactivateWeapon.Invoke ();
|
||||
}
|
||||
|
||||
if (currentInfo.weaponObject != null) {
|
||||
if (currentInfo.weaponObject.activeSelf) {
|
||||
currentInfo.weaponObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentInfo.useWeaponActivateAnimation) {
|
||||
if (currentInfo.weaponActivationAnimationSystem != null) {
|
||||
currentInfo.weaponActivationAnimationSystem.playBackwardAnimation ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentTurretWeaponInfo = turretWeaponInfoList [currentIndex];
|
||||
|
||||
currentTurretWeaponInfo.isCurrentWeapon = true;
|
||||
|
||||
if (currentTurretWeaponInfo.useEventOnSelectWeapon) {
|
||||
currentTurretWeaponInfo.eventOnActivateWeapon.Invoke ();
|
||||
}
|
||||
|
||||
if (currentTurretWeaponInfo.weaponObject != null) {
|
||||
if (!currentTurretWeaponInfo.weaponObject.activeSelf) {
|
||||
currentTurretWeaponInfo.weaponObject.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTurretWeaponInfo.useWeaponActivateAnimation) {
|
||||
if (currentTurretWeaponInfo.weaponActivationAnimationSystem != null) {
|
||||
currentTurretWeaponInfo.weaponActivationAnimationSystem.playForwardAnimation ();
|
||||
}
|
||||
}
|
||||
|
||||
if (useGeneralLayerToDamage) {
|
||||
if (currentTurretWeaponInfo.useSimpleWeaponSystem) {
|
||||
currentTurretWeaponInfo.mainSimpleWeaponSystem.setTargetToDamageLayer (layerToDamage);
|
||||
}
|
||||
}
|
||||
|
||||
shootTimerLimit = currentTurretWeaponInfo.fireRate;
|
||||
|
||||
currentWeaponName = currentTurretWeaponInfo.Name;
|
||||
|
||||
currentWeaponIndex = currentIndex;
|
||||
|
||||
weaponInfoAssigned = true;
|
||||
}
|
||||
}
|
||||
|
||||
void deactivateCurrentWeapon ()
|
||||
{
|
||||
if (weaponInfoAssigned) {
|
||||
if (currentTurretWeaponInfo.useEventOnSelectWeapon) {
|
||||
currentTurretWeaponInfo.eventOnDeactivateWeapon.Invoke ();
|
||||
}
|
||||
|
||||
if (currentTurretWeaponInfo.weaponObject != null) {
|
||||
if (currentTurretWeaponInfo.weaponObject.activeSelf) {
|
||||
currentTurretWeaponInfo.weaponObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTurretWeaponInfo.useSimpleWeaponSystem) {
|
||||
currentTurretWeaponInfo.mainSimpleWeaponSystem.shootWeapon (false);
|
||||
}
|
||||
|
||||
if (currentTurretWeaponInfo.useWeaponActivateAnimation) {
|
||||
if (currentTurretWeaponInfo.weaponActivationAnimationSystem != null) {
|
||||
currentTurretWeaponInfo.weaponActivationAnimationSystem.playBackwardAnimation ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//INPUT FUNCTIONS
|
||||
public void inputSetShootState (bool state)
|
||||
{
|
||||
if (weaponsActive) {
|
||||
if (Time.time > lastTimeWeaponsActivated + 0.6f) {
|
||||
shootingWeapons = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputSetWeaponsState ()
|
||||
{
|
||||
enableOrDisableWeapons (!weaponsActive);
|
||||
}
|
||||
|
||||
public void inputSetNextOrPreviousWeapon (bool state)
|
||||
{
|
||||
if (state) {
|
||||
chooseNextWeapon ();
|
||||
} else {
|
||||
choosePreviousWeapon ();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class turretWeaponInfo
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
|
||||
public float fireRate;
|
||||
|
||||
public bool useWaitTimeToStartShootAfterActivation;
|
||||
public float waitTimeToStartShootAfterActivation;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useSimpleWeaponSystem;
|
||||
public simpleWeaponSystem mainSimpleWeaponSystem;
|
||||
|
||||
[Space]
|
||||
[Header ("Animation Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useWeaponActivateAnimation;
|
||||
|
||||
public simpleAnimationSystem weaponActivationAnimationSystem;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useAnimationOnWeapon;
|
||||
public string weaponAnimationName;
|
||||
|
||||
public Animation animationOnWeapon;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool weaponLookAtTarget;
|
||||
public Transform weaponLookAtTargetTransform;
|
||||
|
||||
public GameObject weaponObject;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool isCurrentWeapon;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnSelectWeapon;
|
||||
|
||||
public UnityEvent eventOnActivateWeapon;
|
||||
public UnityEvent eventOnDeactivateWeapon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fbd3df4028083b46a0cdd170e7927b7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Turret/AITurret.cs
|
||||
uploadId: 814740
|
||||
111
Assets/Game Kit Controller/Scripts/AI/Turret/enemyLaser.cs
Normal file
111
Assets/Game Kit Controller/Scripts/AI/Turret/enemyLaser.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class enemyLaser : laser
|
||||
{
|
||||
[Space]
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public LayerMask layer;
|
||||
|
||||
public float laserDamage = 0.2f;
|
||||
public bool ignoreShield;
|
||||
|
||||
public int damageTypeID = -1;
|
||||
|
||||
public bool damageCanBeBlocked = true;
|
||||
|
||||
public bool useDamageRate;
|
||||
public float damageRate = 0.3f;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public GameObject hitParticles;
|
||||
public GameObject hitSparks;
|
||||
|
||||
public bool useCustomLaserPosition;
|
||||
public Transform customLaserPosition;
|
||||
|
||||
public GameObject owner;
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
Transform currentLaserPosition;
|
||||
|
||||
float lastTimeDamageActive;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
StartCoroutine (laserAnimation ());
|
||||
|
||||
if (useCustomLaserPosition) {
|
||||
currentLaserPosition = customLaserPosition;
|
||||
} else {
|
||||
currentLaserPosition = transform;
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//check the hit collider of the raycast
|
||||
if (Physics.Raycast (currentLaserPosition.position, currentLaserPosition.forward, out hit, Mathf.Infinity, layer)) {
|
||||
bool canApplyDamageResult = true;
|
||||
|
||||
if (useDamageRate) {
|
||||
if (lastTimeDamageActive > 0 && Time.time < damageRate + lastTimeDamageActive) {
|
||||
canApplyDamageResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canApplyDamageResult) {
|
||||
applyDamage.checkHealth (gameObject, hit.collider.gameObject, laserDamage, -currentLaserPosition.forward, (hit.point - (hit.normal / 4)),
|
||||
owner, true, true, ignoreShield, false, damageCanBeBlocked, false, -1, damageTypeID);
|
||||
|
||||
lastTimeDamageActive = Time.time;
|
||||
}
|
||||
|
||||
//set the sparks and .he smoke in the hit point
|
||||
laserDistance = hit.distance;
|
||||
|
||||
if (!hitSparks.activeSelf) {
|
||||
hitSparks.SetActive (true);
|
||||
}
|
||||
|
||||
if (!hitParticles.activeSelf) {
|
||||
hitParticles.SetActive (true);
|
||||
}
|
||||
|
||||
hitParticles.transform.position = hit.point + (currentLaserPosition.position - hit.point) * 0.02f;
|
||||
|
||||
hitParticles.transform.rotation = Quaternion.identity;
|
||||
|
||||
hitSparks.transform.rotation = Quaternion.LookRotation (hit.normal, currentLaserPosition.up);
|
||||
} else {
|
||||
//if the laser does not hit anything, disable the particles and set the hit point
|
||||
if (hitSparks.activeSelf) {
|
||||
hitSparks.SetActive (false);
|
||||
}
|
||||
|
||||
if (hitParticles.activeSelf) {
|
||||
hitParticles.SetActive (false);
|
||||
}
|
||||
|
||||
laserDistance = 1000;
|
||||
|
||||
lastTimeDamageActive = Time.time;
|
||||
}
|
||||
|
||||
//set the size of the laser, according to the hit position
|
||||
lRenderer.SetPosition (1, (laserDistance * Vector3.forward));
|
||||
|
||||
animateLaser ();
|
||||
}
|
||||
|
||||
public void setOwner (GameObject laserOwner)
|
||||
{
|
||||
owner = laserOwner;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32cad009bb77b5e41b751c41ee17f6c3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Turret/enemyLaser.cs
|
||||
uploadId: 814740
|
||||
861
Assets/Game Kit Controller/Scripts/AI/Turret/manageAITarget.cs
Normal file
861
Assets/Game Kit Controller/Scripts/AI/Turret/manageAITarget.cs
Normal file
@@ -0,0 +1,861 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class manageAITarget : MonoBehaviour
|
||||
{
|
||||
[Header ("AI Settings")]
|
||||
[Space]
|
||||
|
||||
public float timeToCheckSuspect;
|
||||
|
||||
public LayerMask layerMask;
|
||||
public LayerMask layerToCheckTargets;
|
||||
|
||||
public string functionToShoot;
|
||||
|
||||
public float extraFieldOfViewRadiusOnSpot;
|
||||
|
||||
public bool checkRaycastToViewTarget = true;
|
||||
public LayerMask layerToCheckRaycastToViewTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Range Vision Settings")]
|
||||
[Space]
|
||||
|
||||
public float visionRange = 90;
|
||||
public float minDistanceToAdquireTarget = 2;
|
||||
public bool allowDetectionWhenTooCloseEvenNotVisible;
|
||||
|
||||
public bool ignoreVisionRangeActive;
|
||||
public float checkIfTargetIsPhysicallyVisibleRadius = 0.2f;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public string factionToChangeName = "Friend Turrets";
|
||||
|
||||
public string surprisedCharacterStateName = "Surprised";
|
||||
public string wonderingCharacterStateName = "Wondering";
|
||||
|
||||
public bool alertFactionOnSpotted;
|
||||
public float alertFactionRadius = 10;
|
||||
|
||||
[Space]
|
||||
[Header ("AI State")]
|
||||
[Space]
|
||||
|
||||
public bool onSpotted;
|
||||
public bool paused;
|
||||
public bool hacking;
|
||||
public bool checkingThreat;
|
||||
public bool targetIsCharacter;
|
||||
public bool targetIsVehicle;
|
||||
public bool threatInfoStored;
|
||||
|
||||
public bool seeingCurrentTarget;
|
||||
|
||||
public GameObject enemyToShoot;
|
||||
|
||||
public GameObject posibleThreat;
|
||||
|
||||
public Transform placeToShoot;
|
||||
|
||||
public bool differentEnemy;
|
||||
|
||||
public GameObject currentObjectDetectedByRaycast;
|
||||
|
||||
[Space]
|
||||
[Header ("Targets Debug")]
|
||||
[Space]
|
||||
|
||||
public List<GameObject> enemies = new List<GameObject> ();
|
||||
public List<GameObject> notEnemies = new List<GameObject> ();
|
||||
|
||||
public List<GameObject> fullEnemyList = new List<GameObject> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoColor = Color.red;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnSpotted;
|
||||
public UnityEvent eventOnSpotted;
|
||||
public UnityEvent eventOnNoTargetsToAttack;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Elements")]
|
||||
[Space]
|
||||
|
||||
public Transform rayCastPosition;
|
||||
public SphereCollider fovTrigger;
|
||||
|
||||
public GameObject hackDevice;
|
||||
|
||||
public checkCollisionType viewTrigger;
|
||||
public characterFactionManager factionManager;
|
||||
public characterStateIconSystem characterStateIconManager;
|
||||
|
||||
RaycastHit hit;
|
||||
float originalFOVRadius;
|
||||
float timeToCheck = 0;
|
||||
float speedMultiplier = 1;
|
||||
|
||||
bool hackFailed;
|
||||
|
||||
playerController currentPlayerController;
|
||||
vehicleHUDManager currentVehicleHUDManager;
|
||||
characterFactionManager characterFactionToCheck;
|
||||
|
||||
bool hasBeenAttacked;
|
||||
Vector3 targetDirection;
|
||||
bool enemyAlertActive;
|
||||
|
||||
float timeWithoutThreatFound;
|
||||
|
||||
Vector3 currentPosition;
|
||||
|
||||
bool targetIsDriving;
|
||||
|
||||
GameObject previousEnemy;
|
||||
|
||||
float currentDistance;
|
||||
|
||||
Vector3 targetToCheckDirection;
|
||||
Transform temporalPlaceToShoot;
|
||||
Vector3 targetToCheckPosition;
|
||||
Vector3 targetToCheckRaycastPosition;
|
||||
vehicleHUDManager temporalVehicleHUDManagerToCheck;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
originalFOVRadius = fovTrigger.radius;
|
||||
|
||||
if (hackDevice != null) {
|
||||
if (tag.Equals ("friend")) {
|
||||
if (hackDevice.activeSelf) {
|
||||
hackDevice.SetActive (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (!hacking && !paused) {
|
||||
|
||||
closestTarget ();
|
||||
|
||||
if (onSpotted) {
|
||||
|
||||
lootAtTarget (placeToShoot);
|
||||
|
||||
if (enemyToShoot != null) {
|
||||
if (Physics.Raycast (rayCastPosition.position, rayCastPosition.forward, out hit, Mathf.Infinity, layerMask)) {
|
||||
if (hit.collider.gameObject == enemyToShoot || hit.collider.gameObject.transform.IsChildOf (enemyToShoot.transform)) {
|
||||
targetDirection = enemyToShoot.transform.position - transform.position;
|
||||
|
||||
float angleWithTarget = Vector3.SignedAngle (rayCastPosition.forward, targetDirection, enemyToShoot.transform.up);
|
||||
|
||||
if (Mathf.Abs (angleWithTarget) < visionRange / 2 || ignoreVisionRangeActive) {
|
||||
shootTarget ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the turret detects a target, it will check if it is an enemy, and this will take 2 seconds, while the enemy choose to leave or stay in the place
|
||||
else if (checkingThreat) {
|
||||
if (posibleThreat != null) {
|
||||
if (!placeToShoot) {
|
||||
//every object with a health component, has a place to be shoot, to avoid that a enemy shoots the player in his foot, so to center the shoot
|
||||
//it is used the gameObject placetoshoot in the health script
|
||||
if (applyDamage.checkIfDead (posibleThreat)) {
|
||||
cancelCheckSuspect (posibleThreat);
|
||||
|
||||
return;
|
||||
} else {
|
||||
placeToShoot = applyDamage.getPlaceToShoot (posibleThreat);
|
||||
}
|
||||
}
|
||||
|
||||
if (!threatInfoStored) {
|
||||
currentPlayerController = posibleThreat.GetComponent<playerController> ();
|
||||
|
||||
if (currentPlayerController != null) {
|
||||
if (currentPlayerController.isCharacterVisibleToAI ()) {
|
||||
setCharacterStateIcon (wonderingCharacterStateName);
|
||||
}
|
||||
} else {
|
||||
setCharacterStateIcon (wonderingCharacterStateName);
|
||||
}
|
||||
|
||||
threatInfoStored = true;
|
||||
}
|
||||
|
||||
if (placeToShoot != null) {
|
||||
//look at the target position
|
||||
lootAtTarget (placeToShoot);
|
||||
}
|
||||
|
||||
//uses a raycast to check the posible threat
|
||||
if (Physics.Raycast (rayCastPosition.position, rayCastPosition.forward, out hit, Mathf.Infinity, layerMask)) {
|
||||
if (hit.collider.gameObject == posibleThreat || hit.collider.gameObject.transform.IsChildOf (posibleThreat.transform)) {
|
||||
timeToCheck += Time.deltaTime * speedMultiplier;
|
||||
} else {
|
||||
timeWithoutThreatFound += Time.deltaTime * speedMultiplier;
|
||||
}
|
||||
|
||||
//when the turret look at the target for a while, it will open fire
|
||||
if (timeToCheck > timeToCheckSuspect) {
|
||||
timeToCheck = 0;
|
||||
|
||||
checkingThreat = false;
|
||||
|
||||
addEnemy (posibleThreat);
|
||||
|
||||
posibleThreat = null;
|
||||
|
||||
disableCharacterStateIcon ();
|
||||
}
|
||||
|
||||
if (timeWithoutThreatFound > timeToCheckSuspect) {
|
||||
resetCheckThreatValues ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCheckThreatValues ()
|
||||
{
|
||||
placeToShoot = null;
|
||||
posibleThreat = null;
|
||||
checkingThreat = false;
|
||||
timeToCheck = 0;
|
||||
timeWithoutThreatFound = 0;
|
||||
|
||||
disableCharacterStateIcon ();
|
||||
}
|
||||
|
||||
//follow the enemy position, to rotate torwards his direction
|
||||
void lootAtTarget (Transform objective)
|
||||
{
|
||||
if (showGizmo) {
|
||||
Debug.DrawRay (rayCastPosition.position, rayCastPosition.forward, Color.red);
|
||||
}
|
||||
|
||||
if (objective != null) {
|
||||
Vector3 targetDir = objective.position - rayCastPosition.position;
|
||||
Quaternion targetRotation = Quaternion.LookRotation (targetDir, transform.up);
|
||||
rayCastPosition.rotation = Quaternion.Slerp (rayCastPosition.rotation, targetRotation, 10 * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public bool checkCharacterFaction (GameObject character, bool damageReceived)
|
||||
{
|
||||
if (fullEnemyList.Contains (character)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
characterFactionToCheck = character.GetComponent<characterFactionManager> ();
|
||||
|
||||
if (characterFactionToCheck != null) {
|
||||
bool isEnemy = false;
|
||||
|
||||
if (damageReceived) {
|
||||
isEnemy = factionManager.isAttackerEnemy (characterFactionToCheck.getFactionName ());
|
||||
} else {
|
||||
isEnemy = factionManager.isCharacterEnemy (characterFactionToCheck.getFactionName ());
|
||||
}
|
||||
|
||||
if (characterFactionToCheck.isIgnoreCharacterFactionEnabled ()) {
|
||||
isEnemy = false;
|
||||
}
|
||||
|
||||
return isEnemy;
|
||||
} else {
|
||||
currentVehicleHUDManager = character.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currentVehicleHUDManager != null) {
|
||||
if (currentVehicleHUDManager.isVehicleBeingDriven ()) {
|
||||
GameObject currentDriver = currentVehicleHUDManager.getCurrentDriver ();
|
||||
|
||||
if (currentDriver == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
characterFactionToCheck = currentDriver.GetComponent<characterFactionManager> ();
|
||||
|
||||
if (characterFactionToCheck != null) {
|
||||
bool isEnemy = false;
|
||||
|
||||
if (damageReceived) {
|
||||
isEnemy = factionManager.isAttackerEnemy (characterFactionToCheck.getFactionName ());
|
||||
} else {
|
||||
isEnemy = factionManager.isCharacterEnemy (characterFactionToCheck.getFactionName ());
|
||||
}
|
||||
|
||||
if (characterFactionToCheck.isIgnoreCharacterFactionEnabled ()) {
|
||||
isEnemy = false;
|
||||
}
|
||||
|
||||
targetIsDriving = true;
|
||||
|
||||
return isEnemy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//check if the object which has collided with the viewTrigger (the capsule collider in the head of the turret) is an enemy checking the tag of that object
|
||||
void checkSuspect (GameObject currentSuspect)
|
||||
{
|
||||
if (canCheckSuspect (currentSuspect.layer)) {
|
||||
if (checkCharacterFaction (currentSuspect, false) && !onSpotted && posibleThreat == null) {
|
||||
|
||||
if (targetIsDriving || applyDamage.isVehicle (currentSuspect)) {
|
||||
targetIsDriving = false;
|
||||
targetIsVehicle = true;
|
||||
}
|
||||
|
||||
if (!checkRaycastToViewTarget || checkIfTargetIsPhysicallyVisible (currentSuspect, true)) {
|
||||
posibleThreat = currentSuspect;
|
||||
checkingThreat = true;
|
||||
hacking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//in the object exits from the viewTrigger, the turret rotates again to search more enemies
|
||||
void cancelCheckSuspect (GameObject col)
|
||||
{
|
||||
if (checkCharacterFaction (col, false) && !onSpotted && posibleThreat != null) {
|
||||
placeToShoot = null;
|
||||
posibleThreat = null;
|
||||
checkingThreat = false;
|
||||
timeToCheck = 0;
|
||||
|
||||
SendMessage ("cancelCheckSuspectTurret", SendMessageOptions.DontRequireReceiver);
|
||||
|
||||
disableCharacterStateIcon ();
|
||||
}
|
||||
}
|
||||
|
||||
//the sphere collider with the trigger of the turret has detected an enemy, so it is added to the list of enemies
|
||||
void enemyDetected (GameObject col)
|
||||
{
|
||||
if (checkCharacterFaction (col, false)) {
|
||||
addEnemy (col.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
//one of the enemies has left, so it is removed from the enemies list
|
||||
void enemyLost (GameObject col)
|
||||
{
|
||||
//if (onSpotted) {
|
||||
removeEnemy (col.gameObject);
|
||||
//}
|
||||
}
|
||||
|
||||
void enemyAlert (GameObject target)
|
||||
{
|
||||
enemyDetected (target);
|
||||
|
||||
enemyAlertActive = true;
|
||||
}
|
||||
|
||||
//if anyone shoot the turret, increase its field of view to search any enemy close to it
|
||||
public void checkShootOrigin (GameObject attacker)
|
||||
{
|
||||
if (!onSpotted) {
|
||||
if (checkCharacterFaction (attacker, true)) {
|
||||
addEnemy (attacker);
|
||||
|
||||
factionManager.addDetectedEnemyFromFaction (attacker);
|
||||
|
||||
hasBeenAttacked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add an enemy to the list, checking that that enemy is not already in the list
|
||||
void addEnemy (GameObject enemy)
|
||||
{
|
||||
if (!enemies.Contains (enemy)) {
|
||||
enemies.Add (enemy);
|
||||
|
||||
if (!fullEnemyList.Contains (enemy)) {
|
||||
fullEnemyList.Add (enemy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove an enemy from the list
|
||||
void removeEnemy (GameObject enemy)
|
||||
{
|
||||
//remove this enemy from the faction system detected enemies for the faction of this character
|
||||
factionManager.removeDetectedEnemyFromFaction (enemy);
|
||||
|
||||
enemies.Remove (enemy);
|
||||
}
|
||||
|
||||
void addNotEnemey (GameObject notEnemy)
|
||||
{
|
||||
if (!notEnemies.Contains (notEnemy)) {
|
||||
characterFactionToCheck = notEnemy.GetComponent<characterFactionManager> ();
|
||||
|
||||
if (characterFactionToCheck != null) {
|
||||
notEnemies.Add (notEnemy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeNotEnemy (GameObject notEnemy)
|
||||
{
|
||||
if (notEnemies.Contains (notEnemy)) {
|
||||
notEnemies.Remove (notEnemy);
|
||||
}
|
||||
}
|
||||
|
||||
//when there is one enemy or more, check which is the closest to shoot it.
|
||||
void closestTarget ()
|
||||
{
|
||||
if (enemies.Count > 0) {
|
||||
currentPosition = transform.position;
|
||||
|
||||
float min = Mathf.Infinity;
|
||||
int index = -1;
|
||||
|
||||
int enemiesCount = enemies.Count;
|
||||
|
||||
for (int i = 0; i < enemiesCount; i++) {
|
||||
if (enemies [i] != null) {
|
||||
|
||||
currentDistance = GKC_Utils.distance (enemies [i].transform.position, currentPosition);
|
||||
|
||||
if (currentDistance < min) {
|
||||
min = currentDistance;
|
||||
index = i;
|
||||
}
|
||||
} else {
|
||||
enemies.RemoveAt (i);
|
||||
|
||||
i = 0;
|
||||
|
||||
enemiesCount = enemies.Count;
|
||||
}
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
enemyToShoot = enemies [index];
|
||||
|
||||
if (enemyToShoot != previousEnemy) {
|
||||
differentEnemy = true;
|
||||
} else {
|
||||
differentEnemy = false;
|
||||
}
|
||||
|
||||
if (placeToShoot == null || differentEnemy) {
|
||||
placeToShoot = applyDamage.getPlaceToShoot (enemyToShoot);
|
||||
}
|
||||
|
||||
if (applyDamage.checkIfDead (enemyToShoot)) {
|
||||
removeEnemy (enemyToShoot);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (differentEnemy) {
|
||||
currentPlayerController = enemyToShoot.GetComponent<playerController> ();
|
||||
}
|
||||
|
||||
if (currentPlayerController != null) {
|
||||
if (currentPlayerController.isPlayerDriving ()) {
|
||||
removeEnemy (enemyToShoot);
|
||||
|
||||
targetIsCharacter = false;
|
||||
|
||||
return;
|
||||
} else {
|
||||
targetIsCharacter = true;
|
||||
targetIsVehicle = false;
|
||||
}
|
||||
} else {
|
||||
if (differentEnemy) {
|
||||
currentVehicleHUDManager = enemyToShoot.GetComponent<vehicleHUDManager> ();
|
||||
}
|
||||
|
||||
if (currentVehicleHUDManager != null) {
|
||||
if (!currentVehicleHUDManager.isVehicleBeingDriven ()) {
|
||||
|
||||
removeEnemy (enemyToShoot);
|
||||
|
||||
return;
|
||||
} else {
|
||||
targetIsCharacter = false;
|
||||
targetIsVehicle = true;
|
||||
}
|
||||
} else {
|
||||
targetIsCharacter = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (previousEnemy != enemyToShoot) {
|
||||
previousEnemy = enemyToShoot;
|
||||
}
|
||||
|
||||
if (!onSpotted) {
|
||||
//the player can hack the turrets, but for that he has to crouch, so he can reach the back of the turret and activate the panel
|
||||
// if the player fails in the hacking or he gets up, the turret will detect the player and will start to fire him
|
||||
//check if the player fails or get up
|
||||
|
||||
seeingCurrentTarget = false;
|
||||
|
||||
if (checkRaycastToViewTarget) {
|
||||
seeingCurrentTarget = checkIfTargetIsPhysicallyVisible (enemyToShoot, false);
|
||||
} else {
|
||||
seeingCurrentTarget = true;
|
||||
}
|
||||
|
||||
if (seeingCurrentTarget) {
|
||||
//if an enemy is inside the trigger, check its position with respect the AI, if the target is in the vision range, adquire it as target
|
||||
targetDirection = enemyToShoot.transform.position - currentPosition;
|
||||
|
||||
float angleWithTarget = Vector3.SignedAngle (rayCastPosition.forward, targetDirection, enemyToShoot.transform.up);
|
||||
|
||||
if (Mathf.Abs (angleWithTarget) < visionRange / 2 || hasBeenAttacked || enemyAlertActive || ignoreVisionRangeActive) {
|
||||
if (currentPlayerController != null) {
|
||||
if ((!currentPlayerController.isCrouching () || hackFailed || checkingThreat || enemyAlertActive || hasBeenAttacked) &&
|
||||
currentPlayerController.isCharacterVisibleToAI ()) {
|
||||
|
||||
hasBeenAttacked = false;
|
||||
|
||||
enemyAlertActive = false;
|
||||
|
||||
hackFailed = false;
|
||||
targetAdquired ();
|
||||
}
|
||||
} else {
|
||||
//else, the target is a friend of the player, so shoot him
|
||||
targetAdquired ();
|
||||
}
|
||||
} else {
|
||||
//else check the distance, if the target is too close, adquire it as target too
|
||||
float distanceToTarget = GKC_Utils.distance (enemyToShoot.transform.position, currentPosition);
|
||||
|
||||
if (distanceToTarget < minDistanceToAdquireTarget && (currentPlayerController.isCharacterVisibleToAI () || allowDetectionWhenTooCloseEvenNotVisible)) {
|
||||
targetAdquired ();
|
||||
}
|
||||
//print ("out of range of vision");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if there are no enemies
|
||||
else {
|
||||
if (onSpotted) {
|
||||
placeToShoot = null;
|
||||
enemyToShoot = null;
|
||||
previousEnemy = null;
|
||||
|
||||
onSpotted = false;
|
||||
|
||||
fovTrigger.radius = originalFOVRadius;
|
||||
|
||||
viewTrigger.gameObject.SetActive (true);
|
||||
|
||||
hackFailed = false;
|
||||
|
||||
SendMessage ("setOnSpottedState", false, SendMessageOptions.DontRequireReceiver);
|
||||
|
||||
checkEventsOnSpotted (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool checkIfTargetIsPhysicallyVisible (GameObject targetToCheck, bool checkingSuspect)
|
||||
{
|
||||
targetToCheckRaycastPosition = transform.position + transform.up;
|
||||
|
||||
if (placeToShoot != null) {
|
||||
targetToCheckDirection = placeToShoot.transform.position - targetToCheckRaycastPosition;
|
||||
} else {
|
||||
temporalPlaceToShoot = applyDamage.getPlaceToShoot (targetToCheck);
|
||||
|
||||
if (temporalPlaceToShoot != null) {
|
||||
targetToCheckDirection = temporalPlaceToShoot.position - targetToCheckRaycastPosition;
|
||||
} else {
|
||||
targetToCheckDirection = (targetToCheck.transform.position + targetToCheck.transform.up) - targetToCheckRaycastPosition;
|
||||
}
|
||||
}
|
||||
|
||||
targetToCheckPosition = targetToCheckRaycastPosition + checkIfTargetIsPhysicallyVisibleRadius * targetToCheckDirection;
|
||||
|
||||
if (targetIsVehicle) {
|
||||
temporalVehicleHUDManagerToCheck = applyDamage.getVehicleHUDManager (targetToCheck);
|
||||
}
|
||||
|
||||
currentObjectDetectedByRaycast = null;
|
||||
|
||||
//Debug.DrawRay (targetToCheckPosition, targetToCheckDirection * 0.2f, Color.green);
|
||||
if (Physics.Raycast (targetToCheckPosition, targetToCheckDirection, out hit, Mathf.Infinity, layerToCheckRaycastToViewTarget)) {
|
||||
//print (hit.collider.gameObject.name + " " + targetIsVehicle);
|
||||
//print (hit.collider.name + " " + hit.transform.IsChildOf (targetToCheck.transform) + " " + targetToCheck.name);
|
||||
|
||||
if ((!targetIsVehicle && (hit.collider.gameObject == targetToCheck || hit.transform.IsChildOf (targetToCheck.transform))) ||
|
||||
(targetIsVehicle && temporalVehicleHUDManagerToCheck &&
|
||||
((temporalVehicleHUDManagerToCheck.gameObject == targetToCheck && checkingSuspect) || temporalVehicleHUDManagerToCheck.checkIfDetectSurfaceBelongToVehicle (hit.collider)))) {
|
||||
|
||||
currentObjectDetectedByRaycast = hit.collider.gameObject;
|
||||
|
||||
if (showGizmo) {
|
||||
Debug.DrawRay (rayCastPosition.position, targetToCheckDirection, Color.green, 2);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
if (showGizmo) {
|
||||
Debug.DrawRay (rayCastPosition.position, targetToCheckDirection, Color.red, 2);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (showGizmo) {
|
||||
Debug.DrawRay (rayCastPosition.position, targetToCheckDirection, Color.black, 2);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void targetAdquired ()
|
||||
{
|
||||
//print ("target adquired");
|
||||
|
||||
onSpotted = true;
|
||||
|
||||
fovTrigger.radius = GKC_Utils.distance (enemyToShoot.transform.position, transform.position) + extraFieldOfViewRadiusOnSpot;
|
||||
|
||||
if (fovTrigger.radius < originalFOVRadius) {
|
||||
fovTrigger.radius = originalFOVRadius;
|
||||
}
|
||||
|
||||
viewTrigger.gameObject.SetActive (false);
|
||||
|
||||
SendMessage ("setOnSpottedState", true, SendMessageOptions.DontRequireReceiver);
|
||||
|
||||
//send this enemy to faction system for the detected enemies list
|
||||
factionManager.addDetectedEnemyFromFaction (enemyToShoot);
|
||||
|
||||
setCharacterStateIcon (surprisedCharacterStateName);
|
||||
|
||||
if (alertFactionOnSpotted) {
|
||||
factionManager.alertFactionOnSpotted (alertFactionRadius, enemyToShoot, transform.position);
|
||||
}
|
||||
|
||||
checkEventsOnSpotted (true);
|
||||
}
|
||||
|
||||
//active the fire mode
|
||||
public void shootTarget ()
|
||||
{
|
||||
//SendMessage (functionToShoot, true);
|
||||
}
|
||||
|
||||
public void pauseAI (bool state)
|
||||
{
|
||||
paused = state;
|
||||
|
||||
//SendMessage ("setPauseState", paused);
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkPossibleTarget (GameObject objectToCheck)
|
||||
{
|
||||
Collider currentCollider = objectToCheck.GetComponent<Collider> ();
|
||||
|
||||
if (currentCollider != null) {
|
||||
checkTriggerInfo (currentCollider, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (canCheckSuspect (col.gameObject.layer)) {
|
||||
if (isEnter) {
|
||||
if (!paused) {
|
||||
if (checkCharacterFaction (col.gameObject, false)) {
|
||||
enemyDetected (col.gameObject);
|
||||
} else {
|
||||
addNotEnemey (col.gameObject);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (checkCharacterFaction (col.gameObject, false)) {
|
||||
enemyLost (col.gameObject);
|
||||
} else {
|
||||
removeNotEnemy (col.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool canCheckSuspect (int suspectLayer)
|
||||
{
|
||||
if ((1 << suspectLayer & layerToCheckTargets.value) == 1 << suspectLayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setCorrectlyHackedState ()
|
||||
{
|
||||
setHackResult (true);
|
||||
}
|
||||
|
||||
public void setIncorrectlyHackedState ()
|
||||
{
|
||||
setHackResult (false);
|
||||
}
|
||||
|
||||
//check the result of the hacking, true the turret now is an ally, else, the turret detects the player
|
||||
public void setHackResult (bool state)
|
||||
{
|
||||
hacking = false;
|
||||
|
||||
if (state) {
|
||||
enemyHackPanel currentEnemyHackPanel = hackDevice.GetComponent<enemyHackPanel> ();
|
||||
|
||||
if (currentEnemyHackPanel != null) {
|
||||
currentEnemyHackPanel.disablePanelHack ();
|
||||
}
|
||||
|
||||
tag = "friend";
|
||||
|
||||
factionManager.changeCharacterToFaction (factionToChangeName);
|
||||
|
||||
//if the turret becomes an ally, change its icon color in the radar
|
||||
mapObjectInformation currentMapObjectInformation = GetComponent<mapObjectInformation> ();
|
||||
|
||||
if (currentMapObjectInformation != null) {
|
||||
currentMapObjectInformation.addMapObject ("Friend");
|
||||
}
|
||||
|
||||
//set in the health slider the new name and slider color
|
||||
health currentHealth = GetComponent<health> ();
|
||||
|
||||
if (currentHealth != null) {
|
||||
currentHealth.hacked ();
|
||||
}
|
||||
|
||||
enemies.Clear ();
|
||||
|
||||
notEnemies.Clear ();
|
||||
|
||||
fullEnemyList.Clear ();
|
||||
} else {
|
||||
hackFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
//the turret is been hacked
|
||||
public void activateHack ()
|
||||
{
|
||||
hacking = true;
|
||||
}
|
||||
|
||||
public void checkCharactersAroundAI ()
|
||||
{
|
||||
for (int i = 0; i < notEnemies.Count; i++) {
|
||||
enemyDetected (notEnemies [i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCharacterStateIcon (string stateName)
|
||||
{
|
||||
if (characterStateIconManager != null) {
|
||||
characterStateIconManager.setCharacterStateIcon (stateName);
|
||||
}
|
||||
}
|
||||
|
||||
public void disableCharacterStateIcon ()
|
||||
{
|
||||
if (characterStateIconManager != null) {
|
||||
characterStateIconManager.disableCharacterStateIcon ();
|
||||
}
|
||||
}
|
||||
|
||||
//disable ai when it dies
|
||||
public void setAIStateToDead ()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public void checkEventsOnSpotted (bool state)
|
||||
{
|
||||
if (useEventsOnSpotted) {
|
||||
if (state) {
|
||||
eventOnSpotted.Invoke ();
|
||||
} else {
|
||||
eventOnNoTargetsToAttack.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
Gizmos.color = gizmoColor;
|
||||
|
||||
Gizmos.DrawWireSphere (transform.position, alertFactionRadius);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 780006d19e41485458ec445f565e7f25
|
||||
timeCreated: 1514837983
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/Turret/manageAITarget.cs
|
||||
uploadId: 814740
|
||||
140
Assets/Game Kit Controller/Scripts/AI/addPatrolSystemToAI.cs
Normal file
140
Assets/Game Kit Controller/Scripts/AI/addPatrolSystemToAI.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class addPatrolSystemToAI : MonoBehaviour
|
||||
{
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public AIPatrolSystem mainAIPatrolSystem;
|
||||
|
||||
public GameObject AIWaypointPatrolUniversalPrefab;
|
||||
|
||||
public AIWayPointPatrol mainAIWaypointPatrol;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
[TextArea (1, 10)]
|
||||
public string explanation = "The button Add Patrol System to AI will add a custom patrol to this character.\n\n" +
|
||||
"The button Assign AI Waypoint Patrol will search for any previous patrol on scene to assign it to this AI.\n" +
|
||||
"So that allows that 2 AI share the same patrol. You can also drop a specific patrol from the scene on the field " +
|
||||
"Main AI Waypoint Patrol and it will that the patrol assigned to the character.";
|
||||
|
||||
public void enableOrdisablePatrolOnAI (bool state)
|
||||
{
|
||||
if (mainAIPatrolSystem == null) {
|
||||
playerComponentsManager currentPlayerComponentsManager = GetComponentInChildren<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
|
||||
findObjectivesSystem currentFindObjectivesSystem = currentPlayerComponentsManager.getFindObjectivesSystem ();
|
||||
|
||||
if (currentFindObjectivesSystem != null) {
|
||||
mainAIPatrolSystem = currentFindObjectivesSystem.AIPatrolManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mainAIPatrolSystem != null) {
|
||||
mainAIPatrolSystem.pauseOrPlayPatrol (!state);
|
||||
|
||||
mainAIPatrolSystem.gameObject.SetActive (state);
|
||||
|
||||
GKC_Utils.updateComponent (mainAIPatrolSystem);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void assignAIWaypointPatrol ()
|
||||
{
|
||||
if (mainAIWaypointPatrol == null) {
|
||||
mainAIWaypointPatrol = FindObjectOfType<AIWayPointPatrol> ();
|
||||
}
|
||||
|
||||
if (mainAIWaypointPatrol == null) {
|
||||
GameObject newAIWaypointPatrol = (GameObject)Instantiate (AIWaypointPatrolUniversalPrefab, transform.position + Vector3.forward * 6, Quaternion.identity);
|
||||
newAIWaypointPatrol.name = "AI Waypoint Patrol";
|
||||
|
||||
mainAIWaypointPatrol = newAIWaypointPatrol.GetComponent<AIWayPointPatrol> ();
|
||||
}
|
||||
|
||||
if (mainAIWaypointPatrol != null) {
|
||||
playerComponentsManager currentPlayerComponentsManager = GetComponentInChildren<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
|
||||
AIPatrolSystem currentAIPatrolSystem = currentPlayerComponentsManager.getAIPatrolSystem ();
|
||||
|
||||
findObjectivesSystem currentFindObjectivesSystem = currentPlayerComponentsManager.getFindObjectivesSystem ();
|
||||
|
||||
if (currentAIPatrolSystem != null) {
|
||||
currentAIPatrolSystem.patrolPath = mainAIWaypointPatrol;
|
||||
|
||||
currentAIPatrolSystem.pauseOrPlayPatrol (false);
|
||||
|
||||
currentFindObjectivesSystem.AIPatrolManager = currentAIPatrolSystem;
|
||||
|
||||
GKC_Utils.updateComponent (currentAIPatrolSystem);
|
||||
|
||||
GKC_Utils.updateComponent (currentFindObjectivesSystem);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPatrolSystem ()
|
||||
{
|
||||
if (AIWaypointPatrolUniversalPrefab == null) {
|
||||
print ("Patrol prefab not configured");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
findObjectivesSystem currentFindObjectivesSystem = GetComponentInChildren<findObjectivesSystem> ();
|
||||
|
||||
if (currentFindObjectivesSystem != null && mainAIWaypointPatrol == null) {
|
||||
|
||||
GameObject newAIWaypointPatrol = (GameObject)Instantiate (AIWaypointPatrolUniversalPrefab, currentFindObjectivesSystem.transform.position + Vector3.forward * 6, Quaternion.identity);
|
||||
newAIWaypointPatrol.name = "AI Waypoint Patrol";
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = GetComponentInChildren<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
|
||||
AIPatrolSystem currentAIPatrolSystem = currentPlayerComponentsManager.getAIPatrolSystem ();
|
||||
|
||||
if (currentAIPatrolSystem != null) {
|
||||
currentAIPatrolSystem.patrolPath = newAIWaypointPatrol.GetComponent<AIWayPointPatrol> ();
|
||||
|
||||
currentAIPatrolSystem.pauseOrPlayPatrol (false);
|
||||
|
||||
currentFindObjectivesSystem.AIPatrolManager = currentAIPatrolSystem;
|
||||
|
||||
mainAIWaypointPatrol = newAIWaypointPatrol.GetComponent<AIWayPointPatrol> ();
|
||||
|
||||
GKC_Utils.updateComponent (currentAIPatrolSystem);
|
||||
}
|
||||
}
|
||||
|
||||
GKC_Utils.updateComponent (currentFindObjectivesSystem);
|
||||
|
||||
updateComponent ();
|
||||
|
||||
print ("Patrol system added to AI");
|
||||
} else {
|
||||
print ("WARNING: patrol system already configured on this AI");
|
||||
}
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Adding patrol to AI", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb2fcf9cd26002949b5c58fd682608d5
|
||||
timeCreated: 1573435648
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/AI/addPatrolSystemToAI.cs
|
||||
uploadId: 814740
|
||||
38
Assets/Game Kit Controller/Scripts/AI/animalAINavmesh.cs
Normal file
38
Assets/Game Kit Controller/Scripts/AI/animalAINavmesh.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class animalAINavmesh : AINavMesh
|
||||
{
|
||||
[Space]
|
||||
[Header ("AI Navmesh Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public inputActionManager mainInputActionManager;
|
||||
|
||||
Vector2 moveInput;
|
||||
|
||||
public override void updateAIControllerInputValues ()
|
||||
{
|
||||
moveInput = new Vector2 (AIMoveInput.moveInput.x, AIMoveInput.moveInput.z);
|
||||
|
||||
mainInputActionManager.overrideInputValues (moveInput, -1, 1, true);
|
||||
|
||||
playerControllerManager.Move (AIMoveInput);
|
||||
//
|
||||
// playerCameraManager.Rotate (rayCastPosition.forward);
|
||||
|
||||
//remove once find objectives is configured on the vehicle AI
|
||||
setOnGroundState (playerControllerManager.isPlayerOnGround ());
|
||||
}
|
||||
|
||||
public override void updateAICameraInputValues ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void disableOverrideInputValues ()
|
||||
{
|
||||
mainInputActionManager.overrideInputValues (Vector2.zero, -1, 1, false);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user