private void Synchronize() { _polygonPoints = PolygonTools.FixTransformBias(polygon.points, polygon.transform); if (_polygonPoints.Length > polygonPointGizmos.Count) // More points than gizmos -> add new gizmos { int diff = _polygonPoints.Length - polygonPointGizmos.Count; for (int i = 0; i < diff; i++) { polygonPointGizmos.Add(CreateGizmo()); } } else if (_polygonPoints.Length < polygonPointGizmos.Count) // More gizmos than points -> remove gizmos { int diff = polygonPointGizmos.Count - _polygonPoints.Length; for (int i = 0; i < diff; i++) { PolygonPointGizmo toRemove = polygonPointGizmos[0]; polygonPointGizmos.Remove(toRemove); DestroyImmediate(toRemove.gameObject); } } for (int i = 0; i < _polygonPoints.Length; i++) { if (polygonPointGizmos[i] == null) { polygonPointGizmos[i] = CreateGizmo(); } lineRenderer.enabled = showLines; polygonPointGizmos[i].gameObject.SetActive(showGizmos); polygonPointGizmos[i].text.gameObject.SetActive(showTexts); } }
private PolygonPointGizmo CreateGizmo() { #if UNITY_EDITOR PolygonPointGizmo gizmo = UnityEditor.PrefabUtility.InstantiatePrefab(template) as PolygonPointGizmo; gizmo.transform.SetParent(transform, true); #else PolygonPointGizmo gizmo = Instantiate(template, transform, true); #endif return(gizmo); }