Exemple #1
0
    public virtual void SpawnShapes()
    {
        int   factoryIndex = Random.Range(0, spawnConfig.factories.Length);
        Shape shape        = spawnConfig.factories[factoryIndex].GetRandom();

        shape.gameObject.layer = gameObject.layer;
        Transform t = shape.transform;

        t.localPosition = SpawnPoint;
        t.localRotation = Random.rotation;
        t.localScale    = Vector3.one * spawnConfig.scale.RandomValueInRange;
        SetupColor(shape);

        float angularSpeed = spawnConfig.angularSpeed.RandomValueInRange;

        if (angularSpeed != 0f)
        {
            var rotation = shape.AddBehaviour <RotationShapeBehaviour>();
            rotation.AngularVelocity = Random.onUnitSphere * angularSpeed;
        }

        float speed = spawnConfig.speed.RandomValueInRange;

        if (speed != 0)
        {
            var movement = shape.AddBehaviour <MovementShapeBehaviour>();
            movement.Velocity = GetDirectionVector(spawnConfig.movementDirection, t) * speed;
        }

        SetupOscillation(shape);

        Vector3 lifecycleDurations = spawnConfig.lifecycle.RandomDurations;

        int satelliteCount = spawnConfig.satellite.amount.RandomValueInRange;

        for (int i = 0; i < satelliteCount; ++i)
        {
            Vector3 durations = spawnConfig.satellite.uniformLifecycles ?
                                lifecycleDurations : spawnConfig.lifecycle.RandomDurations;
            CreateSatelliteFor(shape, durations);
        }

        SetupLifecycle(shape, lifecycleDurations);
    }
    public void Initialize(Shape shape, float growingDuration, float adultDuration, float dyingDuration)
    {
        this.adultDuration = adultDuration;
        this.dyingDuration = dyingDuration;
        dyingAge           = growingDuration + adultDuration;

        if (growingDuration > 0f)
        {
            shape.AddBehaviour <GrowingShapeBehaviour>().Initialize(shape, growingDuration);
        }
    }
Exemple #3
0
 void SetupLifecycle(Shape shape, Vector3 durations)
 {
     if (durations.x > 0f)
     {
         if (durations.y > 0f || durations.z > 0f)
         {
             shape.AddBehaviour <LifecycleShapeBehaviour>().Initialize(shape, durations.x, durations.y, durations.z);
         }
         else
         {
             shape.AddBehaviour <GrowingShapeBehaviour>().Initialize(shape, durations.x);
         }
     }
     else if (durations.y > 0f)
     {
         shape.AddBehaviour <LifecycleShapeBehaviour>().Initialize(shape, durations.x, durations.y, durations.z);
     }
     else if (durations.z > 0f)
     {
         shape.AddBehaviour <DyingShapeBehaviour>().Initialize(shape, durations.z);
     }
 }
 public override bool GameUpdate(Shape shape)
 {
     if (focalShape.IsVaild)
     {
         float t = 2f * Mathf.PI * frequency * shape.Age;
         previousPosition = shape.transform.localPosition;
         shape.transform.localPosition =
             focalShape.Shape.transform.localPosition +
             cosOffset * Mathf.Cos(t) + sinOffset * Mathf.Sin(t);
         return(true);
     }
     shape.AddBehaviour <MovementShapeBehaviour>().Velocity = (shape.transform.localPosition - previousPosition) / Time.deltaTime;
     return(false);
 }
Exemple #5
0
    private void SetupOscillation(Shape shape)
    {
        float amplitude = spawnConfig.oscillationAmplitude.RandomValueInRange;
        float frequency = spawnConfig.oscillationFrequency.RandomValueInRange;

        if (amplitude == 0f || frequency == 0f)
        {
            return;
        }
        var oscillation = shape.AddBehaviour <OscillationShapeBehaviour>();

        oscillation.Offset    = GetDirectionVector(spawnConfig.oscillationDirection, shape.transform) * amplitude;
        oscillation.Frequency = frequency;
    }
    void CreateSatelliteFor(Shape focalShape)
    {
        int       factoryIndex = Random.Range(0, spawnConfig.factories.Length);
        Shape     shape        = spawnConfig.factories[factoryIndex].GetRandom();
        Transform t            = shape.transform;

        t.localRotation = Random.rotation;
        //t.localScale = focalShape.transform.localScale * 0.5f;
        t.localScale = focalShape.transform.localScale * spawnConfig.satellite.relativeScale.RandomValueInRange;
        //t.localPosition = focalShape.transform.localPosition + Vector3.up;
        //shape.AddBehaviour<MovementShapeBehaviour>().Velocity = Vector3.up;
        SetupColor(shape);
        shape.AddBehaviour <SatelliteShapeBehaviour>().Initialize(shape, focalShape,
                                                                  spawnConfig.satellite.orbitRaduis.RandomValueInRange, spawnConfig.satellite.orbitFrequency.RandomValueInRange);
    }
Exemple #7
0
    void CreateSatelliteFor(Shape focalShape, Vector3 lifecycleDurations)
    {
        int       factoryIndex = Random.Range(0, spawnConfig.factories.Length);
        Shape     shape        = spawnConfig.factories[factoryIndex].GetRandom();
        Transform t            = shape.transform;

        t.localRotation = Random.rotation;
        t.localScale    = focalShape.transform.localScale * spawnConfig.satellite.relativeScale.RandomValueInRange;

        SetupColor(shape);
        shape.AddBehaviour <SatelliteShapeBehaviour>().Initialize(shape, focalShape,
                                                                  spawnConfig.satellite.orbitRaduis.RandomValueInRange, spawnConfig.satellite.orbitFrequency.RandomValueInRange);

        SetupLifecycle(shape, lifecycleDurations);
    }
