コード例 #1
0
    public override void OnInspectorGUI()
    {
        NoiseTreeGenerator noiseTreeGen = (NoiseTreeGenerator)target;

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.LabelField("Trunk Length Min Max", "Min: " + trunkMinLen.ToString("F2") + " Max: " + trunkMaxLen.ToString("F2"));
        EditorGUILayout.MinMaxSlider(ref trunkMinLen, ref trunkMaxLen, trunkMinVal, trunkMaxVal);

        EditorGUILayout.LabelField("Num Branches Min Max", "Min: " + branchMinNum.ToString("F0") + " Max: " + branchMaxNum.ToString("F0"));
        EditorGUILayout.MinMaxSlider(ref branchMinNum, ref branchMaxNum, branchMinVal, branchMaxVal);

        EditorGUILayout.LabelField("Branch Len Min Max", "Min: " + branchMinLen.ToString("F2") + " Max: " + branchMaxLen.ToString("F2"));
        EditorGUILayout.MinMaxSlider(ref branchMinLen, ref branchMaxLen, branchMinLenVal, branchMaxLenVal);

        EditorGUILayout.LabelField("Branch Points Min Max", "Min: " + branchPointsMinNum.ToString("F0") + " Max: " + branchPointsMaxNum.ToString("F0"));
        EditorGUILayout.MinMaxSlider(ref branchPointsMinNum, ref branchPointsMaxNum, branchPointsMinVal, branchPointsMaxVal);
        if (EditorGUI.EndChangeCheck())
        {
            // Update values for trunk
            noiseTreeGen.trunkMinLen = Mathf.Round(trunkMinLen * 100f) / 100f;
            noiseTreeGen.trunkMaxLen = Mathf.Round(trunkMaxLen * 100f) / 100f;
            // Update values for branches
            noiseTreeGen.numBrachesMin   = (int)Mathf.Round(branchMinNum);
            noiseTreeGen.numBrachesMax   = (int)Mathf.Round(branchMaxNum);
            noiseTreeGen.branchMinLen    = Mathf.Round(branchMinLen * 100) / 100f;
            noiseTreeGen.branchMaxLen    = Mathf.Round(branchMaxLen * 100) / 100f;
            noiseTreeGen.branchPointsMin = (int)Mathf.Round(branchPointsMinNum);
            noiseTreeGen.branchPointsMax = (int)Mathf.Round(branchPointsMaxNum);
            if (noiseTreeGen.autoUpdate)
            {
                noiseTreeGen.GenerateTree();
            }
        }

        if (DrawDefaultInspector())
        {
            if (noiseTreeGen.autoUpdate)
            {
                noiseTreeGen.GenerateTree();
            }
        }

        if (GUILayout.Button("Generate"))
        {
            noiseTreeGen.GenerateTree();
        }
    }
コード例 #2
0
 void Start()
 {
     nGen             = GetComponent <NoiseTreeGenerator>();
     branchAngle      = nGen.branchAngle;
     nGen.branchAngle = 179.9f;
     nGen.GenerateTree();
     transform.localScale = Vector3.zero;
     StartCoroutine(ScaleUp());
     StartCoroutine(AnimateBranches());
 }
コード例 #3
0
    IEnumerator AnimateBranches()
    {
        float lastTimeTick = Time.time;

        while (nGen.branchAngle > branchAngle)
        {
            if (Time.time > lastTimeTick + angleTick)
            {
                nGen.branchAngle += angleFactor;
                nGen.GenerateTree();
                lastTimeTick = Time.time;
            }
            yield return(null);
        }
    }