public void SetAtlasAndSubtextureP1(ZAtlas inAtlas, int inSubTextureId)
        {
            zobject.SetAtlas(inAtlas);
            zobject.SetSubTextureId(inSubTextureId);
            width  = 2.0f * inAtlas.GetSubTextureWidth(inSubTextureId) / Constants.kScreenMultiplierForShorts;
            height = 2.0f * inAtlas.GetSubTextureHeight(inSubTextureId) / Constants.kScreenMultiplierForShorts;
            if (Globals.deviceIPad)
            {
                width  = 1.0f * inAtlas.GetSubTextureWidth(inSubTextureId) / Constants.kScreenMultiplierForShorts;
                height = 1.0f * inAtlas.GetSubTextureHeight(inSubTextureId) / Constants.kScreenMultiplierForShorts;
            }
            else
            {
                width  = 2.0f * inAtlas.GetSubTextureWidth(inSubTextureId) / Constants.kScreenMultiplierForShorts;
                height = 2.0f * inAtlas.GetSubTextureHeight(inSubTextureId) / Constants.kScreenMultiplierForShorts;
            }

            if (Globals.g_main.usingTextureResolution == TextureResolutionEnum.kTextureResolution_High)
            {
                width  /= 2.0f;
                height /= 2.0f;
            }

            zobject.myAtlasBillboard.myObject.layer = LayerMask.NameToLayer("guistuff");
        }
Esempio n. 2
0
    public void SetScale(float inScale)
    {
        myObject.transform.localScale = new Vector3(inScale, inScale, inScale);

        Default.Namespace.Globals.Assert(myAtlas != null);

        //this.SetUVs(currentSubtextureId);

        MeshFilter mf = myObject.GetComponent <MeshFilter>();

        Mesh mesh;                // = mf.mesh;

        if (mf.sharedMesh == null)
        {
            mesh = new Mesh();
        }
        else
        {
            mesh = mf.sharedMesh;
        }


        Vector3[] vertices = new Vector3[4];

        height = myAtlas.GetSubTextureWidth(currentSubtextureId) * 2.0f;
        width  = myAtlas.GetSubTextureHeight(currentSubtextureId) * 2.0f;

        if (true)
        {
            float halfWidth  = width * 0.5f * inScale;           //(width * 0.5f);
            float halfHeight = height * 0.5f * inScale;          //(height * 0.5f);

            vertices[0] = new Vector3(-halfHeight, -halfWidth, 0.0f);
            vertices[1] = new Vector3(halfHeight, -halfWidth, 0.0f);
            vertices[2] = new Vector3(-halfHeight, halfWidth, 0.0f);
            vertices[3] = new Vector3(halfHeight, halfWidth, 0.0f);
        }
        mesh.vertices = vertices;

        //mesh.RecalculateBounds();

        mf.sharedMesh = mesh;
    }
