コード例 #1
0
    public void OnDebugGrid(LiquidSimulation editorObj, TextureGridType gridType,
                            int sizeX, int sizeY)
    {
        editorObj.currentGridPosX = EditorGUILayout.IntField("Grid Start Position X:", editorObj.currentGridPosX);
        editorObj.currentGridPosY = EditorGUILayout.IntField("Grid Start Position Y:", editorObj.currentGridPosY);

        // Number of Cells
        int cols = 25, rows = 15;

        float gridItemWidth = maxInnerWidth / (1.0f * cols);

        // GUI.Box(new Rect(5,5, 800, 800), "Colors");
        // GUILayout.BeginArea(new Rect(10, 10, 700, 700));
        GUILayout.BeginVertical();
        for (int y = 0; y < rows && y < sizeX - editorObj.currentGridPosY; y++)
        {
            GUILayout.BeginHorizontal();
            for (int x = 0; x < cols && x < sizeY - editorObj.currentGridPosX; x++)
            {
                EditorGUILayout.ColorField(GUIContent.none,
                                           // colorGrid.GetColor(x, y),
                                           editorObj.GetPixelColor(x + editorObj.currentGridPosX,
                                                                   y + editorObj.currentGridPosY,
                                                                   gridType),
                                           false, true, false, null, GUILayout.Width(gridItemWidth));
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();
        // GUILayout.EndArea();
    }
コード例 #2
0
    void Awake()
    {
        Application.targetFrameRate = -1;
        m_solid_simulation          = new SolidSimulation(new Vector3Int(m_grid_width_in_voxels, m_grid_height_in_voxels, m_grid_depth_in_voxels), m_voxel_size_in_meters, m_solid_voxel_chunk_dimenions);
        var solid_layers = m_solid_simulation.GetLayers();

        var water_plane_layer = (int)(m_water_height / m_voxel_size_in_meters.y) + 1;

        m_liquid_simulation = new LiquidSimulation(new Vector3Int(m_grid_width_in_voxels, m_grid_height_in_voxels, m_grid_depth_in_voxels), m_voxel_size_in_meters, m_liquid_voxel_chunk_dimenions, solid_layers, m_solid_iso_level, m_min_density_to_allow_flow, water_plane_layer, m_liquid_tuning);
        var liquid_layers = m_liquid_simulation.GetLayers();

        m_liquid_simulation.SetSimulationEnabled(m_liquid_sim_enabled_on_startup);

        m_solid_brush  = SolidLayeredBrush.LoadBrush("SolidMaterials");
        m_liquid_brush = new LiquidLayeredBrush(Resources.Load <Material>("LiquidMaterials/Liquid"));

        m_solid_mesher  = CreateSolidMesher(solid_layers, m_solid_brush);
        m_liquid_mesher = CreateLiquidMesher(m_liquid_simulation.GetLayers(), m_liquid_brush);

        CreateGroundPlane(m_solid_brush);

        m_water = GameObject.Instantiate(m_water);

        m_water.transform.position = new Vector3(0, m_water_height, 0);

        SetRoomId("quicksave_12345");

        ProcessCommandLineFile();

        GenerateWorld(solid_layers, liquid_layers);

        Instance = this;
    }
コード例 #3
0
    void Start()
    {
        chunkRenderer    = GetComponent <ChunkRenderer>();
        liquidSimulation = GetComponent <LiquidSimulation>();

        worldName = "My world";

        //seed = new Seed();
        seed        = new Seed("8799855771982440");
        Config.seed = seed;

        // 0 = default
        // 1 = alien
        // 2 = cave
        SetTerrain(0);

        // Set render distance
        // 2, 4, 6, 8, 10, 12...
        SetDistances(4);

        // Render terrain from player's position
        LoadPosition();
    }
コード例 #4
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        LiquidSimulation editorObj = target as LiquidSimulation;

        if (editorObj == null)
        {
            return;
        }

        if (GUILayout.Button("Initialize"))
        {
            editorObj.InitState();
        }

        if (editorObj.alreadyStarted)
        {
            if (GUILayout.Button("Update State"))
            {
                editorObj.UpdateState();
            }
        }
    }
コード例 #5
0
    void ShowCellLine(string cell_name, DensityCell cell, SolidSimulation solid_simulation, LiquidSimulation liquid_simulation)
    {
        bool is_valid = solid_simulation.TryGetDensity(cell, out var solid_density);

        liquid_simulation.TryGetDensity(cell, out var liquid_density);
        string text = $"{cell_name}: sd={solid_density}, ld={liquid_density}";

        EditorGUILayout.BeginHorizontal();
        if (is_valid)
        {
            EditorGUILayout.LabelField(text);
            if (GUILayout.Button("->"))
            {
                CellDebugger.s_debug_cell = cell;
            }
        }
        else
        {
            EditorGUILayout.LabelField($"{cell_name}: INVALID");
        }
        EditorGUILayout.EndHorizontal();
    }
コード例 #6
0
    void ShowCellFoldout(string cell_name, DensityCell cell, ref bool is_expanded, SolidSimulation solid_simulation, LiquidSimulation liquid_simulation)
    {
        if (is_expanded = EditorGUILayout.Foldout(is_expanded, cell_name))
        {
            EditorGUI.indentLevel += 2;

            EditorGUILayout.LabelField($"x={cell.m_x}, z={cell.m_z}, l={cell.m_layer_idx}");

            ShowCellLine("C", cell, solid_simulation, liquid_simulation);
            ShowCellLine("L", cell.Dx(-1), solid_simulation, liquid_simulation);
            ShowCellLine("R", cell.Dx(+1), solid_simulation, liquid_simulation);
            ShowCellLine("N", cell.Dz(-1), solid_simulation, liquid_simulation);
            ShowCellLine("F", cell.Dz(+1), solid_simulation, liquid_simulation);
            ShowCellLine("B", cell.Dl(-1), solid_simulation, liquid_simulation);
            ShowCellLine("A", cell.Dl(+1), solid_simulation, liquid_simulation);

            EditorGUI.indentLevel -= 2;
        }
    }