Ejemplo n.º 1
0
 public IAPCurrency(string uid, IAPCurrencySetting s, IAPObjectData d, Action <IAPObject> callback = null, Action <IAPCurrency> errorCallback = null) : base(uid, d, callback)
 {
     title          = s.title;
     icon           = s.icon;
     tags           = s.tags;
     _errorCallback = errorCallback;
 }
Ejemplo n.º 2
0
 public IAPAbility(string uid, IAPAbilitySetting s, IAPObjectData d, Action <IAPObject> callback = null) : base(uid, d, callback)
 {
     title        = s.title;
     description  = s.description;
     currency     = s.currency;
     price        = s.price;
     icon         = s.icon;
     tags         = s.tags;
     maxString    = s.maxString;
     lockedString = s.lockedString;
     levels       = s.levels;
 }
Ejemplo n.º 3
0
        public IAPPackage(string uid, IAPPackageSetting s, IAPObjectData d, Action <IAPObject> callback = null) : base(uid, d, callback)
        {
//			uid=s.productId;
            fetchFromStore = s.fetchFromStore;
            currency       = s.currency;
            price          = s.price;
            content        = new List <IAPPackageContent>();
            icon           = s.icon;
            title          = s.title;
            description    = s.description;
            tags           = s.tags;
            productType    = s.productType;

            // Create the dictionary for finding IAPPackageContent
            _contentDictionary = new Dictionary <string, IAPPackageContent>();

            // Loop and create IAPPackageContent for each setting
            foreach (IAPContentSetting c in s.content)
            {
                IAPPackageContent item = new IAPPackageContent();
                item.amount = c.amount;
                if (c.type == IAPType.Currency)
                {
                    item.obj = IAPInventoryManager.GetCurrency(c.uid);
                }
                else if (c.type == IAPType.Inventory)
                {
                    item.obj = IAPInventoryManager.GetInventory(c.uid);
                }
                else if (c.type == IAPType.GameLevel)
                {
                    item.obj = IAPInventoryManager.GetGameLevel(c.uid);
                }
                content.Add(item);
                _contentDictionary.Add(c.uid, item);
            }

            // Add event for real money purchase
            if (fetchFromStore)
            {
                // Debug.Log("fetchFromStore");
                IAPManager.OnIAPProcessPurchase += handleOnIAPProcessPurchase;
            }
        }
