public static IEnumerator swap(GameObject obj1, GameObject obj2, float seconds, GraphicalList list) { Vector3 vector_obj1 = new Vector3(obj2.transform.position.x - obj1.transform.position.x, 0, 0); Vector3 vector_obj2 = new Vector3(obj1.transform.position.x - obj2.transform.position.x, 0, 0); for (float i = 0; i < seconds; i += Time.deltaTime) { obj1.transform.position += vector_obj1 * Time.deltaTime / seconds; obj2.transform.position += vector_obj2 * Time.deltaTime / seconds; yield return(null); } list.drawObject(); }
public void Start() { GraphicalList graphList = gameObject.AddComponent <GraphicalList>(); List <int> testList = new List <int>() { 5, 4, 3, 2, 1 }; Parser.DynamicList list_test = Parser.VariableUtils.createDynamicList(testList); (list_test.atIndex(new Parser.Integer(0))).setName("int1"); (list_test.atIndex(new Parser.Integer(1))).setName("int2"); (list_test.atIndex(new Parser.Integer(2))).setName("int3"); (list_test.atIndex(new Parser.Integer(3))).setName("int4"); (list_test.atIndex(new Parser.Integer(4))).setName("int5"); Dictionary <string, GameObject> list_dict_test = new Dictionary <string, GameObject>(); graphList.list_dict = list_dict_test; graphList.list = list_test; graphList.drawObject(); // To update the dictionary /* INSERT DEMO * Parser.Integer insert_numb = new Parser.Integer(5); * insert_numb.setName("int6"); * * graphList.insert(new Parser.Integer(2), insert_numb); // tester avec les index qui se trouvent a l'extremite */ /* REMOVE DEMO * graphList.remove(new Parser.Integer(1)); */ /* SWAP DEMO * graphList.swap(new Parser.Integer(1), new Parser.Integer(4)); */ /*float t = Time.time; * * while (t < Time.time - 2) * { * * }*/ //Thread.Sleep(1000); //Debug.Log("Animation finished!"); StartCoroutine(testTimeDelay()); /* BUBBLE SORT DEMO * StartCoroutine(bubbleSort()); */ IEnumerator testTimeDelay() { graphList.swap(new Parser.Integer(1), new Parser.Integer(4)); yield return(new WaitForSeconds(10f)); graphList.remove(new Parser.Integer(1)); } IEnumerator bubbleSort() { for (int j = 0; j <= list_test.length().getValue() - 2; j++) { for (int i = 0; i <= list_test.length().getValue() - 2; i++) { if (list_test.atIndex(new Parser.Integer(i)).getValue() > list_test.atIndex(new Parser.Integer(i + 1)).getValue()) { graphList.swap(new Parser.Integer(i), new Parser.Integer(i + 1)); yield return(new WaitForSeconds(2.5f)); } } } } /*IEnumerator TimeDelayFunction() * { * * for (int j = 0; j <= list_test.length().getValue() - 2; j++) * { * for (int i = 0; i <= list_test.length().getValue() - 2; i++) * { * if (list_test.atIndex(new Parser.Integer(i)).getValue() > list_test.atIndex(new Parser.Integer(i + 1)).getValue()) * { * graphList.swap(new Parser.Integer(i), new Parser.Integer(i + 1)); * yield return new WaitForSeconds(1f); * } * } * } * /* * int smallest; * * for (int i = 0; i < list_test.length().getValue() - 1; i++) * { * smallest = i; * for (int j = i + 1; j < list_test.length().getValue(); j++) * { * if (list_test.atIndex(new Parser.Integer(j)).getValue() < list_test.atIndex(new Parser.Integer(smallest)).getValue()) * { * smallest = j; * } * } * * graphList.swap(new Parser.Integer(smallest), new Parser.Integer(i)); * yield return new WaitForSeconds(1f); * } * * Debug.Log("List is sorted !"); * } */ }
public static IEnumerator insertAnimation(GameObject[] obj_list, string obj_name_to_fade, Vector3 vector, float seconds, int target_alpha, GraphicalList list) { seconds /= 2f; for (float i = 0; i < seconds; i += Time.deltaTime) { foreach (GameObject obj in obj_list) { obj.transform.position += vector * Time.deltaTime / seconds; } yield return(null); } list.drawObject(); GameObject obj_to_fade = list.list_dict[obj_name_to_fade]; MeshRenderer render = obj_to_fade.GetComponent <MeshRenderer>(); render.material = Resources.Load <Material>("Materials/obj_transparent_mat"); Color set_to_transparent = new Color(render.material.color.r, render.material.color.g, render.material.color.b, 0f); render.material.color = set_to_transparent; float stable_alpha_color = target_alpha - render.material.color.a; while (render.material.color.a < target_alpha) { Color new_color = new Color(render.material.color.r, render.material.color.g, render.material.color.b, render.material.color.a + (stable_alpha_color * Time.deltaTime / seconds)); render.material.color = new_color; yield return(null); } render.material = Resources.Load <Material>("Materials/obj_ordinary_mat"); list.drawObject(); }