/// <summary>
        /// Generates the shadow from the source Image.
        /// </summary>
        public void GenerateShadowFromImage()
        {
            isDone = false;

            //	Gets the source Image's Sprite's Texture to use
            destImage = gameObject.GetComponent <Image>();
            if (!destImage)
            {
                destImage = gameObject.AddComponent <Image>();
            }
            sourceSprite = sourceImage.sprite;

            if (sourceSprite != null)
            {
                Texture sourceOriginalTexture = sourceSprite.texture;
                sourceOriginalTexture.hideFlags = HideFlags.HideAndDontSave;

                //	We can't just use sourceOriginalTexture, as it may not be read/write enabled.
                //	Instead, we copy it using the filepath and WWW.LoadImageIntoTexture
                string path = "file://" + Application.dataPath.Replace("Assets", "");
                path += AssetDatabase.GetAssetPath(sourceOriginalTexture);
                WWW www = new WWW(path);
                ContinuationManager.Add(() => www.isDone, () =>
                {
                    sourceTex           = new Texture2D(sourceOriginalTexture.width, sourceOriginalTexture.height);
                    sourceTex.hideFlags = HideFlags.HideAndDontSave;
                    www.LoadImageIntoTexture(sourceTex);
                    SetupFile();
                });
            }
            else
            {
                sourceTex = new Texture2D(8, 8);
                int yCounter = 0;
                int xCounter = 0;
                while (xCounter < sourceTex.width)
                {
                    while (yCounter < sourceTex.height)
                    {
                        sourceTex.SetPixel(xCounter, yCounter, Color.black);
                        yCounter++;
                    }

                    xCounter++;
                    yCounter = 0;
                }
                sourceTex.Apply();
                SetupFile();
            }
        }
示例#2
0
 private void GenerateShadow(ShadowGenerator myTarget)
 {
     if (Selection.gameObjects.Length > 1)
     {
         for (var i = 0; i < Selection.gameObjects.Length; i++)
         {
             if (Selection.gameObjects[i].GetComponent <ShadowGenerator>())
             {
                 Selection.gameObjects[i].GetComponent <ShadowGenerator>().GenerateShadowFromImage();
             }
         }
     }
     else
     {
         m_IsGenerating = true;
         Repaint();
         myTarget.GetComponent <ShadowGenerator>().GenerateShadowFromImage();
         ContinuationManager.Add(() => myTarget.isDone, () =>
         {
             m_IsGenerating = false;
             Repaint();
         });
     }
 }