blob: 6cf22994fd1d0e86949e4b362a4393a44ccc23a9 (
plain)
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 UnityEngine;
namespace NGS.MeshFusionPro;
public abstract class ObjectsCombiner<TCombinedObject, TCombineSource> where TCombinedObject : ICombinedObject where TCombineSource : ICombineSource
{
private List<TCombinedObject> _combinedObjects;
private List<TCombineSource> _sources;
private List<TCombineSource> _sourcesForCombine;
public IReadOnlyList<TCombinedObject> CombinedObjects => _combinedObjects;
public bool ContainSources => _sources.Count > 0;
public event Action<TCombinedObject> onCombinedObjectCreated;
protected ObjectsCombiner()
{
_sources = new List<TCombineSource>();
_combinedObjects = new List<TCombinedObject>();
_sourcesForCombine = new List<TCombineSource>();
}
public virtual void AddSource(TCombineSource source)
{
_sources.Add(source);
}
public void AddSources(IEnumerable<TCombineSource> sources)
{
foreach (TCombineSource source in sources)
{
AddSource(source);
}
}
public void RemoveSource(TCombineSource source)
{
_sources.Remove(source);
}
public void Combine()
{
if (_sources.Count != 0)
{
CleanEmptyData();
CombineInternal();
_sources.Clear();
}
}
private void CleanEmptyData()
{
int num = 0;
while (num < _combinedObjects.Count)
{
if (_combinedObjects[num] == null)
{
_combinedObjects.RemoveAt(num);
}
else
{
num++;
}
}
num = 0;
while (num < _sources.Count)
{
if (_sources[num] == null)
{
_sources.RemoveAt(num);
}
else
{
num++;
}
}
}
private void CombineInternal()
{
_sourcesForCombine.Clear();
int num = 0;
while (num <= _combinedObjects.Count && _sources.Count != 0)
{
bool flag = false;
TCombinedObject val;
if (num == _combinedObjects.Count)
{
try
{
val = CreateCombinedObject(_sources[0]);
_combinedObjects.Add(val);
flag = true;
}
catch (Exception ex)
{
Debug.Log("Unable to create CombinedObject : " + ex.Message + ex.StackTrace);
_sources.RemoveAt(0);
continue;
}
}
else
{
val = _combinedObjects[num];
}
CombinedObjectMatcher<TCombinedObject, TCombineSource> matcher = GetMatcher();
matcher.StartMatching(val);
int num2 = 0;
while (num2 < _sources.Count)
{
TCombineSource val2 = _sources[num2];
if (matcher.CanAddSource(val2))
{
_sourcesForCombine.Add(val2);
matcher.SourceAdded(val2);
_sources.RemoveAt(num2);
}
else
{
num2++;
}
}
if (_sourcesForCombine.Count > 0)
{
try
{
CombineSources(val, _sourcesForCombine);
_sourcesForCombine.Clear();
}
catch (Exception ex2)
{
Debug.Log("Unable to combine sources in ObjectsCombiner : " + ex2.Message + ex2.StackTrace);
_sourcesForCombine.Clear();
continue;
}
}
if (flag)
{
this.onCombinedObjectCreated?.Invoke(val);
}
num++;
}
}
protected abstract CombinedObjectMatcher<TCombinedObject, TCombineSource> GetMatcher();
protected abstract TCombinedObject CreateCombinedObject(TCombineSource source);
protected abstract void CombineSources(TCombinedObject root, IList<TCombineSource> sources);
}
|