Ejemplo n.º 1
0
    static void MakeHead(Transform _headPoint, Transform _chestPoint, Vector3 _headTop)
    {
        float headScale = Vector3.Distance(_chestPoint.position, _headPoint.position) * .01f;


        Selection.activeObject = GameObject.Find("Spine_05");

        Puppet2D_BoneCreation.CreateBoneTool();
        Puppet2D_BoneCreation.BoneCreationMode(_headPoint.position);
        Puppet2D_BoneCreation.BoneCreationMode(_headTop);

        Puppet2D_BoneCreation.BoneFinishCreation();
        GameObject head = GameObject.Find("bone_1");

        head.name = "Head";
        Selection.activeGameObject = head;
        GameObject headEnd = GameObject.Find("bone_2");

        headEnd.name = "HeadEnd";

        Puppet2D_CreateControls.CreateOrientControl();
        GameObject headControl = GameObject.Find("Head_CTRL");

        headControl.GetComponent <Puppet2D_ParentControl>().ConstrianedPosition = true;
        GameObject headControlParent = GameObject.Find("Head_CTRL_GRP");

        headControlParent.transform.localScale = Vector3.one * headScale * 2f;
        //GameObject.Find ("bone_22").name = ("a");
    }
Ejemplo n.º 2
0
    public static void CreateSplineTool()
    {
        Puppet2D_Editor.SplineCreation = true;

        SplineCreationGroup = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("spline_GRP"));
        Undo.RegisterCreatedObjectUndo(SplineCreationGroup, "undo create Spline");
        splineStoreData = SplineCreationGroup.AddComponent <Puppet2D_FFDStoreData>();
    }
Ejemplo n.º 3
0
    static void MakeClav(GameObject parentTo, string boneName)
    {
        Selection.activeObject = parentTo;
        Puppet2D_BoneCreation.CreateBoneTool();
        Puppet2D_BoneCreation.BoneCreationMode(parentTo.transform.position + Vector3.one * .1f);
        Puppet2D_BoneCreation.BoneFinishCreation();
        GameObject clav = GameObject.Find("bone_1");

        clav.name = boneName;
    }
Ejemplo n.º 4
0
    public static void FFDCreationMode(Vector3 mousePos)
    {
        string newCtrlName    = "FFD_CTRL";
        string newCtrlGRPName = "FFD_CTRL_GRP";

        if (Puppet2D_Editor.FFDGameObject)
        {
            newCtrlName    = Puppet2D_Editor.FFDGameObject.name + "_Ctrl";
            newCtrlGRPName = Puppet2D_Editor.FFDGameObject.name + "_Ctrl_GRP";
        }

        GameObject newCtrl    = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName(newCtrlName));
        GameObject newCtrlGRP = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName(newCtrlGRPName));

        newCtrl.transform.parent = newCtrlGRP.transform;

        Undo.RegisterCreatedObjectUndo(newCtrl, "Created newCtrl");
        Undo.RegisterCreatedObjectUndo(newCtrlGRP, "Created newCtrlGRP");

        Undo.RecordObject(ffdStoreData, "Adding FFD Control");
        ffdStoreData.FFDCtrls.Add(newCtrl.transform);


        Puppet2D_FFDLineDisplay ffdline = newCtrl.AddComponent <Puppet2D_FFDLineDisplay>();

        ffdline.vertNumber = ffdStoreData.FFDCtrls.Count - 1;
        if (ffdStoreData.FFDCtrls.Count > 1)
        {
            if (ffdStoreData.FFDPathNumber.Count > 0)
            {
                if (ffdStoreData.FFDCtrls.Count - 1 > ffdStoreData.FFDPathNumber[ffdStoreData.FFDPathNumber.Count - 1])
                {
                    ffdline.target = ffdStoreData.FFDCtrls[ffdStoreData.FFDCtrls.Count - 2];
                }
            }
            else
            {
                ffdline.target = ffdStoreData.FFDCtrls[ffdStoreData.FFDCtrls.Count - 2];
            }
        }



        newCtrlGRP.transform.position = new Vector3(mousePos.x, mousePos.y, 0);

        SpriteRenderer spriteRenderer = newCtrl.AddComponent <SpriteRenderer>();

        spriteRenderer.sortingLayerName = Puppet2D_Editor._controlSortingLayer;
        string path = (Puppet2D_Editor._puppet2DPath + "/Textures/GUI/ffdBone.psd");

        Sprite sprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;

        spriteRenderer.sprite           = sprite;
        spriteRenderer.sortingLayerName = Puppet2D_Editor._controlSortingLayer;
    }