Esempio n. 3
0
/*	public void RenderAtPositionOld_(Default.Namespace.CGPoint inPosition, float inScale, float inRot, float inAlpha, int inSubtextureId)
 *      {
 *              if (currentSubtextureId != inSubtextureId)
 *              {
 *                      currentSubtextureId = inSubtextureId;
 *                      if (myAtlas != null)
 *                      {
 *                              this.SetUVs(currentSubtextureId);
 *                      }
 *              }
 *
 *              this.CheckRender();
 *
 *              if (inAlpha != prevAlpha)
 *                      this.SetAlpha(inAlpha);
 *
 *              MeshFilter mf = myObject.GetComponent<MeshFilter>();
 *              Vector3[] vertices = new Vector3[4];
 *
 *              inPosition.x -= 160.0f;
 *              inPosition.y = 240.0f - inPosition.y;
 *
 *              if (inRot == 0.0f)
 *              {
 *                      float halfWidth = width * 0.5f * inScale;//(width * 0.5f);
 *                      float halfHeight = height * 0.5f *  inScale;//(height * 0.5f);
 *
 *                      vertices[0] = new Vector3(inPosition.x - halfHeight, inPosition.y - halfWidth, Default.Namespace.Globals.renderCounter);
 *                      vertices[1] = new Vector3(inPosition.x + halfHeight, inPosition.y - halfWidth, Default.Namespace.Globals.renderCounter);
 *                      vertices[2] = new Vector3(inPosition.x - halfHeight, inPosition.y + halfWidth, Default.Namespace.Globals.renderCounter);
 *                      vertices[3] = new Vector3(inPosition.x + halfHeight, inPosition.y + halfWidth, Default.Namespace.Globals.renderCounter);
 *              }
 *              else
 *              {
 *                      float rotationAngleToFirstPoint;// = myAtlas.GetRotationAngleToFirstPoint(inSubtextureId);
 *                      float rotationAngleToSecondPoint;// = myAtlas.GetRotationAngleToSecondPoint(inSubtextureId);
 *                      float useRotationScale;// = myAtlas.GetSubTextureRotationScale(inSubtextureId) * inScale;
 *
 *                      if (myAtlas == null)
 *                      {
 *                              //Just loading bar???
 *
 *                              rotationAngleToFirstPoint = rotationAngle1;
 *                              rotationAngleToSecondPoint = rotationAngle2;
 *                              useRotationScale = rotationScale;
 *                      }
 *                      else
 *                      {
 *                              Default.Namespace.Globals.Assert(inSubtextureId != -1);
 *
 *                              rotationAngleToFirstPoint = myAtlas.GetRotationAngleToFirstPoint(inSubtextureId);
 *                              rotationAngleToSecondPoint = myAtlas.GetRotationAngleToSecondPoint(inSubtextureId);
 *                              useRotationScale = myAtlas.GetSubTextureRotationScale(inSubtextureId) * inScale;
 *                      }
 *
 *                      float radians = inRot + rotationAngleToFirstPoint; //kRadiansAngleFor2x1y;
 *                      float a = (Mathf.Cos(radians) * useRotationScale);
 *                      float b = (Mathf.Sin(radians) * useRotationScale);
 *                      radians += rotationAngleToSecondPoint; //0.9272f;//0.4636below*2//2.217f; //(M_PI - (kRadiansAngleFor2x1y * 2.0f));
 *                      float c = (Mathf.Cos(radians) * useRotationScale);
 *                      float d = (Mathf.Sin(radians) * useRotationScale);
 *                      float topRightX = inPosition.x + a;
 *                      float topRightY = inPosition.y + b;
 *                      float topLeftX = inPosition.x + c;
 *                      float topLeftY = inPosition.y + d;
 *                      float bottomLeftX = inPosition.x - a;
 *                      float bottomLeftY = inPosition.y - b;
 *                      float bottomRightX = inPosition.x - c;
 *                      float bottomRightY = inPosition.y - d;
 *
 *                      vertices[2] = new Vector3(topLeftX, topLeftY, Default.Namespace.Globals.renderCounter);
 *                      vertices[3] = new Vector3(topRightX, topRightY, Default.Namespace.Globals.renderCounter);
 *                      vertices[0] = new Vector3(bottomLeftX, bottomLeftY, Default.Namespace.Globals.renderCounter);
 *                      vertices[1] = new Vector3(bottomRightX, bottomRightY, Default.Namespace.Globals.renderCounter);
 *
 *              //	float halfHeight = 50.0f;
 *              //	float halfWidth = 50.0f;
 *
 * //			vertices[0] = new Vector3(inPosition.x - halfHeight, -80, Default.Namespace.Globals.renderCounter);
 * //			vertices[1] = new Vector3(inPosition.x + halfHeight, -80, Default.Namespace.Globals.renderCounter);
 * //			vertices[2] = new Vector3(inPosition.x - halfHeight, 85, Default.Namespace.Globals.renderCounter);
 * //			vertices[3] = new Vector3(inPosition.x + halfHeight, 85, Default.Namespace.Globals.renderCounter);
 *
 *              }
 *
 *              Default.Namespace.Globals.renderCounter -= 0.5f;
 *
 *              //could save this...
 *      //	MeshRenderer meshRenderer = myObject.GetComponent<MeshRenderer>();
 *  //    meshRenderer.material.renderQueue = Default.Namespace.Globals.renderQueueCounter;
 *      //	Default.Namespace.Globals.renderQueueCounter += 1;
 *
 *              mf.mesh.vertices = vertices;
 *      }*/

    public void SetDetailsFromAtlas(Default.Namespace.ZAtlas inAtlas, int subTextureId)
    {
        //Debug.Log ("SetDetailsFromAtlas");

        currentSubtextureId = subTextureId;

        height = inAtlas.GetSubTextureWidth(subTextureId) * 2.0f;
        width  = inAtlas.GetSubTextureHeight(subTextureId) * 2.0f;

        MeshFilter mf = myObject.GetComponent <MeshFilter>();

        Mesh mesh;
        bool newMesh = false;

        if (mf.sharedMesh == null)
        {
            mesh    = new Mesh();
            newMesh = true;
        }
        else
        {
            mesh = mf.sharedMesh;
        }

//		var mesh = new Mesh();
//		mf.mesh = mesh;

        Vector3[] vertices = new Vector3[4];

        float halfWidth  = (width * 0.5f);
        float halfHeight = (height * 0.5f);

        vertices[0] = new Vector3(-halfHeight, -halfWidth, 0);
        vertices[1] = new Vector3(halfHeight, -halfWidth, 0);
        vertices[2] = new Vector3(-halfHeight, halfWidth, 0);
        vertices[3] = new Vector3(halfHeight, halfWidth, 0);


        mesh.vertices = vertices;

        for (int i = 0; i < 4; i++)
        {
//			mesh.vertices[i].x = vertices[i].x;
//			mesh.vertices[i].y = vertices[i].y;
//			mesh.vertices[i].z = vertices[i].z;
        }

//		mesh.vertices = vertices;

        if (newMesh)
        {
            int[] tri = new int[6];

            tri[0] = 0;
            tri[1] = 2;
            tri[2] = 1;

            tri[3] = 2;
            tri[4] = 3;
            tri[5] = 1;

            mesh.triangles = tri;

            Vector3[] normals = new Vector3[4];

            normals[0] = -Vector3.forward;
            normals[1] = -Vector3.forward;
            normals[2] = -Vector3.forward;
            normals[3] = -Vector3.forward;

            mesh.normals = normals;
        }

        Vector2[] uv = new Vector2[4];

        float ux  = inAtlas.GetMinUVP1(subTextureId, 0);
        float uxm = inAtlas.GetMaxUVP1(subTextureId, 0);
        float vx  = inAtlas.GetMinUVP1(subTextureId, 1);
        float vxm = inAtlas.GetMaxUVP1(subTextureId, 1);

        float textureWidth;
        float textureHeight;

        if ((Default.Namespace.Constants.ANDROID_25) && (Default.Namespace.Globals.g_main.loadADCQueue.state == LoadADCQueue.State.kStateBuildingUpAssetList))
        {
            textureWidth  = 256.0f;
            textureHeight = 256.0f;
        }
        else
        {
            textureWidth  = inAtlas.myMaterial.mainTexture.width;
            textureHeight = inAtlas.myMaterial.mainTexture.height;
        }

        ux  /= textureWidth;
        uxm /= textureWidth;
        vx  /= textureHeight;
        vxm /= textureHeight;

        float tempVx = vx;

        vx  = 1.0f - vxm;
        vxm = 1.0f - tempVx;

        //uv[0] = new Vector2(0.0f, 0.0f);
        //uv[1] = new Vector2(1.0f, 0.0f);
        //uv[2] = new Vector2(0.0f, 1.0f);
        //uv[3] = new Vector2(1.0f, 1.0f);

        uv[0] = new Vector2(ux, vx);
        uv[1] = new Vector2(uxm, vx);
        uv[2] = new Vector2(ux, vxm);
        uv[3] = new Vector2(uxm, vxm);
        //uv[0] = new Vector2(vx, ux);
        //uv[1] = new Vector2(vxm, ux);
        //uv[2] = new Vector2(vx, uxm);
        //uv[3] = new Vector2(vxm, uxm);

        mesh.uv = uv;

        for (int i = 0; i < 4; i++)
        {
//			mesh.uv[i].x = uv[i].x;
            //mesh.uv[i].y = uv[i].y;
        }

        mesh.RecalculateBounds();

        mf.sharedMesh = mesh;

        //Now create a

        //MeshRenderer meshRenderer = new MeshRenderer();// GetComponent<MeshRenderer>();

//		texture2D = inAtlas.GetMaterial().GetTexture2D();//Resources.Load(inTextureName, typeof(Texture2D)) as Texture2D;

        //   if (texture2D != null)
//		{
        //       meshRenderer.material.mainTexture = texture2D;
        //	}
    }