Skip to content
Darking Assets edited this page Feb 11, 2022 · 11 revisions

Welcome to the Universal-AI-2.0 wiki!

Universal AI is a professional and modular AI solution for everyone. You can check this wiki for deep info about AI with our well-explained API Codes.

General API Codes

Getting Started

  • To access the Universal AI scripts and variables, you need to import our custom namespace first. To do so, you can put the code line below on top of your script:
 using UniversalAI;
  • After importing our namespace, you will need to get the UniversalAICommandManager script to access our API methods. You can call code on Start Or Awake for best results:
 CommandManager = YourAIObject.GetComponent<UniversalAICommandManager>();
  • Here is a full working example for getting the needed components and calling an API method for example: (You need to attach this to your AI GameObject to make it work).
using UnityEngine;

//Import UniversalAI namespace.
using UniversalAI;

public class APIMethodExample : MonoBehaviour
{
    UniversalAISystem AISystem;
    UniversalAICommandManager CommandManager;

    //On Start, we get the needed components from our AI.
    void Start()
    {
        AISystem = GetComponent<UniversalAISystem>();
        CommandManager = AISystem.UniversalAICommandManager;
    }
    
    //As an example, it will refill the AI's health when pressing the T key.
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            CommandManager.RefillAIHealth();
        }
    }
}

Damage AI

  • AI Take Damage Method, can be called from anywhere.
 void TakeDamage(float damageamount, AttackerType attackertype, GameObject attacker)
  • Usage:
// The method that will damage your AI, you can leave attacker null if you can't get the damager object.
 if(YourAIObject.GetComponent<UniversalAI.UniversalAISystem>() != null)
 {
    YourAIObject.GetComponent<UniversalAI.UniversalAISystem>().TakeDamage(YourDamage, UniversalAI.UniversalAIEnums.AttackerType.Player, YourPlayerObject);
 }

Command Manager API

  • Command Manager component is the main API handler of the Universal AI 2.0.

General

AddIgnoredTarget

  • Adds the given GameObject as ignored list for the AI. AI won't detect and will ignore this GameObject.
 void AddIgnoredTarget(GameObject Target)

RemoveIgnoredTarget

  • Removes the given GameObject from the ignored list of the AI. AI will no longer ignore this GameObject.
 void RemoveIgnoredTarget(GameObject Target)

ClearAllIgnoredTargets

  • Removes every GameObject from the ignored list of the AI. AI will no longer ignore these GameObjects.
 void ClearAllIgnoredTargets()

GetTarget

  • Returns The Current Target GameObject Of The AI. Will Return Null If There Is Currently No Target.
 GameObject GetTarget()

SetTarget

  • Sets the AI's new target.
 void SetTarget(GameObject newTarget)

SetDestination

  • Sets the new destination for the AI, (if the AI isn't wandering, AI will go to the given destination whenever it wanders).
 void SetDestination(Vector3 newDestination)

StopAIBehaviour

  • Stops The AI Behaviour, So The User Can Add Their Custom Actions / Code / Behaviour etc.
 void StopAIBehaviour()

StartAIBehaviour

  • Starts The AI Behaviour Again.
 void StartAIBehaviour()

ChangeDetectionType

  • Changes the AI's current detection type.
 void ChangeDetectionType(UniversalAIEnums.DetectionType detectionType)

ChangeFaction

  • Changes the AI's current faction group.
 void ChangeFaction(UniversalAIEnums.Factions factions)

GetDetectionType

  • Returns the AI's current detection type.
 UniversalAIEnums.DetectionType GetDetectionType()

GetFaction

  • Returns the AI's current faction.
 UniversalAIEnums.Factions GetFaction()

KillAI

  • Kills the AI with a delay or instantly.
 void KillAI(float delay = 0f)

FreezeAI

  • Freezes the AI with a delay or instantly.
 void FreezeAI(float delay = 0f)

UnFreezeAI

  • UnFreezes the AI with a delay or instantly.
 void UnFreezeAI(float delay = 0f)

ReviveAI

  • Revives the AI (can't revive ragdoll death AI).
 void ReviveAI()

SetAIHealth

  • Sets the AI health.
 void SetAIHealth(float newHealth)

RefillAIHealth

  • Refills the AI health.
 void RefillAIHealth()

GetHealth

  • Returns the AI health.
 float GetHealth()

ChangeAIType

  • Sets the AI type.
 void ChangeAIType(UniversalAIEnums.AIType AIType)

ChangeAIConfidence

  • Sets the AI confidence.
 void ChangeAIConfidence(UniversalAIEnums.AIConfidence AIConfidence)

ChangeAIWanderType

  • Sets the AI wander type.
 void ChangeAIWanderType(UniversalAIEnums.WanderType wanderType)

GetAIType

  • Returns the current AI type.
 UniversalAIEnums.AIType GetAIType()

GetAIConfidence

  • Returns the current AI confidence.
 UniversalAIEnums.AIConfidence GetAIConfidence()

GetAIWanderType

  • Returns the current AI wander type.
 UniversalAIEnums.WanderType GetAIWanderType()

GetTargetDistance

  • Returns the current distance between AI and AI's current target, (Returns -1 if the target is null).
 float GetTargetDistance()

EnableHealthRegeneration

  • Enables the health regeneration for the AI
 void EnableHealthRegeneration()

DisableHealthRegeneration

  • Disables the health regeneration for the AI
 void DisableHealthRegeneration()

Companion API

  • To call these methods, you need to say: CommandManager.CompanionCommands instead of only CommandManager.

ChangeAttackState

  • Changes the companion AI's attack state (Aggressive, Passive)
 void ChangeAttackState(AttackState newAttackState)

ChangeCompanionBehaviour

  • Changes the companion AI's behaviour (Follow, Stay)
 void ChangeCompanionBehaviour(CompanionBehaviour newBehaviour)

Pet API

  • To call these methods, you need to say: CommandManager.PetCommands instead of only CommandManager.

ChangePetBehaviour

  • Changes the pet AI's behaviour (Follow, Stay)
 void ChangePetBehaviour(PetBehaviour newBehaviour)