private static void AddWaypointToGroupOnClick(WaypointGroup group, int afterIndex, Vector3 worldPosition) { if (Event.current.alt) { // when using alt the user is likely panning around an object, ignore the add method. return; } Handles.Label(worldPosition, "Inserted waypoint at: " + worldPosition); Handles.color = Color.green; Handles.SphereCap(-1, worldPosition, Quaternion.identity, 0.5f); var afterIndexClamped = Mathf.Max(0, afterIndex - 1); if (afterIndexClamped > 0 && afterIndexClamped < group.waypoints.Length) { Handles.DrawAAPolyLine(LineWidth, group.waypoints[afterIndexClamped].transform.position, worldPosition); } Handles.color = Color.white; // Connect from the last to a new waypoint if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { Undo.RecordObject(group, "Added waypoint"); group.InsertWaypointAfter(group.transform.worldToLocalMatrix * (worldPosition - group.transform.localPosition), afterIndex); _selectedWaypointGroup = group; _selectedWaypointIndex = afterIndex; EditorUtility.SetDirty(group); } }
public override void AddItem(InventoryItemBase item, bool editOnceAdded = true) { base.AddItem(item, editOnceAdded); UpdateAssetName(item); EditorUtility.SetDirty(ItemManager.database); // To save it. }
public override void RemoveItem(int i) { // var l = new List<InventoryItemBase>(ItemManager.database.items); var allUsingCategory = ItemManager.database.items.Where(o => o.category == crudList[i]).ToArray(); if (allUsingCategory.Length == 0) { base.RemoveItem(i); } else { var window = ReplaceWithDialog.Get((index, editorWindow) => { if (index == -1) { Debug.Log("Not replacing - Deleting category"); } else { Debug.Log("Replace category with " + ItemManager.database.categories[index].name); foreach (var item in allUsingCategory) { item.category = ItemManager.database.categories[index]; EditorUtility.SetDirty(item); } } base.RemoveItem(i); editorWindow.Close(); }, "Category", allUsingCategory.Length, ItemManager.database.itemCategoriesStrings); window.Show(); } }
public override void DuplicateItem(int index) { var source = crudList[index]; var item = UnityEngine.Object.Instantiate <InventoryItemBase>(source); item.ID = (crudList.Count > 0) ? crudList.Max(o => o.ID) + 1 : 0; item.name += "(duplicate)"; string prefabPath = InventoryScriptableObjectUtility.GetSaveFolderForFolderName("Items") + "/item_" + System.DateTime.Now.ToFileTimeUtc() + "_PFB.prefab"; var prefab = PrefabUtility.CreatePrefab(prefabPath, item.gameObject); prefab.layer = InventorySettingsManager.instance.settings.itemWorldLayer; AssetDatabase.SetLabels(prefab, new string[] { "InventoryProPrefab" }); AddItem(prefab.gameObject.GetComponent <InventoryItemBase>()); EditorUtility.SetDirty(prefab); // To save it. UnityEngine.Object.DestroyImmediate(item.gameObject, false); // Destroy the instance created window.Repaint(); }
public override void RemoveItem(int i) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(ItemManager.database.items[i])); base.RemoveItem(i); EditorUtility.SetDirty(ItemManager.database); // To save it. }
public override void RemoveItem(int i) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(ItemManager.database.items[i])); //UnityEngine.Object.DestroyImmediate(((InventoryItemBase)itemEditorInspectorList[i].target).gameObject); //itemEditorInspectorList.RemoveAt(i); base.RemoveItem(i); EditorUtility.SetDirty(ItemManager.database); // To save it. }
protected override void CreateNewItem() { var picker = CreateNewItemEditor.Get((System.Type type, GameObject obj, EditorWindow thisWindow) => { InventoryScriptableObjectUtility.SetPrefabSaveFolderIfNotSet(); string prefabPath = InventoryScriptableObjectUtility.GetSaveFolderForFolderName("Items") + "/item_" + System.DateTime.Now.ToFileTimeUtc() + "_PFB.prefab"; //var obj = GameObject.CreatePrimitive(PrimitiveType.Cube); var instanceObj = UnityEngine.Object.Instantiate <GameObject>(obj); // For unity 5.3+ - Source needs to be instance object. var prefab = PrefabUtility.CreatePrefab(prefabPath, instanceObj); UnityEngine.Object.DestroyImmediate(instanceObj); if (InventorySettingsManager.instance != null && InventorySettingsManager.instance.settings != null) { prefab.layer = InventorySettingsManager.instance.settings.itemWorldLayer; } else { Debug.LogWarning("Couldn't set item layer because there's no InventorySettingsManager in the scene"); } AssetDatabase.SetLabels(prefab, new string[] { "InventoryProPrefab" }); var comp = (InventoryItemBase)prefab.AddComponent(type); comp.ID = (crudList.Count > 0) ? crudList.Max(o => o.ID) + 1 : 0; EditorUtility.SetDirty(comp); // To save it. prefab.GetOrAddComponent <ItemTrigger>(); prefab.GetOrAddComponent <ItemTriggerInputHandler>(); if (prefab.GetComponent <SpriteRenderer>() == null) { // This is not a 2D object if (prefab.GetComponent <Collider>() == null) { prefab.AddComponent <BoxCollider>(); } var sphereCollider = prefab.GetOrAddComponent <SphereCollider>(); sphereCollider.isTrigger = true; sphereCollider.radius = 1f; prefab.GetOrAddComponent <Rigidbody>(); } // Avoid deleting the actual prefab / model, only the cube / internal models without an asset path. if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(obj))) { Object.DestroyImmediate(obj); } AddItem(comp, true); thisWindow.Close(); }); picker.Show(); }
/*private void RepairPrefabLinks() * { * var crudListCopy = crudList; * * for(int i = 0; i < crudListCopy.Count; i++) * { * InventoryItemBase realPrefab = null; * * if(DevdogPrefabUtility.IsComponentReferenceIsBroken(crudListCopy[i], ref realPrefab)) * { * crudListCopy[i] = realPrefab; * } * } * * crudList = crudListCopy; * * }*/ protected override void SyncIDs() { Debug.Log("Item ID's out of sync, force updating..."); //RepairPrefabLinks(); List <InventoryItemBase> crudListResult = new List <InventoryItemBase>(); var crudListCopy = crudList; InventoryItemBase realPrefab = null; uint lastID = 0; for (int i = 0, j = 0; i < crudListCopy.Count; ++i) { var item = crudListCopy[i]; if (item != null) { var editor = GetEditor(item, (int)lastID); InventoryItemBase inventoryItemBase = editor.target as InventoryItemBase; inventoryItemBase.ID = lastID++; crudListResult.Add(UpdatePrefab(inventoryItemBase, item)); } /*else if(DevdogPrefabUtility.IsComponentReferenceIsBroken(crudListCopy[i], ref realPrefab)) * { * item = realPrefab; * * var editor = GetEditor(item, (int)lastID); * InventoryItemBase inventoryItemBase = editor.target as InventoryItemBase; * inventoryItemBase.ID = lastID++; * crudListResult.Add(UpdatePrefab(inventoryItemBase, item)); * }*/ else { /* * Debug.Log("Item is null" + item.GetInstanceID()); * * var editor = itemEditorInspectorList[(int)lastID]; * * if (editor != null && itemEditorInspectorList[i].target != null) * { * InventoryItemBase inventoryItemBase = editor.target as InventoryItemBase; * UnityEngine.Object.DestroyImmediate(inventoryItemBase.gameObject); * } * * itemEditorInspectorList.RemoveAt((int)lastID); */ } } crudList = crudListResult; selectedItem = null; EditorUtility.SetDirty(ItemManager.database); }
// Utils private void Save() { if (watch.ElapsedMilliseconds > 5000) { watch.Reset(); watch.Start(); EditorUtility.SetDirty(BoltRuntimeSettings.instance); AssetDatabase.SaveAssets(); } }
// Utils private void Save() { if (Watch.ElapsedMilliseconds > 5000) { Watch.Reset(); Watch.Start(); EditorUtility.SetDirty(AppSettingsScriptableObject); AssetDatabase.SaveAssets(); } }
public override void RemoveItem(int i) { var allUsingStat = ItemManager.database.items.Where(o => o.stats.Any(s => s.stat == crudList[i])).ToArray(); foreach (var item in allUsingStat) { var l = item.stats.ToList(); l.RemoveAll(o => o.stat.ID == crudList[i].ID); item.stats = l.ToArray(); EditorUtility.SetDirty(item); } base.RemoveItem(i); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); var t = (UNetEquipmentCollectionCreator)target; var bridge = t.GetComponent <UNetActionsBridge>(); EditorGUILayout.Space(); EditorGUILayout.Space(); using (new VerticalLayoutBlock("box")) { EditorGUILayout.LabelField("Editor", UnityEditor.EditorStyles.boldLabel); EditorGUILayout.LabelField("Copy collection data from CollectionUI component"); _collectionUI = (EquipmentCollectionUI)EditorGUILayout.ObjectField(_collectionUI, typeof(EquipmentCollectionUI), true); if (_collectionUI != null) { if (GUILayout.Button("Copy (overwrites old)")) { var collection = new EquipmentCollection <IEquippableItemInstance>(0, t.GetComponent <IEquippableCharacter <IEquippableItemInstance> >(), null); _collectionUI.collection = collection; // _collectionUI.IndexSlotsAndMountPoints(); t.slots = new UnitySerializedEquipmentCollectionSlot[_collectionUI.collection.slotCount]; for (int i = 0; i < _collectionUI.collection.slotCount; i++) { var equipmentTypes = new UnityEquipmentType[collection.slots[i].equipmentTypes.Length]; for (int j = 0; j < equipmentTypes.Length; j++) { equipmentTypes[j] = bridge.equipmentTypeDatabase.Get(new Identifier(collection.slots[i].equipmentTypes[j].ID)).result; } t.slots[i] = new UnitySerializedEquipmentCollectionSlot() { equipmentTypes = equipmentTypes, }; } EditorUtility.SetDirty(t); GUI.changed = true; Debug.Log($"Copied {_collectionUI.collection.slotCount} slots to player", t); _collectionUI.collection = null; } } } }
protected override void SyncIDs() { Debug.Log("Item ID's out of sync, force updating..."); crudList = crudList.Where(o => o != null).ToList(); uint lastID = 0; foreach (var item in crudList) { item.ID = lastID++; EditorUtility.SetDirty(item); } GUI.changed = true; EditorUtility.SetDirty(ItemManager.database); }
public void OnGUI() { DrawToolbar(); if (toolbarIndex < 0 || toolbarIndex >= editors.Count || editors.Count == 0) { toolbarIndex = 0; CreateEditors(); } // Draw the editor editors[toolbarIndex].Draw(); if (GUI.changed && LosManager.instance != null) { EditorUtility.SetDirty(LosManager.instance.settings); // To make sure it gets saved. } }
protected override void SyncIDs() { if (updatingPrefabs) { return; } updatingPrefabs = true; Debug.Log("Item ID's out of sync, force updating..."); crudList = crudList.Where(o => o != null).Distinct().ToList(); List <GameObject> brokenPrefabs = new List <GameObject>(); foreach (var o in crudList) { if (IsMissingComponent(o.gameObject)) { brokenPrefabs.Add(o.gameObject); } } if (brokenPrefabs.Count > 0) { Selection.objects = brokenPrefabs.ToArray(); Debug.LogError("Fix Broken Prefabs First"); return; } uint id = 0; foreach (var item in crudList) { UpdatePrefab(item, id); id++; } selectedItem = null; AssetDatabase.SaveAssets(); EditorUtility.SetDirty(ItemManager.database); updatingPrefabs = false; }
public void ConvertThisToNewType(InventoryItemBase currentItem, Type type) { var comp = (InventoryItemBase)currentItem.gameObject.AddComponent(type); ReflectionUtility.CopySerializableValues(currentItem, comp); // Set in database for (int i = 0; i < ItemManager.database.items.Length; i++) { if (ItemManager.database.items[i].ID == currentItem.ID) { ItemManager.database.items[i] = comp; } } selectedItem = comp; itemEditorInspector = Editor.CreateEditor(selectedItem); EditorUtility.SetDirty(selectedItem); GUI.changed = true; Object.DestroyImmediate(currentItem, true); // Get rid of the old object window.Repaint(); }
private static void HandlePositionHandle(WaypointGroup group) { for (int i = 0; i < group.waypoints.Length; i++) { if (group != _selectedWaypointGroup || i != _selectedWaypointIndex) { continue; } var waypoint = group.waypoints[i % group.waypoints.Length]; var waypointWorldPosition = waypoint.transform.position; EditorGUI.BeginChangeCheck(); waypointWorldPosition = Handles.PositionHandle(waypointWorldPosition, group.transform.rotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(group, "Moved waypoint"); waypoint.transform.localPosition = group.transform.worldToLocalMatrix * (waypointWorldPosition - group.transform.localPosition); EditorUtility.SetDirty(group); EditorUtility.SetDirty(group.waypoints[i].transform); } } }
public override void OnEnable() { base.OnEnable(); if (target == null) { return; } id = serializedObject.FindProperty("_id"); itemName = serializedObject.FindProperty("_name"); description = serializedObject.FindProperty("_description"); stats = serializedObject.FindProperty("_stats"); usageRequirements = serializedObject.FindProperty("_usageRequirement"); useCategoryCooldown = serializedObject.FindProperty("_useCategoryCooldown"); overrideDropObjectPrefab = serializedObject.FindProperty("_overrideDropObjectPrefab"); category = serializedObject.FindProperty("_category"); icon = serializedObject.FindProperty("_icon"); weight = serializedObject.FindProperty("_weight"); layoutSizeCols = serializedObject.FindProperty("_layoutSizeCols"); layoutSizeRows = serializedObject.FindProperty("_layoutSizeRows"); requiredLevel = serializedObject.FindProperty("_requiredLevel"); rarity = serializedObject.FindProperty("_rarity"); buyPrice = serializedObject.FindProperty("_buyPrice"); sellPrice = serializedObject.FindProperty("_sellPrice"); isDroppable = serializedObject.FindProperty("_isDroppable"); isSellable = serializedObject.FindProperty("_isSellable"); isStorable = serializedObject.FindProperty("_isStorable"); maxStackSize = serializedObject.FindProperty("_maxStackSize"); cooldownTime = serializedObject.FindProperty("_cooldownTime"); var t = (InventoryItemBase)target; _statsList = new UnityEditorInternal.ReorderableList(serializedObject, stats, true, true, true, true); _statsList.drawHeaderCallback += rect => GUI.Label(rect, "Item stats"); _statsList.elementHeight = 40; _statsList.drawElementCallback += (rect, index, active, focused) => { DrawItemStatLookup(rect, stats.GetArrayElementAtIndex(index), active, focused, true, true); }; _statsList.onAddCallback += (list) => { var l = new List <StatDecorator>(t.stats); l.Add(new StatDecorator()); t.stats = l.ToArray(); GUI.changed = true; // To save.. EditorUtility.SetDirty(target); serializedObject.ApplyModifiedProperties(); Repaint(); }; _usageRequirementList = new UnityEditorInternal.ReorderableList(serializedObject, usageRequirements, true, true, true, true); _usageRequirementList.drawHeaderCallback += rect => GUI.Label(rect, "Usage requirement stats"); _usageRequirementList.elementHeight = 40; _usageRequirementList.drawElementCallback += (rect, index, active, focused) => { var element = usageRequirements.GetArrayElementAtIndex(index); DrawUsageRequirement(rect, element, active, focused, true); }; _usageRequirementList.onAddCallback += (list) => { var l = new List <StatRequirement>(t.usageRequirement); l.Add(new StatRequirement()); t.usageRequirement = l.ToArray(); GUI.changed = true; // To save.. EditorUtility.SetDirty(target); serializedObject.ApplyModifiedProperties(); Repaint(); }; }
/// <summary> /// Save settings data. /// </summary> public virtual void Save() { UnityEditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); }
public override void OnEnable() { base.OnEnable(); equipType = serializedObject.FindProperty("_equipmentType"); equipSlotsData = serializedObject.FindProperty("equipSlotsData"); reorderableList = new ReorderableList(serializedObject, equipSlotsData, false, true, true, true); reorderableList.drawHeaderCallback += rect => EditorGUI.LabelField(rect, "UMA Equipment data"); reorderableList.elementHeight = 210; reorderableList.drawElementCallback += (rect, index, active, focused) => { // var t = (UMAEquippableInventoryItem)target; rect.height = 16; rect.y += 2; var o = equipSlotsData.GetArrayElementAtIndex(index); var umaEquipSlot = o.FindPropertyRelative("umaEquipSlot"); var umaOverrideColor = o.FindPropertyRelative("umaOverrideColor"); var umaOverlayColor = o.FindPropertyRelative("umaOverlayColor"); var umaOverlayDataAsset = o.FindPropertyRelative("umaOverlayDataAsset"); var umaSlotDataAsset = o.FindPropertyRelative("umaSlotDataAsset"); var umaReplaceSlot = o.FindPropertyRelative("umaReplaceSlot"); EditorGUI.LabelField(rect, "Equipment item " + index, UnityEditor.EditorStyles.boldLabel); rect.y += 20; EditorGUI.PropertyField(rect, umaEquipSlot); rect.y += 18; rect.y += 5; EditorGUI.PropertyField(rect, umaOverrideColor); rect.y += 18; if (umaOverrideColor.boolValue) { EditorGUI.PropertyField(rect, umaOverlayColor); rect.y += 18; } rect.y += 5; EditorGUI.PropertyField(rect, umaOverlayDataAsset); rect.y += 18; EditorGUI.PropertyField(rect, umaSlotDataAsset); rect.y += 18; EditorGUI.PropertyField(rect, umaReplaceSlot); rect.y += 23; string msg = ""; rect.height = 40; if (umaEquipSlot.objectReferenceValue != null) { if (umaOverlayDataAsset.objectReferenceValue != null && umaSlotDataAsset.objectReferenceValue == null && umaReplaceSlot.objectReferenceValue == null) { msg = "Equipping " + umaOverlayDataAsset.objectReferenceValue.name + "\nto\n" + umaEquipSlot.objectReferenceValue.name; } else if (umaOverlayDataAsset.objectReferenceValue != null && umaSlotDataAsset.objectReferenceValue != null && umaReplaceSlot.objectReferenceValue == null) { msg = "Equipping " + umaOverlayDataAsset.objectReferenceValue.name + " & " + umaSlotDataAsset.objectReferenceValue.name + "\nto\n" + umaEquipSlot.objectReferenceValue.name; } else if (umaOverlayDataAsset.objectReferenceValue != null && umaSlotDataAsset.objectReferenceValue != null && umaReplaceSlot.objectReferenceValue != null) { rect.height += 14; msg = "Equipping " + umaOverlayDataAsset.objectReferenceValue.name + " & " + umaSlotDataAsset.objectReferenceValue.name + "\nto\n" + umaEquipSlot.objectReferenceValue.name + "\nReplacing slot " + umaReplaceSlot.objectReferenceValue.ToString() + " while equipped."; } } if (msg != "") { EditorGUI.HelpBox(rect, msg, MessageType.Info); } // Changed something, copy property data if (GUI.changed) { EditorUtility.SetDirty(target); serializedObject.ApplyModifiedProperties(); Repaint(); } }; }
public plyStatsEditor(string name, EditorWindow window) { this.name = name; this.window = window; this.requiresDatabase = true; resultList = new UnityEditorInternal.ReorderableList(attributes, typeof(plyGameAttributeDatabaseModel), false, true, false, false); resultList.drawHeaderCallback += rect => { var r = rect; r.width = 40; r.x += 15; // Little offset on the start EditorGUI.LabelField(r, "Show"); var r2 = rect; r2.width -= 50; r2.width /= 3; r2.x += 50; EditorGUI.LabelField(r2, "Display name"); r2.x += r2.width; EditorGUI.LabelField(r2, "Category"); r2.x += r2.width; EditorGUI.LabelField(r2, "Formatter"); }; //resultList.elementHeight = 30; resultList.drawElementCallback += (rect, index, active, focused) => { rect.height = 16; rect.y += 2; if (index >= ItemManager.database.plyAttributes.Length) { return; } var stat = ItemManager.database.plyAttributes[index]; var r2 = rect; r2.width -= 50; r2.width /= 3; r2.width -= 10; r2.x += 50; var r = rect; r.width = 40; r.x += 15; stat.show = EditorGUI.Toggle(r, stat.show); GUI.enabled = stat.show; if (index >= 0 && index <= attributresStrings.Length) { EditorGUI.LabelField(r2, attributresStrings[index]); } r2.x += r2.width; r2.x += 10; stat.category = EditorGUI.TextField(r2, stat.category); GUI.enabled = true; if (GUI.changed) { EditorUtility.SetDirty(ItemManager.database); } }; }