Пример #1
0
    public CollisionMap2(Drag3D[] c, DragLines _draglines, ShelfGenerator parent)
    {
        cubes         = c;
        draglines     = _draglines;
        SG            = parent;
        collisionNote = new Dictionary <int, List <int> >();

        for (int i = 0; i < c.Length; i++)
        {
            collisionNote.Add(c[i].gameObject.GetInstanceID(), new List <int>());
        }

        for (int p = 0; p < cubes.Length; p++)
        {
            UpdateCollisionMap(cubes[p]);
        }
    }
    public void Initialize(ShelfJSON s)
    {
        onItemAttachedCallBacks        = new List <OnItemAttachedCallback>();
        onItemDeattachedCallBacks      = new List <OnItemDeattachedCallback>();
        onShelfClickedCallBacks        = new List <OnShelfClickedCallback>();
        onChildProductClickedCallBacks = new List <OnChildProductClickedCallback>();

        childs_selected = new List <bool>();

        name       = s.name;
        this_shelf = s;

        transform.localPosition = new Vector3(0, s.absolute_height, 0);
        transform.localRotation = Quaternion.identity;

        // Generate new mesh game object
        shelf_mesh = new GameObject("mesh");

        // Calculate the mesh from the raw data
        MeshGenerator meshGen = new MeshGenerator(s.x_points, s.y_points);
        Mesh          msh     = meshGen.get3DMeshFrom2D(-s.thickness);

        // Render the mesh
        shelf_mesh.AddComponent(typeof(MeshRenderer));
        MeshFilter meshRenderer = shelf_mesh.AddComponent(typeof(MeshFilter)) as MeshFilter;

        meshRenderer.mesh = msh;

        shelf_mesh.GetComponent <MeshRenderer>().material       = Resources.Load("Materials/StandardTransparent", typeof(Material)) as Material;
        shelf_mesh.GetComponent <MeshRenderer>().material.color = Color.white;
        shelf_mesh.GetComponent <Transform>().localScale        = new Vector3(1, 1, 1);
        shelf_mesh.GetComponent <Transform>().SetParent(transform);
        shelf_mesh.GetComponent <Transform>().localPosition = new Vector3(0, 0, 0);
        shelf_mesh.GetComponent <Transform>().localRotation = Quaternion.identity;

        // Enables to pass the on click event to this object
        shelf_mesh.AddComponent <OnClickPassUp>();

        MeshCollider mc = shelf_mesh.AddComponent <MeshCollider>();

        mc.sharedMesh = msh;
        mc.convex     = true;
        mc.isTrigger  = true;


        // Calculate the the points that belong to the front face of the shelf
        // If none ar given, they are all front face by default
        if (s.front_index == null)
        {
            s.front_index = new int[s.x_points.Length];

            for (int p = 0; p < s.front_index.Length; p++)
            {
                s.front_index[p] = p;
            }
        }

        Vector3[] vertices = new Vector3[s.front_index.Length];
        for (int a = 0; a < vertices.Length; a++)
        {
            vertices[a] = new Vector3(s.x_points[s.front_index[a]], 0, s.y_points[s.front_index[a]]);
        }

        dragLines = new DragLines(vertices, 0.2f, false);

        cubes     = new List <Drag3D>();
        cubesJSON = new List <BoxJSON>();
        id2cube   = new Dictionary <int, GameObject>();

        if (this_shelf.boxes != null)
        {
            for (int p = 0; p < this_shelf.boxes.Length; p++)
            {
                GameObject new_cube = GenerateProduct(this_shelf.boxes[p]);
                AttachProduct(this_shelf.boxes[p], new_cube);
            }
        }

        sharedCollisionMap = new CollisionMap2(cubes.ToArray(), dragLines, this);

        initialized = true;
    }