using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine; [assembly: InternalsVisibleTo("Unity.Formats.Fbx.Editor")] [assembly: InternalsVisibleTo("Unity.Formats.Fbx.Editor.Tests")] [assembly: InternalsVisibleTo("Unity.ProBuilder.AddOns.Editor")] namespace UnityEngine.Formats.Fbx.Exporter { [System.Serializable] internal struct StringPair { private string m_fbxObjectName; public string FBXObjectName { get { return m_fbxObjectName; } set { m_fbxObjectName = value; } } private string m_unityObjectName; public string UnityObjectName { get { return m_unityObjectName; } set { m_unityObjectName = value; } } } /// /// Handler for an OnUpdate event. /// /// The update is performed on a temporary instance, which, shortly after /// this handler is invoked, will be applied to the prefab. /// /// The event handler can make changes to any objects in the hierarchy rooted /// by the updatedInstance. Those changes will be applied to the prefab. /// /// The updatedObjects include all objects in the temporary instance /// that were: /// - created, or /// - changed parent, or /// - had a component that was created, destroyed, or updated. /// There is no notification for entire objects that were destroyed. /// internal delegate void HandleUpdate(FbxPrefab updatedInstance, IEnumerable updatedObjects); /// /// This component is applied to a prefab. It keeps the prefab sync'd up /// with an FBX file. /// /// Other parts of the ecosystem: /// FbxPrefabInspector /// FbxPrefabAutoUpdater /// internal class FbxPrefab : MonoBehaviour { ////////////////////////////////////////////////////////////////////// // TODO: Fields included in editor must be included in player, or it doesn't // build. /// /// Representation of the FBX file as it was when the prefab was /// last saved. This lets us update the prefab when the FBX changes. /// [SerializeField] // [HideInInspector] string m_fbxHistory; [SerializeField] List m_nameMapping = new List(); /// /// Which FBX file does this refer to? /// [SerializeField] [Tooltip("Which FBX file does this refer to?")] GameObject m_fbxModel; /// /// Should we auto-update this prefab when the FBX file is updated? /// [Tooltip("Should we auto-update this prefab when the FBX file is updated?")] [SerializeField] bool m_autoUpdate = true; public string FbxHistory { get{ return m_fbxHistory; } set{ m_fbxHistory = value; } } public List NameMapping { get { return m_nameMapping; } } public GameObject FbxModel { get{ return m_fbxModel; } set{ m_fbxModel = value; } } public bool AutoUpdate { get{ return m_autoUpdate; } set{ m_autoUpdate = value; } } ////////////////////////////////////////////////////////////////////////// // Event handling for updates. /// /// OnUpdate is raised once when an FbxPrefab gets updated, after all the changes /// have been done. /// public static event HandleUpdate OnUpdate; /// /// Notify listeners that they're free to make adjustments. /// This will be called after the FbxPrefab auto updater has completed it's work. /// /// Updated FbxPrefab instance. /// Updated objects. public static void CallOnUpdate(FbxPrefab instance, IEnumerable updatedObjects){ if (OnUpdate != null) { OnUpdate (instance, updatedObjects); } } } }