예제 #1
0
        //shareSDK
        private void checkPlatforms(DevInfoSet devInfo)
        {
            Type type = devInfo.GetType();

            FieldInfo[] devInfoFields   = type.GetFields();
            Hashtable   enablePlatforms = new Hashtable();

            foreach (FieldInfo devInfoField in devInfoFields)
            {
                DevInfo info = (DevInfo)devInfoField.GetValue(devInfo);
                if (info.Enable)
                {
                    int    platformId = (int)info.GetType().GetField("type").GetValue(info);
                    string appkey     = GetAPPKey(info, platformId);
                    enablePlatforms.Add(platformId, appkey);
                }
            }
            var      files           = System.IO.Directory.GetFiles(Application.dataPath, "ShareSDK.mobpds", System.IO.SearchOption.AllDirectories);
            string   filePath        = files [0];
            FileInfo projectFileInfo = new FileInfo(filePath);

            if (projectFileInfo.Exists)
            {
                StreamReader sReader  = projectFileInfo.OpenText();
                string       contents = sReader.ReadToEnd();
                sReader.Close();
                sReader.Dispose();
                Hashtable datastore = (Hashtable)MiniJSON.jsonDecode(contents);
                if (datastore.ContainsKey("ShareSDKPlatforms"))
                {
                    datastore["ShareSDKPlatforms"] = enablePlatforms;
                }
                else
                {
                    datastore.Add("ShareSDKPlatforms", enablePlatforms);
                }
                var          json    = MiniJSON.jsonEncode(datastore);
                StreamWriter sWriter = new StreamWriter(filePath);
                sWriter.WriteLine(json);
                sWriter.Close();
                sWriter.Dispose();
            }
        }
예제 #2
0
        void Awake()
        {
            devInfo        = new DevInfoSet();
            devInfo.wechat = new WeChat();

            Type      type            = devInfo.GetType();
            Hashtable platformConfigs = new Hashtable();

            FieldInfo[] devInfoFields = type.GetFields();
            foreach (FieldInfo devInfoField in devInfoFields)
            {
                DevInfo     info       = (DevInfo)devInfoField.GetValue(devInfo);
                int         platformId = (int)info.GetType().GetField("type").GetValue(info);
                FieldInfo[] fields     = info.GetType().GetFields();
                Hashtable   table      = new Hashtable();
                foreach (FieldInfo field in fields)
                {
                    if ("type".EndsWith(field.Name))
                    {
                        continue;
                    }
                    else if ("Enable".EndsWith(field.Name) || "ShareByAppClient".EndsWith(field.Name) || "BypassApproval".EndsWith(field.Name) || "ShareByWebApi".EndsWith(field.Name))
                    {
                        table.Add(field.Name, Convert.ToString(field.GetValue(info)).ToLower());
                    }
                    else
                    {
                        table.Add(field.Name, Convert.ToString(field.GetValue(info)));
                    }
                }
                platformConfigs.Add(platformId, table);
            }

                        #if UNITY_ANDROID
            shareSDKUtils = new AndroidImpl(gameObject);
            shareSDKUtils.InitSDK(appKey, appSecret);
                        #elif UNITY_IPHONE
            shareSDKUtils = new iOSImpl(gameObject);
                        #endif

            shareSDKUtils.SetPlatformConfig(platformConfigs);
        }
        //shareSDK
        private void checkPlatforms(DevInfoSet devInfo)
        {
            Type type = devInfo.GetType();

            FieldInfo[] devInfoFields   = type.GetFields();
            Hashtable   enablePlatforms = new Hashtable();

            foreach (FieldInfo devInfoField in devInfoFields)
            {
                DevInfo info = (DevInfo)devInfoField.GetValue(devInfo);
                if (info.Enable)
                {
                    int    platformId = (int)info.GetType().GetField("type").GetValue(info);
                    string appkey     = GetAPPKey(info, platformId);
                    enablePlatforms.Add(platformId, appkey);

                    if (info.GetType().GetField("app_universalLink") != null)
                    {
                        string app_universalLink = GetValueByName(info, "app_universalLink");
                        if (app_universalLink != null && app_universalLink.Length > 0)
                        {
                            app_universalLink = app_universalLink.Trim().TrimEnd('/');

                            if (app_universalLink.Contains("://"))
                            {
                                string[] links = app_universalLink.Split(new[] { "://" }, StringSplitOptions.None);
                                app_universalLink = "applinks:" + links[1];
                                associatedDomains.Add(app_universalLink);
                            }
                            else
                            {
                                if (app_universalLink.Contains(":"))
                                {
                                    associatedDomains.Add(app_universalLink);
                                }
                                else
                                {
                                    app_universalLink = "applinks:" + app_universalLink;
                                    associatedDomains.Add(app_universalLink);
                                }
                            }
                        }
                    }
                }
            }
            var      files           = System.IO.Directory.GetFiles(Application.dataPath, "ShareSDK.mobpds", System.IO.SearchOption.AllDirectories);
            string   filePath        = files [0];
            FileInfo projectFileInfo = new FileInfo(filePath);

            if (projectFileInfo.Exists)
            {
                StreamReader sReader  = projectFileInfo.OpenText();
                string       contents = sReader.ReadToEnd();
                sReader.Close();
                sReader.Dispose();
                Hashtable datastore = (Hashtable)MiniJSON.jsonDecode(contents);
                if (datastore.ContainsKey("ShareSDKPlatforms"))
                {
                    datastore["ShareSDKPlatforms"] = enablePlatforms;
                }
                else
                {
                    datastore.Add("ShareSDKPlatforms", enablePlatforms);
                }

                //Debug.LogWarning("=======================");
                Debug.LogWarning(associatedDomains.ToArray());
                //if (associatedDomains.Count > 0)
                //{
                var associatedDomains_t = associatedDomains.Distinct();

                if (datastore.ContainsKey("AssociatedDomains"))
                {
                    datastore["AssociatedDomains"] = associatedDomains_t.ToArray();
                }
                else
                {
                    datastore.Add("AssociatedDomains", associatedDomains_t.ToArray());
                }
                //}


                var          json    = MiniJSON.jsonEncode(datastore);
                StreamWriter sWriter = new StreamWriter(filePath);
                sWriter.WriteLine(json);
                sWriter.Close();
                sWriter.Dispose();
            }
        }