/// <summary> /// Checks if the given item is part of this combination. /// </summary> public bool IsPartOfCraft(SO_Item _Item) { foreach (SO_Item item in m_CraftablItems) { if (_Item == item) { return(true); } } return(false); }
/// <summary> /// Creates an item asset for the selected items' GameObjects. /// </summary> /// <param name="_SelectedObjects">The current GameObjects selection.</param> private static void CreateItemAsset(GameObject[] _SelectedObjects) { foreach (GameObject go in _SelectedObjects) { if (go.TryGetComponent(out Item item)) { // Get the original prefab of the selected GameObject Item source = PrefabUtility.GetCorrespondingObjectFromOriginalSource(item); if (source == null) { continue; } // Get the path of the original item GameObject prefab string sourcePath = AssetDatabase.GetAssetPath(source); sourcePath = $"{Path.GetDirectoryName(sourcePath)}/{source.name}.asset"; // Create and save the new item asset SO_Item itemAsset = CreateInstance <SO_Item>(); AssetDatabase.CreateAsset(itemAsset, sourcePath); // Assign the item assets' prefab property SerializedObject itemAssetSerialized = new SerializedObject(itemAsset); itemAssetSerialized.FindProperty("m_Prefab").objectReferenceInstanceIDValue = source.GetInstanceID(); itemAssetSerialized.ApplyModifiedProperties(); // Assign the new item asset to the selected GameObject SerializedObject sourceSerialized = new SerializedObject(source); sourceSerialized.FindProperty("m_ItemAsset").objectReferenceInstanceIDValue = itemAsset.GetInstanceID(); // Update assets and save database itemAssetSerialized.ApplyModifiedProperties(); sourceSerialized.ApplyModifiedProperties(); AssetDatabase.SaveAssets(); } } }
/// <summary> /// Checks if this effect can be applied. /// If false, it means that the item can't be used at all. /// </summary> /// <param name="_Item">The used item that triggers this effect.</param> /// <param name="_User">The entity that used the item.</param> /// <returns>Returns true if the effect can be applied, otherwise false.</returns> public virtual bool CanBeApplied(SO_Item _Item, ItemUser _User) { return(true); }
/// <summary> /// Called when this effect should be applied. Note that if this method is used by the system, it means that CanBeApplied() had /// been called before and returned true. /// </summary> /// <param name="_Item">The used item that triggers this effect.</param> /// <param name="_User">The entity that used the item.</param> /// <returns>Returns true if the effect has been applied successfully, otherwise false.</returns> public abstract bool Apply(SO_Item _Item, ItemUser _User);