Ejemplo n.º 1
0
        // Inspector
        public override void OnInspectorGUI()
        {
            // Get target
            conn = target as RayfireConnectivity;
            if (conn == null)
            {
                return;
            }

            GUILayout.Space(8);

            ClusterSetupUI();

            ClusterPreviewUI();

            ClusterCollapseUI();

            GUILayout.Space(3);

            if (conn.cluster.shards.Count > 0)
            {
                GUILayout.Label("    Cluster Shards: " + conn.cluster.shards.Count);
            }

            DrawDefaultInspector();
        }
Ejemplo n.º 2
0
        // Start collapse coroutine
        IEnumerator CollapseCor(RayfireConnectivity scr)
        {
            // Wait time
            WaitForSeconds wait = new WaitForSeconds(duration / steps);

            // Iterate collapse
            inProgress = true;
            float step = (end - start) / (float)steps;

            for (int i = 0; i < steps; i++)
            {
                float percentage = start + step * i;
                if (type == RFCollapseType.ByArea)
                {
                    AreaCollapse(scr, (int)percentage);
                }
                else if (type == RFCollapseType.BySize)
                {
                    SizeCollapse(scr, (int)percentage);
                }
                else if (type == RFCollapseType.Random)
                {
                    RandomCollapse(scr, (int)percentage, scr.seed);
                }
                yield return(wait);
            }
            inProgress = false;
        }
        static void DrawGizmosSelected(RayfireConnectivity targ, GizmoType gizmoType)
        {
            // Connections
            if (targ.showConnections == true)
            {
                if (Application.isPlaying == true)
                {
                    Gizmos.color = Color.green;
                    if (targ.cluster != null && targ.cluster.shards.Count > 0)
                    {
                        foreach (var shard in targ.cluster.shards)
                        {
                            // Set color
                            Gizmos.color = shard.rigid.activation.unyielding == true
                                ? Color.red
                                : Color.green;

                            // draw sphere
                            if (targ.sphereSize > 0)
                            {
                                Gizmos.DrawWireSphere(shard.tm.position, shard.bound.size.magnitude / 13f * targ.sphereSize);
                            }

                            // Draw connection
                            foreach (var neibShard in shard.neibShards)
                            {
                                if (neibShard.rigid.activation.connect != null)
                                {
                                    Gizmos.DrawLine(shard.tm.position, neibShard.tm.position);
                                }
                            }
                        }
                    }
                }
            }

            // Gizmo preview
            if (targ.showGizmo == true)
            {
                // Gizmo properties
                Gizmos.color = wireColor;

                // Gizmo
                if (targ.source == RayfireConnectivity.ConnTargetType.Gizmo)
                {
                    Gizmos.matrix = targ.transform.localToWorldMatrix;
                    Gizmos.DrawWireCube(Vector3.zero, targ.size);
                }

                // Children
                if (targ.source == RayfireConnectivity.ConnTargetType.Children)
                {
                    if (targ.transform.childCount > 0)
                    {
                        Bounds bound = RFCluster.GetChildrenBound(targ.transform);
                        Gizmos.DrawWireCube(bound.center, bound.size);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 // Connectivity check
 public void CheckConnectivity()
 {
     if (byConnectivity == true && connect != null)
     {
         connect.checkNeed = true;
         connect           = null;
     }
 }
Ejemplo n.º 5
0
 void SetDirty(RayfireConnectivity scr)
 {
     if (Application.isPlaying == false)
     {
         EditorUtility.SetDirty(scr);
         EditorSceneManager.MarkSceneDirty(scr.gameObject.scene);
     }
 }
Ejemplo n.º 6
0
 static void DrawGizmosSelected(RayfireConnectivity targ, GizmoType gizmoType)
 {
     // Connections
     //if (targ.enabled == true)
     {
         ClusterDraw(targ);
         GizmoDraw(targ);
     }
 }
Ejemplo n.º 7
0
 static void GizmoDraw(RayfireConnectivity targ)
 {
     if (targ.showGizmo == true)
     {
         // Gizmo properties
         Gizmos.color = wireColor;
         if (targ.transform.childCount > 0)
         {
             Bounds bound = RFCluster.GetChildrenBound(targ.transform);
             Gizmos.DrawWireCube(bound.center, bound.size);
         }
     }
 }
Ejemplo n.º 8
0
        static void DrawGizmosSelected(RayfireConnectivity targ, GizmoType gizmoType)
        {
            // Connections
            //if (targ.enabled == true)
            {
                if (RFCluster.IntegrityCheck(targ.cluster) == false)
                {
                    Debug.Log("RayFire Connectivity: " + targ.name + " has missing shards. Reset or Setup cluster.", targ.gameObject);
                }

                ClusterDraw(targ);
                GizmoDraw(targ);
            }
        }
Ejemplo n.º 9
0
        static void ClusterDraw(RayfireConnectivity targ)
        {
            if (targ.showNodes == true || targ.showConnections == true)
            {
                if (targ.cluster != null && targ.cluster.shards.Count > 0)
                {
                    // Reinit connections
                    if (targ.cluster.initialized == false)
                    {
                        RayfireConnectivity.InitShards(targ.rigidList, targ.cluster);
                    }

                    for (int i = 0; i < targ.cluster.shards.Count; i++)
                    {
                        if (targ.cluster.shards[i].tm != null)
                        {
                            // Color
                            if (targ.cluster.shards[i].rigid == null)
                            {
                                Gizmos.color = targ.cluster.shards[i].uny == true ? Color.red : Color.green;
                            }
                            else
                            {
                                Gizmos.color = targ.cluster.shards[i].rigid.activation.unyielding == true ? Color.red : Color.green;
                            }

                            // Nodes
                            if (targ.showNodes == true)
                            {
                                Gizmos.DrawWireSphere(targ.cluster.shards[i].tm.position, targ.cluster.shards[i].sz / 12f);
                            }

                            // Connection
                            if (targ.showConnections == true)
                            {
                                for (int j = 0; j < targ.cluster.shards[i].neibShards.Count; j++)
                                {
                                    if (targ.cluster.shards[i].neibShards[j].tm != null)
                                    {
                                        Gizmos.DrawLine(targ.cluster.shards[i].tm.position, targ.cluster.shards[i].neibShards[j].tm.position);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        // Start collapse
        public static void StartCollapse(RayfireConnectivity scr)
        {
            // Already running
            if (scr.collapse.inProgress == true)
            {
                return;
            }

            // Not enough shards
            if (scr.cluster.shards.Count <= 1)
            {
                return;
            }

            scr.StartCoroutine(scr.collapse.CollapseCor(scr));
        }
Ejemplo n.º 11
0
        // Crumbling
        public static void SizeCollapse(RayfireConnectivity connectivity, float sizeValue)
        {
            // Value lower than last
            if (sizeValue < connectivity.cluster.sizeCollapse)
            {
                return;
            }

            // Set value
            connectivity.cluster.sizeCollapse = sizeValue;

            // Main cluster.
            int removed = RemNeibBySize(connectivity.cluster, sizeValue);;

            if (removed > 0)
            {
                connectivity.CheckConnectivity();
            }
        }
Ejemplo n.º 12
0
        // Crumbling
        public static void AreaCollapse(RayfireConnectivity connectivity, float areaValue)
        {
            // Value lower than last
            if (areaValue < connectivity.cluster.areaCollapse)
            {
                return;
            }

            // Set value
            connectivity.cluster.areaCollapse = areaValue;

            // Main cluster.
            int removed = RemNeibByArea(connectivity.cluster, areaValue);;

            if (removed > 0)
            {
                connectivity.CheckConnectivity();
            }
        }
Ejemplo n.º 13
0
        // Crumbling
        public static void RandomCollapse(RayfireConnectivity connectivity, int randomPercentage, int seedValue)
        {
            // Clamp
            randomPercentage = Mathf.Clamp(randomPercentage, 0, 100);

            // Value lower than last
            if (randomPercentage < connectivity.cluster.randomCollapse)
            {
                return;
            }

            // Set value
            connectivity.cluster.randomCollapse = randomPercentage;
            connectivity.cluster.randomSeed     = seedValue;

            // Main cluster.
            int removed = RemNeibRandom(connectivity.cluster, randomPercentage, seedValue);

            if (removed > 0)
            {
                connectivity.CheckConnectivity();
            }
        }
Ejemplo n.º 14
0
 // Collapse in percents
 public static void SizeCollapse(RayfireConnectivity connectivity, int sizePercentage)
 {
     sizePercentage = Mathf.Clamp(sizePercentage, 0, 100);
     SizeCollapse(connectivity, Mathf.Lerp(connectivity.cluster.minimumSize, connectivity.cluster.maximumSize, sizePercentage / 100f));
 }
Ejemplo n.º 15
0
        /// /////////////////////////////////////////////////////////
        /// Connectivity
        /// /////////////////////////////////////////////////////////

        // Collapse in percents
        public static void AreaCollapse(RayfireConnectivity connectivity, int areaPercentage)
        {
            areaPercentage = Mathf.Clamp(areaPercentage, 0, 100);
            AreaCollapse(connectivity, Mathf.Lerp(connectivity.cluster.minimumArea, connectivity.cluster.maximumArea, areaPercentage / 100f));
        }