예제 #1
0
파일: HB.cs 프로젝트: calebaden/abomination
        private void CreateHBFixBounds()
        {
            RendererGroupsIterate(renderer =>
            {
                if (renderer is ParticleSystemRenderer)
                {
                    return;
                }

                HBFixBounds fixBounds = renderer.GetComponent <HBFixBounds>();
                if (fixBounds == null)
                {
                    fixBounds = renderer.gameObject.AddComponent <HBFixBounds>();
                }

                if (fixBounds != null && !fixBounds.Lock)
                {
                    fixBounds.FixBoundsRadius = FixBoundsRadius;
                    fixBounds.Curvature       = Curvature;
                    fixBounds.Flatten         = Flatten;
                    fixBounds.HorizonXOffset  = HorizonXOffset;
                    fixBounds.HorizonYOffset  = HorizonYOffset;
                    fixBounds.HorizonZOffset  = HorizonZOffset;
                    fixBounds.BendingMode     = BendingMode;
                    fixBounds.OverrideBounds  = false;
                }
            });
        }
예제 #2
0
파일: HB.cs 프로젝트: calebaden/abomination
        public void Internal_Rollback(bool full)
        {
            DestroyHBCameras();

            FixBoundsRadius = 50.0f;
            Curvature       = 5.0f;
            Flatten         = 0.0f;
            HorizonXOffset  = 0.0f;
            HorizonYOffset  = 0.0f;
            HorizonZOffset  = 0.0f;

            AttachToCamera  = false;
            m_appliedRadius = 0.0f;

            Material[] materials = Materials;
            if (full)
            {
                HBUtils.Find(out Materials, out m_rendererGroups, new GameObject[0]);
            }
            else
            {
                HBUtils.Find(out Materials, out m_rendererGroups, ExcludeGameObjects);
            }
            HBUtils.HorizonBend(new HBSettings(BendingMode._HB_OFF));
            TryRollbackDefaultMaterial();
            ReplaceUIMaterials(materials, true, full);
            RendererGroupsIterate(renderer =>
            {
                if (renderer == null)
                {
                    return;
                }

                HBFixBounds fixBounds = renderer.GetComponent <HBFixBounds>();
                if (fixBounds != null)
                {
                    if (full || !fixBounds.Lock)
                    {
                        fixBounds.Rollback();
                        DestroyImmediate(fixBounds);
                    }
                }
            });

            HBUtils.ReplaceShaders(Materials, HBShaders, true);

            m_rendererGroups.Clear();

            if (LockMaterials)
            {
                Materials = materials;
            }
            else
            {
                Materials = new Material[0];
            }
        }
예제 #3
0
        public static void CreatePrefab(GameObject gameObject)
        {
            HBFixBounds[] hbfb = gameObject.GetComponentsInChildren <HBFixBounds>();
            for (int i = 0; i < hbfb.Length; ++i)
            {
                HBFixBounds fixBounds = hbfb[i];
                if (fixBounds.MeshFilter != null && fixBounds.MeshFilter.sharedMesh != null)
                {
                    StorageHelper.SaveMesh(fixBounds.MeshFilter.sharedMesh, fixBounds.MeshFilter.sharedMesh.name + ".prefab");
                }
            }

            StorageHelper.CreatePrefab(gameObject.name + ".prefab", gameObject);
        }
예제 #4
0
        private static void CreatePrefab()
        {
            if (Application.isPlaying)
            {
                EditorUtility.DisplayDialog("Unable to Create Preafab", "Application.isPlaying == true", "OK");
                return;
            }

            foreach (Transform transform in Selection.transforms)
            {
                if (transform == null)
                {
                    Debug.LogWarning("Select object");
                }
                else
                {
                    HBFixBounds.CreatePrefab(transform.gameObject);
                }
            }
        }
예제 #5
0
파일: HB.cs 프로젝트: calebaden/abomination
        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);
            }
        }
