Exemple #1
0
        internal void ObjectProcessComponent(int index, LineTypes.Component line, IParentObject obj, Stack <GameObject> objectStack, Stack <ParserContext> contextStack, ParserContext context)
        {
            #region Object context
            if (context == this.objectContext)
            {
                switch (index)
                {
                case 0:
                case 2:
                    return;

                case 1:
                    MeshFilter   filter   = objectStack.Peek().AddComponent <MeshFilter>();
                    MeshRenderer renderer = objectStack.Peek().AddComponent <MeshRenderer>();
                    filter.mesh       = Utility.MeshHelper.GetQuad();
                    renderer.material = new Material(Shader.Find("Standard"));
                    return;
                }
            }
            #endregion

            if (context == this.objectContext.Components[2].context)
            {
                // COLLIDER

                // todo: this
            }

            // other components that have sub-components

            throw new Exception("Invalid member in parsed lines list");
        }
Exemple #2
0
            internal override void ProcessProperty(int index, LineTypes.Property line, IParentObject obj, Stack<GameObject> objectStack, ParserContext context)
            {
                if (objectStack.Count > 0) {
                    base.ObjectProcessProperty(index, line, obj, objectStack, context);
                    return;
                }

                if (context == this.context) {
                    ShipTilePrefab tile = (ShipTilePrefab)obj;

                    switch (index) {
                        case 0:
                            tile.ID = line.argumentsData[0].ToString();
                            break;
                        case 1:
                            tile.EditorName = line.argumentsData[0].ToString();
                            break;
                        case 2:
                            tile.EditorDescription = line.argumentsData[0].ToString();
                            break;
                        case 3:
                            tile.EditorThumbnail = (Texture2D)line.argumentsData[0];
                            break;
                        case 4:
                            tile.Mass = (float)line.argumentsData[0];
                            break;
                        case 5:
                            tile.HP = (int)line.argumentsData[0];
                            break;
                    }
                    return;
                }

                throw new Exception("Invalid member in parsed lines list");
            }
        private void ExpandParent(IParentObject parentObject, int position)
        {
            var parentWrapper = (ParentWrapper)_adapterHelper.GetHelperItemAtPosition(position);

            if (parentWrapper == null)
            {
                return;
            }

            if (parentWrapper.Expanded)
            {
                parentWrapper.Expanded = false;

                if (_expandCollapseListener != null)
                {
                    var expandedCountBeforePosition = GetExpandedItemCount(position);
                    _expandCollapseListener.OnRecyclerViewItemCollapsed(position - expandedCountBeforePosition);
                }

                // Was Java HashMap put, need to replace the value
                _stableIdMap[parentWrapper.StableId] = false;
                //_stableIdMap.Add(parentWrapper.StableId, false);
                var childObjectList = ((IParentObject)parentWrapper.ParentObject).ChildObjectList;
                if (childObjectList != null)
                {
                    for (int i = childObjectList.Count - 1; i >= 0; i--)
                    {
                        var pos = position + i + 1;
                        _itemList.RemoveAt(pos);
                        _adapterHelper.HelperItemList.RemoveAt(pos);
                        NotifyItemRemoved(pos);
                    }
                }
            }
            else
            {
                parentWrapper.Expanded = true;

                if (_expandCollapseListener != null)
                {
                    var expandedCountBeforePosition = GetExpandedItemCount(position);
                    _expandCollapseListener.OnRecyclerViewItemExpanded(position - expandedCountBeforePosition);
                }

                // Was Java HashMap put, need to replace the value
                _stableIdMap[parentWrapper.StableId] = true;
                //_stableIdMap.Add(parentWrapper.StableId, true);
                var childObjectList = ((IParentObject)parentWrapper.ParentObject).ChildObjectList;
                if (childObjectList != null)
                {
                    for (int i = 0; i < childObjectList.Count; i++)
                    {
                        var pos = position + i + 1;
                        _itemList.Insert(pos, childObjectList[i]);
                        _adapterHelper.HelperItemList.Insert(pos, childObjectList[i]);
                        NotifyItemInserted(pos);
                    }
                }
            }
        }
