예제 #1
0
    public override void Parse(GTTreeNode treeNode)
    {
        if (null == treeNode)
            return;

        GTTreeNode tnLife = treeNode.GetChild("Life");
        GTTreeNode tnMovementSpeed = treeNode.GetChild("MovementSpeed");
        base.movementSpeed = (tnMovementSpeed != null) ? tnMovementSpeed.AsInt() : 10;
        GTTreeNode tnFloatingEnable = treeNode.GetChild("FloatingEnable");
        base.floatingEnable = (tnFloatingEnable != null) ? tnFloatingEnable.AsBool() : false;
        GTTreeNode tnFloatingSpeed = treeNode.GetChild("FloatingSpeed");
        base.floatingSpeed = (tnFloatingSpeed != null) ? tnFloatingSpeed.AsFloat() : 2.5f;
        GTTreeNode tnFloatingMax = treeNode.GetChild("FloatingMax");
        base.floatingMax = (tnFloatingMax != null) ? tnFloatingMax.AsFloat() : 1.0f;
        GTTreeNode tnMoveLeftLimit = treeNode.GetChild("MoveLeftLimit");
        mMoveLeftLimit=(tnMoveLeftLimit!=null)?tnMoveLeftLimit.AsFloat():40.0f;
        GTTreeNode tnMoveRightLimit = treeNode.GetChild("MoveRightLimit");
        mMoveRightLimit = (tnMoveRightLimit != null) ? tnMoveRightLimit.AsFloat() : 400.0f;        

        //Life = 50
        //LifeMax = 50
        //Attack = 10
        //AttackSpeed = 1
        //AttackRange = 3
        //Armor = 1			
        //Experience = 10
        //ExperienceForNextLevel = 40
        //Money = 700
        //Level = 1
        //SkillPoint = 60
        //SkillPointMax = 60
        //DefaultDirection = 0
    }
예제 #2
0
    /// <summary>
    /// Create button object
    /// </summary>
    /// <param name="treeNode"></param>
    /// <param name="parent"></param>
    /// <param name="canvas"></param>
    /// <returns></returns>
    private bool CreateButton(GTTreeNode treeNode, GTUIWidget parent, GTUICanvas canvas)
    {
        if (treeNode == null || parent == null || null == canvas)
            return false;

        string name = (treeNode.AsString() != string.Empty) ? treeNode.AsString() : "_UIButtonNoName";
        GTTreeNode nodePosition = treeNode.GetChild(TagPosition);
        GTTreeNode nodeSize = treeNode.GetChild(TagSize);
        GTTreeNode nodePieceEnabled = treeNode.GetChild(TagPieceEnabled);
        GTTreeNode nodeEventType = treeNode.GetChild(TagEventType);
        GTTreeNode nodeVisible = treeNode.GetChild(TagVisible);
        GTTreeNode nodeAnchorPoint = treeNode.GetChild(TagAnchorPoint);
        GTTreeNode nodeColor = treeNode.GetChild(TagColor);
        GTTreeNode nodeChildren = treeNode.GetChild(TagChildren);
        GTTreeNode nodeText = treeNode.GetChild(TagText);
        GTTreeNode nodeFont = treeNode.GetChild(TagFont);
        GTTreeNode nodeFontSize = treeNode.GetChild(TagFontSize);

        Vector3 position = (nodePosition != null) ? nodePosition.AsVector3() : new Vector3(0.0f, 0.0f, 0.0f);
        Vector2 size = (nodeSize != null) ? nodeSize.AsVector2() : new Vector2(0.0f, 0.0f);
        string pieceName = (nodePieceEnabled != null) ? nodePieceEnabled.AsString() : "_noPieceName";
        Vector2 anchor = (nodeAnchorPoint != null) ? nodeAnchorPoint.AsVector2() : new Vector2(0.0f, 0.0f);
        Vector3 vColor = (nodeColor != null) ? nodeColor.AsVector3() : new Vector3(255.0f, 255.0f, 255.0f);
        Color color = new Color(vColor.x / 255.0f, vColor.y / 255.0f, vColor.z / 255.0f);
        string text = (nodeText != null) ? nodeText.AsString() : "Button";
        string fontName = (nodeFont != null) ? nodeFont.AsString() : "BabelSans";
        int fontSize = (nodeFontSize != null) ? nodeFontSize.AsInt() : 16;
                
        GTUIButton button = GTUIButton.Create(name, position, size, parent.mGameObject);
        if (button == null)
        {
            Debug.LogError("CreateButton: Failed to create a button object: " + name);
            return false;
        }
        button.color = color;
        button.text = text;
        button.mText.textFont = GTUIManager.Instance.GetFont(fontName);
        button.mText.fontSize = fontSize;
        // Sprite
        Sprite sprite = canvas.mSkin.mFrameSet[pieceName];
        if (sprite != null)
            button.sprite = canvas.mSkin.mFrameSet[pieceName];
        else
            Debug.LogWarning("CreateButton: No piece sprite found: " + pieceName);
        //btn1.clickEvent.AddListener(OnBtnClick);

        // Children
        CreateChildren(nodeChildren, button, canvas);

        return true;
    }
