Пример #1
0
    public RectPattern GetPattern(RectPattern pattern)
    {
        if (!pattern.IsValid() || pattern.IsEmpty())
        {
            return(RectPattern.empty);
        }
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
#endif
        if (!_patternpattern.ContainsKey(pattern))
        {
            return(RectPattern.empty);
        }
        return(_patternpattern[pattern]);

#if UNITY_EDITOR
    }

    else
    {
        int index = _patterns.IndexOf(pattern);
        if (index < 0)
        {
            return(RectPattern.empty);
        }
        return(_patterns[index]);
    }
#endif
    }
Пример #2
0
    public int GetComponentID(RectPattern 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
    }
Пример #3
0
    public void AddPattern(RectDesign component, RectPattern 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
    }
Пример #4
0
    public void DeletePattern(RectDesign component, RectPattern 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
    }
Пример #5
0
    public RectDesign GetComponent(RectPattern 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
    }
Пример #6
0
    public bool PatternExists(RectPattern 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
    }
Пример #7
0
 public override void Start()
 {
     _compid         = new Dictionary <RectDesign, int>();
     _idcomp         = new Dictionary <int, RectDesign>();
     _idpatterns     = new Dictionary <int, List <RectPattern> >();
     _patternid      = new Dictionary <RectPattern, int>();
     _patternpattern = new Dictionary <RectPattern, RectPattern>();
     for (int k = 0; k < _ids.Count; k++)
     {
         int        id   = _ids[k];
         RectDesign comp = _components[k];
         if (comp == null || id < 1)
         {
             continue;
         }
         _compid.Add(comp, id);
         _idcomp.Add(id, comp);
         _idpatterns.Add(id, new List <RectPattern>());
     }
     for (int k = 0; k < _pids.Count; k++)
     {
         int         id      = _pids[k];
         RectPattern 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);
     }
 }
Пример #8
0
    public override void DrawGUI(Rect rect)
    {
        //update both visual lists
        UpdateFaceList();
        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);
        _facelist.DoList(_rect_select_content);
        GUI.EndScrollView();
        //draw add pattern template
        DrawAddPatternPanel();

        //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.IsEmpty() || !_addpat.IsValid();
        bool invalid_faceindex = _facelist.count <= 0 || _facelist.index < 0 || _facelist.index >= _facelist.count;
        bool invalid_exists    = target == null || target.RectPatternExists(_addpat);

        EditorGUI.BeginDisabledGroup(target == null || invalid_addpat || invalid_faceindex || invalid_exists);
        if (GUI.Button(VxlGUI.GetRightElement(_rect_patpanel, 0, button_width), "Add", GUI.skin.GetStyle("LightButton")))
        {
            if (target != null)
            {
                Undo.RecordObject(target, "Add Rect Pattern");
                target.AddRectPattern(_faces[_facelist.index], _addpat);
                _repaint_menu = false;
                //set target dirty
                EditorUtility.SetDirty(target);
                //update pattern list
                UpdatePatternList();
            }
        }
        EditorGUI.EndDisabledGroup();

        bool invalid_patindex = _patternlist.count <= 0 || _patternlist.index < 0 || _patternlist.index >= _patternlist.count;

        EditorGUI.BeginDisabledGroup(target == null || invalid_faceindex || invalid_patindex);
        if (GUI.Button(VxlGUI.GetLeftElement(_rect_patpanel, 0, button_width), "Delete", GUI.skin.GetStyle("LightButton")))
        {
            if (target != null)
            {
                Undo.RecordObject(target, "Delete Rect Pattern");
                target.DeleteRectPattern(_faces[_facelist.index], _patterns[_patternlist.index]);
                _repaint_menu = false;
                //set target dirty
                EditorUtility.SetDirty(target);
                //update pattern list
                UpdatePatternList();
            }
        }
        EditorGUI.EndDisabledGroup();
    }