Ejemplo n.º 1
0
        public void Execute(Entity entity, int index, ref Joiner_C joiner)
        {
            //添加质量组件
            MassPoint_C mass = new MassPoint_C();

            mass.Mass = UnitHelper.Range2Mass(joiner.Range);
            concurrent.AddComponent(index, entity, mass);
            //添加缩放组件
            NonUniformScale scale = new NonUniformScale();

            scale.Value = (float3)(new double3(1, 1, 1) * 2 * joiner.Range);
            concurrent.AddComponent(index, entity, scale);
            //添加缩放组件
            ColorLevel color = new ColorLevel();

            color.Value = 0.5f;
            concurrent.AddComponent(index, entity, color);
        }
Ejemplo n.º 2
0
        public void Execute(Entity entity, int index, ref Spliter_C spliter, ref Translation translation, ref Joiner_C joiner, ref Mover_C mover)
        {
            //校验spliter数据合理性
            if (spliter.direction.Equals(double3.zero))
            {
                return;
            }
            bool3 nanResult = math.isnan(math.normalize(spliter.direction));

            if (nanResult.x || nanResult.y || nanResult.z)
            {
                return;
            }
            //体积过小就无法分离子星体了
            if (joiner.Volume < spliter.volume * 2)
            {
                return;
            }

            // 根据split的方向分离小实体
            Entity   subEntity = concurrent.Instantiate(index, smallStar);
            Joiner_C subJoiner = new Joiner_C()
            {
                Volume = spliter.volume + 0.01
            };
            MassPoint_C subMass = new MassPoint_C()
            {
                Mass = UnitHelper.Range2Mass(subJoiner.Range)
            };
            Mover_C         subMover       = new Mover_C();
            Translation     subTranslation = new Translation();
            NonUniformScale subScale       = new NonUniformScale();
            var             dirNormal      = math.normalize(spliter.direction);
            var             distance       = subJoiner.Range + joiner.Range + 0.01;

            subTranslation.Value = translation.Value + (float3)(dirNormal * distance);
            subScale.Value       = 0.01f;
            concurrent.AddComponent(index, subEntity, subTranslation);
            concurrent.AddComponent(index, subEntity, subJoiner);
            concurrent.AddComponent(index, subEntity, subMass);
            concurrent.AddComponent(index, subEntity, subMover);
            concurrent.AddComponent(index, subEntity, subScale);

            //分离产生的力
            var spliterForce = math.normalize(spliter.direction) * subMass.Mass;

            // 添加子物体受力
            SimapleForceSender_C subForce = new SimapleForceSender_C()
            {
                value = -spliterForce * 2,
                type  = ForceType.external,
                to    = subEntity,
                time  = 0.5f
            };
            Entity fEntity = concurrent.CreateEntity(index);

            concurrent.AddComponent(index, fEntity, subForce);
            //添加子物体动量
            Momentum_C subMomentum = new Momentum_C()
            {
                mass   = subMass.Mass,
                speed  = spliterForce * 2,
                target = subEntity
            };
            Entity mEntity = concurrent.CreateEntity(index);

            concurrent.AddComponent(index, mEntity, subMomentum);
            // 添加主物体动量
            Momentum_C momentum = new Momentum_C()
            {
                mass   = subMass.Mass,
                speed  = -spliterForce * 2,
                target = entity
            };
            Entity mainMEntity = concurrent.CreateEntity(index);

            concurrent.AddComponent(index, mainMEntity, momentum);

            // 减少朱物体mass的质量
            joiner.Volume -= spliter.volume;
            concurrent.RemoveComponent(index, entity, typeof(Spliter_C));
            //UnityEngine.Debug.Log("spliterV:" + spliter.volume);
        }