Exemplo n.º 1
0
 public override void OnInspectorGUI()
 {
     EditorGUILayout.Space();
     explosionRadius = EditorGUILayout.FloatField("Explosion Radius:", explosionRadius);
     if (explosionRadius != voxelExploder.ExplosionRadius) voxelExploder.ExplosionRadius = explosionRadius;
     particleVelocity = EditorGUILayout.FloatField("Particle Velocity:", particleVelocity);
     if (particleVelocity != voxelExploder.ParticleVelocity) voxelExploder.ParticleVelocity = particleVelocity;
     explodeTarget = (Exploder.ExplodeTargets) EditorGUILayout.EnumPopup("Targets:", explodeTarget);
     if (explodeTarget != voxelExploder.ExplodeTarget) voxelExploder.ExplodeTarget = explodeTarget;
     EditorGUILayout.LabelField("Explode when voxel Value is");
     EditorGUILayout.BeginHorizontal();
     valueFilterOperation = (Exploder.ExplodeValueFilterOperation)EditorGUILayout.EnumPopup(valueFilterOperation);
     if (valueFilterOperation != voxelExploder.ValueFilterOperation) voxelExploder.ValueFilterOperation = valueFilterOperation;
     valueFilter = EditorGUILayout.IntField(valueFilter);
     if (valueFilter != voxelExploder.ValueFilter)
     {
         if (valueFilter < 0) valueFilter = 0;
         if (valueFilter >255) valueFilter = 255;
         voxelExploder.ValueFilter = valueFilter;
     }
     EditorGUILayout.EndHorizontal();
     if (GUILayout.Button("Explode!"))
     {
         voxelExploder.Explode();
         foreach (GameObject o in GameObject.FindGameObjectsWithTag("PicaVoxelVolume"))
             o.GetComponent<Volume>().UpdateChunks(true);
     }
 }
Exemplo n.º 2
0
        private void OnEnable()
        {
            voxelExploder = (Exploder) target;

            explosionRadius = voxelExploder.ExplosionRadius;
            particleVelocity = voxelExploder.ParticleVelocity;
            explodeTarget = voxelExploder.ExplodeTarget;
            valueFilterOperation = voxelExploder.ValueFilterOperation;
            valueFilter = voxelExploder.ValueFilter;
        }
Exemplo n.º 3
0
        private void OnEnable()
        {
            voxelExploder = (Exploder)target;

            explosionRadius      = voxelExploder.ExplosionRadius;
            particleVelocity     = voxelExploder.ParticleVelocity;
            explodeTarget        = voxelExploder.ExplodeTarget;
            valueFilterOperation = voxelExploder.ValueFilterOperation;
            valueFilter          = voxelExploder.ValueFilter;
        }
Exemplo n.º 4
0
 public override void OnInspectorGUI()
 {
     EditorGUILayout.Space();
     tag = EditorGUILayout.TextField("Tag:", tag);
     if (tag != voxelExploder.Tag)
     {
         voxelExploder.Tag = tag;
     }
     explosionRadius = EditorGUILayout.FloatField("Explosion Radius:", explosionRadius);
     if (explosionRadius != voxelExploder.ExplosionRadius)
     {
         voxelExploder.ExplosionRadius = explosionRadius;
     }
     particleVelocity = EditorGUILayout.FloatField("Particle Velocity:", particleVelocity);
     if (particleVelocity != voxelExploder.ParticleVelocity)
     {
         voxelExploder.ParticleVelocity = particleVelocity;
     }
     explodeTarget = (Exploder.ExplodeTargets)EditorGUILayout.EnumPopup("Targets:", explodeTarget);
     if (explodeTarget != voxelExploder.ExplodeTarget)
     {
         voxelExploder.ExplodeTarget = explodeTarget;
     }
     EditorGUILayout.LabelField("Explode when voxel Value is");
     EditorGUILayout.BeginHorizontal();
     valueFilterOperation = (Exploder.ExplodeValueFilterOperation)EditorGUILayout.EnumPopup(valueFilterOperation);
     if (valueFilterOperation != voxelExploder.ValueFilterOperation)
     {
         voxelExploder.ValueFilterOperation = valueFilterOperation;
     }
     valueFilter = EditorGUILayout.IntField(valueFilter);
     if (valueFilter != voxelExploder.ValueFilter)
     {
         if (valueFilter < 0)
         {
             valueFilter = 0;
         }
         if (valueFilter > 255)
         {
             valueFilter = 255;
         }
         voxelExploder.ValueFilter = valueFilter;
     }
     EditorGUILayout.EndHorizontal();
     if (GUILayout.Button("Explode!"))
     {
         voxelExploder.Explode();
         foreach (GameObject o in GameObject.FindGameObjectsWithTag("PicaVoxelVolume"))
         {
             o.GetComponent <Volume>().UpdateChunks(true);
         }
     }
 }
