ConstraintStatus AddConstraint(string boneToConstrain, string sourceBone, float weight, Axis freeze)
    {
        var  transform = GameObject.Find(boneToConstrain);
        bool catsUsed  = false;

        if (transform == null)
        {
            transform = GameObject.Find(boneToConstrain.Replace(".", "_"));
            catsUsed  = true;
        }

        if (transform == null)
        {
            EditorUtility.DisplayDialog("Error Twist bone not found!", "The twist bone: " + boneToConstrain + " Could not be found!", "ok");
            return(ConstraintStatus.Error);
        }
        var bone = transform.gameObject;

        if (bone == null)
        {
            EditorUtility.DisplayDialog("Error Twist bone not found!", "The twist bone: " + boneToConstrain + " Could not be found!", "ok");
            return(ConstraintStatus.Error);
        }

        RotationConstraint rc = bone.AddComponent(typeof(RotationConstraint)) as RotationConstraint;

        if (rc != null)
        {
            rc.weight       = weight;
            rc.rotationAxis = freeze;
            var sourceTransform = GameObject.Find(sourceBone).transform;
            var source          = new ConstraintSource();
            source.sourceTransform = sourceTransform;
            source.weight          = 1;
            rc.AddSource(source);
            rc.locked           = false;
            rc.constraintActive = true;
            newConstraints.Add(rc);
            if (catsUsed)
            {
                return(ConstraintStatus.Success);
            }
            else
            {
                return(ConstraintStatus.CATSUsedSuccess);
            }
        }
        else
        {
            Debug.LogWarning("Rotation constraint probably already setup for: " + boneToConstrain);
            return(ConstraintStatus.Warning);
        }
    }
Ejemplo n.º 2
0
        private void SettingConstrintProperties(RotationConstraint rotConst)
        {
            ConstraintSource constraintSource = new ConstraintSource()
            {
                sourceTransform = mainCamera.transform, weight = 1
            };

            rotConst.constraintActive = true;
            rotConst.AddSource(constraintSource);
            rotConst.rotationAxis   = Axis.None;
            rotConst.rotationAxis   = Axis.Y;
            rotConst.rotationOffset = Vector3.zero;
        }