Ejemplo n.º 5
0
    static void CreateSpline()
    {
        if (splineStoreData.FFDCtrls.Count > 2 && splineStoreData.FFDCtrls[0] && splineStoreData.FFDCtrls[1] && splineStoreData.FFDCtrls[2])
        {
            GameObject tangentCtrl = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("spline_Tangent"));
            Undo.RegisterCreatedObjectUndo(tangentCtrl, "Created splineTangent");
            splineStoreData.FFDCtrls.Add(tangentCtrl.transform);
            tangentCtrl.transform.parent        = splineStoreData.FFDCtrls[splineStoreData.FFDCtrls.Count - 2].transform;
            tangentCtrl.transform.localPosition = Vector3.zero;
            SpriteRenderer spriteRenderer = splineStoreData.FFDCtrls[splineStoreData.FFDCtrls.Count - 2].GetComponent <SpriteRenderer>();
            string         path           = (Puppet2D_Editor._puppet2DPath + "/Textures/GUI/splineControl.psd");
            Sprite         sprite         = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;
            spriteRenderer.sprite = sprite;

            splineStoreData.FFDCtrls[1].position += splineStoreData.FFDCtrls[0].position - splineStoreData.FFDCtrls[2].position;

            splineStoreData.FFDCtrls[splineStoreData.FFDCtrls.Count - 1].position += splineStoreData.FFDCtrls[splineStoreData.FFDCtrls.Count - 2].position - splineStoreData.FFDCtrls[splineStoreData.FFDCtrls.Count - 3].position;

            Transform splineCtrlSwap = splineStoreData.FFDCtrls[0];
            splineStoreData.FFDCtrls[0] = splineStoreData.FFDCtrls[1];
            splineStoreData.FFDCtrls[1] = splineCtrlSwap;

            //GameObject OffsetGroup = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("spline_GRP"));
            Puppet2D_SplineControl spline = SplineCreationGroup.AddComponent <Puppet2D_SplineControl>();

            spline._splineCTRLS.AddRange(splineStoreData.FFDCtrls);
            spline.numberBones = Puppet2D_Editor.numberSplineJoints;
            List <GameObject> splineBones = spline.Create();
            foreach (GameObject splineBone in splineBones)
            {
                splineBone.GetComponent <SpriteRenderer>().sortingLayerName = Puppet2D_Editor._boneSortingLayer;
            }
            foreach (Transform ctrl in splineStoreData.FFDCtrls)
            {
                if (!ctrl.parent.parent)
                {
                    ctrl.parent.parent = SplineCreationGroup.transform;
                }
            }
            GameObject globalCtrl = Puppet2D_CreateControls.CreateGlobalControl();
            globalCtrl.GetComponent <Puppet2D_GlobalControl>()._SplineControls.Add(spline);
            SplineCreationGroup.transform.parent = globalCtrl.transform;

            globalCtrl.GetComponent <Puppet2D_GlobalControl>().Run();

            Undo.DestroyObjectImmediate(splineStoreData);

            splineStoreData.FFDCtrls.Clear();
        }
    }
 public static void FFDSetFirstPath()
 {
     FFDControlsGrp = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("FFD_Ctrls_GRP"));
     Undo.RegisterCreatedObjectUndo(FFDControlsGrp, "undo create FFD");
     ffdStoreData = FFDControlsGrp.AddComponent <Puppet2D_FFDStoreData>();
     if ((Puppet2D_Editor.FFDGameObject != null) && Puppet2D_Editor.FFDGameObject.GetComponent <PolygonCollider2D>())
     {
         Vector2[] firstPath = Puppet2D_Editor.FFDGameObject.GetComponent <PolygonCollider2D>().GetPath(0);
         foreach (Vector2 pos in firstPath)
         {
             FFDCreationMode(pos);
         }
         CloseFFDPath();
     }
 }
Ejemplo n.º 7
0
    static void MakeLimb(Transform _thighLPoint, Transform _footLPoint, Transform _kneePoint, Vector3 FootEnd, GameObject parentTo, string controlName, string controlName3, string controlName2, string controlName1, bool flip = false)
    {
        Selection.activeObject = parentTo;

        float   limbScale     = Vector3.Distance(_footLPoint.position, _thighLPoint.position) * .01f;
        Vector3 scaledFootPos = (_footLPoint.position - _thighLPoint.position) / limbScale;

        scaledFootPos += _thighLPoint.position;

        Vector3 scaledKneePos = (_kneePoint.position - _thighLPoint.position) / limbScale;

        scaledKneePos += _thighLPoint.position;

        Puppet2D_BoneCreation.CreateBoneTool();
        Puppet2D_BoneCreation.BoneCreationMode(_thighLPoint.position);

        Puppet2D_BoneCreation.BoneCreationMode(scaledKneePos);
        GameObject endLimbGO = Puppet2D_BoneCreation.BoneCreationMode(scaledFootPos);

        Vector3 scaledFinalEndLimbGO = (FootEnd - _thighLPoint.position) / limbScale;

        scaledFinalEndLimbGO += _thighLPoint.position;

        GameObject finalEndLimbGO = Puppet2D_BoneCreation.BoneCreationMode(scaledFinalEndLimbGO);

        finalEndLimbGO.name = (controlName1 + "End");

        Puppet2D_BoneCreation.BoneFinishCreation();

        Selection.activeGameObject = endLimbGO;
        endLimbGO.name             = controlName1;
        Puppet2D_CreateControls.IKCreateTool(true);
        GameObject limbControlParent = GameObject.Find(controlName1 + "_CTRL_GRP");

        Transform elbow        = endLimbGO.transform.parent;
        Transform shoulderBone = endLimbGO.transform.parent.parent;

        elbow.name        = (controlName2);
        shoulderBone.name = (controlName3);

        Transform limbParent = limbControlParent.transform.parent;

        limbControlParent.transform.parent = shoulderBone;
        shoulderBone.localScale            = shoulderBone.localScale * limbScale;
        limbControlParent.transform.parent = limbParent;
        GameObject.Find(controlName1 + "_CTRL").GetComponent <Puppet2D_IKHandle> ().Flip = flip;
    }
Ejemplo n.º 8
0
    public static void SplineCreationMode(Vector3 mousePos)
    {
        GameObject newCtrl = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("spline_Ctrl"));

        Undo.RegisterCreatedObjectUndo(newCtrl, "Created newCtrl");
        GameObject newCtrlGrp = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("spline_Ctrl_GRP"));

        Undo.RegisterCreatedObjectUndo(newCtrlGrp, "Created newCtrlGrp");
        newCtrl.transform.parent = newCtrlGrp.transform;

        Undo.RecordObject(splineStoreData, "Adding To Spline Control");

        splineStoreData.FFDCtrls.Add(newCtrl.transform);


        // start and end
        if (splineStoreData.FFDCtrls.Count == 1)
        {
            GameObject tangentCtrl = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("spline_Tangent"));
            Undo.RegisterCreatedObjectUndo(tangentCtrl, "Created splineTangent");
            splineStoreData.FFDCtrls.Add(tangentCtrl.transform);
            tangentCtrl.transform.parent = splineStoreData.FFDCtrls[0].transform;
        }



        newCtrlGrp.transform.position = mousePos;
        newCtrlGrp.transform.position = new Vector3(newCtrlGrp.transform.position.x, newCtrlGrp.transform.position.y, 0);

        SpriteRenderer spriteRenderer = newCtrl.AddComponent <SpriteRenderer>();

        spriteRenderer.sortingLayerName = Puppet2D_Editor._controlSortingLayer;
        string path = (Puppet2D_Editor._puppet2DPath + "/Textures/GUI/splineMiddleControl.psd");

        if (splineStoreData.FFDCtrls.Count == 2)
        {
            path = (Puppet2D_Editor._puppet2DPath + "/Textures/GUI/splineControl.psd");
        }

        Sprite sprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;

        spriteRenderer.sprite = sprite;
    }
