void Awake()
    {
        for (int i = 0; i < ik_list.Length; i++)
        {
            Transform target = findRecursively(transform, ik_list[i].target);
            Transform chain  = findRecursively(transform, ik_list[i].chain);

            if (target != null && chain != null)
            {
                IKSolver2D aik = target.gameObject.AddComponent <IKSolver2D>();
                aik.EndTransform = chain;
                aik.Target       = target;
                aik.BendCCW      = ik_list[i].bendCCW;
            }
            else
            {
                if (target == null)
                {
                    Debug.Log("IKSolver2D Smoothmoves Init: Error finding target: " + ik_list[i].target);
                }
                if (chain == null)
                {
                    Debug.Log("IKSolver2D Smoothmoves Init: Error finding chain: " + ik_list[i].chain);
                }
            }
        }
    }
Пример #2
0
    static void OnDrawSceneView(SceneView current)
    {
        IKSolver2D IK = null;

        if (Selection.activeGameObject != null)
        {
            IK = Selection.activeGameObject.GetComponentInChildren <IKSolver2D>();
            if (IK == null)
            {
                IK = Selection.activeGameObject.GetComponent <IKSolver2D>();
            }
        }
        if (IK != null)
        {
            float     boneLenght = 0f;
            Transform chain      = IK.EndTransform == null?IK.transform:IK.EndTransform;
            if (chain.parent != null)
            {
                DrawBone(chain.parent.position, chain.position, IK.GetWorldNormalToPlane());
            }
            if (chain.parent != null && chain.parent.parent != null)
            {
                boneLenght = DrawBone(chain.parent.parent.position, chain.parent.position, IK.GetWorldNormalToPlane());
            }

            if (IK.Target != null)
            {
                float radius = boneLenght / 10f;               //target radius is 10% of bone length
                Handles.color = Color.red;
                Handles.DrawSolidDisc(IK.Target.position, IK.GetWorldNormalToPlane(), radius);
            }
        }
    }
Пример #3
0
    public override void OnInspectorGUI()
    {
        //inspector for this fellow
        IKSolver2D IK = (IKSolver2D)target;

        //Define GUI styles for labesl
        warningStyle = new GUIStyle(EditorStyles.wordWrappedLabel);
        warningStyle.normal.textColor = new Color(1f, 0.2f, 0.2f, 1f);
        infoStyle = new GUIStyle(EditorStyles.wordWrappedLabel);
        infoStyle.normal.textColor = new Color(0.25f, 0.25f, 0.25f, 1f);


        EditorGUIUtility.LookLikeInspector();

        //description  / guide
        EditorGUILayout.LabelField("This will rotate the parents of the EndTransform in order to move it to the Target position", infoStyle);
        EditorGUILayout.Space();

        //List all the public fields, but add error messages and info
        IK.EndTransform = (Transform)EditorGUILayout.ObjectField("End Transform", IK.EndTransform, typeof(Transform), true);
        Transform endPoint = IK.EndTransform;

        if (endPoint == null)
        {
            EditorGUILayout.LabelField("If no End Transform defined we assume this GameObject is the End Transform", warningStyle);
        }
        //Default to this transform
        if (endPoint == null)
        {
            endPoint = IK.transform;
        }

        if (endPoint != null && (endPoint.parent == null || endPoint.parent.parent == null))
        {
            EditorGUILayout.LabelField("Your EndTransform must have at least two parents (2 levels deep in hierarchy)", warningStyle);
        }
        EditorGUILayout.Space();

        IK.Target = (Transform)EditorGUILayout.ObjectField("Target", IK.Target, typeof(Transform), true);
        if (IK.Target == null)
        {
            EditorGUILayout.LabelField("No target defined, you should define this here or from a script", warningStyle);
        }

        EditorGUILayout.Space();

        IK.LocalPlane2D        = (IKSolver2D.Plane2D)EditorGUILayout.EnumPopup("Local 2D Plane", IK.LocalPlane2D);
        IK.BendCCW             = EditorGUILayout.Toggle("Bend CCW", IK.BendCCW);
        IK.ClampTargetPosition = EditorGUILayout.Toggle("Clamp Target Position", IK.ClampTargetPosition);

        EditorGUILayout.Space();
    }