public void AddDecals(List <QD.Decal> dec, int grp, int index, DecalView view) { if (grp > -1 && grp < decalGroups.Count) { if (index > -1) { decalGroups[grp].decals.InsertRange(index, dec); } else { decalGroups[grp].decals.AddRange(dec); } decalGroups[grp].isPacked = false; } else { decalGroups.Add(new DecalGroup( (dec.Count > 0 ? dec[0].texture.name : "New Decal Group"), dec, false, DefaultShader, (Material)null, DecalGroup.MAX_ATLAS_SIZE_DEFAULT, DecalGroup.ATLAS_PADDING_DEFAULT)); } Save(view); }
public bool LoadDecalGroups(DecalView decalView) { decalGroups.Clear(); if (s_decals == null) { return(false); } Dictionary <int, List <QD.Decal> > dict = new Dictionary <int, List <QD.Decal> >(); foreach (string str in s_decals) { QD.Decal d; if (QD.Decal.Deserialize(str, out d)) { int grpIndex = decalView == DecalView.Organizational ? d.orgGroup : d.atlasGroup; if (dict.ContainsKey(grpIndex)) { dict[grpIndex].Add(d); } else { dict.Add(grpIndex, new List <QD.Decal>() { d }); } } } foreach (KeyValuePair <int, List <QD.Decal> > kvp in dict) { if (decalView == DecalView.Atlas) { if (materials != null && kvp.Key < materials.Length) { Material mat = (Material)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(materials[kvp.Key]), typeof(Material)); decalGroups.Add(new DecalGroup(names[kvp.Key], kvp.Value, isPacked[kvp.Key], Shader.Find(shaders[kvp.Key]), mat, atlasSize[kvp.Key], padding[kvp.Key])); } else { decalGroups.Add(new DecalGroup(kvp.Value[0].name, kvp.Value, false, DefaultShader, null, 1024, 3)); } } else { decalGroups.Add(new DecalGroup("", kvp.Value, false, (Shader)null, (Material)null, 0, 0)); } } // now sort the decals per index for (int i = 0; i < decalGroups.Count; i++) { qdUtil.SortDecalsUsingView(ref decalGroups[i].decals, decalView); } return(true); }
public void AddDecals(List<QD.Decal> dec, int grp, int index, DecalView view) { if(grp > -1 && grp < decalGroups.Count) { if(index > -1) decalGroups[grp].decals.InsertRange(index, dec); else decalGroups[grp].decals.AddRange(dec); decalGroups[grp].isPacked = false; } else { decalGroups.Add( new DecalGroup( (dec.Count > 0 ? dec[0].texture.name : "New Decal Group"), dec, false, DefaultShader, (Material)null, DecalGroup.MAX_ATLAS_SIZE_DEFAULT, DecalGroup.ATLAS_PADDING_DEFAULT )); } Save(view); }
/** * The top toolbar with pane toggle and search bar. */ bool DrawToolbar(Rect r) { bool needsRepaint = false; GUI.BeginGroup(r); #if !UNITY_4_3 EditorGUIUtility.LookLikeInspector(); #endif GUILayout.BeginHorizontal(EditorStyles.toolbar); Color col = GUI.backgroundColor; GUI.backgroundColor = decalView == DecalView.Organizational ? ToolbarOnColor : col; if (GUILayout.Button("Decals", EditorStyles.toolbarButton)) { database.Save(decalView); decalView = DecalView.Organizational; selected.Clear(); database.LoadDecalGroups(decalView); decalGroups = database.decalGroups; needsRepaint = true; } GUI.backgroundColor = decalView == DecalView.Atlas ? ToolbarOnColor : col; if (GUILayout.Button("Atlas", EditorStyles.toolbarButton)) { database.Save(decalView); decalView = DecalView.Atlas; selected.Clear(); database.LoadDecalGroups(decalView); decalGroups = database.decalGroups; needsRepaint = true; } GUI.backgroundColor = col; GUILayout.FlexibleSpace(); if (decalView != DecalView.Atlas) { GUI.SetNextControlName("DecalSearch"); searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"), GUILayout.MinWidth(Mathf.Min(160, Screen.width / 2))); if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton"))) { // Remove focus if cleared searchString = ""; GUIUtility.keyboardControl = 0; GUI.FocusControl(""); } } GUILayout.EndHorizontal(); #if !UNITY_4_3 EditorGUIUtility.LookLikeControls(); #endif GUI.EndGroup(); return(needsRepaint); }
public void Save(DecalView view) { List <string> ser = new List <string>(); List <string> mat = new List <string>(); List <string> sha = new List <string>(); List <string> nam = new List <string>(); List <bool> pack = new List <bool>(); List <int> atlas = new List <int>(); List <int> pad = new List <int>(); for (int i = 0; i < decalGroups.Count; i++) { for (int n = 0; n < decalGroups[i].decals.Count; n++) { if (view == DecalView.Organizational) { decalGroups[i].decals[n].orgGroup = i; decalGroups[i].decals[n].orgIndex = n; } else { decalGroups[i].decals[n].atlasGroup = i; decalGroups[i].decals[n].atlasIndex = n; } ser.Add(decalGroups[i].decals[n].Serialize()); } if (view == DecalView.Atlas) { sha.Add(decalGroups[i].shader != null ? decalGroups[i].shader.name : ""); pack.Add(decalGroups[i].isPacked); nam.Add(decalGroups[i].name); atlas.Add(decalGroups[i].maxAtlasSize); pad.Add(decalGroups[i].padding); mat.Add(decalGroups[i].material != null ? AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(decalGroups[i].material)) : ""); } } s_decals = ser.ToArray(); if (view == DecalView.Atlas) { materials = mat.ToArray(); shaders = sha.ToArray(); isPacked = pack.ToArray(); names = nam.ToArray(); padding = pad.ToArray(); atlasSize = atlas.ToArray(); } EditorUtility.SetDirty(this); }
public void AddDecals(List<Decal> dec, DecalView decalView) { decalGroups.Add( new DecalGroup( (dec.Count > 0 ? dec[0].texture.name : "New Decal Group"), dec, false, DefaultShader, (Material)null, DecalGroup.MAX_ATLAS_SIZE_DEFAULT, DecalGroup.ATLAS_PADDING_DEFAULT )); Save(decalView); }
public void AddDecals(List <QD.Decal> dec, DecalView decalView) { decalGroups.Add(new DecalGroup( (dec.Count > 0 ? dec[0].texture.name : "New Decal Group"), dec, false, DefaultShader, (Material)null, DecalGroup.MAX_ATLAS_SIZE_DEFAULT, DecalGroup.ATLAS_PADDING_DEFAULT)); Save(decalView); }
public bool LoadDecalGroups(DecalView decalView) { decalGroups.Clear(); if(s_decals == null) return false; Dictionary<int, List<QD.Decal>> dict = new Dictionary<int, List<QD.Decal>>(); foreach(string str in s_decals) { QD.Decal d; if( QD.Decal.Deserialize(str, out d) ) { int grpIndex = decalView == DecalView.Organizational ? d.orgGroup : d.atlasGroup; if( dict.ContainsKey(grpIndex) ) dict[grpIndex].Add(d); else dict.Add(grpIndex, new List<QD.Decal>(){d}); } } foreach(KeyValuePair<int, List<QD.Decal>> kvp in dict) { if(decalView == DecalView.Atlas) { if(materials != null && kvp.Key < materials.Length) { Material mat = (Material)AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath(materials[kvp.Key]), typeof(Material) ); decalGroups.Add( new DecalGroup( names[kvp.Key], kvp.Value, isPacked[kvp.Key], Shader.Find(shaders[kvp.Key]), mat, atlasSize[kvp.Key], padding[kvp.Key]) ); } else { decalGroups.Add( new DecalGroup( kvp.Value[0].name, kvp.Value, false, DefaultShader, null, 1024, 3) ); } } else { decalGroups.Add( new DecalGroup( "", kvp.Value, false, (Shader)null, (Material)null, 0, 0) ); } } // now sort the decals per index for(int i = 0; i < decalGroups.Count; i++) qdUtil.SortDecalsUsingView(ref decalGroups[i].decals, decalView); return true; }
/** * Probably should have Decal implement IComparable and do it that way, but I'm * unsure of a good way to account for the decalview switch using that method */ public static void SortDecalsUsingView(ref List <Decal> decals, DecalView decalView) { List <Decal> dec = new List <Decal>(); foreach (Decal d in decals) { int ind = decalView == DecalView.Organizational ? d.orgIndex : d.atlasIndex; int smallestIndex = dec.Count; for (int i = dec.Count - 1; i > -1; i--) { if (ind < (decalView == DecalView.Atlas ? dec[i].atlasIndex : dec[i].orgIndex) && ind < smallestIndex) { smallestIndex = ind; } } dec.Insert(smallestIndex, d); } decals = dec; }
public void DeleteDecals(Dictionary <int, List <int> > del, DecalView decalView) { foreach (KeyValuePair <int, List <int> > kvp in del) { // there's probably some linq magic that does this in a cleaner manner, but i don't // know what it is List <Decal> survivors = new List <Decal>(); for (int i = 0; i < decalGroups[kvp.Key].decals.Count; i++) { if (!kvp.Value.Contains(i)) { survivors.Add(decalGroups[kvp.Key].decals[i]); } } decalGroups[kvp.Key].decals = survivors; } Save(decalView); }
public bool LoadDecalGroups(DecalView decalView) { decalGroups.Clear(); if(s_decals == null) return false; Dictionary<int, List<Decal>> dict = new Dictionary<int, List<Decal>>(); foreach(string str in s_decals) { Decal d; if( Decal.Deserialize(str, out d) ) { int grpIndex = decalView == DecalView.Organizational ? d.orgGroup : d.atlasGroup; if( dict.ContainsKey(grpIndex) ) dict[grpIndex].Add(d); else dict.Add(grpIndex, new List<Decal>(){d}); } } foreach(KeyValuePair<int, List<Decal>> kvp in dict) { int ag = kvp.Value[0].atlasGroup; Material mat = (Material)AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath(materials[ag]), typeof(Material) ); decalGroups.Add( new DecalGroup( names[ag], kvp.Value, isPacked[ag], Shader.Find(shaders[ag]), mat, atlasSize[ag], padding[ag]) ); } // now sort the decals per index for(int i = 0; i < decalGroups.Count; i++) qdUtil.SortDecalsUsingView(ref decalGroups[i].decals, decalView); return true; }
public void Save(DecalView view) { List<string> ser = new List<string>(); List<string> mat = new List<string>(); List<string> sha = new List<string>(); List<string> nam = new List<string>(); List<bool> pack = new List<bool>(); List<int> atlas = new List<int>(); List<int> pad = new List<int>(); for(int i = 0; i < decalGroups.Count; i++) { for(int n = 0; n < decalGroups[i].decals.Count; n++) { if(view == DecalView.Organizational) { decalGroups[i].decals[n].orgGroup = i; decalGroups[i].decals[n].orgIndex = n; } else { decalGroups[i].decals[n].atlasGroup = i; decalGroups[i].decals[n].atlasIndex = n; mat.Add(decalGroups[i].material != null ? AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(decalGroups[i].material)) : ""); sha.Add(decalGroups[i].shader.name); pack.Add(decalGroups[i].isPacked); nam.Add(decalGroups[i].name); atlas.Add(decalGroups[i].maxAtlasSize); pad.Add(decalGroups[i].padding); } ser.Add( decalGroups[i].decals[n].Serialize() ); } } s_decals = ser.ToArray(); if(view == DecalView.Atlas) { materials = mat.ToArray(); shaders = sha.ToArray(); isPacked = pack.ToArray(); names = nam.ToArray(); padding = pad.ToArray(); atlasSize = atlas.ToArray(); } EditorUtility.SetDirty(this); }
public void DeleteDecals(Dictionary<int, List<int>> del, DecalView decalView) { foreach(KeyValuePair<int, List<int>> kvp in del) { // there's probably some linq magic that does this in a cleaner manner, but i don't // know what it is List<QD.Decal> survivors = new List<QD.Decal>(); for(int i = 0; i < decalGroups[kvp.Key].decals.Count; i++) if( !kvp.Value.Contains(i) ) survivors.Add( decalGroups[kvp.Key].decals[i] ); decalGroups[kvp.Key].decals = survivors; } Save(decalView); }
/** * The top toolbar with pane toggle and search bar. */ bool DrawToolbar(Rect r) { bool needsRepaint = false; GUI.BeginGroup(r); GUILayout.BeginHorizontal(EditorStyles.toolbar); Color col = GUI.backgroundColor; GUI.backgroundColor = decalView == DecalView.Organizational ? ToolbarOnColor : col; if(GUILayout.Button("Decals", EditorStyles.toolbarButton)) { database.Save(decalView); decalView = DecalView.Organizational; selected.Clear(); database.LoadDecalGroups(decalView); decalGroups = database.decalGroups; needsRepaint = true; } GUI.backgroundColor = decalView == DecalView.Atlas ? ToolbarOnColor : col; if( GUILayout.Button("Atlas", EditorStyles.toolbarButton) ) { database.Save(decalView); decalView = DecalView.Atlas; selected.Clear(); database.LoadDecalGroups(decalView); decalGroups = database.decalGroups; needsRepaint = true; } GUI.backgroundColor = col; GUILayout.FlexibleSpace(); if(decalView != DecalView.Atlas) { GUI.SetNextControlName("DecalSearch"); searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"), GUILayout.MinWidth(Mathf.Min(160, Screen.width/2))); if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton"))) { // Remove focus if cleared searchString = ""; GUIUtility.keyboardControl = 0; GUI.FocusControl(""); } } GUILayout.EndHorizontal(); GUI.EndGroup(); return needsRepaint; }