Ejemplo n.º 9
0
    void OnGUI()
    {
        string path  = ("Assets/Puppet2D/Textures/GUI/BoneNoJoint.psd");
        string path2 = ("Assets/Puppet2D/Textures/GUI/BoneScaled.psd");
        string path3 = ("Assets/Puppet2D/Textures/GUI/BoneJoint.psd");
        string path4 = ("Assets/Puppet2D/Textures/GUI/Bone.psd");

        boneNoJointSprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;
        boneSprite        = AssetDatabase.LoadAssetAtPath(path2, typeof(Sprite)) as Sprite;
        boneHiddenSprite  = AssetDatabase.LoadAssetAtPath(path3, typeof(Sprite)) as Sprite;
        boneOriginal      = AssetDatabase.LoadAssetAtPath(path4, typeof(Sprite)) as Sprite;
        Texture aTexture         = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/GUI_Bones.png", typeof(Texture)) as Texture;
        Texture puppetManTexture = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/GUI_puppetman.png", typeof(Texture)) as Texture;
        Texture rigTexture       = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/GUI_Rig.png", typeof(Texture)) as Texture;
        Texture ControlTexture   = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/parentControl.psd", typeof(Texture)) as Texture;
        Texture VertexTexture    = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/VertexHandle.psd", typeof(Texture)) as Texture;


        string[] sortingLayers = GetSortingLayerNames();
        Color    bgColor       = GUI.backgroundColor;

        if (currentGUIChoice == GUIChoice.BoneCreation)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(0, 0, 80, 20), "Skeleton"))
        {
            currentGUIChoice = GUIChoice.BoneCreation;
        }

        GUI.backgroundColor = bgColor;
        if (currentGUIChoice == GUIChoice.RigginSetup)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(80, 0, 80, 20), "Rigging"))
        {
            currentGUIChoice = GUIChoice.RigginSetup;
        }
        GUI.backgroundColor = bgColor;
        if (currentGUIChoice == GUIChoice.Skinning)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(160, 0, 80, 20), "Skinning"))
        {
            currentGUIChoice = GUIChoice.Skinning;
        }
        GUI.backgroundColor = bgColor;
        if (currentGUIChoice == GUIChoice.Animation)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(240, 0, 80, 20), "Animation"))
        {
            currentGUIChoice = GUIChoice.Animation;
        }
        GUI.backgroundColor = bgColor;

        if (EditSkinWeights || SplineCreation || FFDCreation)
        {
            GUI.backgroundColor = Color.grey;
        }


        GUI.DrawTexture(new Rect(25, 40, 32, 32), boneSprite.texture, ScaleMode.StretchToFill, true, 10.0F);

        EditorGUI.BeginChangeCheck();
        BoneSize = EditorGUI.Slider(new Rect(80, 40, 150, 20), BoneSize, 0F, 0.9999F);
        if (EditorGUI.EndChangeCheck())
        {
            ChangeBoneSize();
            EditorPrefs.SetFloat("Puppet2D_EditorBoneSize", BoneSize);
        }
        EditorGUI.BeginChangeCheck();
        _boneSortingIndex = EditorGUI.Popup(new Rect(80, 60, 150, 30), _boneSortingIndex, sortingLayers);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetInt("Puppet2D_BoneLayer", _boneSortingIndex);
        }
        if (sortingLayers.Length <= _boneSortingIndex)
        {
            _boneSortingIndex = 0;
            EditorPrefs.SetInt("Puppet2D_BoneLayer", _boneSortingIndex);
        }
        _boneSortingLayer = sortingLayers[_boneSortingIndex];


        GUI.DrawTexture(new Rect(25, 100, 32, 32), ControlTexture, ScaleMode.StretchToFill, true, 10.0F);

        EditorGUI.BeginChangeCheck();
        ControlSize = EditorGUI.Slider(new Rect(80, 100, 150, 20), ControlSize, 0F, .9999F);
        if (EditorGUI.EndChangeCheck())
        {
            ChangeControlSize();
            EditorPrefs.SetFloat("Puppet2D_EditorControlSize", ControlSize);
        }
        EditorGUI.BeginChangeCheck();
        _controlSortingIndex = EditorGUI.Popup(new Rect(80, 130, 150, 30), _controlSortingIndex, sortingLayers);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetInt("Puppet2D_ControlLayer", _controlSortingIndex);
        }
        if (sortingLayers.Length <= _controlSortingIndex)
        {
            _controlSortingIndex = 0;
            EditorPrefs.SetInt("Puppet2D_ControlLayer", _controlSortingIndex);
        }
        _controlSortingLayer = sortingLayers[_controlSortingIndex];


        GUI.DrawTexture(new Rect(15, 160, 275, 5), aTexture, ScaleMode.StretchToFill, true, 10.0F);

        int offsetControls = 130;

        if (currentGUIChoice == GUIChoice.BoneCreation)
        {
            //GUILayout.Label("Bone Creation", EditorStyles.boldLabel);

            GUILayout.Space(15);
            GUI.DrawTexture(new Rect(0, 60 + offsetControls, 64, 128), aTexture, ScaleMode.StretchToFill, true, 10.0F);
            GUILayout.Space(15);


            if (BoneCreation)
            {
                GUI.backgroundColor = Color.green;
            }


            if (GUI.Button(new Rect(80, 60 + offsetControls, 150, 30), "Create Bone Tool"))
            {
                BoneCreation      = true;
                currentActiveBone = null;
                EditorPrefs.SetBool("Puppet2D_BoneCreation", BoneCreation);
            }
            if (BoneCreation)
            {
                GUI.backgroundColor = bgColor;
            }


            if (GUI.Button(new Rect(80, 90 + offsetControls, 150, 30), "Finish Bone"))
            {
                Puppet2D_BoneCreation.BoneFinishCreation();
            }

            if (BoneCreation)
            {
                GUI.backgroundColor = Color.grey;
            }



            if (SplineCreation)
            {
                GUI.backgroundColor = Color.green;
            }
            if (GUI.Button(new Rect(80, 150 + offsetControls, 150, 30), "Create Spline Tool"))
            {
                //Puppet2D_Spline.splineStoreData.FFDCtrls.Clear();
                //SplineCreation = true;
                Puppet2D_Spline.CreateSplineTool();
            }
            if (SplineCreation)
            {
                GUI.backgroundColor = bgColor;
            }
            numberSplineJoints = EditorGUI.IntSlider(new Rect(80, 190 + offsetControls, 150, 20), numberSplineJoints, 1, 10);

            if (GUI.Button(new Rect(80, 220 + offsetControls, 150, 30), "Finish Spline"))
            {
                Puppet2D_Spline.SplineFinishCreation();
            }
        }
        if (currentGUIChoice == GUIChoice.RigginSetup)
        {
            // GUILayout.Label("Rigging Setup", EditorStyles.boldLabel);

            GUI.DrawTexture(new Rect(0, 60 + offsetControls, 64, 128), rigTexture, ScaleMode.StretchToFill, true, 10.0F);
            if (GUI.Button(new Rect(80, 60 + offsetControls, 150, 30), "Create IK Control"))
            {
                Puppet2D_CreateControls.IKCreateTool();
            }
            if (GUI.Button(new Rect(80, 90 + offsetControls, 150, 30), "Create Parent Control"))
            {
                Puppet2D_CreateControls.CreateParentControl();
            }
            if (GUI.Button(new Rect(80, 120 + offsetControls, 150, 30), "Create Orient Control"))
            {
                Puppet2D_CreateControls.CreateOrientControl();
            }

            /*if (GUI.Button(new Rect(80, 160+offsetControls, 150, 30), "Create Avatar"))
             * {
             * Puppet2D_CreateControls.CreateAvatar();
             *
             * }*/
        }
        if (currentGUIChoice == GUIChoice.Skinning)
        {
            //GUILayout.Label("Skinning", EditorStyles.boldLabel);

            GUI.DrawTexture(new Rect(0, 50 + offsetControls, 64, 128), puppetManTexture, ScaleMode.StretchToFill, true, 10.0F);

            GUILayout.Space(55 + offsetControls);
            GUIStyle labelNew = EditorStyles.label;
            labelNew.alignment     = TextAnchor.LowerLeft;
            labelNew.contentOffset = new Vector2(80, 0);
            GUILayout.Label("Type of Mesh: ", labelNew);
            labelNew.contentOffset = new Vector2(0, 0);
            string[] TriangulationTypes = { "0", "1", "2", "3" };

            _triangulationIndex = EditorGUI.Popup(new Rect(180, 60 + offsetControls, 50, 30), _triangulationIndex, TriangulationTypes);


            if (GUI.Button(new Rect(80, 80 + offsetControls, 150, 30), "Convert Sprite To Mesh"))
            {
                Puppet2D_Skinning.ConvertSpriteToMesh(_triangulationIndex);
            }
            if (GUI.Button(new Rect(80, 110 + offsetControls, 150, 30), "Parent Object To Bones"))
            {
                Puppet2D_Skinning.BindRigidSkin();
            }
            GUILayout.Space(75);
            labelNew.alignment     = TextAnchor.LowerLeft;
            labelNew.contentOffset = new Vector2(80, 0);
            GUILayout.Label("Num Skin Bones: ", labelNew);
            labelNew.contentOffset = new Vector2(0, 0);
            string[] NumberBonesToSkinTo = { "1", "2", "4 (FFD)" };

            _numberBonesToSkinToIndex = EditorGUI.Popup(new Rect(180, 150 + offsetControls, 50, 30), _numberBonesToSkinToIndex, NumberBonesToSkinTo);

            if (GUI.Button(new Rect(80, 170 + offsetControls, 150, 30), "Bind Smooth Skin"))
            {
                Puppet2D_Skinning.BindSmoothSkin();
            }
            if (EditSkinWeights || SkinWeightsPaint)
            {
                GUI.backgroundColor = Color.green;
            }
            if (SkinWeightsPaint)
            {
                if (GUI.Button(new Rect(80, 200 + offsetControls, 150, 30), "Manually Edit Weights"))
                {
                    // finish paint weights
                    Selection.activeGameObject = currentSelection;
                    if (currentSelection)
                    {
                        if (previousShader)
                        {
                            currentSelection.GetComponent <Renderer>().sharedMaterial.shader = previousShader;
                        }
                        SkinWeightsPaint = false;
                        if (previousVertColors != null && previousVertColors.Length > 0)
                        {
                            currentSelectionMesh.colors = previousVertColors;
                        }
                        currentSelectionMesh = null;
                        currentSelection     = null;
                        previousVertColors   = null;
                    }

                    EditSkinWeights = Puppet2D_Skinning.EditWeights();
                }
            }
            if (!SkinWeightsPaint)
            {
                if (GUI.Button(new Rect(80, 200 + offsetControls, 150, 30), "Paint Weights"))
                {
                    if (EditSkinWeights)
                    {
                        EditSkinWeights = false;
                        Object[] bakedMeshes = Puppet2D_Skinning.FinishEditingWeights();

                        Selection.objects = bakedMeshes;
                    }

                    if (Selection.activeGameObject && Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>() && Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>().sharedMesh)
                    {
                        SkinWeightsPaint = true;
                        SkinnedMeshRenderer smr = Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>();
                        currentSelectionMesh = smr.sharedMesh;
                        currentSelection     = Selection.activeGameObject;
                        previousShader       = currentSelection.GetComponent <Renderer>().sharedMaterial.shader;
                        currentSelection.GetComponent <Renderer>().sharedMaterial.shader = Shader.Find("Puppet2D/vertColor");

                        if (currentSelectionMesh.colors.Length != currentSelectionMesh.vertices.Length)
                        {
                            currentSelectionMesh.colors = new Color[currentSelectionMesh.vertices.Length];
                            EditorUtility.SetDirty(currentSelection);
                            EditorUtility.SetDirty(currentSelectionMesh);
                            AssetDatabase.SaveAssets();
                            EditorApplication.SaveAssets();
                        }
                        else
                        {
                            previousVertColors = currentSelectionMesh.colors;
                        }
                        Selection.activeGameObject = smr.bones[0].gameObject;
                    }
                }
            }



            if (EditSkinWeights || SkinWeightsPaint)
            {
                GUI.backgroundColor = bgColor;
            }

            if (GUI.Button(new Rect(80, 230 + offsetControls, 150, 30), "Finish Edit Skin Weights"))
            {
                if (SkinWeightsPaint)
                {
                    if (currentSelection)
                    {
                        Selection.activeGameObject = currentSelection;

                        if (previousShader)
                        {
                            currentSelection.GetComponent <Renderer>().sharedMaterial.shader = previousShader;
                        }
                        SkinWeightsPaint = false;
                        if (previousVertColors != null && previousVertColors.Length > 0)
                        {
                            currentSelectionMesh.colors = previousVertColors;
                        }
                        currentSelectionMesh = null;
                        currentSelection     = null;
                        previousVertColors   = null;

                        Puppet2D_HiddenBone[] hiddenBones = Transform.FindObjectsOfType <Puppet2D_HiddenBone>();
                        foreach (Puppet2D_HiddenBone hiddenBone in hiddenBones)
                        {
                            hiddenBone.gameObject.GetComponent <SpriteRenderer>().color = Color.white;
                            if (hiddenBone.transform.parent != null)
                            {
                                hiddenBone.transform.parent.GetComponent <SpriteRenderer>().color = Color.white;
                            }
                        }
                    }
                    else
                    {
                        SkinWeightsPaint = false;
                    }
                }
                else
                {
                    EditSkinWeights = false;
                    Puppet2D_Skinning.FinishEditingWeights();
                }
            }
            float SkinWeightsPaintOffset = -80;

            if (EditSkinWeights)
            {
                SkinWeightsPaintOffset = -40;
                GUI.DrawTexture(new Rect(25, 260 + offsetControls, 32, 32), VertexTexture, ScaleMode.StretchToFill, true, 10.0F);
                EditorGUI.BeginChangeCheck();
                VertexHandleSize = EditorGUI.Slider(new Rect(80, 270 + offsetControls, 150, 20), VertexHandleSize, 0F, .9999F);
                if (EditorGUI.EndChangeCheck())
                {
                    ChangeVertexHandleSize();
                    EditorPrefs.SetFloat("Puppet2D_EditorVertexHandleSize", VertexHandleSize);
                }
            }
            if (SkinWeightsPaint)
            {
                SkinWeightsPaintOffset = -20;

                GUILayout.Space(offsetControls - 20);
                GUILayout.Label(" Brush Size", EditorStyles.boldLabel);
                EditSkinWeightRadius = EditorGUI.Slider(new Rect(80, 275 + offsetControls, 150, 20), EditSkinWeightRadius, 0F, 100F);
                GUILayout.Label(" Strength", EditorStyles.boldLabel);
                paintWeightsStrength = EditorGUI.Slider(new Rect(80, 295 + offsetControls, 150, 20), paintWeightsStrength, 0F, 1F);
            }

            if (EditSkinWeights || SkinWeightsPaint)
            {
                GUI.backgroundColor = Color.grey;
            }

            if (FFDCreation)
            {
                GUI.backgroundColor = Color.green;
            }

            if (GUI.Button(new Rect(80, 360 + offsetControls + SkinWeightsPaintOffset, 150, 30), "Create FFD Tool"))
            {
                if (!FFDCreation)
                {
                    FFDCreation = true;
                    if (Selection.activeGameObject && Selection.activeGameObject.GetComponent <SpriteRenderer>() && Selection.activeGameObject.GetComponent <SpriteRenderer>().sprite&& !Selection.activeGameObject.GetComponent <SpriteRenderer>().sprite.name.Contains("bone"))
                    {
                        FFDGameObject = Selection.activeGameObject;
                    }
                    else
                    {
                        Debug.LogWarning("Need to select a sprite to make an FFD mesh, will create a dummy mesh instead");
                    }
                    Puppet2D_FFD.FFDSetFirstPath();
                }
            }
            if (FFDCreation)
            {
                GUI.backgroundColor = bgColor;
            }
            if (GUI.Button(new Rect(80, 390 + offsetControls + SkinWeightsPaintOffset, 150, 30), "Finish FFD"))
            {
                Puppet2D_FFD.FFDFinishCreation();
            }
        }
        if (currentGUIChoice == GUIChoice.Animation)
        {
            //GUILayout.Label("Animation", EditorStyles.boldLabel);

            if (GUI.Button(new Rect(80, 50 + offsetControls, 150, 30), "Bake Animation"))
            {
                Puppet2D_GlobalControl[] globalCtrlScripts = Transform.FindObjectsOfType <Puppet2D_GlobalControl>();
                for (int i = 0; i < globalCtrlScripts.Length; i++)
                {
                    Puppet2D_BakeAnimation BakeAnim = globalCtrlScripts[i].gameObject.AddComponent <Puppet2D_BakeAnimation>();
                    BakeAnim.Run();
                    DestroyImmediate(BakeAnim);
                    globalCtrlScripts[i].enabled = false;
                }
            }
            if (recordPngSequence && !ExportPngAlpha)
            {
                GUI.backgroundColor = Color.green;
            }
            if (GUI.Button(new Rect(80, 100 + offsetControls, 150, 30), "Render Animation"))
            {
                checkPath = EditorUtility.SaveFilePanel("Choose Directory", pngSequPath, "exportedAnim", "");
                if (checkPath != "")
                {
                    pngSequPath       = checkPath;
                    recordPngSequence = true;
                    EditorApplication.ExecuteMenuItem("Edit/Play");
                }
            }
            GUI.backgroundColor = bgColor;
            if (ExportPngAlpha)
            {
                GUI.backgroundColor = Color.green;
            }
            if (GUI.Button(new Rect(80, 130 + offsetControls, 150, 30), "Render Alpha"))
            {
                checkPath = EditorUtility.SaveFilePanel("Choose Directory", pngSequPath, "exportedAnim", "");
                if (checkPath != "")
                {
                    pngSequPath       = checkPath;
                    recordPngSequence = true;
                    ExportPngAlpha    = true;
                    EditorApplication.ExecuteMenuItem("Edit/Play");
                }
            }
            if (ExportPngAlpha || recordPngSequence)
            {
                GUI.backgroundColor = bgColor;
            }
            if (GUI.Button(new Rect(80, 200 + offsetControls, 150, 30), "Save Selection"))
            {
                selectedControls.Add(new List <string>());
                selectedControlsData.Add(new List <string>());

                foreach (GameObject go in Selection.gameObjects)
                {
                    selectedControls[selectedControls.Count - 1].Add(Puppet2D_Selection.GetGameObjectPath(go));
                    selectedControlsData[selectedControlsData.Count - 1].Add(go.transform.localPosition.x + " " + go.transform.localPosition.y + " " + go.transform.localPosition.z + " " + go.transform.localRotation.x + " " + go.transform.localRotation.y + " " + go.transform.localRotation.z + " " + go.transform.localRotation.w + " " + go.transform.localScale.x + " " + go.transform.localScale.y + " " + go.transform.localScale.z + " ");
                }
                Puppet2D_Selection.SetSelectionString();
            }
            if (GUI.Button(new Rect(80, 230 + offsetControls, 150, 30), "Clear Selections"))
            {
                selectedControls.Clear();
                selectedControlsData.Clear();
                Puppet2D_Selection.SetSelectionString();
            }


            for (int i = 0; i < selectedControls.Count; i++)
            {
                int column = i % 3;
                int row    = 0;

                row = i / 3;
                Rect newLoadButtonPosition = new Rect(80 + (50 * column), 265 + offsetControls + row * 30, 50, 30);

                if (Event.current.type == EventType.ContextClick)
                {
                    Vector2 mousePos = Event.current.mousePosition;
                    if ((Event.current.button == 1) && newLoadButtonPosition.Contains(mousePos))
                    {
                        GenericMenu menu = new GenericMenu();

                        menu.AddItem(new GUIContent("Select Objects"), false, Puppet2D_Selection.SaveSelectionLoad, i);
                        menu.AddItem(new GUIContent("Remove Selection"), false, Puppet2D_Selection.SaveSelectionRemove, i);
                        menu.AddItem(new GUIContent("Append Selection"), false, Puppet2D_Selection.SaveSelectionAppend, i);
                        menu.AddItem(new GUIContent("Store Pose"), false, Puppet2D_Selection.StorePose, i);
                        menu.AddItem(new GUIContent("Load Pose"), false, Puppet2D_Selection.LoadPose, i);



                        menu.ShowAsContext();
                        Event.current.Use();
                    }
                }
                GUI.Box(newLoadButtonPosition, "Load");

                /*if (GUI.Button(newLoadButtonPosition, "Load"))
                 * {
                 *  Selection.objects = selectedControls[i].ToArray();
                 * }*/
            }
        }
    }
