1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace NGS.MeshFusionPro;
public class DynamicCombinedObject : MonoBehaviour, ICombinedObject<DynamicCombinedObjectPart, DynamicCombineSource>, ICombinedObject
{
private CombinedObject _baseObject;
private List<DynamicCombinedObjectPart> _parts;
private ICombinedMeshMover _meshMover;
private List<DynamicCombinedObjectPartInternal> _movedParts;
private List<PartMoveInfo> _movedPartsData;
private bool _partsMoved;
IReadOnlyList<ICombinedObjectPart> ICombinedObject.Parts => _parts;
public IReadOnlyList<DynamicCombinedObjectPart> Parts => _parts;
public RendererSettings RendererSettings => _baseObject.RendererSettings;
public Bounds Bounds => _baseObject.Bounds;
public Bounds LocalBounds => _baseObject.LocalBounds;
public int VertexCount => _baseObject.VertexCount;
private void Update()
{
if (_movedParts.Count > 0)
{
if (_meshMover is IAsyncCombinedMeshMover asyncCombinedMeshMover)
{
asyncCombinedMeshMover.MovePartsAsync(_movedPartsData);
}
else
{
_meshMover.MoveParts(_movedPartsData);
}
for (int i = 0; i < _movedParts.Count; i++)
{
_movedParts[i].PositionUpdated();
}
_movedParts.Clear();
_movedPartsData.Clear();
_partsMoved = true;
}
}
private void LateUpdate()
{
if (_partsMoved)
{
if (_meshMover is IAsyncCombinedMeshMover asyncCombinedMeshMover)
{
asyncCombinedMeshMover.FinishAsyncMoving();
}
_meshMover.ApplyData();
_partsMoved = false;
}
_baseObject.ForceUpdate();
if (_movedParts.Count == 0)
{
base.enabled = false;
}
}
private void OnDestroy()
{
if (_meshMover is IDisposable disposable)
{
disposable.Dispose();
}
}
public static DynamicCombinedObject Create(MeshType meshType, CombineMethod combineMethod, MoveMethod moveMethod, RendererSettings settings)
{
return Create(new CombinedMeshFactory(meshType, combineMethod, moveMethod), settings);
}
public static DynamicCombinedObject Create(ICombinedMeshFactory factory, RendererSettings settings)
{
ICombinedMeshMover mover;
CombinedObject combinedObject = CombinedObject.Create(factory.CreateMovableCombinedMesh(out mover), settings);
DynamicCombinedObject dynamicCombinedObject = combinedObject.gameObject.AddComponent<DynamicCombinedObject>();
dynamicCombinedObject.Construct(combinedObject, mover);
return dynamicCombinedObject;
}
private void Construct(CombinedObject baseObject, ICombinedMeshMover mover)
{
base.gameObject.name = "Dynamic Combined Object";
_baseObject = baseObject;
_meshMover = mover;
_parts = new List<DynamicCombinedObjectPart>();
_movedParts = new List<DynamicCombinedObjectPartInternal>();
_movedPartsData = new List<PartMoveInfo>();
_baseObject.Updating = false;
}
public void Combine(IEnumerable<ICombineSource> sources)
{
Combine(sources.Select((ICombineSource s) => (DynamicCombineSource)s));
}
public void Combine(IEnumerable<DynamicCombineSource> sources)
{
int num = sources.Count();
CombineSource[] array = new CombineSource[num];
_ = new DynamicCombinedObjectPart[num];
int num2 = 0;
foreach (DynamicCombineSource source in sources)
{
CombineSource baseSource = source.Base;
array[num2++] = baseSource;
baseSource.onCombinedTyped += delegate(CombinedObject root, CombinedObjectPart part)
{
DynamicCombinedObjectPart dynamicCombinedObjectPart = new DynamicCombinedObjectPartInternal(this, part, baseSource.CombineInfo.transformMatrix);
_parts.Add(dynamicCombinedObjectPart);
source.Combined(this, dynamicCombinedObjectPart);
};
baseSource.onCombineErrorTyped += delegate(CombinedObject root, string message)
{
source.CombineError(this, message);
};
baseSource.onCombineFailedTyped += delegate
{
source.CombineFailed(this);
};
}
_baseObject.Combine(array);
}
public void UpdatePart(DynamicCombinedObjectPartInternal part)
{
_movedParts.Add(part);
_movedPartsData.Add(part.CreateMoveInfo());
base.enabled = true;
}
public void Destroy(DynamicCombinedObjectPart dynamicPart, CombinedObjectPart basePart)
{
if (_parts.Remove(dynamicPart))
{
basePart.Destroy();
base.enabled = true;
}
}
}
|