Exemple #1
0
        public bool UpdateLinkState(bool checkFileChanged)
        {
            PrefabLinkState lastState = this.linkState;

            ComponentNode  cmpNode = this as ComponentNode;
            GameObjectNode objNode = (cmpNode != null ? cmpNode.Parent : this) as GameObjectNode;

            PrefabLink prefabLink           = objNode != null ? objNode.Obj.AffectedByPrefabLink : null;
            bool       affectedByPrefabLink = prefabLink != null;

            if (cmpNode != null)
            {
                affectedByPrefabLink = affectedByPrefabLink && prefabLink.AffectsObject(cmpNode.Component);
            }
            if (objNode != null)
            {
                affectedByPrefabLink = affectedByPrefabLink && prefabLink.AffectsObject(objNode.Obj);
            }

            string filePath   = affectedByPrefabLink ? prefabLink.Prefab.Path : null;
            bool   fileExists = this.linkLastExisted;

            if (checkFileChanged || this.linkLastPath != filePath)
            {
                fileExists = File.Exists(filePath);
            }

            // Prefab-linked entities
            if (affectedByPrefabLink && fileExists)             //prefabLink.Prefab.IsAvailable) // Not sufficient - might be loaded but with a broken path
            {
                this.linkState = PrefabLinkState.Active;
            }
            else if (cmpNode == null && objNode.Obj.PrefabLink != null)
            {
                this.linkState = PrefabLinkState.Broken;
            }
            else
            {
                this.linkState = PrefabLinkState.None;
            }

            this.linkLastExisted = fileExists;
            this.linkLastPath    = filePath;
            return(this.linkState != lastState);
        }
        /// <summary>
        /// A <see cref="Cohee.Serialization.Serializer.FieldBlockers">FieldBlocker</see> to prevent
        /// fields of <see cref="Cohee.Resources.PrefabLink">PrefabLink-ed</see> objects from being serialized unnecessarily.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool PrefabLinkedFieldBlocker(FieldInfo field, object obj)
        {
            Component cmp = obj as Component;

            if (cmp == null || cmp.GameObj == null)
            {
                return(false);
            }

            PrefabLink link = cmp.GameObj.AffectedByPrefabLink;

            if (link == null || !link.AffectsObject(cmp))
            {
                return(false);
            }

            return(field.DeclaringType != typeof(Component));
        }