Ejemplo n.º 4
0
        public IAPGameLevel(string uid, IAPGameLevelSetting s, IAPObjectData d, Action <IAPObject> callback = null) : base(uid, d, callback)
        {
            title       = s.title;
            description = s.description;
            currency    = s.currency;
            price       = s.price;
            icon        = s.icon;
            tags        = s.tags;
            //
            lockedIcon = s.lockedIcon;
            levels     = s.levels;

            // Convert the data from json to dictionary
            _data.properties       = new Dictionary <string, int[]>();
            _data.propertiesString = new Dictionary <string, string>();

            // add default "locked" property
            if (!s.properties.Contains <string>("locked"))
            {
                s.properties.Add("locked");
            }

            // Build the new data
            if (string.IsNullOrEmpty(d.ps))
            {
                // Loop each properties and build a new array
                foreach (string prop in s.properties)
                {
                    int[] p = Enumerable.Repeat(0, levels.Count).ToArray();
                    if (prop == "locked")
                    {
                        for (int i = 0; i < p.Length; i++)
                        {
                            p[i] = s.levels[i].locked?1:0;
                        }
                    }
                    _data.properties.Add(prop, p);
                    _data.propertiesString.Add(prop, JsonHelper.ToJson(p));
                }

                // Convert the properties to json string
                if (s.properties.Count > 0)
                {
                    _data.ps = JsonUtility.ToJson(new Serializer <string, string>(_data.propertiesString));
                }

//				Save();
            }
            else
            {
                // Update the data if data exist

                bool needSave = false;
                // Convert properties from json string
                _data.propertiesString = JsonUtility.FromJson <Serializer <string, string> >(d.ps).ToDictionary();

                // loop each properties
                foreach (string prop in s.properties)
                {
                    // Debug.Log(prop);
                    // if already in the json string
                    if (_data.propertiesString.ContainsKey(prop))
                    {
                        // convert json to array
                        int[] p = JsonHelper.FromJson <int>(_data.propertiesString[prop]);
                        // rebuild array if length < levels.count
                        if (p.Length < levels.Count)
                        {
                            List <int> temp = new List <int>(p);
                            // Add extra data
                            for (int i = p.Length; i < levels.Count; i++)
                            {
                                temp.Add(0);
                            }
                            // convert to array
                            p = temp.ToArray();
                            // for locked properties
                            if (prop == "locked")
                            {
                                for (int i = 0; i < p.Length; i++)
                                {
                                    p[i] = s.levels[i].locked?1:0;
                                }
                            }
                            // Re assign the data
                            _data.propertiesString[prop] = JsonHelper.ToJson(p);
                            needSave = true;
                        }
//						Debug.LogFormat("prop {0} json {1}",prop,_data.propertiesString[prop]);
                        //
                        _data.properties.Add(prop, p);
                    }
                    else
                    {
                        // if not, build a new one
                        int[] p = Enumerable.Repeat(0, levels.Count).ToArray();
                        if (prop == "locked")
                        {
                            for (int i = 0; i < p.Length; i++)
                            {
                                p[i] = s.levels[i].locked?1:0;
                            }
                        }
                        _data.properties.Add(prop, p);
                        _data.propertiesString.Add(prop, JsonHelper.ToJson(p));
                        needSave = true;
                    }
                }

                // Convert the properties to json string
                if (s.properties.Count > 0)
                {
                    _data.ps = JsonUtility.ToJson(new Serializer <string, string>(_data.propertiesString));
                }

                if (needSave)
                {
                    Save();
                }
            }
        }
Ejemplo n.º 5
0
        public IAPInventory(string uid, IAPInventorySetting s, IAPObjectData d, Action <IAPObject> callback = null) : base(uid, d, callback)
        {
            title       = s.title;
            description = s.description;
            currency    = s.currency;
            price       = s.price;
            icon        = s.icon;
            tags        = s.tags;
            //
            properties = new Dictionary <string, IAPProperty>();
            foreach (IAPProperty c in s.properties)
            {
                properties.Add(c.name, c);
            }

            // Convert the data from json to dictionary
            _data.propertiesString = new Dictionary <string, string>();

            // Build the new data
            if (string.IsNullOrEmpty(d.ps))
            {
                // Loop each properties and build a new array
                foreach (IAPProperty c in s.properties)
                {
                    _data.propertiesString.Add(c.name, c.value.ToString());
                }

                // Convert the properties to json string
                if (s.properties.Count > 0)
                {
                    _data.ps = JsonUtility.ToJson(new Serializer <string, string>(_data.propertiesString));
                }
            }
            else
            {
                // Update the data if data exist

                bool needSave = false;
                // Convert properties from json string
                _data.propertiesString = JsonUtility.FromJson <Serializer <string, string> >(d.ps).ToDictionary();

                // loop each properties
                foreach (KeyValuePair <string, IAPProperty> prop in properties)
                {
                    // if already in the json string
                    if (_data.propertiesString.ContainsKey(prop.Key))
                    {
                        prop.Value.value = Int32.Parse(_data.propertiesString[prop.Key]);
                        // needSave=true;
                    }
                    else
                    {
                        _data.propertiesString.Add(prop.Key, prop.Value.value.ToString());
                        needSave = true;
                    }
                }

                // Convert the properties to json string
                if (s.properties.Count > 0)
                {
                    _data.ps = JsonUtility.ToJson(new Serializer <string, string>(_data.propertiesString));
                }

                if (needSave)
                {
                    Save();
                }
            }
        }
Ejemplo n.º 6
0
        // Private Helpers

        virtual protected void InitData(IAPObjectData data)
        {
            _data = data;
        }
Ejemplo n.º 7
0
 public IAPObject(string uid, IAPObjectData data, Action <IAPObject> callback = null)
 {
     this.uid       = uid;
     this._callback = callback;
     InitData(data);
 }