Esempio n. 1
0
        private void DoStaticToggleField(GameObject go)
        {
            var staticRect = GUILayoutUtility.GetRect(s_Styles.staticContent, EditorStyles.toggle, GUILayout.ExpandWidth(false));

            EditorGUI.BeginProperty(staticRect, GUIContent.none, m_StaticEditorFlags);
            EditorGUI.BeginChangeCheck();
            var toggleRect = staticRect;

            EditorGUI.showMixedValue |= ShowMixedStaticEditorFlags((StaticEditorFlags)m_StaticEditorFlags.intValue);
            // Ignore mouse clicks that are not with the primary (left) mouse button so those can be grabbed by other things later.
            Event     evt          = Event.current;
            EventType origType     = evt.type;
            bool      nonLeftClick = (evt.type == EventType.MouseDown && evt.button != 0);

            if (nonLeftClick)
            {
                evt.type = EventType.Ignore;
            }
            var toggled = EditorGUI.ToggleLeft(toggleRect, s_Styles.staticContent, go.isStatic);

            if (nonLeftClick)
            {
                evt.type = origType;
            }
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(targets, ~0, toggled);
                serializedObject.SetIsDifferentCacheDirty();

                // Displaying the dialog to ask the user whether to update children nukes the gui state (case 962453)
                EditorGUIUtility.ExitGUI();
            }
            EditorGUI.EndProperty();
        }
Esempio n. 2
0
        public IEnumerator DefaultUnwrapParamsDoNotOverlap()
        {
            var lightmapMode = Lightmapping.giWorkflowMode;

            try
            {
                Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;

                Lightmapping.started += LightmappingStarted;

                if (Lightmapping.completed == null)
                {
                    Lightmapping.completed = LightmappingCompleted;
                }
                else
                {
                    Lightmapping.completed += LightmappingCompleted;
                }

                Setup();

                float x = -10f;

                using (var shapes = new TestUtility.BuiltInPrimitives())
                {
                    SceneModeUtility.SetStaticFlags(shapes.Select(it => it.gameObject).ToArray(), (int)StaticEditorFlags.LightmapStatic, true);

                    foreach (ProBuilderMesh mesh in shapes)
                    {
                        mesh.transform.position = new Vector3(x, 0f, 0f);
                        x += mesh.mesh.bounds.size.x + .5f;
                        mesh.Optimize(true);
                    }

                    Lightmapping.BakeAsync();

                    while (!s_FinishedBaking)
                    {
                        yield return(null);
                    }

                    LogAssert.NoUnexpectedReceived();
                }
            }
            finally
            {
                Lightmapping.started       -= LightmappingStarted;
                Lightmapping.completed     -= LightmappingCompleted;
                Lightmapping.giWorkflowMode = lightmapMode;
                Cleanup();
            }
        }
Esempio n. 3
0
        void LightmapStaticSettings()
        {
            bool lightmapStatic = (staticEditorFlagsProp.intValue & (int)StaticEditorFlags.LightmapStatic) != 0;

            EditorGUI.BeginChangeCheck();
            lightmapStatic = EditorGUILayout.Toggle(LightmapStaticContents, lightmapStatic);

            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(gameObjectsSerializedObject.targetObjects, (int)StaticEditorFlags.LightmapStatic, lightmapStatic);
                gameObjectsSerializedObject.Update();
            }
        }
        void ChangeMaskValues(int maskIndex, bool add)
        {
            var selectionCount = m_SerializedProperty.serializedObject.targetObjects.Length;

            m_SelectionMaskValues = new uint[selectionCount];

            SceneModeUtility.SetStaticFlags(m_SerializedProperty.serializedObject.targetObjects, maskIndex, add);

            for (int i = 0; i < selectionCount; i++)
            {
                m_SelectionMaskValues[i] = (uint)m_SerializedProperty.intValue;
            }

            m_SerializedProperty.serializedObject.ApplyModifiedProperties();
            m_SerializedProperty.serializedObject.SetIsDifferentCacheDirty();
            m_SerializedProperty.serializedObject.Update();
            editorWindow.Repaint();
        }
