Beispiel #1
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 = PackRecipeV2(umaRecipe);

        PackedSave(packedRecipe, context);
    }
Beispiel #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*/);
            UnpackRecipeVersion2(umaRecipe, packedRecipe, context);
        }
        else         //we can use standard UMALoading
        {
            base.Load(umaRecipe, context);
        }
    }
Beispiel #3
0
        public void OnEnable()
        {
            if (!NeedsReenable())
            {
                return;
            }

            _errorMessage  = null;
            _recipe        = new UMAData.UMARecipe();
            showBaseEditor = false;

            try
            {
                var umaRecipeBase = target as UMARecipeBase;
                if (umaRecipeBase != null)
                {
                    umaRecipeBase.Load(_recipe, UMAContext.FindInstance());
                    _description = umaRecipeBase.GetInfo();
                }
            }
            catch (UMAResourceNotFoundException e)
            {
                _errorMessage = e.Message;
            }

            dnaEditor  = new DNAMasterEditor(_recipe);
            slotEditor = new SlotMasterEditor(_recipe);

            _rebuildOnLayout = true;
        }
    public static ICloths CreatCloth
        (ECharacterResType type, UMAContext _umaContext, CharacterData _characterData, ICharacterSlotOverly _characterSlotOverlay, ICharacterPlayer _character, ICharacterBase _characterBase, ClothModel _cm)
    {
        ICloths ich = null;

        switch (_cm.wearpos)
        {
        case WearPosConst.WAER_POS_CLOTH:
            ich = new Coat(type, _umaContext, _characterData, _characterSlotOverlay, _character, _characterBase, _cm);
            break;

        case WearPosConst.WEAR_POS_PANT:
            ich = new Pant(type, _umaContext, _characterData, _characterSlotOverlay, _character, _characterBase, _cm);
            break;

        case WearPosConst.WEAR_POS_SUIT:
            ich = new Suit(type, _umaContext, _characterData, _characterSlotOverlay, _character, _characterBase, _cm);
            break;

        case WearPosConst.WAER_POS_HAIR:
            ich = new Hair(type, _umaContext, _characterData, _characterSlotOverlay, _character, _characterBase, _cm);
            break;

        case WearPosConst.WEAR_POS_SHOE:
            ich = new Shoe(type, _umaContext, _characterData, _characterSlotOverlay, _character, _characterBase, _cm);
            break;
        }
        return(ich);
    }
Beispiel #5
0
	public void OnEnable()
    {
        thisDCA = target as DynamicCharacterAvatar;
		var context = UMAContext.FindInstance();
		if(context == null)
		{
			context = thisDCA.CreateEditorContext();
		}
		//Set this DynamicCharacterAvatar for RaceSetter so if the user chages the race dropdown the race changes
		if (_racePropDrawer.thisDCA == null)
        {
            _racePropDrawer.thisDCA = thisDCA;
			//Set the raceLibrary for the race setter
			if (context)
			{
				var dynamicRaceLibrary = (DynamicRaceLibrary)context.raceLibrary as DynamicRaceLibrary;
				_racePropDrawer.thisDynamicRaceLibrary = dynamicRaceLibrary;
			}
        }
		if (_wardrobePropDrawer.thisDCS == null)
		{
			_wardrobePropDrawer.thisDCA = thisDCA;
            if (context)
			{
				var dynamicCharacterSystem = (DynamicCharacterSystem)context.dynamicCharacterSystem as DynamicCharacterSystem;
				_wardrobePropDrawer.thisDCS = dynamicCharacterSystem;
			}
		}
		if (_animatorPropDrawer.thisDCA == null)
		{
			_animatorPropDrawer.thisDCA = thisDCA;
		}
	}
Beispiel #6
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 = PackRecipeV2(umaRecipe);
         //DCSPackRecipe doesn't do any more work, it just gets the values from PackRecipeV2 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       = PackRecipeV2(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);
     }
 }
Beispiel #7
0
        //private List<CheckedMaterial> Materials = new List<CheckedMaterial>();

        void Refresh()
        {
            Context = UMAContext.FindInstance();
            if (Context == null)
            {
                EditorUtility.DisplayDialog("Error", "There is no UMA Context in the current scene!", "OK");
                return;
            }

            Slots.Clear();

            if (Race == null)
            {
                EditorUtility.DisplayDialog("Error", "No RaceData selected!", "OK");
                return;
            }

            Recipe = new UMAData.UMARecipe();
            Race.baseRaceRecipe.Load(Recipe, Context);

            if (Recipe == null)
            {
                return;
            }

            foreach (SlotData s in Recipe.slotDataList)
            {
                if (s == null)
                {
                    continue;
                }
                Slots.Add(new CheckedSlot(s, true));
            }
        }
