Skip to content

Commit

Permalink
refactored for unity beta release 2017.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonm-unity committed Apr 19, 2017
1 parent 3555ae7 commit 8317077
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 18 deletions.
@@ -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)
{
Expand All @@ -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);
}
}

Expand All @@ -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);
}

}
Expand Down
@@ -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()
Expand Down
@@ -1,4 +1,4 @@
#if ENABLE_TIMELINE
#if UNITY_2017_1_OR_NEWER

using System;
using UnityEngine;
Expand Down
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,4 +1,4 @@
#if ENABLE_TIMELINE
#if UNITY_2017_1_OR_NEWER
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand Down

0 comments on commit 8317077

Please sign in to comment.