private void Start() { Time.timeScale = 1; IvyCore _ = new IvyCore(); foreach ((Vector3 position, Vector3 normal) in GetRoots()) { //Debug.Log($"This position: {transform.position}, Root position: {root.transform.position}"); IvyGraph ivyGraph = IvyCore.SeedNewIvyGraph(profileAsset.ivyProfile, position, Vector3.up, normal, transform, true); ivyGraph.isGrowing = true; ivyGraphs.Add(ivyGraph); float branchPercentage = Mathf.Clamp(ivyGraph.roots[0].nodes.Last().cS / profileAsset.ivyProfile.maxLength, 0f, 0.38f); int branchCount = Mathf.FloorToInt(profileAsset.ivyProfile.maxBranchesTotal * branchPercentage * profileAsset.ivyProfile.branchingProbability); for (int b = 0; b < branchCount; b++) { IvyCore.ForceRandomIvyBranch(ivyGraph, profileAsset.ivyProfile); } } //Debug.Log($"Mask: {LayerMask.GetMask("Default", "UserLayerB")}"); }
// got working painter code from https://github.com/marmitoTH/Unity-Prefab-Placement-Editor private void OnSceneGUI() { if (ivyBehavior == null) { ivyBehavior = (IvyBehavior)target; } Handles.color = ivyBehavior.debugColor; foreach (var graph in ivyBehavior.ivyGraphs) { if (graph.isVisible && (graph.branchMF == null || graph.branchR == null || (graph.rootGO != null && Vector3.SqrMagnitude(graph.rootGO.transform.position - graph.seedPos) > 0.001f))) { DrawThiccDisc(graph.seedPos, graph.seedNormal, 0.05f); DrawDebugIvy(graph); } } Event current = Event.current; // change current editor tool for painting and positioning if ((isPlantingModeActive || currentIvyGraphMove != null)) { if (Tools.current != Tool.None) { LastTool = Tools.current; Tools.current = Tool.None; Tools.hidden = true; } } else if (LastTool != Tool.None) { Tools.current = LastTool; LastTool = Tool.None; Tools.hidden = false; } if (currentIvyGraphMove != null) { if (current.type == EventType.MouseDrag) { Undo.RegisterCompleteObjectUndo(ivyBehavior, "Hedera > Move Ivy Seed Position"); if (currentIvyGraphMove.rootGO != null) { Undo.RegisterCompleteObjectUndo(currentIvyGraphMove.rootGO, "Hedera > Move Ivy Seed Position"); } } isPlantingModeActive = false; currentIvyGraphMove.seedPos = Handles.PositionHandle(currentIvyGraphMove.seedPos, Quaternion.identity); if (currentIvyGraphMove.rootGO != null) { currentIvyGraphMove.rootGO.transform.position = currentIvyGraphMove.seedPos; } Handles.Label(currentIvyGraphMove.seedPos, currentIvyGraphMove.seedPos.ToString()); } if (!isPlantingModeActive) { return; } int controlId = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive); MousePosition(); if (Event.current.type == EventType.Repaint) { deltaTime = EditorApplication.timeSinceStartup - lastEditorTime; lastEditorTime = EditorApplication.timeSinceStartup; } if ((current.type == EventType.MouseDrag || current.type == EventType.MouseDown)) { if (current.button == 0 && (lastPos == Vector3.zero || CanDraw()) && !current.shift) { mouseDirection = Vector3.MoveTowards(mouseDirection, (mousePos - lastPos).normalized, System.Convert.ToSingle(deltaTime)); lastPos = mousePos; if (current.type == EventType.MouseDown) { ivyBehavior.transform.localScale = Vector3.one; Undo.SetCurrentGroupName("Hedera > Paint Ivy"); Undo.RegisterCompleteObjectUndo(ivyBehavior, "Hedera > Paint Ivy"); currentIvyGraph = IvyCore.SeedNewIvyGraph(ivyBehavior.profileAsset.ivyProfile, lastPos, Vector3.up, -mouseNormal, ivyBehavior.transform, ivyBehavior.generateMeshDuringGrowth); currentIvyGraph.isGrowing = false; ivyBehavior.ivyGraphs.Add(currentIvyGraph); } else if (currentIvyGraph != null) { IvyCore.ForceIvyGrowth(currentIvyGraph, ivyBehavior.profileAsset.ivyProfile, lastPos, mouseNormal); } } // else if (current.button == 0 && current.shift) // { // erase // lastPos = mousePos; // if (current.type == EventType.MouseDown) { // Undo.SetCurrentGroupName( "Hedera > Erase Ivy"); // } else { // } // } } if (current.type == EventType.MouseUp) { ivyBehavior.transform.localScale = Vector3.one; lastPos = Vector3.zero; if (currentIvyGraph != null) { currentIvyGraph.isGrowing = ivyBehavior.enableGrowthSim; if (currentIvyGraph.isGrowing && currentIvyGraph.roots.Count > 0) { float branchPercentage = Mathf.Clamp(currentIvyGraph.roots[0].nodes.Last().cS / ivyBehavior.profileAsset.ivyProfile.maxLength, 0f, 0.38f); int branchCount = Mathf.FloorToInt(ivyBehavior.profileAsset.ivyProfile.maxBranchesTotal * branchPercentage * ivyBehavior.profileAsset.ivyProfile.branchingProbability); for (int b = 0; b < branchCount; b++) { IvyCore.ForceRandomIvyBranch(currentIvyGraph, ivyBehavior.profileAsset.ivyProfile); } } else { IvyCore.needToSaveAssets = true; } currentIvyGraph = null; } } if (Event.current.type == EventType.Layout) { HandleUtility.AddDefaultControl(controlId); } SceneView.RepaintAll(); }