// CLuster connection and nodes viewport preview static void ClusterDraw(RayfireRigid targ) { if (targ.objectType == ObjectType.ConnectedCluster) { if (targ.clusterDemolition.cluster != null && targ.clusterDemolition.cluster.shards.Count > 0) { // Reinit connections if (targ.clusterDemolition.cluster.initialized == false) { RFCluster.InitCluster(targ, targ.clusterDemolition.cluster); } // Draw for (int i = 0; i < targ.clusterDemolition.cluster.shards.Count; i++) { if (targ.clusterDemolition.cluster.shards[i].uny == false) { if (targ.clusterDemolition.cluster.shards[i].nIds.Count > 0) { Gizmos.color = Color.blue; } else { Gizmos.color = Color.gray; } } else { Gizmos.color = Color.red; } if (targ.clusterDemolition.nd == true) { Gizmos.DrawWireSphere(targ.clusterDemolition.cluster.shards[i].tm.position, targ.clusterDemolition.cluster.shards[i].sz / 12f); } if (targ.clusterDemolition.cn == true) { if (targ.clusterDemolition.cluster.shards[i].neibShards != null) { for (int j = 0; j < targ.clusterDemolition.cluster.shards[i].neibShards.Count; j++) { Gizmos.DrawLine(targ.clusterDemolition.cluster.shards[i].tm.position, targ.clusterDemolition.cluster.shards[i].neibShards[j].tm.position); } } } } } } }
/// ///////////////////////////////////////////////////////// /// Save / Restore /// ///////////////////////////////////////////////////////// // Save backup cluster to restore it later public static void SaveBackup(RayfireRigid scr) { // No need to save if (scr.reset.action != RFReset.PostDemolitionType.DeactivateToReset) { return; } // Do not backup child clusters if (scr.clusterDemolition.cluster.id > 1) { return; } // Create backup if not exist if (scr.clusterDemolition.backup == null) { scr.clusterDemolition.backup = new RFBackupCluster(); } // Already saved if (scr.clusterDemolition.backup.saved == true) { return; } // Copy class scr.clusterDemolition.backup.cluster = new RFCluster(scr.clusterDemolition.cluster); // Init shards: set non serialized vars RFCluster.InitCluster(scr, scr.clusterDemolition.backup.cluster); // Save nested clusters shards and clusters position and rotation SaveTmRecursive(scr.clusterDemolition.backup.cluster); // Backup created, do not create again at next reset scr.clusterDemolition.backup.saved = true; // Debug.Log ("Saved"); }
// Restore cluster using backup cluster public static void RestoreBackup(RayfireRigid scr) { if (scr.reset.action == RFReset.PostDemolitionType.DeactivateToReset) { // Do not restore child clusters if (scr.clusterDemolition.cluster.id > 1) { return; } // Has no backup if (scr.clusterDemolition.backup == null) { return; } // Cluster was not demolished. Stop if (scr.objectType == ObjectType.ConnectedCluster) { if (scr.clusterDemolition.cluster.shards.Count == scr.clusterDemolition.backup.cluster.shards.Count) { return; } } // TODO check if nested cluster was demolished // if (false) if (scr.objectType == ObjectType.NestedCluster) // if (scr.clusterDemolition.cluster.tm.gameObject.activeSelf == true) //return; // Completely demolished child clusters do not deactivates if saved // Unyielding component with inactive overlap bug // Reset fragments list scr.fragments = null; // Remove particles DestroyParticles(scr); // Reset local shard rigid, destroy components TODO INPUT ORIGINAL CLUSTER, GET RIGIDS ResetDeepShardRigid(scr, scr.clusterDemolition.backup.cluster); // Create new child clusters roots destroy by nested cluster. BEFORE reparent shards if (scr.objectType == ObjectType.NestedCluster) { ResetRootsRecursive(scr.clusterDemolition.backup.cluster); RestoreClusterTmRecursive(scr.clusterDemolition.backup.cluster); ResetRootsParentsRecursive(scr.clusterDemolition.backup.cluster); } // Restore shards parent, position and rotation RestoreShardTmRecursive(scr.clusterDemolition.backup.cluster); // Destroy new child clusters roots created by connected cluster. AFTER reparent shards if (scr.objectType == ObjectType.ConnectedCluster) { DestroyRoots(scr); } // Copy class scr.clusterDemolition.cluster = new RFCluster(scr.clusterDemolition.backup.cluster); // Reset colliders RFPhysic.CollectClusterColliders(scr, scr.clusterDemolition.cluster); // Init shards: set non serialized vars RFCluster.InitCluster(scr, scr.clusterDemolition.cluster); scr.clusterDemolition.collapse.inProgress = false; } }