示例#1
0
            public void Execute(int i)
            {
                //var dir = ((Vector3) positions[i].Value - (Vector3) headings[i].Value).normalized;

                //assume you have direction
                float3 vel    = blackHoleChildren[i].velocity + (blackHoleChildren[i].acceleration * dt);
                float3 newPos = positions[i].Value + (vel * dt);


                blackHoleChildren[i] = new BlackHoleChild
                {
                    //t = t, //can remove
                    parent        = blackHoleChildren[i].parent,
                    acceleration  = blackHoleChildren[i].acceleration,
                    velocity      = vel,
                    destroyRadius = blackHoleChildren[i].destroyRadius,
                    spawnRadius   = blackHoleChildren[i].spawnRadius
                };

                //float3 newPosition = ringRevolve[i].zRotation * new Vector3(x, y, z);

                positions[i] = new Position
                {
                    Value = newPos
                };
            }
示例#2
0
            public void Execute()
            {
                for (int i = 0; i < positions.Length; i++)
                {
                    //do stuff
                    float distance = ((Vector3)positions[i].Value).magnitude;  //get distance from center of spawner (bc children are parented)

                    //Debug.Log(distance);
                    if (distance < blackHoleChildrenInfo[i].destroyRadius)
                    {
                        //reset its values
                        //var newPos = new NativeArray<float3>(1, Allocator.Temp);

                        //float3 newPos = RandomPointOnSphere(new float3(0,0,0), blackHoleChildrenInfo[i].spawnRadius);

                        //var pointsFound = 0;
                        //float3 newPos = new float3(0, 0, 0);
                        //var count = points.Length;

                        /*
                         * while (pointsFound < 1)
                         * {
                         *  var p = new Vector3
                         *  {
                         *      x = Unity.Mathematics.Random.;
                         *      //y = UnityEngine.Random.Range(-1f, 1f),
                         *      //z = UnityEngine.Random.Range(-1f, 1f)
                         *  };
                         *  if (math.lengthsq(p) < 1)
                         *  {
                         *      p = (p.normalized) * blackHoleChildrenInfo[i].spawnRadius;
                         *
                         *      newPos = (float3) p;
                         *      pointsFound = 1;
                         *      //points[pointsFound] = point;
                         *
                         *      //transform to onto circle with radius r
                         *
                         *
                         *      //pointsFound++;
                         *  }
                         * }
                         */
                        float3 translatedPosition = randomPosition * blackHoleChildrenInfo[i].spawnRadius;

                        //Debug.Log(randomPosition);

                        var newPosition = new Position
                        {
                            Value = translatedPosition
                        };
                        buff.SetComponent(entities[i], newPosition);


                        Vector3 normAccel      = ((Vector3)randomPosition * -1).normalized; //get norm accel
                        float3  newAccel       = (normAccel * randomAcceleration);          //randomize accel
                        var     blackHoleChild = new BlackHoleChild
                        {
                            parent        = blackHoleChildrenInfo[i].parent,
                            acceleration  = newAccel,
                            velocity      = new float3(0, 0, 0),
                            spawnRadius   = blackHoleChildrenInfo[i].spawnRadius,
                            destroyRadius = blackHoleChildrenInfo[i].destroyRadius //arbitrary for right now
                        };
                        buff.SetComponent(entities[i], blackHoleChild);


                        var scaleSpeed = new BlackHoleScaleSpeed
                        {
                            Value = randomScaleSpeed //UnityEngine.Random.Range(0.1f, 0.2f)
                        };
                        buff.SetComponent(entities[i], scaleSpeed);


                        var localScale = new Scale
                        {
                            Value = new float3(0, 0, 0)
                        };
                        buff.SetComponent(entities[i], localScale);



                        //deleteBuffer.DestroyEntity(entities[i]); //destory an entity
                        //countBuffer.AddComponent(sourceEntity, new AddBlackHoleSpawn { }); //tell parent to spawn a new one
                    }
                }
            }