浏览代码

fixed null reference when creating new AnimationPoseConfig

/0.8.0-preview.1_staging
sleal-unity 4 年前
当前提交
6b02e3bb
共有 1 个文件被更改,包括 33 次插入17 次删除
  1. 50
      com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseConfig.cs

50
com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseConfig.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Collections.LowLevel.Unsafe;
namespace UnityEngine.Perception.GroundTruth
{

/// </summary>
[Tooltip("The percentage within the clip that the pose starts, a value from 0 (beginning) to 1 (end)")]
public float startOffsetPercent;
/// <summary>
/// The label to use for any captures inside of this time period
/// </summary>

[CreateAssetMenu(fileName = "AnimationPoseConfig", menuName = "Perception/Animation Pose Config")]
public class AnimationPoseConfig : ScriptableObject
{
const string k_Unset = "unset";
/// The list of timestamps, order dependent
/// The list of timestamps
public List<PoseTimestampRecord> timestamps;
[SerializeField] List<PoseTimestampRecord> m_Timestamps = new List<PoseTimestampRecord>();
SortedList<float, string> sortedTimestamps;
void OnEnable()
/// <summary>
/// The sorted list of timestamps
/// </summary>
public List<PoseTimestampRecord> timestamps
sortedTimestamps = new SortedList<float, string>(timestamps.Count);
foreach (var ts in timestamps)
get => m_Timestamps;
set
sortedTimestamps.Add(ts.startOffsetPercent, ts.poseLabel);
m_Timestamps = value;
SortTimestamps();
const string k_Unset = "unset";
/// <summary>
/// Retrieves the pose for the clip at the current time.

public string GetPoseAtTime(float time)
{
if (time < 0 || time > 1) return k_Unset;
if (timestamps == null || !timestamps.Any()) return k_Unset;
if (time < 0f || time > 1f) return k_Unset;
if (m_Timestamps == null || !m_Timestamps.Any()) return k_Unset;
if (sortedTimestamps.Keys.Count == 1)
if (m_Timestamps.Count == 1)
return time > sortedTimestamps.Keys[0] ? sortedTimestamps.Values[0] : k_Unset;
return time > m_Timestamps[0].startOffsetPercent ? m_Timestamps[0].poseLabel : k_Unset;
for (var i = 0; i < sortedTimestamps.Keys.Count - 1; i++)
for (var i = 0; i < m_Timestamps.Count - 1; i++)
if (time >= sortedTimestamps.Keys[i] && time <= sortedTimestamps.Keys[i + 1]) return sortedTimestamps.Values[i];
if (time >= m_Timestamps[i].startOffsetPercent && time <= m_Timestamps[i + 1].startOffsetPercent)
return m_Timestamps[i].poseLabel;
return time < sortedTimestamps.Keys.Last() ? k_Unset : sortedTimestamps.Values.Last();
var last = m_Timestamps.Last();
return time < last.startOffsetPercent ? k_Unset : last.poseLabel;
}
void OnEnable()
{
SortTimestamps();
}
void SortTimestamps()
{
m_Timestamps.Sort((stamp1, stamp2) => stamp1.startOffsetPercent.CompareTo(stamp2.startOffsetPercent));
}
}
}
正在加载...
取消
保存