private Obb CalcPosition(XdObjectJson xdObject, Obb parentObb, XdObjectJson[] parents) { var obb = new Obb { Parent = parentObb, LocalLeftTopPosition = new Vector2(xdObject.Transform?.Tx ?? 0f, xdObject.Transform?.Ty ?? 0f), Rotation = xdObject.Meta?.Ux?.Rotation ?? 0f // サイズは子供のサイズが無いと決まらない }; var children = new Obb[] { }; if (xdObject.Group != null) { children = CalcPosition(xdObject.Group.Children, obb, parents.Concat(new[] { xdObject }).ToArray()); } foreach (var parser in _objectParsers) { if (!parser.Is(xdObject)) { continue; } var rect = parser.CalcSize(xdObject); obb.ApplyRect(rect); foreach (var child in children) { child.LocalLeftTopPosition -= rect.position; } _obbHolder.Set(xdObject, obb); return(obb); } if (xdObject.Type == "group") { var rect = Obb.MinMaxRect(children); foreach (var parser in _groupParsers) { if (!parser.Is(xdObject, parents)) { continue; } rect = parser.CalcSize(xdObject, rect); break; } obb.ApplyRect(rect); foreach (var child in children) { child.LocalLeftTopPosition -= rect.position; } _obbHolder.Set(xdObject, obb); return(obb); } throw new Exception($"Unknown object type {xdObject.Type}"); }
private Obb CalcPosition(XdObjectJson xdObject, Obb parentObb, XdObjectJson[] parents) { var obb = new Obb { Parent = parentObb, LocalLeftTopPosition = new Vector2(xdObject.Transform?.Tx ?? 0f, xdObject.Transform?.Ty ?? 0f), Rotation = xdObject.Meta?.Ux?.Rotation ?? 0f // サイズは子供のサイズが無いと決まらない }; var children = new Obb[] { }; if (xdObject.Group != null) { children = CalcPosition(xdObject.Group.Children, obb, parents.Concat(new[] { xdObject }).ToArray()); } foreach (var parser in _objectParsers) { if (!parser.Is(xdObject)) { continue; } var rect = parser.CalcSize(xdObject); obb.ApplyRect(rect); foreach (var child in children) { child.LocalLeftTopPosition -= rect.position; } _obbHolder.Set(xdObject, obb); return(obb); } if (xdObject.Type == "group") { var rect = Obb.MinMaxRect(children); var pivotObject = xdObject.Group?.Children?.FirstOrDefault(x => x.HasParameter("pivot")); if (pivotObject != null) { var pivotObb = _obbHolder.Get(pivotObject); var pivotCenter = pivotObb.CalcLocalRect().center; var delta = rect.center - pivotCenter; var newCenter = pivotCenter; var newWidth = rect.width + Mathf.Abs(delta.x) * 2f; var newHeight = rect.height + Mathf.Abs(delta.y) * 2f; rect.width = newWidth; rect.height = newHeight; rect.center = newCenter; } foreach (var parser in _groupParsers) { if (!parser.Is(xdObject, parents)) { continue; } rect = parser.CalcSize(xdObject, rect); break; } obb.ApplyRect(rect); foreach (var child in children) { child.LocalLeftTopPosition -= rect.position; } _obbHolder.Set(xdObject, obb); return(obb); } throw new Exception($"Unknown object type {xdObject.Type}"); }