Esempio n. 5
0
        void LightmapStaticSettings()
        {
#if UNITY_2019_2_OR_NEWER
            bool lightmapStatic = (staticEditorFlagsProp.intValue & (int)StaticEditorFlags.ContributeGI) != 0;
#else
            bool lightmapStatic = (staticEditorFlagsProp.intValue & (int)StaticEditorFlags.LightmapStatic) != 0;
#endif

            EditorGUI.BeginChangeCheck();
            lightmapStatic = EditorGUILayout.Toggle(LightmapStaticContents, lightmapStatic);

            if (EditorGUI.EndChangeCheck())
            {
#if UNITY_2019_2_OR_NEWER
                SceneModeUtility.SetStaticFlags(gameObjectsSerializedObject.targetObjects, (int)StaticEditorFlags.ContributeGI, lightmapStatic);
#else
                SceneModeUtility.SetStaticFlags(gameObjectsSerializedObject.targetObjects, (int)StaticEditorFlags.LightmapStatic, lightmapStatic);
#endif
                gameObjectsSerializedObject.Update();
            }
        }
Esempio n. 6
0
        private void DoStaticFlagsDropDown(GameObject go)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = m_StaticEditorFlags.hasMultipleDifferentValues;
            int  changedFlags;
            bool changedToValue;
            //EditorGUI.EnumFlagsField(
            //    GUILayoutUtility.GetRect(GUIContent.none, s_Styles.staticDropdown, GUILayout.ExpandWidth(false)),
            //    GUIContent.none,
            //    GameObjectUtility.GetStaticEditorFlags(go),
            //    out changedFlags, out changedToValue,
            //    s_Styles.staticDropdown
            //    );
            var paramsX = new object[6]
            {
                GUILayoutUtility.GetRect(GUIContent.none, s_Styles.staticDropdown, GUILayout.ExpandWidth(false)),
                GUIContent.none,
                GameObjectUtility.GetStaticEditorFlags(go),
                null, null,
                s_Styles.staticDropdown
            };

            typeof(EditorGUI).GetMethod("EnumFlagsField", flagX, null, new Type[6] {
                typeof(Rect), typeof(GUIContent), typeof(Enum), typeof(int).MakeByRefType(), typeof(bool).MakeByRefType(), typeof(GUIStyle)
            }, null).Invoke(null, paramsX);
            changedFlags   = (int)paramsX[3];
            changedToValue = (bool)paramsX[4];

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(targets, changedFlags, changedToValue);
                serializedObject.SetIsDifferentCacheDirty();

                // Displaying the dialog to ask the user whether to update children nukes the gui state (case 962453)
                EditorGUIUtility.ExitGUI();
            }
        }
Esempio n. 7
0
        void LightmapStaticSettings()
        {
            m_GameObjectsSerializedObject.Update();

            bool lightmapStatic = (m_StaticEditorFlags.intValue & (int)StaticEditorFlags.LightmapStatic) != 0;

            EditorGUI.BeginChangeCheck();

            lightmapStatic = EditorGUILayout.Toggle(Styles.lightmapStatic, lightmapStatic);

            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(m_GameObjectsSerializedObject.targetObjects, (int)StaticEditorFlags.LightmapStatic, lightmapStatic);
            }

            if (lightmapStatic)
            {
                EditorGUILayout.PropertyField(m_UnwrapParameters, true);

                if (m_UnwrapParameters.isExpanded)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("Reset", Styles.miniButton))
                    {
                        ResetUnwrapParams(m_UnwrapParameters);
                    }

                    if (GUILayout.Button("Apply", Styles.miniButton))
                    {
                        RebuildLightmapUVs();
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.Space(4);
                }

                if (!m_ModifyingMesh)
                {
                    m_AnyMissingLightmapUVs = targets.Any(x =>
                    {
                        if (x is ProBuilderMesh)
                        {
                            return(!((ProBuilderMesh)x).HasArrays(MeshArrays.Texture1));
                        }

                        return(false);
                    });
                }

                if (m_AnyMissingLightmapUVs)
                {
                    EditorGUILayout.HelpBox("Lightmap UVs are missing, please generate Lightmap UVs.", MessageType.Warning);

                    if (GUILayout.Button("Generate Lightmap UVs"))
                    {
                        RebuildLightmapUVs();
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("To enable generation of lightmap UVs for this Mesh, please enable the 'Lightmap Static' property.", MessageType.Info);
            }
        }