public override void GetVehicleBones()
    {
        base.GetVehicleBones();

        List <Transform> childrenList        = new List <Transform>();
        List <int>       childrenInstanceIds = new List <int>();

        childrenList.Add(this.transform);
        childrenInstanceIds.Add(this.transform.GetInstanceID());
        CustomVehiclesUtils.GetAllChildTransforms(this.transform, ref childrenList, ref childrenInstanceIds);

        foreach (Transform child in childrenList)
        {
            switch (child.name)
            {
            case "rotor_joint":
                if (rotor_joint1 == null)
                {
                    rotor_joint1 = child;
                }
                else
                {
                    rotor_joint2 = child;
                }
                break;

            case "back_rotor_joint":
                if (back_rotor_joint1 == null)
                {
                    back_rotor_joint1 = child;
                }
                else
                {
                    back_rotor_joint2 = child;
                }
                break;

            case "headlight":
                if (headlight_rot1 == null)
                {
                    headlight_rot1 = child;
                }
                else
                {
                    headlight_rot2 = child;
                }
                break;
            }
        }

        if (rotor_joint1 == null || back_rotor_joint1 == null || headlight_rot1 == null)
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = false;
            }
            Debug.LogError(this.ToString() + " : Some bones could not be found for set 1. Custom Helicopter will not be fully functionnal.");
        }
        else
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = true;
                DebugMsg(this.ToString() + " : All bones set 1 found.");
            }
        }

        if (rotor_joint2 == null || back_rotor_joint2 == null || headlight_rot2 == null)
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = false;
            }
            DebugMsg(this.ToString() + " : Some bones could not be found for set 2. (this is harmless)");
        }
        else
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = true;
                DebugMsg(this.ToString() + " : All bones set 2 found.");
            }
        }

        if (allBonesSet2Found)
        {
            rotor_joint      = rotor_joint2;
            back_rotor_joint = back_rotor_joint2;
            headlight_rot    = headlight_rot2;
        }
        else if (allBonesSet1Found)
        {
            rotor_joint      = rotor_joint1;
            back_rotor_joint = back_rotor_joint1;
            headlight_rot    = headlight_rot1;
        }
        else
        {
            DebugMsg("No Bones sets found, cannot initiate Helicopter.");
        }
    }
    public override void GetVehicleBones()
    {
        base.GetVehicleBones();

        List <Transform> childrenList        = new List <Transform>();
        List <int>       childrenInstanceIds = new List <int>();

        childrenList.Add(this.transform);
        childrenInstanceIds.Add(this.transform.GetInstanceID());
        CustomVehiclesUtils.GetAllChildTransforms(this.transform, ref childrenList, ref childrenInstanceIds);

        foreach (Transform child in childrenList)
        {
            switch (child.name)
            {
            case "Origin":
                if (Origin == null)
                {
                    Origin = child;
                }
                else
                {
                    Origin2 = child;
                }
                break;

            case "handlebar_joint":
                if (handlebar_joint == null)
                {
                    handlebar_joint = child;
                }
                else
                {
                    handlebar_joint2 = child;
                }
                break;

            case "chassis_joint":
                if (chassis_joint == null)
                {
                    chassis_joint = child;
                }
                else
                {
                    chassis_joint2 = child;
                }
                break;

            case "loader_joint":
                if (loader_joint == null)
                {
                    loader_joint = child;
                }
                else
                {
                    loader_joint2 = child;
                }
                break;

            case "bucket_joint":
                if (bucket_joint == null)
                {
                    bucket_joint = child;
                }
                else
                {
                    bucket_joint2 = child;
                }
                break;
            }
        }

        // Was for testing additional colliders with a custom script. May reuse later...

        /*if (Origin != null)
         * {
         *  BoxCollider bc = Origin.gameObject.GetComponent<BoxCollider>();
         *  if (bc != null)
         *  {
         *      bc.enabled = true;
         *      clc = Origin.gameObject.GetComponent<CustomLoaderControl>();
         *      if (clc == null)
         *      {
         *          DebugMsg("Adding CustomLoaderControl script.");
         *          clc = Origin.gameObject.AddComponent<CustomLoaderControl>();
         *      }
         *      clc.enabled = true;
         *  }
         * }*/

        if (handlebar_joint == null || chassis_joint == null || loader_joint == null || bucket_joint == null)
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = false;
            }
            Debug.LogError(this.ToString() + " : Some bones could not be found for set 1. Custom Car will not be fully functionnal.");
        }
        else
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = true;
                DebugMsg(this.ToString() + " : All bones set 1 found.");
            }

            lastLoaderRot = loader_joint.localRotation.eulerAngles;
            if (lastLoaderRot.x > 180)
            {
                lastLoaderRot.x -= 360;
            }
        }

        if (handlebar_joint2 == null || chassis_joint2 == null || loader_joint2 == null || bucket_joint2 == null)
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = false;
            }
            DebugMsg(this.ToString() + " : Some bones could not be found for set 2. (this is harmless)");
        }
        else
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = true;
                DebugMsg(this.ToString() + " : All bones set 2 found.");
            }

            lastLoaderRot = loader_joint2.localRotation.eulerAngles;
            if (lastLoaderRot.x > 180)
            {
                lastLoaderRot.x -= 360;
            }
        }
    }
