Exemple #1
0
        public void RemoveRelationship(GameObjectRelationship relationship)
        {
            // if null instanciate Relationships
            if (Relationships == null)
            {
                Relationships = new List <GameObjectRelationship>();
            }

            // if relationshipTo's Relationships is null instanciate Relationships
            if (relationship.RelationshipTo.Relationships == null)
            {
                relationship.RelationshipTo.Relationships = new List <GameObjectRelationship>();
            }

            // remove new relationship
            Relationships.Remove(relationship);

            // remove other type of relationship
            if (relationship.RelationshipDirection == RelationshipDirection.ParentToChild)
            {
                relationship.RelationshipTo.Relationships.Remove(new GameObjectRelationship(relationship.RelationshipType, RelationshipDirection.ChildToParent, this));
            }
            else if (relationship.RelationshipDirection == RelationshipDirection.ChildToParent)
            {
                relationship.RelationshipTo.Relationships.Remove(new GameObjectRelationship(relationship.RelationshipType, RelationshipDirection.ParentToChild, this));
            }
        }
Exemple #2
0
        public bool HasDirectRelationshipWith(GameBaseObject baseObject, RelationshipType type, RelationshipDirection direction)
        {
            if (Relationships == null)
            {
                return(false);
            }

            var objectRelationship = new GameObjectRelationship(type, direction, baseObject);

            // Identifies object equality by ID.
            // Returns whether the object's Relationships contains a relationship with the other object in the specified direction.
            return(Relationships.Any(gameObjectRelationship => gameObjectRelationship.RelationshipTo.ID == objectRelationship.RelationshipTo.ID));
        }