IEnumerator Clusterize() { while (true) { yield return(new WaitForSeconds(1)); mClusters = KMeans.Clusterize(mObjectInstances, m_DesiredClusterCount, m_RandomCentroidChoices, m_ProgressionThreshold); Colorize(); } }
void Update() { if (Input.GetKeyDown(KeyCode.R)) { Reset(); } if (Input.GetKeyDown(KeyCode.Mouse1)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { SpawnObjects(hit.point); } } if (Input.GetKeyDown(KeyCode.H)) { mStopwatch.Restart(); mClusters = HAC.Clusterize(mObjectInstances, m_ClusterThresholdHAC); mStopwatch.Stop(); UnityEngine.Debug.LogFormat("Cluster Count: {2}. Instance Count: {0}. Clusterize Time: {1}", mObjectInstances.Count, mStopwatch.Elapsed, mClusters.Count); UnityEngine.Random.InitState(Time.frameCount); Colorize(); } if (Input.GetKeyDown(KeyCode.K)) { mStopwatch.Restart(); mClusters = KMeans.Clusterize(mObjectInstances, m_DesiredClusterCount, m_RandomCentroidChoices, m_ProgressionThreshold); mStopwatch.Stop(); UnityEngine.Debug.LogFormat("Cluster Count: {2}. Instance Count: {0}. Clusterize Time: {1}", mObjectInstances.Count, mStopwatch.Elapsed, mClusters.Count); UnityEngine.Random.InitState(Time.frameCount); Colorize(); if (OnClustersUpdate != null) { OnClustersUpdate(mClusters, mFloorInstances); } StopAllCoroutines(); // StartCoroutine(Clusterize()); } if (Input.GetKeyDown(KeyCode.M)) { for (int i = 0; i < mObjectInstances.Count; i++) { Vector2 force = UnityEngine.Random.insideUnitCircle * 100; mObjectInstances[i].GetComponent <Rigidbody>().AddForce(new Vector3(force.x, 0, force.y)); } } }