From 83170777b3a30d52f81a231c651a052636cda61b Mon Sep 17 00:00:00 2001 From: jasonm-unity Date: Wed, 19 Apr 2017 10:41:05 -0400 Subject: [PATCH] refactored for unity beta release 2017.1 --- .../Editor/Importer/AlembicImporter.cs | 29 +++++++------- .../Editor/Importer/AlembicImporterEditor.cs | 5 ++- .../Scripts/Timeline/AlembicShotAsset.cs | 2 +- .../Scripts/Timeline/AlembicShotPlayable.cs | 38 +++++++++++++++++++ .../Timeline/AlembicShotPlayable.cs.meta | 12 ++++++ .../Alembic/Scripts/Timeline/AlembicTrack.cs | 2 +- 6 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs create mode 100644 AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs.meta diff --git a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs index 5cd224ae9..856c42bbd 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs @@ -1,38 +1,39 @@ -#if ENABLE_SCRIPTED_IMPORTERS +#if UNITY_2017_1_OR_NEWER using UnityEditor; using UnityEngine; +using UnityEditor.Experimental.AssetImporters; namespace UTJ.Alembic { - [UnityEditor.Experimental.ScriptedImporter(1, "abc")] - public class AlembicImporter : UnityEditor.Experimental.ScriptedImporter + [ScriptedImporter(1, "abc")] + public class AlembicImporter : ScriptedImporter { [SerializeField] public AlembicImportSettings m_ImportSettings = new AlembicImportSettings(); [HideInInspector][SerializeField] public AlembicDiagnosticSettings m_diagSettings = new AlembicDiagnosticSettings(); [HideInInspector][SerializeField] public AlembicImportMode m_importMode = AlembicImportMode.AutomaticStreamingSetup; - public override void OnImportAsset() + public override void OnImportAsset(AssetImportContext ctx) { - m_ImportSettings.m_pathToAbc = assetSourcePath; + m_ImportSettings.m_pathToAbc = new DataPath() {root = DataPath.Root.Absolute, leaf = ctx.assetPath }; var mainObject = AlembicImportTasker.Import(m_importMode, m_ImportSettings, m_diagSettings, (stream, mainGO, streamDescr) => { - GenerateSubAssets(mainGO, stream); + GenerateSubAssets(ctx, mainGO, stream); if(streamDescr != null) - AddSubAsset( mainGO.name, streamDescr); + ctx.AddSubAsset( mainGO.name, streamDescr); }); - SetMainAsset(mainObject.name, mainObject); + ctx.SetMainAsset(mainObject.name, mainObject); } - private void GenerateSubAssets( GameObject go, AlembicStream stream) + private void GenerateSubAssets( AssetImportContext ctx, GameObject go, AlembicStream stream) { var material = new Material(Shader.Find("Standard")) { }; - AddSubAsset("Default Material", material); + ctx.AddSubAsset("Default Material", material); - CollectSubAssets(stream.AlembicTreeRoot, material); + CollectSubAssets(ctx, stream.AlembicTreeRoot, material); } - private void CollectSubAssets(AlembicTreeNode node, Material mat) + private void CollectSubAssets(AssetImportContext ctx, AlembicTreeNode node, Material mat) { if (m_ImportSettings.m_importMeshes) { @@ -41,7 +42,7 @@ private void CollectSubAssets(AlembicTreeNode node, Material mat) { var m = meshFilter.sharedMesh; m.name = node.linkedGameObj.name; - AddSubAsset(m.name, m); + ctx.AddSubAsset(m.name, m); } } @@ -50,7 +51,7 @@ private void CollectSubAssets(AlembicTreeNode node, Material mat) renderer.material = mat; foreach( var child in node.children ) - CollectSubAssets(child, mat); + CollectSubAssets(ctx, child, mat); } } diff --git a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs index 011741c82..bc50e185f 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs @@ -1,13 +1,14 @@ -#if ENABLE_SCRIPTED_IMPORTERS +#if UNITY_2017_1_OR_NEWER using System; using UnityEditor; using UnityEngine; +using UnityEditor.Experimental.AssetImporters; namespace UTJ.Alembic { [CustomEditor(typeof(AlembicImporter))] - public class AlembicImporterEditor : UnityEditor.Experimental.ScriptedImporterEditor + public class AlembicImporterEditor : ScriptedImporterEditor { public override void OnInspectorGUI() diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs index 2b0f76776..f925573dc 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs @@ -1,4 +1,4 @@ -#if ENABLE_TIMELINE +#if UNITY_2017_1_OR_NEWER using System; using UnityEngine; diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs new file mode 100644 index 000000000..3dc7608b9 --- /dev/null +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs @@ -0,0 +1,38 @@ +#if UNITY_2017_1_OR_NEWER + +using System; +using UnityEngine.Playables; + +namespace UTJ.Alembic +{ + public class AlembicShotPlayable : ScriptPlayable + { + public AlembicStreamPlayer streamPlayer { get; set; } + + public float m_StartTimeOffsetsdfs; + + public float m_StartTimeOffset; + public float m_EndTimeClipOff; + public float m_TimeScale; + public AlembicPlaybackSettings.CycleType m_Cycle = AlembicPlaybackSettings.CycleType.Hold; + + public override void ProcessFrame(FrameData info, object playerData) + { + base.ProcessFrame(info, playerData); + + if (streamPlayer == null) + return; + + streamPlayer.m_PlaybackSettings.m_startTime = 0f; + streamPlayer.m_PlaybackSettings.m_cycle = m_Cycle; + streamPlayer.m_PlaybackSettings.m_timeOffset = (float)m_StartTimeOffset; + streamPlayer.m_PlaybackSettings.m_endTime = (float)streamPlayer.m_PlaybackSettings.m_duration - m_EndTimeClipOff; + streamPlayer.m_PlaybackSettings.m_timeScale = (float)m_TimeScale; + streamPlayer.m_PlaybackSettings.m_Time = (float)handle.time; + streamPlayer.m_PlaybackSettings.m_OverrideTime = true; + streamPlayer.m_PlaybackSettings.m_preserveStartTime = true; + } + } +} + +#endif diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs.meta b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs.meta new file mode 100644 index 000000000..b27abbbae --- /dev/null +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9cd9987895ad98e4889ea378e1b047f6 +timeCreated: 1492612433 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicTrack.cs b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicTrack.cs index 7dd0b9e4e..482c1b2df 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicTrack.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicTrack.cs @@ -1,4 +1,4 @@ -#if ENABLE_TIMELINE +#if UNITY_2017_1_OR_NEWER using System.Collections; using System.Collections.Generic; using UnityEngine;