Beispiel #8
0
        private void InitializeUMAData()
        {
            if (umaObject == null)
            {
                return;
            }

            if (baseRecipe == null)
            {
                return;
            }

            //Adds the umaData component
            if (_umaData == null)
            {
                _umaData = umaObject.AddComponent <UMAData>();
            }

            if (_umaData == null)
            {
                return;
            }

            //Create a new recipe objects
            if (_umaData.umaRecipe == null)
            {
                _umaData.umaRecipe = new UMAData.UMARecipe();
            }

            baseRecipe.Load(_umaData.umaRecipe, UMAContext.FindInstance());
            Debug.Log("UMAData initialization successful!");
        }
Beispiel #9
0
        public void Initialize(
            UMAContext context, UMAGeneratorBase generator, UMAData data,
            [InjectOptional] UMARecipeBase recipe,
            [InjectOptional] UMARecipeBase [] additionalRecipe,
            ThirdPersonCharacter controller)
        {
            base.context              = context;
            base.umaGenerator         = generator;
            base.umaData              = data;
            base.umaRecipe            = recipe;
            base.umaAdditionalRecipes = additionalRecipe;
            this.controller           = controller;

            this.gameObject.transform.SetParent(controller.gameObject.transform);
            this.gameObject.transform.localPosition = Vector3.zero;
            this.gameObject.transform.localRotation = Quaternion.identity;

            base.Initialize();

            if (umaAdditionalRecipes == null || umaAdditionalRecipes.Length == 0)
            {
                Load(umaRecipe);
            }
            else
            {
                Load(umaRecipe, umaAdditionalRecipes);
            }
        }
 public void OnEnable()
 {
     thisDCA = target as DynamicCharacterAvatar;
     if (thisDCA.context == null)
     {
         thisDCA.context = UMAContext.FindInstance();
         if (thisDCA.context == null)
         {
             thisDCA.context = thisDCA.CreateEditorContext();
         }
     }
     else if (thisDCA.context.gameObject.name == "UMAEditorContext")
     {
         //this will set also the existing Editorcontext if there is one
         thisDCA.CreateEditorContext();
     }
     else if (thisDCA.context.gameObject.transform.parent != null)
     {
         //this will set also the existing Editorcontext if there is one
         if (thisDCA.context.gameObject.transform.parent.gameObject.name == "UMAEditorContext")
         {
             thisDCA.CreateEditorContext();
         }
     }
     _racePropDrawer.thisDCA = thisDCA;
     _racePropDrawer.thisDynamicRaceLibrary = (DynamicRaceLibrary)thisDCA.context.raceLibrary as DynamicRaceLibrary;
     _wardrobePropDrawer.thisDCA            = thisDCA;
     _wardrobePropDrawer.thisDCS            = (DynamicCharacterSystem)thisDCA.context.dynamicCharacterSystem as DynamicCharacterSystem;
     _animatorPropDrawer.thisDCA            = thisDCA;
 }
Beispiel #11
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)
				{
					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 (CharacterDestroyed != null) umaData.CharacterDestroyed = CharacterDestroyed;
		if (CharacterUpdated != null) umaData.CharacterUpdated = CharacterUpdated;
	}
Beispiel #12
0
    /// <summary>
    /// Gets a DCSUnversalPackRecipeModel that has the wardrobeSet set to be the set in this collection for the given race of the sent avatar
    /// </summary>
    public DCSUniversalPackRecipe GetUniversalPackRecipe(DynamicCharacterAvatar dca, UMAContext context)
    {
        var thisPackRecipe = PackedLoadDCSInternal(context);

        thisPackRecipe.wardrobeSet = wardrobeCollection[dca.activeRace.name];
        thisPackRecipe.race        = dca.activeRace.name;
        return(thisPackRecipe);
    }
Beispiel #13
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)
 {
     if ((recipeString == null) || (recipeString.Length == 0))
     {
         return(new UMAPackRecipe());
     }
     return(JsonMapper.ToObject <UMAPackRecipe>(recipeString));
 }
