Ejemplo n.º 1
0
 public static void ResetAssetTypeIfNull <TAsset>(InputSlot inputSlot)
 {
     if (inputSlot != null && inputSlot._assetType.type == null)
     {
         inputSlot._assetType = typeof(TAsset);
     }
 }
Ejemplo n.º 2
0
 public static Predicate <OutputSlot> GetDefaultPredicate(InputSlot input)
 {
     return((OutputSlot output) =>
     {
         return input.assetType.IsAssignableFrom(output.assetType);
     });
 }
Ejemplo n.º 3
0
 public void Connect(InputSlot target)
 {
     if (!_connectionTargets.Contains(target.key))
     {
         _connectionTargets.Add(target.key);
         target.source = this;
     }
 }
Ejemplo n.º 4
0
 public static InputSlot CreateOrResetOptionalMutating <TAsset>(ref InputSlot input, Generator generator)
 {
     if (input == null)
     {
         input = new InputSlot();
     }
     input.Initialize(generator, typeof(TAsset), true, true);
     return(input);
 }
Ejemplo n.º 5
0
 public static InputSlot CreateOrResetRequired <TAsset>(ref InputSlot input, Generator generator)
 {
     if (input == null)
     {
         input = new InputSlot();
     }
     input.Initialize(generator, typeof(TAsset), false, false);
     return(input);
 }
Ejemplo n.º 6
0
        public static InputSlotKey Create(InputSlot slot, Generator generator)
        {
            var instance = CreateInstance <InputSlotKey>();

            instance._slot      = slot;
            instance._generator = generator;
            instance.hideFlags  = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
            return(instance);
        }
Ejemplo n.º 7
0
        public static bool OnInspectorGUI(GUIContent label, InputSlot input, bool autoSelect, Predicate <OutputSlot> predicate)
        {
            var potentialSources = input.generator.executive.GetMatchingGeneratedAssets(input.generator, predicate);

            if (autoSelect && potentialSources.Count == 0 && input.isOptional)
            {
                input.source = null;
                return(false);
            }
            else if (autoSelect && potentialSources.Count == 1 && input.isRequired)
            {
                input.source = potentialSources[0];
                return(false);
            }
            else
            {
                var sourceIndex = potentialSources.IndexOf(input.source) + 1;

                var potentialSourcesContent = new GUIContent[potentialSources.Count + 1];
                potentialSourcesContent[0] = new GUIContent(potentialSources.Count > 0 ? "(no source selected)" : "(no source available)");
                for (int i = 0; i < potentialSources.Count; ++i)
                {
                    potentialSourcesContent[i + 1] = new GUIContent(potentialSources[i].name);
                }

                var priorBackgroundColor = GUI.backgroundColor;
                if (input.isRequired && sourceIndex == 0)
                {
                    GUI.backgroundColor = Color.Lerp(GUI.color, Color.red, 0.5f);
                }

                if (label.text.EndsWith(" Input"))
                {
                    label.text = label.text.Substring(0, label.text.Length - " Input".Length);
                }
                else if (label.text.EndsWith(" Input Slot"))
                {
                    label.text = label.text.Substring(0, label.text.Length - " Input Slot".Length);
                }

                sourceIndex = EditorGUILayout.Popup(label, sourceIndex, potentialSourcesContent);

                GUI.backgroundColor = priorBackgroundColor;

                if (sourceIndex > 0)
                {
                    input.source = potentialSources[sourceIndex - 1];
                }
                else
                {
                    input.source = null;
                }

                return(true);
            }
        }
Ejemplo n.º 8
0
        public void Initialize(Generator generator)
        {
            // Inputs
            InputSlot.CreateOrResetRequiredMutating <IRandom>(ref randomSeedInputSlot, generator);

            // Fields
            randomType = RandomType.XorShift128Plus;
            seedSource = SeedSource.Numerical;
            seedNumber = 0;
            seedText   = "";
        }
Ejemplo n.º 9
0
 public void ResetIfBroken(Generator generator)
 {
     if (randomSeedInputSlot != null && randomSeedInputSlot.generator != null)
     {
         InputSlot.ResetAssetTypeIfNull <IRandom>(randomSeedInputSlot);
     }
     else
     {
         InputSlot.CreateOrResetRequiredMutating <IRandom>(ref randomSeedInputSlot, generator);
     }
 }
