예제 #1
0
    public override void init(GameObject go, txUIObject parent)
    {
        base.init(go, parent);
        // 获取image组件,如果没有则添加,这样是为了使用代码新创建一个image窗口时能够正常使用image组件
        mImage = mObject.GetComponent <Image>();
        if (mImage == null)
        {
            mImage = mObject.AddComponent <Image>();
            // 添加UGUI组件后需要重新获取RectTransform
            mRectTransform = mObject.GetComponent <RectTransform>();
            mTransform     = mRectTransform;
        }
        if (mImage == null)
        {
            logError(GetType() + " can not find " + typeof(Image) + ", window:" + mName + ", layout:" + mLayout.getName());
        }
        mOriginSprite = mImage.sprite;
        // 获取初始的精灵所在图集
        if (mOriginSprite != null)
        {
            mAtlas = mOriginSprite.texture;
            if (mAtlas != null)
            {
                ImageAtlasPath imageAtlasPath = mObject.GetComponent <ImageAtlasPath>();
                string         atlasPath;
                if (imageAtlasPath != null)
                {
                    atlasPath = imageAtlasPath.mAtlasPath;
                }
                else
                {
                    atlasPath = CommonDefine.R_ATLAS_GAME_ATLAS_PATH + mAtlas.name + "/" + mAtlas.name;
                }
                Texture2D atlas = mTPSpriteManager.getAtlas(atlasPath, false, true);
                if (atlas != null && atlas != mAtlas)
                {
                    logError("设置的图集与加载出的图集不一致!可能未添加ImageAtlasPath组件,或者ImageAtlasPath组件中记录的路径错误,或者是在当前物体在重复使用过程中销毁了原始图集");
                }
            }
        }
        mNormalSprite      = getSpriteName();
        mPressSprite       = mNormalSprite;
        mHoverSprite       = mNormalSprite;
        mSelectedSprite    = mNormalSprite;
        mOriginTextureName = mNormalSprite;
        string materialName = getMaterialName();

        // 不再将默认材质替换为自定义的默认材质,只判断其他材质
        if (!isEmpty(materialName) && materialName != CommonDefine.BUILDIN_UI_MATERIAL)
        {
            bool newMaterial = !mShaderManager.isSingleShader(materialName);
            if (newMaterial)
            {
                setMaterialName(materialName, newMaterial);
            }
        }
    }
예제 #2
0
    public override void init()
    {
        base.init();
        // 获取image组件,如果没有则添加,这样是为了使用代码新创建一个image窗口时能够正常使用image组件
        mImage = mObject.GetComponent <Image>();
        if (mImage == null)
        {
            mImage = mObject.AddComponent <Image>();
            // 添加UGUI组件后需要重新获取RectTransform
            mRectTransform = mObject.GetComponent <RectTransform>();
            mTransform     = mRectTransform;
        }
        if (mImage == null)
        {
            logError(Typeof(this) + " can not find " + Typeof <Image>() + ", window:" + mName + ", layout:" + mLayout.getName());
        }
        mOriginSprite = mImage.sprite;
        // 获取初始的精灵所在图集
        if (mOriginSprite != null)
        {
            Texture2D curTexture = mOriginSprite.texture;
            if (curTexture != null)
            {
                ImageAtlasPath imageAtlasPath = mObject.GetComponent <ImageAtlasPath>();
                string         atlasPath;
                if (imageAtlasPath != null)
                {
                    atlasPath = imageAtlasPath.mAtlasPath;
                }
                else
                {
                    atlasPath = FrameDefine.R_ATLAS_GAME_ATLAS_PATH + curTexture.name + "/" + curTexture.name;
                }
                mAtlas = mTPSpriteManager.getAtlas(atlasPath, false, true);
                if (mAtlas != null && mAtlas.mTexture != curTexture)
                {
                    logError("设置的图集与加载出的图集不一致!可能未添加ImageAtlasPath组件,或者ImageAtlasPath组件中记录的路径错误,或者是在当前物体在重复使用过程中销毁了原始图集");
                }
            }
        }
        mOriginTextureName = getSpriteName();
        string materialName = getMaterialName();

        // 不再将默认材质替换为自定义的默认材质,只判断其他材质
        if (!isEmpty(materialName) && materialName != FrameDefine.BUILDIN_UI_MATERIAL)
        {
            if (!mShaderManager.isSingleShader(materialName))
            {
                setMaterialName(materialName, true);
            }
        }
    }