예제 #1
0
 public override void RemoveAtSwapBack(int entityIndex)
 {
     RemoveAtSwapBack(ref decalEntities, entityIndex, count);
     RemoveAtSwapBack(ref decalProjectors, entityIndex, count);
     transformAccessArray.RemoveAtSwapBack(entityIndex);
     count--;
 }
예제 #2
0
        /// <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();
        }
예제 #3
0
        protected override void OnRemove(int index)
        {
            Assert.AreEqual(planets.length, transformPositions.Count);

            data.RemoveAtSwapBack(index);
            planets.RemoveAtSwapBack(index);
            planetPositions.RemoveAtSwapBack(index);
            satellitePositions.RemoveAtSwapBack(index);
        }
예제 #4
0
파일: MoveTest.cs 프로젝트: aiczk/MoApi
        private void Awake()
        {
            movement = GetComponent <Movement>();
            matching = GetComponent <Matching>();

            playerPool = new PlayerPool(prefab);
            transforms = new TransformAccessArray(4, 2);

            for (var i = 0; i < 4; i++)
            {
                var rent = playerPool.Rent();
                var trs  = rent.transform;

                rent.index = i;
                transforms.Add(trs);
            }

            matching
            .JoinClientAsObservable
            .Subscribe(index =>
            {
                Debug.Log(index.ToString());

                for (var i = 0; i < transforms.capacity; i++)
                {
                    var trs = transforms[i];

                    if (trs.GetComponent <IdentifierComponent>().index != index)
                    {
                        continue;
                    }

                    player = trs;
                    trs.gameObject.AddComponent <PlayerController>();
                    transforms.RemoveAtSwapBack(i);
                    break;
                }
            });

            matching
            .LeaveClientAsObservable
            .Subscribe(x =>
            {
                var go = player.gameObject;
                Destroy(go.GetComponent <PlayerController>());
                transforms.Add(player);
            });
        }
    internal void RemoveSpearsFromSystem(int spearCnt)
    {
        spearMovementJH.Complete();

        for (int i = 0; i < spearCnt; ++i)
        {
            taa_spears.RemoveAtSwapBack(taa_spears.length - 1);
        }

        int maxChange = spearCnt;

        if (maxChange > na_spearVelocities.Length)
        {
            na_spearVelocities.Dispose();
            na_spearVelocities = new NativeArray <Vector3>(0, Allocator.Persistent);
        }
        else
        {
            int newSize        = na_spearVelocities.Length - spearCnt;
            var tempVelocities = new NativeArray <Vector3>(newSize, Allocator.Temp);
            NativeArray <Vector3> .Copy(na_spearVelocities, 0, tempVelocities, 0, newSize);

            na_spearVelocities.Dispose();
            na_spearVelocities = new NativeArray <Vector3>(newSize, Allocator.Persistent);
            tempVelocities.CopyTo(na_spearVelocities);
        }

        if (maxChange > na_spearState.Length)
        {
            na_spearState.Dispose();
            na_spearState = new NativeArray <SpearState>(0, Allocator.Persistent);
        }
        else
        {
            int newSize     = na_spearState.Length - spearCnt;
            var tempActives = new NativeArray <SpearState>(newSize, Allocator.Temp);
            NativeArray <SpearState> .Copy(na_spearState, 0, tempActives, 0, newSize);

            na_spearState.Dispose();
            na_spearState = new NativeArray <SpearState>(newSize, Allocator.Persistent);
            tempActives.CopyTo(na_spearState);
        }

        PoolManager.instance.SpearPool.Expand(-spearCnt);
    }
