Ejemplo n.º 1
0
    public void LoadX(PList plist)
    {
        //read metadata
        PList  meta = plist["metadata"] as PList;
        object varCheck;

        if (meta.TryGetValue("realTextureFileName", out varCheck))
        {
            realTextureFileName = meta["realTextureFileName"] as string;
        }
        else
        {
            PList ptarget = meta["target"] as PList;
            realTextureFileName = ptarget["name"] as string;
        }

        size = StrToVec2(meta["size"] as string);

        //read frames
        PList frames = plist["frames"] as PList;

        foreach (var kv in frames)
        {
            string      name      = kv.Key;
            PList       framedata = kv.Value as PList;
            TPFrameData frame     = new TPFrameData();
            frame.LoadX(name, framedata);
            sheets.Add(frame);
        }
    }
Ejemplo n.º 2
0
    public void LoadX(PList plist)
    {
        //read metadata
        PList  meta = plist["metadata"] as PList;
        object varCheck;

        if (meta.TryGetValue("realTextureFileName", out varCheck))
        {
            realTextureFileName = meta["realTextureFileName"] as string;
        }
        else
        {
            PList ptarget = meta["target"] as PList;
            realTextureFileName = ptarget["name"] as string;
        }

        size = StrToVec2(meta["size"] as string);

        // int lastidx = plistFilePath.LastIndexOf('\\');
        //textureFilePath = plistFilePath.Substring(0, lastidx + 1) + realTextureFileName;
        // CreateTexture(textureFilePath, (int)size.x, (int)size.y);

        //read frames
        PList frames = plist["frames"] as PList;

        foreach (var kv in frames)
        {
            string      name      = kv.Key;
            PList       framedata = kv.Value as PList;
            TPFrameData frame     = new TPFrameData(texture);
            frame.LoadX(name, framedata);
            sheets.Add(frame);
        }
    }
Ejemplo n.º 3
0
    //void Update()
    //{
    //    switch(state)
    //    {
    //        case 0:
    //            curtTime = startTime = Time.time;
    //            state = 1;
    //            break;

    //        case 1:
    //            curtTime = Time.time;
    //            break;
    //    }


    //    float tm = curtTime - startTime;
    //    int pos = (int)(tm / delayPerUnit);
    //    int index = pos % frameDataList.Count;

    //    TPFrameData framData = frameDataList[index];

    //    float sx = spriterenderer.transform.localScale.x;
    //    float sy = spriterenderer.transform.localScale.y;

    //    float ox = framData.offset.x  / framData.sprite.pixelsPerUnit * sx;
    //    float oy = framData.offset.y / framData.sprite.pixelsPerUnit * sy;

    //    Vector3 newPos = new Vector3(orgPosition.x + ox, orgPosition.y + oy, orgPosition.z);
    //    spriterenderer.transform.position = newPos;
    //    spriterenderer.sprite = framData.sprite;

    //    img.transform.position = newPos;
    //    img.sprite = framData.sprite;


    //}


    void Update()
    {
        switch (state)
        {
        case 0:
            curtTime = startTime = Time.time;
            state    = 1;
            break;

        case 1:
            curtTime = Time.time;
            break;

        case 2:
            curtTime = Time.time;
            if (curtTime < nextStartTime)
            {
                return;
            }
            state = 1;
            break;
        }

        float tm    = curtTime - startTime;
        int   pos   = (int)(tm / delayPerUnit);
        int   index = pos % frameDataList.Count;

        if (index == frameDataList.Count - 1)
        {
            state         = 2;
            nextStartTime = curtTime + nextStartDelay;
        }


        TPFrameData framData = frameDataList[index];

        //float sx = rectTransform.sizeDelta.x / framData.frame.width;
        //float sy = rectTransform.sizeDelta.y / framData.frame.height;


        float ox = framData.offset.x / 1 * sx;
        float oy = framData.offset.y / 1 * sy;


        Vector3 a = new Vector3();
        float   angle;

        rectTransform.localRotation.ToAngleAxis(out angle, out a);

        Vector3 mx = new Vector3(ox, 0, 0);

        mx = Quaternion.AngleAxis(angle, a) * mx;

        Vector3 my = new Vector3(0, oy, 0);

        my = Quaternion.AngleAxis(angle, a) * my;

        Vector3 m      = mx + my;
        Vector3 newPos = new Vector3(orgPosition.x + m.x, orgPosition.y + m.y, orgPosition.z);

        rectTransform.localPosition = newPos;
        img.sprite = framData.sprite;
        rectTransform.sizeDelta = new Vector2(framData.frame.width, framData.frame.height);
    }