void SaveDefinition()
    {
        string file = EditorUtility.SaveFilePanelInProject("Save Shape Definition", Target.Name, "asset", "Save Shaper definition as");

        if (!string.IsNullOrEmpty(file))
        {
            var def = CurvyShaperDefinition.Create(Target);
            AssetDatabase.CreateAsset(def, file);
            AssetDatabase.SaveAssets();
        }
    }
    public override void OnInspectorGUI()
    {
        
        Definition = (CurvyShaperDefinition)EditorGUILayout.ObjectField(new GUIContent("Select Shape","Load Shape Definition"),Definition, typeof(CurvyShaperDefinition),false);
        LoadGeneral=EditorGUILayout.Toggle(new GUIContent("Load General Params","Check to load saved general parameters"),LoadGeneral);
        if (DefinitionLoaded != Definition) {
            Definition.LoadInto(Target,LoadGeneral);
            DefinitionLoaded = Definition;
            EditorUtility.SetDirty(Target);
            serializedObject.UpdateIfDirtyOrScript();
        }
        EditorGUILayout.LabelField("General", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tName, new GUIContent("Name", "Name of the effect"));
        EditorGUILayout.PropertyField(tResolution, new GUIContent("Resolution", "Max. number of Control Points"));
        EditorGUILayout.PropertyField(tRange, new GUIContent("Range", "Range in Degree"));
        EditorGUILayout.PropertyField(tRadiusBase, new GUIContent("Radius", "Base Radius"));
        EditorGUILayout.PropertyField(tRadiusModifier, new GUIContent("Radius Modifier","How to apply Radius curve?"));
        if (tRadiusModifier.enumNames[tRadiusModifier.enumValueIndex]!="None")
            EditorGUILayout.PropertyField(tRadiusModifierCurve, new GUIContent("Radius Curve","Radius Modifier curve"));
        
        EditorGUILayout.PropertyField(tZ, new GUIContent("Z", "Base Z"));
        EditorGUILayout.PropertyField(tZModifier, new GUIContent("Z Modifier","How to apply Z curve?"));
        if (tZModifier.enumNames[tZModifier.enumValueIndex] != "None")
            EditorGUILayout.PropertyField(tZModifierCurve, new GUIContent("Z Curve", "Z Modifier curve"));
        EditorGUILayout.LabelField("Formula Parameters", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tm);
        EditorGUILayout.PropertyField(tn1);
        EditorGUILayout.PropertyField(tn2);
        EditorGUILayout.PropertyField(tn3);
        EditorGUILayout.PropertyField(ta);
        EditorGUILayout.PropertyField(tb);
        EditorGUILayout.LabelField("Miscellaneous", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tWeld, new GUIContent("Weld Treshold", "Remove Control Points within a certain distance"));
        EditorGUILayout.PropertyField(tAutoRefresh, new GUIContent("Auto Refresh", "Auto Refresh Shape?"));
        EditorGUILayout.PropertyField(tAutoRefreshSpeed, new GUIContent("Auto Refresh Speed", "Refresh rate in seconds"));

        if (serializedObject.targetObject && serializedObject.ApplyModifiedProperties()) {
            Target.RefreshImmediately();
            SceneView.RepaintAll();
            Repaint();
        }


        EditorGUILayout.LabelField("Actions", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent(mTexRefresh,"Refresh"),GUILayout.ExpandWidth(false)))
            Target.RefreshImmediately();
        if (GUILayout.Button(new GUIContent(mTexSave,"Save"),GUILayout.ExpandWidth(false)))
            SaveDefinition();
        if (GUILayout.Button(new GUIContent(mTexHelp,"What are those parameters for?"),GUILayout.ExpandWidth(false)))
            Application.OpenURL("http://paulbourke.net/geometry/supershape/");
        EditorGUILayout.EndHorizontal();
    }
    public override void OnInspectorGUI()
    {
        Definition  = (CurvyShaperDefinition)EditorGUILayout.ObjectField(new GUIContent("Select Shape", "Load Shape Definition"), Definition, typeof(CurvyShaperDefinition), false);
        LoadGeneral = EditorGUILayout.Toggle(new GUIContent("Load General Params", "Check to load saved general parameters"), LoadGeneral);
        if (DefinitionLoaded != Definition)
        {
            Definition.LoadInto(Target, LoadGeneral);
            DefinitionLoaded = Definition;
            EditorUtility.SetDirty(Target);
            serializedObject.UpdateIfDirtyOrScript();
        }
        EditorGUILayout.LabelField("General", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tName, new GUIContent("Name", "Name of the effect"));
        EditorGUILayout.PropertyField(tResolution, new GUIContent("Resolution", "Max. number of Control Points"));
        EditorGUILayout.PropertyField(tRange, new GUIContent("Range", "Range in Degree"));
        EditorGUILayout.PropertyField(tRadiusBase, new GUIContent("Radius", "Base Radius"));
        EditorGUILayout.PropertyField(tRadiusModifier, new GUIContent("Radius Modifier", "How to apply Radius curve?"));
        if (tRadiusModifier.enumNames[tRadiusModifier.enumValueIndex] != "None")
        {
            EditorGUILayout.PropertyField(tRadiusModifierCurve, new GUIContent("Radius Curve", "Radius Modifier curve"));
        }

        EditorGUILayout.PropertyField(tZ, new GUIContent("Z", "Base Z"));
        EditorGUILayout.PropertyField(tZModifier, new GUIContent("Z Modifier", "How to apply Z curve?"));
        if (tZModifier.enumNames[tZModifier.enumValueIndex] != "None")
        {
            EditorGUILayout.PropertyField(tZModifierCurve, new GUIContent("Z Curve", "Z Modifier curve"));
        }
        EditorGUILayout.LabelField("Formula Parameters", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tm);
        EditorGUILayout.PropertyField(tn1);
        EditorGUILayout.PropertyField(tn2);
        EditorGUILayout.PropertyField(tn3);
        EditorGUILayout.PropertyField(ta);
        EditorGUILayout.PropertyField(tb);
        EditorGUILayout.LabelField("Miscellaneous", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tWeld, new GUIContent("Weld Treshold", "Remove Control Points within a certain distance"));
        EditorGUILayout.PropertyField(tAutoRefresh, new GUIContent("Auto Refresh", "Auto Refresh Shape?"));
        EditorGUILayout.PropertyField(tAutoRefreshSpeed, new GUIContent("Auto Refresh Speed", "Refresh rate in seconds"));

        if (serializedObject.targetObject && serializedObject.ApplyModifiedProperties())
        {
            Target.RefreshImmediately();
            SceneView.RepaintAll();
            Repaint();
        }


        EditorGUILayout.LabelField("Actions", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent(mTexRefresh, "Refresh"), GUILayout.ExpandWidth(false)))
        {
            Target.RefreshImmediately();
        }
        if (GUILayout.Button(new GUIContent(mTexSave, "Save"), GUILayout.ExpandWidth(false)))
        {
            SaveDefinition();
        }
        if (GUILayout.Button(new GUIContent(mTexHelp, "What are those parameters for?"), GUILayout.ExpandWidth(false)))
        {
            UnityEngine.Application.OpenURL("http://paulbourke.net/geometry/supershape/");
        }
        EditorGUILayout.EndHorizontal();
    }