public void BuildPanel(string name)
    {
        var   panel   = TestAllPanels.GetByID(name);
        float height  = panel.height;
        float width   = panel.width;
        var   panelGO = new GameObject(name, typeof(MeshRenderer), typeof(MeshFilter), typeof(BoxCollider), typeof(WallPanelInfo));

        panelGO.name = name;
        panelGO.tag  = "WallPanel";
        panelGO.transform.position = tm.TargetPosition;
        panelGO.transform.rotation = tm.TargetRotation;
        var panelMeshFilter   = panelGO.GetComponent <MeshFilter>();
        var panelMeshRenderer = panelGO.GetComponent <MeshRenderer>();
        var panelBoxCollider  = panelGO.GetComponent <BoxCollider>();

        panelBoxCollider.center = new Vector3(panel.width / -2.0f, panel.height / 2.0f, 0.025f);
        panelBoxCollider.size   = new Vector3(panel.width, panel.height, 0.05f);
        var info = panelGO.GetComponent <WallPanelInfo>();

        info.id     = name;
        info.width  = width;
        info.height = height;
        var up               = new Vector3(0, 1, 0);
        var right            = new Vector3(-1, 0, 0);
        var wallPanel        = new WallPanel(Vector3.zero, up, width, height, name);
        var wallPanelBuilder = new WallPanelBuilder(wallPanel);

        panelMeshFilter.mesh       = wallPanelBuilder.Build();
        panelMeshRenderer.material = panelMat;
        tm.SetNewPanelAsTarget(panelGO);
    }
예제 #2
0
    IEnumerator BuildWallPanels(ModulationReport report)
    {
        Dictionary <string, GameObject> wallPanelGameObjects = new Dictionary <string, GameObject>();

        foreach (KeyValuePair <string, List <PositionRotation> > cornerback in report.WallPanels)
        {
            var   panel   = TestAllPanels.GetByID(cornerback.Key);
            float height  = panel.height;
            float width   = panel.width;
            var   panelGO = new GameObject(name, typeof(MeshRenderer), typeof(MeshFilter), typeof(BoxCollider), typeof(WallPanelInfo));
            panelGO.name = cornerback.Key;
            panelGO.tag  = "WallPanel";
            var panelMeshFilter   = panelGO.GetComponent <MeshFilter>();
            var panelMeshRenderer = panelGO.GetComponent <MeshRenderer>();
            var panelBoxCollider  = panelGO.GetComponent <BoxCollider>();
            panelBoxCollider.center = new Vector3(panel.width / -2.0f, panel.height / 2.0f, 0.025f);
            panelBoxCollider.size   = new Vector3(panel.width, panel.height, 0.01f);

            var radius          = 0.03f;
            var cornerCollider1 = panelGO.AddComponent <SphereCollider>();
            var cornerCollider2 = panelGO.AddComponent <SphereCollider>();
            var cornerCollider3 = panelGO.AddComponent <SphereCollider>();
            var cornerCollider4 = panelGO.AddComponent <SphereCollider>();

            cornerCollider1.radius = radius;
            cornerCollider2.radius = radius;
            cornerCollider3.radius = radius;
            cornerCollider4.radius = radius;

            cornerCollider2.center = panel.height * panelGO.transform.up;
            cornerCollider3.center = -panel.width * panelGO.transform.right;
            cornerCollider4.center = panel.height * panelGO.transform.up + -panel.width * panelGO.transform.right;

            var info = panelGO.GetComponent <WallPanelInfo>();
            info.id     = cornerback.Key;
            info.width  = width;
            info.height = height;
            var up               = new Vector3(0, 1, 0);
            var right            = new Vector3(-1, 0, 0);
            var wallPanel        = new WallPanel(Vector3.zero, up, width, height, cornerback.Key);
            var wallPanelBuilder = new WallPanelBuilder(wallPanel);
            panelMeshFilter.mesh       = wallPanelBuilder.Build();
            panelMeshRenderer.material = wallPanelsMaterial;
            wallPanelGameObjects.Add(cornerback.Key, panelGO);
            yield return(null);
        }

        foreach (KeyValuePair <string, List <PositionRotation> > cornerback in report.WallPanels)
        {
            string     id             = cornerback.Key;
            GameObject externalCorner = wallPanelGameObjects [id];
            int        k = 0;
            foreach (PositionRotation transform in cornerback.Value)
            {
                Vector3    position = transform.Position;
                Quaternion rotation = Quaternion.Euler(transform.RotationV3);
                Instantiate(externalCorner, position, rotation);

                if (++k == 5)
                {
                    k = 0;
                    yield return(null);
                }
            }
        }
    }