private void DistributeSunflower(UiInnerNode innerNode, Transform parent) { var rndAngle = TreeGeometry.GetRandomAngle(); for (var i = 0; i < innerNode.Children.Count; i++) { var child = innerNode.Children[i]; var nodeObject = AddChildContainer(child, parent, i, rndAngle); GenerateBranches(child, nodeObject.transform); } innerNode.Circle.Radius = innerNode.Children.Count == 1 ? TreeGeometry.NodeDistanceFactor : TreeGeometry.CalcSunflowerRadius(innerNode.Children.Count - 1); }
private GameObject AddChildContainer(UiNode node, Transform parent, int n, float initialPhi = 0) { ////////////////////////////////// // // // y // // ∧ // // | . r // // | ˙ . // // | ˙ . node // // |__˛ ‚´ . // // | θ \‚´ . // // | ‚´ l . // // |‚´ . // // parent ˚-. ------.--> x // // / φ ˙ . . // // /————´ ˙ . // // ⩗ // // - z // // // ////////////////////////////////// var r = TreeGeometry.CalcSunflowerRadius(n); var phi = TreeGeometry.CalcPhi(n, initialPhi); var theta = TreeGeometry.CalcTheta(manipulator.DefaultEdgeHeight, r); var l = TreeGeometry.CalcEdgeLength(manipulator.DefaultEdgeHeight, theta); var nodePosition = TreeGeometry.CalcNodePosition(l, theta, phi); var branchObject = manipulator.AddEmptyBranchObject(parent); var edgeObject = manipulator.AddEdgeObject(branchObject.transform, TreeGeometry.SizeToScale(l, manipulator.DefaultEdgeHeight, manipulator.DefaultEdgeScale.y), theta, phi); var nodeObject = manipulator.AddEmptyNodeObject(node, branchObject.transform, nodePosition, edgeObject); return(nodeObject); }