Example #1
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>();
    }
Example #2
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;
    }
Example #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>().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();
     }
 }
Example #5
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;
    }