Exemple #1
0
    protected void Float_MinMax_CreateFetchAndClearAsset(string name, Float_MinMax_Reference reference)
    {
        string path = $"Resources/Serialized Data/Variables/Float/{name}.asset";

        Float_MinMax_Variable variable = ScriptableObject.CreateInstance <Float_MinMax_Variable>();

        variable.Min   = reference.Min;
        variable.Max   = reference.Max;
        variable.Value = reference.Value;

        AssetDatabase.CreateAsset(variable, path);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        Float_MinMax_Variable loaded = AssetDatabase.LoadAssetAtPath <Float_MinMax_Variable>(path);

        reference.UseLocal = false;
        reference.Shared   = loaded;

        Clear(name);
    }
Exemple #2
0
    protected Float_MinMax_Reference Float_MinMax_Field(
        string context,
        string name,
        Float_MinMax_Reference input,
        int y
        )
    {
        Float_MinMax_Reference MMF = input;

        string contextual_name = $"{context}{name}";

        EditorGUI.PrefixLabel(
            new Rect(15, y, 80, 16),
            new GUIContent(name)
            );

        if (GUI.Button(new Rect(110, y, 20, 16), MMF.UseLocal ? "L" : "S"))
        {
            GenericMenu menu = new GenericMenu();

            menu.AddItem(
                new GUIContent("Local Value"),
                MMF.UseLocal == true,
                (object result) => MMF.UseLocal = true,
                null
                );

            menu.AddItem(
                new GUIContent("Shared Value"),
                MMF.UseLocal == false,
                (object result) => {
                if (MMF != null)
                {
                    states[contextual_name] = state.EDITING;
                }
                else
                {
                    states[contextual_name] = state.NAMING;
                }

                MMF.UseLocal = false;
            },
                null
                );

            menu.ShowAsContext();
        }

        if (MMF.UseLocal)
        {
            if (states[contextual_name] == state.EDITING)
            {
                MMF.Min = EditorGUI.FloatField(
                    new Rect(135, y, 25, 16),
                    MMF.Min
                    );

                MMF.Max = EditorGUI.FloatField(
                    new Rect(165, y, 25, 16),
                    MMF.Max
                    );

                MMF.Value = EditorGUI.Slider(
                    new Rect(195, y, 220, 16),
                    MMF.Value,
                    MMF.Min,
                    MMF.Max
                    );

                if (GUI.Button(new Rect(420, y, 20, 16), "N"))
                {
                    states[contextual_name] = state.NAMING;
                }
            }
            else
            {
                names[contextual_name] = EditorGUI.TextField(new Rect(135, y, 207, 16), names[contextual_name]);

                if (GUI.Button(new Rect(347, y, 20, 16), "S"))
                {
                    string path = $"Assets/Serialized Data/Variables/{context}/{names[contextual_name]}.asset";

                    Float_MinMax_Variable variable = ScriptableObject.CreateInstance <Float_MinMax_Variable>();

                    variable.name  = names[contextual_name];
                    variable.Min   = MMF.Min;
                    variable.Max   = MMF.Max;
                    variable.Value = MMF.Value;

                    AssetDatabase.CreateAsset(variable, path);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    Float_MinMax_Variable loaded = AssetDatabase.LoadAssetAtPath <Float_MinMax_Variable>(path);

                    MMF.UseLocal = false;
                    MMF.Shared   = loaded;

                    states[contextual_name] = state.EDITING;
                    names[contextual_name]  = "";
                }
                else if (GUI.Button(new Rect(372, y, 20, 16), "C"))
                {
                    states[contextual_name] = state.EDITING;
                    names[contextual_name]  = "";
                }
            }
        }
        else
        {
            MMF.Shared = EditorGUI.ObjectField(
                new Rect(135, y, 252, 16),
                MMF.Shared,
                typeof(Float_MinMax_Variable),
                false
                ) as Float_MinMax_Variable;
        }

        return(MMF);
    }
Exemple #3
0
    protected void Float_MinMax_Field(
        string context,
        string name,
        Float_MinMax_Reference input,
        int x,
        int y
        )
    {
        string contextual_name = $"{context}{name}";

        EditorGUI.PrefixLabel(
            new Rect(x, y, label_width, row_height),
            new GUIContent(name)
            );

        DrawLocal_Float_MinMax_SharedButtons(name, input, x += full_label_width, y);

        if (input.UseLocal)
        {
            if (states[contextual_name] == state.EDITING)
            {
                input.Min       = EditorGUI.FloatField(
                    new Rect(x += full_button_width, y, limit_width, row_height),
                    input.Min
                    );

                input.Max       = EditorGUI.FloatField(
                    new Rect(x += full_limit_width, y, limit_width, row_height),
                    input.Max
                    );

                input.Value     = GUI.HorizontalSlider(
                    new Rect(x += full_limit_width, y, slider_width, row_height),
                    input.Value,
                    input.Min,
                    input.Max
                    );

                input.Value     = EditorGUI.FloatField(
                    new Rect(x += full_slider_width, y, value_width, row_height),
                    input.Value
                    );

                if (GUI.Button(new Rect(x += full_value_width, y, button_width, row_height), "N"))
                {
                    states[contextual_name] = state.NAMING;
                }
            }
            else
            {
                names[contextual_name] = EditorGUI.TextField(
                    new Rect(x        += full_button_width, y, text_width, row_height),
                    names[contextual_name]
                    );

                if (GUI.Button(new Rect(x += full_text_width, y, button_width, row_height), "S"))
                {
                    string path = $"Assets/Serialized Data/Variables/Float/{names[contextual_name]}.asset";

                    Float_MinMax_Variable variable = ScriptableObject.CreateInstance <Float_MinMax_Variable>();

                    variable.name  = names[contextual_name];
                    variable.Min   = input.Min;
                    variable.Max   = input.Max;
                    variable.Value = input.Value;

                    AssetDatabase.CreateAsset(variable, path);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    Float_MinMax_Variable loaded = AssetDatabase.LoadAssetAtPath <Float_MinMax_Variable>(path);

                    input.UseLocal = false;
                    input.Shared   = loaded;

                    states[contextual_name] = state.EDITING;
                    names[contextual_name]  = "";
                }
                else if (GUI.Button(new Rect(x += full_button_width, y, button_width, row_height), "C"))
                {
                    states[contextual_name] = state.EDITING;
                    names[contextual_name]  = "";
                }
            }
        }
        else
        {
            input.Shared    = EditorGUI.ObjectField(
                new Rect(x += full_button_width, y, full_obj_width, row_height),
                input.Shared,
                typeof(Float_MinMax_Variable),
                false
                ) as Float_MinMax_Variable;
        }
    }