/// <summary> /// Show the sprite selection wizard. /// </summary> static public void ShowSelected() { if (IFPipelineSettings.atlas != null) { Show(delegate(string sel) { IFPipelineEditorTools.SelectSprite(sel); }); } }
void DrawShadow() { //[HideInInspector] [SerializeField] public bool biasCustom = false; //[Range(0, 10)] [HideInInspector] [SerializeField] public float shadowBias = 1.0f; //[Range(0, 10)] [HideInInspector] [SerializeField] public float shadowNormalBias = 1.0f; //[Range(0.1f, 10)] [HideInInspector] [SerializeField] public float shadowNearPlane = 0.01f; //[HideInInspector] [SerializeField] public bool softShadow = false; ProjectorLight l = target as ProjectorLight; if (!l.lightParms_Shadow) { if (l.light.shadows != LightShadows.None) { l.light.shadows = LightShadows.None; } return; } GUILayout.Label("Shadow"); GUILayout.BeginVertical("box"); l.biasCustom = EditorGUILayout.Toggle("Custom Bias", l.biasCustom); if (l.biasCustom) { GUILayout.BeginVertical("box"); SerializedProperty sb1 = IFPipelineEditorTools.DrawProperty("Bias", serializedObject, "shadowBias", GUILayout.MinWidth(20f)); if (sb1.floatValue != l.shadowBias) { l.shadowBias = sb1.floatValue; l.light.shadowBias = sb1.floatValue; } sb1 = IFPipelineEditorTools.DrawProperty("Normal Bias", serializedObject, "shadowNormalBias", GUILayout.MinWidth(20f)); if (sb1.floatValue != l.shadowNormalBias) { l.shadowNormalBias = sb1.floatValue; l.light.shadowNormalBias = sb1.floatValue; } GUILayout.EndVertical(); } SerializedProperty sb = IFPipelineEditorTools.DrawProperty("Near Plane", serializedObject, "shadowNearPlane", GUILayout.MinWidth(20f)); if (sb.floatValue != l.shadowNearPlane) { l.shadowNearPlane = sb.floatValue; l.light.shadowNearPlane = sb.floatValue; } sb = IFPipelineEditorTools.DrawProperty("Soft Shadow", serializedObject, "softShadow", GUILayout.MinWidth(20f)); if (sb.boolValue != l.softShadow) { l.softShadow = sb.boolValue; l.light.shadows = LightShadows.Soft; } else { l.light.shadows = LightShadows.Hard; } GUILayout.EndVertical(); }
void DrawLightProperties() { EditorGUILayout.Space(); ProjectorLight l = target as ProjectorLight; GUILayout.Label("Properties"); GUILayout.BeginVertical("box"); { GUILayout.Label("Color"); GUILayout.BeginVertical("box"); SerializedProperty intensity = IFPipelineEditorTools.DrawProperty("Intensity", serializedObject, "intensity", GUILayout.MinWidth(20f)); if (intensity.floatValue != l.Intensity) { l.Intensity = intensity.floatValue; } SerializedProperty lightColor = IFPipelineEditorTools.DrawProperty("Color", serializedObject, "lightColor", GUILayout.MinWidth(20f)); if (lightColor.colorValue != l.LightColor) { l.LightColor = lightColor.colorValue; } bool useTemperature = EditorGUILayout.Toggle("Use Temperature", l.UseTemperature, GUILayout.MinWidth(20f)); if (l.UseTemperature) { l.Temperature = EditorGUILayout.FloatField("Temperature", l.Temperature, GUILayout.MinWidth(20f)); } if (useTemperature != l.UseTemperature) { l.UseTemperature = useTemperature; } l.specMultiplier = EditorGUILayout.FloatField("Specular Multiplier", l.specMultiplier, GUILayout.MinWidth(20f)); l.shadowBleedReduce = EditorGUILayout.FloatField("Shadow Bleed Reduce", l.shadowBleedReduce, GUILayout.MinWidth(20f)); GUILayout.EndVertical(); } { GUILayout.Label("Parameters"); GUILayout.BeginVertical("box"); l.lightParms_Shadow = EditorGUILayout.Toggle("Shadow", l.lightParms_Shadow, GUILayout.MinWidth(20f)); l.lightParms_Rect = EditorGUILayout.Toggle("Rect", l.lightParms_Rect, GUILayout.MinWidth(20f)); l.lightParms_Circle = EditorGUILayout.Toggle("Circle", l.lightParms_Circle, GUILayout.MinWidth(20f)); l.lightParms_SkipSkipModel = EditorGUILayout.Toggle("Not Skip", l.lightParms_SkipSkipModel, GUILayout.MinWidth(20f)); //l.lightParams_IsArea = EditorGUILayout.Toggle("Area", l.lightParams_IsArea, GUILayout.MinWidth(20f)); l.lightParams_NoDiffuse = EditorGUILayout.Toggle("No Diffuse", l.lightParams_NoDiffuse, GUILayout.MinWidth(20f)); l.area_width = EditorGUILayout.FloatField("Area Width", l.area_width, GUILayout.MinWidth(20f)); l.area_height = EditorGUILayout.FloatField("Area Height", l.area_height, GUILayout.MinWidth(20f)); l.area_falloff = EditorGUILayout.FloatField("Area Falloff", l.area_falloff, GUILayout.MinWidth(20f)); GUILayout.EndVertical(); } GUILayout.EndVertical(); }
/// <summary> /// Edit the sprite (context menu selection) /// </summary> void EditSprite(object obj) { if (this == null) { return; } SpriteData sd = obj as SpriteData; IFPipelineEditorTools.SelectSprite(sd.name); Close(); }
void DrawAtlas() { EditorGUILayout.Space(); ProjectorLight l = target as ProjectorLight; GUILayout.Label("Sprite"); GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); if (IFPipelineEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <SpritesAtlas>(OnSelectAtlas); } SerializedProperty atlas = IFPipelineEditorTools.DrawProperty("", serializedObject, "spritesAtlas", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (atlas != null) { SpritesAtlas atl = atlas.objectReferenceValue as SpritesAtlas; if (atl != null && atl != l.spritesAtlas) { l.spritesAtlas = atl; } GUILayout.Label("Project Sprite"); GUILayout.BeginHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mprojSpriteName"); IFPipelineEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as SpritesAtlas, sp.stringValue, SelectProjSprite, false); GUILayout.EndHorizontal(); GUILayout.Label("Falloff Sprite"); GUILayout.BeginHorizontal(); SerializedProperty spfalloff = serializedObject.FindProperty("mfalloffSpriteName"); IFPipelineEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as SpritesAtlas, spfalloff.stringValue, SelectFalloffSprite, false); GUILayout.EndHorizontal(); } else { l.mprojSpriteName = ""; l.mfalloffSpriteName = ""; l.falloffSpriteData = new SpriteData(); l.projSpriteData = new SpriteData(); Tools.SetDirty(serializedObject.targetObject); } GUILayout.EndVertical(); }
/// <summary> /// Get a previously saved object from settings. /// </summary> static public T Get <T>(string name, T defaultValue) where T : Object { string path = EditorPrefs.GetString(name); if (string.IsNullOrEmpty(path)) { return(null); } T retVal = IFPipelineEditorTools.LoadAsset <T>(path); if (retVal == null) { int id; if (int.TryParse(path, out id)) { return(EditorUtility.InstanceIDToObject(id) as T); } } return(retVal); }
override public void OnPreviewGUI(Rect rect, GUIStyle background) { ProjectorLight l = target as ProjectorLight; if (l.spritesAtlas == null) { return; } Texture2D tex = l.spritesAtlas.texture as Texture2D; if (tex == null) { return; } //GUILayout.Label("Preview"); //GUILayout.BeginVertical("box"); SpriteData sd = l.spritesAtlas.GetSprite(l.mprojSpriteName); IFPipelineEditorTools.DrawSprite(tex, rect, sd, Color.white); //GUILayout.EndVertical(); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { IFPipelineEditorTools.SetLabelWidth(80f); if (IFPipelineSettings.atlas == null) { GUILayout.Label("No Atlas selected.", "LODLevelNotifyText"); } else { SpritesAtlas atlas = IFPipelineSettings.atlas; bool close = false; GUILayout.Label(atlas.name + " Sprites", "LODLevelNotifyText"); IFPipelineEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string before = IFPipelineSettings.partialSprite; string after = EditorGUILayout.TextField("", before, "SearchTextField"); if (before != after) { IFPipelineSettings.partialSprite = after; } if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f))) { IFPipelineSettings.partialSprite = ""; GUIUtility.keyboardControl = 0; } GUILayout.Space(84f); GUILayout.EndHorizontal(); Texture2D tex = atlas.texture as Texture2D; if (tex == null) { GUILayout.Label("The atlas doesn't have a texture to work with"); return; } BetterList <string> sprites = atlas.GetListOfSprites(IFPipelineSettings.partialSprite); float size = 80f; float padded = size + 10f; int columns = Mathf.FloorToInt(Screen.width / padded); if (columns < 1) { columns = 1; } int offset = 0; Rect rect = new Rect(10f, 0, size, size); GUILayout.Space(10f); mPos = GUILayout.BeginScrollView(mPos); int rows = 1; while (offset < sprites.size) { GUILayout.BeginHorizontal(); { int col = 0; rect.x = 10f; for (; offset < sprites.size; ++offset) { SpriteData sprite = atlas.GetSprite(sprites[offset]); if (sprite == null) { continue; } // Button comes first if (GUI.Button(rect, "")) { if (Event.current.button == 0) { float delta = Time.realtimeSinceStartup - mClickTime; mClickTime = Time.realtimeSinceStartup; if (IFPipelineSettings.selectedSprite != sprite.name) { //if (mSprite != null) //{ // IFPipelineEditorTools.RegisterUndo("Atlas Selection", mSprite); // mSprite.MakePixelPerfect(); // EditorUtility.SetDirty(mSprite.gameObject); //} IFPipelineSettings.selectedSprite = sprite.name; IFPipelineEditorTools.RepaintSprites(); mCallback?.Invoke(sprite.name); } else if (delta < 0.5f) { close = true; } } else { //NGUIContextMenu.AddItem("Edit", false, EditSprite, sprite); //NGUIContextMenu.AddItem("Delete", false, DeleteSprite, sprite); //NGUIContextMenu.Show(); } } if (Event.current.type == EventType.Repaint) { // On top of the button we have a checkboard grid IFPipelineEditorTools.DrawTiledTexture(rect, IFPipelineEditorTools.backdropTexture); Rect uv = new Rect(sprite.x, sprite.y, sprite.width, sprite.height); uv = Math.ConvertToTexCoords(uv, tex.width, tex.height); // Calculate the texture's scale that's needed to display the sprite in the clipped area float scaleX = rect.width / uv.width; float scaleY = rect.height / uv.height; // Stretch the sprite so that it will appear proper float aspect = (scaleY / scaleX) / ((float)tex.height / tex.width); Rect clipRect = rect; if (aspect != 1f) { if (aspect < 1f) { // The sprite is taller than it is wider float padding = size * (1f - aspect) * 0.5f; clipRect.xMin += padding; clipRect.xMax -= padding; } else { // The sprite is wider than it is taller float padding = size * (1f - 1f / aspect) * 0.5f; clipRect.yMin += padding; clipRect.yMax -= padding; } } GUI.DrawTextureWithTexCoords(clipRect, tex, uv); // Draw the selection if (IFPipelineSettings.selectedSprite == sprite.name) { IFPipelineEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } } GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); GUI.contentColor = new Color(1f, 1f, 1f, 0.7f); GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), sprite.name, "ProgressBarBack"); GUI.contentColor = Color.white; GUI.backgroundColor = Color.white; if (++col >= columns) { ++offset; break; } rect.x += padded; } } GUILayout.EndHorizontal(); GUILayout.Space(padded); rect.y += padded + 26; ++rows; } GUILayout.Space(rows * 26); GUILayout.EndScrollView(); if (close) { Close(); } } }