Ejemplo n.º 1
0
        //加力
        public float3 CastForceForNote(ref float3 position, ref NoteComponent b, ForceMode forceMode)
        {
            float3 forceDir = (position - b.position);
            float  d        = math.length(forceDir);

            d        = math.clamp(d, 1, 25);
            forceDir = math.normalize(forceDir);
            // F = GMm / d^2
            float strength = (G * mouseMass * b.Mass) / (d * d);

            forceDir *= strength;
            return((forceMode == ForceMode.PUSH) ? forceDir * -1 : forceDir);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 生成音符
        /// </summary>
        public void GenerateNote()
        {
            if (LaneController.HitOrNot)
            {
                var entityManager = World.Active.GetOrCreateManager <EntityManager>();
                for (int i = 0; i < CubeBasis.GetInstance().createNum_Cube; i++)
                {
                    Entity note = entityManager.CreateEntity(NoteArchetype);

                    float3 randomVel = UnityEngine.Random.onUnitSphere;
                    //float3 randomVel = UnityEngine.Random.value;

                    float3 mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.mousePosition.x, Input.mousePosition.y, 248 /*Camera.main.transform.position.z*/));
                    mousePos.z = 248.0f;
                    float3 initialPosition = new float3(mousePos.x + randomVel.x, mousePos.y + randomVel.y, mousePos.z + randomVel.z);

                    entityManager.SetComponentData(note, new Position {
                        Value = initialPosition
                    });
                    //entityManager.SetComponentData(note, new Rotation { Value = Quaternion.Euler(90, 0, 0) });
                    entityManager.SetComponentData(note, new Scale {
                        Value = new float3(0.75f, 0.75f, 0.75f)
                    });

                    NoteComponent n = new NoteComponent
                    {
                        position   = initialPosition,
                        acceration = float3.zero,
                        lifeTime   = CubeBasis.GetInstance().lifeTime_Cube,

                        Mass      = CubeBasis.GetInstance().mass,
                        Radius    = CubeBasis.GetInstance().radius,
                        MaxLength = CubeBasis.GetInstance().maxLength,
                        Velocity  = new float3(0, 0, randomVel.z * 100f),
                    };

                    entityManager.SetComponentData(note, n);

                    float4 v = new float4(-960f, -540f, 960f, 540f);

                    ForceComponent f = new ForceComponent {
                        mouseMass = 50f, bound = v, frictionCoe = 0.1f
                    };

                    entityManager.SetComponentData(note, f);

                    entityManager.SetSharedComponentData(note, noteRenderer);
                }
                LaneController.HitOrNot = false;
            }
        }