예제 #1
0
 public void SetAvatar(GameObject newAvatarObject)
 {
     if (guideUMA != null)
     {
         if (newAvatarObject == guideUMA.gameObject)
         {
             //reset guide transparency one we have sussed out how to do this
             guideUMA = null;
         }
     }
     if (targetUMA == null || newAvatarObject != targetUMA.gameObject)
     {
         if (newAvatarObject.GetComponent <UMAAvatarBase>() != null)
         {
             targetUMA = newAvatarObject.GetComponent <UMAAvatarBase>();
             activeUMA = newAvatarObject.GetComponent <UMAAvatarBase>();
             SetAvailableConverters(activeUMA.umaData);
             selectedConverter = null;
         }
         else
         {
             targetUMA = null;
             activeUMA = null;
             availableConverters.Clear();
             selectedConverter = null;
         }
     }
 }
예제 #2
0
        public Dictionary <string, DnaSetter> GetDNA(UMAData umaData, IDNAConverter dcb, string[] dbNames)
        {
            Dictionary <string, DnaSetter> dna = new Dictionary <string, DnaSetter>();

            foreach (UMADnaBase db in umaData.GetAllDna())
            {
                string Category = dcb.DisplayValue;

                if (dbNames.Length == 0)
                {
                    Debug.Break();
                }
                for (int i = 0; i < db.Count; i++)
                {
                    if (dna.ContainsKey(dbNames[i]))
                    {
                        dna[db.Names[i]] = new DnaSetter(dbNames[i], db.Values[i], i, db, Category);
                    }
                    else
                    {
                        try
                        {
                            dna.Add(dbNames[i], new DnaSetter(dbNames[i], db.Values[i], i, db, Category));
                        }
                        catch (System.Exception ex)
                        {
                            Debug.LogException(ex);
                        }
                    }
                }
            }
            return(dna);
        }
예제 #3
0
        //We could probably do with a Utility here to draw this kind of thing universally since DefaultWardrobeRecipes and WardrobeCollections Arbitrary recipes,
        //and the slot/overlay libraries also have the same thing
        //draws a list like this maybe something like a 'DropList' that handles the drawing of the area, and the items in the list
        //TODO make this 'click to pick' DynamicDNAConverterControllers
        private void DropAreaGUI(Rect dropArea, SerializedProperty converterListProp)
        {
            var evt = Event.current;

            if (evt.type == EventType.DragUpdated)
            {
                if (dropArea.Contains(evt.mousePosition))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    //can we make this show 'rejected' if the object wont get added for any reason?
                }
            }
            if (evt.type == EventType.DragPerform)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                if (dropArea.Contains(evt.mousePosition))
                {
                    DragAndDrop.AcceptDrag();
                    UnityEngine.Object[] draggedObjects = DragAndDrop.objectReferences as UnityEngine.Object[];
                    IDNAConverter        IDCObj         = null;
                    if (draggedObjects[0] is IDNAConverter)
                    {
                        IDCObj = draggedObjects[0] as IDNAConverter;
                    }
                    else if (draggedObjects[0].GetType() == typeof(GameObject))
                    {
                        if ((draggedObjects[0] as GameObject).GetComponent <IDNAConverter>() != null)
                        {
                            IDCObj = (draggedObjects[0] as GameObject).GetComponent <IDNAConverter>();
                        }
                    }
                    if (IDCObj != null)
                    {
                        bool canAdd = true;
                        for (int i = 0; i < converterListProp.arraySize; i++)
                        {
                            if (converterListProp.GetArrayElementAtIndex(i).objectReferenceValue == IDCObj as UnityEngine.Object)
                            {
                                canAdd = false;
                            }
                        }
                        if (canAdd)
                        {
                            converterListProp.arraySize++;
                            converterListProp.GetArrayElementAtIndex(converterListProp.arraySize - 1).objectReferenceValue = IDCObj as UnityEngine.Object;
                            converterListProp.serializedObject.ApplyModifiedProperties();
                            GUI.changed = true;
                        }
                        else
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                        }
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                }
            }
        }
예제 #4
0
 public void Insert(int index, IDNAConverter converter)
 {
     if (converter == null)
     {
         return;
     }
     _converters.Insert(index, converter as Object);
 }
예제 #5
0
 public bool Contains(IDNAConverter converter)
 {
     if (converter == null)
     {
         return(false);
     }
     return(_converters.Contains(converter as UnityEngine.Object));
 }