Exemple #8
0
 void DestroyShape()
 {
     if (shapes.Count - dyingShapeCount > 0)
     {
         int   index = Random.Range(0, shapes.Count);
         Shape shape = shapes[index];
         if (destroyDuration < 0f)
         {
             KillImmediately(shape);
         }
         else
         {
             shape.AddBehaviour <DyingShapeBehaviour>().Initialize(shape, destroyDuration);
         }
     }
 }
Exemple #9
0
    public void Initialize(Shape shape, Shape focalShape, float radius, float frequency)
    {
        this.focalShape = focalShape;
        this.frequency  = frequency;
        Vector3 orbitAxis = Random.onUnitSphere;

        do
        {
            cosOffset = Vector3.Cross(orbitAxis, Random.onUnitSphere).normalized;
        }while (cosOffset.sqrMagnitude < 0.1f);

        sinOffset  = Vector3.Cross(cosOffset, orbitAxis);
        cosOffset *= radius;
        sinOffset *= radius;

        shape.AddBehaviour <RotationShapeBehaviour>().AngularVelocity = -360f * frequency * shape.transform.InverseTransformDirection(orbitAxis);

        GameUpdate(shape);
        previousPosition = shape.transform.localPosition;
    }
    public override bool GameUpdate(Shape shape)
    {
        if (shape.Age >= dyingAge)
        {
            if (dyingDuration <= 0f)
            {
                shape.Die();
                return(true);
            }

            if (!shape.IsMarkedAsDying)
            {
                shape.AddBehaviour <DyingShapeBehaviour>().Initialize(shape, dyingDuration + dyingAge - shape.Age);
            }

            return(false);
        }

        return(true);
    }
Exemple #11
0
    void DestroyShape()
    {
        if (shapes.Count - dyingShapeCount > 0)
        {
            //int index = Random.Range(0, shapes.Count);
            //shapes[index].Recycle();
            //int lastIndex = shapes.Count - 1;
            //shapes[lastIndex].SaveIndex = index;
            //shapes[index] = shapes[lastIndex];
            //shapes.RemoveAt(lastIndex);

            int   index = Random.Range(0, shapes.Count);
            Shape shape = shapes[index];
            if (destroyDuration < 0f)
            {
                KillImmediately(shape);
            }
            else
            {
                shape.AddBehaviour <DyingShapeBehaviour>().Initialize(shape, destroyDuration);
            }
        }
    }
Exemple #12
0
    //public virtual void ConfigureSpawn(Shape shape)
    public virtual Shape SpawnShape()
    {
        int       factoryIndex = Random.Range(0, spawnConfg.factories.Length);
        Shape     shape        = spawnConfg.factories[factoryIndex].GetRandom();
        Transform t            = shape.transform;

        t.localPosition = SpawnPoint;
        t.localRotation = Random.rotation;
        t.localScale    = Vector3.one * spawnConfg.scale.RandomValueInRange;
        //shape.SetColor(Random.ColorHSV(hueMin: 0f, hueMax: 1f, saturationMin: 0.5f,
        //    saturationMax: 1f, valueMin: 0.25f, valueMax: 1f, alphaMin: 1f, alphaMax: 1f));
        if (spawnConfg.uniformColor)
        {
            shape.SetColor(spawnConfg.color.RandomInRange);
        }
        else
        {
            for (int i = 0; i < shape.ColorCount; ++i)
            {
                shape.SetColor(spawnConfg.color.RandomInRange, i);
            }
        }

        //shape.AngularVelocity = Random.onUnitSphere * spawnConfg.scale.RandomValueInRange;
        //shape.Velocity = Random.onUnitSphere * Random.Range(0f, 2f);
        float angularSpeed = spawnConfg.angularSpeed.RandomValueInRange;

        if (angularSpeed != 0f)
        {
            //var rotation = shape.gameObject.AddComponent<RotationShapeBehavior>();
            var rotation = shape.AddBehaviour <RotationShapeBehaviour>();
            rotation.AngularVelocity = Random.onUnitSphere * angularSpeed;
        }

        //shape.Velocity = direction * spawnConfg.speed.RandomValueInRange;
        float speed = spawnConfg.speed.RandomValueInRange;

        if (speed != 0)
        {
            //Vector3 direction;
            //switch (spawnConfg.movementDirection)
            //{
            //    case SpawnConfguration.MovementDirection.Upward:
            //        direction = transform.up;
            //        break;
            //    case SpawnConfguration.MovementDirection.Outward:
            //        direction = (t.localPosition - transform.position).normalized;
            //        break;
            //    case SpawnConfguration.MovementDirection.Random:
            //        direction = Random.onUnitSphere;
            //        break;
            //    default:
            //        direction = transform.forward;
            //        break;
            //}

            //var movement = shape.gameObject.AddComponent<MovementShapeBehavior>();
            var movement = shape.AddBehaviour <MovementShapeBehaviour>();
            movement.Velocity = GetDirectionVector(spawnConfg.movementDirection, t) * speed;
        }

        SetupOscillation(shape);

        return(shape);
    }