示例#1
0
 /// <summary>
 /// Creates a temporary UMAContext for use when editing recipes when the open Scene does not have an UMAContext or libraries set up
 /// </summary>
 ///
 public override UMAContext CreateEditorContext()
 {
     UMAContext.CreateEditorContext();
     return(UMAContext.Instance);
 }
        public bool AddExtraStuff()
        {
            SerializedProperty baseRaceRecipe = serializedObject.FindProperty("baseRaceRecipe");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(baseRaceRecipe, true);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            if (wardrobeSlotList == null)
            {
                InitWardrobeSlotList();
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            wardrobeSlotList.DoLayoutList();
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                if (!race.ValidateWardrobeSlots())
                {
                    EditorUtility.SetDirty(race);
                }
            }
            //new CrossCompatibilitySettings
            //To push any old settings in RaceData.backwardsCompatibleWith into the new crossCompatibilitySettings we have to call GetCrossCompatibleRaces() directly on the target
#pragma warning disable 618
            if (race.backwardsCompatibleWith.Count > 0)
            {
                var cc = race.GetCrossCompatibleRaces();
                if (cc.Count > 0)
                {
                    serializedObject.Update();
                }
            }
#pragma warning restore 618
            SerializedProperty _crossCompatibilitySettings     = serializedObject.FindProperty("_crossCompatibilitySettings");
            SerializedProperty _crossCompatibilitySettingsData = _crossCompatibilitySettings.FindPropertyRelative("settingsData");
            //draw the new version of the crossCompatibility list that allows users to define what slots in this races base recipe equate to in the backwards compatible races base recipe
            _crossCompatibilitySettings.isExpanded = EditorGUILayout.Foldout(_crossCompatibilitySettings.isExpanded, "Cross Compatibility Settings");
            if (_crossCompatibilitySettings.isExpanded)
            {
                //draw an info foldout
                EditorGUI.indentLevel++;
                _crossCompatibilitySettingsData.isExpanded = EditorGUILayout.Foldout(_crossCompatibilitySettingsData.isExpanded, "Help");
                if (_crossCompatibilitySettingsData.isExpanded)
                {
                    var helpText = "CrossCompatibilitySettings allows this race to wear wardrobe slots from another race, if this race has a wardrobe slot that the recipe is set to.";
                    helpText += " You can further configure the compatibility settings for each compatible race to define 'equivalent' slotdatas in the races' base recipes.";
                    helpText += " For example you could define that this races 'highpolyMaleChest' slotdata in its base recipe is equivalent to HumanMales 'MaleChest' slot data in its base recipe.";
                    helpText += " This would mean that any recipes which hid or applied an overlay to 'MaleChest' would hide or apply an overlay to 'highPolyMaleChest' on this race.";
                    helpText += " If 'Overlays Match' is unchecked then overlays in a recipe wont be applied.";
                    EditorGUILayout.HelpBox(helpText, MessageType.Info);
                }
                EditorGUI.indentLevel--;
                if (baseRaceRecipe.objectReferenceValue != null)
                {
                    Rect dropArea = new Rect();
                    dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));
                    GUI.Box(dropArea, "Drag cross compatible Races here. Click to pick.");
                    CompatibleRacesDropArea(dropArea, _crossCompatibilitySettingsData);
                    EditorGUILayout.Space();
                    //update the foldouts list if the dropbox changes anything
                    if (_BCFoldouts.Length != _crossCompatibilitySettingsData.arraySize)
                    {
                        Array.Resize <bool>(ref _BCFoldouts, _crossCompatibilitySettingsData.arraySize);
                    }
                    //we need an uptodate list of the slots in THIS races base recipe
                    baseSlotsList.Clear();
                    baseSlotsNamesList.Clear();
                    //editing a race will require a context too because we need to get the base recipes and their slots
                    if (UMAContext.FindInstance() == null)
                    {
                        EditorUMAContext = UMAContext.CreateEditorContext();
                    }
                    UMAData.UMARecipe thisBaseRecipe = (baseRaceRecipe.objectReferenceValue as UMARecipeBase).GetCachedRecipe(UMAContext.Instance);
                    SlotData[]        thisBaseSlots  = thisBaseRecipe.GetAllSlots();
                    foreach (SlotData slot in thisBaseSlots)
                    {
                        if (slot != null)
                        {
                            baseSlotsList.Add(slot);
                            baseSlotsNamesList.Add(slot.slotName);
                        }
                    }
                    List <int> crossCompatibleSettingsToDelete = new List <int>();
                    //draw a foldout area for each compatible race that will show an entry for each slot in this races base recipe
                    //with a picker to choose the slot from the compatible race's base recipe that it equates to
                    for (int i = 0; i < _crossCompatibilitySettingsData.arraySize; i++)
                    {
                        bool del            = false;
                        var  thisCCSettings = _crossCompatibilitySettingsData.GetArrayElementAtIndex(i).FindPropertyRelative("ccSettings");
                        var  ccRaceName     = _crossCompatibilitySettingsData.GetArrayElementAtIndex(i).FindPropertyRelative("ccRace").stringValue;
                        //this could be missing- we should show that
                        var label = ccRaceName;
                        if (GetCompatibleRaceData(ccRaceName) == null)
                        {
                            label += " (missing)";
                        }
                        GUIHelper.FoldoutBar(ref _BCFoldouts[i], label, out del);
                        if (del)
                        {
                            crossCompatibleSettingsToDelete.Add(i);
                        }
                        if (_BCFoldouts[i])
                        {
                            DrawCCUI(ccRaceName, baseRaceRecipe, thisCCSettings);
                        }
                    }
                    if (crossCompatibleSettingsToDelete.Count > 0)
                    {
                        foreach (int del in crossCompatibleSettingsToDelete)
                        {
                            _crossCompatibilitySettingsData.DeleteArrayElementAtIndex(del);
                            serializedObject.ApplyModifiedProperties();
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Please define this races baseRaceRecipe before trying to define its cross compatibility settings.", MessageType.Info);
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("raceThumbnails"), true);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            return(false);
        }