Exemplo n.º 5
0
        private bool FilterExplosion(byte value, int valueFilter, Exploder.ExplodeValueFilterOperation valueFilterOperation)
        {
            switch (valueFilterOperation)
            {
                case Exploder.ExplodeValueFilterOperation.LessThan:
                    return value < valueFilter;
                case Exploder.ExplodeValueFilterOperation.LessThanOrEqualTo:
                    return value <= valueFilter;
                case Exploder.ExplodeValueFilterOperation.EqualTo:
                    return value == valueFilter;
                case Exploder.ExplodeValueFilterOperation.GreaterThanOrEqualTo:
                    return value >= valueFilter;
                case Exploder.ExplodeValueFilterOperation.GreaterThan:
                    return value > valueFilter;
            }

            return false;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Deactivates all particles in the current frame, within a supplied radius of a world position
        /// </summary>
        /// <param name="position">The world position of the centre of the explosion</param>
        /// <param name="explosionRadius">The radius of the explosion</param>
        /// <returns>A Batch of voxels that were destroyed by the explosion</returns>
        public Batch Explode(Vector3 position, float explosionRadius, int valueFilter, Exploder.ExplodeValueFilterOperation valueFilterOperation)
        {
            Batch batch = new Batch(this);

            Color tint = Material.GetColor("_Tint");

            Matrix4x4 transformMatrix = transform.worldToLocalMatrix;

            position += (transform.rotation * (Pivot));

            for (float x = position.x - explosionRadius; x <= position.x + explosionRadius; x += VoxelSize * 0.5f)
            {
                for (float y = position.y - explosionRadius; y <= position.y + explosionRadius; y += VoxelSize * 0.5f)
                {
                    for (float z = position.z - explosionRadius; z <= position.z + explosionRadius; z += VoxelSize * 0.5f)
                    {
                        Vector3 checkPos = new Vector3(x, y, z);
                        if (Vector3.Distance(checkPos, position) <= explosionRadius)
                        {
                            Vector3 localPos = transformMatrix.MultiplyPoint3x4(checkPos); //transform.InverseTransformPoint(pos);

                            //if (!Frames[CurrentFrame].IsLocalPositionInBounds(localPos)) continue;

                            int testX = (int)(localPos.x / VoxelSize);
                            int testY = (int)(localPos.y / VoxelSize);
                            int testZ = (int)(localPos.z / VoxelSize);
                            if (testX < 0 || testY < 0 || testZ < 0 || testX >= XSize || testY >= YSize || testZ >= ZSize)
                            {
                                continue;
                            }

                            if (Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)].Active &&
                                FilterExplosion(Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)].Value, valueFilter, valueFilterOperation) &&
                                Vector3.Distance(position, checkPos) <= explosionRadius)
                            {
                                Voxel v = Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)];
                                v.Color *= tint;
                                batch.Add(v, testX, testY, testZ, checkPos - (transform.rotation * (Pivot)));
                                SetVoxelStateAtArrayPosition(testX, testY, testZ, VoxelState.Hidden);
                            }
                        }
                    }
                }
            }



            return(batch);
        }