Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(pivotPosition);
        EditorGUILayout.PropertyField(smoothNormals);

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

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

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

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

        EditorGUILayout.PropertyField(sectors);
        if (sectors.intValue < 3)
        {
            sectors.intValue = 3;
        }

        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);
        }
    }
Ejemplo n.º 2
0
    private void OnEnable()
    {
        shape         = (ProceduralCone)target;
        pivotPosition = serializedObject.FindProperty("pivotPosition");
        smoothNormals = serializedObject.FindProperty("smoothNormals");
        height        = serializedObject.FindProperty("height");
        lowerRadius   = serializedObject.FindProperty("lowerRadius");
        upperRadius   = serializedObject.FindProperty("upperRadius");
        segments      = serializedObject.FindProperty("segments");
        sectors       = serializedObject.FindProperty("sectors");

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

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