public AssignedBehavior AddBehavior(UnassignedBehavior behavior) { OnBeforeAnyChange(); Debug.Assert(!behavior.behaviorUri.IsNullOrEmpty()); string finalBehaviorUri = behavior.behaviorUri; // Alright, some special logic here. If it's a user-library behavior, do not // just use the URI directly. Import it, so turn it into embedded, then use // it. We want VOOS files to be stand-alone, so we can't have any local user // library dependencies. if (BehaviorSystem.IsUserLibraryBehaviorUri(behavior.behaviorUri)) { Behaviors.Behavior importedBehavior = GetBehaviorSystem().GetBehaviorData(behavior.behaviorUri); Debug.Assert(!importedBehavior.userLibraryFile.IsNullOrEmpty()); string importedId = GetBehaviorSystem().GenerateUniqueId(); GetBehaviorSystem().PutBehavior(importedId, importedBehavior); string importedUri = BehaviorSystem.IdToEmbeddedBehaviorUri(importedId); finalBehaviorUri = importedUri; } // Create the use in the database string useId = actor.GetBehaviorSystem().GenerateUniqueId(); var brain = GetBrain(); brain.AddUse(new BehaviorUse { id = useId, behaviorUri = finalBehaviorUri, propertyAssignments = new Behaviors.PropertyAssignment[0] }); GetBehaviorSystem().PutBrain(GetBrainId(), brain); return(new AssignedBehavior(useId, this)); }