public void ProcessCurrentOverlays(bool retry = true)
        {
            if (baseOverlayProperty == null)
            {
                return;
            }


            if (BaseOverlay == null || (BaseOverlay.asset.GetInstanceID() != (baseOverlayProperty.objectReferenceValue as OverlayDataAsset).GetInstanceID()))
            {
                OverlayDataAsset overlayDataAsset = baseOverlayProperty.objectReferenceValue as OverlayDataAsset;
                BaseOverlay = new OverlayData(overlayDataAsset);
            }

            OverlayViewer viewerobj = serializedObject.targetObject as OverlayViewer;

            List <OverlayData> od = new List <OverlayData>();

            od.Add(BaseOverlay);

            foreach (OverlayDataAsset o in viewerobj.Overlays)
            {
                if (o != null)
                {
                    if (!AdditionalOverlays.ContainsKey(o.GetInstanceID()))
                    {
                        AdditionalOverlays.Add(o.GetInstanceID(), new OverlayData(o));
                    }
                    od.Add(AdditionalOverlays[o.GetInstanceID()]);
                }
            }

            TempSlot.asset.material = od[0].asset.material;
            TempSlot.SetOverlayList(od);
            SlotData[] slot = new SlotData[1];
            slot[0] = TempSlot;
            TempUMAData.SetSlots(slot);

            TextureProcessBaseCoroutine textureProcessCoroutine;

            textureProcessCoroutine = new TextureProcessPROCoroutine();
            textureProcessCoroutine.Prepare(TempUMAData, TempUMAData.umaGenerator);
            activeGeneratorCoroutine.Prepare(TempUMAData.umaGenerator, TempUMAData, textureProcessCoroutine, false, 1);
            try
            {
                bool workDone = activeGeneratorCoroutine.Work();
                //Debug.Log("Workdone is " + workDone);
                rawImage.material = TempUMAData.generatedMaterials.materials[0].material;
            }
            catch (Exception ex)
            {
                Debug.Log("Something has gone wrong. Reinitializing. Text of error was: " + ex.Message);
                if (retry)
                {
                    Initialize(false);
                }
            }
        }
        private void Initialize(bool retry = true)
        {
            overlayViewer            = serializedObject.targetObject as OverlayViewer;
            TempUMAData              = overlayViewer.gameObject.GetComponent <UMAData>();
            ugb                      = overlayViewer.gameObject.GetComponent <UMAGeneratorStub>();
            TempSlot                 = new SlotData(overlayViewer.SlotDataAsset);
            rawImage                 = overlayViewer.ImageViewer;
            activeGeneratorCoroutine = new UMAGeneratorCoroutine();

            SetupGenerator();

            TempUMAData.Initialize(ugb);
            TempUMAData.SetSlot(0, TempSlot);

            baseOverlayProperty = serializedObject.FindProperty("BaseOverlay");
            overlaysProperty    = serializedObject.FindProperty("Overlays");
            texMergeProperty    = serializedObject.FindProperty("TextureMergePrefab");

            overlayDataList = new ReorderableList(serializedObject, overlaysProperty, true, true, false, false);
            overlayDataList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Overlays");
            };
            overlayDataList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                var element = overlayDataList.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 2;
                OverlayDataAsset o    = element.objectReferenceValue as OverlayDataAsset;
                string           name = "Not Set";
                if (o != null)
                {
                    name = o.overlayName;
                }
                EditorGUI.PropertyField(new Rect(rect.x + 10, rect.y, rect.width - 10, EditorGUIUtility.singleLineHeight), element);
            };


            overlayDataList.onSelectCallback = (ReorderableList list) =>
            {
                SelectNewOverlay(list.index);
            };


            overlayDataList.onChangedCallback = (ReorderableList list) =>
            {
                SelectNewOverlay(list.index);
                ProcessCurrentOverlays(retry);
            };
        }