Ejemplo n.º 10
0
    void OnSceneGUI(SceneView sceneView)
    {
        Event e = Event.current;

        switch (e.type)
        {
        case EventType.keyDown:
        {
            if (Event.current.keyCode == (KeyCode.Return))
            {
                if (BoneCreation)
                {
                    Puppet2D_BoneCreation.BoneFinishCreation();
                }
                if (SplineCreation)
                {
                    Puppet2D_Spline.SplineFinishCreation();
                }
                if (FFDCreation)
                {
                    FFDCreation = false;
                    Puppet2D_FFD.FFDFinishCreation();
                }
                Repaint();
            }
            if (Event.current.keyCode == (KeyCode.KeypadPlus) && SkinWeightsPaint)
            {
                EditSkinWeightRadius += 0.2f;
            }
            if (Event.current.keyCode == (KeyCode.KeypadMinus) && SkinWeightsPaint)
            {
                EditSkinWeightRadius -= 0.2f;
            }
            if (BoneCreation)
            {
                if (Event.current.keyCode == (KeyCode.Backspace))
                {
                    Puppet2D_BoneCreation.BoneDeleteMode();
                }
            }
            if (SkinWeightsPaint)
            {
                if (Event.current.keyCode == (KeyCode.N))
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    if (!ChangingRadius)
                    {
                        ChangeRadiusStartPosition = worldRay.GetPoint(0);
                        ChangeRadiusStartValue    = paintWeightsStrength;
                    }

                    Puppet2D_Skinning.ChangePaintStrength(worldRay.GetPoint(0));
                    ChangingRadius = true;
                }
                if (Event.current.keyCode == (KeyCode.B))
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    if (!ChangingRadius)
                    {
                        ChangeRadiusStartPosition = worldRay.GetPoint(0);
                        ChangeRadiusStartValue    = EditSkinWeightRadius;
                    }

                    Puppet2D_Skinning.ChangePaintRadius(worldRay.GetPoint(0));
                    ChangingRadius = true;
                }
            }
            break;
        }

        case EventType.mouseMove:
        {
            if (Event.current.button == 0)
            {
                if (BoneCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    if (Event.current.control == true)
                    {
                        Puppet2D_BoneCreation.BoneMoveMode(worldRay.GetPoint(0));
                    }
                    if (Event.current.shift == true)
                    {
                        Puppet2D_BoneCreation.BoneMoveIndividualMode(worldRay.GetPoint(0));
                    }
                }
                if (FFDCreation || SplineCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    if ((Event.current.control == true) || (Event.current.shift == true))
                    {
                        MoveControl(worldRay.GetPoint(0));
                    }
                }
            }
            break;
        }

        case EventType.MouseDown:
        {
            if (Event.current.button == 0)
            {
                if (BoneCreation)
                {
                    Ray worldRay  = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    int controlID = GUIUtility.GetControlID(FocusType.Passive);
                    HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
                    GameObject c = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                    if (c)
                    {
                        Selection.activeGameObject = c;
                    }
                    else
                    {
                        if (Event.current.alt)
                        {
                            Puppet2D_BoneCreation.BoneAddMode(worldRay.GetPoint(0));
                        }
                        else
                        {
                            Puppet2D_BoneCreation.BoneCreationMode(worldRay.GetPoint(0));
                        }
                    }
                    HandleUtility.AddDefaultControl(controlID);
                }
                else if (SplineCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    Puppet2D_Spline.SplineCreationMode(worldRay.GetPoint(0));
                }
                else if (FFDCreation)
                {
                    Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                    Puppet2D_FFD.FFDCreationMode(worldRay.GetPoint(0));
                }
                else if (SkinWeightsPaint)
                {
                    GameObject c = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                    if (c && c.GetComponent <SpriteRenderer>() && c.GetComponent <SpriteRenderer>().sprite&& c.GetComponent <SpriteRenderer>().sprite.name.Contains("Bone"))
                    {
                        Selection.activeGameObject = c;
                    }
                }
            }

            else if (Event.current.button == 1)
            {
                if (BoneCreation)
                {
                    Puppet2D_BoneCreation.BoneFinishCreation();
                    Selection.activeObject = null;
                    currentActiveBone      = null;
                    BoneCreation           = true;
                }
                else if (FFDCreation)
                {
                    Puppet2D_FFD.CloseFFDPath();
                }
            }
            break;
        }

        case EventType.keyUp:
        {
            if (Event.current.keyCode == (KeyCode.B) || Event.current.keyCode == (KeyCode.N))
            {
                if (SkinWeightsPaint)
                {
                    ChangingRadius = false;
                }
            }
            break;
        }

        case EventType.mouseDrag:
        {
            paintControlColor = new Color(.8f, 1f, .8f, .5f);



            if (SkinWeightsPaint)
            {
                Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                if (Event.current.control == true)
                {
                    paintControlColor = new Color(1f, .8f, .8f, .5f);
                    if (Event.current.button == 0)
                    {
                        Puppet2D_Skinning.PaintWeights(worldRay.GetPoint(0), -1);
                    }
                }
                else if (Event.current.shift == true)
                {
                    paintControlColor = new Color(.8f, .8f, 1f, .5f);
                    if (Event.current.button == 0)
                    {
                        Puppet2D_Skinning.PaintSmoothWeights(worldRay.GetPoint(0));
                    }
                }
                else
                {
                    paintControlColor = new Color(.8f, 1f, .8f, .5f);
                    if (Event.current.button == 0)
                    {
                        Puppet2D_Skinning.PaintWeights(worldRay.GetPoint(0), 1);
                    }
                }
            }


            break;
        }
        }
        if (SkinWeightsPaint)
        {
            Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            if (ChangingRadius)
            {
                Puppet2D_Skinning.DrawHandle(ChangeRadiusStartPosition);
            }
            else
            {
                Puppet2D_Skinning.DrawHandle(worldRay.GetPoint(0));
            }
            Repaint();
            SceneView.RepaintAll();

            int controlID = GUIUtility.GetControlID(FocusType.Passive);
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));



            HandleUtility.AddDefaultControl(controlID);
        }
        // Do your drawing here using Handles.

        GameObject[] selection = Selection.gameObjects;

        Handles.BeginGUI();
        if (BoneCreation)
        {
            if (selection.Length > 0)
            {
                Handles.color = Color.blue;
                Handles.Label(selection[0].transform.position + new Vector3(2, 2, 0),
                              "Left Click To Draw Bones\nPress Enter To Finish.\nBackspace To Delete A Bone\nHold Shift To Move Individual Bone\nHold Ctrl To Move Bone & Hierachy\nAlt Left Click To Add A Bone In Chain\nRight Click To Deselect");
            }
            else
            {
                Handles.color = Color.blue;
                Handles.Label(SceneView.lastActiveSceneView.camera.transform.position + Vector3.forward * 2,
                              "Bone Create Mode.\nLeft Click to Draw Bones.\nOr click on a bone to be a parent");
            }
        }
        if (SkinWeightsPaint)
        {
            Handles.color = Color.blue;
            Handles.Label(new Vector3(20, -40, 0),
                          "Select Bones to paint their Weights\n" +
                          "Left Click Adds Weights\n" +
                          "Left Click & Ctrl Removes Weights\n" +
                          "Left Click & Shift Smooths Weights\n" +
                          "Hold B to Change Brush Size\n" +
                          "Hold N to Change Strength");
        }
        // Do your drawing here using GUI.
        Handles.EndGUI();
    }
