protected override void CreateNewItem() { var picker = ScriptPickerEditor.Get(typeof(Achievement)); picker.OnPickObject = (type) => { var savePath = EditorPrefs.GetString(SettingsEditor.PrefabSaveKey); if (savePath == string.Empty || Directory.Exists(savePath) == false) { Debug.LogWarning("The directory you're trying to save to doesn't exist! (" + savePath + ")"); return; } var asset = (Achievement)ScriptableObject.CreateInstance(type); AssetDatabase.CreateAsset(asset, savePath + "/" + GetAssetName(asset) + ".asset"); AssetDatabase.SetLabels(asset, new string[] { "Achievement" }); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); AddItem(asset, true); picker.Close(); }; picker.Show(); }
protected override void DrawDetail(InventoryItemBase item, int index) { EditorGUIUtility.labelWidth = EditorStyles.labelWidth; if (InventoryScriptableObjectUtility.isPrefabsSaveFolderSet == false) { EditorGUILayout.HelpBox("Prefab save folder is not set.", MessageType.Error); if (GUILayout.Button("Set prefab save folder")) { InventoryScriptableObjectUtility.SetPrefabSaveFolder(); } EditorGUIUtility.labelWidth = 0; return; } GUILayout.Label("Use the inspector if you want to add custom components.", EditorStyles.titleStyle); EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Convert type")) { var typePicker = ScriptPickerEditor.Get(typeof(InventoryItemBase)); typePicker.Show(); typePicker.OnPickObject += type => { ConvertThisToNewType(item, type); }; return; } //EditorGUI.BeginChangeCheck(); var instance = (InventoryItemBase)itemEditorInspector.target; itemEditorInspector.OnInspectorGUI(); if (_previouslySelectedGUIItemName == "ItemEditor_itemName" && GUI.GetNameOfFocusedControl() != _previouslySelectedGUIItemName) { //UpdateAssetName(item); if (itemEditorInspector.target is InventoryItemBase) { // TODO Remove this } } //if (EditorGUI.EndChangeCheck() && selectedItem != null) if (GUI.changed || !EditorIsSaved()) { selectedItem = ItemManager.database.items[index] = UpdatePrefab(instance, item); UnityEditor.EditorUtility.SetDirty(selectedItem); SetEditorIsSaved(); } _previouslySelectedGUIItemName = GUI.GetNameOfFocusedControl(); ValidateItemFromCache(item); EditorGUIUtility.labelWidth = 0; }
protected override void CreateNewItem() { var picker = ScriptPickerEditor.Get(typeof(Quest), typeof(Achievement)); picker.OnPickObject = (type) => { var asset = (Quest)ScriptableObjectUtility.CreateAsset(type, EditorPrefs.GetString(SettingsEditor.PrefabSaveKey), GetAssetName()); AddItem(asset, true); picker.Close(); }; picker.Show(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var original = position; var l = position; l.width = EditorGUIUtility.labelWidth; EditorGUI.LabelField(l, label); position.width -= l.width; position.x += l.width; var b = property.FindPropertyRelative("_assemblyQualifiedName"); Type type = null; try { type = Type.GetType(b.stringValue); } catch (Exception) { // Ignored } GUI.enabled = false; EditorGUI.LabelField(position, type != null ? type.Name : "(NOT SET)"); GUI.enabled = true; position.x = original.x + original.width - 60; position.width = 60; position.height = 14; position.y += 2; if (GUI.Button(position, "Set", "minibutton")) { var typePicker = ScriptPickerEditor.Get(typeof(object)); typePicker.Show(); typePicker.OnPickObject += pickedType => { b.stringValue = pickedType.AssemblyQualifiedName; GUI.changed = true; b.serializedObject.ApplyModifiedProperties(); }; } EditorGUI.EndProperty(); }
public void Reset() { _firstStepType = null; _picker = ScriptPickerEditor.Get(typeof(UnityItemDefinition)); _picker.Show(true); _picker.Close(); _picker.OnPickObject += type => { _firstStepType = type; Repaint(); }; Focus(); }
// public virtual string GetFileName(T item, string suffix = "") // { // var name = item?.name?.Replace(' ', '_').ToLower() + suffix ?? ""; // if (name.EndsWith(".asset")) // { // name += ".asset"; // } // // return name; // } // protected virtual void UpdateAssetName(T item) // { // var newName = GetFileName(item); // if (AssetDatabase.GetAssetPath(item).EndsWith(newName) == false) // { // AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(item), newName); // } // } protected override void CreateNewItem() { var picker = ScriptPickerEditor.Get(typeof(T)); picker.OnPickObject += type => { InventoryScriptableObjectUtility.SetPrefabSaveFolderIfNotSet(); string assetPath = InventoryScriptableObjectUtility.GetSaveFolderForFolderName(SaveFolderName); var asset = CreateNewInstanceFromType(type); AssetDatabase.CreateAsset(asset, assetPath + "/" + GetNewFileName(type)); AssetDatabase.SetLabels(asset, new string[] { RucksackConstants.ProductName }); AddItem(asset, true); }; picker.Show(); }
public void Reset() { step = 0; firstStepType = null; step2Model = null; picker = ScriptPickerEditor.Get(typeof(InventoryItemBase)); picker.Show(true); picker.Close(); picker.OnPickObject += type => { firstStepType = type; step++; Repaint(); }; Focus(); }
private void ShowModuleTypePicker() { if (list == null) { UpdateList(); return; } const float buttonWidth = 200f; Rect rect = GUILayoutUtility.GetRect(buttonWidth, 9999f, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, GUILayout.ExpandHeight(false)); rect.y -= 4f; var width = rect.width; rect.width = buttonWidth; rect.x += (width - buttonWidth); if (allowMultipleImplementations || list.Count == 0) { if (GUI.Button(rect, new GUIContent("Add module", EditorGUIUtility.FindTexture("d_Toolbar Plus")), Style.addModuleButtonStyle)) { var ignoreList = new List <Type>(); if (allowDuplicateImplementations == false) { ignoreList = list.Select(o => o.GetType()).ToList(); ignoreList.AddRange(ReflectionUtility.GetAllTypesThatImplement(typeof(T)).Where(o => typeof(UnityEngine.Component).IsAssignableFrom(o) == false)); } var window = ScriptPickerEditor.Get(typeof(T), ignoreList.ToArray()); window.Show(); window.OnPickObject += type => { addModule(type); }; } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var r = position; r.width = 100; EditorGUI.PropertyField(r, property.FindPropertyRelative("restrictionType"), new GUIContent("")); r.x += r.width + 5; EditorGUI.PropertyField(r, property.FindPropertyRelative("filterType"), new GUIContent("")); int restrictionTypeIndex = property.FindPropertyRelative("restrictionType").enumValueIndex; var restrictionType = (ItemFilter.RestrictionType)restrictionTypeIndex; int filterTypeIndex = property.FindPropertyRelative("filterType").enumValueIndex; ItemFilter.FilterType filterType = (ItemFilter.FilterType)filterTypeIndex; r.x += r.width + 5; r.width = position.width - 210; var categoryValue = property.FindPropertyRelative("categoryValue"); var propertyValue = property.FindPropertyRelative("statDefinitionValue"); var rarityValue = property.FindPropertyRelative("rarityValue"); var stringValue = property.FindPropertyRelative("stringValue"); var boolValue = property.FindPropertyRelative("boolValue"); var floatValue = property.FindPropertyRelative("floatValue"); // var intValue = property.FindPropertyRelative("intValue"); switch (restrictionType) { case ItemFilter.RestrictionType.Type: //r.width -= 65; GUI.enabled = false; var t = System.Type.GetType(stringValue.stringValue); EditorGUI.LabelField(r, t != null ? t.Name : "(NOT SET)"); GUI.enabled = true; r.x += r.width - 60; r.width = 60; r.height = 14; if (GUI.Button(r, "Set", "minibutton")) { var typePicker = ScriptPickerEditor.Get(typeof(InventoryItemBase)); typePicker.Show(); typePicker.OnPickObject += type => { stringValue.stringValue = type.AssemblyQualifiedName; GUI.changed = true; // To save.. stringValue.serializedObject.ApplyModifiedProperties(); }; } break; case ItemFilter.RestrictionType.Stat: if (filterType == ItemFilter.FilterType.LessThan || filterType == ItemFilter.FilterType.GreatherThan) { r.width /= 2; ObjectPickerUtility.RenderObjectPickerForType <StatDefinition>(r, "", propertyValue); r.x += r.width; floatValue.floatValue = EditorGUI.FloatField(r, floatValue.floatValue); } else { ObjectPickerUtility.RenderObjectPickerForType <StatDefinition>(r, "", propertyValue); } break; case ItemFilter.RestrictionType.Category: ObjectPickerUtility.RenderObjectPickerForType <ItemCategory>(r, "", categoryValue); break; case ItemFilter.RestrictionType.Rarity: ObjectPickerUtility.RenderObjectPickerForType <ItemRarity>(r, "", rarityValue); break; case ItemFilter.RestrictionType.Weight: floatValue.floatValue = EditorGUI.FloatField(r, floatValue.floatValue); break; case ItemFilter.RestrictionType.Sellable: case ItemFilter.RestrictionType.Storable: case ItemFilter.RestrictionType.Droppable: boolValue.boolValue = EditorGUI.Toggle(r, boolValue.boolValue); break; default: break; } EditorGUI.EndProperty(); }