예제 #1
0
        static private void SetReflectedObject(UnityEngine.Object inRoot, string inPath, object inValue)
        {
            inPath = inPath.Replace("Array.data", "");

            // locate the parent object
            StringSlice path    = inPath;
            int         lastDot = path.LastIndexOf('.');

            if (lastDot < 0)
            {
                return;
            }

            StringSlice parentPath   = path.Substring(0, lastDot);
            StringSlice fieldName    = path.Substring(lastDot + 1);
            object      parentObject = LocateReflectedObject(inRoot, parentPath.ToString());

            if (parentObject == null)
            {
                return;
            }

            Type objType  = parentObject.GetType();
            int  arrayIdx = -1;

            // capture array
            if (fieldName.EndsWith(']'))
            {
                int         elementIndexStart = fieldName.IndexOf('[');
                int         length            = fieldName.Length - elementIndexStart - 1;
                StringSlice elementIndexSlice = fieldName.Substring(elementIndexStart + 1, length);
                arrayIdx  = Convert.ToInt32(elementIndexSlice.ToString());
                fieldName = fieldName.Substring(0, elementIndexStart);
            }

            FieldInfo field = objType.GetField(fieldName.ToString(), InstanceBindingFlags);

            if (field == null)
            {
                return;
            }

            if (arrayIdx >= 0)
            {
                IList list = field.GetValue(parentObject) as IList;
                if (list != null)
                {
                    list[arrayIdx] = inValue;
                }
                return;
            }

            field.SetValue(parentObject, inValue);
        }
예제 #2
0
        /// <summary>
        /// Returns the parent property.
        /// </summary>
        static public SerializedProperty FindPropertyParent(this SerializedProperty inProperty)
        {
            StringSlice path    = inProperty.propertyPath.Replace("Array.data", "");
            int         lastDot = path.LastIndexOf('.');

            if (lastDot < 0)
            {
                return(null);
            }

            StringSlice parentPath = path.Substring(0, lastDot);

            return(inProperty.serializedObject.FindProperty(parentPath.ToString()));
        }
예제 #3
0
        static private string GetLocationFromTrace(string inTrace)
        {
            foreach (var line in StringSlice.EnumeratedSplit(inTrace, StringUtils.DefaultNewLineChars, StringSplitOptions.RemoveEmptyEntries))
            {
                int atIndex = line.IndexOf(" (at ");
                if (atIndex > 0)
                {
                    StringSlice method   = line.Substring(0, atIndex).Trim();
                    StringSlice location = line.Substring(atIndex + 5);
                    location = location.Substring(0, location.Length - 1).Trim();

                    // ignore locations with < or >, these are internal and not helpfuls
                    if (location.Contains('<') || location.Contains('>'))
                    {
                        continue;
                    }

                    int param = method.IndexOf('(');
                    if (param > 0)
                    {
                        method = method.Substring(0, param).Trim();
                    }

                    int lineNum = 0;
                    int colon   = location.IndexOf(':');
                    if (colon > 0)
                    {
                        StringSlice lineNumStr = location.Substring(colon + 1);
                        lineNum  = StringParser.ParseInt(lineNumStr);
                        location = location.Substring(0, colon).Trim();
                    }

                    int lastSlash = location.LastIndexOf('/');
                    if (lastSlash >= 0)
                    {
                        location = location.Substring(lastSlash + 1);
                    }
                    return(string.Format("{0} @{1}:{2}", method, lastSlash, lineNum));
                }
            }
            return(StackTraceDisabledMessage);
        }
예제 #4
0
        public static MatchedTextRange?SearchInText(
            this SearchState state,
            StringSlice text,
            int?startTextPosition)
        {
            IRegex re = state.re;

            // matched string position
            int  matchBegin       = 0;    // index of the first matched char
            int  matchEnd         = 0;    // index of following after the last matched one
            bool wholeTextMatched = false;

            if (!string.IsNullOrEmpty(state.options.Template))             // empty/null template means that text matching isn't required, i.e. match any input
            {
                int textPos;

                if (startTextPosition.HasValue)
                {
                    textPos = startTextPosition.Value;
                }
                else if (state.options.ReverseSearch)
                {
                    textPos = text.Length;
                }
                else
                {
                    textPos = 0;
                }

                for (; ;)
                {
                    if (re != null)
                    {
                        if (!re.Match(text, textPos, ref state.searchMatch))
                        {
                            return(null);
                        }
                        matchBegin = state.searchMatch.Index;
                        matchEnd   = matchBegin + state.searchMatch.Length;
                    }
                    else
                    {
                        StringComparison cmp = state.options.MatchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
                        int i;
                        // todo: use running hash
                        if (state.options.ReverseSearch)
                        {
                            i = text.LastIndexOf(state.options.Template, textPos, cmp);
                        }
                        else
                        {
                            i = text.IndexOf(state.options.Template, textPos, cmp);
                        }
                        if (i < 0)
                        {
                            return(null);
                        }
                        matchBegin = i;
                        matchEnd   = matchBegin + state.options.Template.Length;
                    }

                    if (state.options.WholeWord && !IsWordBoundary(text, matchBegin, matchEnd))
                    {
                        textPos = state.options.ReverseSearch ? matchBegin : matchEnd;
                        continue;
                    }

                    break;
                }
            }
            else
            {
                matchBegin       = 0;
                matchEnd         = text.Length;
                wholeTextMatched = true;
            }

            return(new MatchedTextRange(text, matchBegin, matchEnd, wholeTextMatched));
        }