示例#1
0
        private void LoadCombos()
        {
            EExtractType extType = new EExtractType();

            cmbType.DataSource     = EnumUtil.MakeEnumWithSpaces(extType);
            cmbType.DataTextField  = "Key";
            cmbType.DataValueField = "Value";
            cmbType.DataBind();
            cmbType.SelectedIndex = 0;

            EExtractSource source = new EExtractSource();

            cmbSource.DataSource     = EnumUtil.MakeEnumWithSpaces(source);
            cmbSource.DataTextField  = "Key";
            cmbSource.DataValueField = "Value";
            cmbSource.DataBind();
            cmbSource.SelectedIndex = 0;



            LoadYearCombo();
            SetCboYearVisibility();
        }
        /**
         * Extract a foliage prefab type for an operation. Returns null if it couldn't be used for that operation.
         */
        public static GameObject ExtractFromFoliagePrefab(GameObject foliageType, EExtractType extractType, bool shouldBeStatic)
        {
            GameObject prototype = null;

            // Pass unchanged
            if (extractType == EExtractType.COLLIDERS ||
                extractType == EExtractType.RENDERERS_FOR_COLLIDER_MESHES_NAVMESH ||
                extractType == EExtractType.RENDERERS)
            {
                System.Type[] systemMustHaveType = null;
                System.Type   systemExtractType  = null;

                switch (extractType)
                {
                case EExtractType.COLLIDERS:
                    systemMustHaveType = new System.Type[] { typeof(Collider) };
                    systemExtractType  = typeof(Collider);
                    break;

                case EExtractType.RENDERERS_FOR_COLLIDER_MESHES_NAVMESH:
                    systemMustHaveType = new System.Type[] { typeof(Collider), typeof(MeshFilter) };
                    systemExtractType  = typeof(Renderer);
                    break;

                case EExtractType.RENDERERS:
                    systemMustHaveType = new System.Type[] { typeof(Collider), typeof(MeshFilter) };
                    systemExtractType  = typeof(Renderer);
                    break;
                }

                Debug.Assert(systemExtractType != null);

                // If it's for colliders, can return null
                if (systemMustHaveType != null)
                {
                    for (int i = 0; i < systemMustHaveType.Length; i++)
                    {
                        if (foliageType.GetComponentInChildren(systemMustHaveType[i]) == null)
                        {
                            return(null);
                        }
                    }
                }

                prototype      = GameObject.Instantiate(foliageType);
                prototype.name = extractType + "_Prototype_" + foliageType.name;

                if (extractType == EExtractType.COLLIDERS)
                {
                    LODGroup lod = prototype.GetComponent <LODGroup>();
                    if (lod)
                    {
                        GameObject.DestroyImmediate(lod);
                    }
                }

                // Clear any owned GObjects that don't have colliders
                for (int i = prototype.transform.childCount - 1; i >= 0; i--)
                {
                    GameObject owned = prototype.transform.GetChild(i).gameObject;

                    if (owned.GetComponent(systemExtractType) == null)
                    {
                        GameObject.DestroyImmediate(owned);
                    }
                }

                Component[] components = prototype.GetComponentsInChildren <Component>();

                // Delete all non-colliders
                for (int i = 0; i < components.Length; i++)
                {
                    if (extractType == EExtractType.COLLIDERS)
                    {
                        if ((components[i].GetType().IsSubclassOf(systemExtractType)) == false && (components[i] is Transform) == false)
                        {
                            GameObject.DestroyImmediate(components[i]);
                        }
                    }
                    else
                    {
                        if ((components[i].GetType().IsSubclassOf(systemExtractType)) == false &&
                            (components[i] is Transform) == false &&
                            (components[i] is LODGroup) == false &&
                            (components[i] is MeshFilter) == false)
                        {
                            GameObject.DestroyImmediate(components[i]);
                        }
                    }
                }
            }
            else if (extractType == EExtractType.NON_MODIFIED)
            {
                prototype      = GameObject.Instantiate(foliageType);
                prototype.name = extractType + "_Prototype_" + foliageType.name;
            }


#if UNITY_EDITOR
            if (prototype != null && shouldBeStatic && extractType != EExtractType.RENDERERS_FOR_COLLIDER_MESHES_NAVMESH)
            {
                prototype.isStatic = true;

                for (int i = prototype.transform.childCount - 1; i >= 0; i--)
                {
                    prototype.transform.GetChild(i).gameObject.isStatic = true;
                }
            }
            else if (extractType == EExtractType.RENDERERS_FOR_COLLIDER_MESHES_NAVMESH && shouldBeStatic)
            {
                UnityEditor.GameObjectUtility.SetStaticEditorFlags(prototype, UnityEditor.StaticEditorFlags.NavigationStatic);

                for (int i = prototype.transform.childCount - 1; i >= 0; i--)
                {
                    UnityEditor.GameObjectUtility.SetStaticEditorFlags(prototype.transform.GetChild(i).gameObject, UnityEditor.StaticEditorFlags.NavigationStatic);
                }
            }
#endif

            return(prototype);
        }