public LongitudePattern GetPattern(LongitudePattern pattern) { if (!pattern.IsValid() || pattern.IsEmpty()) { return(LongitudePattern.empty); } #if UNITY_EDITOR if (Application.isPlaying) { #endif if (!_patternpattern.ContainsKey(pattern)) { return(LongitudePattern.empty); } return(_patternpattern[pattern]); #if UNITY_EDITOR } else { int index = _patterns.IndexOf(pattern); if (index < 0) { return(LongitudePattern.empty); } return(_patterns[index]); } #endif }
public int GetComponentID(LongitudePattern pattern) { if (!pattern.IsValid() || pattern.IsEmpty()) { return(0); } #if UNITY_EDITOR if (Application.isPlaying) { #endif if (!_patternid.ContainsKey(pattern)) { return(0); } return(_patternid[pattern]); #if UNITY_EDITOR } else { int index = _patterns.IndexOf(pattern); if (index < 0) { return(0); } return(_pids[index]); } #endif }
public void AddPattern(LongitudeDesign component, LongitudePattern pattern) { if (component == null || !pattern.IsValid() || pattern.IsEmpty()) { return; } #if UNITY_EDITOR if (Application.isPlaying) { #endif if (!_compid.ContainsKey(component) || _patternid.ContainsKey(pattern)) { return; } int id = _compid[component]; if (id < 1) { return; } _patternid.Add(pattern, id); _idpatterns[id].Add(pattern); _patternpattern.Add(pattern, pattern); #if UNITY_EDITOR } else { int comp_index = _components.IndexOf(component); if (comp_index < 0) { return; } if (_patterns.Contains(pattern)) { return; } _pids.Add(_ids[comp_index]); _patterns.Add(pattern); } #endif }
public void DeletePattern(LongitudeDesign component, LongitudePattern pattern) { if (component == null || !pattern.IsValid() || pattern.IsEmpty()) { return; } #if UNITY_EDITOR if (Application.isPlaying) { #endif if (!_compid.ContainsKey(component) || !_patternid.ContainsKey(pattern)) { return; } _patternid.Remove(pattern); _idpatterns[_compid[component]].Remove(pattern); _patternpattern.Remove(pattern); #if UNITY_EDITOR } else { int comp_index = _components.IndexOf(component); if (comp_index < 0) { return; } int id = _ids[comp_index]; int pat_index = _patterns.IndexOf(pattern); if (pat_index < 0) { return; } if (_pids[pat_index] != id) { return; } _pids.RemoveAt(pat_index); _patterns.RemoveAt(pat_index); } #endif }
public LongitudeDesign GetComponent(LongitudePattern pattern) { if (!pattern.IsValid() || pattern.IsEmpty()) { return(null); } #if UNITY_EDITOR if (Application.isPlaying) { #endif if (!_patternid.ContainsKey(pattern)) { return(null); } int id = _patternid[pattern]; if (!_idcomp.ContainsKey(id)) { return(null); } return(_idcomp[id]); #if UNITY_EDITOR } else { int pat_index = _patterns.IndexOf(pattern); if (pat_index < 0) { return(null); } int id = _pids[pat_index]; int comp_index = _ids.IndexOf(id); if (comp_index < 0) { return(null); } return(_components[comp_index]); } #endif }
public bool PatternExists(LongitudePattern pattern) { if (!pattern.IsValid() || pattern.IsEmpty()) { return(false); } #if UNITY_EDITOR if (Application.isPlaying) { #endif return(_patternid.ContainsKey(pattern)); #if UNITY_EDITOR } else { return(_patterns.Contains(pattern)); } #endif }
public override void Start() { _compid = new Dictionary <LongitudeDesign, int>(); _idcomp = new Dictionary <int, LongitudeDesign>(); _idpatterns = new Dictionary <int, List <LongitudePattern> >(); _patternid = new Dictionary <LongitudePattern, int>(); _patternpattern = new Dictionary <LongitudePattern, LongitudePattern>(); for (int k = 0; k < _ids.Count; k++) { int id = _ids[k]; LongitudeDesign comp = _components[k]; if (comp == null || id < 1) { continue; } _compid.Add(comp, id); _idcomp.Add(id, comp); _idpatterns.Add(id, new List <LongitudePattern>()); } for (int k = 0; k < _pids.Count; k++) { int id = _pids[k]; LongitudePattern pattern = _patterns[k]; if (!pattern.IsValid() || pattern.IsEmpty()) { continue; } if (_patternid.ContainsKey(pattern) || !_idpatterns.ContainsKey(id)) { continue; } _patternid.Add(pattern, id); _patternpattern.Add(pattern, pattern); _idpatterns[id].Add(pattern); } }
public override void DrawGUI(Rect rect) { //update both visual lists UpdateEdgeList(); UpdatePatternList(); //update layout rects UpdateLayoutRects(rect); //draw key selection header VxlGUI.DrawRect(_rect_selectheader, "DarkGradient"); GUI.Label(_rect_selectheader, _title, GUI.skin.GetStyle("LeftLightHeader")); //draw key selection list VxlGUI.DrawRect(_rect_selectscroll, "DarkWhite"); _selectscroll = GUI.BeginScrollView(_rect_selectscroll, _selectscroll, _rect_select_content); _edgelist.DoList(_rect_select_content); GUI.EndScrollView(); //draw add pattern template VxlGUI.DrawRect(_rect_pattemplateheader, "DarkGradient"); GUI.Label(_rect_pattemplateheader, "Add Lateral Edge", GUI.skin.GetStyle("LeftLightHeader")); VxlGUI.DrawRect(_rect_pattemplate, "DarkWhite"); Rect rect_content = VxlGUI.GetPaddedRect(_rect_pattemplate, VxlGUI.MED_PAD); EditorGUI.BeginChangeCheck(); Rect rect_row = VxlGUI.GetAboveElement(rect_content, 0, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0); float two = rect_row.width / 2f; //plugs row GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Plugs:", GUI.skin.GetStyle("LeftLrgDarkLabel")); int p0 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 2f, 40)), _addpat.p0); int p1 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 2f, 40)), _addpat.p1); //above voxels rect_row = VxlGUI.GetAboveElement(rect_content, 1, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0); GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Voxel In:", GUI.skin.GetStyle("LeftLrgDarkLabel")); int vin = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 2f, 40)), _addpat.in0); //below voxels rect_row = VxlGUI.GetAboveElement(rect_content, 2, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0); GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Voxel Out:", GUI.skin.GetStyle("LeftLrgDarkLabel")); int vout0 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 2f, 40)), _addpat.out0); int vout1 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 2f, 40)), _addpat.out1); //flips rect_row = VxlGUI.GetAboveElement(rect_content, 3, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0); bool flipx = EditorGUI.Foldout(VxlGUI.GetLeftElement(rect_row, 0, two), _addpat.xflip, "FlipX", true, GUI.skin.GetStyle("LightFoldout")); bool flipy = EditorGUI.Foldout(VxlGUI.GetLeftElement(rect_row, 1, two), _addpat.yflip, "FlipY", true, GUI.skin.GetStyle("LightFoldout")); //apply change if (EditorGUI.EndChangeCheck()) { _addpat = new LongitudePattern(flipx, flipy, p0, p1, vin, vout0, vout1); _repaint_menu = false; } //draw pattern header VxlGUI.DrawRect(_rect_patheader, "DarkGradient"); GUI.Label(_rect_patheader, "Patterns", GUI.skin.GetStyle("LeftLightHeader")); //draw pattern list VxlGUI.DrawRect(_rect_patscroll, "DarkWhite"); _patscroll = GUI.BeginScrollView(_rect_patscroll, _patscroll, _rect_patcontent); _patternlist.DoList(_rect_patcontent); GUI.EndScrollView(); //draw pattern panel VxlGUI.DrawRect(_rect_patpanel, "DarkGradient"); float button_width = Mathf.Min(60f, _rect_patpanel.width / 2f); bool invalid_addpat = !_addpat.IsValid() || _addpat.IsEmpty(); bool invalid_edgeindex = _edgelist.count <= 0 || _edgelist.index < 0 || _edgelist.index >= _edgelist.count; bool invalid_exists = target != null && target.LongitudePatternExists(_addpat); EditorGUI.BeginDisabledGroup(target == null || invalid_addpat || invalid_edgeindex || invalid_exists); if (GUI.Button(VxlGUI.GetRightElement(_rect_patpanel, 0, button_width), "Add", GUI.skin.GetStyle("LightButton"))) { if (target != null) { Undo.RecordObject(target, "Add Longitude Pattern"); target.AddLongitudePattern(_edges[_edgelist.index], _addpat); _repaint_menu = false; //dirty target EditorUtility.SetDirty(target); //update pattern list UpdatePatternList(); } } EditorGUI.EndDisabledGroup(); bool invalid_patternindex = _patternlist.count <= 0 || _patternlist.index < 0 || _patternlist.index >= _patternlist.count; EditorGUI.BeginDisabledGroup(target == null || invalid_edgeindex || invalid_patternindex); if (GUI.Button(VxlGUI.GetLeftElement(_rect_patpanel, 0, button_width), "Delete", GUI.skin.GetStyle("LightButton"))) { if (target != null) { Undo.RecordObject(target, "Delete Longitude Pattern"); target.DeleteLongitudePattern(_edges[_edgelist.index], _patterns[_patternlist.index]); _repaint_menu = false; //dirty target EditorUtility.SetDirty(target); //update pattern list UpdatePatternList(); } } EditorGUI.EndDisabledGroup(); }