Exemple #4
0
        internal void ObjectProcessComponent(int index, LineTypes.Component line, IParentObject obj, Stack<GameObject> objectStack, Stack<ParserContext> contextStack, ParserContext context)
        {
            #region Object context
            if (context == this.objectContext) {
                switch (index) {
                    case 0:
                    case 2:
                        return;
                    case 1:
                        MeshFilter filter = objectStack.Peek().AddComponent<MeshFilter>();
                        MeshRenderer renderer = objectStack.Peek().AddComponent<MeshRenderer>();
                        filter.mesh = Utility.MeshHelper.GetQuad();
                        renderer.material = new Material(Shader.Find("Standard"));
                        return;
                }
            }
            #endregion

            if (context == this.objectContext.Components[2].context) {
                // COLLIDER

                // todo: this
            }

            // other components that have sub-components

            throw new Exception("Invalid member in parsed lines list");
        }
Exemple #5
0
            internal override void FinalizeObject(IParentObject obj)
            {
                Floor tempObj = (Floor)obj;

                if (tempObj.name == "") throw new System.Exception("Name not assigned");
                if (tempObj.diffuse == null) throw new System.Exception("Diffuse texture not assigned");
                if (tempObj.normal == null) throw new System.Exception("Normal map not assigned");
            }
Exemple #6
0
            internal override void ProcessComponent(int index, LineTypes.Component line, IParentObject obj, Stack<GameObject> objectStack, Stack<ParserContext> contextStack, ParserContext context)
            {
                if (objectStack.Count > 0) {
                    base.ObjectProcessComponent(index, line, obj, objectStack, contextStack, context);
                    return;
                }

                throw new Exception("Invalid member in parsed lines list");
            }
Exemple #7
0
        public static void SetParent(object parent, object subObject)
        {
            IParentObject intf = subObject as IParentObject;

            if (intf != null)
            {
                intf.SetParent(parent);
            }
        }
Exemple #8
0
 internal override void ProcessProperty(int index, LineTypes.Property line, IParentObject obj, System.Collections.Generic.Stack<GameObject> objectStack, ParserContext context)
 {
     Floor tempObj = (Floor)obj;
     switch (index) {
         case 0:
             tempObj.name = line.argumentsData[0].ToString();
             break;
         case 1:
             tempObj.diffuse = (Texture2D)line.argumentsData[0];
             break;
         case 2:
             tempObj.normal = (Texture2D)line.argumentsData[0];
             break;
     }
 }
Exemple #9
0
            internal override void FinalizeObject(IParentObject obj)
            {
                Floor tempObj = (Floor)obj;

                if (tempObj.name == "")
                {
                    throw new System.Exception("Name not assigned");
                }
                if (tempObj.diffuse == null)
                {
                    throw new System.Exception("Diffuse texture not assigned");
                }
                if (tempObj.normal == null)
                {
                    throw new System.Exception("Normal map not assigned");
                }
            }
Exemple #10
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);
        }
Exemple #11
0
 private void PixelMapObject_OnParentChanged(IParentObject obj)
 {
     BasicPosition -= obj.GetGamePosition();
 }
Exemple #12
0
            internal override void ProcessProperty(int index, LineTypes.Property line, IParentObject obj, System.Collections.Generic.Stack <GameObject> objectStack, ParserContext context)
            {
                Floor tempObj = (Floor)obj;

                switch (index)
                {
                case 0:
                    tempObj.name = line.argumentsData[0].ToString();
                    break;

                case 1:
                    tempObj.diffuse = (Texture2D)line.argumentsData[0];
                    break;

                case 2:
                    tempObj.normal = (Texture2D)line.argumentsData[0];
                    break;
                }
            }