예제 #6
0
 private void RemoveFromJobArrays(int removeAtIndex)
 {
     m_CachedTransforms.RemoveAtSwapBack(removeAtIndex);
     m_Positions[removeAtIndex]             = m_Positions[m_DecalsCount - 1];
     m_Rotations[removeAtIndex]             = m_Rotations[m_DecalsCount - 1];
     m_Scales[removeAtIndex]                = m_Scales[m_DecalsCount - 1];
     m_Sizes[removeAtIndex]                 = m_Sizes[m_DecalsCount - 1];
     m_Offsets[removeAtIndex]               = m_Offsets[m_DecalsCount - 1];
     m_ResolvedRotations[removeAtIndex]     = m_ResolvedRotations[m_DecalsCount - 1];
     m_ResolvedScales[removeAtIndex]        = m_ResolvedScales[m_DecalsCount - 1];
     m_ResolvedSizeOffsets[removeAtIndex]   = m_ResolvedSizeOffsets[m_DecalsCount - 1];
     m_ScaleModes[removeAtIndex]            = m_ScaleModes[m_DecalsCount - 1];
     m_NormalToWorlds[removeAtIndex]        = m_NormalToWorlds[m_DecalsCount - 1];
     m_DecalToWorlds[removeAtIndex]         = m_DecalToWorlds[m_DecalsCount - 1];
     m_BoundingSpheres[removeAtIndex]       = m_BoundingSpheres[m_DecalsCount - 1];
     m_Dirty[removeAtIndex]                 = m_Dirty[m_DecalsCount - 1];
     m_CachedBoundingSpheres[removeAtIndex] = m_CachedBoundingSpheres[m_DecalsCount - 1];
 }
    internal void RemoveMobsFromSystem(int mobCnt)
    {
        movementJH.Complete();

        for (int i = 0; i < mobCnt; ++i)
        {
            if (taa_mobs.length > 0)
            {
                taa_mobs.RemoveAtSwapBack(taa_mobs.length - 1);
            }

            if (nl_startPos.Length > 0)
            {
                nl_startPos.RemoveAtSwapBack(nl_startPos.Length - 1);
            }

            if (nl_targetPos.Length > 0)
            {
                nl_targetPos.RemoveAtSwapBack(nl_targetPos.Length - 1);
            }
        }

        int maxChange = mobCnt;

        if (maxChange > na_mobStates.Length)
        {
            na_mobStates.Dispose();
            na_mobStates = new NativeArray <MobState>(0, Allocator.Persistent);
        }
        else
        {
            int newSize    = na_mobStates.Length - mobCnt;
            var tempStates = new NativeArray <MobState>(newSize, Allocator.Temp);
            NativeArray <MobState> .Copy(na_mobStates, 0, tempStates, 0, newSize);

            na_mobStates.Dispose();
            na_mobStates = new NativeArray <MobState>(newSize, Allocator.Persistent);
            tempStates.CopyTo(na_mobStates);
        }

        PoolManager.instance.MobPool.Expand(-mobCnt);

        RemoveSpearsFromSystem(mobCnt);
    }
    void Update()
    {
        // add instance
        if (Input.GetKey(add))
        {
            AddInstance();
        }
        // remove instance
        if (num > 0 && Input.GetKey(remove))
        {
            var i = UnityEngine.Random.Range(0, num);
            Destroy(trs[i].gameObject);
            pos.RemoveAtSwapBack(i);
            vel.RemoveAtSwapBack(i);
            acc.RemoveAtSwapBack(i);
            trs.RemoveAtSwapBack(i);
            num--;
        }

        var jobWall = new UpdateWall {
            position = pos.AsDeferredJobArray(), accel = acc.AsDeferredJobArray(), scale = areaSize
        };
        var jobSmlt = new UpdateSmlt {
            position = pos.AsDeferredJobArray(), velocity = vel.AsDeferredJobArray(), accel = acc.AsDeferredJobArray(), dstThreshold = distThreshold, weights = simWeight
        };
        var jobMove = new UpdateMove {
            position = pos.AsDeferredJobArray(), velocity = vel.AsDeferredJobArray(), accel = acc.AsDeferredJobArray(), dt = Time.deltaTime, limit = velThreshold
        };
        var jobBlck = new UpdateBlck {
            position = pos.AsDeferredJobArray(), result = rst
        };
        var handlerWall = jobWall.Schedule(num, 0);
        var handlerSmlt = jobSmlt.Schedule(num, 0, handlerWall);
        var handlerMove = jobMove.Schedule(trs, handlerSmlt);
        var handlerBlck = jobBlck.Schedule(handlerMove);

        handlerBlck.Complete();
    }
    void UpdateQueue()
    {
        while (m_loadingQueue.Count > 0)
        {
            DynamicBoneBeta target = m_loadingQueue.Dequeue();

            int idx = m_dynamicBoneList.IndexOf(target);
            if (idx == -1)
            {
                m_dynamicBoneList.Add(target);



                target.m_headInfo.m_jobDataOffset = m_particleInfo.Length;

                int headIndex = m_headInfo.Length;
                target.m_headInfo.ResetHeadIndex(headIndex);

                m_headInfo.Add(target.m_headInfo);
                m_particleInfo.AddRange(target.m_Particles);
                m_headRootTransform.Add(target.m_rootParentTransform);

                for (int i = 0; i < DynamicBoneBeta.MAX_TRANSFORM_LIMIT; i++)
                {
                    m_particleTransformArr.Add(target.m_particleTransformArr[i]);
                }

                m_DbDataLen++;
            }
        }

        while (m_removeQueue.Count > 0)
        {
            DynamicBoneBeta target = m_removeQueue.Dequeue();

            int idx = m_dynamicBoneList.IndexOf(target);
            if (idx != -1)
            {
                m_dynamicBoneList.RemoveAt(idx);

                int curHeadIndex = target.m_headInfo.GetHeadIndex();

                //是否是队列中末尾对象
                bool isEndTarget = curHeadIndex == m_headInfo.Length - 1;
                if (isEndTarget)
                {
                    m_headInfo.RemoveAtSwapBack(curHeadIndex);
                    m_headRootTransform.RemoveAtSwapBack(curHeadIndex);

                    for (int i = DynamicBoneBeta.MAX_TRANSFORM_LIMIT - 1; i >= 0; i--)
                    {
                        int dataOffset = curHeadIndex * DynamicBoneBeta.MAX_TRANSFORM_LIMIT + i;
                        m_particleInfo.RemoveAtSwapBack(dataOffset);
                        m_particleTransformArr.RemoveAtSwapBack(dataOffset);
                    }
                }
                else
                {
                    //将最末列的HeadInfo 索引设置为当前将要移除的HeadInfo 索引
                    DynamicBoneBeta lastTarget = m_dynamicBoneList[m_dynamicBoneList.Count - 1];

                    DynamicBoneBeta.HeadInfo lastHeadInfo = lastTarget.ResetHeadIndexAndDataOffset(curHeadIndex);

                    m_headInfo.RemoveAtSwapBack(curHeadIndex);

                    m_headInfo[curHeadIndex] = lastHeadInfo;

                    m_headRootTransform.RemoveAtSwapBack(curHeadIndex);

                    for (int i = DynamicBoneBeta.MAX_TRANSFORM_LIMIT - 1; i >= 0; i--)
                    {
                        int dataOffset = curHeadIndex * DynamicBoneBeta.MAX_TRANSFORM_LIMIT + i;
                        m_particleInfo.RemoveAtSwapBack(dataOffset);
                        m_particleTransformArr.RemoveAtSwapBack(dataOffset);
                    }
                }

                m_DbDataLen--;
            }

            target.ClearJobData();
        }
    }