void Start() { Renderer r = this.gameObject.GetComponent <Renderer>(); Texture t = r.material.mainTexture; if (t.width > t.height) { this.targetScale = new Vector3(blowupSize, blowupSize * t.height / t.width, 1.0f); } else { this.targetScale = new Vector3(blowupSize * t.width / t.height, blowupSize, 1.0f); } this.startScale = this.transform.localScale; this.startTextureScale = r.material.mainTextureScale; this.startTextureOffset = r.material.mainTextureOffset; this.startPosition = this.transform.position; FadeColour fc = this.gameObject.AddComponent <FadeColour>(); fc.delay = 0.0f; fc.startValue = fc.getValue(); fc.endValue = Color.white; fc.animationTime = this.animationTime; }
// Use this for initialization protected override void StartSubclass() { Debug.Log("1. Making my own GameObject and putting an icImageMaterial on it with image: " + myImageUrl); // Make a standard cube that starts off transparent myImageCube = GameObject.CreatePrimitive(PrimitiveType.Cube); myImageCube.renderer.material.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 0.0f)); myImageCube.renderer.material.shader = Shader.Find("Transparent/Diffuse"); // Parent it to this ToolbeltManager this.ParentToMe(myImageCube); // Put an icImageMaterial on it icMediaLoader icml = this.MediaLoader; icImageMaterial myImageMat = icml.CreateImageMaterial(myImageUrl, myImageCube); // Give it a mediaReady callback so it fades to white after the image loads. FadeColour fadeScript = myImageMat.CreateMediaReadyCallback <FadeColour>(); fadeScript.targetColour = Color.white; fadeScript.duration = 2.0f; myImageCube.transform.localPosition = new Vector3(-2.0f, 0.0f, 5.0f); myImageCube.transform.Rotate(0, 90, 0); ///////////////////////////////////////////////////// // CreateImageQuad() and CreateBinkQuad() are convenience functions // that create the quad for you with the appropriate icMaterial, // with the quad already parented to the ToolbeltManager Debug.Log("2. Making image quad with image: " + imageUrl); imageQuad = this.CreateImageQuad(imageUrl); imageQuad.transform.localPosition = new Vector3(-1.0f, 0.0f, 5.0f); AddImageShaderScript(imageQuad); Debug.Log("3. Making bink quad with file: " + binkUrl); binkQuad = this.CreateBinkQuad(binkUrl); binkQuad.transform.localPosition = new Vector3(1.0f, 0.0f, 5.0f); Debug.Log("4. Making multiple quads with same image to show image caching"); // Attach them all to a parent GameObject dupParent = new GameObject("dupParent"); dupParent.transform.parent = this.gameObject.transform; // Give the empty GameObject an icMaterial so it can be used for colour parenting dupParent.AddComponent <icMaterial>(); const int count = 12; float step = 10.0f / count; for (int i = 0; i < count; ++i) { GameObject q = this.CreateImageQuad(dupImageUrl); q.name = "Dup Quad " + i; q.transform.localPosition = new Vector3(-4.0f + i * step, -1.0f, 6.0f); q.transform.parent = dupParent.transform; AddImageShaderScript(q); duplicateQuads.Add(q); } }