예제 #6
0
파일: HB.cs 프로젝트: calebaden/abomination
        private void RendererGroupsIterate(Filter filter, Action <HBFixBounds> action)
        {
            foreach (KeyValuePair <Mesh, Dictionary <TransformToHash, List <Renderer> > > groupKVP in m_rendererGroups)
            {
                Dictionary <TransformToHash, List <Renderer> > rendererGroups = groupKVP.Value;
                foreach (List <Renderer> rendererGroup in rendererGroups.Values)
                {
                    if ((filter & Filter.FirstStatic) != 0)
                    {
                        foreach (Renderer renderer in rendererGroup)
                        {
                            if (renderer == null)
                            {
                                continue;
                            }

                            if (!renderer.gameObject.isStatic)
                            {
                                continue;
                            }

                            HBFixBounds fixBounds = renderer.GetComponent <HBFixBounds>();
                            if (fixBounds == null)
                            {
                                continue;
                            }

                            if ((filter & Filter.GlobalSettingsOverriden) != 0)
                            {
                                if (fixBounds.IsGlobalSettingOverriden())
                                {
                                    action(fixBounds);
                                    break;
                                }
                            }
                            else
                            {
                                if (!fixBounds.IsGlobalSettingOverriden())
                                {
                                    action(fixBounds);
                                    break;
                                }
                            }
                        }
                    }
                    else if ((filter & Filter.FirstDynamic) != 0)
                    {
                        foreach (Renderer renderer in rendererGroup)
                        {
                            if (renderer == null)
                            {
                                continue;
                            }

                            if (renderer.gameObject.isStatic)
                            {
                                continue;
                            }

                            HBFixBounds fixBounds = renderer.GetComponent <HBFixBounds>();
                            if (fixBounds == null)
                            {
                                continue;
                            }

                            if ((filter & Filter.GlobalSettingsOverriden) != 0)
                            {
                                if (fixBounds.IsGlobalSettingOverriden())
                                {
                                    action(fixBounds);
                                    break;
                                }
                            }
                            else
                            {
                                if (!fixBounds.IsGlobalSettingOverriden())
                                {
                                    action(fixBounds);
                                    break;
                                }
                            }
                        }
                    }
                    else if (filter == Filter.GlobalSettingsOverriden)
                    {
                        foreach (Renderer renderer in rendererGroup)
                        {
                            if (renderer == null)
                            {
                                continue;
                            }

                            HBFixBounds fixBounds = renderer.GetComponent <HBFixBounds>();
                            if (fixBounds == null)
                            {
                                continue;
                            }

                            if (fixBounds.IsGlobalSettingOverriden())
                            {
                                action(fixBounds);
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        private static void Subdivide()
        {
            if (Application.isPlaying)
            {
                EditorUtility.DisplayDialog("Unable to Subdivide Mesh", "Application.isPlaying == true", "OK");
                return;
            }

            foreach (Transform transform in Selection.transforms)
            {
                MeshFilter meshFilter = transform.GetComponent <MeshFilter>();
                if (meshFilter == null)
                {
                    Debug.LogWarning("Select object with MeshFilter component attached");
                    return;
                }

                if (meshFilter.sharedMesh == null)
                {
                    Debug.LogError("meshFilter.sharedMesh is null");
                    return;
                }

                Undo.RecordObject(meshFilter, "Subdivide");
                HBFixBounds hbFixBounds = transform.GetComponent <HBFixBounds>();
                if (hbFixBounds == null)
                {
                    Mesh mesh = Subdivider.Subdivide4(meshFilter.sharedMesh);
                    if (!meshFilter.sharedMesh.name.Contains("HBSubdivided"))
                    {
                        mesh.name = meshFilter.sharedMesh.name + " HBSubdivided";
                    }
                    else
                    {
                        mesh.name = meshFilter.sharedMesh.name;
                    }
                    meshFilter.sharedMesh = mesh;
                }
                else
                {
                    if (hbFixBounds.OriginalMesh != meshFilter.sharedMesh)
                    {
                        hbFixBounds.Rollback();
                    }

                    Mesh mesh = Subdivider.Subdivide4(meshFilter.sharedMesh);
                    if (!hbFixBounds.OriginalMesh.name.Contains("HBSubdivided"))
                    {
                        mesh.name = hbFixBounds.OriginalMesh.name + " HBSubdivided";
                    }
                    else
                    {
                        mesh.name = hbFixBounds.OriginalMesh.name;
                    }

                    hbFixBounds.OriginalMesh = mesh;
                    hbFixBounds.FixBounds(false);
                }
                Undo.RecordObject(meshFilter, "Subdivide");
            }
        }
예제 #8
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();
        }
예제 #9
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            HBFixBounds fixBounds = (HBFixBounds)target;

            if (HB.Instance != null)
            {
                if (fixBounds.OverrideBounds)
                {
                    if (fixBounds.SkinnedMesh != null && fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.SkinnedMesh != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                }
                else
                {
                    DrawPropertiesExcluding(serializedObject,
                                            "SkinnedBounds", "Bounds", "Lock", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                }
            }
            else
            {
                if (!fixBounds.OverrideBounds)
                {
                    DrawPropertiesExcluding(serializedObject, "BendingMode", "SkinnedBounds", "Bounds");
                }
                else
                {
                    if (fixBounds.SkinnedMesh != null && fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.SkinnedMesh != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();


            if (fixBounds.MeshFilter != null)
            {
                if (PrefabUtility.GetPrefabType(target) != PrefabType.Prefab)
                {
                    if (!Application.isPlaying)
                    {
                        if (GUILayout.Button("Fix Bounds"))
                        {
                            if (Application.isEditor)
                            {
                                bool global = false;
                                fixBounds.Rollback();
                                fixBounds.FixBounds(global);
                            }
                        }

                        if (fixBounds.IsBoundsFixed || fixBounds.IsMeshFixed)
                        {
                            if (GUILayout.Button("Rollback"))
                            {
                                if (Application.isEditor)
                                {
                                    fixBounds.Rollback();
                                }
                            }

                            if (GUILayout.Button("Create Prefab"))
                            {
                                if (Application.isEditor)
                                {
                                    HBFixBounds.CreatePrefab(fixBounds.gameObject);
                                }
                            }
                        }
                    }
                }
            }
        }