Beispiel #1
0
        public static void  ShowWindow()
        {
            UMAAssetIndexerEditor window = EditorWindow.GetWindow <UMAAssetIndexerEditor>();
            Texture icon = AssetDatabase.LoadAssetAtPath <Texture> ("Assets/UMA/InternalDataStore/UMA32.png");
            // Create the instance of GUIContent to assign to the window. Gives the title "RBSettings" and the icon
            GUIContent titleContent = new GUIContent("UMA Library", icon);

            window.titleContent = titleContent;
        }
		public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){
			if (warningIcon == null)
			{
				warningIcon = EditorGUIUtility.FindTexture("console.warnicon.sml");
			}
			EditorGUI.BeginProperty (position, label, property);
			var r0 = new Rect (position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
			SerializedProperty foldoutProp1 = property.FindPropertyRelative ("defaultAnimationController");
			foldoutProp1.isExpanded = EditorGUI.Foldout (r0, foldoutProp1.isExpanded, "Race Animation Controllers");

			if (foldoutProp1.isExpanded) {
				EditorGUI.indentLevel++;
				var valR = r0;
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				EditorGUI.PropertyField (valR,property.FindPropertyRelative ("defaultAnimationController"));
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				SerializedProperty foldoutProp2 = property.FindPropertyRelative ("animators");
				foldoutProp2.isExpanded = EditorGUI.Foldout (valR, foldoutProp2.isExpanded, "Race Animators");
				//we cant delete elements in the loop so ...
				List<int> willDeleteArrayElementAtIndex = new List<int> ();

				if (foldoutProp2.isExpanded) {
					EditorGUI.indentLevel++;
					var thisAnimatorsProp = property.FindPropertyRelative ("animators");
					var numAnimators = thisAnimatorsProp.arraySize;
					var warningStyle = new GUIStyle(EditorStyles.label);
					warningStyle.fixedHeight = warningIcon.height + 4f;
					warningStyle.contentOffset = new Vector2(0, -2f);
					for (int i = 0; i < numAnimators; i++) {
						var thisAnimtorProp = thisAnimatorsProp.GetArrayElementAtIndex (i);
						valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
						var propsR = valR;
						propsR.width = propsR.width - 20f;
						var rPropR = propsR;
						rPropR.width = rPropR.width / 2;
						var aPropR = rPropR;
						aPropR.x = propsR.x + rPropR.width;
						var rLabelR = rPropR;
						rLabelR.width = (float)(rLabelR.width * 0.3)+(15f * (EditorGUI.indentLevel -1));
						var rFieldR = rPropR;
						rFieldR.x = rFieldR.x + rLabelR.width;
						rFieldR.width = rFieldR.width - rLabelR.width;
						//
						var aLabelR = aPropR;
						aLabelR.width = (float)(aLabelR.width * 0.3);
						var aFieldR = aPropR;
						aFieldR.x = aFieldR.x + aLabelR.width;
						aFieldR.width = aFieldR.width - aLabelR.width;
						var removeR = propsR;
						removeR.x = aFieldR.xMax;
						removeR.width = 20f;

						EditorGUI.LabelField (rLabelR, "Race");
						EditorGUI.indentLevel--;
						EditorGUI.indentLevel--;
						if (thisAnimtorProp.FindPropertyRelative ("raceName").stringValue == "") {
							//draw an object field for RaceData
							EditorGUI.BeginChangeCheck();
							RaceData thisRD = null;
							thisRD = (RaceData)EditorGUI.ObjectField (rFieldR, thisRD, typeof(RaceData),false);
							//if this gets filled set the values
							if(EditorGUI.EndChangeCheck()){
								if (thisRD != null) {
									thisAnimatorsProp.GetArrayElementAtIndex (i).FindPropertyRelative ("raceName").stringValue = thisRD.raceName;
								}
							}
						}
						else
						{
							EditorGUI.BeginDisabledGroup (true);
							EditorGUI.TextField (rFieldR, thisAnimtorProp.FindPropertyRelative ("raceName").stringValue);
							EditorGUI.EndDisabledGroup ();
						}
						EditorGUI.LabelField (aLabelR, "Animator");
						var thisAnimatorName = thisAnimtorProp.FindPropertyRelative("animatorControllerName").stringValue;
						if (thisAnimatorName == "")
						{
							//draw an object field for RunTimeAnimatorController
							EditorGUI.BeginChangeCheck();
							RuntimeAnimatorController thisRC = null;
							thisRC = (RuntimeAnimatorController)EditorGUI.ObjectField (aFieldR, thisRC, typeof(RuntimeAnimatorController), false);
							//if this gets filled set the values
							if(EditorGUI.EndChangeCheck()){
								if (thisRC != null) {
									thisAnimatorsProp.GetArrayElementAtIndex (i).FindPropertyRelative ("animatorControllerName").stringValue = thisRC.name;
								}
							}
						}
						else
						{
							if (DynamicAssetLoader.Instance)
							{
								if (!CheckAnimatorAvailability(thisAnimatorName))
								{
									var warningRect = new Rect((removeR.xMin - 20f), removeR.yMin, 20f, removeR.height);
									aFieldR.xMax = aFieldR.xMax - 20f;
									//if its in an assetbundle we need a different message (i.e "turn on 'Dynamically Add From AssetBundles"') 
									var warningGUIContent = new GUIContent("", thisAnimtorProp.FindPropertyRelative("animatorControllerName").stringValue + " was not Live. If the asset is in an assetBundle check 'Dynamically Add from AssetBundles' below otherwise click this button to add it to the Global Library.");
									warningGUIContent.image = warningIcon;
									if (GUI.Button(warningRect, warningGUIContent, warningStyle))
									{
										var thisAnimator = FindMissingAnimator(thisAnimatorName);
										if (thisAnimator != null)
											UMAAssetIndexer.Instance.EvilAddAsset(thisAnimator.GetType(), thisAnimator);
										else
											UMAAssetIndexerEditor.ShowWindow();
									}
								}
							}
							EditorGUI.BeginDisabledGroup(true);
							EditorGUI.TextField(aFieldR, thisAnimtorProp.FindPropertyRelative("animatorControllerName").stringValue);
							EditorGUI.EndDisabledGroup();
						}
						if(GUI.Button(removeR,"X")){
							willDeleteArrayElementAtIndex.Add(i);
						}
						EditorGUI.indentLevel++;
						EditorGUI.indentLevel++;
					}
					if (willDeleteArrayElementAtIndex.Count > 0) {
						foreach (int i in willDeleteArrayElementAtIndex) {
							thisAnimatorsProp.DeleteArrayElementAtIndex (i);
						}
					}
					thisAnimatorsProp.serializedObject.ApplyModifiedProperties();
					valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
					var butValR = valR;
					//GUI doesn't know EditorGUI.indentLevel
					butValR.xMin = valR.xMin + (15 * EditorGUI.indentLevel);
					if(GUI.Button(butValR,"Add Race Animator")){
						//add a new element to the list
						thisAnimatorsProp.InsertArrayElementAtIndex(numAnimators);
						thisAnimatorsProp.serializedObject.ApplyModifiedProperties();
						//make sure its blank
						thisAnimatorsProp.GetArrayElementAtIndex(numAnimators).FindPropertyRelative("raceName").stringValue = "";
						thisAnimatorsProp.GetArrayElementAtIndex(numAnimators).FindPropertyRelative("animatorControllerName").stringValue = "";
						thisAnimatorsProp.GetArrayElementAtIndex(numAnimators).FindPropertyRelative("animatorController").objectReferenceValue = null;
						thisAnimatorsProp.serializedObject.ApplyModifiedProperties();
					}
					EditorGUI.indentLevel--;
				}
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				var dynamicallyAddFromResources = property.FindPropertyRelative ("dynamicallyAddFromResources").boolValue;
				EditorGUI.BeginChangeCheck();
				dynamicallyAddFromResources = EditorGUI.ToggleLeft(valR,"Dynamically Add from Global Library", dynamicallyAddFromResources);
				if(EditorGUI.EndChangeCheck()){
					property.FindPropertyRelative ("dynamicallyAddFromResources").boolValue = dynamicallyAddFromResources;
					property.serializedObject.ApplyModifiedProperties ();
				}
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				EditorGUI.PropertyField (valR,property.FindPropertyRelative ("resourcesFolderPath"), new GUIContent("Global Library Folder Filter"));
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				var dynamicallyAddFromAssetBundles = property.FindPropertyRelative ("dynamicallyAddFromAssetBundles").boolValue;
				EditorGUI.BeginChangeCheck();
				dynamicallyAddFromAssetBundles = EditorGUI.ToggleLeft(valR,"Dynamically Add from Asset Bundles", dynamicallyAddFromAssetBundles);
				if(EditorGUI.EndChangeCheck()){
					property.FindPropertyRelative ("dynamicallyAddFromAssetBundles").boolValue = dynamicallyAddFromAssetBundles;
					property.serializedObject.ApplyModifiedProperties ();
				}
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				EditorGUI.PropertyField (valR,property.FindPropertyRelative ("assetBundleNames"), new GUIContent("AssetBundles to Search"));
				EditorGUI.indentLevel--;
			}
			EditorGUI.EndProperty ();
		}
Beispiel #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
			changed = false;
            if (warningIcon == null)
            {
                warningIcon = EditorGUIUtility.FindTexture("console.warnicon.sml");
            }
            EditorGUI.BeginProperty(position, label, property);
            var r0 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            SerializedProperty foldoutProp1 = property.FindPropertyRelative("loadDefaultRecipes");
            foldoutProp1.isExpanded = EditorGUI.Foldout(r0, foldoutProp1.isExpanded, "Default Wardrobe Recipes");
            if (foldoutProp1.isExpanded)
            {
                var valR = r0;
                valR = new Rect(valR.xMin, valR.yMax, valR.width, EditorGUIUtility.singleLineHeight);
                EditorGUI.PropertyField(valR, property.FindPropertyRelative("loadDefaultRecipes"));
                Rect dropArea = new Rect(valR.xMin, (valR.yMax + padding), valR.width, 50f);
                GUI.Box(dropArea, "Drag Wardrobe Recipes here");
                valR = new Rect(valR.xMin, (valR.yMin + 50f + padding), valR.width, EditorGUIUtility.singleLineHeight);
                var thisRecipesProp = property.FindPropertyRelative("recipes");
                float textFieldWidth = (valR.width - 20f);
                var warningStyle = new GUIStyle(EditorStyles.label);
                warningStyle.fixedHeight = warningIcon.height + 4f;
                warningStyle.contentOffset = new Vector2(0, -2f);
                //can we make these validate to the compatible races is upto date?
                thisDCA.preloadWardrobeRecipes.Validate();
                for (int i = 0; i < thisRecipesProp.arraySize; i++)
                {
                    var valRBut = new Rect((textFieldWidth + 18f), (valR.yMax + padding), 20f, EditorGUIUtility.singleLineHeight);
                    valR = new Rect(valR.xMin, (valR.yMax + padding), textFieldWidth, EditorGUIUtility.singleLineHeight);
                    SerializedProperty thisElement = thisRecipesProp.GetArrayElementAtIndex(i);
                    EditorGUI.BeginDisabledGroup(true);
                    int compatibleRacesArraySize = thisElement.FindPropertyRelative("_compatibleRaces").arraySize;
                    string compatibleRaces = "";
                    for (int cr = 0; cr < compatibleRacesArraySize; cr++)
                    {
                        compatibleRaces = compatibleRaces + thisElement.FindPropertyRelative("_compatibleRaces").GetArrayElementAtIndex(cr).stringValue;
                        if (cr < compatibleRacesArraySize - 1)
                        {
                            compatibleRaces = compatibleRaces + ", ";
                        }
                    }
                    var recipeIsLive = true;
                    var recipeName = thisElement.FindPropertyRelative("_recipeName").stringValue;
                    if (DynamicAssetLoader.Instance)
                        recipeIsLive = CheckRecipeAvailability(recipeName);
                    if (!recipeIsLive)
                        valR.width = valR.width - 25f;
                    EditorGUI.TextField(valR, recipeName + " (" + compatibleRaces + ")");
                    EditorGUI.EndDisabledGroup();
                    if (!recipeIsLive)
                    {
                        var warningRect = new Rect((valRBut.xMin - 25f), valRBut.yMin, 20f, valRBut.height);
						var warningGUIContent = new GUIContent("", recipeName + " was not Live. If the asset is in an assetBundle make sure the DynamicCharacterSystem is set to Add assets from assetBundles otherwise click this button to add it to the Global Library.");
						warningGUIContent.image = warningIcon;
						//show a warning icon if the added recipe is not available from the global index (or assetBundles)
						var foundRecipe = FindMissingRecipe(recipeName);
						if (GUI.Button(warningRect, warningGUIContent, warningStyle))
						{
							//the _recipe value is no longer serialized so we need to get it from AssetDatabase
							if (foundRecipe != null)
								UMAAssetIndexer.Instance.EvilAddAsset(foundRecipe.GetType(), foundRecipe);
							else
								UMAAssetIndexerEditor.ShowWindow();
						}
					}
                    if (GUI.Button(valRBut, "X"))
                    {
						changed = true;
                        thisRecipesProp.DeleteArrayElementAtIndex(i);
                        thisRecipesProp.serializedObject.ApplyModifiedProperties();
                    }
                }
                DropAreaGUI(dropArea, thisRecipesProp);
            }
            EditorGUI.EndProperty();
        }