Пример #1
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            TransformToHash other = (TransformToHash)obj;

            return(other.m_s == m_s && other.m_r == m_r);
        }
Пример #2
0
        public void Internal_UpdateMeshInGroup(HBFixBounds fixBounds, Mesh mesh)
        {
            if (fixBounds.OriginalMesh == null)
            {
                throw new ArgumentException("fixBounds.OriginalMesh is null", "fixBounds");
            }

            MeshRenderer meshRenderer = fixBounds.GetComponent <MeshRenderer>();

            if (meshRenderer != null)
            {
                if (m_rendererGroups.ContainsKey(fixBounds.OriginalMesh))
                {
                    Dictionary <TransformToHash, List <Renderer> > renderersGroupedByTransform = m_rendererGroups[fixBounds.OriginalMesh];
                    TransformToHash tth = new TransformToHash(fixBounds.transform);
                    if (renderersGroupedByTransform.ContainsKey(tth))
                    {
                        List <Renderer> renderers = renderersGroupedByTransform[tth];
                        for (int i = 0; i < renderers.Count; ++i)
                        {
                            HBFixBounds otherFixBounds = renderers[i].GetComponent <HBFixBounds>();
                            if (otherFixBounds != null && otherFixBounds.gameObject.isStatic == fixBounds.gameObject.isStatic)
                            {
                                if (!otherFixBounds.IsGlobalSettingOverriden())
                                {
                                    otherFixBounds.SetMesh(mesh, fixBounds.IsMeshFixed, fixBounds.IsBoundsFixed);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Debug.LogWarningFormat("MeshRenderer is null. gameobject {0}", fixBounds.gameObject.name);
            }
        }
Пример #3
0
        public static void Find(out Material[] materials, out RendererGroups groups, GameObject[] excludeGameObjects)
        {
            HashSet <Material> materialsHS        = new HashSet <Material>();
            HashSet <Renderer> excludeRenderersHS = new HashSet <Renderer>();

            for (int i = 0; i < excludeGameObjects.Length; ++i)
            {
                GameObject go          = excludeGameObjects[i];
                Renderer[] goRenderers = go.GetComponents <Renderer>();
                for (int j = 0; j < goRenderers.Length; ++j)
                {
                    Renderer renderer = goRenderers[j];
                    if (!excludeRenderersHS.Contains(renderer))
                    {
                        excludeRenderersHS.Add(renderer);
                    }
                }
            }
            Mesh particleSystemMesh = new Mesh();

            groups = new RendererGroups();

            Renderer[] renderers;
            renderers = UnityObject.FindObjectsOfType <Renderer>();

            for (int r = 0; r < renderers.Length; ++r)
            {
                Mesh mesh = null;

                Renderer renderer = renderers[r];
                if (excludeRenderersHS.Contains(renderer))
                {
                    continue;
                }

                Material[] rendererMaterials = renderer.sharedMaterials;
                for (int m = 0; m < rendererMaterials.Length; ++m)
                {
                    Material rendererMaterial = rendererMaterials[m];
                    if (!materialsHS.Contains(rendererMaterial))
                    {
                        materialsHS.Add(rendererMaterial);
                    }
                }

                if (renderer is MeshRenderer)
                {
                    HBFixBounds fixBounds = renderer.GetComponent <HBFixBounds>();
                    if (fixBounds != null)
                    {
                        mesh = fixBounds.OriginalMesh;
                    }
                    else
                    {
                        MeshFilter meshFilter = renderer.GetComponent <MeshFilter>();
                        if (meshFilter != null)
                        {
                            mesh = meshFilter.sharedMesh;
                        }
                    }
                }
                else if (renderer is SkinnedMeshRenderer)
                {
                    SkinnedMeshRenderer skinnedRenderer = (SkinnedMeshRenderer)renderer;
                    mesh = skinnedRenderer.sharedMesh;
                }
                else if (renderer is ParticleSystemRenderer)
                {
                    mesh = particleSystemMesh;
                }


                if (mesh != null)
                {
                    if (!groups.ContainsKey(mesh))
                    {
                        groups.Add(mesh, new Dictionary <TransformToHash, List <Renderer> >());
                    }

                    Dictionary <TransformToHash, List <Renderer> > renderersByTransform = groups[mesh];
                    TransformToHash tth = new TransformToHash(renderer.gameObject.transform);
                    if (!renderersByTransform.ContainsKey(tth))
                    {
                        renderersByTransform.Add(tth, new List <Renderer>());
                    }

                    List <Renderer> renderersList = renderersByTransform[tth];
                    renderersList.Add(renderer);
                }
            }

            materials = materialsHS.ToArray();
        }