public void OnEnable() { //Manifest that defines what the SO uses from Machinations. Manifest = new MnObjectManifest { Name = "Sound Event", DiagramMappings = new List <DiagramMapping> { new DiagramMapping { PropertyName = M_MAX_SOUND_HIGH_HEALTH, DiagramElementID = 250, DefaultElementBase = new ElementBase(4, null), OverrideElementBase = new ElementBase(4, null) }, new DiagramMapping { PropertyName = M_MAX_SOUND_LOW_HEALTH, DiagramElementID = 251, DefaultElementBase = new ElementBase(6, null), OverrideElementBase = new ElementBase(6, null) } }, CommonStatesAssociations = new List <StatesAssociation> { new StatesAssociation("Exploring", new List <GameStates>() { GameStates.Exploring }) } }; //Register this SO with the MDL. MnDataLayer.EnrollScriptableObject(this, Manifest); }
/// <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="MnGameObject"/> enrolls itself /// using <see cref="MnDataLayer.EnrollGameObject"/>, this event WILL fire if the MachinationsDataLayer /// has been initialized. So, this is why it is allowed to send an EventHandler callback upon Construction. /// </param> public MnGameObject(MnObjectManifest manifest, EventHandler onBindersUpdated = null) { _name = manifest.Name; _manifest = manifest; foreach (DiagramMapping diagramMapping in _manifest.DiagramMappings) { 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; } MnDataLayer.EnrollGameObject(this); }
/// <summary> /// Called by <see cref="MnDataLayer"/> when initialization is complete. /// For all <see cref="MachinationsUP.Integration.Binder.ElementBinder"/>, retrieves their /// required <see cref="MachinationsUP.Integration.Elements.ElementBase"/> from MDL, FOR EACH /// possible <see cref="MachinationsUP.GameEngineAPI.States.StatesAssociation"/>. /// Complete override from <see cref="MnGameObject"/>. /// </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(MnDataLayer.GetGameState()); //Notify any listeners of base.OnBindersUpdated. NotifyBindersUpdated(); }
public void OnEnable() { //Manifest that defines what the SO uses from Machinations. Manifest = new MnObjectManifest { Name = "Enemy Tank Stats", DiagramMappings = new List <DiagramMapping> { new DiagramMapping { EditorElementBase = Health, PropertyName = M_HEALTH, DiagramElementID = 8920, DefaultElementBase = new ElementBase(105, null) }, new DiagramMapping { EditorElementBase = Speed, PropertyName = M_SPEED, DiagramElementID = 8917, DefaultElementBase = new ElementBase(25, null) }, //BUFFS. new DiagramMapping { EditorElementBase = HealthBuff, PropertyName = M_HEALTH_BUFF, DiagramElementID = 9120, DefaultElementBase = new ElementBase(25, null) }, new DiagramMapping { EditorElementBase = SpeedBuff, PropertyName = M_SPEED_BUFF, DiagramElementID = 9301, DefaultElementBase = new ElementBase(10, null) } } }; //Register this SO with the MDL. MnDataLayer.EnrollScriptableObject(this, Manifest); }
/// <summary> /// Emits the 'Game Init Request' Socket event. /// <param name="selectiveGet">TRUE: get only elements that we don't already have.</param> /// </summary> public void EmitDiagramInitRequest(bool selectiveGet) { if (!IsInitialized) { throw new Exception("SocketIO: Socket not open!"); } L.D("SocketIO: EmitMachinationsInitRequest."); var initRequestData = MnDataLayer.GetInitRequestData(_diagramToken, selectiveGet); //If there's nothing to request, quit. if (!initRequestData) { L.D("SocketIO: EmitMachinationsInitRequest: no data has been requested."); _mnService.InitComplete(null); return; } //TODO: better tracking of server responses. _socket.Emit(SyncMsgs.SEND_GAME_INIT, initRequestData); }
void Start() { AudioListener.pause = true; if (System.IO.File.Exists(SavedSettingsPath)) { GameSettings.LoadFromJSON(SavedSettingsPath); } else { GameSettings.InitializeFromDefault(GameSettingsTemplate); } foreach (var info in GetComponentsInChildren <PlayerInfoController>()) { info.Refresh(); } NumberOfRoundsSlider.value = GameSettings.Instance.NumberOfRounds; MnDataLayer.Prepare(); }
/// <summary> /// Handles Machinations tasks. /// </summary> public void ProcessSchedule() { try { //Execute any updates from the back-end. while (_updatesFromBackEnd.Count > 0) { MnDataLayer.UpdateSourcesWithValuesFromMachinations(_updatesFromBackEnd[0].Key, _updatesFromBackEnd[0].Value); _updatesFromBackEnd.RemoveAt(0); } //Rudimentary State Machine: //Socket not yet ready? if (!_socketClient.IsInitialized) { L.D("Machinations Service SocketIO Scheduler: Waiting for Socket Connection. Current State: " + _currentState); if (_currentState != State.WaitingForSocketReady) { L.E("Invalid state given the fact that the socket is not even initialized."); FreshStart(); } return; } //If the socket isn't yet ready, starting the Auth process. if (_currentState == State.WaitingForSocketReady) { L.D("Machinations Service SocketIO Scheduler: WaitingForSocketReady -> AuthRequested."); _currentState = State.AuthRequested; _socketClient.EmitAuthRequest(); return; } //Wait for Auth. if (_currentState == State.AuthRequested) { L.D("Machinations Service SocketIO Scheduler: Waiting for Auth Response."); return; } //Wait for Init. if (_currentState == State.InitRequested) { L.D("Machinations Service SocketIO Scheduler: Waiting for Sync Init Response."); return; } //When everything is connected, switching through the following states: switch (_currentState) { case State.AuthSuccess: L.D("Machinations Service SocketIO Scheduler: Auth Success. Idling."); _currentState = State.Idling; //Make sure we request init at first start. if (!HasPerformedFullDiagramInit) { _initRequested = true; } break; case State.Idling: if (_initRequested) { L.D("Machinations Service SocketIO Scheduler: Init Requested: Idling -> PreparingForInitRequest."); _currentState = State.PreparingForInitRequest; } break; //Wait at least 1 Timer interval before making the Sync request. case State.PreparingForInitRequest: L.D("Machinations Service SocketIO Scheduler: Init Requested."); _currentState = State.InitRequested; _initRequested = false; //The first time we get here, we will perform a FULL init request. _socketClient.EmitDiagramInitRequest(HasPerformedFullDiagramInit); HasPerformedFullDiagramInit = true; //But subsequent times, we will only ask for whatever is new. break; case State.InitComplete: L.D("Machinations Service SocketIO Scheduler: Init Complete. " + _currentState + " -> Idling."); _currentState = State.Idling; MnDataLayer.UpdateSourcesWithValuesFromMachinations(_diagramElementsFromBackEnd); MnDataLayer.SyncComplete(); break; } } catch (Exception ex) { L.ToLogFile("MachinationsService Scheduler Exception Caught:"); L.ExToLogFile(ex); } }
//TODO: to be switched to event-based during next iteration. public void FailedToConnect(bool loadCache) { FreshStart(); MnDataLayer.SyncFail(loadCache); }
public void OnEnable() { //Manifest that defines what the SO uses from Machinations. Manifest = new MnObjectManifest { Name = "Drop Ratios", DiagramMappings = new List <DiagramMapping> { new DiagramMapping { EditorElementBase = EnemyLifeBuffWeight, PropertyName = M_ENEMY_LIFE_BUFF_WEIGHT, DiagramElementID = 9135, DefaultElementBase = new ElementBase(200, null) }, new DiagramMapping { EditorElementBase = ExplosionForceBuffWeight, PropertyName = M_EXPLOSION_FORCE_BUFF_WEIGHT, DiagramElementID = 9136, DefaultElementBase = new ElementBase(100, null) }, new DiagramMapping { EditorElementBase = ExplosionRadiusBuffWeight, PropertyName = M_EXPLOSION_RADIUS_BUFF_WEIGHT, DiagramElementID = 9137, DefaultElementBase = new ElementBase(100, null) }, new DiagramMapping { EditorElementBase = EnemyCooldownBuffWeight, PropertyName = M_ENEMY_COOLDOWN_BUFF_WEIGHT, DiagramElementID = 9139, DefaultElementBase = new ElementBase(1, null) }, new DiagramMapping { EditorElementBase = EnemyDamageBuffWeight, PropertyName = M_ENEMY_DAMAGE_BUFF_WEIGHT, DiagramElementID = 9138, DefaultElementBase = new ElementBase(1, null) }, new DiagramMapping { EditorElementBase = PlayerCooldownBuffWeight, PropertyName = M_PLAYER_COOLDOWN_BUFF_WEIGHT, DiagramElementID = 9127, DefaultElementBase = new ElementBase(1, null) }, new DiagramMapping { EditorElementBase = PlayerProjectileSpeedBuffWeight, PropertyName = M_PLAYER_PROJECTILE_SPEED_BUFF_WEIGHT, DiagramElementID = 9049, DefaultElementBase = new ElementBase(1, null) }, new DiagramMapping { EditorElementBase = PlayerSpeedBuffWeight, PropertyName = M_PLAYER_SPEED_BUFF_WEIGHT, DiagramElementID = 9051, DefaultElementBase = new ElementBase(1, null) }, new DiagramMapping { EditorElementBase = PlayerLifeBuffWeight, PropertyName = M_PLAYER_LIFE_BUFF_WEIGHT, DiagramElementID = 9131, DefaultElementBase = new ElementBase(1, null) }, new DiagramMapping { EditorElementBase = EnemySpeedBuffWeight, PropertyName = M_ENEMY_SPEED_BUFF_WEIGHT, DiagramElementID = 9304, DefaultElementBase = new ElementBase(1, null) } } }; //Register this SO with the MDL. MnDataLayer.EnrollScriptableObject(this, Manifest); UpdateDropRates(); }
/// <summary> /// Draws the Machionations Control Panel GUI. /// </summary> void OnGUI() { //Wait until MnConfig instance is created. if (MnConfig.Instance == null && MnConfig.HasSettings) { return; } if (!_restoredFromSettings && MnConfig.HasSettings && MnConfig.Instance != null) { _restoredFromSettings = true; _APIURL = MnConfig.Instance.APIURL; _userKey = MnConfig.Instance.UserKey; _gameName = MnConfig.Instance.GameName; _diagramToken = MnConfig.Instance.DiagramToken; } EditorGUI.BeginChangeCheck(); GUILayout.Label("Machinations.io Connection Settings", EditorStyles.boldLabel); _APIURL = EditorGUILayout.TextField("API URL", _APIURL); _userKey = EditorGUILayout.TextField("User Key", _userKey); _gameName = EditorGUILayout.TextField("Game Name", _gameName); _diagramToken = EditorGUILayout.TextField("Diagram Token", _diagramToken); PopupSearchList.DrawLineInInspector(Color.black, 2, 10); //If it's not there yet, get Scriptable Object with Control Panel Graphics. if (_cpGraphics == null) { string assetGUID = AssetDatabase.FindAssets("t:MnCPanelGraphics")[0]; string path = AssetDatabase.GUIDToAssetPath(assetGUID); _cpGraphics = (MnCPanelGraphics)AssetDatabase.LoadAssetAtPath <ScriptableObject>(path); } //Now we can initialize the list of MachinationsElementType (which inherit from ITagProvider, used to provide custom //graphics to the PopupSearchList component). else { //Initialize only if required. if (_usedTypes == null) { _usedTypes = new Dictionary <string, MnElementTypeTagProvider> { { "Pool", new MnElementTypeTagProvider { Aspect = _cpGraphics.Pool, Name = "Pool" } }, { "Drain", new MnElementTypeTagProvider { Aspect = _cpGraphics.Drain, Name = "Drain" } }, { "State Connection", new MnElementTypeTagProvider { Aspect = _cpGraphics.StateConnection, Name = "State Connection" } }, { "Resource Connection", new MnElementTypeTagProvider { Aspect = _cpGraphics.ResourceConnection, Name = "Resource Connection" } }, { "End Condition", new MnElementTypeTagProvider { Aspect = _cpGraphics.EndCondition, Name = "End Condition" } }, { "Delay", new MnElementTypeTagProvider { Aspect = _cpGraphics.Delay, Name = "Delay" } }, { "Register", new MnElementTypeTagProvider { Aspect = _cpGraphics.Register, Name = "Register" } }, { "Converter", new MnElementTypeTagProvider { Aspect = _cpGraphics.Converter, Name = "Converter" } }, { "Trader", new MnElementTypeTagProvider { Aspect = _cpGraphics.Trader, Name = "Trader" } }, { "Gate", new MnElementTypeTagProvider { Aspect = _cpGraphics.Gate, Name = "Gate" } }, { "Source", new MnElementTypeTagProvider { Aspect = _cpGraphics.Source, Name = "Source" } }, }; } } //Setup PopupSearchList for importing Machinations Elements. if (_usedTypes != null && GUILayout.Button("Import Elements", GUILayout.Width(200))) { List <DiagramMapping> currentMappings = MnDataLayer.GetRegisteredMappings(); List <SearchListItem> searchListItems = new List <SearchListItem>(); foreach (DiagramMapping dm in currentMappings) { //No type specified? Cannot show such items. if (dm.Type == null) { continue; } //Handling NULL labels. if (dm.Label == null) { dm.Label = "[no label]"; } //Temporary fix of corrupted diagram elements. dm.Label = dm.Label.Replace("<span>", ""); dm.Label = dm.Label.Replace("</span>", ""); dm.Label = dm.Label.Replace("<span/>", ""); dm.Label = dm.Label.Replace("<br>", ""); dm.Label = dm.Label.Replace("</br>", ""); dm.Label = dm.Label.Replace("<br/>", ""); //Now create the SearchListItem. var sli = new SearchListItem { ID = dm.DiagramElementID, Name = dm.Label, TagProvider = _usedTypes[dm.Type], AttachedObject = dm }; searchListItems.Add(sli); } //The Popup will be shown immediately next to the button. PopupWindow.Show(_btnImportElementsRect, new PopupSearchList(Screen.width, searchListItems, new List <ITagProvider>(_usedTypes.Values))); } //Save buttonRect position so that we know where to place the PopupSearchList. //GetLastRect will return the Rect of the last-painted element, which in this case is the call to GUILayout.Button above. if (Event.current.type == EventType.Repaint) { _btnImportElementsRect = GUILayoutUtility.GetLastRect(); } EditorGUILayout.Separator(); if (GUI.changed) { SaveMachinationsConfig(); } }
public void OnEnable() { //Manifest that defines what the SO uses from Machinations. Manifest = new MnObjectManifest { Name = "Shell Stats", DiagramMappings = new List <DiagramMapping> { new DiagramMapping { EditorElementBase = Damage, PropertyName = M_DAMAGE, DiagramElementID = 8907, DefaultElementBase = new ElementBase(10, null) }, new DiagramMapping { EditorElementBase = Radius, PropertyName = M_RADIUS, DiagramElementID = 8905, DefaultElementBase = new ElementBase(25, null) }, new DiagramMapping { EditorElementBase = Force, PropertyName = M_FORCE, DiagramElementID = 8904, DefaultElementBase = new ElementBase(90, null) }, new DiagramMapping { EditorElementBase = Speed, PropertyName = M_SPEED, DiagramElementID = 8906, DefaultElementBase = new ElementBase(90, null) }, new DiagramMapping { EditorElementBase = ShotCooldown, PropertyName = M_COOLDOWN, DiagramElementID = 8909, DefaultElementBase = new ElementBase(0, null) }, //BUFFS. new DiagramMapping { EditorElementBase = ShotCooldownBuff, PropertyName = M_COOLDOWN_BUFF, DiagramElementID = 9130, DefaultElementBase = new ElementBase(0, null) }, new DiagramMapping { EditorElementBase = ExplosionForceBuff, PropertyName = M_EXPLOSION_FORCE_BUFF, DiagramElementID = 9237, CrossManifestName = "ExplosionForce", DefaultElementBase = new ElementBase(0, null) }, new DiagramMapping { EditorElementBase = ExplosionRadiusBuff, PropertyName = M_EXPLOSION_RADIUS_BUFF, DiagramElementID = 9238, CrossManifestName = "ExplosionRadius", DefaultElementBase = new ElementBase(0, null) }, new DiagramMapping { EditorElementBase = ShellSpeedBuff, PropertyName = M_SHELL_SPEED_BUFF, DiagramElementID = 9032, DefaultElementBase = new ElementBase(0, null) } } }; //Register this SO with the MDL. MnDataLayer.EnrollScriptableObject(this, Manifest); }