예제 #6
0
 public void Remove(IDNAConverter converter)
 {
     if (converter == null)
     {
         return;
     }
     if (_converters.Contains(converter as UnityEngine.Object))
     {
         _converters.Remove(converter as UnityEngine.Object);
     }
 }
예제 #7
0
 public void Add(IDNAConverter converter)
 {
     if (converter == null)
     {
         return;
     }
     if (!_converters.Contains(converter as UnityEngine.Object))
     {
         _converters.Add(converter as UnityEngine.Object);
     }
 }
예제 #8
0
        public IDNAConverter[] ToArray()
        {
            //If there is no way to add to the list directly (debug mode maybe) we wont need to validate
            Validate();
            var ret = new IDNAConverter[_converters.Count];

            for (int i = 0; i < _converters.Count; i++)
            {
                ret[i] = _converters[i] as IDNAConverter;
            }
            return(ret);
        }
예제 #9
0
        public bool Replace(IDNAConverter oldConverter, IDNAConverter newConverter)
        {
            if (oldConverter == null || newConverter == null)
            {
                return(false);
            }
            var replaceIndex = _converters.IndexOf(oldConverter as UnityEngine.Object);

            if (replaceIndex != -1)
            {
                _converters[replaceIndex] = newConverter as UnityEngine.Object;
                return(true);
            }
            return(false);
        }
예제 #10
0
 public int IndexOf(IDNAConverter converter)
 {
     if (converter == null)
     {
         return(-1);
     }
     Validate();            //will this be fast enough?
     for (int i = 0; i < _converters.Count; i++)
     {
         if (_converters[i] == converter as Object)
         {
             return(i);
         }
     }
     return(-1);
 }
예제 #11
0
        /// <summary>
        /// Finds any names in the given replacing converter, that match ones in the original converter
        /// </summary>
        /// <param name="originalConverter"></param>
        /// <param name="replacingConverter"></param>
        /// <returns>returns a dictionary of matching indexes, where the entry's index is the index in the replacing converter's dna and the entry's value is the corresponding index in the original converter's dna </returns>
        private Dictionary <int, int> GetMatchingIndexes(IDNAConverter originalConverter, IDNAConverter replacingConverter)
        {
            List <string> originalNames  = new List <string>();
            List <string> replacingNames = new List <string>();
            UMADnaBase    originalDNA;
            UMADnaBase    replacingDNA;

            //original
            if (originalConverter.DNAType == typeof(DynamicUMADna))
            {
                originalNames.AddRange(((IDynamicDNAConverter)originalConverter).dnaAsset.Names);
            }
            else
            {
                originalDNA = originalConverter.DNAType.GetConstructor(System.Type.EmptyTypes).Invoke(null) as UMADnaBase;
                if (originalDNA != null)
                {
                    originalNames.AddRange(originalDNA.Names);
                }
            }
            //replacing
            if (replacingConverter.DNAType == typeof(DynamicUMADna))
            {
                replacingNames.AddRange(((IDynamicDNAConverter)replacingConverter).dnaAsset.Names);
            }
            else
            {
                replacingDNA = replacingConverter.DNAType.GetConstructor(System.Type.EmptyTypes).Invoke(null) as UMADnaBase;
                if (replacingDNA != null)
                {
                    replacingNames.AddRange(replacingDNA.Names);
                }
            }
            Dictionary <int, int> matchingIndexes = new Dictionary <int, int>();

            for (int i = 0; i < originalNames.Count; i++)
            {
                if (replacingNames.Contains(originalNames[i]))
                {
                    matchingIndexes.Add(i, replacingNames.IndexOf(originalNames[i]));
                }
            }
            return(matchingIndexes);
        }
        private void DoDropArea(Rect dropArea, SerializedProperty property)
        {
            Event evt = Event.current;

            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[];
                    IDNAConverter        IDCObj         = null;
                    if (draggedObjects[0] is IDNAConverter)
                    {
                        IDCObj = draggedObjects[0] as IDNAConverter;
                    }
                    else if (draggedObjects[0].GetType() == typeof(GameObject))
                    {
                        if ((draggedObjects[0] as GameObject).GetComponent <IDNAConverter>() != null)
                        {
                            IDCObj = (draggedObjects[0] as GameObject).GetComponent <IDNAConverter>();
                        }
                    }
                    if (IDCObj != null)
                    {
                        property.objectReferenceValue = IDCObj as UnityEngine.Object;
                        property.serializedObject.ApplyModifiedProperties();                        //Needed?
                        GUI.changed = true;
                    }
                }
            }
        }