Exemple #13
0
        internal void ObjectProcessProperty(int index, LineTypes.Property line, IParentObject obj, Stack <GameObject> objectStack, ParserContext context)
        {
            #region Object context
            if (context == this.objectContext)
            {
                // properties for object itself (none atm)
                // return;
            }
            #endregion

            #region Transform
            if (context == this.objectContext.Components[0].context)
            {
                switch (index)
                {
                case 0:     // position
                    objectStack.Peek().transform.localPosition = (Vector3)line.argumentsData[0];
                    return;

                case 1:     // rotation
                    objectStack.Peek().transform.localRotation = Quaternion.Euler((Vector3)line.argumentsData[0]);
                    return;

                case 2:     // scale
                    objectStack.Peek().transform.localScale = (Vector3)line.argumentsData[0];
                    return;
                }
            }
            #endregion

            #region Renderer
            if (context == this.objectContext.Components[1].context)
            {
                MeshRenderer renderer = objectStack.Peek().GetComponent <MeshRenderer>();

                switch (index)
                {
                case 0:     // texture
                    renderer.sharedMaterial.SetTexture(line.argumentsData[0].ToString(), (Texture2D)line.argumentsData[1]);
                    return;

                case 1:     // texture scale
                    renderer.sharedMaterial.SetTextureScale(line.argumentsData[0].ToString(), (Vector2)line.argumentsData[1]);
                    return;

                case 2:     // texture offset
                    renderer.sharedMaterial.SetTextureOffset(line.argumentsData[0].ToString(), (Vector2)line.argumentsData[1]);
                    return;

                case 3:     // color
                    renderer.sharedMaterial.SetColor(line.argumentsData[0].ToString(), (Color)line.argumentsData[1]);
                    return;

                case 4:     // shader
                    renderer.sharedMaterial = new Material(Shader.Find(line.argumentsData[0].ToString()));
                    return;

                case 5:     // rendering mode
                    string mode = line.argumentsData[0].ToString().Trim().ToLower();
                    switch (mode)
                    {
                    case "opaque":
                        renderer.sharedMaterial.SetFloat("_Mode", 0);
                        break;

                    case "cutout":
                        renderer.sharedMaterial.SetFloat("_Mode", 1);
                        break;

                    case "fade":
                        renderer.sharedMaterial.SetFloat("_Mode", 2);
                        break;

                    case "transparent":
                        renderer.sharedMaterial.SetFloat("_Mode", 3);
                        break;

                    default:
                        throw new ParserExceptions.ParserEnumException(mode, "Opaque", "Cutout", "Fade", "Transparent");
                    }
                    return;

                default:
                    throw new Exception("Invalid member in parsed lines list");
                }
            }
            #endregion

            // todo: other contexts

            throw new Exception("Invalid member in parsed lines list");
        }
Exemple #14
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");
            }
        }
Exemple #15
0
 internal virtual void FinalizeObject(IParentObject obj)
 {
     // overload if needed and do finishing touches to object
 }
Exemple #16
0
 internal virtual void ProcessComponent(int index, LineTypes.Component line, IParentObject obj, Stack <GameObject> objectStack, Stack <ParserContext> contextStack, ParserContext context)
 {
     // overload with switch-case and handle functionalities
     throw new Exception("Invalid member in parsed lines list");
 }
Exemple #17
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");
            }
        }
Exemple #18
0
 internal virtual void FinalizeObject(IParentObject obj)
 {
     // overload if needed and do finishing touches to object
 }
Exemple #19
0
 internal virtual void ProcessProperty(int index, LineTypes.Property line, IParentObject obj, Stack<GameObject> objectStack, ParserContext context)
 {
     // overload with switch-case and handle functionalities
     throw new Exception("Invalid member in parsed lines list");
 }
