Esempio n. 1
0
 /// <summary>
 /// 交还图片显示控件
 /// </summary>
 /// <param name="image"></param>
 void PushImageContainer(EmueraImage image)
 {
     image.Clear();
     image.gameObject.SetActive(false);
     image.gameObject.name = "unused";
     image.transform.SetParent(cache_images);
     cache_image_containers_.Push(image);
 }
Esempio n. 2
0
    void UpdateLine(Vector2 local, float display_height, int index, int delta)
    {
        var zero = begin_index;

        while (zero <= index && index < end_index)
        {
            var l = console_lines_[index % max_log_count];
            if (l.position_y > local.y + display_height ||
                l.position_y + l.height < local.y)
            {
                break;
            }

            for (int li = 0; li < l.units.Count; ++li)
            {
                var unit = l.units[li];
                if (!unit.empty)
                {
                    var lc = PullLine();
                    lc.line_desc = l;
                    lc.UnitIdx   = li;
                    lc.Width     = unit.width;
                    lc.UpdateContent();
                    lc.SetPosition(unit.posx + local.x, local.y - lc.logic_y);
                    display_lines_.Add(lc);
                }
                if (unit.image_indices != null && unit.image_indices.Count > 0)
                {
                    var         hash = l.LineNo * 1000 + li;
                    EmueraImage ic   = null;
                    if (!display_images_.TryGetValue(hash, out ic))
                    {
                        ic = PullImageContainer();
                        display_images_.Add(l.LineNo * 1000 + li, ic);
                    }
                    else
                    {
                        ic.Clear();
                    }
                    ic.line_desc = l;
                    ic.UnitIdx   = li;
                    ic.Width     = unit.width;
                    ic.UpdateContent();
                    ic.SetPosition(unit.posx + local.x, local.y - ic.logic_y);
                }
            }
            index += delta;
        }
    }
Esempio n. 3
0
    /// <summary>
    /// 获取图片显示控件
    /// </summary>
    /// <returns></returns>
    EmueraImage PullImageContainer()
    {
        EmueraImage image = null;

        if (cache_image_containers_.Count > 0)
        {
            image = cache_image_containers_.Pop();
        }
        else
        {
            var obj = GameObject.Instantiate(template_images.gameObject);
            image = obj.GetComponent <EmueraImage>();
        }
        image.transform.SetParent(image_content);
        image.transform.localScale = Vector3.one;
        image.gameObject.SetActive(true);
        return(image);
    }
Esempio n. 4
0
    public void Update()
    {
        if (!dirty && drag_delta == Vector2.zero)
        {
            return;
        }
        dirty = false;

        float display_width  = DISPLAY_WIDTH;
        float display_height = DISPLAY_HEIGHT;

        if (drag_delta != Vector2.zero)
        {
            float t = drag_delta.magnitude;
            drag_delta    *= (Mathf.Max(0, t - 300.0f * Time.deltaTime) / t);
            local_position = GetLimitPosition(local_position + drag_delta,
                                              display_width, display_height);
            if ((local_position.x <= display_width - content_width && drag_delta.x < 0) ||
                (local_position.x >= 0 && drag_delta.x > 0))
            {
                drag_delta.x = 0;
            }
            if ((local_position.y >= content_height - display_height && drag_delta.y > 0) ||
                (local_position.y <= offset_height && drag_delta.y < 0))
            {
                drag_delta.y = 0;
            }
        }

        var pos = local_position + (drag_curr_position - drag_begin_position);

        pos = GetLimitPosition(pos, display_width, display_height);

        int remove_count = 0;
        int count        = display_lines_.Count;
        int max_line_no  = -1;
        int min_line_no  = int.MaxValue;

        for (int i = 0; i < count - remove_count; ++i)
        {
            var line = display_lines_[i];
            if (line.logic_y > pos.y + display_height ||
                line.logic_y + line.logic_height < pos.y)
            {
                display_lines_[i] = display_lines_[count - remove_count - 1];
                PushLine(line);
                ++remove_count;
                --i;
            }
            else
            {
                line.SetPosition(pos.x + line.unit_desc.posx, pos.y - line.logic_y);
                max_line_no = System.Math.Max(line.LineNo, max_line_no);
                min_line_no = System.Math.Min(line.LineNo, min_line_no);
            }
        }
        if (remove_count > 0)
        {
            display_lines_.RemoveRange(count - remove_count, remove_count);
        }

        List <EmueraImage> image_removelist = null;
        var display_iter = display_images_.GetEnumerator();

        while (display_iter.MoveNext())
        {
            var image = display_iter.Current.Value;
            if (image.logic_y > pos.y + display_height ||
                image.logic_y + image.logic_height < pos.y)
            {
                if (image_removelist == null)
                {
                    image_removelist = new List <EmueraImage>();
                }
                image_removelist.Add(image);
            }
            else
            {
                image.SetPosition(pos.x + image.unit_desc.posx, pos.y - image.logic_y);
            }
        }
        if (image_removelist != null)
        {
            var         listcount = image_removelist.Count;
            EmueraImage image     = null;
            for (int i = 0; i < listcount; ++i)
            {
                image = image_removelist[i];
                PushImageContainer(image);
                display_images_.Remove(image.LineNo * 1000 + image.UnitIdx);
            }
        }

        var index = GetLineNoIndex(min_line_no - 1);

        index = GetPrevLineNoIndex(index);
        if (index >= 0)
        {
            UpdateLine(pos, display_height, index, -1);
        }
        index = GetLineNoIndex(max_line_no + 1);
        index = GetNextLineNoIndex(index);
        if (index >= 0)
        {
            UpdateLine(pos, display_height, index, +1);
        }
        if (display_lines_.Count == 0 &&
            console_lines_ != null && console_lines_.Count > 0)
        {
            index = GetLineNoIndexForPosY(pos.y);
            UpdateLine(pos, display_height, index, -1);
            UpdateLine(pos, display_height, index + 1, +1);
        }
    }