Exemplo n.º 1
0
            public bool OnGUI()
            {
                bool changed = false;

                if (_race != null)
                {
                    if (_race.wardrobeSlots.Count > 0)
                    {
                        var context = UMAContext.FindInstance();
                        if (context == null)
                        {
                            var _errorMessage = "Editing a recipe requires a loaded scene with a valid UMAContext.";
                            Debug.LogWarning(_errorMessage);
                        }

                        if (_wardrobeSet == null || context == null)
                        {
                            return(false);
                        }
                        GUIHelper.BeginVerticalPadded(10, new Color(0.75f, 0.875f, 1f));
                        foreach (string wsl in _race.wardrobeSlots)
                        {
                            if (wsl == "None")
                            {
                                continue;
                            }

                            if (wsl == "FullOutfit" && _allowWardrobeCollectionSlot == false)
                            {
                                continue;
                            }

                            WardrobeSlotRecipePopup thisPicker = null;
                            bool assignedPicker = false;
                            for (int wsi = 0; wsi < _wardrobeSet.Count; wsi++)
                            {
                                if (_wardrobeSet[wsi].slot == wsl)
                                {
                                    thisPicker     = new WardrobeSlotRecipePopup(_race.raceName, wsl, _wardrobeSet[wsi].recipe);
                                    assignedPicker = true;
                                    break;
                                }
                            }
                            if (!assignedPicker)                            //means there was nothing in the wardrobe set for it
                            {
                                thisPicker = new WardrobeSlotRecipePopup(_race.raceName, wsl, "");
                            }
                            if (thisPicker.OnGUI())
                            {
                                changed = true;
                                if (thisPicker.RecipeName != "None" && thisPicker.RecipeName != "")
                                {
                                    bool contained = false;
                                    for (int i = 0; i < _wardrobeSet.Count; i++)
                                    {
                                        if (_wardrobeSet[i].slot == wsl)
                                        {
                                            _wardrobeSet[i].recipe = thisPicker.RecipeName;
                                            contained = true;
                                            break;
                                        }
                                    }
                                    if (!contained)
                                    {
                                        _wardrobeSet.Add(new WardrobeSettings(wsl, thisPicker.RecipeName));
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < _wardrobeSet.Count; i++)
                                    {
                                        if (_wardrobeSet[i].slot == wsl)
                                        {
                                            _wardrobeSet.RemoveAt(i);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (WardrobeSet.Count > 0)
                        {
                            if (GUILayout.Button(new GUIContent("UpdateSharedColors", "Automatically adds any shared colors defined in the selected recipes to this recipes SharedColors")))
                            {
                                for (int i = 0; i < _wardrobeSet.Count; i++)
                                {
                                    changed = AddSharedColorsFromRecipe(_wardrobeSet[i].recipe, _recipe) == true ? true : changed;
                                }
                            }
                        }
                        GUIHelper.EndVerticalPadded(10);
                    }
                }
                return(changed);
            }
Exemplo n.º 2
0
            public bool OnGUI()
            {
                bool changed = false;

                if (_race != null)
                {
                    if (_race.wardrobeSlots.Count > 0)
                    {
                        var context = UMAContextBase.Instance;
                        if (context == null)
                        {
                            var _errorMessage = "Editing a recipe requires a loaded scene with a valid UMAContextBase.";
                            Debug.LogWarning(_errorMessage);
                        }

                        if (_wardrobeSet == null || context == null)
                        {
                            return(false);
                        }
                        GUIHelper.BeginVerticalPadded(10, new Color(0.75f, 0.875f, 1f));

                        EditorGUILayout.HelpBox("Recently added recipes not showing up? Make sure you have added them to the 'UMA Global Library' and click the 'Refresh Recipes' button below.", MessageType.Info);
                        if (GUILayout.Button("Refresh Recipes"))
                        {
                            context.ValidateDictionaries();
                            return(false);
                        }
                        //a dictionary of slots that are being assigned by WardrobeCollections
                        var slotsAssignedByWCs = new Dictionary <string, string>();
                        if (_allowWardrobeCollectionSlot)
                        {
                            var wcRecipesForRace = context.GetRecipesForRaceSlot(_race.raceName, "WardrobeCollection");
                            var wcGroupDict      = new Dictionary <string, List <UMARecipeBase> >();
                            //I'm using reflection here to get fields and methods from the UMAWardrobeCollection type so this will still work if 'StandardAssets' is moved to 'Standard Assets'
                            for (int i = 0; i < wcRecipesForRace.Count; i++)
                            {
                                Type wcType = wcRecipesForRace[i].GetType();
                                if (wcType.ToString().Replace(wcType.Namespace + ".", "") == "UMAWardrobeCollection")
                                {
                                    FieldInfo wcRecipeSlotField = wcType.GetField("wardrobeSlot", BindingFlags.Public | BindingFlags.Instance);
                                    var       wcRecipeSlot      = (string)wcRecipeSlotField.GetValue(wcRecipesForRace[i]);
                                    if (!wcGroupDict.ContainsKey(wcRecipeSlot))
                                    {
                                        wcGroupDict.Add(wcRecipeSlot, new List <UMARecipeBase>());
                                    }
                                    wcGroupDict[wcRecipeSlot].Add(wcRecipesForRace[i]);
                                }
                            }
                            if (wcGroupDict.Count > 0)
                            {
                                MethodInfo WCGetRacesWardrobeSetMethod = null;
                                EditorGUILayout.LabelField("WardrobeCollections");
                                EditorGUI.indentLevel++;
                                foreach (KeyValuePair <string, List <UMARecipeBase> > kp in wcGroupDict)
                                {
                                    if (WCGetRacesWardrobeSetMethod == null)
                                    {
                                        WCGetRacesWardrobeSetMethod = kp.Value[0].GetType().GetMethod("GetRacesWardrobeSet", new Type[] { typeof(RaceData) });
                                    }
                                    var selected      = 0;
                                    var prevRecipe    = "";
                                    var thisPopupVals = new List <string>();
                                    thisPopupVals.Add("None");
                                    for (int i = 0; i < kp.Value.Count; i++)
                                    {
                                        thisPopupVals.Add(kp.Value[i].name);
                                        //check if this is selected
                                        for (int wsi = 0; wsi < _wardrobeSet.Count; wsi++)
                                        {
                                            if (kp.Value[i].name == _wardrobeSet[wsi].recipe)
                                            {
                                                prevRecipe = _wardrobeSet[wsi].recipe;
                                                selected   = i + 1;
                                                var thisWCWardrobeSet = (List <WardrobeSettings>)WCGetRacesWardrobeSetMethod.Invoke(kp.Value[i], new object[] { _race });
                                                for (int wcwsi = 0; wcwsi < thisWCWardrobeSet.Count; wcwsi++)
                                                {
                                                    if (!slotsAssignedByWCs.ContainsKey(thisWCWardrobeSet[wcwsi].slot))
                                                    {
                                                        slotsAssignedByWCs.Add(thisWCWardrobeSet[wcwsi].slot, kp.Value[i].name);
                                                    }
                                                    else
                                                    {
                                                        slotsAssignedByWCs[thisWCWardrobeSet[wcwsi].slot] = kp.Value[i].name;
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    EditorGUI.BeginChangeCheck();
                                    var newSelected = EditorGUILayout.Popup(kp.Key, selected, thisPopupVals.ToArray());
                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        for (int wsi = 0; wsi < _wardrobeSet.Count; wsi++)
                                        {
                                            if (_wardrobeSet[wsi].recipe == prevRecipe)
                                            {
                                                //we need to remove the wardrobeSettings that has prevRecipe as its value from _wardrobeSettings
                                                if (newSelected == 0)
                                                {
                                                    _wardrobeSet.RemoveAt(wsi);
                                                }
                                                else
                                                {
                                                    //we need to make wardrobeSettings that has prevRecipe have the new value
                                                    _wardrobeSet[wsi].recipe = thisPopupVals[newSelected];
                                                }
                                            }
                                        }
                                        changed = true;
                                    }
                                }
                                EditorGUI.indentLevel--;
                                EditorGUILayout.Space();
                                EditorGUILayout.LabelField("WardrobeSlots");
                                EditorGUI.indentLevel++;
                            }
                        }
                        foreach (string wsl in _race.wardrobeSlots)
                        {
                            if (wsl == "None")
                            {
                                continue;
                            }

                            //Obsolete- now wardrobeCollections apply their WardrobeSet to any slots
                            //if (wsl == "FullOutfit" && _allowWardrobeCollectionSlot == false)
                            //	continue;

                            WardrobeSlotRecipePopup thisPicker = null;
                            bool assignedPicker = false;
                            for (int wsi = 0; wsi < _wardrobeSet.Count; wsi++)
                            {
                                if (_wardrobeSet[wsi].slot == wsl)
                                {
                                    thisPicker     = new WardrobeSlotRecipePopup(_race.raceName, wsl, _wardrobeSet[wsi].recipe);
                                    assignedPicker = true;
                                    break;
                                }
                            }
                            if (!assignedPicker)                            //means there was nothing in the wardrobe set for it
                            {
                                //This may still be being assigned by a wardrobe collection though so show that
                                var wcOverrideName = "";
                                if (slotsAssignedByWCs.ContainsKey(wsl))
                                {
                                    wcOverrideName = slotsAssignedByWCs[wsl];
                                }
                                thisPicker = new WardrobeSlotRecipePopup(_race.raceName, wsl, "");
                            }
                            if (thisPicker.OnGUI())
                            {
                                changed = true;
                                if (thisPicker.RecipeName != "None" && thisPicker.RecipeName != "")
                                {
                                    bool contained = false;
                                    for (int i = 0; i < _wardrobeSet.Count; i++)
                                    {
                                        if (_wardrobeSet[i].slot == wsl)
                                        {
                                            _wardrobeSet[i].recipe = thisPicker.RecipeName;
                                            contained = true;
                                            break;
                                        }
                                    }
                                    if (!contained)
                                    {
                                        _wardrobeSet.Add(new WardrobeSettings(wsl, thisPicker.RecipeName));
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < _wardrobeSet.Count; i++)
                                    {
                                        if (_wardrobeSet[i].slot == wsl)
                                        {
                                            _wardrobeSet.RemoveAt(i);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (_allowWardrobeCollectionSlot)
                        {
                            EditorGUI.indentLevel--;
                        }
                        if (WardrobeSet.Count > 0)
                        {
                            EditorGUILayout.Space();
                            if (GUILayout.Button(new GUIContent("UpdateSharedColors", "Automatically adds any shared colors defined in the selected recipes to this recipes SharedColors")))
                            {
                                for (int i = 0; i < _wardrobeSet.Count; i++)
                                {
                                    changed = AddSharedColorsFromRecipe(_wardrobeSet[i].recipe, _recipe) == true ? true : changed;
                                }
                            }
                        }
                        GUIHelper.EndVerticalPadded(10);
                    }
                }
                return(changed);
            }
Exemplo n.º 3
0
            public bool OnGUI()
            {
                bool changed = false;

                if (_race != null)
                {
                    if (_race.wardrobeSlots.Count > 0)
                    {
                        var context = UMAContext.FindInstance();
                        if (context == null)
                        {
                            var _errorMessage = "Editing a recipe requires a loaded scene with a valid UMAContext.";
                            Debug.LogWarning(_errorMessage);
                        }

                        if (_wardrobeSet == null || context == null)
                        {
                            return(false);
                        }
                        GUIHelper.BeginVerticalPadded(10, new Color(0.75f, 0.875f, 1f));
                        if (_allowWardrobeCollectionSlot)
                        {
                            var wcRecipesForRace = context.dynamicCharacterSystem.GetRecipesForRaceSlot(_race.raceName, "WardrobeCollection");
                            var wcGroupDict      = new Dictionary <string, List <string> >();
                            //for 'Standard Assets' we need to do some kind of get Types thing I think because we then need to use reflection to get the wardrobeSlot field
                            //how can we get what we want here when WardrobeCollections dont exist in Standard Assets (if 'StandardAssets' has been moved there)
                            for (int i = 0; i < wcRecipesForRace.Count; i++)
                            {
                                Type wcType = wcRecipesForRace[i].GetType();
                                if (wcType.ToString().Replace(wcType.Namespace + ".", "") == "UMAWardrobeCollection")
                                {
                                    FieldInfo wcRecipeSlotField = wcType.GetField("wardrobeSlot", BindingFlags.Public | BindingFlags.Instance);
                                    var       wcRecipeSlot      = (string)wcRecipeSlotField.GetValue(wcRecipesForRace[i]);
                                    if (!wcGroupDict.ContainsKey(wcRecipeSlot))
                                    {
                                        wcGroupDict.Add(wcRecipeSlot, new List <string>());
                                    }
                                    wcGroupDict[wcRecipeSlot].Add(wcRecipesForRace[i].name);
                                }
                            }
                            if (wcGroupDict.Count > 0)
                            {
                                EditorGUILayout.LabelField("WardrobeCollections");
                                EditorGUI.indentLevel++;
                                foreach (KeyValuePair <string, List <string> > kp in wcGroupDict)
                                {
                                    var thisPopupVals = new List <string>();
                                    thisPopupVals.Add("None");
                                    thisPopupVals.AddRange(kp.Value);
                                    var selected   = 0;
                                    var prevRecipe = "";
                                    //if one of the recipes in the wardrobe set is one of these then its selected
                                    for (int pvi = 0; pvi < thisPopupVals.Count; pvi++)
                                    {
                                        for (int wsi = 0; wsi < _wardrobeSet.Count; wsi++)
                                        {
                                            if (thisPopupVals[pvi] == _wardrobeSet[wsi].recipe)
                                            {
                                                prevRecipe = _wardrobeSet[wsi].recipe;
                                                selected   = pvi;
                                                break;
                                            }
                                        }
                                    }
                                    EditorGUI.BeginChangeCheck();
                                    var newSelected = EditorGUILayout.Popup(kp.Key, selected, thisPopupVals.ToArray());
                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        for (int wsi = 0; wsi < _wardrobeSet.Count; wsi++)
                                        {
                                            if (_wardrobeSet[wsi].recipe == prevRecipe)
                                            {
                                                //we need to remove the wardrobeSettings that has prevRecipe as its value from _wardrobeSettings
                                                if (newSelected == 0)
                                                {
                                                    _wardrobeSet.RemoveAt(wsi);
                                                }
                                                else
                                                {
                                                    //we need to make wardrobeSettings that has prevRecipe have the new value
                                                    _wardrobeSet[wsi].recipe = thisPopupVals[newSelected];
                                                }
                                            }
                                        }
                                        changed = true;
                                    }
                                }
                                EditorGUI.indentLevel--;
                                EditorGUILayout.Space();
                                EditorGUILayout.LabelField("WardrobeSlots");
                                EditorGUI.indentLevel++;
                            }
                        }
                        foreach (string wsl in _race.wardrobeSlots)
                        {
                            if (wsl == "None")
                            {
                                continue;
                            }

                            if (wsl == "FullOutfit" && _allowWardrobeCollectionSlot == false)
                            {
                                continue;
                            }

                            WardrobeSlotRecipePopup thisPicker = null;
                            bool assignedPicker = false;
                            for (int wsi = 0; wsi < _wardrobeSet.Count; wsi++)
                            {
                                if (_wardrobeSet[wsi].slot == wsl)
                                {
                                    thisPicker     = new WardrobeSlotRecipePopup(_race.raceName, wsl, _wardrobeSet[wsi].recipe);
                                    assignedPicker = true;
                                    break;
                                }
                            }
                            if (!assignedPicker)                            //means there was nothing in the wardrobe set for it
                            {
                                thisPicker = new WardrobeSlotRecipePopup(_race.raceName, wsl, "");
                            }
                            if (thisPicker.OnGUI())
                            {
                                changed = true;
                                if (thisPicker.RecipeName != "None" && thisPicker.RecipeName != "")
                                {
                                    bool contained = false;
                                    for (int i = 0; i < _wardrobeSet.Count; i++)
                                    {
                                        if (_wardrobeSet[i].slot == wsl)
                                        {
                                            _wardrobeSet[i].recipe = thisPicker.RecipeName;
                                            contained = true;
                                            break;
                                        }
                                    }
                                    if (!contained)
                                    {
                                        _wardrobeSet.Add(new WardrobeSettings(wsl, thisPicker.RecipeName));
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < _wardrobeSet.Count; i++)
                                    {
                                        if (_wardrobeSet[i].slot == wsl)
                                        {
                                            _wardrobeSet.RemoveAt(i);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (_allowWardrobeCollectionSlot)
                        {
                            EditorGUI.indentLevel--;
                        }
                        if (WardrobeSet.Count > 0)
                        {
                            EditorGUILayout.Space();
                            if (GUILayout.Button(new GUIContent("UpdateSharedColors", "Automatically adds any shared colors defined in the selected recipes to this recipes SharedColors")))
                            {
                                for (int i = 0; i < _wardrobeSet.Count; i++)
                                {
                                    changed = AddSharedColorsFromRecipe(_wardrobeSet[i].recipe, _recipe) == true ? true : changed;
                                }
                            }
                        }
                        GUIHelper.EndVerticalPadded(10);
                    }
                }
                return(changed);
            }