Ejemplo n.º 1
0
 //This is used when an inspected recipe asset is saved
 public override void Save(UMAData.UMARecipe umaRecipe, UMAContext context)
 {
     if (recipeType == "Wardrobe")            //Wardrobe Recipes can save the standard UMA way- they dont have WardrobeSets- although the recipe string wont have a packedRecipeType field
     {
         base.Save(umaRecipe, context);
     }
     else if (recipeType != "Standard")            //this will just be for type DynamicCharacterAvatar- and WardrobeCollection if we add that
     {
         var packedRecipe = PackRecipeV3(umaRecipe);
         //DCSPackRecipe doesn't do any more work, it just gets the values from PackRecipeV3 that we need and discards the rest
         var packedRecipeToSave = new DCSPackRecipe(packedRecipe, this.name, recipeType, activeWardrobeSet);
         recipeString = JsonUtility.ToJson(packedRecipeToSave);
     }
     else             //This will be Standard- this is 'backwards Compatible' and is also how the Recipe Editor saves 'backwardsCompatible' 'Standard' recipes when they are inspected
     {
         umaRecipe.MergeMatchingOverlays();
         var packedRecipe       = PackRecipeV3(umaRecipe);
         var packedRecipeToSave = new DCSUniversalPackRecipe(packedRecipe);                //this gets us a recipe with all the standard stuff plus our extra fields
         //so now we can save the wardrobeSet into it if it existed
         if (activeWardrobeSet != null)
         {
             if (activeWardrobeSet.Count > 0)
             {
                 packedRecipeToSave.wardrobeSet = activeWardrobeSet;
             }
         }
         recipeString = JsonUtility.ToJson(packedRecipeToSave);
     }
 }
