Esempio n. 1
0
 // Copy from
 public void CopyFrom(RFReferenceDemolition referenceDemolitionDml)
 {
     reference = referenceDemolitionDml.reference;
     if (referenceDemolitionDml.randomList != null && referenceDemolitionDml.randomList.Count > 0)
     {
         if (randomList == null)
         {
             randomList = new List <GameObject>();
         }
         randomList = referenceDemolitionDml.randomList;
     }
     addRigid     = referenceDemolitionDml.addRigid;
     inheritScale = referenceDemolitionDml.inheritScale;
 }
Esempio n. 2
0
        // Demolish object
        public void Demolish()
        {
            // Profiler.BeginSample ("Demolition");
            // Debug.Log (limitations.demolitionShould);

            // Initialize if not
            if (initialized == false)
            {
                Initialize();
            }

            // Timestamp
            float t1 = Time.realtimeSinceStartup;

            // Restore position and rotation to prevent high collision offset
            transForm.position = physics.position;
            transForm.rotation = physics.rotation;

            // Demolish mesh or cluster to reference
            if (RFReferenceDemolition.DemolishReference(this) == false)
            {
                return;
            }

            // Demolish mesh and create fragments. Stop if runtime caching or no meshes/fragments were created
            if (RFDemolitionMesh.DemolishMesh(this) == false)
            {
                return;
            }

            /* EXPERIMENTAL
             * // TODO Clusterize
             * bool clusterize = true;
             * if (clusterize == true && objectType == ObjectType.Mesh && demolitionType == DemolitionType.Runtime)
             * {
             *
             *  foreach (var frag in fragments)
             *  {
             *      Destroy (frag.physics.rigidBody);
             *      Destroy (frag);
             *  }
             *
             *  RayfireRigid scr = this.rootChild.gameObject.AddComponent<RayfireRigid>();
             *  this.CopyPropertiesTo (scr);
             *  scr.demolitionType = DemolitionType.Runtime;
             *  scr.objectType     = ObjectType.ConnectedCluster;
             *
             *  scr.limitations.contactPoint   = this.limitations.contactPoint;
             *  scr.limitations.contactNormal  = this.limitations.contactNormal;
             *  scr.limitations.contactVector3 = this.limitations.contactVector3;
             *
             *  scr.physics.velocity = this.physics.velocity;
             *
             *  scr.clusterDemolition.cluster  = new RFCluster();
             *  scr.Initialize();
             *
             *  scr.physics.rigidBody.velocity   = this.physics.velocity;
             *  scr.limitations.demolitionShould = true;
             *  //scr.Demolish();
             *  RayfireMan.DestroyFragment (this, rootParent);
             *  return;
             * }
             */


            // Demolish cluster to children nodes
            if (RFDemolitionCluster.DemolishCluster(this) == true)
            {
                return;
            }

            // Check fragments and proceed TODO separate flow for connected cls demolition
            if (limitations.demolished == false)
            {
                limitations.demolitionShould = false;
                demolitionType = DemolitionType.None;
                return;
            }

            // Connectivity check
            activation.CheckConnectivity();

            // Fragments initialisation
            InitMeshFragments();

            // Sum total demolition time
            RayfireMan.inst.maxTimeThisFrame += Time.realtimeSinceStartup - t1;

            // Init particles
            RFParticles.InitDemolitionParticles(this);

            // Init sound
            RFSound.DemolitionSound(sound, limitations.bboxSize);

            // Event
            demolitionEvent.InvokeLocalEvent(this);
            RFDemolitionEvent.InvokeGlobalEvent(this);

            // Destroy demolished object
            RayfireMan.DestroyFragment(this, rootParent);

            // Timestamp
            // float t2 = Time.realtimeSinceStartup;
            // Debug.Log (t2 - t1);
            // Profiler.EndSample();
        }
Esempio n. 3
0
        // Demolish object
        public void Demolish()
        {
            // Profiler.BeginSample ("Demolition");
            // Debug.Log (limitations.demolitionShould);

            // Initialize if not
            if (initialized == false)
            {
                Initialize();
            }

            // Timestamp
            float t1 = Time.realtimeSinceStartup;

            // Restore position and rotation to prevent high collision offset
            transForm.position = physics.position;
            transForm.rotation = physics.rotation;

            // Demolish mesh or cluster to reference
            if (RFReferenceDemolition.DemolishReference(this) == false)
            {
                return;
            }

            // Demolish mesh and create fragments. Stop if runtime caching or no meshes/fragments were created
            if (RFDemolitionMesh.DemolishMesh(this) == false)
            {
                return;
            }

            // Demolish cluster to children nodes
            if (RFDemolitionCluster.DemolishCluster(this) == true)
            {
                return;
            }

            // Check fragments and proceed TODO separate flow for connected cls demolition
            if (limitations.demolished == false)
            {
                limitations.demolitionShould = false;
                demolitionType = DemolitionType.None;
                return;
            }

            // Connectivity check
            activation.CheckConnectivity();

            // Fragments initialisation
            InitMeshFragments();

            // Sum total demolition time
            RayfireMan.inst.maxTimeThisFrame += Time.realtimeSinceStartup - t1;

            // Init particles
            RFParticles.InitDemolitionParticles(this);

            // Event
            demolitionEvent.InvokeLocalEvent(this);
            RFDemolitionEvent.InvokeGlobalEvent(this);

            // Destroy demolished object
            RayfireMan.DestroyFragment(this, rootParent);

            // Timestamp
            // float t2 = Time.realtimeSinceStartup;
            // Debug.Log (t2 - t1);
            // Profiler.EndSample();
        }
Esempio n. 4
0
 // Copy from
 public void CopyFrom(RFReferenceDemolition referenceDemolitionDml)
 {
     reference  = referenceDemolitionDml.reference;
     randomList = referenceDemolitionDml.randomList;
     addRigid   = referenceDemolitionDml.addRigid;
 }