Exemple #1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(sizeX);
        if (sizeX.floatValue < 0)
        {
            sizeX.floatValue = 0;
        }

        EditorGUILayout.PropertyField(sizeY);
        if (sizeY.floatValue < 0)
        {
            sizeY.floatValue = 0;
        }

        EditorGUILayout.PropertyField(sizeZ);
        if (sizeZ.floatValue < 0)
        {
            sizeZ.floatValue = 0;
        }

        EditorGUILayout.PropertyField(segmentsX);
        if (segmentsX.intValue < 1)
        {
            segmentsX.intValue = 1;
        }

        EditorGUILayout.PropertyField(segmentsY);
        if (segmentsY.intValue < 1)
        {
            segmentsY.intValue = 1;
        }

        EditorGUILayout.PropertyField(segmentsZ);
        if (segmentsZ.intValue < 1)
        {
            segmentsZ.intValue = 1;
        }

        bool propertyChanged = serializedObject.ApplyModifiedProperties();

        if (propertyChanged)
        {
            shape.UpdateMesh();
        }

        if (GUILayout.Button("Bake"))
        {
            var mesh = shape.GetComponent <MeshFilter>().sharedMesh;
            CreateMeshAsset(mesh);
            DestroyImmediate(serializedObject.targetObject);
        }

        if (GUILayout.Button("Create mesh asset"))
        {
            var mesh = shape.GetComponent <MeshFilter>().sharedMesh;
            CreateMeshAsset(mesh);
        }
    }
Exemple #2
0
    private void OnEnable()
    {
        shape     = (ProceduralBox)target;
        sizeX     = serializedObject.FindProperty("sizeX");
        sizeY     = serializedObject.FindProperty("sizeY");
        sizeZ     = serializedObject.FindProperty("sizeZ");
        segmentsX = serializedObject.FindProperty("segmentsX");
        segmentsY = serializedObject.FindProperty("segmentsY");
        segmentsZ = serializedObject.FindProperty("segmentsZ");

        var meshFilter = shape.GetComponent <MeshFilter>();
        var mesh       = meshFilter.sharedMesh;

        if (mesh == null)
        {
            shape.UpdateMesh();
        }
    }