Beispiel #14
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)
 {
     if ((recipeString == null) || (recipeString.Length == 0))
     {
         return(new UMAPackRecipe());
     }
     return(JsonUtility.FromJson <UMAPackRecipe>(recipeString));
 }
        #pragma warning disable 618
        private void AddRaces(RaceData[] races)
        {
            int currentNumRaces = raceElementList.Length;

            foreach (RaceData race in races)
            {
        #if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    bool alreadyExisted = false;

                    foreach (RaceData addedRace in raceElementList)
                    {
                        if (addedRace == race)
                        {
                            alreadyExisted = true;
                            break;
                        }
                    }
                    if (alreadyExisted)
                    {
                        continue;
                    }
                    if (!editorAddedAssets.Contains(race))
                    {
                        editorAddedAssets.Add(race);
                        if (UMAContext.Instance == null)
                        {
                            UMAContext.FindInstance();
                        }
                        if (UMAContext.Instance != null)
                        {
                            if (UMAContext.Instance.dynamicCharacterSystem != null)
                            {
                                (UMAContext.Instance.dynamicCharacterSystem as DynamicCharacterSystem).Refresh(false);
                            }
                        }
                    }
                }
                else
        #endif
                AddRace(race);
            }
            //Ensure the new races have keys in the DCS dictionary
            if (currentNumRaces != raceElementList.Length && Application.isPlaying)
            {
                if (UMAContext.Instance == null)
                {
                    UMAContext.FindInstance();
                }
                if (UMAContext.Instance != null && UMAContext.Instance.dynamicCharacterSystem != null)
                {
                    (UMAContext.Instance.dynamicCharacterSystem as DynamicCharacterSystem).RefreshRaceKeys();
                }
            }
            //This doesn't actually seem to do anything apart from slow things down
            //StartCoroutine(CleanRacesFromResourcesAndBundles());
        }
    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;
    }
Beispiel #17
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);
 }
        static void SaveRecipe(UMAData umaData, UMAContext context)
        {
            string assetPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(CommonNames.umaCharacterAssetPath, umaData.umaRecipe.raceData.raceName + ".asset"));
            var    asset     = ScriptableObject.CreateInstance <UMATextRecipe>();

            asset.Save(umaData.umaRecipe, context);
            AssetDatabase.CreateAsset(asset, assetPath);
            AssetDatabase.SaveAssets();
        }
Beispiel #19
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;
	}
Beispiel #20
0
#pragma warning restore 618

	public static UMAContext FindInstance()
	{
		if (Instance == null)
		{
			var contextGO = GameObject.Find("UMAContext");
			if (contextGO != null)
				Instance = contextGO.GetComponent<UMAContext>();
		}
		return Instance;	
	}
Beispiel #21
0
 public CharacterCloth
     (ECharacterResType type, CharacterData _characterData, ICharacterSlotOverly _characterSlotOverlay, ICharacterPlayer _character, ICharacterBase _characterBase)
 {
     resType              = type;
     umaContext           = UMAContext.FindInstance();
     characterData        = _characterData;
     characterSlotOverlay = _characterSlotOverlay;
     character            = _character;
     characterBase        = _characterBase;
 }
Beispiel #22
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);
    }
