summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/NGS.MeshFusionPro/RuntimeMeshFusion.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-19 16:05:58 +0800
committerchai <215380520@qq.com>2024-05-19 16:05:58 +0800
commit8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (patch)
tree63ef85c460288891f5a593d69afeca16cba050b3 /Thronefall_1_57/Decompile/NGS.MeshFusionPro/RuntimeMeshFusion.cs
parentc5f145786f4c6d2fe4bea831dfc16e52228920a5 (diff)
+1.57
Diffstat (limited to 'Thronefall_1_57/Decompile/NGS.MeshFusionPro/RuntimeMeshFusion.cs')
-rw-r--r--Thronefall_1_57/Decompile/NGS.MeshFusionPro/RuntimeMeshFusion.cs197
1 files changed, 197 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/NGS.MeshFusionPro/RuntimeMeshFusion.cs b/Thronefall_1_57/Decompile/NGS.MeshFusionPro/RuntimeMeshFusion.cs
new file mode 100644
index 0000000..38c811b
--- /dev/null
+++ b/Thronefall_1_57/Decompile/NGS.MeshFusionPro/RuntimeMeshFusion.cs
@@ -0,0 +1,197 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace NGS.MeshFusionPro;
+
+public class RuntimeMeshFusion : MonoBehaviour
+{
+ private static List<RuntimeMeshFusion> _Instances;
+
+ [SerializeField]
+ [HideInInspector]
+ private int _controllerIndex;
+
+ [SerializeField]
+ [HideInInspector]
+ private bool _drawGizmo;
+
+ [SerializeField]
+ [HideInInspector]
+ private int _cellSize = 80;
+
+ [SerializeField]
+ [HideInInspector]
+ private int _maxVerticesPerObject = 40000;
+
+ [SerializeField]
+ [HideInInspector]
+ private MeshType _meshType;
+
+ [SerializeField]
+ [HideInInspector]
+ private MoveMethod _moveMethod = MoveMethod.Jobs;
+
+ private CombineTree _combineTree;
+
+ private bool _sourceAdded;
+
+ private BinaryTreeDrawer<ICombineSource> _treeDrawer;
+
+ public int ControllerIndex
+ {
+ get
+ {
+ return _controllerIndex;
+ }
+ set
+ {
+ if (!Application.isPlaying)
+ {
+ _controllerIndex = value;
+ }
+ }
+ }
+
+ public bool DrawGizmo
+ {
+ get
+ {
+ return _drawGizmo;
+ }
+ set
+ {
+ _drawGizmo = value;
+ }
+ }
+
+ public int CellSize
+ {
+ get
+ {
+ return _cellSize;
+ }
+ set
+ {
+ if (!Application.isPlaying)
+ {
+ _cellSize = Mathf.Max(1, value);
+ }
+ }
+ }
+
+ public int MaxVertices
+ {
+ get
+ {
+ return _maxVerticesPerObject;
+ }
+ set
+ {
+ if (!Application.isPlaying)
+ {
+ _maxVerticesPerObject = Mathf.Clamp(value, 500, 65000);
+ }
+ }
+ }
+
+ public MeshType MeshType
+ {
+ get
+ {
+ return _meshType;
+ }
+ set
+ {
+ if (!Application.isPlaying)
+ {
+ _meshType = value;
+ }
+ }
+ }
+
+ public MoveMethod MoveMethod
+ {
+ get
+ {
+ return _moveMethod;
+ }
+ set
+ {
+ if (!Application.isPlaying)
+ {
+ _moveMethod = value;
+ }
+ }
+ }
+
+ private void Awake()
+ {
+ if (_Instances == null)
+ {
+ _Instances = new List<RuntimeMeshFusion>();
+ }
+ _Instances.Add(this);
+ ICombinedMeshFactory factory = new CombinedMeshFactory(_meshType, CombineMethod.Simple, _moveMethod);
+ _combineTree = new CombineTree(factory, _cellSize, _maxVerticesPerObject);
+ _treeDrawer = new BinaryTreeDrawer<ICombineSource>();
+ Transform parent = new GameObject("CombinedObjects").transform;
+ _combineTree.onStaticCombinedObjectCreated += delegate(CombinedObject r)
+ {
+ r.transform.parent = parent;
+ };
+ _combineTree.onDynamicCombinedObjectCreated += delegate(DynamicCombinedObject r)
+ {
+ r.transform.parent = parent;
+ };
+ _combineTree.onCombinedLODGroupCreated += delegate(CombinedLODGroup r)
+ {
+ r.transform.parent = parent;
+ };
+ }
+
+ private void Update()
+ {
+ if (_sourceAdded)
+ {
+ _combineTree.Combine();
+ _sourceAdded = false;
+ }
+ }
+
+ private void OnDrawGizmos()
+ {
+ if (Application.isPlaying && _drawGizmo && _combineTree != null && _combineTree.Root != null)
+ {
+ _treeDrawer.DrawGizmo(_combineTree.Root, Color.white);
+ }
+ }
+
+ private void OnDestroy()
+ {
+ _Instances.Remove(this);
+ }
+
+ public static RuntimeMeshFusion FindByIndex(int index)
+ {
+ for (int i = 0; i < _Instances.Count; i++)
+ {
+ RuntimeMeshFusion runtimeMeshFusion = _Instances[i];
+ if (runtimeMeshFusion.ControllerIndex == index)
+ {
+ return runtimeMeshFusion;
+ }
+ }
+ throw new KeyNotFoundException("MeshFusionController with index : " + index + " not found");
+ }
+
+ public void AddSource(ICombineSource source)
+ {
+ _combineTree.Add(source);
+ _sourceAdded = true;
+ }
+
+ public void RemoveSource(ICombineSource source)
+ {
+ _combineTree.Remove(source);
+ }
+}