private void SetupIconPreview(CustomPreviewEditor preview) { iconWindow.OnPreviewCreated -= SetupIconPreview; ModularCharacterManager iconCharacter = preview.TargetObject.GetComponent <ModularCharacterManager>(); iconCharacter.SwapGender(currentGender); iconCharacter.ToggleBaseBodyDisplay(false); foreach (var part in armorParts) { if (part.partID > -1) { iconCharacter.ActivatePart(part.bodyType, part.partID); for (int i = 0; i < armorColors.Length; i++) { iconCharacter.SetPartColor(part.bodyType, part.partID, armorColors[i].property, armorColors[i].color); } } else { iconCharacter.DeactivatePart(part.bodyType); } } }
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(); }
private void OnGUI() { _customStyle = new GUIStyle(GUI.skin.button); _customStyle.padding = new RectOffset(10, 10, 10, 10); _titleStyle = new GUIStyle(GUI.skin.button); _titleStyle.fontStyle = FontStyle.Bold; _titleStyle.alignment = TextAnchor.MiddleCenter; if (_targetObject != null) { if (_previewWindow == null) { _previewWindow = Editor.CreateEditor(_targetObject, typeof(CustomPreviewEditor)) as CustomPreviewEditor; _previewWindow.TargetAsset = _targetObject; OnPreviewCreated?.Invoke(_previewWindow); UpdateOptionsToPreviewSettings(); } if (_previewWindow.HasPreviewGUI()) { _previewWindow.OnInteractivePreviewGUI(_previewRect, null); UpdateOptionsToPreviewSettings(); } } else { GUILayout.BeginArea(_previewRect); GUI.Box(new Rect(0, 0, _previewRect.width, _previewRect.height), "Image Not Available", _customStyle); GUILayout.EndArea(); } /* * Icon Options Area */ GUILayout.BeginArea(_iconOptionsArea, _customStyle); GUILayout.BeginVertical(); GUILayout.Label("Icon Options", _titleStyle); if (_targetObject != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Transparency"); EditorGUI.BeginChangeCheck(); _isTransparent = GUILayout.Toggle(_isTransparent, _isTransparent.ToString() /*, GUI.skin.button*/); if (EditorGUI.EndChangeCheck()) { if (_isTransparent) { _previewWindow.SetBackgroundColor(_transparencyColor, true); } else { _previewWindow.SetBackgroundColor(_iconBGColor); } } GUILayout.EndHorizontal(); if (!_isTransparent) { GUILayout.BeginHorizontal(); GUILayout.Label("Background Color"); EditorGUI.BeginChangeCheck(); _iconBGColor = EditorGUILayout.ColorField(_iconBGColor); if (EditorGUI.EndChangeCheck()) { _previewWindow.SetBackgroundColor(_iconBGColor); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Background Texture"); EditorGUI.BeginChangeCheck(); _bgTexture = EditorGUILayout.ObjectField(_bgTexture, typeof(Texture2D), false) as Texture2D; if (EditorGUI.EndChangeCheck()) { if (_bgTexture != null) { _previewWindow.BGTexture = _bgTexture; } else { _previewWindow.BGTexture = null; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Foreground Texture"); EditorGUI.BeginChangeCheck(); _fgTexture = EditorGUILayout.ObjectField(_fgTexture, typeof(Texture2D), false) as Texture2D; if (EditorGUI.EndChangeCheck()) { if (_fgTexture != null) { _previewWindow.FGTExture = _fgTexture; } else { _previewWindow.FGTExture = null; } } GUILayout.EndHorizontal(); if (GUILayout.Button("Reset Icon Options")) { ResetIconOptions(); } } GUILayout.EndVertical(); GUILayout.EndArea(); /* * Below Preview Options */ GUILayout.BeginArea(_previewOptionsArea, _customStyle); GUILayout.BeginVertical(); GUILayout.Label("Preview Window Options", _titleStyle); GUILayout.BeginHorizontal(); GUILayout.Label("Icon Object"); EditorGUI.BeginChangeCheck(); _targetObject = EditorGUILayout.ObjectField(_targetObject, typeof(GameObject), false) as GameObject; if (EditorGUI.EndChangeCheck()) { DestroyImmediate(_previewWindow); if (_targetObject != null) { _iconName = _targetObject.name; } } GUILayout.EndHorizontal(); if (_targetObject != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Light One Color"); EditorGUI.BeginChangeCheck(); _previewLightOneColor = EditorGUILayout.ColorField(_previewLightOneColor); if (EditorGUI.EndChangeCheck()) { _previewWindow.LightOneColor = _previewLightOneColor; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Light One Intensity"); EditorGUI.BeginChangeCheck(); _previewLightOneIntensity = EditorGUILayout.Slider(_previewLightOneIntensity, 0, 2.0f); if (EditorGUI.EndChangeCheck()) { _previewWindow.LightOneIntensity = _previewLightOneIntensity; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Light Two Color"); EditorGUI.BeginChangeCheck(); _previewLightTwoColor = EditorGUILayout.ColorField(_previewLightTwoColor); if (EditorGUI.EndChangeCheck()) { _previewWindow.LightTwoColor = _previewLightTwoColor; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Light Two Intensity"); EditorGUI.BeginChangeCheck(); _previewLightTwoIntensity = EditorGUILayout.Slider(_previewLightTwoIntensity, 0, 2.0f); if (EditorGUI.EndChangeCheck()) { _previewWindow.LightTwoIntensity = _previewLightTwoIntensity; } GUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reset Lights")) { ResetWindowOptions(); } if (GUILayout.Button("Reset Object")) { ResetTarget(); } EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndArea(); /* * Save Icon Options */ GUILayout.BeginArea(_saveOptionsArea, _customStyle); GUILayout.BeginVertical(); GUILayout.Label("Save Options", _titleStyle); if (_targetObject != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Icon Resolution"); EditorGUI.BeginChangeCheck(); _iconResIndex = EditorGUILayout.Popup(_iconResIndex, Array.ConvertAll <int, string>(_iconResolutions, x => x.ToString())); if (EditorGUI.EndChangeCheck()) { GUI.changed = true; } GUILayout.Label("x"); GUILayout.Label(_iconResolutions[_iconResIndex].ToString()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Icon Name"); _iconName = GUILayout.TextField(_iconName); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Icon Path:"); _savePath = GUILayout.TextArea(_savePath); GUILayout.EndHorizontal(); if (GUILayout.Button("Create Icon")) { if (_previewWindow.PreviewTexture != null) { CreatePngFromTexture(); } } } GUILayout.EndVertical(); GUILayout.EndArea(); }
private void OnGUI() { GUILayout.BeginArea(new Rect(previewRect.x + windowPadding.x, previewRect.y + windowPadding.y, previewRect.width - windowPadding.x, previewRect.height - windowPadding.y)); if (previewPrefab != null) { if (previewEditor == null) { previewEditor = Editor.CreateEditor(previewPrefab, typeof(CustomPreviewEditor)) as CustomPreviewEditor; previewEditor.OnPreviewObjectInstantiated += LoadPreviewObject; previewEditor.TargetAsset = previewPrefab; } else { if (characterManager == null) { LoadPreviewObject(previewEditor.TargetObject); } } if (previewEditor.HasPreviewGUI()) { previewEditor.OnInteractivePreviewGUI(new Rect(0, 0, previewRect.width - windowPadding.x, previewRect.height - windowPadding.y), null); } } GUILayout.EndArea(); GUILayout.BeginArea(new Rect(bodyOptionsRect.x + windowPadding.x, bodyOptionsRect.y + windowPadding.y, bodyOptionsRect.width - windowPadding.x, bodyOptionsRect.height - windowPadding.y)); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Male")) { characterManager.SwapGender(Gender.Male); currentGender = Gender.Male; } if (GUILayout.Button("Female")) { characterManager.SwapGender(Gender.Female); currentGender = Gender.Female; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("ShowBody")) { characterManager.ToggleBaseBodyDisplay(true); } if (GUILayout.Button("HideBody")) { characterManager.ToggleBaseBodyDisplay(false); } GUILayout.EndHorizontal(); if (GUILayout.Button("Reset")) { ResetAll(); } GUILayout.Label("Existing Modular Armor Asset"); EditorGUI.BeginChangeCheck(); existingArmor = EditorGUILayout.ObjectField(existingArmor, typeof(ModularArmor), false) as ModularArmor; if (EditorGUI.EndChangeCheck()) { if (existingArmor != null) { armorName = existingArmor.name; ResetParts(); SetupPartsFromExisting(); SetMaterialColorsToExisting(); characterManager.SetAllPartsMaterial(previewMaterial); InitializeColors(); } else { ResetAll(); } } GUILayout.EndVertical(); GUILayout.EndArea(); GUILayout.BeginArea(new Rect(armorOptionsRect.x + windowPadding.x, armorOptionsRect.y + windowPadding.y, armorOptionsRect.width - windowPadding.x, armorOptionsRect.height - windowPadding.y)); EditorGUI.BeginChangeCheck(); armorTypeIndex = EditorGUILayout.Popup(armorTypeIndex, Array.ConvertAll <ModularArmorType, string>(armorTypes, x => x.ToString()), GUILayout.Width(340)); if (EditorGUI.EndChangeCheck()) { ResetParts(); armorParts = GetArmorParts(armorTypes[armorTypeIndex]); SetupParts(); } GUILayout.BeginVertical(); armorScrollView = GUILayout.BeginScrollView(armorScrollView); if (armorParts.Count > 0) { for (int i = 0; i < armorParts.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Label(armorParts[i].bodyType.ToString()); EditorGUI.BeginChangeCheck(); int maxPartID = -1; if (characterManager != null) { maxPartID = characterManager.GetCharacterBody()[armorParts[i].bodyType].Length - 1; } activePartID[i] = EditorGUILayout.IntSlider(activePartID[i], -1, maxPartID); if (EditorGUI.EndChangeCheck()) { if (activePartID[i] > -1) { characterManager.ActivatePart(armorParts[i].bodyType, activePartID[i]); } else { characterManager.DeactivatePart(armorParts[i].bodyType); } armorParts[i].partID = activePartID[i]; } GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); GUILayout.EndArea(); GUILayout.BeginArea(new Rect(colorOptionsRect.x + windowPadding.x, colorOptionsRect.y + windowPadding.y, colorOptionsRect.width - windowPadding.x, colorOptionsRect.height - windowPadding.y)); foreach (var armorColor in armorColors) { SetupColorFields(ref armorColor.color, armorColor.property, armorColor.property); } GUILayout.EndArea(); GUILayout.EndVertical(); GUILayout.BeginArea(new Rect(armorNameRect.x + windowPadding.x, armorNameRect.y + windowPadding.y, armorNameRect.width - windowPadding.x, armorNameRect.height - windowPadding.y)); GUILayout.BeginHorizontal(); GUILayout.Label("Armor Name: ", GUILayout.Width(75)); armorName = GUILayout.TextField(armorName, GUILayout.Width(260)); GUILayout.EndHorizontal(); GUILayout.EndArea(); GUILayout.BeginArea(new Rect(saveButtonRect.x + windowPadding.x, saveButtonRect.y + windowPadding.y, saveButtonRect.width - windowPadding.x, saveButtonRect.height - windowPadding.y)); GUILayout.BeginHorizontal(); if (GUILayout.Button("Save as New")) { SaveDataToAsset(true); } if (GUILayout.Button("Overwrite Existing")) { SaveDataToAsset(false); } GUILayout.EndHorizontal(); if (GUILayout.Button("Create Icon")) { iconWindow = EditorWindow.GetWindow <IconCreatorWindow>(); iconWindow.Show(); if (iconWindow.PreviewEditor != null) { DestroyImmediate(iconWindow.PreviewEditor); } iconWindow.TargetObject = previewPrefab; iconWindow.OnPreviewCreated += SetupIconPreview; } GUILayout.EndArea(); }