Exemplo n.º 1
0
        public static void BoneFinishCreation()
        {
            Puppet2D_Editor.BoneCreation = false;
            EditorPrefs.SetBool("Puppet2D_BoneCreation", false);

            Puppet2D_Bone[] Bones = GameObject.FindObjectsOfType <Puppet2D_Bone>();


            /*foreach (Puppet2D_Bone bone in Bones)
             * {
             *
             *      GameObject globalCtrlNew = Puppet2D_CreateControls.CreateGlobalControl();
             *
             *      bone.transform.parent = globalCtrlNew.transform;
             *
             *
             * }*/


            GameObject globalCtrl = Puppet2D_CreateControls.CreateGlobalControl();

            if (globalCtrl != null)
            {
                foreach (Puppet2D_Bone Bone in Bones)
                {
                    if (Bone && Bone.transform.parent == null)
                    {
                        Bone.transform.parent = globalCtrl.transform;
                    }
                }
            }
        }
        public static void BoneFinishCreation()
        {
            Puppet2D_Editor.BoneCreation = false;
            EditorPrefs.SetBool("Puppet2D_BoneCreation", false);

            Puppet2D_HiddenBone[] hiddenBones = GameObject.FindObjectsOfType <Puppet2D_HiddenBone>();


            SpriteRenderer[] sprites = GameObject.FindObjectsOfType <SpriteRenderer>();
            foreach (SpriteRenderer spr in sprites)
            {
                if (spr.sprite != null && spr.sprite.name == "BoneNoJoint" && spr.transform.parent == null)
                {
                    GameObject globalCtrlNew = Puppet2D_CreateControls.CreateGlobalControl();

                    spr.transform.parent = globalCtrlNew.transform;
                }
            }


            GameObject globalCtrl = Puppet2D_CreateControls.CreateGlobalControl();

            if (globalCtrl != null)
            {
                foreach (Puppet2D_HiddenBone hiddenBone in hiddenBones)
                {
                    if (hiddenBone && hiddenBone.transform.parent && hiddenBone.transform.parent.parent == null)
                    {
                        hiddenBone.transform.parent.parent = globalCtrl.transform;
                    }
                }
            }
        }