Ejemplo n.º 11
0
    public static void IKCreateTool(bool worldSpace = false)
    {
        GameObject bone = Selection.activeObject as GameObject;

        if (bone)
        {
            if (bone.GetComponent <SpriteRenderer>())
            {
                if (!bone.GetComponent <SpriteRenderer>().sprite.name.Contains("Bone"))
                {
                    Debug.LogWarning("This is not a Puppet2D Bone");
                    return;
                }
            }
            else
            {
                Debug.LogWarning("This is not a Puppet2D Bone");
                return;
            }
        }
        else
        {
            Debug.LogWarning("This is not a Puppet2D Bone");
            return;
        }
        GameObject globalCtrl = CreateGlobalControl();

        foreach (Puppet2D_ParentControl parentControl in globalCtrl.GetComponent <Puppet2D_GlobalControl>()._ParentControls)
        {
            if ((parentControl.bone.transform == bone.transform) || (parentControl.bone.transform == bone.transform.parent.transform))
            {
                Debug.LogWarning("Can't create a IK Control on Bone; it alreay has an Parent Control");
                return;
            }
        }
        foreach (Puppet2D_IKHandle ikhandle in globalCtrl.GetComponent <Puppet2D_GlobalControl>()._Ikhandles)
        {
            if ((ikhandle.bottomJointTransform == bone.transform) || (ikhandle.middleJointTransform == bone.transform) || (ikhandle.topJointTransform == bone.transform))
            {
                Debug.LogWarning("Can't create a IK Control on Bone; it alreay has an IK handle");
                return;
            }
        }

        GameObject IKRoot = null;

        if (bone.transform.parent && bone.transform.parent.transform.parent && bone.transform.parent.transform.parent.GetComponent <SpriteRenderer>() && bone.transform.parent.transform.parent.GetComponent <SpriteRenderer>().sprite != null && bone.transform.parent.transform.parent.GetComponent <SpriteRenderer>().sprite.name.Contains("Bone"))
        {
            IKRoot = bone.transform.parent.transform.parent.gameObject;
        }
        if (IKRoot == null)
        {
            Debug.LogWarning("You need to select the end of a chain of three bones");
            return;
        }
        // CHECK IF TOP BONE HAS AN IK ATTACHED

        Puppet2D_GlobalControl[] globalCtrls = GameObject.FindObjectsOfType <Puppet2D_GlobalControl>();
        foreach (Puppet2D_GlobalControl glblCtrl in globalCtrls)
        {
            foreach (Puppet2D_IKHandle ik in glblCtrl._Ikhandles)
            {
                if (ik.topJointTransform == bone.transform.parent.transform.parent)
                {
                    Debug.LogWarning(bone.transform.parent.transform.parent.name + " already has an IK control");
                    return;
                }
            }
            foreach (Puppet2D_SplineControl splineCtrl in glblCtrl._SplineControls)
            {
                foreach (GameObject splineBone in splineCtrl.bones)
                {
                    if (splineBone.transform == bone.transform.parent.transform.parent)
                    {
                        Debug.LogWarning(bone.transform.parent.transform.parent.name + " has a Spline control attached, please make sure there are at least 3 bones after the spline bone");
                        return;
                    }
                }
            }
        }


        // CHECK TO SEE IF THE BOTTOM BONE IS POINTING AT THE MIDDLE BONE
        if (bone.transform.parent.transform.parent.rotation != Quaternion.LookRotation(bone.transform.parent.transform.position - bone.transform.parent.transform.parent.position, Vector3.forward) * Quaternion.AngleAxis(90, Vector3.right))
        {           //if(bone.transform.parent.transform.parent);
            Puppet2D_BoneCreation.sortOutBoneHierachy(bone.transform.parent.gameObject, true);
        }
        if (bone.transform.parent.rotation != Quaternion.LookRotation(bone.transform.position - bone.transform.parent.position, Vector3.forward) * Quaternion.AngleAxis(90, Vector3.right))
        {           //if(bone.transform.parent.transform.parent);
            Puppet2D_BoneCreation.sortOutBoneHierachy(bone, true);
        }


        GameObject control = new GameObject();

        Undo.RegisterCreatedObjectUndo(control, "Created control");
        control.name = (bone.name + "_CTRL");
        GameObject controlGroup = new GameObject();

        Undo.RegisterCreatedObjectUndo(controlGroup, "new control grp");
        controlGroup.name = (bone.name + "_CTRL_GRP");

        control.transform.parent        = controlGroup.transform;
        controlGroup.transform.position = bone.transform.position;
        if (!worldSpace)
        {
            controlGroup.transform.rotation = bone.transform.rotation;
        }

        GameObject poleVector = new GameObject();

        Undo.RegisterCreatedObjectUndo(poleVector, "Created polevector");
        poleVector.name = (bone.name + "_POLE");

        SpriteRenderer spriteRenderer = control.AddComponent <SpriteRenderer>();
        string         path           = (Puppet2D_Editor._puppet2DPath + "/Textures/GUI/IKControl.psd");
        Sprite         sprite         = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;

        spriteRenderer.sprite           = sprite;
        spriteRenderer.sortingLayerName = Puppet2D_Editor._controlSortingLayer;

        // store middle bone position to check if it needs flipping

        Vector3 middleBonePos = bone.transform.parent.transform.position;

        Puppet2D_IKHandle ikHandle = control.AddComponent <Puppet2D_IKHandle>();

        ikHandle.topJointTransform    = IKRoot.transform;
        ikHandle.middleJointTransform = bone.transform.parent.transform;
        ikHandle.bottomJointTransform = bone.transform;
        ikHandle.poleVector           = poleVector.transform;
        ikHandle.scaleStart[0]        = IKRoot.transform.localScale;
        ikHandle.scaleStart[1]        = IKRoot.transform.GetChild(0).localScale;
        ikHandle.OffsetScale          = bone.transform.localScale;

        if (worldSpace)
        {
            ikHandle.Offset = ikHandle.bottomJointTransform.rotation;
        }

        if (bone.GetComponent <SpriteRenderer>().sprite.name.Contains("Bone"))
        {
            ikHandle.AimDirection = Vector3.forward;
            ikHandle.UpDirection  = Vector3.right;
        }
        else
        {
            Debug.LogWarning("This is not a Puppet2D Bone");
            ikHandle.AimDirection = Vector3.right;
            ikHandle.UpDirection  = Vector3.up;
        }


        //if (bone.transform.parent.transform.position.x < IKRoot.transform.position.x)

        Selection.activeObject = ikHandle;

        controlGroup.transform.parent = globalCtrl.transform;
        poleVector.transform.parent   = globalCtrl.transform;
        if (globalCtrl.GetComponent <Puppet2D_GlobalControl>().AutoRefresh)
        {
            globalCtrl.GetComponent <Puppet2D_GlobalControl>().Init();
        }
        else
        {
            globalCtrl.GetComponent <Puppet2D_GlobalControl>()._Ikhandles.Add(ikHandle);
        }


        //fix from now on for 180 flip
        globalCtrl.GetComponent <Puppet2D_GlobalControl> ()._flipCorrection = -1;
        globalCtrl.GetComponent <Puppet2D_GlobalControl>().Run();
        if ((Vector3.Distance(bone.transform.parent.transform.position, middleBonePos) > 0.0001f))
        {
            ikHandle.Flip = true;
        }
    }