Beispiel #23
0
    /// <summary>
    /// Fills in a UMA recipe with random partial fragments from the sections.
    /// </summary>
    /// <param name="umaRecipe">UMA recipe.</param>
    /// <param name="context">Context.</param>
    public void FillUMARecipe(UMAData.UMARecipe umaRecipe, UMAContext context)
    {
        if (raceData == null)
        {
            Debug.LogWarning("Race Data must be set!");
            return;
        }
        umaRecipe.SetRace(raceData);

        int sectionCount = (recipeSections == null) ? 0 : recipeSections.Length;

        for (int i = 0; i < sectionCount; i++)
        {
            RecipeSection section = recipeSections[i];
            if ((section.recipes == null) || (section.recipes.Length == 0))
            {
                continue;
            }

            switch (section.selectionRule)
            {
            case SelectionType.IncludeNone:
                break;

            case SelectionType.IncludeAll:
                for (int j = 0; j < section.recipes.Length; j++)
                {
                    IncludeRecipe(section.recipes[j], umaRecipe, context, false);
                }
                break;

            case SelectionType.IncludeSome:
                float chance = 1f / (float)(section.recipes.Length + 1);
                for (int j = 0; j < section.recipes.Length; j++)
                {
                    if (Random.value < chance)
                    {
                        IncludeRecipe(section.recipes[j], umaRecipe, context, false);
                    }
                }
                break;

            case SelectionType.IncludeOne:
            default:
                int index = Random.Range(0, section.recipes.Length);
                IncludeRecipe(section.recipes[index], umaRecipe, context, false);
                break;
            }
        }

        for (int i = 0; i < additionalRecipes.Length; i++)
        {
            IncludeRecipe(additionalRecipes[i], umaRecipe, context, true);
        }
    }
 //Override Load from PackedRecipeBase
 /// <summary>
 /// NOTE: Use GetUniversalPackRecipe to get a recipe that includes a wardrobeSet. Load this Recipe's recipeString into the specified UMAData.UMARecipe.
 /// </summary>
 public override void Load(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
 {
     if ((recipeString != null) && (recipeString.Length > 0))
     {
         var packedRecipe = PackedLoadDCSInternal(context);
         if (packedRecipe != null)
         {
             UnpackRecipe(umaRecipe, packedRecipe, context);
         }
     }
 }
Beispiel #25
0
        public void OnEnable()
        {
            base.OnEnable();

            if (!NeedsReenable())
            {
                return;
            }

            _errorMessage  = null;
            _recipe        = new UMAData.UMARecipe();
            showBaseEditor = false;

            try
            {
                var umaRecipeBase = target as UMARecipeBase;
                if (umaRecipeBase != null)
                {
                    var context = UMAContext.FindInstance();
                    //create a virtual UMAContext if we dont have one and we have DCS
                    if (context == null || context.gameObject.name == "UMAEditorContext")
                    {
                        context          = umaRecipeBase.CreateEditorContext();               //will create or update an UMAEditorContext to the latest version
                        generatedContext = context.gameObject.transform.parent.gameObject;    //The UMAContext in a UMAEditorContext is that gameobject's child
                    }
                    //legacy checks for context
                    if (context == null)
                    {
                        _errorMessage = "Editing a recipe requires a loaded scene with a valid UMAContext.";
                        Debug.LogWarning(_errorMessage);
                        //_recipe = null;
                        //return;
                    }
                    else if (context.raceLibrary == null)
                    {
                        _errorMessage = "Editing a recipe requires a loaded scene with a valid UMAContext with RaceLibrary assigned.";
                        Debug.LogWarning(_errorMessage);
                        //_recipe = null;
                        //return;
                    }
                    umaRecipeBase.Load(_recipe, context);
                    _description = umaRecipeBase.GetInfo();
                }
            }
            catch (UMAResourceNotFoundException e)
            {
                _errorMessage = e.Message;
            }

            dnaEditor  = new DNAMasterEditor(_recipe);
            slotEditor = new SlotMasterEditor(_recipe);

            _rebuildOnLayout = true;
        }
Beispiel #26
0
 public Cloth
     (ECharacterResType type, UMAContext _umaContext, CharacterData _characterData, ICharacterSlotOverly _characterSlotOverlay, ICharacterPlayer _character, ICharacterBase _characterBase, ClothModel _cm)
 {
     resType              = type;
     umaContext           = _umaContext;
     characterSlotOverlay = _characterSlotOverlay;
     character            = _character;
     characterData        = _characterData;
     characterBase        = _characterBase;
     cm          = _cm;
     PutOnDelete = new List <string>();
 }
        void OnEnable()
        {
            RendererElements = serializedObject.FindProperty("RendererElements");
            showHelp         = serializedObject.FindProperty("showHelp");
            context          = UMAContext.FindInstance();

            DCARendererManager manager = target as DCARendererManager;

            avatar = manager.GetComponent <DynamicCharacterAvatar>();

            UpdateOptions();
        }
Beispiel #28
0
            /// <summary>
            /// Adds the shared colors from a given recipe name into the target recipe
            /// </summary>
            /// <param name="sourceRecipeName"></param>
            protected virtual bool AddSharedColorsFromRecipe(string sourceRecipeName, UMAData.UMARecipe targetRecipe)
            {
                bool changed           = false;
                var  thisUmaDataRecipe = new UMAData.UMARecipe();
                var  context           = UMAContext.FindInstance();

                if (context == null)
                {
                    return(false);
                }
                var thisWardrobeRecipe = context.dynamicCharacterSystem.GetBaseRecipe(sourceRecipeName);

                if (thisWardrobeRecipe == null)
                {
                    return(false);
                }
                try
                {
                    thisWardrobeRecipe.Load(thisUmaDataRecipe, context);
                }
                catch
                {
                    return(false);
                }
                if (thisUmaDataRecipe.sharedColors.Length > 0)
                {
                    List <OverlayColorData> newSharedColors = new List <OverlayColorData>();
                    newSharedColors.AddRange(targetRecipe.sharedColors);
                    for (int i = 0; i < thisUmaDataRecipe.sharedColors.Length; i++)
                    {
                        bool existed = false;
                        for (int ii = 0; ii < newSharedColors.Count; ii++)
                        {
                            if (newSharedColors[ii].name == thisUmaDataRecipe.sharedColors[i].name)
                            {
                                existed = true;
                                break;
                            }
                        }
                        if (!existed)
                        {
                            newSharedColors.Add(thisUmaDataRecipe.sharedColors[i]);
                            changed = true;
                        }
                    }
                    if (changed)
                    {
                        targetRecipe.sharedColors = newSharedColors.ToArray();
                    }
                }
                return(changed);
            }
		public override void OnInspectorGUI()
		{
			var context = UMAContext.FindInstance();
			EditorGUI.BeginDisabledGroup(context == null);
			if (GUILayout.Button("Add to Scene Context"))
			{
				var collection = target as UMAAssetCollection;
				collection.AddToContext(context);
			}
			EditorGUI.EndDisabledGroup();

			base.OnInspectorGUI();
		}
        public List <WardrobeSettings> GetRacesWardrobeSet(string race)
        {
            var thisContext = UMAContext.FindInstance();

            if (thisContext == null)
            {
                Debug.LogWarning("Getting the WardrobeSet from a WardrobeCollection requires a valid UMAContext in the scene");
                return(new List <WardrobeSettings>());
            }
            var thisRace = (thisContext.raceLibrary as DynamicRaceLibrary).GetRace(race, true);

            return(GetRacesWardrobeSet(thisRace));
        }
Beispiel #31
0
 public CharacterBase
     (ECharacterResType type,
     ICharacterSlotOverly _characterSlotOverlay,
     UMAData _umaData,
     UMADynamicAvatar _umaDynamicAvatar,
     CharacterData _characterData)
 {
     resType              = type;
     umaContext           = UMAContext.FindInstance();
     characterSlotOverlay = _characterSlotOverlay;
     umaData              = _umaData;
     umaDynamicAvatar     = _umaDynamicAvatar;
     characterData        = _characterData;
 }
Beispiel #32
0
    void Initialize()
    {
        UMAInstance();

        gameObject = new GameObject(objectName);
        UpdateVec();

        umaContext = UMAContext.FindInstance();
        UMAGenerator generator = umaContext.umaGenerator;

        umaDynamicAvatar = gameObject.AddComponent <UMADynamicAvatar>();
        umaDynamicAvatar.Initialize();

        UMAData umaData = umaDynamicAvatar.umaData;

        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        UMATextRecipe recipe = UMATextRecipe.CreateInstance <UMATextRecipe>();

        recipe.Load(umaData.umaRecipe, umaContext);
        umaDynamicAvatar.umaRecipe = recipe;
        umaData.AddAdditionalRecipes(new UMARecipeBase[] { umaContext.umaTextRecipe }, umaContext);
        umaData.OnCharacterCreated   += CharacterCreated;
        umaData.OnCharacterUpdated   += CharacterUpdated;
        umaData.OnCharacterDestroyed += CharacterDestroyed;

        if (isExpress)
        {
            expressionPlayer = gameObject.AddComponent <UMAExpressionPlayer>();
            expressionPlayer.overrideMecanimEyes = true;
            expressionPlayer.overrideMecanimHead = true;
            expressionPlayer.overrideMecanimJaw  = true;
            expressionPlayer.overrideMecanimNeck = true;
        }

        umaData.umaRecipe.slotDataList = new SlotData[100];
        UMADnaHumanoid umaDna         = new UMADnaHumanoid();
        UMADnaTutorial umaTutorialDNA = new UMADnaTutorial();

        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        ICharacterSlotOverly characterSlotOverlay = new CharacterSlotOverly(umaDynamicAvatar);

        characterAnim = new CharacterAnim(umaDynamicAvatar);
        //characterDna = new CharacterDna(umaDna, umaData, characterAnim, characterData);
        characterBase  = new CharacterBase(resType, characterSlotOverlay, umaData, umaDynamicAvatar, characterData);
        characterCloth = new CharacterCloth(resType, characterData, characterSlotOverlay, this, characterBase);
    }
Beispiel #33
0
	/// <summary>
	/// Fills in a UMA recipe with random partial fragments from the sections.
	/// </summary>
	/// <param name="umaRecipe">UMA recipe.</param>
	/// <param name="context">Context.</param>
	public void FillUMARecipe(UMAData.UMARecipe umaRecipe, UMAContext context)
	{
		if (raceData == null)
		{
			Debug.LogWarning("Race Data must be set!");
			return;
		}
		umaRecipe.SetRace(raceData);

		int sectionCount = (recipeSections == null) ? 0 : recipeSections.Length;
		for (int i = 0; i < sectionCount; i++)
		{
			RecipeSection section = recipeSections[i];
			if ((section.recipes == null) || (section.recipes.Length == 0))
				continue;

			switch (section.selectionRule)
			{
				case SelectionType.IncludeNone:
					break;
				case SelectionType.IncludeAll:
					for (int j = 0; j < section.recipes.Length; j++)
					{
						IncludeRecipe(section.recipes[j], umaRecipe, context, false);
					}
					break;
				case SelectionType.IncludeSome:
					float chance = 1f / (float)(section.recipes.Length + 1);
					for (int j = 0; j < section.recipes.Length; j++)
					{
						if (Random.value < chance)
						{
							IncludeRecipe(section.recipes[j], umaRecipe, context, false);
						}
					}
					break;
				case SelectionType.IncludeOne:
				default:
					int index = Random.Range(0, section.recipes.Length);
					IncludeRecipe(section.recipes[index], umaRecipe, context, false);
					break;
			}
		}

		for (int i = 0; i < additionalRecipes.Length; i++)
		{
			IncludeRecipe(additionalRecipes[i], umaRecipe, context, true);
		}
	}
Beispiel #34
0
#pragma warning disable 618
	public void Start()
	{
		if (!slotLibrary)
		{
			slotLibrary = GameObject.Find("SlotLibrary").GetComponent("SlotLibrary") as SlotLibrary;
		}
		if (!raceLibrary)
		{
			raceLibrary = GameObject.Find("RaceLibrary").GetComponent("RaceLibrary") as RaceLibrary;
		}
		if (!overlayLibrary)
		{
			overlayLibrary = GameObject.Find("OverlayLibrary").GetComponent("OverlayLibrary") as OverlayLibrary;
		}
		if (Instance == null) Instance = this;
	}
Beispiel #35
0
    public static UMADynamicAvatar Load(string jsonData, UMAContext umaContext, Transform desiredTransform)
    {
        UMAPackedRecipeBase.UMAPackRecipe loadedRecipe = LitJson.JsonMapper.ToObject<UMAPackedRecipeBase.UMAPackRecipe>(jsonData);

        var newGO = new GameObject("Generated Character");
        newGO.transform.parent = desiredTransform;
        UMADynamicAvatar umaDynamicAvatar = newGO.AddComponent<UMADynamicAvatar>();
        umaDynamicAvatar.Initialize();
        UMAData umaData = umaDynamicAvatar.umaData;
        UMAPackedRecipeBase.UnpackRecipe(umaData, loadedRecipe, umaContext);
        umaDynamicAvatar.UpdateNewRace();
        umaDynamicAvatar.umaData.myRenderer.enabled = false;
        //umaDynamicAvatar.tag = "Player";

        return umaDynamicAvatar;
    }
    public void Initialize()
    {
        if (context == null)
        {
            context = UMAContext.FindInstance();
        }

        if (umaData == null)
        {
            umaData = GetComponent<UMAData>();
            if (umaData == null)
            {
                umaData = gameObject.AddComponent<UMAData>();
                umaData.umaGenerator = umaGenerator ?? umaData.umaGenerator;
            }
        }
    }
Beispiel #37
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);
		switch (packedRecipe.version)
		{
			case 2:
				UnpackRecipeVersion2(umaRecipe, packedRecipe, context);
				break;

			case 1:
			default:
				if (UnpackRecipeVersion1 (umaRecipe, packedRecipe, context)) 
				{
					umaRecipe.MergeMatchingOverlays ();
				}
				break;
		}
	}
