Esempio n. 1
0
        private void AddNewCurrency(string newCurrencyName)
        {
            bool isUniqueCurrencyName = true;

            foreach (AccountManagerSettings.CurrecnyInfo currencyInfo in _reference.listOfCurrencyInfos)
            {
                if (StringOperation.IsSameString(currencyInfo.enumName, newCurrencyName))
                {
                    isUniqueCurrencyName = false;
                    break;
                }
            }

            foreach (AccountManagerSettings.CurrecnyInfo currencyInfo in _listOfCurrencyToBeAdded)
            {
                if (StringOperation.IsSameString(currencyInfo.enumName, newCurrencyName))
                {
                    isUniqueCurrencyName = false;
                    break;
                }
            }

            if (isUniqueCurrencyName)
            {
                AccountManagerSettings.CurrecnyInfo newCurrency = new AccountManagerSettings.CurrecnyInfo()
                {
                    enumName = newCurrencyName
                };

                _listOfCurrencyToBeAdded.Add(newCurrency);
                _flagedForGeneratingEnum = true;

                return;
            }

            Debug.LogError("The following currency name is already in used : " + newCurrencyName);
        }
Esempio n. 2
0
        private void GenerateEnum()
        {
            int numberOfCurrencyAlreadyInList = _reference.listOfCurrencyInfos.Count;
            int numberOfCurrencyToBeAdded     = _listOfCurrencyToBeAdded.Count;

            string path = "";

            if (_packageStatus == CoreEnums.CorePackageStatus.InDevelopment)
            {
                path += "Assets/com.faith.core/Runtime/AccountManager";
            }
            else
            {
                path += "Packages/com.faith.core/Runtime/AccountManager";
            }

            path += "/AccountManagerCurrencyEnum.cs";

            using (StreamWriter streamWriter = new StreamWriter(path)) {
                string scriptData = "namespace com.faith.core";
                scriptData += "\n{";
                scriptData += "\n\tpublic enum AccountManagerCurrencyEnum";
                scriptData += "\n\t{";
                //Starting

                for (int i = 0; i < numberOfCurrencyAlreadyInList; i++)
                {
                    scriptData += "\n\t\t" + _reference.listOfCurrencyInfos[i].enumName.ToUpper();

                    if (i == (numberOfCurrencyAlreadyInList - 1))
                    {
                        if (numberOfCurrencyToBeAdded > 0)
                        {
                            scriptData += ",";
                        }
                    }
                    else
                    {
                        scriptData += ",";
                    }
                }

                for (int i = 0; i < numberOfCurrencyToBeAdded; i++)
                {
                    scriptData += "\n\t\t" + _listOfCurrencyToBeAdded[i].enumName.ToUpper();
                    if (i == 0 && numberOfCurrencyToBeAdded > 0 && numberOfCurrencyAlreadyInList > 0)
                    {
                        scriptData += ",";
                    }
                    else if (i < (numberOfCurrencyToBeAdded - 1))
                    {
                        scriptData += ",";
                    }
                }


                //Ending
                scriptData += "\n\t}";
                scriptData += "\n}";

                streamWriter.Write(scriptData);
            }

            AssetDatabase.Refresh();

            for (int i = 0; i < numberOfCurrencyToBeAdded; i++)
            {
                AccountManagerSettings.CurrecnyInfo currencyInfo = _listOfCurrencyToBeAdded[0];
                _reference.listOfCurrencyInfos.Add(currencyInfo);
                _listOfCurrencyToBeAdded.RemoveAt(0);
            }
            _listOfCurrencyInfos.serializedObject.ApplyModifiedProperties();
        }