Esempio n. 1
0
    public override void gaxb_final(TBXMLElement element, object _parent, Hashtable args)
    {
        if (gameObject == null)
        {
            gameObject = new GameObject("<GameObject />", typeof(RectTransform));
        }

        gameObject.AddComponent <GameObjectRemoveFromNotificationCenter> ();

        if (title != null)
        {
            gameObject.name = title;
        }

        if (_parent is GameObject)
        {
            SetParentGameObject(_parent as GameObject);
        }
        else if (_parent is PUGameObject)
        {
            PUGameObject parentEntity = (PUGameObject)_parent;
            SetParentGameObject(parentEntity.gameObject);
        }

        if (bounds != null)
        {
            this.position = new Vector3(bounds.Value.x, bounds.Value.y, 0.0f);
            this.size     = new Vector2(bounds.Value.z, bounds.Value.w);
        }

        UpdateRectTransform();

        gameObject.layer = LayerMask.NameToLayer("UI");

        if (rectMask2D)
        {
            gameObject.AddComponent <RectMask2D> ();
        }

        if (mask)
        {
            Mask maskComponent = gameObject.AddComponent <Mask> ();
            maskComponent.showMaskGraphic = showMaskGraphic;

            // Mask requires a Graphic; if we don't have one, add one and tell it now to draw it...
            if (gameObject.GetComponent <Graphic> () == null)
            {
                MaskGraphic graphic = gameObject.AddComponent <MaskGraphic> ();

                if (maskInset != null)
                {
                    graphic.insetLeft   = maskInset.Value.x;
                    graphic.insetRight  = maskInset.Value.y;
                    graphic.insetTop    = maskInset.Value.z;
                    graphic.insetBottom = maskInset.Value.w;
                }
            }
        }

        if (outline)
        {
            gameObject.AddComponent <Outline> ();
        }

        if (shader != null)
        {
            Graphic graphic = gameObject.GetComponent <Graphic> ();
            if (graphic != null)
            {
                graphic.material = new Material(Shader.Find(shader));
            }
        }
        else
        {
            string defaultShader = PlanetUnityOverride.shaderForObject(this);
            if (defaultShader != null)
            {
                Graphic graphic = gameObject.GetComponent <Graphic> ();
                if (graphic != null)
                {
                    graphic.material = new Material(Shader.Find(defaultShader));
                }
            }
        }

        if (ignoreMouse)
        {
            IgnoreMouse(true);
        }

        if (components != null)
        {
            string[] allComponentNames = components.Split(',');
            foreach (string componentName in allComponentNames)
            {
                gameObject.AddComponent(Type.GetType(componentName));
            }
        }

        gameObject.SetActive(active);
    }