Exemplo n.º 1
0
        private IEnumerator WaitUntilGeneratorFinishRoutine(ShadowGenerator target, System.Action callback)
        {
            while (target != null && !target.isDone)
            {
                yield return(null);
            }

            if (callback != null)
            {
                callback.Invoke();
            }
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            ShadowGenerator myTarget = (ShadowGenerator)target;

            ShadowGenerator.generatedShadowsDirectory = EditorGUILayout.TextField("Generated Shadows Directory", ShadowGenerator.generatedShadowsDirectory);
            ValidateShadowPath();

            if (m_IsGenerating)
            {
                GUI.enabled = false;
                GUILayout.Button("Generating Shadow...");
                GUI.enabled = true;
            }
            else
            {
                if (GUILayout.Button("Generate Shadow"))
                {
                    GenerateShadow(myTarget);
                }
            }
        }
Exemplo n.º 3
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();
         });
     }
 }
Exemplo n.º 4
0
 private void GenerateShadow(ShadowGenerator myTarget)
 {
     if (Selection.gameObjects.Length > 1)
     {
         for (int 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();
         });
     }
 }
Exemplo n.º 5
0
 private void GenerateShadow(ShadowGenerator myTarget)
 {
     if (Selection.gameObjects.Length > 1)
     {
         for (int 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();
         EditorCoroutine.Start(WaitUntilGeneratorFinishRoutine(myTarget, () =>
         {
             m_IsGenerating = false;
             Repaint();
         }));
     }
 }
Exemplo n.º 6
0
        public static void AttachAndSetupShadow()
        {
            GameObject sourceGameObject = Selection.activeGameObject;

            Undo.RecordObject(sourceGameObject, sourceGameObject.name);
            RectTransform sourceRectTransform = sourceGameObject.GetComponent <RectTransform>();
            Vector3       sourcePos           = sourceRectTransform.position;
            Vector2       sourceSize          = sourceRectTransform.sizeDelta;
            Vector2       sourceLayoutSize    = sourceRectTransform.GetProperSize();
            Image         sourceImage         = sourceGameObject.GetAddComponent <Image>();

            CreateShadow();

            GameObject shadowGameObject = Selection.activeGameObject;

            shadowGameObject.name = sourceGameObject.name + " Shadow";
            ShadowGenerator shadowGenerator = shadowGameObject.GetAddComponent <ShadowGenerator>();

            shadowGenerator.sourceImage = sourceImage;

            RectTransform shadowTransform = shadowGameObject.GetAddComponent <RectTransform>();

            shadowTransform.anchorMin = sourceRectTransform.anchorMin;
            shadowTransform.anchorMax = sourceRectTransform.anchorMax;
            shadowTransform.pivot     = sourceRectTransform.pivot;

            bool probablyHasLayout = (sourceGameObject.GetComponent <LayoutGroup>() != null || sourceGameObject.GetComponent <LayoutElement>() != null);

            GameObject newParentGameObject = new GameObject(sourceGameObject.name);

            newParentGameObject.transform.SetParent(sourceRectTransform.parent);
            RectTransform newParentRectTransform = newParentGameObject.GetAddComponent <RectTransform>();

            newParentRectTransform.SetSiblingIndex(sourceRectTransform.GetSiblingIndex());
            newParentRectTransform.anchorMin = sourceRectTransform.anchorMin;
            newParentRectTransform.anchorMax = sourceRectTransform.anchorMax;
            newParentRectTransform.pivot     = sourceRectTransform.pivot;
            newParentRectTransform.position  = sourcePos;
            newParentRectTransform.sizeDelta = sourceSize;
            LayoutElement layoutElement = null;

            if (probablyHasLayout)
            {
                layoutElement = newParentGameObject.AddComponent <LayoutElement>();
                layoutElement.preferredWidth  = sourceLayoutSize.x;
                layoutElement.preferredHeight = sourceLayoutSize.y;
            }

            shadowGameObject.GetComponent <RectTransform>().SetParent(newParentRectTransform, true);
            sourceRectTransform.SetParent(newParentRectTransform, true);

            sourceGameObject.name = sourceGameObject.name + " Image";

            if (probablyHasLayout)
            {
                layoutElement.CalculateLayoutInputHorizontal();
                layoutElement.CalculateLayoutInputVertical();
            }

            shadowGenerator.GenerateShadowFromImage();

            Selection.activeObject = newParentGameObject;
            Undo.RegisterCreatedObjectUndo(shadowGameObject, shadowGameObject.name);
            Undo.RegisterCreatedObjectUndo(newParentGameObject, newParentGameObject.name);
        }