void Rebuild() { Debug.Log("Rebuilding"); solver.reset(); if (canvas != null) { if (!vars.ContainsKey(canvas)) { vars[canvas] = new WrappedRect(canvas); } updateScreenConstraints(); IUIConstraint[] cons = canvas.gameObject.GetComponentsInChildren <IUIConstraint>(true); foreach (IUIConstraint con in cons) { cassowary.Constraint st = con.getConstraint(vars); if (st == null) { continue; } try { solver.addConstraint(st); } catch { } } foreach (UIConnection con in connections) { cassowary.Constraint st = con.getConstraint(vars); try { solver.addConstraint(st); } catch { } } solver.updateVariables(); needs_rebuild = true; } }
// Start is called before the first frame update void updateScreenConstraints() { if (canvas == null) { return; } solver.addConstraint(cassowary.Constraint.Eq(vars[canvas].getTermFromSide(rectSide.Top), 0)); solver.addConstraint(cassowary.Constraint.Eq(vars[canvas].getTermFromSide(rectSide.Left), 0)); cassowary.Constraint newx = cassowary.Constraint.Eq(vars[canvas].getTermFromSide(rectSide.Right), Screen.width); cassowary.Constraint newy = cassowary.Constraint.Eq(vars[canvas].getTermFromSide(rectSide.Bottom), Screen.height); try { solver.addConstraint(newx); } catch { } try { solver.addConstraint(newy); } catch { } if (safeArea != null) { if (!vars.ContainsKey(safeArea)) { vars[safeArea] = new WrappedRect(safeArea); } Rect rs = new Rect(Screen.safeArea.xMin, Screen.height - Screen.safeArea.yMax, Screen.safeArea.width, Screen.safeArea.height); Debug.LogFormat("Safe Area: {0}", rs); solver.addConstraint(cassowary.Constraint.Eq(vars[safeArea].getTermFromSide(rectSide.Top), rs.yMin)); solver.addConstraint(cassowary.Constraint.Eq(vars[safeArea].getTermFromSide(rectSide.Left), rs.xMin)); cassowary.Constraint snewx = cassowary.Constraint.Eq(vars[safeArea].getTermFromSide(rectSide.Right), rs.xMax); cassowary.Constraint snewy = cassowary.Constraint.Eq(vars[safeArea].getTermFromSide(rectSide.Bottom), rs.yMax); try { solver.addConstraint(snewx); } catch { } try { solver.addConstraint(snewy); } catch { } } prevScreen = new Vector2(Screen.width, Screen.height); Debug.Log(prevScreen); Debug.Log(Screen.width); }
public bool removeConstraint(cassowary.Constraint c) { try { Debug.Log(c); solver.removeConstraint(c); needs_reassign = true; return(true); } catch { return(false); } }