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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user