Exemple #1
0
 internal void _doOpenUrlWith(string component, core core, bool open_in_new_tab = false, Action <LoaderResult> callback = null)
 {
     core.callComponent(component, this, (ResultModel _r) =>
     {
         LoaderResult r = (LoaderResult)_r;
         if (callback != null)
         {
             callback(r);
         }
         if (r.success)
         {
             core.openUrl(r.url, open_in_new_tab);
         }
     }
                        );
 }
Exemple #2
0
        public SessionLoader(core core)
        {
            _core = core;
            session initial_session = new session();

            string session_id = getSessionIdFromURL();

            if (ngioPluginLoaded())
            {
                newgroundsioAddPluginScripts();

                if (string.IsNullOrEmpty(session_id))
                {
                    session_id = getSessionFromLocalStorage();
                }
            }
            else
            {
                if (UnityEngine.PlayerPrefs.HasKey(_session_pref))
                {
                    session_id = UnityEngine.PlayerPrefs.GetString(_session_pref);
                }
            }

            if (string.IsNullOrEmpty(session_id))
            {
                session_id = core.session_id;
            }

            if (!string.IsNullOrEmpty(session_id))
            {
                initial_session.id = session_id;
            }
            else
            {
                initial_session.expired = true;
            }

            session = initial_session;

            stopwatch.Start();
        }
Exemple #3
0
        /// <summary>
        ///  Extracts keys from a SimpleJSON.JSONNode matching public properties in this model object.
        /// </summary>
        /// <param name="json">A SimpleJSON.JObject that has been processed from a JSON string.</param>
        /// <param name="core">The core instance to attach to this object.</param>
        internal void setPropertiesFromSimpleJSON(JObject json, core core = null)
        {
            if (core != null)
            {
                this.ngio_core = core;
            }
            else
            {
                core = this.ngio_core;
            }

            Type rType = this.GetType();

            PropertyInfo[] rProps = rType.GetProperties();

            Dictionary <string, JObject> jdict = json.ObjectValue;

            SimpleJSONImportable pval;
            Type ptype;

            foreach (PropertyInfo property in rProps)
            {
                if (!jdict.ContainsKey(property.Name))
                {
                    continue;
                }

                bool    is_model = property.PropertyType.IsSubclassOf(typeof(SimpleJSONImportable));
                JObject jprop    = jdict[property.Name];

                // subclasses can override this method to handle special case properties
                if (setSpecialPropertyFromJSON(property.Name, jprop, core))
                {
                    continue;
                }

                if (jprop.Kind == JObjectKind.Null)
                {
                    property.SetValue(this, null, null);
                }
                else if (is_model)
                {
                    pval = (SimpleJSONImportable)property.GetValue(this, null);
                    pval.setPropertiesFromSimpleJSON(jprop, core);
                }
                else if (isMultiTypeProperty(property.Name) && multi_property_map[property.Name][MultiValueFlat].GetType().IsSubclassOf(typeof(SimpleJSONImportable)))
                {
                    switch (jprop.Kind)
                    {
                    case JObjectKind.Array:
                        SimpleJSONImportableList plist = new SimpleJSONImportableList();
                        ptype      = multi_property_map[property.Name][MultiValueFlat].GetType();
                        plist.type = ptype;
                        foreach (JObject jrow in jprop.ArrayValue)
                        {
                            pval = (SimpleJSONImportable)Activator.CreateInstance(ptype);
                            pval.setPropertiesFromSimpleJSON(jrow, core);
                            plist.Add(pval);
                        }
                        property.SetValue(this, plist, null);
                        break;

                    case JObjectKind.Object:
                        pval = (SimpleJSONImportable)property.GetValue(this, null);
                        pval.setPropertiesFromSimpleJSON(jprop, core);
                        break;

                    default:
                        Debug.LogWarning("Unexpected property value for " + property.Name + ". Setting to null.");
                        property.SetValue(this, null, null);
                        break;
                    }
                }
                else
                {
                    JObjectKind jk  = jprop.Kind;
                    string      ppt = property.PropertyType.ToString();

                    // some bools and numbers may get passed in as strings, this should catch them.
                    if (jk == JObjectKind.String && ppt != "System.String")
                    {
                        switch (ppt)
                        {
                        case "System.Boolean":
                            jk = JObjectKind.Boolean;
                            break;

                        default:
                            jk = JObjectKind.Number;
                            break;
                        }
                    }
                    // and some bools may be set as 0/1 integers too
                    else if (jk == JObjectKind.Number && ppt == "System.Boolean")
                    {
                        jk = JObjectKind.Boolean;
                    }

                    switch (jk)
                    {
                    case JObjectKind.Null:
                        property.SetValue(this, null, null);
                        break;

                    case JObjectKind.Boolean:
                        property.SetValue(this, jprop.BooleanValue, null);
                        break;

                    case JObjectKind.String:
                        property.SetValue(this, jprop.StringValue, null);
                        break;

                    case JObjectKind.Number:

                        // now to figure out what number type to use...
                        if (ppt.StartsWith("System.Int"))
                        {
                            property.SetValue(this, jprop.IntValue, null);
                        }
                        else
                        {
                            property.SetValue(this, jprop.DoubleValue, null);
                        }
                        break;

                    default:
                        Debug.LogWarning("Unexpected property value for " + property.Name + " (Kind=" + jk.ToString() + "). Setting to null.");
                        property.SetValue(this, null, null);
                        break;
                    }
                }
            }
        }
Exemple #4
0
 internal virtual bool setSpecialPropertyFromJSON(string property, JObject json, core core)
 {
     return(false);
 }