public override void OnInspectorGUI()
    {
        UnifyMeshes bm = (UnifyMeshes)target;

        GUILayout.Box(banner, GUILayout.ExpandWidth(true));

        GUILayout.BeginVertical("box");
        if (GUILayout.Button("Unify"))
        {
            bm.Unify();
        }

        if (GUILayout.Button("Make editable"))
        {
            bm.Modify();
        }

        if (GUILayout.Button("DeOrganize"))
        {
            bm.DeOrganize();
        }

        if (GUILayout.Button("Export Mesh"))
        {
            bm.ExportMesh();
        }
        GUILayout.EndVertical();
    }
Ejemplo n.º 2
0
    public void Organize()
    {
        sm = gameObject.GetComponentsInChildren <Transform>();

        int counter = 0;

        MeshRenderer[] bm    = gameObject.GetComponentsInChildren <MeshRenderer>();
        GameObject     newGO = new GameObject("District " + counter);

        newGO.transform.SetParent(gameObject.transform);
        UnifyMeshes um = newGO.AddComponent <UnifyMeshes>();

        um.mat = material;

        for (int i = 0; i < bm.Length; i++)
        {
            Mesh mr = bm[i].gameObject.GetComponent <MeshFilter>().sharedMesh;
            counter = counter + mr.vertexCount;
            if (counter < 63000)
            {
                bm[i].gameObject.transform.SetParent(newGO.transform);
            }
            else
            {
                newGO = new GameObject("District " + counter);
                newGO.transform.SetParent(gameObject.transform);
                bm[i].gameObject.transform.SetParent(newGO.transform);
                um      = newGO.AddComponent <UnifyMeshes>();
                um.mat  = material;
                counter = 0;
            }
        }
    }