예제 #13
0
 /// <summary>
 /// Adds a DNAConverter to this Races list of converters
 /// </summary>
 /// <param name="converter"></param>
 public void AddConverter(IDNAConverter converter)
 {
     _dnaConverterList.Add(converter);
 }
예제 #14
0
        public override void OnInspectorGUI()
        {
            bool dirty = false;

            var           currentSource = dnaRange.dnaConverter;
            IDNAConverter newSource     = currentSource;

            var converterProp = serializedObject.FindProperty("_dnaConverter");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(converterProp);
            if (EditorGUI.EndChangeCheck())
            {
                var converterFieldProp = converterProp.FindPropertyRelative("_converter");
                if (converterFieldProp.objectReferenceValue != null)
                {
                    newSource             = converterFieldProp.objectReferenceValue as IDNAConverter;
                    dnaRange.dnaConverter = newSource;
                }
                GetEntryCount();
                serializedObject.ApplyModifiedProperties();
            }
            //UMA 2.8 FixDNAPrefabs:Use the propertyField
            //newSource = EditorGUILayout.ObjectField("DNA Converter", dnaRange.dnaConverter, typeof(DnaConverterBehaviour), true) as DnaConverterBehaviour;

            if (currentSource != newSource)
            {
                dnaRange.dnaConverter = newSource;
                dnaSource             = null;
                //UMA 2.8 FixDNAPrefabs: We want to preserve the settings if we can
                var matchingIndexes = GetMatchingIndexes(currentSource, newSource);

                var newMeans      = new float[entryCount];
                var newDeviations = new float[entryCount];
                var newSpreads    = new float[entryCount];
                for (int i = 0; i < entryCount; i++)
                {
                    if (matchingIndexes.ContainsKey(i))
                    {
                        newMeans[i]      = dnaRange.means[matchingIndexes[i]];
                        newDeviations[i] = dnaRange.deviations[matchingIndexes[i]];
                        newSpreads[i]    = dnaRange.spreads[matchingIndexes[i]];
                    }
                    else
                    {
                        newMeans[i]      = 0.5f;
                        newDeviations[i] = 0.16f;
                        newSpreads[i]    = 0.5f;
                    }
                }

                /*dnaRange.means = new float[entryCount];
                 * dnaRange.deviations = new float[entryCount];
                 * dnaRange.spreads = new float[entryCount];
                 * for (int i = 0; i < entryCount; i++)
                 * {
                 *      dnaRange.means[i] = 0.5f;
                 *      dnaRange.deviations[i] = 0.16f;
                 *      dnaRange.spreads[i] = 0.5f;
                 * }*/

                dnaRange.means      = newMeans;
                dnaRange.deviations = newDeviations;
                dnaRange.spreads    = newSpreads;

                dirty = true;
            }

            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

            if (dnaRange.dnaConverter != null)
            {
                GUILayout.Space(2f);
                GUIStyle headerStyle = new GUIStyle();
                headerStyle.alignment        = TextAnchor.MiddleCenter;
                headerStyle.normal.textColor = Color.white;
                headerStyle.fontSize         = 12;
                EditorGUILayout.LabelField(dnaRange.dnaConverter.DNAType.Name, headerStyle);

                string[] dnaNames;
                if (dnaRange.dnaConverter.DNAType == typeof(DynamicUMADna))
                {
                    dnaNames = ((IDynamicDNAConverter)dnaRange.dnaConverter).dnaAsset.Names;
                }
                else
                {
                    dnaNames = dnaSource.Names;
                }

                for (int i = 0; i < entryCount; i++)
                {
                    if (i > dnaRange.means.Length - 1)
                    {
                        break;
                    }
                    float currentMin = dnaRange.means[i] - dnaRange.spreads[i];
                    float currentMax = dnaRange.means[i] + dnaRange.spreads[i];
                    float min        = currentMin;
                    float max        = currentMax;
                    EditorGUILayout.PrefixLabel(dnaNames[i]);
                    EditorGUILayout.MinMaxSlider(ref min, ref max, 0f, 1f);
                    if ((min != currentMin) || (max != currentMax))
                    {
                        dnaRange.means[i]      = (min + max) / 2f;
                        dnaRange.spreads[i]    = (max - min) / 2f;
                        dnaRange.deviations[i] = dnaRange.spreads[i] / 3f;
                        dirty = true;
                    }
                }
            }

            if (dirty)
            {
                EditorUtility.SetDirty(dnaRange);
                AssetDatabase.SaveAssets();
            }
        }