Ejemplo n.º 1
0
        internal object Generate()
        {
            IParentObject         rootObject   = GenerateSetupObject();
            Stack <ParserContext> contextStack = new Stack <ParserContext>();
            Stack <GameObject>    objectStack  = new Stack <GameObject>();

            contextStack.Push(this.context);

            while (Lines.Count > 0)
            {
                IParserLine tempLine = Lines[0];
                ProcessLine(rootObject, contextStack, objectStack, tempLine);
                Lines.RemoveAt(0);
            }

            FinalizeObject(rootObject);

            return(rootObject);
        }
Ejemplo n.º 2
0
        private void ProcessLine(IParentObject rootObject, Stack<ParserContext> contextStack, Stack<GameObject> objectStack, IParserLine tempLine)
        {
            LineType type = tempLine.GetType();
            ParserContext currentContext = contextStack.Peek();

            int index = -1;

            switch (type) {
                case LineType.Property:
                    LineTypes.Property lineProperty = (LineTypes.Property)tempLine;

                    for (int i = 0; i < currentContext.Properties.Length; i++) {
                        if (currentContext.Properties[i].name == lineProperty.name) {
                            index = i;
                            break;
                        }
                    }
                    if (index == -1) throw new Exception("Invalid member in parsed lines list");
                    ProcessProperty(index, lineProperty, rootObject, objectStack, currentContext);
                    break;
                case LineType.Component:
                    LineTypes.Component lineComponent = (LineTypes.Component)tempLine;

                    for (int i = 0; i < currentContext.Components.Length; i++) {
                        if (currentContext.Components[i].name == lineComponent.name) {
                            index = i;
                            break;
                        }
                    }
                    if (index == -1) throw new Exception("Invalid member in parsed lines list");
                    ProcessComponent(index, lineComponent, rootObject, objectStack, contextStack, currentContext);
                    contextStack.Push(currentContext.Components[index].context);
                    break;
                case LineType.Object:
                    LineTypes.Object lineObject = (LineTypes.Object)tempLine;

                    GameObject tempGO = new GameObject();
                    tempGO.name = lineObject.name;
                    tempGO.SetActive(false);

                    if (objectStack.Count > 0) tempGO.transform.parent = objectStack.Peek().transform;
                    rootObject.AssignChild(tempGO);

                    objectStack.Push(tempGO);
                    contextStack.Push(this.objectContext);
                    break;
                case LineType.ObjectClose:
                case LineType.ComponentClose:
                    contextStack.Pop();
                    break;
                default:
                    throw new System.Exception("Invalid line type in parsed lines list");
            }
        }
Ejemplo n.º 3
0
        private void ProcessLine(IParentObject rootObject, Stack <ParserContext> contextStack, Stack <GameObject> objectStack, IParserLine tempLine)
        {
            LineType      type           = tempLine.GetType();
            ParserContext currentContext = contextStack.Peek();

            int index = -1;

            switch (type)
            {
            case LineType.Property:
                LineTypes.Property lineProperty = (LineTypes.Property)tempLine;

                for (int i = 0; i < currentContext.Properties.Length; i++)
                {
                    if (currentContext.Properties[i].name == lineProperty.name)
                    {
                        index = i;
                        break;
                    }
                }
                if (index == -1)
                {
                    throw new Exception("Invalid member in parsed lines list");
                }
                ProcessProperty(index, lineProperty, rootObject, objectStack, currentContext);
                break;

            case LineType.Component:
                LineTypes.Component lineComponent = (LineTypes.Component)tempLine;

                for (int i = 0; i < currentContext.Components.Length; i++)
                {
                    if (currentContext.Components[i].name == lineComponent.name)
                    {
                        index = i;
                        break;
                    }
                }
                if (index == -1)
                {
                    throw new Exception("Invalid member in parsed lines list");
                }
                ProcessComponent(index, lineComponent, rootObject, objectStack, contextStack, currentContext);
                contextStack.Push(currentContext.Components[index].context);
                break;

            case LineType.Object:
                LineTypes.Object lineObject = (LineTypes.Object)tempLine;

                GameObject tempGO = new GameObject();
                tempGO.name = lineObject.name;
                tempGO.SetActive(false);

                if (objectStack.Count > 0)
                {
                    tempGO.transform.parent = objectStack.Peek().transform;
                }
                rootObject.AssignChild(tempGO);

                objectStack.Push(tempGO);
                contextStack.Push(this.objectContext);
                break;

            case LineType.ObjectClose:
            case LineType.ComponentClose:
                contextStack.Pop();
                break;

            default:
                throw new System.Exception("Invalid line type in parsed lines list");
            }
        }