add ckg
plantilla base para movimiento básico
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user