private void UpdateOptionsToPreviewSettings() { if (!_isTransparent) { _previewWindow.SetBackgroundColor(_iconBGColor); } else { _previewWindow.SetBackgroundColor(_transparencyColor, true); } _previewWindow.LightOneColor = _previewLightOneColor; _previewWindow.LightOneIntensity = _previewLightOneIntensity; _previewWindow.LightTwoColor = _previewLightTwoColor; _previewWindow.LightTwoIntensity = _previewLightTwoIntensity; if (_bgTexture != null) { _previewWindow.BGTexture = _bgTexture; } if (_fgTexture != null) { _previewWindow.FGTExture = _fgTexture; } }
private void OnGUI() { if (targetObject != null) { if (previewEditor == null) { previewEditor = Editor.CreateEditor(targetObject, typeof(CustomPreviewEditor)) as CustomPreviewEditor; previewEditor.TargetAsset = targetObject; OnPreviewCreated?.Invoke(previewEditor); } if (previewEditor.HasPreviewGUI()) { previewEditor.OnInteractivePreviewGUI(new Rect(0, 0, previewResolutions[previewResIndex], previewResolutions[previewResIndex]), null); } } GUILayout.BeginArea(new Rect(previewResolutions[previewResIndex], 0, 200, 200)); GUILayout.BeginVertical(); GUILayout.Label("Gameobject to create icon from"); EditorGUI.BeginChangeCheck(); targetObject = EditorGUILayout.ObjectField(targetObject, typeof(GameObject), false) as GameObject; if (EditorGUI.EndChangeCheck()) { DestroyImmediate(previewEditor); if (targetObject != null) { iconName = targetObject.name; } } GUILayout.BeginHorizontal(); GUILayout.Label("Icon Resolution"); EditorGUI.BeginChangeCheck(); previewResIndex = EditorGUILayout.Popup(previewResIndex, Array.ConvertAll <int, string>(previewResolutions, x => x.ToString())); if (EditorGUI.EndChangeCheck()) { GUI.changed = true; } GUILayout.EndHorizontal(); if (targetObject != null) { EditorGUI.BeginChangeCheck(); isTransparent = GUILayout.Toggle(isTransparent, "isTransparent", GUI.skin.button); if (EditorGUI.EndChangeCheck()) { if (isTransparent) { previewEditor.SetBackgroundColor(Color.magenta, true); } else { previewEditor.SetBackgroundColor(iconBackgroundColor); } } EditorGUI.BeginChangeCheck(); bgTexture = EditorGUILayout.ObjectField(bgTexture, typeof(Texture2D), false) as Texture2D; if (EditorGUI.EndChangeCheck()) { if (bgTexture != null) { previewEditor.BGTexture = bgTexture; } else { previewEditor.BGTexture = null; } } if (!isTransparent) { GUILayout.BeginHorizontal(); GUILayout.Label("Background Color"); EditorGUI.BeginChangeCheck(); iconBackgroundColor = EditorGUILayout.ColorField(iconBackgroundColor); if (EditorGUI.EndChangeCheck()) { previewEditor.SetBackgroundColor(iconBackgroundColor); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Icon name"); iconName = GUILayout.TextField(iconName); GUILayout.EndHorizontal(); if (GUILayout.Button("Create Icon")) { if (previewEditor.PreviewTexture != null) { CreatePngFromTexture(); } } } GUILayout.EndVertical(); GUILayout.EndArea(); }