本文整理汇总了C#中UnityEngine.Transform.SetSiblingIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.SetSiblingIndex方法的具体用法?C# Transform.SetSiblingIndex怎么用?C# Transform.SetSiblingIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.SetSiblingIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
private void Update()
{
if (UpdateTimer.UpdateAutoReset())
{
int count = transform.childCount;
if (count == 0)
return;
if (startedChildCount != count)
{
//Child count changed
Reset(count);
}
if (lastIndex == -1)
{
trans = transform.GetChild(currentIndex);
pos = trans.position.z;
if (!trans.gameObject.activeSelf)
pos += 10000f;
for (int i = 0; i < 100; i++)
{
if (!sortedChilds.ContainsKey(pos))
break;
pos += 0.01f;
}
sortedChilds.Add(pos, trans);
currentIndex++;
if (currentIndex >= startedChildCount)
{
if (ReverseWorkingDirection)
lastIndex = 0;
else
lastIndex = sortedChilds.Count - 1;
}
}
else
{
for (int i = 0; i < sortedChilds.Count; i++)
{
trans = sortedChilds[sortedChilds.Keys[lastIndex]];
trans.SetSiblingIndex(ReverseOrder ? (sortedChilds.Count - lastIndex) : lastIndex);
if (ReverseWorkingDirection)
lastIndex++;
else
lastIndex--;
if (lastIndex < 0 || lastIndex >= sortedChilds.Count)
{
break;
}
}
Reset();
}
}
}
示例2: Rebase
static public void Rebase(Transform transform, Transform to)
{
var transformSO = new SerializedObject(transform);
var toSO = new SerializedObject(to);
var transformPrefabLink = transformSO.FindProperty("m_PrefabInternal").objectReferenceValue;
var toPrefabLink = toSO.FindProperty("m_PrefabInternal").objectReferenceValue;
toSO.FindProperty("m_PrefabInternal").objectReferenceValue = null;
transformSO.FindProperty("m_PrefabInternal").objectReferenceValue = null;
transformSO.ApplyModifiedProperties();
toSO.ApplyModifiedProperties();
var index = transform.GetSiblingIndex();
var lp = transform.localPosition;
var lr = transform.localRotation;
var ls = transform.localScale;
transform.parent = to;
transform.localPosition = lp;
transform.localRotation = lr;
transform.localScale = ls;
transform.SetSiblingIndex(index);
transformSO.Update();
toSO.Update();
transformSO.FindProperty("m_PrefabInternal").objectReferenceValue = transformPrefabLink;
toSO.FindProperty("m_PrefabInternal").objectReferenceValue = toPrefabLink;
transformSO.ApplyModifiedProperties();
toSO.ApplyModifiedProperties();
}