Exemple #1
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);
        }
        public static bool SetStaticFlags(UnityEngine.Object[] targetObjects, int changedFlags, bool flagValue)
        {
            bool flag = changedFlags == -1;
            StaticEditorFlags staticEditorFlags = (!flag) ? ((StaticEditorFlags)Enum.Parse(typeof(StaticEditorFlags), changedFlags.ToString())) : ((StaticEditorFlags)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?"));
            bool result;

            if (shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.Cancel)
            {
                GUIUtility.ExitGUI();
                result = false;
            }
            else
            {
                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);
                }
                result = true;
            }
            return(result);
        }
Exemple #3
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);
        }