// Set cluster
        void SetCluster(List <Transform> tmList)
        {
            // In case of runtime add
            if (cluster == null)
            {
                cluster = new RFCluster();
            }

            // Main cluster cached, reinit non serialized vars
            if (cluster.shards.Count > 0)
            {
                InitShards(rigidList, cluster);
            }

            // Create main cluster
            if (cluster.shards.Count == 0)
            {
                cluster              = new RFCluster();
                cluster.id           = RFCluster.GetUniqClusterId(cluster);
                cluster.tm           = transform;
                cluster.depth        = 0;
                cluster.pos          = transform.position;
                cluster.initialized  = true;
                cluster.demolishable = demolishable;

                // Set shards for main cluster
                if (Application.isPlaying == true)
                {
                    SetShardsByRigids(cluster, rigidList, type);
                }
                else
                {
                    RFShard.SetShardsByTransforms(cluster, tmList, type);
                }

                // Set shard neibs
                RFShard.SetShardNeibs(cluster.shards, type, minimumArea, minimumSize, percentage, seed);

                // Set range for area and size
                RFCollapse.SetRangeData(cluster, percentage, seed);

                // Debug.Log ("SetCluster" + rigidList.Count);
            }
        }
示例#2
0
        // CLuster collapse ui
        void ClusterCollapseUI()
        {
            if (rigid.objectType == ObjectType.ConnectedCluster)
            {
                GUILayout.Label("  Collapse", EditorStyles.boldLabel);

                GUILayout.BeginHorizontal();

                GUILayout.Label("By Area:", GUILayout.Width(55));

                // Start check for slider change
                EditorGUI.BeginChangeCheck();
                rigid.clusterDemolition.cluster.areaCollapse = EditorGUILayout.Slider(rigid.clusterDemolition.cluster.areaCollapse,
                                                                                      rigid.clusterDemolition.cluster.minimumArea, rigid.clusterDemolition.cluster.maximumArea);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    if (Application.isPlaying == true)
                    {
                        RFCollapse.AreaCollapse(rigid, rigid.clusterDemolition.cluster.areaCollapse);
                    }
                }
                ;

                EditorGUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Label("By Size:", GUILayout.Width(55));

                // Start check for slider change
                EditorGUI.BeginChangeCheck();
                rigid.clusterDemolition.cluster.sizeCollapse = EditorGUILayout.Slider(rigid.clusterDemolition.cluster.sizeCollapse,
                                                                                      rigid.clusterDemolition.cluster.minimumSize, rigid.clusterDemolition.cluster.maximumSize);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    if (Application.isPlaying == true)
                    {
                        RFCollapse.SizeCollapse(rigid, rigid.clusterDemolition.cluster.sizeCollapse);
                    }
                }
                ;

                EditorGUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Label("Random:", GUILayout.Width(55));

                // Start check for slider change
                EditorGUI.BeginChangeCheck();
                rigid.clusterDemolition.cluster.randomCollapse = EditorGUILayout.IntSlider(rigid.clusterDemolition.cluster.randomCollapse, 0, 100);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    RFCollapse.RandomCollapse(rigid, rigid.clusterDemolition.cluster.randomCollapse, rigid.clusterDemolition.seed);
                }

                EditorGUILayout.EndHorizontal();

                if (GUILayout.Button("Start Collapse", GUILayout.Height(25)))
                {
                    if (Application.isPlaying)
                    {
                        foreach (var targ in targets)
                        {
                            if (targ as RayfireRigid != null)
                            {
                                RFCollapse.StartCollapse(targ as RayfireRigid);
                            }
                        }
                    }
                }
            }
        }