Exemplo n.º 3
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>().InitializeArrays();
                globalCtrl.GetComponent <Puppet2D_GlobalControl>().Run();

                Undo.DestroyObjectImmediate(splineStoreData);

                splineStoreData.FFDCtrls.Clear();


                // parent spline bones
                Puppet2D_HiddenBone[] hiddenBones = GameObject.FindObjectsOfType <Puppet2D_HiddenBone>();

                if (globalCtrl != null)
                {
                    foreach (Puppet2D_HiddenBone hiddenBone in hiddenBones)
                    {
                        if (hiddenBone && hiddenBone.transform.parent && hiddenBone.transform.parent.parent == null)
                        {
                            hiddenBone.transform.parent.parent = globalCtrl.transform;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void FFDFinishCreation()
        {
            if (ffdStoreData == null)
            {
                return;
            }
            Puppet2D_Editor.FFDCreation = false;
            CloseFFDPath();



            Texture spriteTexture = null;

            //GameObject FFDControlsGrp = new GameObject(Puppet2D_BoneCreation.GetUniqueBoneName("FFD_Ctrls_GRP"));

            if (Puppet2D_Editor.FFDGameObject && Puppet2D_Editor.FFDGameObject.GetComponent <SpriteRenderer>() && Puppet2D_Editor.FFDGameObject.GetComponent <SpriteRenderer>().sprite)
            {
                spriteTexture = Puppet2D_Editor.FFDGameObject.GetComponent <SpriteRenderer>().sprite.texture;

                foreach (Transform FFDCtrl in ffdStoreData.FFDCtrls)
                {
                    FFDCtrl.transform.position = Puppet2D_Editor.FFDGameObject.transform.InverseTransformPoint(FFDCtrl.transform.position);
                }


                FFDControlsGrp.transform.position   = Puppet2D_Editor.FFDGameObject.transform.position;
                FFDControlsGrp.transform.rotation   = Puppet2D_Editor.FFDGameObject.transform.rotation;
                FFDControlsGrp.transform.localScale = Puppet2D_Editor.FFDGameObject.transform.localScale;

                //Puppet2D_Editor.FFDGameObject.transform.position = Vector3.zero;
                //Puppet2D_Editor.FFDGameObject.transform.rotation = Quaternion.identity;
                //Puppet2D_Editor.FFDGameObject.transform.localScale = Vector3.one;
            }

            if (ffdStoreData.FFDCtrls.Count < 3)
            {
                //Undo.DestroyObjectImmediate(ffdStoreData);
                return;
            }

            Puppet2D_CreatePolygonFromSprite polyFromSprite = ScriptableObject.CreateInstance("Puppet2D_CreatePolygonFromSprite") as Puppet2D_CreatePolygonFromSprite;

            List <Vector3> verts = new List <Vector3>();

            for (int i = 0; i < ffdStoreData.FFDCtrls.Count(); i++)
            {
                if (ffdStoreData.FFDCtrls[i])
                {
                    verts.Add(new Vector3(ffdStoreData.FFDCtrls[i].position.x, ffdStoreData.FFDCtrls[i].position.y, 0));
                }
                else
                {
                    //                Debug.LogWarning("A FFD control point has been removed, no mesh created");
                    //                Undo.DestroyObjectImmediate(ffdStoreData);
                    //                return;
                }
            }
            GameObject newMesh;


            if (ffdStoreData.FFDPathNumber.Count > 0 && verts.Count > 2)
            {
                if (Puppet2D_Editor.FFDGameObject == null)
                {
                    Puppet2D_Editor.FFDGameObject = new GameObject();
                    Undo.RegisterCreatedObjectUndo(Puppet2D_Editor.FFDGameObject, "newGameObject");
                }


                Puppet2D_Editor._numberBonesToSkinToIndex = 0;

                string sortingLayer = "";
                int    sortingOrder = 0;
                if (Puppet2D_Editor.FFDGameObject.GetComponent <Renderer>())
                {
                    sortingLayer = Puppet2D_Editor.FFDGameObject.GetComponent <Renderer>().sortingLayerName;
                    sortingOrder = Puppet2D_Editor.FFDGameObject.GetComponent <Renderer>().sortingOrder;
                }



                newMesh = polyFromSprite.MakeFromVerts(true, verts.ToArray(), ffdStoreData.FFDPathNumber, Puppet2D_Editor.FFDGameObject);

                if (Puppet2D_Editor.FFDGameObject.GetComponent <Renderer>())
                {
                    newMesh.GetComponent <Renderer>().sortingLayerName = sortingLayer;
                    newMesh.GetComponent <Renderer>().sortingOrder     = sortingOrder;
                }
                Puppet2D_Editor._numberBonesToSkinToIndex = 1;
            }
            else
            {
                //Undo.DestroyObjectImmediate(ffdStoreData);
                return;
            }



            Undo.DestroyObjectImmediate(polyFromSprite);



            if (Puppet2D_Editor.FFDGameObject)
            {
                if (spriteTexture != null)
                {
                    newMesh.GetComponent <Renderer>().sharedMaterial.mainTexture = spriteTexture;
                }
                else
                {
                    newMesh.GetComponent <Renderer>().sharedMaterial = new Material(Shader.Find("Unlit/Texture"));
                }
                newMesh.name = Puppet2D_Editor.FFDGameObject.name;

                ffdStoreData.FFDCtrls.Add(newMesh.transform);

                Undo.DestroyObjectImmediate(Puppet2D_Editor.FFDGameObject);
            }



            GameObject globalCtrl = Puppet2D_CreateControls.CreateGlobalControl();

            Undo.SetTransformParent(FFDControlsGrp.transform, globalCtrl.transform, "parentToGlobal");
            Undo.SetTransformParent(newMesh.transform, globalCtrl.transform, "parentToGlobal");

            List <Object> newObjs = new List <Object>();

            foreach (Transform tr in ffdStoreData.FFDCtrls)
            {
                if (tr)
                {
                    newObjs.Add(tr.gameObject);
                }
            }
            Selection.objects = newObjs.ToArray();

            Puppet2D_Editor._numberBonesToSkinToIndex = 1;


            //Undo.RecordObjects (newObjs.ToArray(), "recordingStuff");
            //Undo.RegisterCompleteObjectUndo (newObjs.ToArray(), "recordingStuff");

            Puppet2D_Skinning.BindSmoothSkin(1);

            for (int i = 0; i < ffdStoreData.FFDCtrls.Count - 1; i++)
            {
                //Debug.Log(ffdStoreData.FFDCtrls[i]);
                if (ffdStoreData.FFDCtrls[i])
                {
                    Puppet2D_FFDLineDisplay ffdLine = ffdStoreData.FFDCtrls[i].GetComponent <Puppet2D_FFDLineDisplay>();
                    ffdLine.outputSkinnedMesh = newMesh.GetComponent <SkinnedMeshRenderer>();
                    for (int j = 0; j < ffdLine.outputSkinnedMesh.sharedMesh.vertices.Length; j++)
                    {
                        Vector3 vert = ffdLine.outputSkinnedMesh.sharedMesh.vertices[j];
                        if (Vector3.Distance(vert, ffdStoreData.FFDCtrls[i].transform.position) < .001f)
                        {
                            ffdStoreData.FFDCtrls[i].GetComponent <Puppet2D_FFDLineDisplay>().vertNumber = j;
                        }
                    }
                    Undo.SetTransformParent(ffdStoreData.FFDCtrls[i].parent.transform, FFDControlsGrp.transform, "parentFFDControls");

                    ffdStoreData.FFDCtrls[i].transform.localPosition = Vector3.zero;
                }
            }
            FFDControlsGrp.transform.position = new Vector3(FFDControlsGrp.transform.position.x, FFDControlsGrp.transform.position.y, ffdStoreData.OriginalSpritePosition.z);


            Selection.activeGameObject = ffdStoreData.FFDCtrls[ffdStoreData.FFDCtrls.Count - 1].gameObject;
            ffdStoreData.FFDCtrls.RemoveAt(ffdStoreData.FFDCtrls.Count - 1);
            Undo.RegisterCompleteObjectUndo(ffdStoreData, "changinEditable");
            ffdStoreData.Editable = false;
            //        Undo.DestroyObjectImmediate(ffdStoreData);
            if (globalCtrl.GetComponent <Puppet2D_GlobalControl>().AutoRefresh)
            {
                globalCtrl.GetComponent <Puppet2D_GlobalControl>().Init();
            }
        }