Example #1
0
    private void Awake()
    {
        //instance = this;
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
    }
Example #2
0
        /// <summary>Creates a formatting string basing on an actual content of a line.</summary>
        public string ExtractFormat(string content)
        {
            //bool afterKey = false; bool beforeVal = false; bool beforeEvery = true; bool afterVal = false;
            //return IniFileEx.DefaultValueFormatting;
            FEState pos = FEState.BeforeEvery;
            string  insideWhiteChars = "";

            StringBuilder form = new StringBuilder();

            for (int i = 0; i < content.Length; i++)
            {
                char currC = content[i];
                if (char.IsLetterOrDigit(currC))
                {
                    if (pos == FEState.BeforeEvery)
                    {
                        form.Append('?');
                        pos = FEState.AfterKey;
                        //afterKey = true; beforeEvery = false; ;
                    }
                    else if (pos == FEState.BeforeVal)
                    {
                        form.Append('$');
                        pos = FEState.AfterVal;
                    }
                }
                else if (pos == FEState.AfterKey && content.Length - i >= IniFileEx.EqualsString.Length && content.Substring(i, IniFileEx.EqualsString.Length) == IniFileEx.EqualsString)
                {
                    form.Append(insideWhiteChars);
                    pos = FEState.BeforeVal;
                    //afterKey = false; beforeVal = true;
                    form.Append('=');
                }
                else if ((OfAny(i, content, IniFileEx.CommentChars)) != null)
                {
                    form.Append(insideWhiteChars);
                    form.Append(';');
                }
                else if (char.IsWhiteSpace(currC))
                {
                    string theWhiteChar;
                    if (currC == '\t' && IniFileEx.TabReplacement != null)
                    {
                        theWhiteChar = IniFileEx.TabReplacement;
                    }
                    else
                    {
                        theWhiteChar = currC.ToString();
                    }

                    if (pos == FEState.AfterKey || pos == FEState.AfterVal)
                    {
                        insideWhiteChars += theWhiteChar;
                        continue;
                    }

                    form.Append(theWhiteChar);
                }
                insideWhiteChars = "";
            }
            if (pos == FEState.BeforeVal)
            {
                form.Append('$');
                pos = FEState.AfterVal;
            }
            string ret = form.ToString();

            if (ret.IndexOf(';') == -1)
            {
                ret += "   ;";
            }
            return(ret);
        }