protected void Int_MinMax_CreateFetchAndClearAsset(string name, Int_MinMax_Reference reference) { string path = $"Resources/Serialized Data/Variables/Int/{name}.asset"; Int_MinMax_Variable variable = ScriptableObject.CreateInstance <Int_MinMax_Variable>(); variable.Min = reference.Min; variable.Max = reference.Max; variable.Value = reference.Value; AssetDatabase.CreateAsset(variable, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Int_MinMax_Variable loaded = AssetDatabase.LoadAssetAtPath <Int_MinMax_Variable>(path); reference.UseLocal = false; reference.Shared = loaded; Clear(name); }
protected Int_MinMax_Reference Int_MinMax_Field( string context, string name, Int_MinMax_Reference input, int y ) { Int_MinMax_Reference property = 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), property.UseLocal ? "L" : "S")) { GenericMenu menu = new GenericMenu(); menu.AddItem( new GUIContent("Local Value"), property.UseLocal == true, (object result) => property.UseLocal = true, null ); menu.AddItem( new GUIContent("Shared Value"), property.UseLocal == false, (object result) => { if (property != null) { states[contextual_name] = state.EDITING; } else { states[contextual_name] = state.NAMING; } property.UseLocal = false; }, null ); menu.ShowAsContext(); } if (property.UseLocal) { if (states[contextual_name] == state.EDITING) { property.Min = EditorGUI.IntField( new Rect(135, y, 25, 16), property.Min ); property.Max = EditorGUI.IntField( new Rect(165, y, 25, 16), property.Max ); property.Value = EditorGUI.IntSlider( new Rect(195, y, 220, 16), property.Value, property.Min, property.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"; Int_MinMax_Variable variable = ScriptableObject.CreateInstance <Int_MinMax_Variable>(); variable.name = names[contextual_name]; variable.Min = property.Min; variable.Max = property.Max; variable.Value = property.Value; AssetDatabase.CreateAsset(variable, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Int_MinMax_Variable loaded = AssetDatabase.LoadAssetAtPath <Int_MinMax_Variable>(path); property.UseLocal = false; property.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 { property.Shared = EditorGUI.ObjectField( new Rect(135, y, 252, 16), property.Shared, typeof(Int_MinMax_Variable), false ) as Int_MinMax_Variable; } return(property); }
protected void Int_MinMax_Field( string context, string name, Int_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_Int_MinMax_SharedButtons(name, input, x += full_label_width, y); if (input.UseLocal) { if (states[contextual_name] == state.EDITING) { input.Min = EditorGUI.IntField( new Rect(x += full_button_width, y, limit_width, row_height), input.Min ); input.Max = EditorGUI.IntField( new Rect(x += full_limit_width, y, limit_width, row_height), input.Max ); input.Value = (int)GUI.HorizontalSlider( new Rect(x += full_limit_width, y, slider_width, row_height), input.Value, input.Min, input.Max ); input.Value = EditorGUI.IntField( 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/Int/{names[contextual_name]}.asset"; Int_MinMax_Variable variable = ScriptableObject.CreateInstance <Int_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(); Int_MinMax_Variable loaded = AssetDatabase.LoadAssetAtPath <Int_MinMax_Variable>(path); input.UseLocal = false; input.Shared = loaded; states[contextual_name] = state.EDITING; name = ""; } else if (GUI.Button(new Rect(x += full_button_width, y, button_width, row_height), "C")) { states[contextual_name] = state.EDITING; name = ""; } } } else { input.Shared = EditorGUI.ObjectField( new Rect(x += full_button_width, y, full_obj_width, row_height), input.Shared, typeof(Int_MinMax_Variable), false ) as Int_MinMax_Variable; } }