예제 #3
0
    /// <summary>
    /// Create a sprite from the atlas
    /// </summary>
    /// <param name="spriteAtlas"></param>
    /// <returns></returns>
    public bool Create(GTSpriteAtlasCocos2D spriteAtlas, GTTreeNode tnSprite)
    {
        if (null == spriteAtlas || spriteAtlas.frameCount == 0)
            return false;

        GTTreeNode tnAnimation = tnSprite.GetChild(GTPropertyFile.TagAnimation);
        GTTreeNode tnAnchor = tnSprite.GetChild(GTPropertyFile.TagAnchor);
        Vector2 pivot = GTSpriteFrameSet.PivotCenter;
        if (tnAnchor != null)
            pivot = tnAnchor.AsVector2();

        if (tnAnimation != null && tnAnimation.childCount != 0)
        {
            mFrameSet = new GTSpriteFrameSet[tnAnimation.childCount];
            // Create each frameset
            for (int childIndex = 0; childIndex < tnAnimation.childCount; childIndex++)
            {
                GTTreeNode tnFramdset = tnAnimation.GetChild(childIndex);
                if (tnFramdset != null)
                {
                    GTTreeNode tnFPS = tnFramdset.GetChild(GTPropertyFile.TagFPS);
                    GTTreeNode tnStartFrame = tnFramdset.GetChild(GTPropertyFile.TagStartFrame);
                    GTTreeNode tnFrameCount = tnFramdset.GetChild(GTPropertyFile.TagFrameCount);
                    if (tnStartFrame == null)
                        Debug.LogError("Couldn't find StartFrame in GTTreeNode !");
                    if (tnFrameCount == null)
                        Debug.LogError("Couldn't find FrameCount in GTTreeNode !");
                    if (tnStartFrame != null && tnFrameCount != null)
                    {
                        mFrameSet[childIndex] = new GTSpriteFrameSet();
                        mFrameSet[childIndex].name = tnFramdset.AsString();
                        mFrameSet[childIndex].Create(
                            spriteAtlas,
                            tnStartFrame.AsInt(),
                            tnFrameCount.AsInt(),
                            pivot
                            );
                        if (tnFPS != null)
                        {
                            mFrameSet[childIndex].FPS = tnFPS.AsFloat();
                        }
                    }

                    if(!mFrameSetNameDic.ContainsKey(tnFramdset.AsString()))
                        mFrameSetNameDic.Add(tnFramdset.AsString(), (uint)childIndex);
                }
            }
        }

        return true;
    }
예제 #4
0
    private bool CreateChildren(GTTreeNode treeNode, GTUIWidget parent, GTUICanvas canvas)
    {
        if (treeNode == null)
            return false;

        for (int child = 0; child < treeNode.childCount; child++)
        {
            GTTreeNode childNode = treeNode.GetChild(child);
            if (childNode == null)
                continue;

            switch (childNode.tag)
            {
                case TagUIImage:
                    CreateImage(childNode, parent, canvas);
                    break;

                case TagUIButton:
                    CreateButton(childNode, parent, canvas);
                    break;
            }
        }

        return true;
    }
예제 #5
0
    /// <summary>
    /// Create image object
    /// </summary>
    /// <param name="treeNode"></param>
    /// <param name="parent"></param>
    /// <param name="canvas"></param>
    /// <returns></returns>
    private bool CreateImage(GTTreeNode treeNode, GTUIWidget parent, GTUICanvas canvas)
    {
        if (treeNode == null || parent == null || null == canvas)
            return false;

        string name = (treeNode.AsString() != string.Empty) ? treeNode.AsString() : "_UIImageNoName";
        GTTreeNode nodePosition = treeNode.GetChild(TagPosition);
        GTTreeNode nodeSize = treeNode.GetChild(TagSize);
        GTTreeNode nodePieceEnabled = treeNode.GetChild(TagPieceEnabled);
        GTTreeNode nodeEventType = treeNode.GetChild(TagEventType);
        GTTreeNode nodeVisible = treeNode.GetChild(TagVisible);
        GTTreeNode nodeAnchorPoint = treeNode.GetChild(TagAnchorPoint);
        GTTreeNode nodeColor = treeNode.GetChild(TagColor);
        GTTreeNode nodeChildren = treeNode.GetChild(TagChildren);

        Vector3 position = (nodePosition != null) ? nodePosition.AsVector3() : new Vector3(0.0f, 0.0f, 0.0f);
        Vector2 size = (nodeSize != null) ? nodeSize.AsVector2() : new Vector2(0.0f, 0.0f);
        string pieceName = (nodePieceEnabled != null) ? nodePieceEnabled.AsString() : "_noPieceName";
        Vector2 anchor = (nodeAnchorPoint != null) ? nodeAnchorPoint.AsVector2() : new Vector2(0.0f, 0.0f);
        Vector3 vColor = (nodeColor != null) ? nodeColor.AsVector3() : new Vector3(255.0f, 255.0f, 255.0f);
        Color color = new Color(vColor.x / 255.0f, vColor.y / 255.0f, vColor.z / 255.0f);

        GTUIImage image = GTUIImage.Create(name, position, size, parent.mGameObject);
        if (image == null)
        {
            Debug.LogError("CreateImage: Failed to create an image object: " + name);
            return false;
        }
        image.color = color;
        // Sprite
        Sprite sprite = canvas.mSkin.mFrameSet[pieceName];
        if (sprite != null)
            image.sprite = canvas.mSkin.mFrameSet[pieceName];
        else
            Debug.LogWarning("CreateImage: No piece sprite found: " + pieceName);

        // Children
        CreateChildren(nodeChildren, image, canvas);

        return true;
    }