Beispiel #38
0
	private void IncludeRecipe(UMARecipeBase recipe, UMAData.UMARecipe umaRecipe, UMAContext context, bool additional)
	{
		UMAData.UMARecipe cachedRecipe = recipe.GetCachedRecipe(context);
		umaRecipe.Merge(cachedRecipe, additional);
	}
 public override void PackedSave(UMAPackedRecipeBase.UMAPackRecipe packedRecipe, UMAContext context)
 {
     recipeString = JsonMapper.ToJson(packedRecipe);
 }
 public override UMAPackedRecipeBase.UMAPackRecipe PackedLoad(UMAContext context)
 {
     return JsonMapper.ToObject<UMAPackRecipe>(recipeString);
 }
Beispiel #41
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);
Beispiel #42
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)
	{
		if ((recipeString== null) || (recipeString.Length == 0)) return new UMAPackRecipe();
		return JsonMapper.ToObject<UMAPackRecipe>(recipeString);
	}
Beispiel #43
0
    public static void UnpackRecipeVersion2(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
    {
        umaRecipe.slotDataList = new SlotData[umaPackRecipe.slotsV2.Length];
        umaRecipe.additionalSlotCount = 0;
        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));
        }

        OverlayColorData[] colorData;
        if ((umaPackRecipe.fColors != null) && (umaPackRecipe.fColors.Length > 0))
        {
            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.colors != null) && (umaPackRecipe.colors.Length > 0))
        {
            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 (packedSlot != null && packedSlot.id != null)
            {
                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];
                        }
                        overlayData.EnsureChannels(overlayData.asset.material.channels.Length);
                        tempSlotData.AddOverlay(overlayData);
                    }
                }
                else
                {
                    tempSlotData.SetOverlayList(umaRecipe.slotDataList[packedSlot.copyIdx].GetOverlayList());
                }
            }
        }
    }
