// Imports animation rules from AnimationRule class (or from text file containing AnimationRule info) // Sets animeReady flag indicating animation ready to play in Update() //[ExposeInEditor(RuntimeOnly = false)] public void ImportRule() { var fileName = ""; switch (SelectObject.combinationName) { case "Screw_Nut_Interaction": fileName = textAsset_Screw_Nut_Interaction.name + ".txt"; info = textAsset_Screw_Nut_Interaction.text; Functions_Screw_Nut_Interaction CustomFunctions_Screw_Nut_Interaction = new Functions_Screw_Nut_Interaction(); CustomFunctions_Screw_Nut_Interaction = JsonUtility.FromJson <Functions_Screw_Nut_Interaction>(info); for (int i = 0; i < CustomFunctions_Screw_Nut_Interaction.functions.Count; i++) { if ((CustomFunctions_Screw_Nut_Interaction.functions[i].combination_name == SelectObject.combinationName) && (CustomFunctions_Screw_Nut_Interaction.functions[i].Animation_name == SaveFunction_BeltandPulley.animationName)) { CustomFunction_Screw_Nut_Interaction = CustomFunctions_Screw_Nut_Interaction.functions[i]; } } rule = new AnimationRule(highlighter.animationRule.objNames); //Create markers rule.sourceRotation = StringToQuaternion(CustomFunction_Screw_Nut_Interaction.sourceRotation); rule.sourceNormal = StringToVector3(CustomFunction_Screw_Nut_Interaction.sourceNormal); rule.targetCentroid = StringToVector3(CustomFunction_Screw_Nut_Interaction.targetCentroid); rule.targetNormal = StringToVector3(CustomFunction_Screw_Nut_Interaction.targetNormal); rule.sourcePosition = StringToVector3(CustomFunction_Screw_Nut_Interaction.sourcePosition); rule.startpt = StringToVector3(CustomFunction_Screw_Nut_Interaction.startpt); rule.endpt = StringToVector3(CustomFunction_Screw_Nut_Interaction.endpt); rule.contactpt = StringToVector3(CustomFunction_Screw_Nut_Interaction.contactpt); GameObject sourceObj = GameObject.Find("Screw"); GameObject targetObj = GameObject.Find("Nut"); marker_start = Instantiate(marker, transform.TransformPoint(rule.startpt), Quaternion.identity); marker_start.name = "start"; marker_end = Instantiate(marker, transform.TransformPoint(rule.endpt), Quaternion.identity); marker_end.name = "end"; marker_start.transform.parent = sourceObj.transform; marker_end.transform.parent = sourceObj.transform; marker_contact = Instantiate(marker, targetObj.transform.TransformPoint(rule.contactpt), Quaternion.identity); marker_contact.name = "contact"; marker_contact.transform.parent = targetObj.transform; AlignObjectsNoviceClick(); if (SaveFunction_BeltandPulley.animationRun == true) { animeReady = true; } else { animeReady = false; } break; case "Gear": fileName = textAsset_Gear.name + ".txt"; info = textAsset_Gear.text; Functions_Gear CustomFunctions_Gear = new Functions_Gear(); CustomFunctions_Gear = JsonUtility.FromJson <Functions_Gear>(info); for (int i = 0; i < CustomFunctions_Gear.functions.Count; i++) { if ((CustomFunctions_Gear.functions[i].combination_name == SelectObject.combinationName) && (CustomFunctions_Gear.functions[i].Animation_name == SaveFunction_BeltandPulley.animationName)) { CustomFunction_Gear = CustomFunctions_Gear.functions[i]; } } rule = new AnimationRule(); rule.gearAngle = float.Parse(CustomFunction_Gear.speed); rule.targetNormal = StringToVector3(CustomFunction_Gear.surfaceNormal); Transform[] gears = GameObject.Find("Gear").GetComponentsInChildren <Transform>(); if (SaveFunction_BeltandPulley.animationRun == true) { animeReady = true; GearSetup(rule.targetNormal, rule.gearAngle, gears); } else { animeReady = false; GearSetup(rule.targetNormal, rule.gearAngle, gears); } break; case "Belt and Pulley": fileName = textAsset_BeltandPulley.name + ".txt"; info = textAsset_BeltandPulley.text; Functions_BeltandPulley CustomFunctions_BeltandPulley = new Functions_BeltandPulley(); CustomFunctions_BeltandPulley = JsonUtility.FromJson <Functions_BeltandPulley>(info); for (int i = 0; i < CustomFunctions_BeltandPulley.functions.Count; i++) { if ((CustomFunctions_BeltandPulley.functions[i].combination_name == SelectObject.combinationName) && (CustomFunctions_BeltandPulley.functions[i].Animation_name == SaveFunction_BeltandPulley.animationName)) { CustomFunction_BeltandPulley = CustomFunctions_BeltandPulley.functions[i]; } } rule_BeltandPulley = new AnimationRule_BeltandPulley(highlighter.animationRule_BeltandPulley.objNames); //Create markers rule_BeltandPulley.surfaceNormal = StringToVector3(CustomFunction_BeltandPulley.surfaceNormal); if (SaveFunction_BeltandPulley.animationRun == true) { animeReady = true; } else { animeReady = false; } break; } }
// Imports animation rules from AnimationRule class (or from text file containing AnimationRule info) // Sets animeReady flag indicating animation ready to play in Update() //[ExposeInEditor(RuntimeOnly = false)] public void ImportRule() { var fileName = ""; switch (SelectObject.combinationName) { case "Screw_Nut_Interaction": fileName = textAsset_Screw_Nut_Interaction.name + ".txt"; info = textAsset_Screw_Nut_Interaction.text; Functions_Screw_Nut_Interaction CustomFunctions_Screw_Nut_Interaction = new Functions_Screw_Nut_Interaction(); CustomFunctions_Screw_Nut_Interaction = JsonUtility.FromJson <Functions_Screw_Nut_Interaction>(info); for (int i = 0; i < CustomFunctions_Screw_Nut_Interaction.functions.Count; i++) { if ((CustomFunctions_Screw_Nut_Interaction.functions[i].combination_name == SelectObject.combinationName) && (CustomFunctions_Screw_Nut_Interaction.functions[i].Animation_name == SaveFunction_Novice.animationName)) { CustomFunction_Screw_Nut_Interaction = CustomFunctions_Screw_Nut_Interaction.functions[i]; } } rule = new AnimationRule_Novice(); //Create markers rule.sourceRotation = StringToQuaternion(CustomFunction_Screw_Nut_Interaction.sourceRotation); rule.sourceNormal = StringToVector3(CustomFunction_Screw_Nut_Interaction.sourceNormal); rule.targetCentroid = StringToVector3(CustomFunction_Screw_Nut_Interaction.targetCentroid); rule.targetNormal = StringToVector3(CustomFunction_Screw_Nut_Interaction.targetNormal); rule.sourcePosition = StringToVector3(CustomFunction_Screw_Nut_Interaction.sourcePosition); rule.startpt = StringToVector3(CustomFunction_Screw_Nut_Interaction.startpt); rule.endpt = StringToVector3(CustomFunction_Screw_Nut_Interaction.endpt); rule.contactpt = StringToVector3(CustomFunction_Screw_Nut_Interaction.contactpt); GameObject sourceObj = GameObject.Find("Screw"); GameObject targetObj = GameObject.Find("Nut"); marker_start = Instantiate(marker, transform.TransformPoint(rule.startpt), Quaternion.identity); marker_start.name = "start"; marker_end = Instantiate(marker, transform.TransformPoint(rule.endpt), Quaternion.identity); marker_end.name = "end"; marker_start.transform.parent = sourceObj.transform; marker_end.transform.parent = sourceObj.transform; marker_contact = Instantiate(marker, targetObj.transform.TransformPoint(rule.contactpt), Quaternion.identity); marker_contact.name = "contact"; marker_contact.transform.parent = targetObj.transform; AlignObjectsNoviceClick(); if (SaveFunction_Novice.animationRun == true) { animeReady = true; } else { animeReady = false; } break; case "Gear": fileName = textAsset_Gear.name + ".txt"; info = textAsset_Gear.text; Functions_Gear CustomFunctions_Gear = new Functions_Gear(); CustomFunctions_Gear = JsonUtility.FromJson <Functions_Gear>(info); for (int i = 0; i < CustomFunctions_Gear.functions.Count; i++) { if ((CustomFunctions_Gear.functions[i].combination_name == SelectObject.combinationName) && (CustomFunctions_Gear.functions[i].Animation_name == SaveFunction_Novice.animationName)) { CustomFunction_Gear = CustomFunctions_Gear.functions[i]; } } rule = new AnimationRule_Novice(); rule.gearAngle = float.Parse(CustomFunction_Gear.speed); rule.targetNormal = StringToVector3(CustomFunction_Gear.surfaceNormal); Transform[] gears = GameObject.Find("Gear").GetComponentsInChildren <Transform>(); if (SaveFunction_Novice.animationRun == true) { animeReady = true; GearSetup(rule.targetNormal, rule.gearAngle, gears); } else { animeReady = false; GearSetup(rule.targetNormal, rule.gearAngle, gears); } break; case "Belt and Pulley": fileName = textAsset_BeltandPulley.name + ".txt"; info = textAsset_BeltandPulley.text; Functions_BeltandPulley CustomFunctions_BeltandPulley = new Functions_BeltandPulley(); CustomFunctions_BeltandPulley = JsonUtility.FromJson <Functions_BeltandPulley>(info); for (int i = 0; i < CustomFunctions_BeltandPulley.functions.Count; i++) { if ((CustomFunctions_BeltandPulley.functions[i].combination_name == SelectObject.combinationName) && (CustomFunctions_BeltandPulley.functions[i].Animation_name == SaveFunction_Novice.animationName)) { CustomFunction_BeltandPulley = CustomFunctions_BeltandPulley.functions[i]; } } rule_BeltandPulley = new AnimationRule_BeltandPulley(); //Create markers rule_BeltandPulley.surfaceNormal = StringToVector3(CustomFunction_BeltandPulley.surfaceNormal); if (SaveFunction_Novice.animationRun == true) { animeReady = true; } else { animeReady = false; } break; case "Transmission": fileName = textAsset_Transmission.name + ".txt"; info = textAsset_Transmission.text; Functions_Transmission CustomFunctions_Transmission = new Functions_Transmission(); CustomFunctions_Transmission = JsonUtility.FromJson <Functions_Transmission>(info); for (int i = 0; i < CustomFunctions_Transmission.functions.Count; i++) { if ((CustomFunctions_Transmission.functions[i].combination_name == SelectObject.combinationName) && (CustomFunctions_Transmission.functions[i].Animation_name == SaveFunction_Novice.animationName)) { CustomFunction_Transmission = CustomFunctions_Transmission.functions[i]; } } Debug.Log(CustomFunction_Transmission.speed1); if (CustomFunction_Transmission.speed1 != "") { transmission = true; List <string> contactpts = new List <string>(); string[] points = new String[] { }; points = CustomFunction_Transmission.contactpts.Split(';'); for (int i = 0; i < 6; i++) { contactpts.Add(points[i]); rule = new AnimationRule_Novice(highlighter.animationRule.objNames); //Create markers //Transform sourceObj = GameObject.Find(rule.objNames[0]).transform; Transform targetObj_Transmission = GameObject.Find("Transmission").transform.Find("Handle_Gear2/Plate"); /*rule.targetNormal = targetObj_Transmission.TransformVector(highlighter.animationRule.targetNormal); * rule.sourceNormal = transform.TransformVector(highlighter.animationRule.sourceNormal); * //rule.targetCentroid = targetObj.TransformPoint(highlighter.animationRule.targetCentroid); * rule.targetCentroid = targetObj_Transmission.TransformPoint(highlighter.animationRule.contactlist[i]); * rule.startpt = highlighter.animationRule.startpt; * rule.endpt = highlighter.animationRule.endpt; * rule.contactpt = highlighter.animationRule.contactlist[i];*/ //Create markers //rule.sourceRotation = StringToQuaternion(CustomFunction_Screw_Nut_Interaction.sourceRotation); rule.targetCentroid = targetObj_Transmission.TransformPoint(StringToVector3(contactpts[i])); rule.targetNormal = targetObj_Transmission.TransformVector(StringToVector3(CustomFunction_Transmission.targetNormal)); rule.sourcePosition = StringToVector3(CustomFunction_Transmission.sourcePosition); rule.startpt = StringToVector3(CustomFunction_Transmission.startpt); rule.endpt = StringToVector3(CustomFunction_Transmission.endpt); rule.contactpt = StringToVector3(contactpts[i]); Transform sourceObj_Transmission = GameObject.Find("Transmission/Handle_Gear2/Plate/Screw_02_" + i).transform; //GameObject targetObj = GameObject.Find("Nut"); rule.sourceNormal = sourceObj_Transmission.TransformVector(StringToVector3(CustomFunction_Transmission.sourceNormal)); marker_start = Instantiate(marker, sourceObj_Transmission.transform.TransformPoint(rule.startpt), Quaternion.identity); marker_start.name = "start"; marker_end = Instantiate(marker, sourceObj_Transmission.transform.TransformPoint(rule.endpt), Quaternion.identity); marker_end.name = "end"; marker_start.transform.parent = sourceObj_Transmission.transform; marker_end.transform.parent = sourceObj_Transmission.transform; marker_contact = Instantiate(marker, targetObj_Transmission.TransformPoint(rule.contactpt), Quaternion.identity); marker_contact.name = "contact"; marker_contact.transform.parent = targetObj_Transmission; sourceObj_Transmission.rotation = Quaternion.FromToRotation(-rule.sourceNormal, rule.targetNormal) * sourceObj_Transmission.rotation; sourceObj_Transmission.position = rule.targetCentroid + rule.targetNormal; //AlignObjects(rule); } if (SaveFunction_Novice.animationRun == true) { animeReady = true; } else { animeReady = false; } } else { transmission = false; rule = new AnimationRule_Novice(highlighter.animationRule.objNames); rule.gearAngle = float.Parse(CustomFunction_Transmission.speed2); rule.targetNormal = StringToVector3(CustomFunction_Transmission.surfaceNormal); GameObject gearTransmission = GameObject.Find("Transmission/Gear"); Debug.Log(gearTransmission.name); Transform[] gearsTransmission = gearTransmission.GetComponentsInChildren <Transform>(); if (SaveFunction_Novice.animationRun == true) { animeReady = true; GearSetup(rule.targetNormal, rule.gearAngle, gearsTransmission); } else { animeReady = false; GearSetup(rule.targetNormal, rule.gearAngle, gearsTransmission); } } break; } }