예제 #6
0
    /// <summary>
    /// Create cavans object
    /// </summary>
    /// <param name="treeNode"></param>
    /// <returns></returns>
    private bool CreateCanvas(GTTreeNode treeNode)
    {
        if (treeNode == null)
            return false;
        if (treeNode.tag != TagUICanvas)
            return false;

        // Use specified or default name
        string name = (treeNode.AsString() != string.Empty) ? treeNode.AsString() : "_UICanvasNoName";
        GTUICanvas canvas = GTUICanvas.Create(name);

        for (int child = 0; child < treeNode.childCount; child++)
        {
            GTTreeNode childNode = treeNode.GetChild(child);
            if (childNode == null)
                continue;

            switch (childNode.tag)
            {
                case TagSkin:
                    {
                        string skinFileName = childNode.AsString();
                        if (skinFileName != string.Empty)
                        {
                            // Check if this skin object is loaded already
                            if(!mSkins.ContainsKey(skinFileName))
                            {
                                // Not load yet
                                GTUISkin skin = GTUISkin.Create(skinFileName);
                                if (skin != null)
                                {
                                    mSkins.Add(skinFileName, skin);
                                    canvas.mSkin = skin;
                                    mCanvases.Add(name, canvas);
                                }
                                else
                                    Debug.LogError("CreateCanvas: Failed to load GTUISkin: " + childNode.AsString());
                            }
                        }
                    }
                    break;

                case TagFont:
                    break;

                case TagPosition:
                    break;

                case TagSize:
                    break;

                case TagVisible:
                    break;

                case TagEventType:
                    break;

                case TagChildren:
                    CreateChildren(childNode, canvas as GTUIWidget, canvas);
                    break;
            }
        }

        return true;
    }
예제 #7
0
	/// <summary>
	/// Parses a string representation of the tree and fills out the hierarchy.
    /// Supports GTTreeNode as well as JSON formats.
	/// </summary>
	/// <param name="text">Text to parse.</param>
	/// <returns>Newly created tree or 'null' if parsing was not successful.</returns>

    static public GTTreeNode FromString(string text)
	{
		if (text != null && text.Length > 1)
		{
			// Note: All Unicode files have the first character as 0xeff
			// Adding the check for text[0] = 0xfeff address this issue.
			if (text[0] == '{' || (text[0] == 0xfeff && text[1] == '{'))
			{
				text = JSONToTreeNode(text);
			}

			// Remove c++ style block comments (/* */)
            text = GTStringUtility.StripBlockComments(text);

			string[] lines = text.Split(new char[]{'\n'}, StringSplitOptions.RemoveEmptyEntries);

			if (lines.Length > 0)
			{
                GTTreeNode tree = new GTTreeNode();
				tree.ProcessLines(lines, 0);
				return (tree.children != null) ? tree.children[0] : tree;
			}
		}
		return null;
	}
예제 #8
0
	/// <summary>
	/// Adds an existing tree node as a child of this one.
	/// </summary>
	/// <param name="child">Child node to add.</param>
	/// <returns>For consistency purposes -- returns the newly added node.</returns>

    public GTTreeNode AddChild(GTTreeNode child)
	{
        if (children == null) children = new List<GTTreeNode>();
		children.Add(child);
		return child;
	}
예제 #9
0
	/// <summary>
	/// Adds a new child to this node.
	/// </summary>
	/// <returns>Newly created node.</returns>

    public GTTreeNode AddChild()
	{
        GTTreeNode node = new GTTreeNode();
        if (children == null) children = new List<GTTreeNode>();
		children.Add(node); 
		return node;
	}
예제 #10
0
 /// <summary>
 /// This method is called after Awake.
 /// If there are some perperties defined, they can be parsed here.
 /// </summary>
 /// <param name="treeNode"></param>
 public virtual void Parse(GTTreeNode treeNode)
 {
 }