Beispiel #44
0
 public override void Load(UMAData umaData, UMAContext context)
 {
     var packedRecipe = PackedLoad(context);
     UnpackRecipe(umaData, packedRecipe, context);
 }
Beispiel #45
0
    public static bool UnpackRecipeVersion1(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
    {
        if (umaPackRecipe.packedSlotDataList == null)
            return false;

        umaRecipe.slotDataList = new SlotData[umaPackRecipe.packedSlotDataList.Length];
        umaRecipe.additionalSlotCount = 0;
        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.packedSlotDataList[i] != null && umaPackRecipe.packedSlotDataList[i].slotID != null)
            {
                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.packedSlotDataList[i].OverlayDataList[overlay].colorList != null)
                        {
                            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.packedSlotDataList[i].OverlayDataList[overlay].rectList != null)
                        {
                            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.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList != null)
                        {
                            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.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList != null)
                        {
                            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;
    }
Beispiel #46
0
	public abstract void Load(UMA.UMAData.UMARecipe umaRecipe, UMAContext context);
 public override void Load(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
 {
     var packedRecipe = PackedLoad(context);
     UnpackRecipe(umaRecipe, packedRecipe, context);
 }
Beispiel #48
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 = PackRecipeV2(umaRecipe);
     PackedSave(packedRecipe, context);
 }
 public override void Save(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
 {
     var packedRecipe = PackRecipe(umaRecipe);
     PackedSave(packedRecipe, context);
 }
Beispiel #50
0
 public override void Save(UMAData umaData, UMAContext context)
 {
     var packedRecipe = PackRecipe(umaData);
     PackedSave(packedRecipe, context);
 }
Beispiel #51
0
 public abstract void Save(UMA.UMAData umaData, UMAContext context);
Beispiel #52
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);
Beispiel #53
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);
Beispiel #54
0
 public abstract void Load(UMA.UMAData umaData, UMAContext context);
Beispiel #55
0
	protected void SaveRecipe(UMAData umaData, UMAContext context)
	{
		string assetPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(saveFolderPath, umaData.umaRecipe.raceData.raceName + ".asset"));
		var asset = ScriptableObject.CreateInstance<UMATextRecipe>();
		asset.Save(umaData.umaRecipe, context);
		AssetDatabase.CreateAsset(asset, assetPath);
		AssetDatabase.SaveAssets();
	}