/// <summary> /// Default constructor. /// </summary> /// <param name="manifest">The Manifest that will be used to initialized this MachinationsGameObject.</param> /// <param name="onBindersUpdated">When a <see cref="MachinationsGameObject"/> enrolls itself /// using <see cref="MachinationsGameLayer.EnrollGameObject"/>, this event WILL fire if the MachinationsGameLayer /// has been initialized. So, this is why it is allowed to send an EventHandler callback upon Construction. /// </param> public MachinationsGameObject(MachinationsGameObjectManifest manifest, EventHandler onBindersUpdated = null) { _gameObjectName = manifest.GameObjectName; _manifest = manifest; foreach (DiagramMapping diagramMapping in _manifest.PropertiesToSync) { CreateBinder(diagramMapping); } //Assign event, if any was provided. This has to be done before EnrollGameObject, because that function //may call MGLInitComplete, which may in turn call OnBindersUpdated. if (onBindersUpdated != null) { OnBindersUpdated = onBindersUpdated; } MachinationsGameLayer.EnrollGameObject(this); }
/// <summary> /// Called by <see cref="MachinationsUP.Engines.Unity.MachinationsGameLayer"/> when initialization is complete. /// For all <see cref="MachinationsUP.Integration.Binder.ElementBinder"/>, retrieves their /// required <see cref="MachinationsUP.Integration.Elements.ElementBase"/> from MGL, FOR EACH /// possible <see cref="MachinationsUP.GameEngineAPI.States.StatesAssociation"/>. /// Complete override from <see cref="MachinationsUP.Integration.GameObject.MachinationsGameObject"/>. /// </summary> override internal void MGLInitComplete(bool isRunningOffline = false) { //Go through all Binders and ask them to retrieve their ElementBase, For each StatesAssociation. foreach (string gameObjectPropertyName in _binders.Keys) { foreach (StatesAssociation sa in _manifest.GetStatesAssociationsForPropertyName(gameObjectPropertyName)) { _binders[gameObjectPropertyName].CreateElementBaseForStateAssoc(sa, isRunningOffline, isRunningOffline); } } //Since this is a Game Aware Object, update its Game State. OnGameStateChanged(MachinationsGameLayer.GetGameState()); //Notify any listeners of base.OnBindersUpdated. NotifyBindersUpdated(); }