init 1.1.2

This commit is contained in:
2025-07-20 10:01:29 +08:00
commit 2afbbf9be4
1327 changed files with 1596159 additions and 0 deletions
@@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EmeraldAI;
using EmeraldAI.Utility;
namespace EmeraldAI.Example
{
/// <summary>
/// Spawns random blood splatter GameObjects. None are included with Emerald AI, but an open source asset can be found at the following link which was used in Emerald AI's 3.0's demo videos.
/// Dynamic Decals: https://github.com/EricFreeman/DynamicDecals
/// </summary>
[RequireComponent(typeof(EmeraldEvents))]
public class BloodSplatterManager : MonoBehaviour
{
public List<GameObject> BloodEffects = new List<GameObject>();
public float BloodSpawnDelay = 0;
public float BloodSpawnRadius = 0.6f;
public int BloodDespawnTime = 16;
public int OddsForBlood = 100;
EmeraldEvents EmeraldEventsComponent;
EmeraldSystem EmeraldComponent;
void Start()
{
EmeraldEventsComponent = GetComponent<EmeraldEvents>();
EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldEventsComponent.OnTakeDamageEvent.AddListener(() => { CreateBloodSplatter(); });
}
public void CreateBloodSplatter()
{
Invoke("DelayCreateBloodSplatter", BloodSpawnDelay);
}
void DelayCreateBloodSplatter()
{
var Odds = Random.Range(0, 101);
if (Odds <= OddsForBlood && EmeraldComponent != null && !EmeraldComponent.AnimationComponent.IsBlocking)
{
GameObject BloodEffect = EmeraldObjectPool.SpawnEffect(BloodEffects[Random.Range(0, BloodEffects.Count)], transform.position + Random.insideUnitSphere * BloodSpawnRadius, Quaternion.identity, BloodDespawnTime);
BloodEffect.transform.position = new Vector3(BloodEffect.transform.position.x, transform.position.y, BloodEffect.transform.position.z);
BloodEffect.transform.rotation = Quaternion.AngleAxis(Random.Range(55, 125), Vector3.right) * Quaternion.AngleAxis(Random.Range(10, 350), Vector3.forward);
BloodEffect.transform.localScale = Vector3.one * Random.Range(0.8f, 1f);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9d8fdead26a91ac4e9cd6d83bfdc56cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace EmeraldAI.Example
{
/// <summary>
/// A script that damages AI based on collisions. Can be used for dynamic damaging objects such as rocks, logs,
/// and other falling objects or collision based weapons.
/// </summary>
public class DamageAIByCollision : MonoBehaviour
{
public bool IsTrigger = false;
public int DamageAmount = 10;
public int RagdollForceAmount = 50;
private void OnTriggerEnter(Collider collision)
{
if (!IsTrigger) return;
//Damages an AI to the collided object
if (collision.gameObject.GetComponent<IDamageable>() != null)
{
collision.gameObject.GetComponent<IDamageable>().Damage(DamageAmount, transform, RagdollForceAmount);
}
//Damages an AI's location based damage component
else if (collision.gameObject.GetComponent<LocationBasedDamageArea>() != null)
{
LocationBasedDamageArea LBDArea = collision.gameObject.GetComponent<LocationBasedDamageArea>();
LBDArea.DamageArea(DamageAmount, transform, RagdollForceAmount);
}
}
private void OnCollisionEnter(Collision collision)
{
if (IsTrigger) return;
//Damages an AI to the collided object
if (collision.gameObject.GetComponent<IDamageable>() != null)
{
collision.gameObject.GetComponent<IDamageable>().Damage(DamageAmount, transform, RagdollForceAmount);
}
//Damages an AI's location based damage component
else if (collision.gameObject.GetComponent<LocationBasedDamageArea>() != null)
{
LocationBasedDamageArea LBDArea = collision.gameObject.GetComponent<LocationBasedDamageArea>();
LBDArea.DamageArea(DamageAmount, transform, RagdollForceAmount);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7d0e7b29451388447aa01a5b05a0c65e
timeCreated: 1584721361
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EmeraldAI;
using EmeraldAI.Utility;
[RequireComponent(typeof(AudioSource))]
public class DamageAIByExplosion : MonoBehaviour
{
public LayerMask EmeraldAILayer;
public int DamageAmount = 200;
public int ExplosionRadius = 4;
public int ExplosionForce = 400;
public GameObject ExplosionEffect;
public AudioClip ExplosionSound;
GameObject ExplosionSoundObject;
private void Start()
{
ExplosionSoundObject = Resources.Load("Emerald Sound") as GameObject;
Invoke(nameof(Explode), 1.75f);
}
/// <summary>
/// Call this function when you want to damage surrounding AI based on the set public variables within this script.
/// </summary>
public void Explode ()
{
EmeraldObjectPool.SpawnEffect(ExplosionEffect, transform.position, Quaternion.identity, 4);
Collider[] hitColliders = Physics.OverlapSphere(transform.position, ExplosionRadius, EmeraldAILayer);
foreach (var hitCollider in hitColliders)
{
int DamageMitigation = Mathf.RoundToInt((1f - Vector3.Distance(hitCollider.transform.position, transform.position) / ExplosionRadius) * DamageAmount);
int ForceMitigation = Mathf.RoundToInt((1f - Vector3.Distance(hitCollider.transform.position, transform.position) / ExplosionRadius) * ExplosionForce);
if (hitCollider.GetComponent<IDamageable>() != null)
{
hitCollider.GetComponent<IDamageable>().Damage(DamageMitigation, transform, ForceMitigation);
}
}
SpawnExplosionSound();
gameObject.SetActive(false);
}
void SpawnExplosionSound ()
{
GameObject SpawnedExplosionSound = EmeraldObjectPool.SpawnEffect(ExplosionSoundObject, transform.position, Quaternion.identity, 3);
SpawnedExplosionSound.transform.SetParent(EmeraldSystem.ObjectPool.transform);
AudioSource ExplosionAudioSource = SpawnedExplosionSound.GetComponent<AudioSource>();
if (ExplosionSound != null) ExplosionAudioSource.PlayOneShot(ExplosionSound);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f51213230916d74ab4576269fa7d7c3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,168 @@
using UnityEngine;
using System.Collections;
#if (ENABLE_INPUT_SYSTEM)
using UnityEngine.InputSystem;
#endif
namespace EmeraldAI.Example
{
public class FlyCamera : MonoBehaviour
{
public float mainSpeed = 10.0f;
public float shiftAdd = 25.0f;
public float maxShift = 25.0f;
public float camSens = 0.25f;
private Vector3 lastMouse = new Vector3(255, 255, 255);
private float totalRun = 1.0f;
void Update()
{
#if (ENABLE_LEGACY_INPUT_MANAGER)
LegacyInput();
#elif (ENABLE_INPUT_SYSTEM)
NewInput();
#endif
}
#if (ENABLE_LEGACY_INPUT_MANAGER)
void LegacyInput()
{
if (Input.GetMouseButtonDown(1))
{
lastMouse = Input.mousePosition;
}
if (Input.GetMouseButton(1))
{
lastMouse = Input.mousePosition - lastMouse;
lastMouse = new Vector3(-lastMouse.y * camSens, lastMouse.x * camSens, 0);
lastMouse = new Vector3(transform.eulerAngles.x + lastMouse.x, transform.eulerAngles.y + lastMouse.y, 0);
transform.eulerAngles = lastMouse;
lastMouse = Input.mousePosition;
}
//Keyboard commands
Vector3 p = GetBaseLegacyInput();
if (Input.GetKey(KeyCode.LeftShift))
{
totalRun += Time.deltaTime;
p = p * totalRun * shiftAdd;
p.x = Mathf.Clamp(p.x, -maxShift, maxShift);
p.y = Mathf.Clamp(p.y, -maxShift, maxShift);
p.z = Mathf.Clamp(p.z, -maxShift, maxShift);
}
else
{
totalRun = Mathf.Clamp(totalRun * 0.5f, 1f, 1000f);
p = p * mainSpeed;
}
p = p * Time.deltaTime;
transform.Translate(p);
}
#endif
#if (ENABLE_INPUT_SYSTEM)
void NewInput()
{
if (!Mouse.current.rightButton.isPressed)
{
lastMouse = Mouse.current.position.ReadValue();
}
if (Mouse.current.rightButton.isPressed)
{
lastMouse = (Vector3)Mouse.current.position.ReadValue() - lastMouse;
lastMouse = new Vector3(-lastMouse.y * camSens, lastMouse.x * camSens, 0);
lastMouse = new Vector3(transform.eulerAngles.x + lastMouse.x, transform.eulerAngles.y + lastMouse.y, 0);
transform.eulerAngles = lastMouse;
lastMouse = Mouse.current.position.ReadValue();
}
//Keyboard commands
Vector3 p = GetBaseNewInput();
if (Keyboard.current.leftShiftKey.isPressed)
{
totalRun += Time.deltaTime;
p = p * totalRun * shiftAdd;
p.x = Mathf.Clamp(p.x, -maxShift, maxShift);
p.y = Mathf.Clamp(p.y, -maxShift, maxShift);
p.z = Mathf.Clamp(p.z, -maxShift, maxShift);
}
else
{
totalRun = Mathf.Clamp(totalRun * 0.5f, 1f, 1000f);
p = p * mainSpeed;
}
p = p * Time.deltaTime;
transform.Translate(p);
}
#endif
#if (ENABLE_LEGACY_INPUT_MANAGER)
private Vector3 GetBaseLegacyInput()
{
Vector3 p_Velocity = new Vector3();
if (Input.GetKey(KeyCode.W))
{
p_Velocity += new Vector3(0, 0, 1);
}
if (Input.GetKey(KeyCode.S))
{
p_Velocity += new Vector3(0, 0, -1);
}
if (Input.GetKey(KeyCode.A))
{
p_Velocity += new Vector3(-1, 0, 0);
}
if (Input.GetKey(KeyCode.D))
{
p_Velocity += new Vector3(1, 0, 0);
}
if (Input.GetKey(KeyCode.Q))
{
p_Velocity += new Vector3(0, 1, 0);
}
if (Input.GetKey(KeyCode.E))
{
p_Velocity += new Vector3(0, -1, 0);
}
return p_Velocity;
}
#endif
#if (ENABLE_INPUT_SYSTEM)
private Vector3 GetBaseNewInput()
{
Vector3 p_Velocity = new Vector3();
if (Keyboard.current.wKey.isPressed)
{
p_Velocity += new Vector3(0, 0, 1);
}
if (Keyboard.current.sKey.isPressed)
{
p_Velocity += new Vector3(0, 0, -1);
}
if (Keyboard.current.aKey.isPressed)
{
p_Velocity += new Vector3(-1, 0, 0);
}
if (Keyboard.current.dKey.isPressed)
{
p_Velocity += new Vector3(1, 0, 0);
}
if (Keyboard.current.qKey.isPressed)
{
p_Velocity += new Vector3(0, 1, 0);
}
if (Keyboard.current.eKey.isPressed)
{
p_Velocity += new Vector3(0, -1, 0);
}
return p_Velocity;
}
#endif
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 018e0762c4cf63242ad455eec12f4579
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace EmeraldAI.Example
{
/// <summary>
/// A script for initializing the CombatTextSystem, given that there are no AI in the scene.
/// </summary>
public class InitializeCombatTextSystem : MonoBehaviour
{
private void Awake()
{
SetupCombatText();
}
void SetupCombatText()
{
GameObject m_CombatTextSystem = Instantiate((GameObject)Resources.Load("Combat Text System") as GameObject, Vector3.zero, Quaternion.identity);
m_CombatTextSystem.name = "Combat Text System";
GameObject m_CombatTextCanvas = Instantiate((GameObject)Resources.Load("Combat Text Canvas") as GameObject, Vector3.zero, Quaternion.identity);
m_CombatTextCanvas.name = "Combat Text Canvas";
CombatTextSystem.Instance.CombatTextCanvas = m_CombatTextCanvas;
EmeraldSystem.CombatTextSystemObject = m_CombatTextCanvas;
CombatTextSystem.Instance.Initialize();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 515ee66bfaecf5b459948745d908358a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EmeraldAI;
using EmeraldAI.Utility;
public class MoveToMousePosition : MonoBehaviour
{
EmeraldSystem EmeraldComponent;
private void Start()
{
EmeraldComponent = GetComponent<EmeraldSystem>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray;
RaycastHit hit;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 80))
{
if (EmeraldComponent != null)
{
EmeraldAPI.Movement.SetCustomDestination(EmeraldComponent, hit.point);
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f3bdfb459aa62824cbec5615bd2eac9e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
namespace EmeraldAI.CharacterController
{
public class SmoothFollow : MonoBehaviour
{
public Vector3 CameraOffset;
public Transform target;
public float smoothTime = 0.3F;
private Vector3 velocity = Vector3.zero;
void Update()
{
// Smoothly move the camera towards that target position
transform.position = Vector3.SmoothDamp(transform.position, target.position + CameraOffset, ref velocity, smoothTime);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1173f1580ab379946b67f47d664adf6a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: