plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent 195b696771
commit 779f2c8b20
14443 changed files with 23840465 additions and 452 deletions

View File

@@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GKC_PoolingAIManager : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool findDisabledElementsOnSceneGameObjects = true;
[Space]
[Header ("AI Pooling List Settings")]
[Space]
public List<GKC_PoolingElementAI> GKC_PoolingElementAIList = new List<GKC_PoolingElementAI> ();
public void getAllGKC_PoolingElementAIOnLevel ()
{
GKC_PoolingElementAIList.Clear ();
if (findDisabledElementsOnSceneGameObjects) {
GKC_PoolingElementAIList = GKC_Utils.FindObjectsOfTypeAll<GKC_PoolingElementAI> ();
} else {
GKC_PoolingElementAI[] newGKC_PoolingElementAIList = FindObjectsOfType<GKC_PoolingElementAI> ();
foreach (GKC_PoolingElementAI currentGKC_PoolingElementAI in newGKC_PoolingElementAIList) {
if (!GKC_PoolingElementAIList.Contains (currentGKC_PoolingElementAI)) {
GKC_PoolingElementAIList.Add (currentGKC_PoolingElementAI);
}
}
}
updateComponent ();
}
public void clearGKC_PoolingElementAIList ()
{
GKC_PoolingElementAIList.Clear ();
updateComponent ();
}
public void enableAllGKC_PoolingElementAIOnLevel ()
{
enableOrDisableAllGKC_PoolingElementAIOnLevel (true);
}
public void disableAllGKC_PoolingElementAIOnLevel ()
{
enableOrDisableAllGKC_PoolingElementAIOnLevel (false);
}
public void enableOrDisableAllGKC_PoolingElementAIOnLevel (bool state)
{
for (int i = 0; i < GKC_PoolingElementAIList.Count; i++) {
GKC_PoolingElementAIList [i].checkEventsOnEnableOrDisablePoolingManagementOnObject (state);
}
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Pooling AI Manager " + gameObject.name, gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 175e7e85701b9e54a8cbad931bab9012
timeCreated: 1709264386
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/Pooling System/GKC_PoolingAIManager.cs
uploadId: 814740

View File

@@ -0,0 +1,136 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class GKC_PoolingElement : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool usePoolingEnabled = true;
public GameObject mainPoolGameObject;
[Space]
[Header ("Other Settings")]
[Space]
public Vector3 currentPositionToSpawn;
public Quaternion currentRotationToSpawn;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventOnSpawn;
public UnityEvent eventOnSpawn;
[Space]
public bool useEventOnDespawn;
public UnityEvent eventOnDespawn;
[Space]
[Space]
public UnityEvent eventToEnablePoolManagement;
public UnityEvent eventToDisablePoolManagement;
public void setPositionToSpawn (Vector3 newValue)
{
currentPositionToSpawn = newValue;
}
public void setRotationToSpawn (Quaternion newValue)
{
currentRotationToSpawn = newValue;
}
public virtual void spawnPoolObject ()
{
if (usePoolingEnabled) {
// GKC_PoolingSystem.Spawn (mainPoolGameObject, currentPositionToSpawn, currentRotationToSpawn);
checkEventOnSpawn ();
checkObjectStateAfterSpawn ();
}
}
public virtual void despawnPoolObject ()
{
if (usePoolingEnabled) {
checkObjectStateBeforeDespawn ();
checkEventOnDespawn ();
GKC_PoolingSystem.Despawn (mainPoolGameObject);
}
}
public virtual void checkObjectStateBeforeDespawn ()
{
}
public virtual void checkObjectStateAfterSpawn ()
{
}
public void checkEventOnSpawn ()
{
if (useEventOnSpawn) {
eventOnSpawn.Invoke ();
}
}
public void checkEventOnDespawn ()
{
if (useEventOnDespawn) {
eventOnDespawn.Invoke ();
}
}
public void setUsePoolingEnabledState (bool state)
{
usePoolingEnabled = state;
}
public void checkEventsOnEnableOrDisablePoolingManagementOnObject (bool state)
{
setUsePoolingEnabledState (state);
if (state) {
eventToEnablePoolManagement.Invoke ();
} else {
eventToDisablePoolManagement.Invoke ();
}
if (!Application.isPlaying) {
updateComponent ();
}
}
//EDITOR FUNCTIONS
public void setUsePoolingEnabledStateFromEditor (bool state)
{
setUsePoolingEnabledState (state);
updateComponent ();
}
public void checkEventsOnEnableOrDisablePoolingManagementOnObjectFromEditor (bool state)
{
checkEventsOnEnableOrDisablePoolingManagementOnObject (state);
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update GKC Poolong Element " + gameObject.name, gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 84c6d410c03ec3f4cbdb738cb9716db4
timeCreated: 1702101986
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/Pooling System/GKC_PoolingElement.cs
uploadId: 814740

View File

@@ -0,0 +1,113 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GKC_PoolingElementAI : GKC_PoolingElement
{
[Space]
[Header ("Custom Settings")]
[Space]
public bool setRandomPlayerModeOnSpawnEnabled;
public bool setMainPlayerAsTargetOnSpawnEnabled;
[Space]
[Header ("Components")]
[Space]
public playerController mainPlayerController;
public health mainHealth;
public ragdollActivator mainRagdollActivator;
public findObjectivesSystem mainFindObjectivesSystem;
public AINavMesh mainAINavMesh;
public gravitySystem mainGravitySystem;
public playerStatesManager mainPlayerStatesManager;
public override void checkObjectStateAfterSpawn ()
{
bool characterWasDead = mainHealth.isDead ();
if (characterWasDead) {
mainPlayerController.resetAnimator ();
mainRagdollActivator.setActivateQuickGetUpInsteadOfRegularGetUpState (true);
mainRagdollActivator.setForceQuickGetUpOnCharacterState (true);
mainRagdollActivator.disabledCheckGetUpPaused ();
mainRagdollActivator.setCharacterBodyParentOut ();
mainHealth.resurrectFromExternalCall ();
mainRagdollActivator.setForceQuickGetUpOnCharacterState (false);
}
if (!mainHealth.isDead ()) {
mainFindObjectivesSystem.clearFullEnemiesList ();
mainFindObjectivesSystem.removeCharacterAsTargetOnSameFaction ();
mainFindObjectivesSystem.resetAITargets ();
mainFindObjectivesSystem.removeTargetInfo ();
if (characterWasDead) {
mainHealth.setHealthAmountOnMaxValue ();
}
if (characterWasDead) {
mainPlayerController.setCharacterMeshGameObjectState (true);
mainRagdollActivator.setCharacterBodyActiveState (true);
}
mainAINavMesh.pauseAI (false);
if (setRandomPlayerModeOnSpawnEnabled) {
if (mainPlayerStatesManager.isUseRandomPlayerModeOnStartActive ()) {
mainPlayerStatesManager.checkUseRandomPlayerModeOnStart ();
if (characterWasDead) {
mainPlayerStatesManager.setDefaultPlayersModeAsCurrentOne ();
}
}
}
if (characterWasDead) {
mainFindObjectivesSystem.resetAIToOriginalPosition ();
}
mainFindObjectivesSystem.checkAIBehaviorStateOnCharacterSpawn ();
mainAINavMesh.resetInitialTargetCheckedOnCharacterSpawn ();
if (setMainPlayerAsTargetOnSpawnEnabled) {
Transform newTarget = GKC_Utils.findMainPlayerTransformOnScene ();
if (newTarget != null) {
mainAINavMesh.follow (newTarget);
}
}
mainPlayerController.getRigidbody ().isKinematic = false;
}
}
public override void checkObjectStateBeforeDespawn ()
{
mainAINavMesh.pauseAI (true);
mainRagdollActivator.setModelAndSkeletonParentInsideCharacter ();
mainGravitySystem.setNewParent (mainPoolGameObject.transform);
mainFindObjectivesSystem.checkAIBehaviorStateOnCharacterDespawn ();
mainFindObjectivesSystem.resetAIToOriginalPosition ();
mainPlayerController.getRigidbody ().isKinematic = true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2598ef21f70c260449fb563bc5bc49b2
timeCreated: 1702102628
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/Pooling System/GKC_PoolingElementAI.cs
uploadId: 814740

View File

@@ -0,0 +1,200 @@
using UnityEngine;
using System.Collections.Generic;
public static class GKC_PoolingSystem
{
// You can avoid resizing of the Stack's internal data by
// setting this to a number equal to or greater to what you
// expect most of your pool sizes to be.
// Note, you can also use Preload() to set the initial size
// of a pool -- this can be handy if only some of your pools
// are going to be exceptionally large (for example, your bullets.)
const int DEFAULT_POOL_SIZE = 3;
/// <summary>
/// The Pool class represents the pool for a particular prefab.
/// </summary>
class Pool
{
// We append an id to the name of anything we instantiate.
// This is purely cosmetic.
int nextId = 1;
// The structure containing our inactive objects.
// Why a Stack and not a List? Because we'll never need to
// pluck an object from the start or middle of the array.
// We'll always just grab the last one, which eliminates
// any need to shuffle the objects around in memory.
Stack<GameObject> inactive;
// The prefab that we are pooling
GameObject prefab;
// Constructor
public Pool (GameObject prefab, int initialQty)
{
this.prefab = prefab;
// If Stack uses a linked list internally, then this
// whole initialQty thing is a placebo that we could
// strip out for more minimal code. But it can't *hurt*.
inactive = new Stack<GameObject> (initialQty);
}
// Spawn an object from our pool
public GameObject Spawn (Vector3 pos, Quaternion rot)
{
GameObject obj;
if (inactive.Count == 0) {
// We don't have an object in our pool, so we
// instantiate a whole new object.
obj = (GameObject)GameObject.Instantiate (prefab, pos, rot);
obj.name = prefab.name + " (" + (nextId++) + ")";
// Add a PoolMember component so we know what pool
// we belong to.
obj.AddComponent<PoolMember> ().myPool = this;
} else {
// Grab the last object in the inactive array
obj = inactive.Pop ();
if (obj == null) {
// The inactive object we expected to find no longer exists.
// The most likely causes are:
// - Someone calling Destroy() on our object
// - A scene change (which will destroy all our objects).
// NOTE: This could be prevented with a DontDestroyOnLoad
// if you really don't want this.
// No worries -- we'll just try the next one in our sequence.
return Spawn (pos, rot);
}
}
obj.transform.position = pos;
obj.transform.rotation = rot;
if (!obj.activeSelf) {
obj.SetActive (true);
}
return obj;
}
// Return an object to the inactive pool.
public void Despawn (GameObject obj)
{
if (obj.activeSelf) {
obj.SetActive (false);
}
// Since Stack doesn't have a Capacity member, we can't control
// the growth factor if it does have to expand an internal array.
// On the other hand, it might simply be using a linked list
// internally. But then, why does it allow us to specify a size
// in the constructor? Maybe it's a placebo? Stack is weird.
inactive.Push (obj);
}
}
/// <summary>
/// Added to freshly instantiated objects, so we can link back
/// to the correct pool on despawn.
/// </summary>
class PoolMember : MonoBehaviour
{
public Pool myPool;
}
// All of our pools
static Dictionary< GameObject, Pool > pools;
/// <summary>
/// Initialize our dictionary.
/// </summary>
static void Init (GameObject prefab = null, int qty = DEFAULT_POOL_SIZE)
{
if (pools == null) {
pools = new Dictionary<GameObject, Pool> ();
}
if (prefab != null && pools.ContainsKey (prefab) == false) {
pools [prefab] = new Pool (prefab, qty);
}
}
/// <summary>
/// If you want to preload a few copies of an object at the start
/// of a scene, you can use this. Really not needed unless you're
/// going to go from zero instances to 100+ very quickly.
/// Could technically be optimized more, but in practice the
/// Spawn/Despawn sequence is going to be pretty darn quick and
/// this avoids code duplication.
/// </summary>
public static void Preload (GameObject prefab, int qty = 1)
{
Init (prefab, qty);
// Make an array to grab the objects we're about to pre-spawn.
GameObject[] obs = new GameObject[qty];
for (int i = 0; i < qty; i++) {
obs [i] = Spawn (prefab, Vector3.zero, Quaternion.identity);
}
// Now despawn them all.
for (int i = 0; i < qty; i++) {
Despawn (obs [i]);
}
}
/// <summary>
/// Spawns a copy of the specified prefab (instantiating one if required).
/// NOTE: Remember that Awake() or Start() will only run on the very first
/// spawn and that member variables won't get reset. OnEnable will run
/// after spawning -- but remember that toggling IsActive will also
/// call that function.
/// </summary>
public static GameObject Spawn (GameObject prefab, Vector3 pos, Quaternion rot)
{
Init (prefab);
return pools [prefab].Spawn (pos, rot);
}
public static GameObject Spawn (GameObject prefab, Vector3 pos, Quaternion rot, int qty)
{
Init (prefab, qty);
return pools [prefab].Spawn (pos, rot);
}
/// <summary>
/// Despawn the specified gameobject back into its pool.
/// </summary>
public static void Despawn (GameObject obj)
{
PoolMember pm = obj.GetComponent<PoolMember> ();
if (pm == null) {
// Debug.Log ("Object '" + obj.name + "' wasn't spawned from a pool. Destroying it instead.");
if (GKC_Utils.isApplicationPlaying () && Time.deltaTime > 0) {
// Debug.Log ("DESTROYING");
// obj.SetActive (false);
GameObject.Destroy (obj);
}
} else {
// Debug.Log ("despawn " + obj.name);
pm.myPool.Despawn (obj);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 7548d81c1e9af34409dff8ade7c34183
timeCreated: 1608700611
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/Pooling System/GKC_PoolingSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GKC_SimplePoolPreloadSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool preloadObjectsEnabled = true;
[Space]
[Header ("Object List Settings")]
[Space]
public List<poolObjectPreloadInfo> poolObjectPreloadInfoList = new List<poolObjectPreloadInfo> ();
void Start ()
{
if (preloadObjectsEnabled) {
preloadObjects ();
}
}
public void preloadObjects ()
{
int poolObjectPreloadInfoListCount = poolObjectPreloadInfoList.Count;
for (int i = 0; i < poolObjectPreloadInfoListCount; i++) {
if (poolObjectPreloadInfoList [i].prefabObject != null) {
GKC_PoolingSystem.Preload (poolObjectPreloadInfoList [i].prefabObject, poolObjectPreloadInfoList [i].objectAmount);
}
}
}
[System.Serializable]
public class poolObjectPreloadInfo
{
[Header ("Main Settings")]
[Space]
public GameObject prefabObject;
public int objectAmount;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 70cf8c8c6742f484cb201066b07f9bbb
timeCreated: 1653044920
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/Pooling System/GKC_SimplePoolPreloadSystem.cs
uploadId: 814740