/// <summary> /// Adds a copy of the provided schema object. /// </summary> /// <param name="schema">The schema to add. A copy will be made and saved in a folder relative to the main Addressables settings asset. </param> /// <param name="postEvent">Determines if this method call will post an event to the internal addressables event system</param> /// <returns>The created schema object.</returns> public AddressableAssetGroupSchema AddSchema(AddressableAssetGroupSchema schema, bool postEvent = true) { var added = m_SchemaSet.AddSchema(schema, GetSchemaAssetPath); if (added != null) { added.Group = this; SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaAdded, this, postEvent); } return(added); }
/// <summary> /// Adds a copy of the provided schema object. /// </summary> /// <param name="schema">The schema to copy.</param> /// <param name="pathFunc">A function that returns the path where this method can save the schema asset. Set to null to not create an in-project asset.</param> /// <returns>The created schema object.</returns> public AddressableAssetGroupSchema AddSchema(AddressableAssetGroupSchema schema, Func <Type, string> pathFunc) { if (schema == null) { Debug.LogWarning("Cannot add null Schema object."); return(null); } var type = schema.GetType(); if (GetSchema(type) != null) { Debug.LogWarningFormat("Cannot add multiple schemas of the same type: {0}.", type.FullName); return(null); } if (pathFunc == null) { m_Schemas.Add(schema); return(schema); } var assetName = pathFunc(type); if (File.Exists(assetName)) { Debug.LogWarningFormat("Schema asset already exists at path {0}, relinking.", assetName); var existingSchema = AssetDatabase.LoadAssetAtPath(assetName, type) as AddressableAssetGroupSchema; m_Schemas.Add(existingSchema); return(existingSchema); } var newSchema = Object.Instantiate(schema); if (!string.IsNullOrEmpty(assetName)) { var dir = Path.GetDirectoryName(assetName); if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) { Directory.CreateDirectory(dir); } AssetDatabase.CreateAsset(newSchema, assetName); } m_Schemas.Add(newSchema); return(newSchema); }
/// <summary> /// Adds the AddressableAssetGroupSchema of type to the template. /// </summary> /// <param name="type">The Type for the AddressableAssetGroupSchema to add to this template.</param> /// <param name="postEvent">If true, the event is propagated to callbacks.</param> /// <returns>If true, the type was added successfully.</returns> public bool AddSchema(Type type, bool postEvent = true) { if (type == null) { Debug.LogWarning("Cannot remove schema with null type."); return(false); } if (!typeof(AddressableAssetGroupSchema).IsAssignableFrom(type)) { Debug.LogWarningFormat("Invalid Schema type {0}. Schemas must inherit from AddressableAssetGroupSchema.", type.FullName); return(false); } foreach (AddressableAssetGroupSchema schemaObject in m_SchemaObjects) { if (schemaObject.GetType() == type) { Debug.LogError("Scheme of type " + type + " already exists"); return(false); } } AddressableAssetGroupSchema schemaInstance = (AddressableAssetGroupSchema)CreateInstance(type); if (schemaInstance != null) { schemaInstance.name = type.Name; try { schemaInstance.hideFlags |= HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(schemaInstance, this); } catch (Exception e) { Console.WriteLine(e); throw; } m_SchemaObjects.Add(schemaInstance); SetDirty(AddressableAssetSettings.ModificationEvent.GroupTemplateSchemaAdded, this, postEvent); AssetDatabase.SaveAssets(); } return(schemaInstance != null); }
/// <summary> /// Adds a copy of the provided schema object. /// </summary> /// <param name="schema">The schema to add. A copy will be made and saved in a folder relative to the main Addressables settings asset. </param> /// <param name="postEvent">Determines if this method call will post an event to the internal addressables event system</param> /// <returns>The created schema object.</returns> public AddressableAssetGroupSchema AddSchema(AddressableAssetGroupSchema schema, bool postEvent = true) { var added = m_SchemaSet.AddSchema(schema, GetSchemaAssetPath); if (added != null) { added.Group = this; if (m_Settings && m_Settings.IsPersisted) { EditorUtility.SetDirty(added); } SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaAdded, this, postEvent, true); AssetDatabase.SaveAssets(); } return(added); }