コード例 #1
0
        public void UpdateInternalData()
        {
            if (_subject == null)
            {
                return;
            }
            _modelbounds.center = Vector3.zero;
            _modelbounds.size   = Vector3.zero;
            Vector3 subjectScale = _subject.transform.localScale;

            MeshFilter[] meshFilters = _subject.GetComponentsInChildren <MeshFilter>();
            int          meshCount   = meshFilters.Length;

//            Debug.Log(meshCount);
            _meshes    = new Mesh[meshCount];
            _materials = new MaterialArray[meshCount];
            Vector3 offset = _subject.transform.position;

            for (int m = 0; m < meshCount; m++)
            {
                _meshes[m] = meshFilters[m].sharedMesh;
                MeshRenderer rend = meshFilters[m].gameObject.GetComponent <MeshRenderer>();
//	            Debug.Log("UpdateInternalData "+rend);
                if (rend != null)
                {
                    _modelbounds.Encapsulate(rend.bounds);
//					Debug.Log("UpdateInternalData " + rend.bounds);
                    Material[] mats = rend.sharedMaterials;
//					Debug.Log("UpdateInternalData " + rend.sharedMaterials);
                    int rendMatCount = mats.Length;
                    _materials[m] = new MaterialArray(new Material[rendMatCount]);
                    for (int mt = 0; mt < rendMatCount; mt++)
                    {
                        _materials[m].materials[mt] = mats[mt];
                    }
                }
                else
                {
                    _materials[m] = new MaterialArray();
                }
            }

            _modelbounds.size    = Vector3.Scale(_modelbounds.size, subjectScale);
            _modelbounds.center += -offset;

            if (_userbounds.size.magnitude < Mathf.Epsilon)
            {
                _userbounds.Encapsulate(_modelbounds);
            }

#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(this);
#endif
        }
コード例 #2
0
            public static Material[][] ToArray(MaterialArray[] marray)
            {
                int count = marray.Length;

                Material[][] output = new Material[count][];
                for (int m = 0; m < count; m++)
                {
                    MaterialArray array  = marray[m];
                    int           countB = array.materials.Length;
                    output[m] = new Material[countB];
                    for (int mx = 0; mx < countB; mx++)
                    {
                        output[m][mx] = array.materials[mx];
                    }
                }
                return(output);
            }