private void AlignObjects(AnimationRule_Authoring rule)
    {
        Transform sourceObj = GameObject.Find(rule.objNames[0]).transform;
        Transform targetObj = GameObject.Find(rule.objNames[1]).transform;

        transform.rotation = Quaternion.FromToRotation(-rule.sourceNormal, rule.targetNormal) * transform.rotation;
        transform.position = rule.targetCentroid + rule.targetNormal;
    }
 //[ExposeInEditor(RuntimeOnly = false)]
 public void ImportGearRule()
 {
     rule              = new AnimationRule_Authoring();
     rule.gearAngle    = highlighter.animationRule.gearAngle;
     rule.targetNormal = highlighter.animationRule.targetNormal;
     Transform[] gears = gameObject.GetComponentsInChildren <Transform>();
     GearSetup(rule.targetNormal, rule.gearAngle, gears);
     animeReady = true;
 }
 // Start is called before the first frame update
 void Start()
 {
     cam           = Camera.main;
     animationRule = new AnimationRule_Authoring();
     if (cam == null)
     {
         Debug.Log("camera null reference");
     }
 }
    void ImportTransmissionRule(int i)
    {
        rule = new AnimationRule_Authoring(highlighter.animationRule.objNames);
        //Create markers
        //Transform sourceObj = GameObject.Find(rule.objNames[0]).transform;
        Transform targetObj = GameObject.Find(rule.objNames[1]).transform;

        rule.targetNormal = targetObj.TransformVector(highlighter.animationRule.targetNormal);
        rule.sourceNormal = transform.TransformVector(highlighter.animationRule.sourceNormal);
        //rule.targetCentroid = targetObj.TransformPoint(highlighter.animationRule.targetCentroid);
        rule.targetCentroid = targetObj.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.sourceNormal   = StringToVector3(CustomFunction_Transmission.sourceNormal);
        rule.targetCentroid = StringToVector3(CustomFunction_Transmission.targetCentroid);
        rule.targetNormal   = 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(CustomFunction_Transmission.contactpts);

        GameObject sourceObj = GameObject.Find("TransmissionScrew");

        //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 = transform;
        marker_end.transform.parent   = transform;

        marker_contact = Instantiate(marker, targetObj.TransformPoint(rule.contactpt), Quaternion.identity);

        marker_contact.name             = "contact";
        marker_contact.transform.parent = targetObj;

        AlignObjects(rule);
        animeReady = true;
    }
    // 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_Authoring.animationName))
                {
                    CustomFunction_Screw_Nut_Interaction = CustomFunctions_Screw_Nut_Interaction.functions[i];
                }
            }

            rule = new AnimationRule_Authoring(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_Authoring.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_Authoring.animationName))
                {
                    CustomFunction_Gear = CustomFunctions_Gear.functions[i];
                }
            }

            rule              = new AnimationRule_Authoring();
            rule.gearAngle    = float.Parse(CustomFunction_Gear.speed);
            rule.targetNormal = StringToVector3(CustomFunction_Gear.surfaceNormal);
            Transform[] gears = GameObject.Find("Gear").GetComponentsInChildren <Transform>();
            if (SaveFunction_Authoring.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_Authoring.animationName))
                {
                    CustomFunction_BeltandPulley = CustomFunctions_BeltandPulley.functions[i];
                }
            }
            rule_BeltandPulley = new AnimationRule_BeltandPulley(highlighter.animationRule.objNames);
            //Create markers
            rule_BeltandPulley.surfaceNormal = StringToVector3(CustomFunction_BeltandPulley.surfaceNormal);
            if (SaveFunction_Authoring.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_Authoring.animationName))
                {
                    CustomFunction_Transmission = CustomFunctions_Transmission.functions[i];
                }
            }
            for (int i = 0; i < 6; i++)
            {
                ImportTransmissionRule(i);
            }
            if (SaveFunction_Authoring.animationRun == true)
            {
                animeReady = true;
            }
            else
            {
                animeReady = false;
            }
            break;
        }
    }