Ejemplo n.º 10
0
        public static bool OnInspectorGUI(SerializedProperty property)
        {
            var obj   = property.serializedObject.targetObject;
            var field = obj.GetType().GetField(property.name);
            var input = (InputSlot)field.GetValue(obj);

            if (input.isActive)
            {
                return(OnInspectorGUI(new GUIContent(property.displayName), input, InputSlot.ShouldAutoSelect(field)));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 11
0
 public void Disconnect(InputSlot target)
 {
     _connectionTargets.Remove(target.key);
     target.source = null;
 }
Ejemplo n.º 12
0
        protected virtual void OnPropertiesGUI()
        {
            var generatorType = _generator.GetType();
            var property      = _serializedGenerator.GetIterator();

            if (property.NextVisible(true))
            {
                do
                {
                    var field = generatorType.GetField(property.name);
                    if (field == null)
                    {
                        continue;
                    }
                    if (field.FieldType == typeof(OutputSlot))
                    {
                        continue;
                    }
                    if (field.FieldType == typeof(OutputSlot[]))
                    {
                        continue;
                    }
                    if (field.FieldType == typeof(List <OutputSlot>))
                    {
                        continue;
                    }
                    if (!IsInAssetGeneratorSubclass(field))
                    {
                        continue;
                    }

                    var labelAttribute = GeneralUtility.GetAttribute <LabelAttribute>(field);
                    var labelContent   = new GUIContent(
                        labelAttribute != null ? labelAttribute.text : property.displayName,
                        property.tooltip);

                    if (field.FieldType == typeof(InputSlot))
                    {
                        var input = (InputSlot)field.GetValue(property.serializedObject.targetObject);
                        if (input.isActive)
                        {
                            InputSlotEditor.OnInspectorGUI(labelContent, input, InputSlot.ShouldAutoSelect(field));
                        }
                    }
                    else if (field.FieldType == typeof(RandomnessDescriptor))
                    {
                        var randomness = (RandomnessDescriptor)field.GetValue(property.serializedObject.targetObject);
                        randomness = RandomnessDescriptorEditor.OnInspectorGUI(labelContent, randomness);
                        field.SetValue(property.serializedObject.targetObject, randomness);
                    }
                    else if (typeof(Component).IsAssignableFrom(field.FieldType))
                    {
                        field.SetValue(property.serializedObject.targetObject, EditorGUILayoutExtensions.ObjectField(labelContent, property.objectReferenceValue, field.FieldType, false));
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(property, labelContent, true);
                    }
                } while (property.NextVisible(false));
            }
        }
        public static RandomnessDescriptor OnInspectorGUI(GUIContent label, RandomnessDescriptor randomness)
        {
            var priorIndentLevel = EditorGUI.indentLevel;

            if (!string.IsNullOrEmpty(label.text))
            {
                EditorGUILayout.LabelField(label);
                EditorGUI.indentLevel += 1;
            }

            randomness.randomType = (RandomnessDescriptor.RandomType)EditorGUILayout.EnumPopup("RNG Type", randomness.randomType);

            var priorSeedSource = randomness.seedSource;

            randomness.seedSource = (RandomnessDescriptor.SeedSource)EditorGUILayout.EnumPopup("Seed Source", randomness.seedSource);

            switch (priorSeedSource)
            {
            case RandomnessDescriptor.SeedSource.Random:
            case RandomnessDescriptor.SeedSource.RandomAndSystemTime:
            case RandomnessDescriptor.SeedSource.RandomAndNumerical:
            case RandomnessDescriptor.SeedSource.RandomAndTextual:
                InputSlotEditor.OnInspectorGUI(new GUIContent("Seeder"), randomness.randomSeedInputSlot, InputSlot.ShouldAutoSelect(randomness, "randomSeedInputSlot"));
                break;
            }

            switch (priorSeedSource)
            {
            case RandomnessDescriptor.SeedSource.Numerical:
            case RandomnessDescriptor.SeedSource.RandomAndNumerical:
                randomness.seedNumber = EditorGUILayout.IntField("Seed Number", randomness.seedNumber);
                break;

            case RandomnessDescriptor.SeedSource.Textual:
            case RandomnessDescriptor.SeedSource.RandomAndTextual:
                randomness.seedText = EditorGUILayout.TextField("Seed Text", randomness.seedText);
                break;
            }

            EditorGUI.indentLevel = priorIndentLevel;

            return(randomness);
        }
Ejemplo n.º 14
0
 public static bool OnInspectorGUI(GUIContent label, InputSlot input, bool autoSelect = false)
 {
     return(OnInspectorGUI(label, input, autoSelect, GetDefaultPredicate(input)));
 }