Beispiel #1
0
        protected VFXModelDescriptor(VFXModel template, Variant variants = null)
        {
            m_Variants = variants?.settings ?? new KeyValuePair <string, object> [0];
            //Don't notify model here for performance reason, we are assuming the name shouldn't relies on something in Invalidate of VFXModel
            ApplyVariant(template, false);

            model     = template;
            name      = model.libraryName;
            info      = VFXInfoAttribute.Get(model.GetType());
            modelType = model.GetType();
            category  = info?.category;

            if (!string.IsNullOrEmpty(category) && variants?.categories != null)
            {
                category = string.Format(category, variants.categories);
            }
        }
Beispiel #2
0
        private static Dictionary <Type, VFXModelDescriptor <VFXSlot> > LoadSlots()
        {
            // First find concrete slots
            var slotTypes  = FindConcreteSubclasses(typeof(VFXSlot), typeof(VFXInfoAttribute));
            var dictionary = new Dictionary <Type, VFXModelDescriptor <VFXSlot> >();

            foreach (var slotType in slotTypes)
            {
                try
                {
                    Type boundType = VFXInfoAttribute.Get(slotType).type; // Not null as it was filtered before
                    if (boundType != null)
                    {
                        if (dictionary.ContainsKey(boundType))
                        {
                            throw new Exception(boundType + " was already bound to a slot type");
                        }

                        VFXSlot instance = (VFXSlot)ScriptableObject.CreateInstance(slotType);
                        dictionary[boundType] = new VFXModelDescriptor <VFXSlot>(instance);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("Error while loading slot from type " + slotType + ": " + e);
                }
            }

            // Then find types that needs a generic slot
            var vfxTypes = FindConcreteSubclasses(null, typeof(VFXTypeAttribute));

            foreach (var type in vfxTypes)
            {
                if (!dictionary.ContainsKey(type)) // If a slot was not already explicitly declared
                {
                    VFXSlot instance = ScriptableObject.CreateInstance <VFXSlot>();
                    dictionary[type] = new VFXModelDescriptor <VFXSlot>(instance);
                }
            }

            return(dictionary);
        }