Ejemplo n.º 3
0
    public void Organize()
    {
        holder        = gameObject;
        objectsHolder = holder.GetComponentsInChildren <Renderer>(false);



        Renderer[] bm = holder.GetComponentsInChildren <Renderer>(false);
        Material[] uniqueMats;
        System.Array.Resize(ref mats, 0);
        //checkMaterials
        for (int i = 0; i < bm.Length; i++)
        {
            Material currentMat = bm[i].sharedMaterial;
            if (currentMat != null)
            {
                System.Array.Resize(ref mats, mats.Length + 1);
                mats[i] = currentMat;
            }
        }

        uniqueMats = mats.Distinct().ToArray();
        mats       = uniqueMats;


        for (int m = 0; m < mats.Length; m++)
        {
            int        counter = 0;
            GameObject newGO   = new GameObject("District " + counter);
            newGO.transform.SetParent(holder.transform);
            newGO.isStatic = true;
            newGO.layer    = 19;
            UnifyMeshes um = newGO.AddComponent <UnifyMeshes>();
            um.mat = mats[m];
            //um.mat = material;

            for (int i = 0; i < bm.Length; i++)
            {
                Mesh mr = bm[i].gameObject.GetComponent <MeshFilter>().sharedMesh;
                if (bm[i].sharedMaterial == um.mat)
                {
                    counter = counter + mr.vertexCount;
                    if (counter < 63000)
                    {
                        if (bm[i].sharedMaterial == um.mat)
                        {
                            bm[i].gameObject.transform.SetParent(newGO.transform);
                        }
                    }

                    else
                    {
                        newGO = new GameObject("District " + counter);
                        newGO.transform.SetParent(holder.transform);
                        newGO.isStatic = true;
                        newGO.layer    = 19;
                        bm[i].gameObject.transform.SetParent(newGO.transform);
                        um      = newGO.AddComponent <UnifyMeshes>();
                        um.mat  = mats[m];
                        counter = 0;
                    }
                }
            }
        }


        Unify();
    }
    //   float range = 30;


    void OnEnable()
    {
        UnifyMeshes um = (UnifyMeshes)target;

        banner = Resources.Load("CSHeader") as Texture;
    }
    public void Organize()
    {
        sm = cr.streets.GetComponentsInChildren <StreetModifier>();
        if (!maximizeEfficiency)
        {
            for (int i = 0; i < sm.Length; i++)
            {
                if (sm[i].streetType == StreetModifier.CScapeStreetType.Street)
                {
                    GameObject newGO = new GameObject("District " + i);
                    newGO.transform.SetParent(cr.buildings.transform);
                    newGO.isStatic = true;

                    UnifyMeshes um = newGO.AddComponent <UnifyMeshes>();
                    um.mat = material;



                    if (sm[i].frontBuildings.Length > 0)
                    {
                        for (int j = 0; j < sm[i].frontBuildings.Length; j++)
                        {
                            //  Debug.Log(sm[i].frontBuildings.Length + " " + sm[i]);
                            if (sm[i].frontBuildings[j] != null)
                            {
                                sm[i].frontBuildings[j].transform.SetParent(newGO.transform);
                            }
                        }
                    }
                    if (sm[i].backBuildings.Length > 0)
                    {
                        for (int j = 0; j < sm[i].backBuildings.Length; j++)
                        {
                            if (sm[i].backBuildings[j] != null)
                            {
                                sm[i].backBuildings[j].transform.SetParent(newGO.transform);
                            }
                        }
                    }

                    if (sm[i].leftBuildings.Length > 0)
                    {
                        for (int j = 0; j < sm[i].leftBuildings.Length; j++)
                        {
                            if (sm[i].leftBuildings[j] != null)
                            {
                                sm[i].leftBuildings[j].transform.SetParent(newGO.transform);
                            }
                        }
                    }
                    if (sm[i].rightBuildings.Length > 0)
                    {
                        for (int j = 0; j < sm[i].rightBuildings.Length; j++)
                        {
                            if (sm[i].rightBuildings[j] != null)
                            {
                                sm[i].rightBuildings[j].transform.SetParent(newGO.transform);
                            }
                        }
                    }
                }
            }
        }

        else
        {
            BuildingModifier[] bm = cr.buildings.GetComponentsInChildren <BuildingModifier>();
            Material[]         uniqueMats;
            System.Array.Resize(ref mats, 0);
            //checkMaterials
            for (int i = 0; i < bm.Length; i++)
            {
                Material currentMat = bm[i].gameObject.GetComponent <Renderer>().sharedMaterial;
                if (currentMat != null)
                {
                    System.Array.Resize(ref mats, mats.Length + 1);
                    mats[i] = currentMat;
                }
            }

            uniqueMats = mats.Distinct().ToArray();
            mats       = uniqueMats;


            for (int m = 0; m < mats.Length; m++)
            {
                int        counter = 0;
                GameObject newGO   = new GameObject("District " + counter);
                newGO.transform.SetParent(cr.buildings.transform);
                newGO.isStatic = true;
                newGO.layer    = 19;
                UnifyMeshes um = newGO.AddComponent <UnifyMeshes>();
                um.mat = mats[m];
                //um.mat = material;

                for (int i = 0; i < bm.Length; i++)
                {
                    Mesh mr = bm[i].gameObject.GetComponent <MeshFilter>().sharedMesh;
                    if (bm[i].GetComponent <Renderer>().sharedMaterial == um.mat)
                    {
                        counter = counter + mr.vertexCount;
                        if (counter < 63000)
                        {
                            if (bm[i].GetComponent <Renderer>().sharedMaterial == um.mat)
                            {
                                bm[i].gameObject.transform.SetParent(newGO.transform);
                            }
                        }

                        else
                        {
                            newGO = new GameObject("District " + counter);
                            newGO.transform.SetParent(cr.buildings.transform);
                            newGO.isStatic = true;
                            newGO.layer    = 19;
                            bm[i].gameObject.transform.SetParent(newGO.transform);
                            um      = newGO.AddComponent <UnifyMeshes>();
                            um.mat  = mats[m];
                            counter = 0;
                        }
                    }
                }
            }
        }
        Unify();
    }