public DynamicUMADnaAsset CreateDNAAsset(string assetFolder = "", string assetName = "")
        {
            if (assetFolder == "")
            {
                assetFolder = AssetDatabase.GetAssetPath(selectedConverter);
                assetFolder = assetFolder.Substring(0, assetFolder.LastIndexOf('/'));
            }
            if (assetName == "")
            {
                assetName = selectedConverter.name + "DNAAsset";
                var uniquePath = AssetDatabase.GenerateUniqueAssetPath(assetFolder + "/" + assetName + ".asset");
                assetName = uniquePath.Replace(assetFolder + "/", "").Replace(".asset", "");
            }

            if (!System.IO.Directory.Exists(assetFolder))
            {
                System.IO.Directory.CreateDirectory(assetFolder);
            }

            DynamicUMADnaAsset asset = ScriptableObject.CreateInstance <DynamicUMADnaAsset>();

            AssetDatabase.CreateAsset(asset, assetFolder + "/" + assetName + ".asset");
            AssetDatabase.SaveAssets();
            return(asset);
        }
コード例 #2
0
        private void ImportDNADropArea(Rect dropArea, List <string> dnaNames, int addMethod)
        {
            Event evt = Event.current;

            //make the box clickable so that the user can select DynamicUMADnaAsset assets from the asset selection window
            if (evt.type == EventType.MouseUp)
            {
                if (dropArea.Contains(evt.mousePosition))
                {
                    DNAAssetPickerID = EditorGUIUtility.GetControlID(new GUIContent("DNAAssetPicker"), FocusType.Passive);
                    EditorGUIUtility.ShowObjectPicker <DynamicUMADnaAsset>(null, false, "", DNAAssetPickerID);
                    Event.current.Use();                    //stops the Mismatched LayoutGroup errors
                    return;
                }
            }
            if (evt.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == DNAAssetPickerID)
            {
                DynamicUMADnaAsset tempDnaAsset = EditorGUIUtility.GetObjectPickerObject() as DynamicUMADnaAsset;
                if (tempDnaAsset)
                {
                    AddDNANames(tempDnaAsset, dnaNames, addMethod);
                }
                Event.current.Use();                //stops the Mismatched LayoutGroup errors
                return;
            }
            if (evt.type == EventType.DragUpdated)
            {
                if (dropArea.Contains(evt.mousePosition))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
            }
            if (evt.type == EventType.DragPerform)
            {
                if (dropArea.Contains(evt.mousePosition))
                {
                    DragAndDrop.AcceptDrag();

                    UnityEngine.Object[] draggedObjects = DragAndDrop.objectReferences as UnityEngine.Object[];
                    for (int i = 0; i < draggedObjects.Length; i++)
                    {
                        if (draggedObjects[i])
                        {
                            DynamicUMADnaAsset tempDnaAsset = draggedObjects[i] as DynamicUMADnaAsset;
                            if (tempDnaAsset)
                            {
                                AddDNANames(tempDnaAsset, dnaNames, addMethod);
                                continue;
                            }

                            var path = AssetDatabase.GetAssetPath(draggedObjects[i]);
                            if (System.IO.Directory.Exists(path))
                            {
                                RecursiveScanFoldersForAssets(path, dnaNames, addMethod);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        public override void OnInspectorGUI()
        {
            //base.DrawDefaultInspector();

            serializedObject.Update();
            DrawPropertiesExcluding(serializedObject, _excludeProperties);

            GUILayout.Space(10);
            GUIHelper.BeginVerticalPadded(3, new Color(0.75f, 0.875f, 1f, 0.3f));
            _editorFoldout = EditorGUILayout.Foldout(_editorFoldout, "Editor Tools", true);
            if (_editorFoldout)
            {
                if (GUILayout.Button("Clear DNA Morphs List", GUILayout.MaxWidth(200)))
                {
                    if (EditorUtility.DisplayDialog("Warning", "Are you sure you want to clear the DNA Morphs list?", "Yes", "Cancel"))
                    {
                        ClearDnaMorphs();
                    }
                }
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent("Extract BlendShape Names", "This will find all the blendshape names in the supplied SlotData->MeshData and add them to the dna morph list. Warning! Will clear existing morphs."), GUILayout.MaxWidth(200)))
                {
                    if (EditorUtility.DisplayDialog("Warning", "This will clear your current dna morph list. Are you sure to proceed?", "Yes", "Cancel"))
                    {
                        ExtractBlendShapeNames();
                    }
                }
                _slotAsset = EditorGUILayout.ObjectField(_slotAsset, typeof(SlotDataAsset), false) as SlotDataAsset;

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent("Write to DynamicDNA", "This will write all the dna entry names from the dna morph list to the supplied DynamicUMADnaAsset.  Warning! This will clear the existing Dna Names on the DynamicUMADnaAsset."), GUILayout.MaxWidth(200)))
                {
                    if (EditorUtility.DisplayDialog("Warning", "This will clear your DynamicDnaName list. Are you sure to proceed?", "Yes", "Cancel"))
                    {
                        WriteToDynamicDNA();
                    }
                }
                _dnaAsset = EditorGUILayout.ObjectField(_dnaAsset, typeof(DynamicUMADnaAsset), false) as DynamicUMADnaAsset;
                EditorGUILayout.EndHorizontal();
            }
            GUIHelper.EndVerticalPadded(3);

            GUILayout.Space(10);
            GUIHelper.BeginVerticalPadded(3, new Color(0.75f, 0.875f, 1f, 0.3f));
            _morphsFoldout = EditorGUILayout.Foldout(_morphsFoldout, "Open/Close DNA Morphs", true);

            if (_morphsFoldout)
            {
                _morphList.DoLayoutList();
            }

            GUIHelper.EndVerticalPadded(3);

            serializedObject.ApplyModifiedProperties();
        }
コード例 #4
0
        //gets the names for the above popup, keeps missing names in the list too so that users can reselect them
        private static List <string> GetDNANamesForPopup(DynamicUMADnaAsset DNAAsset)
        {
            var _dnaNamesForPopup = new List <string>();

            for (int i = 0; i < DNAAsset.Names.Length; i++)
            {
                _dnaNamesForPopup.Add(DNAAsset.Names[i]);
            }
            _dnaNamesForPopup.Insert(0, "Choose DNA Name");
            return(_dnaNamesForPopup);
        }
コード例 #5
0
        public void Init()
        {
            thisDUDA = target as DynamicUMADnaAsset;
            //check the ID and paths
            bool doUpdate = thisDUDA.SetCurrentAssetPath();

            if (doUpdate)
            {
                serializedObject.Update();
            }
            initialized = true;
        }
コード例 #6
0
        private bool Init()
        {
            if (!_initialized)
            {
                bool stylesSet = false;

                if (EditorStyles.helpBox == null || EditorStyles.foldout == null || EditorStyles.label == null)
                {
                    //Dont set any styles
                }
                else
                {
                    //Style for subHeaders
                    _subHeaderStyle        = new GUIStyle(EditorStyles.helpBox);
                    _subHeaderStyle.margin = new RectOffset(_subHeaderStyle.margin.left, _subHeaderStyle.margin.right, _subHeaderStyle.margin.top, 0);

                    //Style for Tips
                    _foldoutTipStyle           = new GUIStyle(EditorStyles.foldout);
                    _foldoutTipStyle.fontStyle = FontStyle.Bold;

                    //Help Icon & style
                    _helpIcon = EditorGUIUtility.FindTexture("_Help");

                    _helpStyle               = new GUIStyle(EditorStyles.label);
                    _helpStyle.fixedHeight   = _helpIcon.height + 4f;
                    _helpStyle.contentOffset = new Vector2(-4f, 0f);

                    //Styles for the Add Converter area
                    var reorderableListDefaults = new ReorderableList.Defaults();
                    _pluginChooserAreaStyle               = new GUIStyle(reorderableListDefaults.boxBackground);
                    _pluginChooserAreaStyle.margin        = new RectOffset(4, 4, 2, 2);
                    _pluginChooserAreaStyle.stretchHeight = false;
                    _pluginChooserAreaStyle.padding       = new RectOffset(8, 8, 4, 8);

                    _pluginsByDNAAreaStyle         = new GUIStyle(EditorStyles.textField);
                    _pluginsByDNAAreaStyle.margin  = new RectOffset(0, 0, 0, 0);
                    _pluginsByDNAAreaStyle.padding = new RectOffset(4, 4, 4, 4);

                    stylesSet = true;
                }

                _initialized = stylesSet;

                _target = target as DynamicDNAConverterController;

                _dnaAsset = _target.DNAAsset;

                InitPlugins();
            }
            return(_initialized);
        }
コード例 #7
0
        private void AddDNANames(DynamicUMADnaAsset tempDNAAsset, List <string> dnaNames, int addMethod)
        {
            List <string> newNames = addMethod == 0 ? new List <string>(dnaNames) : new List <string>();

            for (int i = 0; i < tempDNAAsset.Names.Length; i++)
            {
                if (!newNames.Contains(tempDNAAsset.Names[i]))
                {
                    newNames.Add(tempDNAAsset.Names[i]);
                }
            }
            dnaNames = newNames;
            (target as DynamicUMADnaAsset).Names = dnaNames.ToArray();
        }
コード例 #8
0
        private void DrawDNAAssetField()
        {
            var dnaAssetProp        = serializedObject.FindProperty("_dnaAsset");
            var dnaAssetFoldoutRect = EditorGUILayout.GetControlRect();

            dnaAssetFoldoutRect.height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            var dnaAssetLabel = EditorGUI.BeginProperty(dnaAssetFoldoutRect, new GUIContent(dnaAssetProp.displayName), dnaAssetProp);

            dnaAssetLabel.text = dnaAssetLabel.text.ToUpper();
            GUIHelper.ToolbarStyleFoldout(dnaAssetFoldoutRect, dnaAssetLabel.text.ToUpper(), new string[] { dnaAssetLabel.tooltip }, ref _dnaAssetExpanded, ref _dnaAssetHelpExpanded);

            if (_dnaAssetExpanded)
            {
                GUIHelper.BeginVerticalPadded(3, new Color(0.75f, 0.875f, 1f, 0.3f));
                GUILayout.Space(5);
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(dnaAssetProp);
                if (EditorGUI.EndChangeCheck())
                {
                    if (dnaAssetProp.objectReferenceValue != null)
                    {
                        _dnaAsset = dnaAssetProp.objectReferenceValue as DynamicUMADnaAsset;
                    }
                    else
                    {
                        _dnaAsset = null;
                    }
                    //TODO in the ConverterBehaviour editor we cleared the DNA on the avatar.umaData (if we are in play mode and inspecting using customizer)
                    //we could probably do with doing the same here

                    /*
                     * //force the Avatar to update its dna and dnaconverter dictionaries
                     *      umaData.umaRecipe.ClearDna();
                     *      umaData.umaRecipe.ClearDNAConverters();
                     */
                }
                GUIHelper.EndVerticalPadded(3);
            }

            EditorGUILayout.Space();
        }
コード例 #9
0
        public void UpdateNames()
        {
            string[]           dnaNames = null;
            DynamicUMADnaAsset dnaAsset = null;

            if (target != null)
            {
                dnaAsset = target.dnaAsset;
            }
            if (dnaAsset != null)
            {
                _skelModPropDrawer.Init(dnaAsset.Names);
            }
            else
            {
                _skelModPropDrawer.Init(dnaNames);
            }
            if (minimalMode)
            {
                _skelModPropDrawer.bonesInSkeleton = bonesInSkeleton;
            }
        }
コード例 #10
0
 //Id really like this to show 'Choose DNA Name' in the field and 'None' as the 'Un-Choose' option in the list
 //but for that we need a generic menu
 //I also want a customOption that shows the textfield until you press return and then asks you if you want to add the name to the dna asset
 /// <summary>
 /// Draws a popup for selecting a dna name from the converters DynamicDNAAsset (if set) otherwise draws a text field
 /// </summary>
 public static void DNANamesPopup(Rect position, SerializedProperty property, string selected, DynamicUMADnaAsset DNAAsset)
 {
     if (DNAAsset == null)
     {
         EditorGUI.BeginChangeCheck();
         property.stringValue = EditorGUI.TextField(position, selected);
         if (EditorGUI.EndChangeCheck())
         {
             property.serializedObject.ApplyModifiedProperties();
             GUI.changed = true;
         }
     }
     else
     {
         int selectedIndex = -1;
         var names         = GetDNANamesForPopup(DNAAsset);
         selectedIndex = names.IndexOf(selected);
         if (selectedIndex == -1)
         {
             if (!string.IsNullOrEmpty(selected))
             {
                 names.Insert(1, selected);
                 selectedIndex = 1;
             }
             else
             {
                 selectedIndex = 0;
             }
         }
         EditorGUI.BeginChangeCheck();
         selectedIndex = EditorGUI.Popup(position, selectedIndex, names.ToArray());
         if (EditorGUI.EndChangeCheck())
         {
             if (selectedIndex != 0)
             {
                 property.stringValue = names[selectedIndex];
             }
             else
             {
                 property.stringValue = "";
             }
             property.serializedObject.ApplyModifiedProperties();
             GUI.changed = true;
         }
     }
 }