/** * Creates an object from the supplied hash table * * @param newParams * TODO Fill this in */ private GameObject CreateObject(IDictionary Params, string Tag) { string prefab = ObjectFactoryHelper.DeterminePrefab(Params, Tag); //Debug.Log("ObjectFactory: prefab: " + prefab); GameObject BaseObject = Resources.Load(prefab) as GameObject; //Debug.Log("Objectfactory: BaseObject: " + BaseObject); //Debug.Log("ObjectFactory: BaseObject transform: " + BaseObject.transform.position); //GameObject BaseObject = Resources.Load(prefab) as GameObject; ////Debug.Log("Objectfactory: BaseObject: " + BaseObject); GameObject GO = NetworkManager.NetworkInstance.InstancePrefabOnNetwork(prefab); // Iterate through all possible parameters for the game object. // If one of the parameters has not been supplied, use the default value. foreach (string ParamName in Params.Keys) { IDictionary Value = Params[ParamName] as IDictionary; // Determines the controller that this parameter will be sent to. //string Ctrl = ParamName + "Controller"; string Ctrl = ObjectFactoryHelper.DetermineControllerCreate(ParamName, prefab); // Send the value of the parameter to the controller PassToController(GO, Ctrl, Value); } //Debug.Log(System.String.Format("ObjectFactory: GO.transform at end: {0}", GO.transform.position)); return(GO); }
// IMPORTANT NOTE: This method does not necessarily *create* (well, resolve) service instances itself - it returns a delegate which in-turn performs the resolution process - but as an optimization it returns the resolved service, if available as part of the testing process. private ObjectFactory RequiredObjectFactoryFactory(Type serviceType, ObjectFactoryHelper helper) { // This is a convoluted operation: // 1. The first pass tests that the object is available from the serviceProvider, and if so, returns an ObjectFactory that uses the serviceProvider (regardless of scope depth). // 2. If nothing else works, then it returns an ObjectFactory for MEDI's ActivatorUtilities or Activator. // Now, this COULD work by performing the test, then discarding the returned object, and then invoking the ObjectFactory anyway... // but instead, we use the method argument to pass the returned object back to the caller to prevent needing to invoke the ObjectFactory twice whenever a new serviceType is requested for the first time. // 1: { Object result = helper.ServiceProvider.GetService(serviceType); // Btw, don't use `GetRequiredService(Type)` because that throws an exception if it fails. if (result != null) { helper.Instance = result; return(new ObjectFactory((sp, args) => sp.GetRequiredService(serviceType))); // this ObjectFactory will be used in future calls to GetService. } } // 2: try { // ActivatorUtilities.CreateFactory only throws InvalidOperationException if it cannot find a suitable constructor. // As the `ObjectFactory` itself isn't actually being invoked, we can be certain the exception is not being thrown from anywhere else. // See `CreateFactory` and `FindApplicableConstructor` in https://github.com/aspnet/DependencyInjection/blob/1.0.0-rc1/src/Microsoft.Extensions.DependencyInjection.Abstractions/ActivatorUtilities.cs return(ActivatorUtilities.CreateFactory(instanceType: serviceType, argumentTypes: Array.Empty <Type>())); } catch (InvalidOperationException) { // Fallback to Activator: return(ActivatorObjectFactoryFactory(serviceType)); } }
private IDictionary DeconstructObjectMultiThreaded(string toDeconstruct, iGameObjectDAO dao) { Dictionary <string, System.Object> defaultDict = dao.LoadDefault(); List <string> keys = new List <string>(); keys.AddRange(defaultDict.Keys); IDictionary shell = ControllerShell.Container[toDeconstruct] as IDictionary; for (int i = 0; i < keys.Count; i++) { string tag = toDeconstruct.Split('-')[0]; string Ctrl = ObjectFactoryHelper.DetermineControllerDestroyMultiThreaded(keys[i], tag); defaultDict[keys[i]] = (shell[Ctrl] as ISetGetValues).GetValues(); } return(defaultDict); }
private IDictionary DeconstructObject(GameObject toDeconstruct, iGameObjectDAO dao) { Dictionary <string, System.Object> defaultDict = dao.LoadDefault(); List <string> keys = new List <string>(); keys.AddRange(defaultDict.Keys); for (int i = 0; i < keys.Count; i++) { //string Ctrl = keys[i] + "Controller"; string Ctrl = ObjectFactoryHelper.DetermineControllerDestroy(keys[i], toDeconstruct); defaultDict[keys[i]] = GetFromController(toDeconstruct, Ctrl); //Debug.Log(defaultDict[keys[i]]); } return(defaultDict); }
/// <summary>Gets the service object of the specified type from <paramref name="serviceProvider"/>. This method never returns a <c>null</c> object reference and will throw an exception if resolution fails.</summary> public Object GetRequiredService(IServiceProvider serviceProvider, Type serviceType) { if (serviceProvider is null) { throw new ArgumentNullException(nameof(serviceProvider)); } if (serviceType is null) { throw new ArgumentNullException(nameof(serviceType)); } // // Optimziation: TryGet at first to avoid having to create ObjectFactoryHelper if we really don't need it: if (this.objectFactories.TryGetValue(serviceType, out ObjectFactory existingObjectFactoryFunc)) { return(existingObjectFactoryFunc(serviceProvider, arguments: null)); } else { ObjectFactoryHelper helper = new ObjectFactoryHelper(serviceProvider); ObjectFactory objectFactoryFunc = this.objectFactories.GetOrAdd(key: serviceType, valueFactory: this.RequiredObjectFactoryFactory, factoryArgument: helper); if (helper.Instance != null) { // A new service was requested for the first time, which necessarily meant creating it as part of the ObjectFactory-building process, so return it to avoid invoking the ObjectFactory twice: return(helper.Instance); } else { // Otherwise, an existing ObjectFactory was returned (or a test helper instance wasn't created), so use the ObjectFactory: return(objectFactoryFunc(serviceProvider: serviceProvider, arguments: null)); } } }
public void AlterWeaponData(string key) { AttackController uat = currentObject.GetComponent( ObjectFactoryHelper.DetermineControllerLiveObject( "Attack", currentObject)) as AttackController; Single validator = 0.0f; Weapon wep = uat.GetWeapon(key); string wnameval = WepNameVal.GetComponent <InputField> ().text; string wlethstring = WepLethalityVal.GetComponent <InputField> ().text; bool lethvalid = Single.TryParse(wlethstring, out validator); float wlethval = 0f; if (lethvalid) { wlethval = Single.Parse(wlethstring); } else { wlethval = wep.GetDamage(); } string wrangestring = WepRangeVal.GetComponent <InputField> ().text; bool rangevalid = Single.TryParse(wrangestring, out validator); float wrangeval = 0f; if (rangevalid) { wrangeval = Single.Parse(wrangestring); } else { wrangeval = wep.GetRange(); } string wprobstring = WepProbVal.GetComponent <InputField> ().text; bool probvalid = Single.TryParse(wprobstring, out validator); float wprobval = 0f; if (probvalid) { wprobval = Single.Parse(wprobstring); } else { wprobval = wep.GetHitChance(); } string wammostring = WepAmmoVal.GetComponent <InputField> ().text; bool ammovalid = Single.TryParse(wammostring, out validator); float wammoval = 0f; if (ammovalid) { wammoval = Single.Parse(wammostring); } else { wammoval = wep.GetMaxAmmo(); } string wcurrammostring = WepCurrAmmoVal.GetComponent <InputField> ().text; bool currammovalid = Single.TryParse(wcurrammostring, out validator); float wcurrammoval = 0f; if (currammovalid) { wcurrammoval = Single.Parse(wcurrammostring); } else { wcurrammoval = wep.GetCurAmmo(); } string wratestring = WepRateVal.GetComponent <InputField> ().text; bool ratevalid = Single.TryParse(wratestring, out validator); float wrateval = 0f; if (ratevalid) { wrateval = Single.Parse(wratestring); } else { wrateval = wep.GetMaxShots(); } uat.ThrowDamageChangeEvent(key, wlethval); uat.ThrowRangeChangeEvent(key, wrangeval); uat.ThrowHitChanceChangeEvent(key, wprobval); uat.ThrowMaxAmmoChangeEvent(key, (int)wammoval); uat.ThrowCurrentAmmoChangeEvent(key, (int)wcurrammoval); uat.ThrowMaxShotsChangeEvent(key, (int)wrateval); }
public void AlterUnitData() { // IdentityController uid = currentObject.GetComponent <IdentityController>(); // MoverController umov = currentObject.GetComponent <MoverController>(); // DetectorController udet = currentObject.GetComponent <DetectorController>(); // AttackController uat = currentObject.GetComponent <AttackController>(); // HealthController uhp = currentObject.GetComponent <HealthController>(); IdentityController uid = currentObject.GetComponent( ObjectFactoryHelper.DetermineControllerLiveObject( "Identity", currentObject)) as IdentityController; MoverController umov = currentObject.GetComponent( ObjectFactoryHelper.DetermineControllerLiveObject( "Mover", currentObject)) as MoverController; DetectorController udet = currentObject.GetComponent( ObjectFactoryHelper.DetermineControllerLiveObject( "Detector", currentObject)) as DetectorController; AttackController uat = currentObject.GetComponent( ObjectFactoryHelper.DetermineControllerLiveObject( "Attack", currentObject)) as AttackController; HealthController uhp = currentObject.GetComponent( ObjectFactoryHelper.DetermineControllerLiveObject( "Health", currentObject)) as HealthController; //Debug.Log ("max health at start: " + uhp.GetMaxHealth ()); Single validator = 0.0f; //validate hp input string maxhpstring = MaxHealthVal.GetComponent <InputField> ().text; bool maxhpvalid = Single.TryParse(maxhpstring, out validator); float maxhp_event = uhp.GetMaxHealth(); if (maxhpvalid) { maxhp_event = Single.Parse(maxhpstring); //uhp.SetMaxHealth(maxhp_event); } string namestring = NameVal.GetComponent <InputField>().text; string curhpstring = CurHealthVal.GetComponent <InputField> ().text; bool curhpvalid = Single.TryParse(curhpstring, out validator); float curhp_event = uhp.GetCurrentHealth(); if (curhpvalid) { curhp_event = Single.Parse(curhpstring); //uhp.SetCurrentHealth(curhp_event); } //same for movement string movstring = MoveVal.GetComponent <InputField> ().text; bool movvalid = Single.TryParse(movstring, out validator); float mov_event = umov.GetMoveRange(); if (movvalid) { mov_event = Single.Parse(movstring); //umov.SetMoveRange(mov_event); } ////Debug.Log ("max health after: " + uhp.GetMaxHealth ()); //same for ranges string airstring = AirRadarVal.GetComponent <InputField> ().text; bool airvalid = Single.TryParse(airstring, out validator); float airval = 0f; if (airvalid) { airval = Single.Parse(airstring); } else { airval = udet.AirRange; } string surfstring = SurfRadarVal.GetComponent <InputField> ().text; bool surfvalid = Single.TryParse(surfstring, out validator); float surfval = 0f; if (surfvalid) { surfval = Single.Parse(surfstring); } else { surfval = udet.SurfaceRange; } string substring = SubSonarVal.GetComponent <InputField> ().text; bool subvalid = Single.TryParse(substring, out validator); float subval = 0f; if (subvalid) { subval = Single.Parse(substring); } else { subval = udet.SonarRange; } if (!namestring.Equals(name)) { uid.ThrowNameChangeEvent(namestring); } uhp.ThrowMaxHealthChangeEvent(maxhp_event); uhp.ThrowCurrentHealthChangeEvent(curhp_event); umov.ThrowRangeChangeEvent(mov_event); udet.ThrowRangeChangeEvent(DetectorController.Event_Air_Change, airval); udet.ThrowRangeChangeEvent(DetectorController.Event_Surf_Change, surfval); udet.ThrowRangeChangeEvent(DetectorController.Event_Sonar_Change, subval); int index = WepDropdown.SelectedIndex; string comboname = WepDropdown.Items [index].LocalItem.ToString(); AlterWeaponData(comboname); }
public override object CreateNumber(string data) { return(ObjectFactoryHelper.ParseInt64(this, data)); }