public static bool SetStaticFlags(UnityEngine.Object[] targetObjects, int changedFlags, bool flagValue)
        {
            bool flag = changedFlags == -1;
            StaticEditorFlags staticEditorFlags = (StaticEditorFlags)((!flag) ? ((int)Enum.Parse(typeof(StaticEditorFlags), changedFlags.ToString())) : 0);

            GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(targetObjects.OfType <GameObject>(), "Change Static Flags", (!flag) ? string.Concat(new string[]
            {
                "Do you want to ",
                (!flagValue) ? "disable" : "enable",
                " the ",
                ObjectNames.NicifyVariableName(staticEditorFlags.ToString()),
                " flag for all the child objects as well?"
            }) : ("Do you want to " + ((!flagValue) ? "disable" : "enable") + " the static flags for all the child objects as well?"));
            if (shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.Cancel)
            {
                GUIUtility.ExitGUI();
                return(false);
            }
            GameObject[] objects = SceneModeUtility.GetObjects(targetObjects, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
            Undo.RecordObjects(objects, "Change Static Flags");
            GameObject[] array = objects;
            for (int i = 0; i < array.Length; i++)
            {
                GameObject go  = array[i];
                int        num = (int)GameObjectUtility.GetStaticEditorFlags(go);
                num = ((!flagValue) ? (num & ~changedFlags) : (num | changedFlags));
                GameObjectUtility.SetStaticEditorFlags(go, (StaticEditorFlags)num);
            }
            return(true);
        }
Beispiel #2
0
        public void ShowMenu()
        {
            GenericMenu staticFlagMenu = new GenericMenu();

            staticFlagMenu.AddItem(new GUIContent("Nothing"), (int)this.StaticFlags == 0, this.FlagsChanged, 0);
            staticFlagMenu.AddItem(new GUIContent("Everything"), (int)this.StaticFlags == -1, this.FlagsChanged, -1);
            staticFlagMenu.AddSeparator("");
            foreach (object staticEditorFlagObject in Enum.GetValues(typeof(StaticEditorFlags)))
            {
                StaticEditorFlags staticEditorFlag = (StaticEditorFlags)staticEditorFlagObject;
                staticFlagMenu.AddItem(new GUIContent(staticEditorFlag.ToString()), (this.StaticFlags & staticEditorFlag) > 0, this.FlagsChanged, staticEditorFlag);
            }
            staticFlagMenu.ShowAsContext();
        }
Beispiel #3
0
        public static bool SetStaticFlags(UnityEngine.Object[] targetObjects, int changedFlags, bool flagValue)
        {
            bool flag = changedFlags == -1;
            StaticEditorFlags flags = !flag ? ((StaticEditorFlags)Enum.Parse(typeof(StaticEditorFlags), changedFlags.ToString())) : ((StaticEditorFlags)0);

            GameObjectUtility.ShouldIncludeChildren children = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(targetObjects.OfType <GameObject>(), "Change Static Flags", !flag ? ("Do you want to " + (!flagValue ? "disable" : "enable") + " the " + ObjectNames.NicifyVariableName(flags.ToString()) + " flag for all the child objects as well?") : ("Do you want to " + (!flagValue ? "disable" : "enable") + " the static flags for all the child objects as well?"));
            if (children == GameObjectUtility.ShouldIncludeChildren.Cancel)
            {
                GUIUtility.ExitGUI();
                return(false);
            }
            GameObject[] objects = GetObjects(targetObjects, children == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
            Undo.RecordObjects(objects, "Change Static Flags");
            foreach (GameObject obj2 in objects)
            {
                int staticEditorFlags = (int)GameObjectUtility.GetStaticEditorFlags(obj2);
                staticEditorFlags = !flagValue ? (staticEditorFlags & ~changedFlags) : (staticEditorFlags | changedFlags);
                GameObjectUtility.SetStaticEditorFlags(obj2, (StaticEditorFlags)staticEditorFlags);
            }
            return(true);
        }
Beispiel #4
0
        public static bool SetStaticFlags(UnityEngine.Object[] targetObjects, int changedFlags, bool flagValue)
        {
            bool flag = changedFlags == -1;
            StaticEditorFlags        staticEditorFlags1 = !flag ? (StaticEditorFlags)Enum.Parse(typeof(StaticEditorFlags), changedFlags.ToString()) : (StaticEditorFlags)0;
            IEnumerable <GameObject> gameObjects        = targetObjects.OfType <GameObject>();
            string title = "Change Static Flags";
            string message;

            if (flag)
            {
                message = "Do you want to " + (!flagValue ? "disable" : "enable") + " the static flags for all the child objects as well?";
            }
            else
            {
                message = "Do you want to " + (!flagValue ? "disable" : "enable") + " the " + ObjectNames.NicifyVariableName(staticEditorFlags1.ToString()) + " flag for all the child objects as well?";
            }
            GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(gameObjects, title, message);
            if (shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.Cancel)
            {
                GUIUtility.ExitGUI();
                return(false);
            }
            GameObject[] objects = SceneModeUtility.GetObjects(targetObjects, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
            Undo.RecordObjects((UnityEngine.Object[])objects, "Change Static Flags");
            foreach (GameObject go in objects)
            {
                int staticEditorFlags2 = (int)GameObjectUtility.GetStaticEditorFlags(go);
                int num = !flagValue ? staticEditorFlags2 & ~changedFlags : staticEditorFlags2 | changedFlags;
                GameObjectUtility.SetStaticEditorFlags(go, (StaticEditorFlags)num);
            }
            return(true);
        }
        public static bool SetStaticFlags(Object[] targetObjects, int changedFlags, bool flagValue)
        {
            bool allFlagsAreChanged = (changedFlags == ~0);
            var  msgChangedFlags    = changedFlags;

            if (msgChangedFlags < 0 && !allFlagsAreChanged)
            {
                //In order to have a list of human readable list of changed flags,
                //we need to filter out bits that does not correspont to any option.
                int allPossibleValues = 0;
                var values            = Enum.GetValues(typeof(StaticEditorFlags));
                foreach (var value in values)
                {
                    allPossibleValues |= (int)value;
                }

                msgChangedFlags = msgChangedFlags & allPossibleValues;
            }
            StaticEditorFlags flag = allFlagsAreChanged ?
                                     (StaticEditorFlags)0 :
                                     (StaticEditorFlags)Enum.Parse(typeof(StaticEditorFlags), msgChangedFlags.ToString());


            // Should we include child objects?
            GameObjectUtility.ShouldIncludeChildren includeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(targetObjects.OfType <GameObject>(), "Change Static Flags",
                                                                                                                            allFlagsAreChanged ?
                                                                                                                            "Do you want to " + (flagValue ? "enable" : "disable") + " the static flags for all the child objects as well?" :
                                                                                                                            "Do you want to " + (flagValue ? "enable" : "disable") + " the " + ObjectNames.NicifyVariableName(flag.ToString()) + " flag for all the child objects as well?");

            if (includeChildren == GameObjectUtility.ShouldIncludeChildren.Cancel)
            {
                EditorGUIUtility.ExitGUI();
                return(false);
            }
            var objects = GetObjects(targetObjects, includeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);

            Undo.RecordObjects(objects, "Change Static Flags");

            // Calculate new flags value separately for each object so other flags are not affected.
            foreach (GameObject go in objects)
            {
                int goFlags = (int)GameObjectUtility.GetStaticEditorFlags(go);
                goFlags = flagValue ?
                          goFlags | changedFlags :
                          goFlags & ~changedFlags;
                GameObjectUtility.SetStaticEditorFlags(go, (StaticEditorFlags)goFlags);
            }

            return(true);
        }
Beispiel #6
0
        public static bool SetStaticFlags(Object[] targetObjects, int changedFlags, bool flagValue)
        {
            bool allFlagsAreChanged = (changedFlags == int.MaxValue);
            var  msgChangedFlags    = changedFlags;

            if (msgChangedFlags < 0 && !allFlagsAreChanged)
            {
                //In order to have a list of human readable list of changed flags,
                //we need to filter out bits that does not correspont to any option.
                int allPossibleValues = 0;
                var values            = Enum.GetValues(typeof(StaticEditorFlags));
                foreach (var value in values)
                {
                    allPossibleValues |= (int)value;
                }

                msgChangedFlags = msgChangedFlags & allPossibleValues;
            }
            StaticEditorFlags flag = allFlagsAreChanged ?
                                     (StaticEditorFlags)0 :
                                     (StaticEditorFlags)Enum.Parse(typeof(StaticEditorFlags), msgChangedFlags.ToString());


            // Should we include child objects?
            GameObjectUtility.ShouldIncludeChildren includeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(targetObjects.OfType <GameObject>(), "Change Static Flags",
                                                                                                                            allFlagsAreChanged ?
                                                                                                                            "Do you want to " + (flagValue ? "enable" : "disable") + " the static flags for all the child objects as well?" :
                                                                                                                            "Do you want to " + (flagValue ? "enable" : "disable") + " the " + ObjectNames.NicifyVariableName(flag.ToString()) + " flag for all the child objects as well?");

            if (includeChildren == GameObjectUtility.ShouldIncludeChildren.Cancel)
            {
                EditorGUIUtility.ExitGUI();
                return(false);
            }
            var objects = GetObjects(targetObjects, includeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);

            Undo.RecordObjects(objects, "Change Static Flags");

            // Calculate new flags value separately for each object so other flags are not affected.
            foreach (GameObject go in objects)
            {
                int goFlags = (int)GameObjectUtility.GetStaticEditorFlags(go);

                // Following change is for backward compatibility after fixing case 1221145
                if (goFlags < 0)
                {
                    goFlags = int.MaxValue;
                }

                // MaxValue will cause issues when changing it to other values so we set it to the max possible value
                // that Static Editor flags can have before doing anything else with it
                if (goFlags == int.MaxValue && flagValue == false)
                {
                    goFlags = (int)Math.Pow(2, Enum.GetNames(typeof(StaticEditorFlags)).Length - 1) - 1;
                }

                goFlags = flagValue ?
                          goFlags | changedFlags :
                          goFlags & ~changedFlags;
                GameObjectUtility.SetStaticEditorFlags(go, (StaticEditorFlags)goFlags);
            }

            return(true);
        }