コード例 #1
0
    void DrawBlend(NoiseBlend module)
    {
        Rect r = Box(module.editorPos, 5, module);

        // main box
        EditorGUI.BeginDisabledGroup(add == module);
        GUILayout.BeginArea(new Rect(r.x + 16, r.y + 5, r.width - 32, r.height - 10));

        EditorGUILayout.LabelField("Blend", EditorStyles.boldLabel);
        module.type = (NoiseBlendType)EditorGUILayout.EnumPopup("Type", module.type);
        EditorGUILayout.LabelField("Control", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("Module 1", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("Module 2", EditorStyles.boldLabel);

        GUILayout.EndArea();

        EditorGUI.EndDisabledGroup();

        // connection buttons
        ConnectionOutputButton(module, new Vector3(r.xMax, r.center.y)); // module output

        Vector2 pos = new Vector2(r.x, (int)(r.y + 5 + EditorGUIUtility.singleLineHeight * .5f + (EditorGUIUtility.singleLineHeight + 2f) * 2f + .5f));

        // control
        ConnectionInputButton(
            (int nm) => { module.control = nm; }, pos,
            () => { module.control = -1; });
        if (module.control != -1)
        {
            DrawLine(planet.noiseModules[module.control].editorPos + cameraOffset + new Vector2(moduleWidth * .5f, 0f), pos);
        }
        pos.y += EditorGUIUtility.singleLineHeight + 2f;
        pos.y  = (int)(pos.y + .5f);

        // module1
        ConnectionInputButton(
            (int nm) => { module.module1 = nm; }, pos,
            () => { module.module1 = -1; });
        if (module.module1 != -1)
        {
            DrawLine(planet.noiseModules[module.module1].editorPos + cameraOffset + new Vector2(moduleWidth * .5f, 0f), pos);
        }
        pos.y += EditorGUIUtility.singleLineHeight + 2f;
        pos.y  = (int)(pos.y + .5f);

        // module2
        ConnectionInputButton(
            (int nm) => { module.module2 = nm; }, pos,
            () => { module.module2 = -1; });
        if (module.module2 != -1)
        {
            DrawLine(planet.noiseModules[module.module2].editorPos + cameraOffset + new Vector2(moduleWidth * .5f, 0f), pos);
        }
    }
コード例 #2
0
    void RemoveModule(int index)
    {
        Undo.RecordObject(planet, "Remove module");

        NoiseModule[] tmp = new NoiseModule[planet.noiseModules.Length - 1];

        for (int i = 0; i < planet.noiseModules.Length; i++)
        {
            int j = i;
            if (i > index)
            {
                j      = i - 1;
                tmp[j] = planet.noiseModules[i];
                tmp[j].index--;
            }
            else if (i < index)
            {
                tmp[j] = planet.noiseModules[i];
            }
            else
            {
                continue;
            }

            if (tmp[j] is NoiseBlend)
            {
                NoiseBlend m = tmp[j] as NoiseBlend;

                if (m.control > index)
                {
                    m.control--;
                }
                else if (m.control == index)
                {
                    m.control = -1;
                }

                if (m.module1 > index)
                {
                    m.module1--;
                }
                else if (m.control == index)
                {
                    m.control = -1;
                }

                if (m.control > index)
                {
                    m.control--;
                }
                else if (m.module2 == index)
                {
                    m.module2 = -1;
                }
            }
            else if (tmp[j] is NoiseMath)
            {
                NoiseMath m = tmp[j] as NoiseMath;

                for (int k = 0; k < m.modules.Count; k++)
                {
                    if (m.modules[k] > index)
                    {
                        m.modules[k]--;
                    }
                    else if (m.modules[k] == index)
                    {
                        m.modules.RemoveAt(k);
                        k--;
                    }
                }
            }
            else if (tmp[j] is Fractal)
            {
                Fractal m = tmp[j] as Fractal;
                if (m.warpModule > index)
                {
                    m.warpModule--;
                }
                else if (m.warpModule == index)
                {
                    m.warpModule = -1;
                }
            }
            else if (tmp[j] is Simplex)
            {
                Simplex m = tmp[j] as Simplex;
                if (m.warpModule > index)
                {
                    m.warpModule--;
                }
                else if (m.warpModule == index)
                {
                    m.warpModule = -1;
                }
            }
        }

        if (planet.heightOutput == index)
        {
            planet.heightOutput = 0;
        }
        else if (planet.heightOutput > index)
        {
            planet.heightOutput--;
        }

        planet.noiseModules = tmp;
    }