139 lines
4.4 KiB
C#
139 lines
4.4 KiB
C#
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; }
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
internal delegate void HandleUpdate(FbxPrefab updatedInstance, IEnumerable<GameObject> updatedObjects);
|
|
|
|
/// <summary>
|
|
/// 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
|
|
/// </summary>
|
|
internal class FbxPrefab : MonoBehaviour
|
|
{
|
|
//////////////////////////////////////////////////////////////////////
|
|
// TODO: Fields included in editor must be included in player, or it doesn't
|
|
// build.
|
|
|
|
/// <summary>
|
|
/// Representation of the FBX file as it was when the prefab was
|
|
/// last saved. This lets us update the prefab when the FBX changes.
|
|
/// </summary>
|
|
[SerializeField] // [HideInInspector]
|
|
string m_fbxHistory;
|
|
|
|
[SerializeField]
|
|
List<StringPair> m_nameMapping = new List<StringPair>();
|
|
|
|
/// <summary>
|
|
/// Which FBX file does this refer to?
|
|
/// </summary>
|
|
[SerializeField]
|
|
[Tooltip("Which FBX file does this refer to?")]
|
|
GameObject m_fbxModel;
|
|
|
|
/// <summary>
|
|
/// Should we auto-update this prefab when the FBX file is updated?
|
|
/// <summary>
|
|
[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<StringPair> 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.
|
|
/// <summary>
|
|
/// OnUpdate is raised once when an FbxPrefab gets updated, after all the changes
|
|
/// have been done.
|
|
/// </summary>
|
|
public static event HandleUpdate OnUpdate;
|
|
|
|
/// <summary>
|
|
/// Notify listeners that they're free to make adjustments.
|
|
/// This will be called after the FbxPrefab auto updater has completed it's work.
|
|
/// </summary>
|
|
/// <param name="instance">Updated FbxPrefab instance.</param>
|
|
/// <param name="updatedObjects">Updated objects.</param>
|
|
public static void CallOnUpdate(FbxPrefab instance, IEnumerable<GameObject> updatedObjects){
|
|
if (OnUpdate != null) {
|
|
OnUpdate (instance, updatedObjects);
|
|
}
|
|
}
|
|
}
|
|
}
|