### Pool Management Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html An example demonstrating the basic usage of the Lean Pool system, including initialization, getting, and returning objects. ```csharp public class PoolManager : MonoBehaviour { public GameObject cubePrefab; void Start() { LeanPool.InitPool(cubePrefab); } void Update() { if (Input.GetKeyDown(KeyCode.G)) { LeanPool.Get(cubePrefab); } if (Input.GetKeyDown(KeyCode.R)) { GameObject cubeToReturn = GameObject.Find(cubePrefab.name); if (cubeToReturn != null) { LeanPool.Return(cubeToReturn); } } } } ``` -------------------------------- ### Basic Object Pooling Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates the fundamental usage of the Lean Pool for creating and getting objects. Ensure the 'Pool' class is accessible. ```csharp using Lean.Pool; public class Example : MonoBehaviour { public int PoolSize = 10; private void Start() { // Create a pool of GameObjects with a specific size var pool = new Pool(PoolSize, CreateGameObject, OnGetGameObject, OnReleaseGameObject, OnDestroyGameObject); // Get an object from the pool var instance = pool.Get(); // Use the instance... // Release the object back to the pool pool.Release(instance); } private GameObject CreateGameObject() { // Factory method to create new GameObjects var instance = new GameObject("PooledObject"); return instance; } private void OnGetGameObject(GameObject instance) { // Called when an object is retrieved from the pool instance.SetActive(true); } private void OnReleaseGameObject(GameObject instance) { // Called when an object is returned to the pool instance.SetActive(false); } private void OnDestroyGameObject(GameObject instance) { // Called when the pool needs to destroy an object Destroy(instance); } } ``` -------------------------------- ### Basic Pool Usage Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html A simple example demonstrating how to create a pool, spawn an object, and then despawn it. ```csharp public class Example : MonoBehaviour { public GameObject prefab; private Pool pool; void Start() { this.pool = Pool.Create(this.prefab); GameObject spawnedObject = this.pool.Spawn(); // Use the spawnedObject... this.pool.Despawn(spawnedObject); } } ``` -------------------------------- ### Pool Example Usage Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html A comprehensive example demonstrating the creation, spawning, and despawning of objects using LeanPool. ```csharp public class Example : MonoBehaviour { public GameObject Prefab; void Start() { // Create a pool with capacity 10 and Self reset mode var pool = LeanPool.Create(10, LeanPool.ResetMode.Self); // Spawn an object var instance = LeanPool.Spawn(Prefab, transform.position, transform.rotation); // Despawn the object after 5 seconds LeanPool.Despawn(instance, 5f); } } ``` -------------------------------- ### Template Syntax Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Doc/custom_generate.md Demonstrates the template syntax for custom code generation, including eval, code, and literal elements. This example shows how to iterate over assembly information and types to generate XML. ```xml <% require "TemplateCommon" %> <%ForEachCsList(assembly_infos, function(assembly_info) %> <%ForEachCsList(assembly_info.Types, function(type) %> <%end)%> <%end)%> ``` -------------------------------- ### Basic Pool Creation and Usage Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates how to create a pool and use its basic functions like Get and Release. ```csharp using UnityEngine; public class Example : MonoBehaviour { public PoolableObject prefab; private Pool pool; void Awake() { pool = new Pool(prefab.gameObject); } void Start() { var instance = pool.Get(); instance.transform.position = Vector3.zero; } void Update() { if (Input.GetKeyDown(KeyCode.Space)) { var instance = pool.Get(); instance.transform.position = Random.insideUnitSphere * 5; } } void OnDestroy() { pool.Release(transform); } } ``` -------------------------------- ### Example GetTasks Implementation for link.xml Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Doc/Custom_Generate_EN.md This C# implementation of GetTasks prepares data for the link.xml template and specifies the output stream. ```csharp public static IEnumerable GetTasks(LuaEnv lua_env, UserConfig user_cfg) { LuaTable data = lua_env.NewTable(); var assembly_infos = (from type in user_cfg.ReflectionUse group type by type.Assembly.GetName().Name into assembly_info select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList(); data.Set("assembly_infos", assembly_infos); yield return new CustomGenTask { Data = data, Output = new StreamWriter(GeneratorConfig.common_path + "/link.xml", false, Encoding.UTF8) }; } ``` -------------------------------- ### Pool Initialization with Capacity Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Example of initializing a pool with a specific capacity. This pre-allocates a set number of objects. ```csharp public static Pool Create(T prefab, int capacity) where T : Object { return new Pool(prefab, capacity); } ``` -------------------------------- ### Basic Object Pooling Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates the fundamental usage of object pooling for creating and resetting objects. Ensure the 'Pool' class is imported. ```csharp public class Pool { private Stack m_pool = new Stack(); private Func m_constructor; private Action m_reset; private Action m_destroy; public Pool(Func constructor, Action reset = null, Action destroy = null) { m_constructor = constructor; m_reset = reset; m_destroy = destroy; } public object Spawn(object owner = null) { object obj; if (m_pool.Count > 0) { obj = m_pool.Pop(); } else { obj = m_constructor(); } if (m_reset != null) { m_reset(obj); } return obj; } public void Despawn(object obj) { if (m_destroy != null) { m_destroy(obj); } if (m_reset != null) { m_reset(obj); } m_pool.Push(obj); } } ``` -------------------------------- ### Lua Coroutine Runner Setup Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Examples/06_Coroutine/Resources/cs_coroutine.lua.txt Sets up a GameObject and a C# Coroutine_Runner component to manage Lua-driven coroutines. This script should be run once at the start of the application. ```lua local util = require 'xlua.util' local gameobject = CS.UnityEngine.GameObject('Coroutine_Runner') CS.UnityEngine.Object.DontDestroyOnLoad(gameobject) local cs_coroutine_runner = gameobject:AddComponent(typeof(CS.XLuaTest.Coroutine_Runner)) return { start = function(...) return cs_coroutine_runner:StartCoroutine(util.cs_generator(...)) end; stop = function(coroutine) cs_coroutine_runner:StopCoroutine(coroutine) end } ``` -------------------------------- ### Start and Manage Coroutines with xLua Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Examples/06_Coroutine/Resources/coruntine_test.lua.txt Starts a main coroutine 'a' that includes nested coroutines and yields. It also starts another coroutine to stop 'a' after a delay. ```lua local cs_coroutine = (require 'cs_coroutine') local a = cs_coroutine.start(function() print('coroutine a started') coroutine.yield(cs_coroutine.start(function() print('coroutine b stated inside cotoutine a') coroutine.yield(CS.UnityEngine.WaitForSeconds(1)) print('i am coroutine b') end)) print('coroutine b finish') while true do coroutine.yield(CS.UnityEngine.WaitForSeconds(1)) print('i am coroutine a') end end) cs_coroutine.start(function() print('stop coroutine a after 5 seconds') coroutine.yield(CS.UnityEngine.WaitForSeconds(5)) cs_coroutine.stop(a) print('coroutine a stoped') end) ``` -------------------------------- ### Install xNode with Unity Package Manager Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/xNode-1.8.0/README.md Add this line to your project's manifest.json to install xNode as a Git dependency. Requires Unity version 2018.3.0b7 or above and Git installed. ```json "com.github.siccity.xnode": "https://github.com/siccity/xNode.git" ``` -------------------------------- ### Pooling Prefabs with Custom Initialization Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Illustrates how to provide custom initialization logic when spawning objects from the pool. ```csharp public static void Example() { var obj = LeanPool.Spawn(prefab, (spawnedObj) => { // Custom initialization logic here spawnedObj.GetComponent().Initialize(); }); LeanPool.Despawn(obj); } ``` -------------------------------- ### Basic Lean Pool Usage Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Replace Instantiate with LeanPool.Spawn and Destroy with LeanPool.Despawn for object pooling. This example shows spawning an enemy prefab and despawning it later. ```csharp var enemy = Lean.Pool.LeanPool.Spawn(enemyPrefab); ... Lean.Pool.LeanPool.Despawn(enemy); ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Custom Options Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates pooling a prefab instance using LeanPoolOptions for spawn parameters. ```csharp public static void Example() { var instance = Instantiate(prefab); var options = new LeanPoolOptions { Position = Vector3.up, Rotation = Quaternion.Euler(0, 90, 0) }; var obj = LeanPool.Spawn(instance, options); LeanPool.Despawn(obj); } ``` -------------------------------- ### Get Value from LuaTable by Path Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Doc/XLua_API_EN.md Retrieves a value from a nested LuaTable using a dot-separated path. This is more efficient than multiple Get calls for nested structures. ```csharp T GetInPath(string path) ``` -------------------------------- ### C# Indexer Get Implementation Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt Generates C# code for handling Lua access to C# indexers (get operation). It casts the key argument and retrieves the value from the indexer. ```csharp <%=GetCasterStatement(keyType, 2, "key", true)%>; <%=GetPushStatement(overload.ReturnType, "gen_to_be_invoked[key]")%>; ``` -------------------------------- ### Spawning with Options Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates spawning an object using a LeanPoolOptions object for fine-grained control over spawn parameters. ```csharp public static void Example() { var options = new LeanPoolOptions { Position = Vector3.zero, Rotation = Quaternion.identity, Parent = parent, Global = true }; var obj = LeanPool.Spawn(prefab, options); LeanPool.Despawn(obj); } ``` -------------------------------- ### Node Example: MathNode Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/xNode-1.8.0/README.md Example of a custom node class deriving from Node. Fields marked with [Input] or [Output] become ports. The GetValue method calculates and returns output values. ```csharp // public classes deriving from Node are registered as nodes for use within a graph public class MathNode : Node { // Adding [Input] or [Output] is all you need to do to register a field as a valid port on your node [Input] public float a; [Input] public float b; // The value of an output node field is not used for anything, but could be used for caching output results [Output] public float result; [Output] public float sum; // The value of 'mathType' will be displayed on the node in an editable format, similar to the inspector public MathType mathType = MathType.Add; public enum MathType { Add, Subtract, Multiply, Divide} // GetValue should be overridden to return a value for any specified output port public override object GetValue(NodePort port) { // Get new a and b values from input connections. Fallback to field values if input is not connected float a = GetInputValue("a", this.a); float b = GetInputValue("b", this.b); // After you've gotten your input values, you can perform your calculations and return a value if (port.fieldName == "result") switch(mathType) { case MathType.Add: default: return a + b; case MathType.Subtract: return a - b; case MathType.Multiply: return a * b; case MathType.Divide: return a / b; } else if (port.fieldName == "sum") return a + b; else return 0f; } } ``` -------------------------------- ### C# Type Pushing and Getting Initialization Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt Initializes the process for pushing and getting C# value types and optimized tables. This includes registering an initializer that sets up type IDs and casters. ```csharp #if USE_UNI_LUA using LuaAPI = UniLua.Lua; using RealStatePtr = UniLua.ILuaState; using LuaCSFunction = UniLua.CSharpFunctionDelegate; #else using LuaAPI = XLua.LuaDLL.Lua; using RealStatePtr = System.IntPtr; using LuaCSFunction = XLua.LuaDLL.lua_CSFunction; #endif using System; <%= require "TemplateCommon" %> namespace XLua { public partial class ObjectTranslator { <%if purevaluetypes.Count > 0 then local init_class_name = "IniterAdder" .. CSVariableName(purevaluetypes[0].Type) %> class <%=init_class_name%> { static <%=init_class_name%>() { LuaEnv.AddIniter(Init); } static void Init(LuaEnv luaenv, ObjectTranslator translator) { <%ForEachCsList(purevaluetypes, function(type_info) if not type_info.Type.IsValueType then return end local full_type_name = CsFullTypeName(type_info.Type)%> translator.RegisterPushAndGetAndUpdate<<%=full_type_name%>>(<%=translator.Push<%=CSVariableName(type_info.Type)%>, translator.Get, translator.Update<%=CSVariableName(type_info.Type)%>); <% end) %> <%ForEachCsList(tableoptimzetypes, function(type_info) local full_type_name = CsFullTypeName(type_info.Type)%> translator.RegisterCaster<<%=full_type_name%>>(<%=translator.Get%>); <% end) %> } } static <%=init_class_name%> s_<%=init_class_name%>_dumb_obj = new <%=init_class_name%>(); static <%=init_class_name%> <%=init_class_name%>_dumb_obj {get{return s_<%=init_class_name%>_dumb_obj;}} <%end%> ``` -------------------------------- ### Basic Object Pooling Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates the fundamental usage of the Lean Pool system for creating and retrieving pooled objects. Ensure the 'LeanPool' class is accessible in your project. ```csharp public static void Example() { var obj = LeanPool.Spawn(prefab, Vector3.zero, Quaternion.identity); LeanPool.Despawn(obj); } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Shows the basic process of instantiating a prefab before pooling it. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance); LeanPool.Despawn(obj); } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Custom Despawn Logic with Destroy and Delay and Global and Parent and Options Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Illustrates pooling a prefab instance with all possible custom despawn configurations. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance); var options = new LeanPoolOptions { Delay = 2f, Destroy = true, Global = true, Parent = parent }; LeanPool.Despawn(obj, options, (despawnedObj) => { Debug.Log("Full custom despawn for instantiated object."); }); } ``` -------------------------------- ### Player.ControllerHelper.MapHelper.ButtonMapsWithAction Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/Plugins/Rewired/Documentation/ReleaseNotes.txt Gets all button maps for an action. ```APIDOC ## Player.ControllerHelper.MapHelper.ButtonMapsWithAction ### Description Gets all button maps for a specific action. ### Method `IEnumerable Player.ControllerHelper.MapHelper.ButtonMapsWithAction(ControllerType controllerType, int controllerId, int actionId, bool skipDisabledMaps)` `IEnumerable Player.ControllerHelper.MapHelper.ButtonMapsWithAction(ControllerType controllerType, int controllerId, string actionName, bool skipDisabledMaps)` ``` -------------------------------- ### Controller.elementCount Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/Plugins/Rewired/Documentation/ReleaseNotes.txt Gets the number of elements on a controller. ```APIDOC ## Controller.elementCount ### Description Gets the number of elements on the controller. ### Property `int Controller.elementCount { get; }` ``` -------------------------------- ### Creating a Pool with Specific Size Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates creating a pool with a predefined initial size. This can help pre-allocate resources and avoid initial instantiation spikes. ```csharp public static void Example() { var pool = LeanPool.CreatePool(prefab, 10); var obj = LeanPool.Spawn(pool); LeanPool.Despawn(obj); } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Custom Despawn Logic with Destroy and Delay and Global and Parent and Options and Tag Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates pooling a prefab instance with all possible custom despawn configurations including tagging. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance); LeanPool.AddTag(obj, "MyTag"); var options = new LeanPoolOptions { Delay = 2f, Destroy = true, Global = true, Parent = parent }; LeanPool.Despawn(obj, options, (despawnedObj) => { Debug.Log("Full custom despawn with tag for instantiated object."); }); } ``` -------------------------------- ### Player.ControllerHelper.MapHelper.GetFirstButtonMapWithAction Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/Plugins/Rewired/Documentation/ReleaseNotes.txt Gets the first button map for an action. ```APIDOC ## Player.ControllerHelper.MapHelper.GetFirstButtonMapWithAction ### Description Gets the first button map for a specific action. ### Method `ButtonMap Player.ControllerHelper.MapHelper.GetFirstButtonMapWithAction(ControllerType controllerType, int controllerId, int actionId, bool skipDisabledMaps)` `ButtonMap Player.ControllerHelper.MapHelper.GetFirstButtonMapWithAction(ControllerType controllerType, int controllerId, string actionName, bool skipDisabledMaps)` ``` -------------------------------- ### Mouse.screenPositionDelta Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/Plugins/Rewired/Documentation/ReleaseNotes.txt Gets the screen position delta of the mouse. ```APIDOC ## Mouse.screenPositionDelta ### Description Gets the screen position delta of the mouse. ### Property `Vector2 Mouse.screenPositionDelta { get; }` ``` -------------------------------- ### Mouse.screenPositionPrev Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/Plugins/Rewired/Documentation/ReleaseNotes.txt Gets the previous screen position of the mouse. ```APIDOC ## Mouse.screenPositionPrev ### Description Gets the previous screen position of the mouse. ### Property `Vector2 Mouse.screenPositionPrev { get; }` ``` -------------------------------- ### Creating a Pool with Size and Capacity Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Shows how to create a pool with both an initial size and a maximum capacity. This prevents the pool from growing indefinitely. ```csharp public static void Example() { var pool = LeanPool.CreatePool(prefab, 10, 20); var obj = LeanPool.Spawn(pool); LeanPool.Despawn(obj); } ``` -------------------------------- ### Get C# Object from Lua Table with Field Iteration Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt Retrieves a C# object from Lua, handling both userdata and table types. For tables, it iterates through fields, recursively calling 'Get' to populate the C# object. Supports null assignment for non-value types. ```csharp public void Get(RealStatePtr L, int index, out <%=full_type_name%> val) { LuaTypes type = LuaAPI.lua_type(L, index); if (type == LuaTypes.LUA_TUSERDATA ) { val = (<%=full_type_name%>)FastGetCSObj(L, index); } else if (type == LuaTypes.LUA_TTABLE) { val = new <%=full_type_name%>(); int top = LuaAPI.lua_gettop(L); <%ForEachCsList(type_info.Fields, function(fieldInfo)%> if (Utils.LoadField(L, index, "<%=fieldInfo.Name%>\"")) { Get(L, top + 1, out val.<%=fieldInfo.Name%>); } LuaAPI.lua_pop(L, 1); <%end) %> }<%if not type_info.Type.IsValueType then%> else if (type == LuaTypes.LUA_TNIL || type == LuaTypes.LUA_TNONE) { val = null; }<%end%> else { throw new Exception("can not cast " + LuaAPI.lua_type(L, index) + " to " + typeof(<%=full_type_name%>)); } } ``` -------------------------------- ### Pool with Pre-warming Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Shows how to pre-warm a pool with a specified number of objects. ```csharp using UnityEngine; public class ExamplePrewarm : MonoBehaviour { public PoolableObject prefab; private Pool pool; void Awake() { pool = new Pool(prefab.gameObject, 10); } void Start() { var instance = pool.Get(); instance.transform.position = Vector3.zero; } } ``` -------------------------------- ### Keyboard.GetKeyName Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/Plugins/Rewired/Documentation/ReleaseNotes.txt Gets the name of a key with optional modifier flags. ```APIDOC ## Keyboard.GetKeyName ### Description Gets the name of a key, with optional modifier flags. ### Method `string Keyboard.GetKeyName(KeyCode key, ModifierKeyFlags flags)` ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Custom Despawn Logic with Delay Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates pooling a prefab instance, waiting, and then executing custom despawn logic. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance); LeanPool.Despawn(obj, 1.5f, (despawnedObj) => { Debug.Log("Custom despawn after delay for instantiated object."); }); } ``` -------------------------------- ### ActionElementMap.controllerMap Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/Plugins/Rewired/Documentation/ReleaseNotes.txt Gets the Controller Map this Action Element Map belongs to. ```APIDOC ## ActionElementMap.controllerMap ### Description Gets the Controller Map this Action Element Map belongs to. ### Property `ControllerMap ActionElementMap.controllerMap { get; }` ``` -------------------------------- ### Hotfix C# Class Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Doc/hotfix.md Defines a C# class with overloaded methods that will be hotfixed. ```csharp using UnityEngine; // 要fix的C#类 [Hotfix] public class HotfixCalc { public int Add(int a, int b) { return a - b; } public Vector3 Add(Vector3 a, Vector3 b) { return a - b; } } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Custom Despawn Logic with Destroy and Delay and Global Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates pooling a prefab instance, waiting, executing custom despawn logic, destroying it, and marking it as global. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance); LeanPool.Despawn(obj, 2f, true, true, (despawnedObj) => { Debug.Log("Custom despawn, destroy, delay, and global for instantiated object."); }); } ``` -------------------------------- ### Get All Active Pools Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Retrieves a list of all active and enabled LeanGameObjectPool instances in the scene. ```C# public static LinkedList Instances { get; } { // Implementation details } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Custom Despawn Logic Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Illustrates pooling a prefab instance and using custom despawn logic. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance); LeanPool.Despawn(obj, (despawnedObj) => { Debug.Log("Custom despawn for instantiated object."); }); } ``` -------------------------------- ### Lua Environment Setup Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt Includes the Lua require statement for template common utilities. ```lua <% require "TemplateCommon" %> ``` -------------------------------- ### Using LeanPool with ScriptableObjects Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates how to use LeanPool with ScriptableObjects, allowing for configuration data to be managed via assets. ```csharp public class MyScriptableObject : ScriptableObject { public GameObject prefab; public void SpawnObject() { LeanPool.Spawn(prefab); } } ``` -------------------------------- ### C# Class for Hotfix Example Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/XLua/Doc/Hotfix_EN.md This C# class demonstrates a method that will be hotfixed using Lua. ```csharp public class HotfixCalc { public int Add(int a, int b) { return a - b; } public Vector3 Add(Vector3 a, Vector3 b) { return a - b; } } ``` -------------------------------- ### Initialize Object Pool Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates how to initialize an object pool with a specific prefab. This is a fundamental step before using the pool. ```csharp public static void InitPool(GameObject prefab) { if (prefab == null) { Debug.LogError("Prefab is null."); return; } if (Pool.ContainsKey(prefab.name)) { Debug.LogWarning("Pool already contains prefab: " + prefab.name); return; } Pool.Add(prefab.name, new Stack()); } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Global Setting with Delay Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates pooling a global prefab instance and despawning it after a delay. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance, Vector3.zero, Quaternion.identity, null, true); LeanPool.Despawn(obj, 2f, true, true); } ``` -------------------------------- ### Spawn an Object from Pool Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Get an object from the pool. If the pool is empty, it will create a new instance. ```csharp public T Spawn() { T obj; if (this.freeObjects.Count > 0) { obj = this.freeObjects.Pop(); } else { obj = Object.Instantiate(this.prefab); this.allObjects.Add(obj); } this.activeObjects.Add(obj); return obj; } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Options Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Combines prefab instantiation with LeanPool options for spawning. ```csharp public static void Example() { var instance = Instantiate(prefab); var options = new LeanPoolOptions { Position = Vector3.one }; var obj = LeanPool.Spawn(instance, options); LeanPool.Despawn(obj); } ``` -------------------------------- ### Pool with Pre-allocated Capacity Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Example of creating a pool with a specific initial capacity to avoid frequent allocations. ```csharp public class Example : MonoBehaviour { public GameObject prefab; private Pool pool; void Start() { this.pool = Pool.Create(this.prefab, 10); // ... use the pool ... } } ``` -------------------------------- ### Pooling Prefabs with Prefab Instantiation and Custom Despawn Logic with Destroy and Delay and Global and Parent Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Shows pooling a prefab instance, waiting, executing custom despawn logic, destroying it, marking it global, and setting its parent. ```csharp public static void Example() { var instance = Instantiate(prefab); var obj = LeanPool.Spawn(instance); LeanPool.Despawn(obj, 2f, true, true, parent, (despawnedObj) => { Debug.Log("Custom despawn, destroy, delay, global, and parent for instantiated object."); }); } ``` -------------------------------- ### Get Object from Pool Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Retrieves an object from the pool. If the pool is empty, it creates a new instance of the prefab. ```csharp public static GameObject Get(GameObject prefab) { if (prefab == null) { Debug.LogError("Prefab is null."); return null; } InitPool(prefab); GameObject obj; if (Pool[prefab.name].Count > 0) { obj = Pool[prefab.name].Pop(); } else { obj = Object.Instantiate(prefab); obj.name = prefab.name; } obj.SetActive(true); return obj; } ``` -------------------------------- ### Custom Pool Configuration Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Shows how to configure a custom pool using LeanPool.CreatePool with specific settings for initial size, capacity, and despawn options. ```csharp public static void Example() { var options = new LeanPoolOptions { MaxStackSize = 10, DespawnOnSceneLoad = false }; var pool = LeanPool.CreatePool(prefab, 5, 15, options); } ``` -------------------------------- ### Pooling Prefabs with Asset Bundles Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Shows how to pool prefabs loaded from Asset Bundles. ```csharp public static void Example() { // Assuming assetBundle and prefabName are loaded correctly // var prefab = assetBundle.LoadAsset(prefabName); // var obj = LeanPool.Spawn(prefab); // LeanPool.Despawn(obj); } ``` -------------------------------- ### Get and Release Pooled Objects Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Demonstrates how to retrieve an object from the pool and return it. Ensure the pool is initialized before use. ```C# public static T Get() where T : Component { return Get(typeof(T)); } public static T Get(string id) where T : Component { return Get(id, typeof(T)); } public static Component Get(Type type) { return Get("", type); } public static Component Get(string id, Type type) { var prefab = GetPrefab(id, type); if (prefab == null) { return null; } return Get(prefab); } public static T Get(GameObject prefab) { return Get(prefab).GetComponent(); } public static GameObject Get(GameObject prefab) { if (prefab == null) { return null; } var pool = GetPool(prefab.GetHashCode()); if (pool == null) { pool = CreatePool(prefab); } return pool.Get(); } public static void Release(T component) where T : Component { Release(component.gameObject); } public static void Release(GameObject instance) { if (instance == null) { return; } var pool = GetPool(instance.GetHashCode()); if (pool == null) { Object.Destroy(instance); return; } pool.Release(instance); } public static void Clear() { foreach (var pool in pools.Values) { pool.Clear(); } pools.Clear(); } ``` -------------------------------- ### Getting Pool Size Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Retrieves the current number of active objects in a specific pool. This can be used for monitoring or debugging. ```csharp public static void Example() { var count = LeanPool.GetPoolSize(prefab); Debug.Log("Pool size: " + count); } ``` -------------------------------- ### Advanced Pool Initialization Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Shows how to initialize a pool with a specific prefab and a custom transform to act as the pool's parent in the hierarchy. ```csharp public static void InitPool(GameObject prefab, Transform parent) { if (prefab == null) { Debug.LogError("Prefab is null."); return; } if (Pool.ContainsKey(prefab.name)) { Debug.LogWarning("Pool already contains prefab: " + prefab.name); return; } Pool.Add(prefab.name, new Stack()); if (parent != null) { GameObject poolContainer = new GameObject(prefab.name + "_Pool"); poolContainer.transform.SetParent(parent); } } ``` -------------------------------- ### Pool Reset Mode Property Source: https://github.com/manhua-man/fork_jynew/blob/main/jyx2/Assets/3rd/Lean/Pool/Documentation/Documentation.html Gets or sets the reset mode for the pool. This determines how objects are reset when despawned. ```csharp pool.ResetMode; ```