Exemple #20
0
        internal void ObjectProcessProperty(int index, LineTypes.Property line, IParentObject obj, Stack<GameObject> objectStack, ParserContext context)
        {
            #region Object context
            if (context == this.objectContext) {
                // properties for object itself (none atm)
                // return;
            }
            #endregion

            #region Transform
            if (context == this.objectContext.Components[0].context) {
                switch (index) {
                    case 0: // position
                        objectStack.Peek().transform.localPosition = (Vector3)line.argumentsData[0];
                        return;
                    case 1: // rotation
                        objectStack.Peek().transform.localRotation = Quaternion.Euler((Vector3)line.argumentsData[0]);
                        return;
                    case 2: // scale
                        objectStack.Peek().transform.localScale = (Vector3)line.argumentsData[0];
                        return;
                }
            }
            #endregion

            #region Renderer
            if (context == this.objectContext.Components[1].context) {

                MeshRenderer renderer = objectStack.Peek().GetComponent<MeshRenderer>();

                switch (index) {
                    case 0: // texture
                        renderer.sharedMaterial.SetTexture(line.argumentsData[0].ToString(), (Texture2D)line.argumentsData[1]);
                        return;
                    case 1: // texture scale
                        renderer.sharedMaterial.SetTextureScale(line.argumentsData[0].ToString(), (Vector2)line.argumentsData[1]);
                        return;
                    case 2: // texture offset
                        renderer.sharedMaterial.SetTextureOffset(line.argumentsData[0].ToString(), (Vector2)line.argumentsData[1]);
                        return;
                    case 3: // color
                        renderer.sharedMaterial.SetColor(line.argumentsData[0].ToString(), (Color)line.argumentsData[1]);
                        return;
                    case 4: // shader
                        renderer.sharedMaterial = new Material(Shader.Find(line.argumentsData[0].ToString()));
                        return;
                    case 5: // rendering mode
                        string mode = line.argumentsData[0].ToString().Trim().ToLower();
                        switch (mode) {
                            case "opaque":
                                renderer.sharedMaterial.SetFloat("_Mode", 0);
                                break;
                            case "cutout":
                                renderer.sharedMaterial.SetFloat("_Mode", 1);
                                break;
                            case "fade":
                                renderer.sharedMaterial.SetFloat("_Mode", 2);
                                break;
                            case "transparent":
                                renderer.sharedMaterial.SetFloat("_Mode", 3);
                                break;
                            default:
                                throw new ParserExceptions.ParserEnumException(mode, "Opaque", "Cutout", "Fade", "Transparent");
                        }
                        return;
                    default:
                        throw new Exception("Invalid member in parsed lines list");
                }
            }
            #endregion

            // todo: other contexts

            throw new Exception("Invalid member in parsed lines list");
        }
Exemple #21
0
 private void PixelMapObject_OnParentRemoved(IParentObject obj)
 {
     BasicPosition += obj.GetGamePosition();
 }
Exemple #22
0
            internal override void ProcessProperty(int index, LineTypes.Property line, IParentObject obj, Stack <GameObject> objectStack, ParserContext context)
            {
                if (objectStack.Count > 0)
                {
                    base.ObjectProcessProperty(index, line, obj, objectStack, context);
                    return;
                }

                if (context == this.context)
                {
                    ShipTilePrefab tile = (ShipTilePrefab)obj;

                    switch (index)
                    {
                    case 0:
                        tile.ID = line.argumentsData[0].ToString();
                        break;

                    case 1:
                        tile.EditorName = line.argumentsData[0].ToString();
                        break;

                    case 2:
                        tile.EditorDescription = line.argumentsData[0].ToString();
                        break;

                    case 3:
                        tile.EditorThumbnail = (Texture2D)line.argumentsData[0];
                        break;

                    case 4:
                        tile.Mass = (float)line.argumentsData[0];
                        break;

                    case 5:
                        tile.HP = (int)line.argumentsData[0];
                        break;
                    }
                    return;
                }

                throw new Exception("Invalid member in parsed lines list");
            }
Exemple #23
0
            internal override void ProcessComponent(int index, LineTypes.Component line, IParentObject obj, Stack <GameObject> objectStack, Stack <ParserContext> contextStack, ParserContext context)
            {
                if (objectStack.Count > 0)
                {
                    base.ObjectProcessComponent(index, line, obj, objectStack, contextStack, context);
                    return;
                }

                throw new Exception("Invalid member in parsed lines list");
            }