public override void OnPreviewGUI(Rect r, GUIStyle background) { CCGradient gradient = (CCGradient)target; if (r.width <= 1f) { // events, no drawing return; } if (r.width == 40f) { // draw the thumbnail gradient.WriteToTexture(0f, 1f, thumbTexture); thumbTexture.Apply(); CCEditorUtility.DrawTexture(r, thumbTexture, previewMode); return; } // draw the preview if ((int)r.width != previewTexture.width) { previewTexture.Resize((int)r.width, 1); } gradient.WriteToTexture(previewFrom, previewTo, previewTexture); previewTexture.Apply(); CCEditorUtility.DrawTexture(r, previewTexture, previewMode); }
public void OnSceneGUI() { CCText box = (CCText)target; if (!box.enabled) { return; } Vector3 min = box.minBounds, max = box.maxBounds; Transform t = box.transform; if (min.z == max.z) { // draw a white box to show mesh bounds and a yellow box to show caret bounds CCEditorUtility.DrawWireRectangle(min, max, t); Handles.color = Color.yellow; CCEditorUtility.DrawWireRectangle(box.CaretMinBounds, box.CaretMaxBounds, t); } else { CCEditorUtility.DrawWireCube(min, max, t); } }
static void CreateTextBox() { CCFont font = Selection.activeObject as CCFont; CCText newBox = CCEditorUtility.CreateGameObjectWithComponent <CCText>("New Text Box"); if (font != null) { // set its font to the currently selected font newBox.Font = font; } }
public override void OnInspectorGUI() { if (CCEditorUtility.UndoRedoEventHappened) { // update any text boxes currently using the font font.UpdateAllCCText(); } if (font.IsValid) { EditorGUILayout.LabelField("Non-ASCII Chars", font.otherChars.Length.ToString()); EditorGUILayout.LabelField("Pixel Line Height", font.pixelLineHeight.ToString()); EditorGUILayout.LabelField("Pixel Scale", font.pixelScale.ToString()); EditorGUILayout.LabelField("Supports Kerning", font.supportsKerning.ToString()); } else { GUIStyle labelStyle = new GUIStyle(EditorStyles.label); labelStyle.wordWrap = true; GUILayout.Label("Please import a BMFont compatible font specification. Text and XML formats are supported.", labelStyle); } if (GUILayout.Button("Import FNT file")) { string filePath = CCEditorUtility.OpenFilePanelInSameFolder("Open FNT file", "fnt", font); if (filePath.Length == 0) { return; } Undo.SetSnapshotTarget(font, "Import FNT file"); Undo.CreateSnapshot(); try{ Import(filePath); } catch (Exception e) { Undo.RestoreSnapshot(); Debug.LogError("Failed to import FNT file. See next error for details."); throw e; } Undo.RegisterSnapshot(); EditorUtility.SetDirty(font); // update any text boxes currently using the font font.UpdateAllCCText(); } }
static void CreateColorGradient() { CCEditorUtility.CreateAsset <CCGradient>("New Gradient"); }
static void CreateNewAsset() { CCEditorUtility.CreateAsset <CCTextTorusWrapper>("New Torus Wrapper"); }
void OnGUI() { CCGradient oldGradient = gradient; gradient = (CCGradient)EditorGUILayout.ObjectField("Gradient", gradient, typeof(CCGradient), false); bool updateTexture = gradient != oldGradient; if (gradient == null) { return; } float oldValue = minimum; minimum = EditorGUILayout.FloatField("Minimum", minimum); if (minimum != oldValue) { EditorPrefs.SetFloat(minimumKey, minimum); updateTexture = true; } oldValue = maximum; maximum = EditorGUILayout.FloatField("Maximum", maximum); if (maximum != oldValue) { EditorPrefs.SetFloat(maximumKey, maximum); updateTexture = true; } int oldPixels = pixels; pixels = Mathf.Max(1, EditorGUILayout.IntField("Pixels", pixels)); if (pixels != oldPixels) { texture.Resize(pixels, 1); EditorPrefs.SetInt(pixelsKey, pixels); updateTexture = true; } bool oldToggle = bilinearPreview; bilinearPreview = EditorGUILayout.Toggle("Bilinear Preview", bilinearPreview); if (bilinearPreview != oldToggle) { EditorPrefs.SetBool(bilinearPreviewKey, bilinearPreview); texture.filterMode = bilinearPreview ? FilterMode.Bilinear : FilterMode.Point; } if (updateTexture) { gradient.WriteToTexture(minimum, maximum, texture); texture.Apply(); } if (GUILayout.Button("Export PNG file")) { string filePath = CCEditorUtility.SaveFilePanelInSameFolder("Save Color Gradient", gradient.name + " map", "png", gradient); if (filePath.Length > 0) { File.WriteAllBytes(filePath, texture.EncodeToPNG()); AssetDatabase.Refresh(); Close(); } } CCEditorUtility.DrawTexture(new Rect(2f, 130f, position.width - 4f, position.height - 132f), texture); }
static void CreateNewAsset() { CCEditorUtility.CreateAsset <CCTextRangeColorer>("New Range Colorer"); }
static void CreateNewAsset() { CCEditorUtility.CreateAsset <CCTextVerticalColorer>("New Vertical Colorer"); }
static void CreateSpriteFont() { CCEditorUtility.CreateAsset <CCFont>("New Font"); }
static void CreateNewAsset() { CCEditorUtility.CreateAsset <CCTextCylinderWrapper>("New Cylinder Wrapper"); }
static void CreateNewAsset() { CCEditorUtility.CreateAsset <CCTextMarkedColorer>("New Marked Colorer"); }