/// <summary> /// 当目标骨骼需要移除的时候使用,目前还不完善,先不要使用 /// </summary> /// <param name="target">要移除的目标骨骼</param> public void RemoveBone(DynamicBone target) { int index = boneList.IndexOf(target); if (index == -1) { return; } //TODO:移除骨骼的逻辑 boneList.RemoveAt(index); int curHeadIndex = target.HeadInfo.Index; //移除Bone的相关Collider的关系 boneColliderMatchMap.Remove(curHeadIndex); //是否是队列中末尾对象 bool isEndTarget = curHeadIndex == headInfoList.Length - 1; if (isEndTarget) { headInfoList.RemoveAtSwapBack(curHeadIndex); headTransformAccessArray.RemoveAtSwapBack(curHeadIndex); for (int i = MaxParticleLimit - 1; i >= 0; i--) { int dataOffset = curHeadIndex * MaxParticleLimit + i; particleInfoList.RemoveAtSwapBack(dataOffset); particleTransformAccessArray.RemoveAtSwapBack(dataOffset); } } else { //将最末列的HeadInfo 索引设置为当前将要移除的HeadInfo 索引 DynamicBone lastTarget = boneList[boneList.Count - 1]; HeadInfo lastHeadInfo = lastTarget.ResetHeadIndexAndDataOffset(curHeadIndex); headInfoList.RemoveAtSwapBack(curHeadIndex); headInfoList[curHeadIndex] = lastHeadInfo; headTransformAccessArray.RemoveAtSwapBack(curHeadIndex); for (int i = MaxParticleLimit - 1; i >= 0; i--) { int dataOffset = curHeadIndex * MaxParticleLimit + i; particleInfoList.RemoveAtSwapBack(dataOffset); particleTransformAccessArray.RemoveAtSwapBack(dataOffset); } } target.ClearJobData(); }
/// <summary> /// 将目标骨骼添加到结构中 /// </summary> /// <param name="target"></param> public void AddBone(DynamicBone target) { int index = boneList.IndexOf(target); if (index != -1) { return; // //防止重复添加 } boneList.Add(target); target.HeadInfo.DataOffsetInGlobalArray = particleInfoList.Length; int headIndex = headInfoList.Length; target.HeadInfo.Index = headIndex; //添加Bone和Collider的关系 foreach (var c in target.GetColliderArray()) { boneColliderMatchMap.Add(headIndex, c.ColliderInfo.Index); } headInfoList.Add(target.HeadInfo); particleInfoList.AddRange(target.ParticleInfoArray); headTransformAccessArray.Add(target.RootBoneParentTransform); for (int i = 0; i < MaxParticleLimit; i++) { particleTransformAccessArray.Add(target.ParticleTransformArray[i]); } ////树状结构测试 // Debug.Log(target.ParticleInfoArray.Length); // for (int i = 0; i < target.ParticleInfoArray.Length; i++) // { // Debug.Log(target.ParticleInfoArray[i].ParentIndex); // } }