RayFire Connectivity

RayFire Connectivity manages connection among separate objects with Rigid component and activates them. Using Connectivity you can break complex structures at their bottom and top will be activated and fall down automatically. Also Connectivity can clusterize top group of objects so they will be simulated as one Connected Cluster.

Rigid component requirements: Connectivity will consider child object with Rigid component as it's Shard only if Rigid component fits it's requirements.
· 	Inactive or Kinematic simulation type: Objects with Rigid component should have simulation type set to Inactive or Kinematik, only these simulation types possible to Activate which means turn to Dynamic objects affected by Gravity. 
·	Mesh object type: Connectivity needs Rigid component to be single object with Mesh.
·	By Connectivity activation: By Connectivity property in Activation properties should be Enabled.
·	Unyielding Shard:  At lease one child Rigid should have Enabled Unyielding property in Activation properties. Every shard in Connectivity structure will check for connection with at least one Unyielding shard and will be activated if there is no such connection. You can add Unyielding component on the same root with Connectivity component to define one or several groups of Unyielding Shards by it's gizmo. It will enable Unyielding property in Activation properties.

https://youtu.be/WeKrhsZyXsE	
	
	Cluster

Setup Cluster button: Create cluster with all children as cluster shards and establish all connections among then based on Connectivity type and Filters properties. During connection calculation every shard also cache shared area value which later can be used for Collapse.
If cluster is not created at Start then it will be created automatically, but it is better to do this manually to save resources. You will need to setup cluster again in case you will change children position or destroy or add new children. 

Reset Cluster button: Nullify Connectivity cluster.

Show Gizmo toggle: Toggle preview of bounding box gizmo which cover all Shards in Connectivity cluster.

Show Connections toggle: Toggle preview of all connections among Shards. Every shard will show a line from it's center to center of connected Shard.

Show Nodes toggle: Toggle preview of all Shards. Every shard will show a sphere at it's center.
	
	Connectivity

Type: Define the the way connections among Shards will be calculated. 
·	By Bounding Box: Shards will be considered as connected if their bound boxes interpenetrates with each other. This is the fastest way to establish connectivity and can be used in Runtime, but calculated shared are value will not be precise and will be based on shard's size.
·	By Mesh: Shards will be considered as connected if triangle of one Shard fits triangle of neighbor shard. This is the slowest way to establish connectivity and should be used only in Editor with Setup Cluster button, but it precisely calculates shared area value which provides realistic Collapse By Area.
·	By Bounding Box and Mesh: Shards will be considered as connected if their bound boxes interpenetrates with each other. If Shards also share triangles then Shared area will be calculated using By Mesh method, if shards do not share triangles then By Bounding Box method will be used.
	
	Filters
Filters allows you to decrease amount of connections. There are three filters and they are turned off by default.

Minimum Area: Two shards will have connection if their shared area is bigger than this value.

Minimum Size: Two shards will have connection if their size is bigger than this value.

Percentage: Random percentage of connections will be discarded.

Seed: Seed for random percentage filter and for Random Collapse.

	Cluster Properties

Clusterize: All activated group of Shards which are not connected through other shards with any Unyielding Shard but connected with each other will be moved under one empty root parent which will get Connected Cluster Rigid component and whole group will be simulated as one object. Rigid component will inherit Connected Cluster properties from first Shard's Connected Cluster properties except Demolition Type property which depends on Demolishable property.

Demolishable: If Clusterize is On, Set Demolition type to Runtime for Connected Clusters created during activation. Otherwise it will be set to None.

	Collapse
Collapse allows you start break connections among shards and activate single Shards or Group of Shards if they are not connected with any of Unyielding Shard. It is a good idea to use Collapse with other activation types like By Offset, in this case shards which were activated by Collpase will fall down and move still Inactive shards and activate them as well and at some point whole collapse will start look like a chain reaction.

https://youtu.be/_-L_INZ_QZg

There are two ways to initiate collapse: 
·	Set Collapse threshold values: You can break connections by manually setting By Area, By Size and Random threshold values. You can set these thresholds using Collapse Sliders on top of component UI or using public static Methods. You can set all three of them together depends on which one works better for you. For instance, if you set By Size value to 0.5, all shards with size less than 0.5 units will loose their connections. 
·	Start Collapse using Collapse properties: If you don't want to directly set exact threshold values you can automate this process using Collapse group of properties which allows you to define collapse type and speed. You can start Collapse using Start Collapse button on top of components UI or using public static method. With Start Collapse feature you can set only one type which will be used during collapse.

	User Interface
In Connectivity component you may see Collapse UI on top of the component and at the bottom. 
	At the top you can manually set collapse threshold values in Runtime to initiate collapse. By Area and By Size values represented as float units and Random values represented as integer. When you setup cluster all three sliders will be set to value 0 so you will be able to increase them and break connections. By Area and By Size sliders will be capped by biggest shared area and biggest shard size accordingly, Random slider will be capped by value 100 since it is measured in percentage.
	
	At the bottom you can setup collapse properties for Start Collapse button/method. 
Type: There are three ways to break connections among Shards. You should try in Editor all of them to find the one which looks better for your structure and your goal.  
·	By Area: Shard will loose it's connections if it's shared area surface is less then defined value.
·	By Size: Shard will loose it's connections if it's Size is less then defined value.
·	Random: Shard will loose it's connections if it's random value in range from 0 to 100 is less then defined value.

Start: Defines start value in percentage relative to whole range of picked type. For instance, Type set to By Size, you have 200 shards with the smallest shard size equal to 0.1 unit and biggest shard size equal to 50 units. If you set Start value to 50% it will start collapse by setting By Size threshold value to 25 units and all shards with size less than 25 units will loose their connections. Increase this value if you want to Start Collapse quickly so a lot of shards will loose connections and will be activated right from the beginning. Set it to 0 if you want to start collapse slowly activating shards one by one.

End: Defines end value in percentage relative to whole range of picked type. Set tp 100 if you want to break all connections or set it lower if you want to keep some connections.

Steps: Amount of times when defined threshold value will be set during Duration period. 

Duration: Time which it will take Start value to be increased to End value.

	Methods
You can initiate collapse using several public static methods implemented in RFCollapse class. 

By Area collapse methods:
public static void AreaCollapse (RayfireConnectivity scr, int areaPercentage);
public static void AreaCollapse (RayfireConnectivity scr, float areaValue);

By Size collapse methods:
public static void SizeCollapse (RayfireConnectivity scr, int sizePercentage);
public static void SizeCollapse (RayfireConnectivity scr, float sizeValue);

Random  collapse method:
public static void RandomCollapse (RayfireConnectivity scr, int percentage, int seed);

Start Collapse method:
public static void StartCollapse(RayfireConnectivity scr);

Example:

GameObject obj = GameObject.Find ("ConnectivityObject");
RayfireConnectivity scr = obj.GetComponent<RayfireConnectivity>();

RFCollapse.AreaCollapse (scr, 0.5f);
or
RFCollapse.StartCollapse(scr);

Shooting tutorial
https://youtu.be/1DjkINDRL9I

Activator tutorial
https://youtu.be/MeIQpwY6glc