Ejemplo n.º 2
0
        //Override Load from PackedRecipeBase
        /// <summary>
        /// Load this Recipe's recipeString into the specified UMAData.UMARecipe. If there is Wardrobe data in the recipe string, its values are set to this recipe assets 'activeWardrobeSet' field
        /// </summary>
        /// <param name="umaRecipe">UMA recipe.</param>
        /// <param name="context">Context.</param>
        public override void Load(UMA.UMAData.UMARecipe umaRecipe, UMAContext context = null)
        {
            //This check can be removed in future- If we set the recipeType properly from now on we should not need to do this check
            var typeInRecipe = GetRecipesType(recipeString);

            recipeType = typeInRecipe != "Standard" ? typeInRecipe : recipeType;
            if (RecipeHasWardrobeSet(recipeString))
            {
                activeWardrobeSet = GetRecipesWardrobeSet(recipeString);
            }
            //if its an old UMARecipe there wont be an activeWardrobeSet field
            if (activeWardrobeSet == null)
            {
                recipeType = "Standard";
                base.Load(umaRecipe, context);
                return;
            }
            //if it has a wardrobeSet or was saved using the DCSPackRecipe Model
            if (activeWardrobeSet.Count > 0 || (recipeType == "DynamicCharacterAvatar" /*|| recipeType == "WardrobeCollection"*/))
            {
                var packedRecipe = PackedLoadDCSInternal(context /*, recipeString*/);
                UnpackRecipe(umaRecipe, packedRecipe, context);
            }
            else             //we can use standard UMALoading
            {
                base.Load(umaRecipe, context);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Save data from the specified UMA recipe.
        /// </summary>
        /// <param name="umaRecipe">UMA recipe.</param>
        /// <param name="context">Context.</param>
        public override void Save(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
        {
            umaRecipe.MergeMatchingOverlays();
            var packedRecipe = PackRecipeV3(umaRecipe);

            PackedSave(packedRecipe, context);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Deserialize recipeString data into packed recipe.
 /// </summary>
 /// <returns>The packed recipe.</returns>
 /// <param name="context">Context.</param>
 public override UMAPackedRecipeBase.UMAPackRecipe PackedLoad(UMAContext context = null)
 {
     if ((recipeString == null) || (recipeString.Length == 0))
     {
         return(new UMAPackRecipe());
     }
     return(JsonUtility.FromJson <UMAPackRecipe>(recipeString));
 }
Ejemplo n.º 5
0
 //TODO: once everyone has their recipes updated remove this- we only want UMATextRecipes to save as 'Standard'
 /// <summary>
 /// Saves a 'Standard' UMATextRecipe. If saving a DynamicCharacterAvatar as 'Backwards Compatible' this will save a recipe that has slots/overlay data AND a wardrobe set
 /// </summary>
 public void Save(UMAData.UMARecipe umaRecipe, UMAContext context, Dictionary <string, UMATextRecipe> wardrobeRecipes, bool backwardsCompatible = true)
 {
     if (wardrobeRecipes.Count > 0)
     {
         activeWardrobeSet = GenerateWardrobeSet(wardrobeRecipes);
     }
     recipeType = backwardsCompatible ? "Standard" : "DynamicCharacterAvatar";
     Save(umaRecipe, context);
 }
Ejemplo n.º 6
0
        static void CreateDynamicAvatarMenuItem()
        {
            var res = new GameObject("New Dynamic Avatar");
            var da  = res.AddComponent <UMADynamicAvatar>();

            da.context      = UMAContext.FindInstance();
            da.umaGenerator = Component.FindObjectOfType <UMAGeneratorBase>();
            UnityEditor.Selection.activeGameObject = res;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Return a cached version of the UMA recipe, Load if required.
        /// </summary>
        /// <returns>The cached recipe.</returns>
        /// <param name="context">Context.</param>
        public UMAData.UMARecipe GetCachedRecipe(UMAContext context)
        {
            if (!cached)
            {
                umaRecipe = new UMAData.UMARecipe();
                Load(umaRecipe, context);
            }

            return(umaRecipe);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Adds additional, non serialized, recipes.
 /// </summary>
 /// <param name="umaAdditionalRecipes">Additional recipes.</param>
 /// <param name="context">Context.</param>
 public void AddAdditionalRecipes(UMARecipeBase[] umaAdditionalRecipes, UMAContext context)
 {
     if (umaAdditionalRecipes != null)
     {
         foreach (var umaAdditionalRecipe in umaAdditionalRecipes)
         {
             UMARecipe cachedRecipe = umaAdditionalRecipe.GetCachedRecipe(context);
             umaRecipe.Merge(cachedRecipe, true);
         }
     }
 }
Ejemplo n.º 9
0
        public void Initialize()
        {
            if (context == null)
            {
                context = UMAContext.FindInstance();
            }

            if (umaData == null)
            {
                umaData = GetComponent <UMAData>();
                if (umaData == null)
                {
                    umaData = gameObject.AddComponent <UMAData>();
                    if (umaGenerator != null && !umaGenerator.gameObject.activeInHierarchy)
                    {
                        if (Debug.isDebugBuild)
                        {
                            Debug.LogError("Invalid UMA Generator on Avatar.", gameObject);
                            Debug.LogError("UMA generators must be active scene objects!", umaGenerator.gameObject);
                        }
                        umaGenerator = null;
                    }
                }
            }
            if (umaGenerator != null)
            {
                umaData.umaGenerator = umaGenerator;
            }
            if (CharacterCreated != null)
            {
                umaData.CharacterCreated = CharacterCreated;
            }
            if (CharacterBegun != null)
            {
                umaData.CharacterBegun = CharacterBegun;
            }
            if (CharacterDestroyed != null)
            {
                umaData.CharacterDestroyed = CharacterDestroyed;
            }
            if (CharacterUpdated != null)
            {
                umaData.CharacterUpdated = CharacterUpdated;
            }
            if (CharacterDnaUpdated != null)
            {
                umaData.CharacterDnaUpdated = CharacterDnaUpdated;
            }
        }
Ejemplo n.º 10
0
 #pragma warning restore 618
 /// <summary>
 /// Finds the singleton context in the scene.
 /// </summary>
 /// <returns>The UMA context.</returns>
 public static UMAContext FindInstance()
 {
     if (Instance == null)
     {
         var contextGO = GameObject.Find("UMAContext");
         if (contextGO != null)
         {
             Instance = contextGO.GetComponent <UMAContext>();
         }
     }
     if (Instance == null)
     {
         Instance = Component.FindObjectOfType <UMAContext>();
     }
     return(Instance);
 }
Ejemplo n.º 11
0
 #pragma warning disable 618
 public void Start()
 {
     if (!slotLibrary)
     {
         slotLibrary = GameObject.Find("SlotLibrary").GetComponent <SlotLibraryBase>();
     }
     if (!raceLibrary)
     {
         raceLibrary = GameObject.Find("RaceLibrary").GetComponent <RaceLibraryBase>();
     }
     if (!overlayLibrary)
     {
         overlayLibrary = GameObject.Find("OverlayLibrary").GetComponent <OverlayLibraryBase>();
     }
     // Note: Removed null check so that this is always assigned if you have a UMAContext in your scene
     // This will avoid those occasions where someone drops in a bogus context in a test scene, and then
     // later loads a valid scene (and everything breaks)
     Instance = this;
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns the recipe string as a DCSUniversalPackRecipe data model that can be used by any UMA
        /// </summary>
        /// <param name="context"></param>
        /// <param name="recipeToUnpack"></param>
        /// <param name="targetUTR">If set the wardrobeSet (if it exists) and the recipeType will assigned to UMATextRecipe assets fields (used by the Recipe Editor)</param>
        /// <returns></returns>
        public static DCSUniversalPackRecipe PackedLoadDCS(UMAContext context, string recipeToUnpack, UMATextRecipe targetUTR = null)
        {
            if ((recipeToUnpack == null) || (recipeToUnpack.Length == 0))
            {
                return(new DCSUniversalPackRecipe());
            }
            //first use the DCSRecipeChecker to check if this is a DCS recipe
            var typeInRecipe     = GetRecipesType(recipeToUnpack);
            var targetRecipeType = typeInRecipe != "Standard" ? typeInRecipe : (targetUTR != null ? targetUTR.recipeType : "Standard");

            if (targetUTR != null)
            {
                targetUTR.recipeType = targetRecipeType;
                if (RecipeHasWardrobeSet(recipeToUnpack))
                {
                    targetUTR.activeWardrobeSet = GetRecipesWardrobeSet(recipeToUnpack);
                }
            }
            //Right now the only recipeType that uses the DCSModel is "DynamicCharacterAvatar"
            DCSUniversalPackRecipe thisUnpackedUniversal = null;

            if (targetRecipeType == "DynamicCharacterAvatar" || targetRecipeType == "WardrobeCollection")
            {
                var thisUnpacked = JsonUtility.FromJson <DCSPackRecipe>(recipeToUnpack);
                thisUnpackedUniversal = new DCSUniversalPackRecipe(thisUnpacked);
            }
            else
            {
                var thisUnpacked = JsonUtility.FromJson <UMAPackRecipe>(recipeToUnpack);
                thisUnpackedUniversal = new DCSUniversalPackRecipe(thisUnpacked);
            }
            if (RecipeHasWardrobeSet(recipeToUnpack))
            {
                thisUnpackedUniversal.wardrobeSet = GetRecipesWardrobeSet(recipeToUnpack);
            }

            return(thisUnpackedUniversal);
        }
Ejemplo n.º 13
0
        public virtual void AddToContext(UMAContext context)
        {
            if (context == null)
            {
                return;
            }

            if (overlayData.Length > 0)
            {
#if UNITY_EDITOR
                UnityEditor.Undo.RecordObject(context, "Added overlays from asset collection");
#endif
                for (int i = 0; i < overlayData.Length; i++)
                {
                    context.AddOverlayAsset(overlayData[i]);
                }
            }
            if (slotData.Length > 0)
            {
#if UNITY_EDITOR
                UnityEditor.Undo.RecordObject(context, "Added slots from asset collection");
#endif
                for (int i = 0; i < slotData.Length; i++)
                {
                    context.AddSlotAsset(slotData[i]);
                }
            }
            if (raceData.Length > 0)
            {
#if UNITY_EDITOR
                UnityEditor.Undo.RecordObject(context, "Added races from asset collection");
#endif
                for (int i = 0; i < raceData.Length; i++)
                {
                    context.AddRace(raceData[i]);
                }
            }
        }
Ejemplo n.º 14
0
 public static UMAData.UMARecipe UnpackRecipeVersion3(UMAPackRecipe umaPackRecipe, UMAContext context)
 {
     UMAData.UMARecipe umaRecipe = new UMAData.UMARecipe();
     UnpackRecipeVersion3(umaRecipe, umaPackRecipe, context);
     return(umaRecipe);
 }
Ejemplo n.º 15
0
        public static void UnpackRecipeVersion2(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
        {
            umaRecipe.slotDataList = new SlotData[umaPackRecipe.slotsV2.Length];
            umaRecipe.SetRace(context.GetRace(umaPackRecipe.race));

            umaRecipe.ClearDna();
            List <UMADnaBase> packedDna = UnPackDNA(umaPackRecipe.packedDna);

            foreach (UMADnaBase umd in packedDna)
            {
                umaRecipe.AddDna(umd);
            }

            OverlayColorData[] colorData;
            if (UMAPackRecipe.ArrayHasData(umaPackRecipe.fColors))
            {
                colorData = new OverlayColorData[umaPackRecipe.fColors.Length];
                for (int i = 0; i < colorData.Length; i++)
                {
                    colorData[i] = new OverlayColorData();
                    umaPackRecipe.fColors[i].SetOverlayColorData(colorData[i]);
                }
            }
            else if (UMAPackRecipe.ArrayHasData(umaPackRecipe.colors))
            {
                colorData = new OverlayColorData[umaPackRecipe.colors.Length];
                for (int i = 0; i < colorData.Length; i++)
                {
                    colorData[i] = new OverlayColorData();
                    umaPackRecipe.colors[i].SetOverlayColorData(colorData[i]);
                }
            }
            else
            {
                colorData = new OverlayColorData[0];
            }

            umaRecipe.sharedColors = new OverlayColorData[umaPackRecipe.sharedColorCount];
            for (int i = 0; i < umaRecipe.sharedColors.Length; i++)
            {
                umaRecipe.sharedColors[i] = colorData[i];
            }

            for (int i = 0; i < umaPackRecipe.slotsV2.Length; i++)
            {
                PackedSlotDataV2 packedSlot = umaPackRecipe.slotsV2[i];
                if (UMAPackRecipe.SlotIsValid(packedSlot))
                {
                    var tempSlotData = context.InstantiateSlot(packedSlot.id);
                    tempSlotData.overlayScale = packedSlot.scale * 0.01f;
                    umaRecipe.slotDataList[i] = tempSlotData;

                    if (packedSlot.copyIdx == -1)
                    {
                        for (int i2 = 0; i2 < packedSlot.overlays.Length; i2++)
                        {
                            PackedOverlayDataV2 packedOverlay = packedSlot.overlays[i2];
                            OverlayData         overlayData   = context.InstantiateOverlay(packedOverlay.id);
                            overlayData.rect = new Rect(packedOverlay.rect[0],
                                                        packedOverlay.rect[1],
                                                        packedOverlay.rect[2],
                                                        packedOverlay.rect[3]);
                            if (packedOverlay.colorIdx < umaPackRecipe.sharedColorCount)
                            {
                                overlayData.colorData = umaRecipe.sharedColors[packedOverlay.colorIdx];
                            }
                            else
                            {
                                overlayData.colorData      = colorData[packedOverlay.colorIdx].Duplicate();
                                overlayData.colorData.name = OverlayColorData.UNSHARED;
                            }
                            if (UMAPackRecipe.MaterialIsValid(overlayData.asset.material))
                            {
                                overlayData.EnsureChannels(overlayData.asset.material.channels.Length);
                            }
                            tempSlotData.AddOverlay(overlayData);
                        }
                    }
                    else
                    {
                        tempSlotData.SetOverlayList(umaRecipe.slotDataList[packedSlot.copyIdx].GetOverlayList());
                    }
                }
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Serialize the packed recipe.
 /// </summary>
 /// <param name="packedRecipe">Packed recipe.</param>
 /// <param name="context">Context.</param>
 public abstract void PackedSave(UMAPackRecipe packedRecipe, UMAContext context);
Ejemplo n.º 17
0
        public static bool UnpackRecipeVersion1(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
        {
            if (!UMAPackRecipe.ArrayHasData(umaPackRecipe.packedSlotDataList))
            {
                return(false);
            }

            umaRecipe.slotDataList = new SlotData[umaPackRecipe.packedSlotDataList.Length];

            umaRecipe.SetRace(context.GetRace(umaPackRecipe.race));

            umaRecipe.ClearDna();
            for (int dna = 0; dna < umaPackRecipe.packedDna.Count; dna++)
            {
                Type dnaType = UMADna.GetType(umaPackRecipe.packedDna[dna].dnaType);
                umaRecipe.AddDna(UMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna));
            }

            for (int i = 0; i < umaPackRecipe.packedSlotDataList.Length; i++)
            {
                if (UMAPackRecipe.SlotIsValid(umaPackRecipe.packedSlotDataList[i]))
                {
                    var tempSlotData = context.InstantiateSlot(umaPackRecipe.packedSlotDataList[i].slotID);
                    tempSlotData.overlayScale = umaPackRecipe.packedSlotDataList[i].overlayScale * 0.01f;
                    umaRecipe.slotDataList[i] = tempSlotData;

                    if (umaPackRecipe.packedSlotDataList[i].copyOverlayIndex == -1)
                    {
                        for (int overlay = 0; overlay < umaPackRecipe.packedSlotDataList[i].OverlayDataList.Length; overlay++)
                        {
                            Color tempColor;
                            Rect  tempRect;

                            if (UMAPackRecipe.ArrayHasData(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList))
                            {
                                tempColor = new Color(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[0] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[1] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[2] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[3] / 255.0f);
                            }
                            else
                            {
                                tempColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                            }

                            if (UMAPackRecipe.ArrayHasData(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList))
                            {
                                Rect originalRect = context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID).rect;
                                tempRect = new Rect(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[0], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[1], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[2], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[3]);

                                Vector2 aspectRatio = new Vector2(tempRect.width / originalRect.width, tempRect.height / originalRect.height);

                                tempRect = new Rect(tempRect.x / aspectRatio.x, tempRect.y / aspectRatio.y, tempRect.width / aspectRatio.x, tempRect.height / aspectRatio.y);
                            }
                            else
                            {
                                tempRect = new Rect(0, 0, 0, 0);
                            }

                            tempSlotData.AddOverlay(context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID));
                            tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).colorData.color = tempColor;
                            tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).rect            = tempRect;

                            if (UMAPackRecipe.ArrayHasData(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList))
                            {
                                for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList.Length; channelAdjust++)
                                {
                                    packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                    tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetColor(channelAdjust, new Color32((byte)tempData.channelMaskList[channelAdjust][0],
                                                                                                                               (byte)tempData.channelMaskList[channelAdjust][1],
                                                                                                                               (byte)tempData.channelMaskList[channelAdjust][2],
                                                                                                                               (byte)tempData.channelMaskList[channelAdjust][3]));
                                }
                            }

                            if (UMAPackRecipe.ArrayHasData(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList))
                            {
                                for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList.Length; channelAdjust++)
                                {
                                    packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                    tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetAdditive(channelAdjust, new Color32((byte)tempData.channelAdditiveMaskList[channelAdjust][0],
                                                                                                                                  (byte)tempData.channelAdditiveMaskList[channelAdjust][1],
                                                                                                                                  (byte)tempData.channelAdditiveMaskList[channelAdjust][2],
                                                                                                                                  (byte)tempData.channelAdditiveMaskList[channelAdjust][3]));
                                }
                            }
                        }
                    }
                    else
                    {
                        tempSlotData.SetOverlayList(umaRecipe.slotDataList[umaPackRecipe.packedSlotDataList[i].copyOverlayIndex].GetOverlayList());
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Load serialized data into the packed recipe.
 /// </summary>
 /// <returns>The UMAPackRecipe.</returns>
 /// <param name="context">Context.</param>
 public abstract UMAPackRecipe PackedLoad(UMAContext context);
Ejemplo n.º 19
0
 /// <summary>
 /// Internal call to static PackedLoadDCS which uses the assets string and object and returns a DCSUniversalPackRecipe data model that can be used by any UMA
 /// </summary>
 /// <param name="context"></param>
 /// <param name="recipeToUnpack"></param>
 /// <returns></returns>
 protected DCSUniversalPackRecipe PackedLoadDCSInternal(UMAContext context /*, string recipeToUnpack*/)
 {
     return(PackedLoadDCS(context, recipeString, this));
 }
Ejemplo n.º 20
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);
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Load data into the specified UMA recipe.
        /// </summary>
        /// <param name="umaRecipe">UMA recipe.</param>
        /// <param name="context">Context.</param>
        public override void Load(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
        {
            var packedRecipe = PackedLoad(context);

            UnpackRecipe(umaRecipe, packedRecipe, context);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Serialize recipeString data into packed recipe.
 /// </summary>
 /// <param name="packedRecipe">Packed recipe.</param>
 /// <param name="context">Context.</param>
 public override void PackedSave(UMAPackedRecipeBase.UMAPackRecipe packedRecipe, UMAContext context)
 {
     recipeString = JsonUtility.ToJson(packedRecipe);
 }
Ejemplo n.º 23
0
        public static void UnpackRecipeVersion3(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
        {
            umaRecipe.slotDataList = new SlotData[umaPackRecipe.slotsV3.Length];
            umaRecipe.SetRace(context.GetRace(umaPackRecipe.race));

            umaRecipe.ClearDna();
            List <UMADnaBase> packedDna = UnPackDNA(umaPackRecipe.packedDna);

            foreach (UMADnaBase umd in packedDna)
            {
                umaRecipe.AddDna(umd);
            }

            OverlayColorData[] colorData;
            if (UMAPackRecipe.ArrayHasData(umaPackRecipe.fColors))
            {
                colorData = new OverlayColorData[umaPackRecipe.fColors.Length];
                for (int i = 0; i < colorData.Length; i++)
                {
                    colorData[i] = new OverlayColorData();
                    umaPackRecipe.fColors[i].SetOverlayColorData(colorData[i]);
                }
            }
            else if (UMAPackRecipe.ArrayHasData(umaPackRecipe.colors))
            {
                colorData = new OverlayColorData[umaPackRecipe.colors.Length];
                for (int i = 0; i < colorData.Length; i++)
                {
                    colorData[i] = new OverlayColorData();
                    umaPackRecipe.colors[i].SetOverlayColorData(colorData[i]);
                }
            }
            else
            {
                colorData = new OverlayColorData[0];
            }

            umaRecipe.sharedColors = new OverlayColorData[umaPackRecipe.sharedColorCount];
            for (int i = 0; i < umaRecipe.sharedColors.Length; i++)
            {
                umaRecipe.sharedColors[i] = colorData[i];
            }

            for (int i = 0; i < umaPackRecipe.slotsV3.Length; i++)
            {
                PackedSlotDataV3 packedSlot = umaPackRecipe.slotsV3[i];
                if (UMAPackRecipe.SlotIsValid(packedSlot))
                {
                    var tempSlotData = context.InstantiateSlot(packedSlot.id);
                    tempSlotData.overlayScale = packedSlot.scale * 0.01f;
                    umaRecipe.slotDataList[i] = tempSlotData;

                    if (packedSlot.copyIdx == -1)
                    {
                        for (int i2 = 0; i2 < packedSlot.overlays.Length; i2++)
                        {
                            PackedOverlayDataV3 packedOverlay = packedSlot.overlays[i2];
                            OverlayData         overlayData   = context.InstantiateOverlay(packedOverlay.id);
                            overlayData.rect = new Rect(
                                packedOverlay.rect[0],
                                packedOverlay.rect[1],
                                packedOverlay.rect[2],
                                packedOverlay.rect[3]);

                            if (packedOverlay.colorIdx < umaPackRecipe.sharedColorCount)
                            {
                                overlayData.colorData = umaRecipe.sharedColors[packedOverlay.colorIdx];
                            }
                            else
                            {
                                overlayData.colorData      = colorData[packedOverlay.colorIdx].Duplicate();
                                overlayData.colorData.name = OverlayColorData.UNSHARED;
                            }

                            if (UMAPackRecipe.MaterialIsValid(overlayData.asset.material))
                            {
                                overlayData.EnsureChannels(overlayData.asset.material.channels.Length);
                            }

                                                        #if (UNITY_STANDALONE || UNITY_IOS || UNITY_ANDROID || UNITY_PS4 || UNITY_XBOXONE) && !UNITY_2017_3_OR_NEWER //supported platforms for procedural materials
                            if (packedOverlay.data == null)
                            {
                                overlayData.proceduralData = new OverlayData.OverlayProceduralData[0];
                            }
                            else
                            {
                                overlayData.proceduralData = new OverlayData.OverlayProceduralData[packedOverlay.data.Length];

                                for (int dataIdx = 0; dataIdx < packedOverlay.data.Length; dataIdx++)
                                {
                                    OverlayData.OverlayProceduralData proceduralData = new OverlayData.OverlayProceduralData();
                                    packedOverlay.data[dataIdx].SetOverlayProceduralData(proceduralData);
                                    overlayData.proceduralData[dataIdx] = proceduralData;
                                }
                            }
                            #endif

                            tempSlotData.AddOverlay(overlayData);
                        }
                    }
                    else
                    {
                        tempSlotData.SetOverlayList(umaRecipe.slotDataList[packedSlot.copyIdx].GetOverlayList());
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public static void UnpackRecipe(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
        {
            switch (umaPackRecipe.version)
            {
            case 3:
                UnpackRecipeVersion3(umaRecipe, umaPackRecipe, context);
                break;

            case 2:
                UnpackRecipeVersion2(umaRecipe, umaPackRecipe, context);
                break;

            case 1:
            default:
                if (UnpackRecipeVersion1(umaRecipe, umaPackRecipe, context))
                {
                    umaRecipe.MergeMatchingOverlays();
                }
                break;
            }
        }
Ejemplo n.º 25
0
        public static GameObject CreateEditorContext()
        {
            GameObject EditorUMAContext = null;

            if (UnityEditor.BuildPipeline.isBuildingPlayer)
            {
                return(null);
            }
            if (Application.isPlaying)
            {
                Debug.LogWarning("There was no UMAContext in this scene. Please add the UMA_DCS prefab to this scene before you try to generate an UMA.");
                return(null);
            }
            Debug.Log("UMA Recipe Editor created an UMAEditorContext to enable editing. This will auto delete once you have finished editing your recipe or you add the UMA_DCS prefab to this scene.");
            //if there is already an EditorUMAContext use it
            if (UMAContext.FindInstance() != null)
            {
                if (UMAContext.FindInstance().gameObject.name == "UMAEditorContext")
                {
                    EditorUMAContext = UMAContext.FindInstance().gameObject;
                    //if the UMAContext itself is on this game object, it means this was created and not deleted by the previous version of 'CreateEditorContext'
                    //(The new version creates the UMAContext on a child game object called 'UMAContext' so that UMAContext.FindInstance can find it properly)
                    //so in this case delete all the components that would have been added from the found gameObject from the previous code
                    if (EditorUMAContext.GetComponent <UMAContext>())
                    {
                        Destroy(EditorUMAContext.GetComponent <UMAContext>());                       //should also make the instance null again
                        if (EditorUMAContext.GetComponent <DynamicRaceLibrary>())
                        {
                            Destroy(EditorUMAContext.GetComponent <DynamicRaceLibrary>());
                        }
                        if (EditorUMAContext.GetComponent <DynamicSlotLibrary>())
                        {
                            Destroy(EditorUMAContext.GetComponent <DynamicSlotLibrary>());
                        }
                        if (EditorUMAContext.GetComponent <DynamicOverlayLibrary>())
                        {
                            Destroy(EditorUMAContext.GetComponent <DynamicOverlayLibrary>());
                        }
                        if (EditorUMAContext.GetComponent <DynamicCharacterSystem>())
                        {
                            Destroy(EditorUMAContext.GetComponent <DynamicCharacterSystem>());
                        }
                        if (EditorUMAContext.GetComponent <DynamicAssetLoader>())
                        {
                            Destroy(EditorUMAContext.GetComponent <DynamicAssetLoader>());
                        }
                    }
                }
                else if (UMAContext.FindInstance().gameObject.transform.parent.gameObject.name == "UMAEditorContext")
                {
                    EditorUMAContext = UMAContext.FindInstance().gameObject.transform.parent.gameObject;
                }
            }
            else if (GameObject.Find("UMAEditorContext"))
            {
                EditorUMAContext = GameObject.Find("UMAEditorContext");
            }
            else
            {
                EditorUMAContext      = new GameObject();
                EditorUMAContext.name = "UMAEditorContext";
            }
            //Make this GameObject not show up in the scene or save
            EditorUMAContext.hideFlags = HideFlags.DontSave | HideFlags.NotEditable;
            //if this gameobject does not contain an UMAContext add it - we have to call it UMAContext because UMAContext.FindInstance searches for that game object
            var thisUMAContext = UMAContext.Instance = EditorUMAContext.GetComponentInChildren <UMAContext>();

            if (UMAContext.Instance == null)
            {
                var thisUMAContextGO = new GameObject();
                thisUMAContextGO.name             = "UMAContext";
                thisUMAContextGO.transform.parent = EditorUMAContext.transform;
                thisUMAContext      = thisUMAContextGO.AddComponent <UMAContext>();
                UMAContext.Instance = thisUMAContext;
            }
            //we need to add the libraries as components of the game object too
            //and then set THOSE components to the umaContext component
            thisUMAContext.raceLibrary = thisUMAContext.gameObject.AddComponent <DynamicRaceLibrary>();
            (thisUMAContext.raceLibrary as DynamicRaceLibrary).dynamicallyAddFromResources    = true;
            (thisUMAContext.raceLibrary as DynamicRaceLibrary).dynamicallyAddFromAssetBundles = true;
            thisUMAContext.overlayLibrary = thisUMAContext.gameObject.AddComponent <DynamicOverlayLibrary>();
            (thisUMAContext.overlayLibrary as DynamicOverlayLibrary).dynamicallyAddFromResources    = true;
            (thisUMAContext.overlayLibrary as DynamicOverlayLibrary).dynamicallyAddFromAssetBundles = true;
            thisUMAContext.slotLibrary = thisUMAContext.gameObject.AddComponent <DynamicSlotLibrary>();
            (thisUMAContext.slotLibrary as DynamicSlotLibrary).dynamicallyAddFromResources    = true;
            (thisUMAContext.slotLibrary as DynamicSlotLibrary).dynamicallyAddFromAssetBundles = true;
            thisUMAContext.dynamicCharacterSystem = thisUMAContext.gameObject.AddComponent <DynamicCharacterSystem>();
            (thisUMAContext.dynamicCharacterSystem as DynamicCharacterSystem).dynamicallyAddFromResources    = true;
            (thisUMAContext.dynamicCharacterSystem as DynamicCharacterSystem).dynamicallyAddFromAssetBundles = true;
            var thisDAL = thisUMAContext.gameObject.AddComponent <DynamicAssetLoader>();

            DynamicAssetLoader.Instance = thisDAL;
            return(EditorUMAContext);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Save data from the specified umaRecipe.
 /// </summary>
 /// <param name="umaRecipe">UMA recipe.</param>
 /// <param name="context">Context.</param>
 public abstract void Save(UMAData.UMARecipe umaRecipe, UMAContext context);