Esempio n. 1
0
        private void Destruct()
        {
            Batch batch = new Batch(PicaVoxelVolume);

            Vector3 posZero = PicaVoxelVolume.transform.position +
                              (transform.rotation *
                               (-PicaVoxelVolume.Pivot + (Vector3.one * (PicaVoxelVolume.VoxelSize * 0.5f))));
            Vector3 oneX = PicaVoxelVolume.transform.rotation * (new Vector3(PicaVoxelVolume.VoxelSize, 0, 0));
            Vector3 oneY = PicaVoxelVolume.transform.rotation * (new Vector3(0f, PicaVoxelVolume.VoxelSize, 0));
            Vector3 oneZ = PicaVoxelVolume.transform.rotation * (new Vector3(0, 0, PicaVoxelVolume.VoxelSize));

            Vector3 constructorPosition = transform.position;

            Frame frame = PicaVoxelVolume.GetCurrentFrame();

            //int numVox = 0;

            Vector3 checkPos = posZero;

            for (int x = 0; x < PicaVoxelVolume.XSize; x++)
            {
                Vector3 xmult = oneX * x;
                for (int y = 0; y < PicaVoxelVolume.YSize; y++)
                {
                    Vector3 ymult = oneY * y;
                    for (int z = 0; z < PicaVoxelVolume.ZSize; z++)
                    {
                        Vector3 zmult = oneZ * z;
                        checkPos.x = posZero.x + xmult.x + ymult.x + zmult.x;
                        checkPos.y = posZero.y + xmult.y + ymult.y + zmult.y;
                        checkPos.z = posZero.z + xmult.z + ymult.z + zmult.z;

                        if (frame.Voxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)].Active &&
                            Vector3.Distance(constructorPosition, checkPos) <= radius)
                        {
                            //numVox++;
                            Voxel v = frame.Voxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)];
                            v.Color *= PicaVoxelVolume.Material.GetColor("_Tint");
                            batch.Add(v, x, y, z, checkPos);
                            frame.SetVoxelStateAtArrayPosition(x, y, z, VoxelState.Hidden);
                            //frame.SetChunkAtVoxelPositionDirty(x, y, z);
                        }
                    }
                }
            }

            frame.UpdateChunks(false);

            if (CreateParticles && batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null)
            {
                VoxelParticleSystem.Instance.SpawnBatch(batch,
                                                        pos =>
                                                        ((transform.position - (pos + Random.insideUnitSphere)) *
                                                         1f));
            }

            batch.Dispose();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds particles to the PicaVoxel Particle System (if available) representing the shape of this volume
        /// Use it before destroying/deactivating the volume to leave particles behind
        /// </summary>
        /// <param name="particleVelocity">Initial velocity of the created particles (outward from center of volume)</param>
        /// <param name="actuallyDestroyVoxels">If true, will set all the voxels to inactive</param>
        public void Destruct(float particleVelocity, bool actuallyDestroyVoxels)
        {
            Batch batch = new Batch(this);

            Vector3 posZero = transform.position + (transform.rotation * (-Pivot + (Vector3.one * (VoxelSize * 0.5f))));
            Vector3 oneX    = transform.rotation * (new Vector3(VoxelSize, 0, 0));
            Vector3 oneY    = transform.rotation * (new Vector3(0f, VoxelSize, 0));
            Vector3 oneZ    = transform.rotation * (new Vector3(0, 0, VoxelSize));

            Vector3 partPos = posZero;

            for (int x = 0; x < XSize; x++)
            {
                Vector3 xmult = oneX * x;
                for (int y = 0; y < YSize; y++)
                {
                    Vector3 ymult = oneY * y;
                    for (int z = 0; z < ZSize; z++)
                    {
                        Vector3 zmult = oneZ * z;
                        partPos.x = posZero.x + xmult.x + ymult.x + zmult.x;
                        partPos.y = posZero.y + xmult.y + ymult.y + zmult.y;
                        partPos.z = posZero.z + xmult.z + ymult.z + zmult.z;

                        if (Frames[CurrentFrame].Voxels[x + XSize * (y + YSize * z)].Active)
                        {
                            Voxel v = Frames[CurrentFrame].Voxels[x + XSize * (y + YSize * z)];
                            v.Color *= Material.GetColor("_Tint");
                            batch.Add(v, x, y, z, partPos);
                            if (actuallyDestroyVoxels)
                            {
                                SetVoxelAtArrayPosition(x, y, z, new Voxel()
                                {
                                    State = VoxelState.Hidden
                                });
                            }
                        }
                    }
                }
            }

            if (batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null)
            {
                VoxelParticleSystem.Instance.SpawnBatch(batch,
                                                        pos => (pos - transform.position).normalized * Random.Range(0f, particleVelocity * 2f));
            }

            batch.Dispose();
        }
Esempio n. 3
0
        public void Explode(Vector3 additionalVelocity)
        {
            foreach (Volume pvo in GameObject.FindObjectsOfType <Volume>())
            {
                if (ExplodeTarget == ExplodeTargets.AllButSelf && pvo.transform.root == transform.root)
                {
                    continue;
                }
                if (ExplodeTarget == ExplodeTargets.SelfOnly && pvo.transform.root != transform.root)
                {
                    continue;
                }

                //Volume pvo = o.GetComponent<Volume>();
                if (pvo == null)
                {
                    continue;
                }
                Vector3 cpob = pvo.Hitbox.ClosestPointOnBounds(transform.position);

                if (Vector3.Distance(transform.position, cpob) <= ExplosionRadius ||
                    pvo.GetVoxelAtWorldPosition(transform.position) != null)
                {
                    Batch batch = pvo.Explode(transform.position, ExplosionRadius, ValueFilter, ValueFilterOperation);

                    if (batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null)
                    {
                        VoxelParticleSystem.Instance.SpawnBatch(batch,
                                                                pos =>
                                                                (((pos + Random.insideUnitSphere) - transform.position) *
                                                                 ((Random.Range(ParticleVelocity - 1f, ParticleVelocity + 1f)))) + additionalVelocity);
                    }

                    batch.Dispose();
                }
            }
        }
