public static void UnlinkModel(VFXModel model, bool notify = true)
 {
     if (model is IVFXSlotContainer)
     {
         var     slotContainer = (IVFXSlotContainer)model;
         VFXSlot slotToClean   = null;
         do
         {
             slotToClean = slotContainer.inputSlots.Concat(slotContainer.outputSlots).FirstOrDefault(o => o.HasLink(true));
             if (slotToClean)
             {
                 slotToClean.UnlinkAll(true, notify);
             }
         }while (slotToClean != null);
     }
 }
        public void RemoveChild(VFXModel model, bool notify = true)
        {
            if (model.m_Parent != this)
            {
                return;
            }

            model.OnRemoved();
            m_Children.Remove(model);
            model.m_Parent = null;

            if (notify)
            {
                Invalidate(InvalidationCause.kStructureChanged);
            }
        }
        protected override void OnInvalidate(VFXModel model, InvalidationCause cause)
        {
            base.OnInvalidate(model, cause);

            if (cause == InvalidationCause.kSettingChanged)
            {
                //Delete incompatible blocks

                foreach (var block in children.ToList())
                {
                    if (!Accept(block))
                    {
                        RemoveChild(block);
                    }
                }
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        protected override void OnInvalidate(VFXModel model, InvalidationCause cause)
        {
            if (cause == InvalidationCause.kSettingChanged || cause == InvalidationCause.kExpressionInvalidated)
            {
                if (cause == InvalidationCause.kSettingChanged && (m_Subgraph != null || object.ReferenceEquals(m_Subgraph, null))) // do not recreate subchildren if the subgraph is not available but is not null
                {
                    RecreateCopy();
                }

                base.OnInvalidate(model, cause);
                PatchInputExpressions();
            }
            else
            {
                base.OnInvalidate(model, cause);
            }
        }
Exemplo n.º 6
0
        protected override void OnInvalidate(VFXModel model, VFXModel.InvalidationCause cause)
        {
            m_saved = false;
            base.OnInvalidate(model, cause);

            if (model is VFXParameter || model is VFXSlot && (model as VFXSlot).owner is VFXParameter)
            {
                BuildParameterInfo();
            }

            if (cause == VFXModel.InvalidationCause.kStructureChanged)
            {
                UpdateSubAssets();
                if (model == this)
                {
                    VFXSubgraphContext.CallOnGraphChanged(this);
                }
            }

            if (cause == VFXModel.InvalidationCause.kSettingChanged && model is VFXParameter)
            {
                VFXSubgraphContext.CallOnGraphChanged(this);
            }

            if (cause != VFXModel.InvalidationCause.kExpressionInvalidated &&
                cause != VFXModel.InvalidationCause.kExpressionGraphChanged)
            {
                EditorUtility.SetDirty(this);
            }

            if (cause == VFXModel.InvalidationCause.kExpressionGraphChanged)
            {
                m_ExpressionGraphDirty = true;
                m_DependentDirty       = true;
            }

            if (cause == VFXModel.InvalidationCause.kParamChanged)
            {
                m_ExpressionValuesDirty = true;
                m_DependentDirty        = true;
            }
        }
Exemplo n.º 7
0
        public string GetUniqueSystemName(VFXModel model)
        {
            int index;

            if (m_SystemToIndex.TryGetValue(model, out index))
            {
                var wishedName = GetSystemUnindexedName(model);
                if (string.IsNullOrEmpty(wishedName))
                {
                    wishedName = DefaultSystemName;
                }
                var format  = "{0} ({1})";
                var newName = index == 0 ? wishedName : string.Format(format, wishedName, index);
                return(newName);
            }
            if (!(model is VFXSubgraphContext))
            {
                throw new InvalidOperationException("SystemNames : Model is not registered " + model);
            }
            return(GetSystemName(model));
        }
Exemplo n.º 8
0
        public string GetUniqueSystemName(VFXModel model)
        {
            int index;

            if (m_SystemToIndex.TryGetValue(model, out index))
            {
                var wishedName = GetSystemUnindexedName(model);
                if (string.IsNullOrEmpty(wishedName))
                {
                    wishedName = DefaultSystemName;
                }
                var format  = "{0} ({1})";
                var newName = index == 0 ? wishedName : string.Format(format, wishedName, index);
                return(newName);
            }
            if (!(model is VFXSubgraphContext))
            {
                Debug.LogError("model not registered.");
            }
            return(GetSystemName(model));
        }
        protected override void Invalidate(VFXModel model, InvalidationCause cause)
        {
            if (cause == InvalidationCause.kSettingChanged)
            {
                var graph = GetGraph();

                if (graph != null && subgraph != null && m_Subgraph.GetResource() != null)
                {
                    var otherGraph = m_Subgraph.GetResource().GetOrCreateGraph();
                    if (otherGraph == graph || otherGraph.subgraphDependencies.Contains(graph.GetResource().visualEffectObject))
                    {
                        m_Subgraph = null;              // prevent cyclic dependencies.
                    }
                    if (graph.GetResource().isSubgraph) // BuildSubgraphDependenciesis called for vfx by recompilation, but in subgraph we must call it explicitely
                    {
                        graph.BuildSubgraphDependencies();
                    }
                }
            }

            base.Invalidate(model, cause);
        }
Exemplo n.º 10
0
        protected override void OnInvalidate(VFXModel model, InvalidationCause cause)
        {
            base.OnInvalidate(model, cause);

            if (cause == InvalidationCause.kStructureChanged ||
                cause == InvalidationCause.kConnectionChanged ||
                cause == InvalidationCause.kExpressionInvalidated ||
                cause == InvalidationCause.kSettingChanged ||
                cause == InvalidationCause.kEnableChanged)
            {
                if (hasBeenCompiled || CanBeCompiled())
                {
                    bool skip = false;

                    // Check if the invalidation comes from a disable block and in that case don't recompile
                    if (cause != InvalidationCause.kEnableChanged)
                    {
                        VFXBlock block = null;
                        if (model is VFXBlock)
                        {
                            block = (VFXBlock)model;
                        }
                        else if (model is VFXSlot)
                        {
                            block = ((VFXSlot)model).owner as VFXBlock;
                        }

                        skip = block != null && !block.enabled;
                    }

                    if (!skip)
                    {
                        Invalidate(InvalidationCause.kExpressionGraphChanged);
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void AddChild(VFXModel model, int index = -1, bool notify = true)
        {
            int realIndex = index == -1 ? m_Children.Count : index;

            if (model.m_Parent != this || realIndex != GetIndex(model))
            {
                if (!AcceptChild(model, index))
                {
                    throw new ArgumentException("Cannot attach " + model + " to " + this);
                }

                model.Detach(notify && model.m_Parent != this);     // Dont notify if the owner is already this to avoid double invalidation
                realIndex = index == -1 ? m_Children.Count : index; // Recompute as the child may have been removed

                m_Children.Insert(realIndex, model);
                model.m_Parent = this;
                model.OnAdded();

                if (notify)
                {
                    Invalidate(InvalidationCause.kStructureChanged);
                }
            }
        }
Exemplo n.º 12
0
 public virtual bool AcceptChild(VFXModel model, int index = -1)
 {
     return(false);
 }
Exemplo n.º 13
0
 public override bool AcceptChild(VFXModel model, int index = -1)
 {
     return(!(model is VFXGraph)); // Can hold any model except other VFXGraph
 }
Exemplo n.º 14
0
 public VFXNodeID(VFXModel model, int id)
 {
     this.model        = model;
     this.isStickyNote = false;
     this.id           = id;
 }
Exemplo n.º 15
0
 protected void ApplyVariant(VFXModel m, bool notify)
 {
     m.SetSettingValues(m_Variants, notify);
 }
 protected override void Invalidate(VFXModel model, InvalidationCause cause)
 {
     base.Invalidate(model, cause);
 }
Exemplo n.º 17
0
        public static void ToOperatorWithoutFloatN(VFXOperator input, Type outputType)
        {
            if (!input.inputSlots.Where(o => o.property.type == typeof(FloatN)).Any())
            {
                Debug.LogError("SanitizeToOperatorNew is dedicated to operator using FloatN " + input);
                return;
            }

            var realTypeAndValue = input.inputSlots.Select(o =>
            {
                Type type      = null;
                object value   = null;
                bool wasFloatN = o.property.type == typeof(FloatN);
                if (!wasFloatN)
                {
                    type  = o.property.type;
                    value = o.HasLink() ? null : o.value;
                }
                else
                {
                    if (o.HasLink())
                    {
                        type = o.LinkedSlots.First().property.type;
                    }
                    else
                    {
                        var floatN = (FloatN)o.value;
                        type       = floatN.GetCurrentType();
                        value      = (FloatN)o.value;
                    }
                }
                return(new
                {
                    type = type,
                    value = value,
                    wasFloatN = wasFloatN
                });
            }).ToArray();

            var output = ScriptableObject.CreateInstance(outputType) as VFXOperatorDynamicOperand;

            //Transfer settings
            var settingsIn  = input.GetSettings(true).Where(o => o.FieldType != typeof(SerializableType));
            var settingsOut = output.GetSettings(true).Where(o => o.FieldType != typeof(SerializableType));

            if (settingsIn.Count() != settingsOut.Count())
            {
                Debug.LogError("Settings has been changed, unable to automatically transfer them");
                return;
            }

            var itSettingIn  = settingsIn.GetEnumerator();
            var itSettingOut = settingsOut.GetEnumerator();

            while (itSettingIn.MoveNext() && itSettingOut.MoveNext())
            {
                if (itSettingIn.Current.Name != itSettingOut.Current.Name.Replace("m_", string.Empty))
                {
                    Debug.Log(string.Format("Unexpected settings : {0} vs {1}", itSettingIn.Current.Name, itSettingOut.Current.Name));
                    return;
                }
                output.SetSettingValue(itSettingOut.Current.Name, itSettingIn.Current.GetValue(input));
            }

            //Apply dynamic type behavior
            if (output is IVFXOperatorUniform)
            {
                var uniform = output as IVFXOperatorUniform;
                var maxType = realTypeAndValue.Where(o => o.wasFloatN && o.type != typeof(FloatN))
                              .Select(o => o.type)
                              .OrderBy(o => VFXExpression.TypeToSize(VFXExpression.GetVFXValueTypeFromType(o)))
                              .LastOrDefault();

                if (maxType != null)
                {
                    //ignore int/uint while sanitizing
                    if (maxType == typeof(int) || maxType == typeof(uint))
                    {
                        maxType = typeof(float);
                    }

                    maxType = output.GetBestAffinityType(maxType);
                    uniform.SetOperandType(maxType);
                }
            }
            else if (output is VFXOperatorNumericCascadedUnified)
            {
                var cascaded = output as VFXOperatorNumericCascadedUnified;
                //Remove all empty last operand (has influence of output type for append)
                realTypeAndValue = realTypeAndValue.Reverse().SkipWhile(o => o.type == typeof(FloatN)).Reverse().ToArray();

                while (cascaded.inputSlots.Count < realTypeAndValue.Length)
                {
                    cascaded.AddOperand();
                }

                for (int i = 0; i < realTypeAndValue.Length; ++i)
                {
                    var currentType = cascaded.GetBestAffinityType(realTypeAndValue[i].type);
                    if (currentType != null)
                    {
                        cascaded.SetOperandType(i, currentType);
                    }
                }
            }
            else if (output is VFXOperatorNumericUnified)
            {
                var unified = output as VFXOperatorNumericUnified;
                var slotIndiceThatShouldHaveSameType = Enumerable.Empty <int>();
                var slotIndiceThatCanBeScale         = Enumerable.Empty <int>();
                if (output is IVFXOperatorNumericUnifiedConstrained)
                {
                    slotIndiceThatShouldHaveSameType = (output as IVFXOperatorNumericUnifiedConstrained).slotIndicesThatMustHaveSameType;
                    slotIndiceThatCanBeScale         = (output as IVFXOperatorNumericUnifiedConstrained).slotIndicesThatCanBeScalar;
                }

                Type maxTypeConstrained = null;
                if (slotIndiceThatShouldHaveSameType.Any())
                {
                    var typeConstrained = slotIndiceThatShouldHaveSameType.Select(i =>
                    {
                        if (i < realTypeAndValue.Length)
                        {
                            return(realTypeAndValue[i].type);
                        }
                        return((Type)null);
                    }).Where(o => o != null);

                    if (!typeConstrained.Any())
                    {
                        Debug.LogError("Unexpected behavior while sanitizing to unified constrained");
                        return;
                    }
                    maxTypeConstrained = typeConstrained.OrderBy(o => VFXExpression.TypeToSize(VFXExpression.GetVFXValueTypeFromType(o))).LastOrDefault();
                }

                for (int i = 0; i < realTypeAndValue.Length; ++i)
                {
                    var currentType = realTypeAndValue[i].type;
                    if (slotIndiceThatShouldHaveSameType.Contains(i) &&
                        !(slotIndiceThatCanBeScale.Contains(i) && VFXExpression.GetMatchingScalar(currentType) == currentType))
                    {
                        currentType = maxTypeConstrained;
                    }
                    currentType = output.GetBestAffinityType(currentType);
                    if (currentType != null)
                    {
                        unified.SetOperandType(i, currentType);
                    }
                }
            }
            else
            {
                Debug.LogError("Unable to determine what kind of " + output.GetType());
                return;
            }

            for (int i = 0; i < realTypeAndValue.Length; ++i)
            {
                var current = realTypeAndValue[i];
                if (!current.wasFloatN)
                {
                    VFXSlot.CopyLinksAndValue(output.inputSlots[i], input.inputSlots[i], true);
                }
                else
                {
                    if (current.value == null)
                    {
                        var slotDst = output.inputSlots[i];
                        var slotSrc = input.inputSlots[i].LinkedSlots.First();
                        if (slotSrc.CanLink(slotDst))
                        {
                            //Main path (most common case)
                            VFXSlot.CopyLinks(output.inputSlots[i], input.inputSlots[i], true);
                        }
                        else
                        {
                            //Trying to connect by subslot (e.g. : Vector4 to Vector3)
                            var itSubSlotSrc = slotSrc.children.GetEnumerator();
                            var itSubSlotDst = slotDst.children.GetEnumerator();
                            while (itSubSlotDst.MoveNext() && itSubSlotSrc.MoveNext())
                            {
                                itSubSlotSrc.Current.Link(itSubSlotDst.Current);
                            }
                        }
                    }
                    else
                    {
                        object orgValue   = null;
                        var    floatN     = (FloatN)current.value;
                        var    targetType = output.inputSlots[i].property.type;
                        if (targetType == typeof(float))
                        {
                            orgValue = (float)floatN;
                        }
                        else if (targetType == typeof(Vector2))
                        {
                            orgValue = (Vector2)floatN;
                        }
                        else if (targetType == typeof(Vector3))
                        {
                            orgValue = (Vector3)floatN;
                        }
                        else if (targetType == typeof(Vector4))
                        {
                            orgValue = (Vector4)floatN;
                        }
                        else
                        {
                            Debug.LogError("Unexpected type of FloatN while sanitizing : " + targetType);
                            return;
                        }
                        output.inputSlots[i].value = orgValue;
                    }
                }
            }

            for (int i = 0; i < input.outputSlots.Count; ++i)
            {
                VFXSlot.CopyLinks(output.outputSlots[i], input.outputSlots[i], true);
            }
            VFXModel.ReplaceModel(output, input);
        }
Exemplo n.º 18
0
 public int GetIndex(VFXModel child)
 {
     return(m_Children.IndexOf(child));
 }
Exemplo n.º 19
0
        public static void ReplaceModel(VFXModel dst, VFXModel src, bool notify = true)
        {
            // UI
            dst.m_UIPosition       = src.m_UIPosition;
            dst.m_UICollapsed      = src.m_UICollapsed;
            dst.m_UISuperCollapsed = src.m_UISuperCollapsed;

            if (notify)
            {
                dst.Invalidate(InvalidationCause.kUIChanged);
            }

            VFXGraph graph = src.GetGraph();

            if (graph != null && graph.UIInfos != null && graph.UIInfos.groupInfos != null)
            {
                // Update group nodes
                foreach (var groupInfo in graph.UIInfos.groupInfos)
                {
                    if (groupInfo.contents != null)
                    {
                        for (int i = 0; i < groupInfo.contents.Length; ++i)
                        {
                            if (groupInfo.contents[i].model == src)
                            {
                                groupInfo.contents[i].model = dst;
                            }
                        }
                    }
                }
            }

            if (dst is VFXBlock && src is VFXBlock)
            {
                ((VFXBlock)dst).enabled = ((VFXBlock)src).enabled;
            }

            // Unlink everything
            if (src is IVFXSlotContainer)
            {
                var     slotContainer = src as IVFXSlotContainer;
                VFXSlot slotToClean   = null;
                do
                {
                    slotToClean = slotContainer.inputSlots.Concat(slotContainer.outputSlots).FirstOrDefault(o => o.HasLink(true));
                    if (slotToClean)
                    {
                        slotToClean.UnlinkAll(true, true);
                    }
                }while (slotToClean != null);
            }

            // Replace model
            var parent = src.GetParent();
            int index  = parent.GetIndex(src);

            src.Detach(notify);

            if (parent)
            {
                parent.AddChild(dst, index, notify);
            }
        }
Exemplo n.º 20
0
 protected void ApplyVariant(VFXModel model)
 {
     model.SetSettingValues(m_Variants);
 }
Exemplo n.º 21
0
 public bool AcceptParent(VFXModel parent, int index = -1)
 {
     return(parent.AcceptChild(m_Template, index));
 }
 protected override void OnInvalidate(VFXModel model, InvalidationCause cause)
 {
     base.OnInvalidate(model, cause);
     _bufferName = string.Concat(_bufferName.Where(char.IsLetterOrDigit));
 }
Exemplo n.º 23
0
 protected internal override void Invalidate(VFXModel model, InvalidationCause cause)
 {
     base.Invalidate(model, cause);
     ResolveCustomCallbackInstance();
 }
Exemplo n.º 24
0
        protected override void OnInvalidate(VFXModel model, VFXModel.InvalidationCause cause)
        {
            if (cause == VFXModel.InvalidationCause.kStructureChanged ||
                cause == VFXModel.InvalidationCause.kSettingChanged ||
                cause == VFXModel.InvalidationCause.kSettingChanged ||
                cause == VFXModel.InvalidationCause.kConnectionChanged)
            {
                m_SystemNames.Sync(this);
            }

            base.OnInvalidate(model, cause);

            if (model is VFXParameter ||                              //Something changed directly on VFXParameter (e.g. exposed state boolean)
                model is VFXSlot && (model as VFXSlot).owner is VFXParameter || //Something changed on a slot owned by a VFXParameter (e.g. the default value)
                cause == VFXModel.InvalidationCause.kStructureChanged //A VFXParameter could have been removed
                )
            {
                BuildParameterInfo();
            }


            if (cause == VFXModel.InvalidationCause.kStructureChanged)
            {
                UpdateSubAssets();
                if (model == this)
                {
                    VFXSubgraphContext.CallOnGraphChanged(this);
                }

                m_DependentDirty = true;
            }

            if (cause == VFXModel.InvalidationCause.kSettingChanged && model is VFXParameter)
            {
                VFXSubgraphContext.CallOnGraphChanged(this);
                m_DependentDirty = true;
            }

            if (cause != VFXModel.InvalidationCause.kExpressionInvalidated &&
                cause != VFXModel.InvalidationCause.kExpressionGraphChanged &&
                cause != VFXModel.InvalidationCause.kUIChangedTransient &&
                (model.hideFlags & HideFlags.DontSave) == 0)
            {
                EditorUtility.SetDirty(this);
            }

            if (cause == VFXModel.InvalidationCause.kExpressionGraphChanged)
            {
                m_ExpressionGraphDirty = true;
                m_DependentDirty       = true;
            }

            if (cause == VFXModel.InvalidationCause.kParamChanged)
            {
                m_ExpressionValuesDirty = true;
                m_DependentDirty        = true;
            }

            if (cause == VFXModel.InvalidationCause.kMaterialChanged)
            {
                m_MaterialsDirty = true;
            }
        }
Exemplo n.º 25
0
 public VFXInvalidateErrorReporter(VFXErrorManager manager, VFXModel model)
 {
     m_Model   = model;
     m_Manager = manager;
 }
Exemplo n.º 26
0
        private static string GetSystemUnindexedName(VFXModel model)
        {
            var name = GetSystemName(model);

            return(string.IsNullOrEmpty(name) ? name : SysRegex.Replace(name, IndexPattern, ""));
        }
Exemplo n.º 27
0
 public void Attach(VFXModel parent, bool notify = true)
 {
     parent.AddChild(this, -1, notify);
 }
 void IVFXSlotContainer.Invalidate(VFXModel model, InvalidationCause cause)
 {
     Invalidate(model, cause);
 }
Exemplo n.º 29
0
 void SubChildrenOnInvalidate(VFXModel model, InvalidationCause cause)
 {
     Invalidate(this, cause);
 }
Exemplo n.º 30
0
 public VFXSetting(FieldInfo field, VFXModel instance)
 {
     this.field    = field;
     this.instance = instance;
 }