Exemple #3
0
    public override void GetVehicleBones()
    {
        base.GetVehicleBones();

        List <Transform> childrenList        = new List <Transform>();
        List <int>       childrenInstanceIds = new List <int>();

        childrenList.Add(this.transform);
        childrenInstanceIds.Add(this.transform.GetInstanceID());
        CustomVehiclesUtils.GetAllChildTransforms(this.transform, ref childrenList, ref childrenInstanceIds);

        foreach (Transform child in childrenList)
        {
            switch (child.name)
            {
            case "handlebar_joint":
                if (handlebar_joint == null)
                {
                    handlebar_joint = child;
                }
                else
                {
                    handlebar_joint2 = child;
                }
                break;

            case "frontWheel_joint_yaw":
                if (frontWheel_joint_yaw == null)
                {
                    frontWheel_joint_yaw = child;
                }
                else
                {
                    frontWheel_joint_yaw2 = child;
                }
                break;

            case "frontWheel_joint":
                if (frontWheel_joint == null)
                {
                    frontWheel_joint = child;
                }
                else
                {
                    frontWheel_joint2 = child;
                }
                break;

            case "right_frontWheel_joint_yaw":
                if (right_frontWheel_joint_yaw == null)
                {
                    right_frontWheel_joint_yaw = child;
                }
                else
                {
                    right_frontWheel_joint_yaw2 = child;
                }
                break;

            case "right_frontWheel_joint":
                if (right_frontWheel_joint == null)
                {
                    right_frontWheel_joint = child;
                }
                else
                {
                    right_frontWheel_joint2 = child;
                }
                break;
            }
        }

        if (handlebar_joint == null || frontWheel_joint_yaw == null || frontWheel_joint == null || right_frontWheel_joint_yaw == null || right_frontWheel_joint == null)
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = false;
            }
            Debug.LogError(this.ToString() + " : Some bones could not be found for set 1. Custom Car will not be fully functionnal.");
        }
        else
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = true;
                DebugMsg(this.ToString() + " : All bones set 1 found.");
            }
        }

        if (handlebar_joint2 == null || frontWheel_joint_yaw2 == null || frontWheel_joint2 == null || right_frontWheel_joint_yaw2 == null || right_frontWheel_joint2 == null)
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = false;
            }
            DebugMsg(this.ToString() + " : Some bones could not be found for set 2. (this is harmless)");
        }
        else
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = true;
                DebugMsg(this.ToString() + " : All bones set 2 found.");
            }
        }
    }