// Use this for initialization void Awake() { lights = GetComponentsInChildren <Light>(true); tb = GetComponentInChildren <ThrowBuilder>(true); // start with all lights off, otherwise first frame will see lights flash as the cookies haven't processed yet foreach (Light l in lights) { l.gameObject.SetActive(false); } // in the editor, however, we want the first light on, in order to see the size and shape of the image #if UNITY_EDITOR lights[0].gameObject.SetActive(true); #endif int cookieSizeInt = int.Parse(cookieSize.ToString().Substring(2)); #if UNITY_EDITOR // if in editor play mode, queue the updating images if (EditorApplication.isPlaying) { #endif previousProcessingTimes = new float[5]; // do first cookie as per usual cookie = new Cookie(new CookieData(shift_v, shift_h, keystoneH, keystoneV, throwRatio, aspectRatio), cookieSizeInt, lights[0], lights[1], lights[2], forceLegacyMethod, renderTexture, borderSize, colour, true); cookie.SetProjectedImageType(colour?Cookie.ImageType.Colour:Cookie.ImageType.Grey, this.enabled); convertedTexture = new Texture2D(renderTexture.width, renderTexture.height); //UpdateImage(); // garbage collection System.GC.Collect(); System.GC.WaitForPendingFinalizers(); #if UNITY_EDITOR } else // EDITOR EDIT MODE - only calculate the white cookie { // use slot 0 as the preview cookie cookie = new Cookie(new CookieData(shift_v, shift_h, keystoneH, keystoneV, throwRatio, aspectRatio), cookieSizeInt, lights[0], lights[1], lights[2], forceLegacyMethod, null, borderSize, colour); } #endif AssignLightCookies(); }
// Use this for initialization void Awake() { lights = GetComponentsInChildren <Light>(true); tb = GetComponentInChildren <ThrowBuilder>(true); if (!tb) { Debug.Log("No ThrowBuilder found! by " + gameObject.name); } foreach (Light l in lights) { l.gameObject.SetActive(false); } // ensure there is always at least 1 entry in the array if (images.Count > 0) { cookies = new Cookie[images.Capacity]; } else { cookies = new Cookie[1]; // no images but we need a cookie for white } int cookieSizeInt = int.Parse(cookieSize.ToString().Substring(2)); #if UNITY_EDITOR // if in editor edit mode, ensure preview image index is valid if (!EditorApplication.isPlaying) { previewImageIndex = Mathf.Clamp(previewImageIndex, 0, images.Count - 1); // don't allow user to choose a value out of range } // if in editor play mode, calculate all cookies (because we want to play the slideshow) if (EditorApplication.isPlaying) { #endif // if in any play mode, generate all cookies for slideshow // do first cookie as per usual cookies[0] = new Cookie(new CookieData(shift_v, shift_h, keystoneH, keystoneV, throwRatio, aspectRatio), cookieSizeInt, lights[0], lights[1], lights[2], forceLegacyMethod, images[0], borderSize, colour); // use first cookie data for remaining cookies for (int i = 1; i < cookies.Length; i++) { if (forceLegacyMethod) // revert to old way of re-using first cookie's texture { cookies[i] = new Cookie(cookies[0].GetProjectedImageData(), cookies[0].GetRedCookie(), images[i]); } else { cookies[i] = new Cookie(new CookieData(shift_v, shift_h, keystoneH, keystoneV, throwRatio, aspectRatio), cookieSizeInt, lights[0], lights[1], lights[2], false, images[i], borderSize, colour); } } // garbage collection images = null; System.GC.Collect(); System.GC.WaitForPendingFinalizers(); #if UNITY_EDITOR } else // EDITOR EDIT MODE - only calculate the preview cookie { // use slot 0 as the preview cookie cookies[0] = new Cookie(new CookieData(shift_v, shift_h, keystoneH, keystoneV, throwRatio, aspectRatio), cookieSizeInt, lights[0], lights[1], lights[2], forceLegacyMethod, images[previewImageIndex], borderSize, colour); } #endif AssignLightCookies(); }