Fixed photoshoot script
This commit is contained in:
parent
9980dd0497
commit
9fc24ad88a
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,6 @@ using UnityEngine.UI;
|
||||
public class Photoshoot : MonoBehaviour
|
||||
{
|
||||
public string OutputPath;
|
||||
public string itemPrefabPath;
|
||||
public Camera camera;
|
||||
public GameObject items;
|
||||
|
||||
@ -24,10 +23,42 @@ public class Photoshoot : MonoBehaviour
|
||||
{
|
||||
Debug.LogError("Output Path should not be empty");
|
||||
}
|
||||
|
||||
/*if(items != null)
|
||||
{
|
||||
SetActiveRecursively(items.transform, true);
|
||||
}*/
|
||||
}
|
||||
|
||||
static void SetActiveRecursively(Transform trans, bool active)
|
||||
{
|
||||
trans.gameObject.SetActive(active);
|
||||
if (trans.GetComponent<ItemUI>() != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (Transform child in trans)
|
||||
{
|
||||
SetActiveRecursively(child, active);
|
||||
}
|
||||
}
|
||||
static void SetActiveRecursivelyUpward(Transform trans, bool active)
|
||||
{
|
||||
trans.gameObject.SetActive(active);
|
||||
if (trans.parent != null)
|
||||
{
|
||||
SetActiveRecursivelyUpward(trans.parent, active);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
|
||||
SetActiveRecursively(items.transform, false);
|
||||
}
|
||||
|
||||
public void ProcessScreenshots()
|
||||
@ -37,7 +68,7 @@ public class Photoshoot : MonoBehaviour
|
||||
|
||||
public void ProcessScreenshotsFaster()
|
||||
{
|
||||
ScreenshotFaster();
|
||||
ScreenshotFasterPlus();
|
||||
}
|
||||
|
||||
private IEnumerator Screenshot()
|
||||
@ -143,10 +174,42 @@ public class Photoshoot : MonoBehaviour
|
||||
}
|
||||
Debug.Log($"Screenshot: Complete");
|
||||
}
|
||||
private void ScreenshotFasterPlus()
|
||||
{
|
||||
if (items != null)
|
||||
{
|
||||
items.SetActive(true);
|
||||
SetActiveRecursively(items.transform, true);
|
||||
}
|
||||
ItemUI[] itemUIs = items.GetComponentsInChildren<ItemUI>();
|
||||
if (items != null)
|
||||
{
|
||||
SetActiveRecursively(items.transform, false);
|
||||
items.SetActive(true);
|
||||
}
|
||||
|
||||
Debug.Log($"Screenshot: Found {itemUIs.Length} items.");
|
||||
|
||||
for (int i = 0; i < itemUIs.Length; i++)
|
||||
{
|
||||
if (items != null)
|
||||
{
|
||||
//items.SetActive(true);
|
||||
}
|
||||
ItemUI item = itemUIs[i].GetComponentInChildren<ItemUI>();
|
||||
GameObject obj = item.transform.parent.gameObject; // This assumed ItemUIs are correctly parented.
|
||||
|
||||
TakeScreenshotFaster($"{Application.dataPath}/{OutputPath}/{item.itemName}_icon.png", obj);
|
||||
|
||||
}
|
||||
|
||||
Debug.Log($"Screenshot: Complete");
|
||||
}
|
||||
|
||||
void TakeScreenshotFaster(string fullPath, GameObject obj)
|
||||
{
|
||||
obj.SetActive(true);
|
||||
SetActiveRecursivelyUpward(obj.transform, true);
|
||||
SetActiveRecursively(obj.transform, true);
|
||||
|
||||
RenderTexture rt = new RenderTexture(256, 256, 24);
|
||||
camera.targetTexture = rt;
|
||||
@ -173,7 +236,8 @@ public class Photoshoot : MonoBehaviour
|
||||
AssetDatabase.Refresh();
|
||||
#endif
|
||||
|
||||
obj.SetActive(false);
|
||||
SetActiveRecursively(obj.transform, false);
|
||||
SetActiveRecursivelyUpward(obj.transform, false);
|
||||
}
|
||||
|
||||
void TakeScreenshot(string fullPath)
|
||||
|
Loading…
Reference in New Issue
Block a user