示例#1
0
    public override void Enable()
    {
        _update_mesh  = true;
        _render_mesh  = true;
        _repaint_menu = true;
        _addpat       = LongitudePattern.empty;
        _selectscroll = Vector2.zero;
        _patscroll    = Vector2.zero;

        _edgelist = new ReorderableList(_edges, typeof(LongitudeDesign), false, false, false, false);
        _edgelist.showDefaultBackground          = false;
        _edgelist.headerHeight                   = 0;
        _edgelist.footerHeight                   = 0;
        _edgelist.elementHeight                  = VxlGUI.MED_BAR;
        _edgelist.drawNoneElementCallback       += DrawEdgeNoneElement;
        _edgelist.drawElementCallback           += DrawEdgeElement;
        _edgelist.drawElementBackgroundCallback += DrawEdgeElementBackground;

        _patternlist = new ReorderableList(_patterns, typeof(LongitudePattern), 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;
    }
示例#2
0
    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
    }
示例#3
0
    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
    }
示例#4
0
    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
    }
示例#5
0
    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
    }
示例#6
0
    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
    }
示例#7
0
    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
    }
示例#8
0
 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);
     }
 }
示例#9
0
    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();
    }
示例#10
0
 public LongitudePattern GetLongitudePattern(LongitudePattern pattern)
 {
     return(_longitude.GetPattern(pattern));
 }
示例#11
0
 public LongitudeDesign GetLongitude(LongitudePattern pattern)
 {
     return(_longitude.GetComponent(pattern));
 }
示例#12
0
 public int GetLongitudeID(LongitudePattern pattern)
 {
     return(_longitude.GetComponentID(pattern));
 }
示例#13
0
 public bool LongitudePatternExists(LongitudePattern pattern)
 {
     return(_longitude.PatternExists(pattern));
 }
示例#14
0
 public void DeleteLongitudePattern(LongitudeDesign longitude, LongitudePattern pattern)
 {
     _longitude.DeletePattern(longitude, pattern);
 }
示例#15
0
 public void AddLongitudePattern(LongitudeDesign longitude, LongitudePattern pattern)
 {
     _longitude.AddPattern(longitude, pattern);
 }