public List <GameObject> Create()
        {
            RecursivelyFindFolderPath("Assets");

            bones.Clear();

            CatmullRom(_splineCTRLS, out outCoordinates, numberBones);

            int j = 0;

            foreach (Vector3 outCoord in outCoordinates)
            {
                GameObject newGO = new GameObject(GetUniqueName("bone"));
                Undo.RegisterCreatedObjectUndo(newGO, "Created bone");
                SpriteRenderer spriteRenderer = newGO.AddComponent <SpriteRenderer>();
                string         path           = "";

                path = (_puppet2DPath + "/Textures/GUI/BoneNoJoint.psd");

                Sprite sprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;
                spriteRenderer.sprite    = sprite;
                newGO.transform.position = outCoord;
                bones.Add(newGO);

                if (j > 0)
                {
                    newGO.transform.parent = bones[j - 1].transform;
                }


                GameObject newInvisibleBone = new GameObject(GetUniqueName("hiddenBone"));
                Undo.RegisterCreatedObjectUndo(newInvisibleBone, "Created new invisible Bone");
                SpriteRenderer spriteRendererInvisbile = newInvisibleBone.AddComponent <SpriteRenderer>();
                newInvisibleBone.transform.position = new Vector3(10000, 10000, 10000);

                path = (_puppet2DPath + "/Textures/GUI/BoneJoint.psd");
                Sprite boneHiddenSprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;
                spriteRendererInvisbile.sprite    = boneHiddenSprite;
                newInvisibleBone.transform.parent = newGO.transform.parent;
                Puppet2D_HiddenBone hiddenBoneComp = newInvisibleBone.AddComponent <Puppet2D_HiddenBone>();
                hiddenBoneComp.boneToAimAt = newGO.transform;
                hiddenBoneComp.Refresh();


                j++;
            }
            return(bones);
        }
        public static GameObject BoneCreationMode(Vector3 mousePos)
        {
            bool isSplineBone = false;

            if (Selection.activeGameObject == null)
            {
                if (Puppet2D_Editor.currentActiveBone)
                {
                    Selection.activeGameObject = Puppet2D_Editor.currentActiveBone;
                }
            }
            if (Selection.activeGameObject)
            {
                if (Selection.activeGameObject.GetComponent <Puppet2D_HiddenBone>())
                {
                    Selection.activeGameObject = Selection.activeGameObject.transform.parent.gameObject;
                }

                if (Selection.activeGameObject.GetComponent <SpriteRenderer>())
                {
                    if (Selection.activeGameObject.GetComponent <SpriteRenderer>().sprite)
                    {
                        if (Selection.activeGameObject.GetComponent <SpriteRenderer>().sprite.name.Contains("Bone"))
                        {
                            // MAKE SURE SELECTION IS NOT AN IK OR PARENT

                            Puppet2D_GlobalControl[] globalCtrlScripts = Transform.FindObjectsOfType <Puppet2D_GlobalControl>();
                            for (int i = 0; i < globalCtrlScripts.Length; i++)
                            {
                                foreach (Puppet2D_IKHandle Ik in globalCtrlScripts[i]._Ikhandles)
                                {
                                    if ((Ik.topJointTransform == Selection.activeGameObject.transform) || (Ik.bottomJointTransform == Selection.activeGameObject.transform) || (Ik.middleJointTransform == Selection.activeGameObject.transform))
                                    {
                                        Debug.LogWarning("Cannot parent bone, as this one has an IK handle");
                                        Selection.activeGameObject = null;
                                        return(null);
                                    }
                                }
                                foreach (Puppet2D_SplineControl splineCtrl in globalCtrlScripts[i]._SplineControls)
                                {
                                    foreach (GameObject bone in splineCtrl.bones)
                                    {
                                        if (bone == Selection.activeGameObject)
                                        {
                                            isSplineBone = true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }



            GameObject newBone = new GameObject(GetUniqueBoneName("bone"));

            Undo.RegisterCreatedObjectUndo(newBone, "Created newBone");
            newBone.transform.position = mousePos;
            newBone.transform.position = new Vector3(newBone.transform.position.x, newBone.transform.position.y, 0);

            if (Selection.activeGameObject)
            {
                newBone.transform.parent = Selection.activeGameObject.transform;

                GameObject newInvisibleBone = new GameObject(GetUniqueBoneName("hiddenBone"));
                Undo.RegisterCreatedObjectUndo(newInvisibleBone, "Created new invisible Bone");

                SpriteRenderer spriteRendererInvisbile = newInvisibleBone.AddComponent <SpriteRenderer>();
                newInvisibleBone.transform.position      = new Vector3(10000, 10000, 10000);
                spriteRendererInvisbile.sortingLayerName = Puppet2D_Editor._boneSortingLayer;
                spriteRendererInvisbile.sprite           = Puppet2D_Editor.boneHiddenSprite;
                newInvisibleBone.transform.parent        = Selection.activeGameObject.transform;
                Undo.AddComponent(newInvisibleBone, typeof(Puppet2D_HiddenBone));
                Puppet2D_HiddenBone hiddenBoneComp = newInvisibleBone.GetComponent <Puppet2D_HiddenBone>();
                hiddenBoneComp.boneToAimAt = newBone.transform;
                hiddenBoneComp.Refresh();
            }

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

            spriteRenderer.sortingLayerName = Puppet2D_Editor._boneSortingLayer;

            if (isSplineBone)
            {
                newBone.transform.parent = null;
            }

            sortOutBoneHierachy(newBone);

            if (isSplineBone)
            {
                newBone.transform.parent = Selection.activeGameObject.transform;
            }

            Selection.activeGameObject = newBone;

            Puppet2D_Editor.currentActiveBone = newBone;

            return(newBone);
        }
 void OnEnable()
 {
     handle = (Puppet2D_HiddenBone)target;
 }