关于unishare。按钮设置

来源:互联网 发布:linux mmap 编辑:程序博客网 时间:2024/06/05 12:10
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UniShare;

public class FuntionalButton : MonoBehaviour {

    public FuncButton funcType;
    public GameObject photoAfter;
    public GameObject photoButton;

    public GameObject achor;
    public GameObject k_center;

    Vector3 orgin = new Vector3(106106106);
    Vector3 orgin_shu = new Vector3(535353);

    static bool sendWeibo = false;
    string weiboContent = "我在华宁弘基哦";
    // Use this for initialization
    void Start () {
        SinaWeibo.instance.OnOauthCallBack += oauthCallback;
        SinaWeibo.instance.appKey = "2486190234";
        SinaWeibo.instance.appSecret = "58c64af48a9e94bb4768a0d29c44f617";
        SinaWeibo.instance.callbackUrl = "https://api.weibo.com/oauth2/default.html";
    }
    
    // Update is called once per frame
    void Update () {
    
    }

    void OnClick()
    {
        if (funcType == FuncButton.Share)
        {
            Share();
            Back();
        }
        else if (funcType == FuncButton.Save)
        {
            Save();
            Back();
        }
        else if (funcType == FuncButton.Back)
        {
            Back();
        }
        
    }

    void Share()
    {
        sendWeibo = false;
        if (!SinaWeibo.instance.IsBinded)
        {
            SinaWeibo.instance.Authorize();
        }
        else
        {
            SendSinaWeibo();
        }
    }

    void Save()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            CopyPhoto(false);
        }
    }

    void Back()
    {
        photoAfter.SetActive(false);
        photoButton.SetActive(true);

        achor.SetActive(true);
        k_center.SetActive(true);

        photoButton.transform.localScale = orgin;
        Screen.orientation = ScreenOrientation.AutoRotation;
    }

    void CopyPhoto(bool isWeibo)
    {
        try
        {
            if (!Directory.Exists("/sdcard/DCIM/Camera"))
                Directory.CreateDirectory("/sdcard/DCIM/Camera");

            string filename = "/sdcard/Android/data/com.ileou.myqcaractivity/files/photo_" + TakePhoto.number.ToString() + ".png";
            string desFilename = "/sdcard/DCIM/Camera/photo_" + TakePhoto.number.ToString() + ".png";
            if (File.Exists(filename))
            {
                File.Copy(filenamedesFilenametrue);
                RefreshPicture(isWeibo);
            }

        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
    }

    void RefreshPicture(bool isWeibo)
    {
        using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        {
            using (AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"))
            {
                jo.Call("refreshPicture""photo_" + TakePhoto.number.ToString() + ".png"isWeibo);
            }
        }
    }

    void SendSinaWeibo()
    {
        if (sendWeibo == false)
        {
            sendWeibo = true;
            string filename = "/sdcard/Android/data/com.ileou.myqcaractivity/files/photo_" + TakePhoto.number.ToString() + ".png";
            if (File.Exists(filename))
            {
                SinaWeibo.instance.ShareWithImage(weiboContentfilename);
                CopyPhoto(true);
            }
            else
            {
                SinaWeibo.instance.Share(weiboContent);
            }
        }
        
    }

    void oauthCallback(PlatformType pTypebool success)
    {
        if (success)
        {
            SendSinaWeibo();
        }
    }
}

public enum FuncButton
{
    Share = 0,
    Save,
    Back
}
0 0