Esempio n. 4
0
        private void Destruct()
        {
            Batch batch = new Batch(PicaVoxelVolume);

            Vector3 posZero = PicaVoxelVolume.transform.position +
                              (transform.rotation*
                               (-PicaVoxelVolume.Pivot + (Vector3.one*(PicaVoxelVolume.VoxelSize*0.5f))));
            Vector3 oneX = PicaVoxelVolume.transform.rotation*(new Vector3(PicaVoxelVolume.VoxelSize, 0, 0));
            Vector3 oneY = PicaVoxelVolume.transform.rotation*(new Vector3(0f, PicaVoxelVolume.VoxelSize, 0));
            Vector3 oneZ = PicaVoxelVolume.transform.rotation*(new Vector3(0, 0, PicaVoxelVolume.VoxelSize));

            Vector3 constructorPosition = transform.position;

            Frame frame = PicaVoxelVolume.GetCurrentFrame();

            //int numVox = 0;

            Vector3 checkPos = posZero;
            for (int x = 0; x < PicaVoxelVolume.XSize; x++)
            {
                Vector3 xmult = oneX*x;
                for (int y = 0; y < PicaVoxelVolume.YSize; y++)
                {
                    Vector3 ymult = oneY*y;
                    for (int z = 0; z < PicaVoxelVolume.ZSize; z++)
                    {
                        Vector3 zmult = oneZ*z;
                        checkPos.x = posZero.x + xmult.x + ymult.x + zmult.x;
                        checkPos.y = posZero.y + xmult.y + ymult.y + zmult.y;
                        checkPos.z = posZero.z + xmult.z + ymult.z + zmult.z;

                        if (frame.Voxels[x + PicaVoxelVolume.XSize*(y + PicaVoxelVolume.YSize*z)].Active &&
                            Vector3.Distance(constructorPosition, checkPos) <= radius)
                        {
                            //numVox++;
                            Voxel v = frame.Voxels[x + PicaVoxelVolume.XSize*(y + PicaVoxelVolume.YSize*z)];
                            v.Color *= PicaVoxelVolume.Material.GetColor("_Tint");
                            batch.Add(v, x, y, z, checkPos);
                            frame.Voxels[x + PicaVoxelVolume.XSize*(y + PicaVoxelVolume.YSize*z)].State = VoxelState.Hidden;
                            frame.SetChunkAtVoxelPositionDirty(x, y, z);
                        }
                    }
                }
            }

            if (CreateParticles && batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null)
                VoxelParticleSystem.Instance.SpawnBatch(batch,
                    pos =>
                        ((transform.position - (pos + Random.insideUnitSphere))*
                         1f));

            batch.Dispose();
        }
Esempio n. 5
0
        /// <summary>
        /// Adds particles to the PicaVoxel Particle System (if available) representing the shape of this volume
        /// Use it before destroying/deactivating the volume to leave particles behind
        /// </summary>
        /// <param name="particleVelocity">Initial velocity of the created particles (outward from center of volume)</param>
        /// <param name="actuallyDestroyVoxels">If true, will set all the voxels to inactive</param>
        public void Destruct(float particleVelocity, bool actuallyDestroyVoxels)
        {
            Batch batch = new Batch(this);

            Vector3 posZero = transform.position + (transform.rotation * (-Pivot + (Vector3.one * (VoxelSize * 0.5f))));
            Vector3 oneX = transform.rotation * (new Vector3(VoxelSize, 0, 0));
            Vector3 oneY = transform.rotation * (new Vector3(0f, VoxelSize, 0));
            Vector3 oneZ = transform.rotation * (new Vector3(0, 0, VoxelSize));

            Vector3 partPos = posZero;
            for (int x = 0; x < XSize; x++)
            {
                Vector3 xmult = oneX * x;
                for (int y = 0; y < YSize; y++)
                {
                    Vector3 ymult = oneY * y;
                    for (int z = 0; z < ZSize; z++)
                    {
                        Vector3 zmult = oneZ * z;
                        partPos.x = posZero.x + xmult.x + ymult.x + zmult.x;
                        partPos.y = posZero.y + xmult.y + ymult.y + zmult.y;
                        partPos.z = posZero.z + xmult.z + ymult.z + zmult.z;

                        if (Frames[CurrentFrame].Voxels[x + XSize * (y + YSize * z)].Active)
                        {
                            Voxel v = Frames[CurrentFrame].Voxels[x + XSize * (y + YSize * z)];
                            v.Color *= Material.GetColor("_Tint");
                            batch.Add(v, x, y, z, partPos);
                            if(actuallyDestroyVoxels) SetVoxelAtArrayPosition(x, y, z, new Voxel() { State = VoxelState.Hidden });
                        }
                    }
                }
            }

            if (batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null)
                VoxelParticleSystem.Instance.SpawnBatch(batch,
                    pos => (pos - transform.position).normalized * Random.Range(0f, particleVelocity * 2f));

            batch.Dispose();
        }