public int GetComponentID(HexagonPattern 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 override void Enable() { _update_mesh = true; _render_mesh = true; _repaint_menu = true; _addpat = HexagonPattern.empty; _selectscroll = Vector2.zero; _patscroll = Vector2.zero; _facelist = new ReorderableList(_faces, typeof(HexagonDesign), false, false, false, false); _facelist.showDefaultBackground = false; _facelist.headerHeight = 0; _facelist.footerHeight = 0; _facelist.elementHeight = VxlGUI.MED_BAR; _facelist.drawNoneElementCallback += DrawFaceNoneElement; _facelist.drawElementCallback += DrawFaceElement; _facelist.drawElementBackgroundCallback += DrawFaceElementBackground; _patternlist = new ReorderableList(_patterns, typeof(HexagonPattern), false, false, false, false); _patternlist.showDefaultBackground = false; _patternlist.headerHeight = 0; _patternlist.footerHeight = 0; _patternlist.elementHeightCallback += PatternHeight; _patternlist.drawNoneElementCallback += DrawPatternNoneElement; _patternlist.drawElementCallback += DrawPatternElement; _patternlist.drawElementBackgroundCallback += DrawPatternElementBackground; }
public HexagonPattern GetPattern(HexagonPattern pattern) { if (!pattern.IsValid() || pattern.IsEmpty()) { return(HexagonPattern.empty); } #if UNITY_EDITOR if (Application.isPlaying) { #endif if (!_patternpattern.ContainsKey(pattern)) { return(HexagonPattern.empty); } return(_patternpattern[pattern]); #if UNITY_EDITOR } else { int index = _patterns.IndexOf(pattern); if (index < 0) { return(HexagonPattern.empty); } return(_patterns[index]); } #endif }
private void DrawAddPatternPanel() { EditorGUI.BeginChangeCheck(); VxlGUI.DrawRect(_rect_pattemplateheader, "DarkGradient"); GUI.Label(_rect_pattemplateheader, "Add Rect Pattern", GUI.skin.GetStyle("LeftLightHeader")); VxlGUI.DrawRect(_rect_pattemplate, "DarkWhite"); Rect rect_content = VxlGUI.GetPaddedRect(_rect_pattemplate, VxlGUI.MED_PAD); float two = rect_content.width / 2f; //row 0 - a1 a0 Rect rect_row = VxlGUI.GetAboveElement(rect_content, 0, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0); GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Above:", GUI.skin.GetStyle("LeftLightHeader")); int c4 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 2, Mathf.Min(two / 3f, 40)), _addpat.c4_p); int c5 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 3f, 40)), _addpat.c5_p); int c0 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 3f, 40)), _addpat.c0_p); //row 1 - b1 b0 rect_row = VxlGUI.GetAboveElement(rect_content, 1, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0); GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Below:", GUI.skin.GetStyle("LeftLightHeader")); int c3 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 2, Mathf.Min(two / 3f, 40)), _addpat.c3_p); int c2 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 3f, 40)), _addpat.c2_p); int c1 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 3f, 40)), _addpat.c1_p); //row 2 - vin vout rect_row = VxlGUI.GetAboveElement(rect_content, 2, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0); GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Voxels:", GUI.skin.GetStyle("LeftLightHeader")); int vb = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 2f, 40)), _addpat.vb); int va = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 2f, 40)), _addpat.va); //row 3 - flipx flipy 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 HexagonPattern(flipx, flipy, c0, c1, c2, c3, c4, c5, va, vb); _repaint_menu = false; } }
public void AddPattern(HexagonDesign component, HexagonPattern 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(HexagonDesign component, HexagonPattern 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 HexagonDesign GetComponent(HexagonPattern 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(HexagonPattern 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 <HexagonDesign, int>(); _idcomp = new Dictionary <int, HexagonDesign>(); _idpatterns = new Dictionary <int, List <HexagonPattern> >(); _patternid = new Dictionary <HexagonPattern, int>(); _patternpattern = new Dictionary <HexagonPattern, HexagonPattern>(); for (int k = 0; k < _ids.Count; k++) { int id = _ids[k]; HexagonDesign comp = _components[k]; if (comp == null || id < 1) { continue; } _compid.Add(comp, id); _idcomp.Add(id, comp); _idpatterns.Add(id, new List <HexagonPattern>()); } for (int k = 0; k < _pids.Count; k++) { int id = _pids[k]; HexagonPattern 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 HexagonPattern GetHexagonPattern(HexagonPattern pattern) { return(_hexagon.GetPattern(pattern)); }
public HexagonDesign GetHexagon(HexagonPattern pattern) { return(_hexagon.GetComponent(pattern)); }
public int GetHexagonID(HexagonPattern pattern) { return(_hexagon.GetComponentID(pattern)); }
public bool HexagonPatternExists(HexagonPattern pattern) { return(_hexagon.PatternExists(pattern)); }
public void DeleteHexagonPattern(HexagonDesign hexagon, HexagonPattern pattern) { _hexagon.DeletePattern(hexagon, pattern); }
public void AddHexagonPattern(HexagonDesign hexagon, HexagonPattern pattern) { _hexagon.AddPattern(hexagon, pattern); }