示例#1
0
        private VFXSlot InternalSanitize(int version)
        {
            // Remove invalid links (without owners)
            if (owner == null)
            {
                UnlinkAll();
            }

            foreach (var link in LinkedSlots.ToArray())
            {
                if (link.owner == null || ((VFXModel)(link.owner)).GetGraph() != ((VFXModel)owner).GetGraph())
                {
                    Unlink(link);
                }
            }

            // Here we check if hierarchy of type match with slot hierarchy
            var  subProperties = property.SubProperties().ToList();
            bool hierarchySane = subProperties.Count == GetNbChildren();

            if (hierarchySane)
            {
                for (int i = 0; i < GetNbChildren(); ++i)
                {
                    if (subProperties[i].type != this[i].property.type)
                    {
                        hierarchySane = false;
                        break;
                    }
                    else
                    {
                        // Just ensure potential renaming of property is taken into account
                        this[i].m_Property = subProperties[i];
                    }
                }
            }

            if (!hierarchySane)
            {
                Debug.LogWarningFormat("Slot {0} holding {1} didnt match the type layout. It is recreated and all links are lost.", property.name, property.type);
                return(Recreate());
            }
            return(this);
        }
示例#2
0
        private VFXSlot InternalSanitize(int version)
        {
            // Remove invalid links (without owners)
            if (owner == null)
            {
                UnlinkAll();
            }

            foreach (var link in LinkedSlots.ToArray())
            {
                if (link.owner == null || ((VFXModel)(link.owner)).GetGraph() != ((VFXModel)owner).GetGraph())
                {
                    Unlink(link);
                }
            }

            // Here we check if hierarchy of type match with slot hierarchy
            var  subProperties = property.SubProperties().ToList();
            bool hierarchySane = subProperties.Count == GetNbChildren();

            if (hierarchySane)
            {
                for (int i = 0; i < GetNbChildren(); ++i)
                {
                    if (subProperties[i].type != this[i].property.type)
                    {
                        hierarchySane = false;
                        break;
                    }
                    else
                    {
                        // Just ensure potential renaming of property is taken into account
                        this[i].m_Property = subProperties[i];
                    }
                }
            }

            if (!hierarchySane)
            {
                Debug.LogWarningFormat("Slot {0} holding {1} didnt match the type layout. It is recreated and all links are lost.", property.name, property.type);

                // Try to retrieve the value
                object previousValue = null;
                try
                {
                    previousValue = this.value;
                }
                catch (Exception e)
                {
                    Debug.LogWarningFormat("Exception while trying to retrieve value: {0}: {1}", e, e.StackTrace);
                }

                // Recreate the slot
                var newSlot = Create(property, direction, previousValue);
                if (IsMasterSlot())
                {
                    var owner = this.owner;
                    if (owner != null)
                    {
                        int index = owner.GetSlotIndex(this);
                        owner.RemoveSlot(this);
                        owner.AddSlot(newSlot, index);
                    }
                }
                else
                {
                    var parent = GetParent();
                    var index  = parent.GetIndex(this);
                    parent.RemoveChild(this, false);
                    parent.AddChild(newSlot, index);
                }

                CopyLinks(newSlot, this, true);
                CopySpace(newSlot, this, true);
                UnlinkAll(true);
                return(newSlot);
            }
            return(this);
        }