protected override void FireWeapon( UnitWeaponSystem _weaponSys , NamedObject _TargetUnit ) { if( true == GlobalSingleton.GetGlobalSingletonObj().GetComponent<AutoPlayMachine>().m_Active ) return ; string weaponComponent = "" ; // check phaser weaponComponent = _weaponSys.FindAbleWeaponComponent( RandomAWeaponKeyword() , _TargetUnit.Name ) ; if( 0 == weaponComponent.Length ) { // Debug.Log( "FireWeapon() no available weapon" ) ; this.SetState( AI_Fire_State.MoveToTarget ) ; return ; } // fire if( true == _weaponSys.ActiveWeapon( weaponComponent , _TargetUnit , ConstName.UnitDataComponentUnitIntagraty ) ) { this.SetState( AI_Fire_State.WaitForReload ) ; } }
public Object FindAsset(ClassIDType classID, string name) { foreach (Object asset in FetchAssets()) { if (asset.ClassID == classID) { NamedObject namedAsset = (NamedObject)asset; if (namedAsset.ValidName == name) { return(asset); } } } foreach (FileIdentifier identifier in Metadata.Dependencies) { ISerializedFile file = Collection.FindSerializedFile(identifier.GetFilePath()); if (file == null) { continue; } foreach (Object asset in file.FetchAssets()) { if (asset.ClassID == classID) { NamedObject namedAsset = (NamedObject)asset; if (namedAsset.Name == name) { return(asset); } } } } return(null); }
public void CanGetName() { var obj = new NamedObject("Name 1"); var name = obj.Name; Assert.Equal("Name 1", name); }
virtual protected bool Update(NamedObject ndo_changes, out NamedObject to_change) { string idProperty_Name = null; to_change = ResolveNDO(ndo_changes, out idProperty_Name); if (to_change != null) { ObjScope.Transaction.Begin(); foreach (PropertyInfo pi in ndo_changes.GetType().GetProperties()) { if (pi.Name == idProperty_Name) { continue; // do not update Primary Property } object v_changes = pi.GetValue(ndo_changes, null); if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType)) { SetProperty(to_change, pi, v_changes); } } ObjScope.Transaction.Commit(); return(true); } else { return(false); } }
public void SetsReturnValueOfInvocation() { object result = new NamedObject("result"); ReturnAction action = new ReturnAction(result); Assert.AreSame(result, ResultOfAction(action), "result"); }
private async void LoadTagsAsync() { try { var tags = await _siService.GetTagsAsync(); Tags = new[] { All, new NamedObject { ID = -1, Name = null } }.Concat(tags).ToArray(); if (_tags.Length > 0) { // Без асинхронной загрузки пакетов if (DefaultTag != null) { _currentTag = _tags.FirstOrDefault(p => p.Name == DefaultTag) ?? _tags[0]; } else { _currentTag = _tags[0]; } OnPropertyChanged(nameof(CurrentTag)); } LoadPackagesAsync(); } catch (Exception exc) { Error?.Invoke(exc); IsLoading = false; } }
public void HasAReadableDescription() { object result = new NamedObject("result"); ReturnAction action = new ReturnAction(result); AssertDescription.IsEqual(action, "return <result>(NMockTests.NamedObject)"); }
public void TestThatConstructorInitializeNamedObjectWithDescription() { var fixture = new Fixture(); var nameSource = fixture.CreateAnonymous <string>(); var nameTarget = fixture.CreateAnonymous <string>(); var description = fixture.CreateAnonymous <string>(); var namedObject = new NamedObject(nameSource, nameTarget, description); Assert.That(namedObject, Is.Not.Null); Assert.That(namedObject.NameSource, Is.Not.Null); Assert.That(namedObject.NameSource, Is.Not.Empty); Assert.That(namedObject.NameSource, Is.EqualTo(nameSource)); Assert.That(namedObject.NameTarget, Is.Not.Null); Assert.That(namedObject.NameTarget, Is.Not.Empty); Assert.That(namedObject.NameTarget, Is.EqualTo(nameTarget)); Assert.That(namedObject.Description, Is.Not.Null); Assert.That(namedObject.Description, Is.Not.Empty); Assert.That(namedObject.Description, Is.EqualTo(description)); Assert.That(namedObject.ExceptionInfo, Is.Not.Null); Assert.That(namedObject.ExceptionInfo, Is.Not.Empty); Assert.That(namedObject.ExceptionInfo, Is.EqualTo(string.Format("{0}, NameSource={1}, NameTarget={2}, Description={3}", namedObject.GetType().Name, namedObject.NameSource, namedObject.NameTarget, namedObject.Description))); Assert.That(namedObject.MetadataObject, Is.Not.Null); Assert.That(namedObject.MetadataObject, Is.EqualTo(namedObject)); }
static protected void DumpCDOObject(object dump_obj) { Type t_res = dump_obj.GetType(); Console.WriteLine("Class: {0}", t_res.Name); PropertyInfo[] propertyInfos = t_res.GetProperties(); foreach (PropertyInfo pi in propertyInfos) { object v = pi.GetValue(dump_obj, null); if (v != null) { Type t_v = v.GetType(); Console.WriteLine("{0,-20}: {1,10}", t_v.Name, v.ToString()); if (t_v.IsGenericType == true) { PropertyInfo pi_item = t_v.GetProperty("Item"); System.Collections.IList i_v_list = v as System.Collections.IList; Console.WriteLine(pi_item.Name + " has " + i_v_list.Count + " element."); for (int i = 0; i < i_v_list.Count; i++) { object[] indexArgs = { i }; object pi_item_value = pi_item.GetValue(v, indexArgs); NamedObject pi_item_name = pi_item_value as NamedObject; Console.WriteLine(" Value: {0}, Name: {1}", pi_item_value, pi_item_name.Name); } } } } }
public void TestThatDescriptionSetterRaisePropertyChangedIfValueIsChanged() { var fixture = new Fixture(); var namedObject = new NamedObject(fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>()); Assert.That(namedObject, Is.Not.Null); var eventCalled = false; namedObject.PropertyChanged += ((s, e) => { Assert.That(s, Is.Not.Null); Assert.That(e, Is.Not.Null); Assert.That(e.PropertyName, Is.Not.Null); Assert.That(e.PropertyName, Is.Not.Empty); if (e.PropertyName.CompareTo("Description") == 0) { eventCalled = true; } }); namedObject.Description = namedObject.Description; Assert.That(eventCalled, Is.False); var newValue = fixture.CreateAnonymous <string>(); namedObject.Description = newValue; Assert.That(namedObject.Description, Is.EqualTo(newValue)); Assert.That(eventCalled, Is.True); }
virtual public bool Add(NamedObject ndo_insert) { string idProperty_Name = null; object check_exist = ResolveNDO(ndo_insert, out idProperty_Name); if (check_exist == null) { foreach (PropertyInfo pi in ndo_insert.GetType().GetProperties()) { if (pi.Name == idProperty_Name) { continue; // do not update Primary Property } object v_changes = pi.GetValue(ndo_insert, null); if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType)) { SetProperty(ndo_insert, pi, v_changes); } } ObjScope.Transaction.Begin(); ObjScope.Add(ndo_insert); ObjScope.Transaction.Commit(); return(true); } else { return(false); } }
static void ExportFiles(string _AssetBundlePath, string _ExportFileList, string _OutputDir) { if (File.Exists(_AssetBundlePath)) { Console.WriteLine("Loading assetbundle: " + '"' + _AssetBundlePath + '"'); assetsManager.LoadFiles(_AssetBundlePath); string pat = @"([^;]+)"; MatchCollection matches = Regex.Matches(_ExportFileList, pat); Match[] arr = new Match[matches.Count]; matches.CopyTo(arr, 0); HashSet <string> export_name_set = new HashSet <string>(); foreach (var item in arr) { export_name_set.Add(item.Value); } Console.WriteLine("Export files: "); foreach (var serifile in assetsManager.assetsFileList) { foreach (var assetobj in serifile.Objects) { NamedObject n_obj = assetobj as NamedObject; if (n_obj != null) { if (export_name_set.Contains(n_obj.m_Name)) { Console.WriteLine(n_obj.m_Name); ExportAsset(n_obj, _OutputDir); } } } } } }
private void ExportAsset(ProjectAssetContainer container, NamedObject asset, string path) { NativeFormatImporter importer = new NativeFormatImporter(container.ExportLayout); importer.MainObjectFileID = GetExportID(asset); ExportAsset(container, importer, asset, path, asset.Name); }
protected string GetUniqueFileName(Object @object, string dirPath) { string fileName; NamedObject named = @object as NamedObject; if (named == null) { Prefab prefab = @object as Prefab; if (prefab != null) { fileName = prefab.Name; } else { fileName = @object.GetType().Name; } } else { fileName = named.Name; } fileName = DirectoryUtils.GetMaxIndexName(dirPath, fileName); fileName = $"{fileName}.{@object.ExportExtension}"; return(fileName); }
public void SetsReturnValueOfInvocation() { object result = new NamedObject("result"); var action = new ReturnAction(result); Assert.AreSame(result, ResultOfAction(action), "result"); }
public void HasAReadableDescription() { object result = new NamedObject("result"); var action = new ReturnAction(result); AssertDescription.IsEqual(action, "return <result>"); }
public void CanSpecifyResultForOtherType() { var synth = new ResultSynthesizer(); var value = new NamedObject("value"); synth.SetResult(typeof (NamedObject), value); AssertReturnsValue(synth, typeof (NamedObject), value); }
public SubSection(string name, NamedObject source = null, NamedObject target = null, string tsName = null, double maxFlow = 10000.0) { Name = name; Source = source; Target = target; TechnologicalSectionName = tsName; MaxFlows = maxFlow; }
static bool ExportRawFile(NamedObject obj, string exportPath) { var exportFullName = Path.Combine(exportPath, obj.m_Name + ".dat"); Directory.CreateDirectory(Path.GetDirectoryName(exportFullName)); File.WriteAllBytes(exportFullName, obj.GetRawData()); return(true); }
internal void SetNamedObject(string name, object value, bool fullyInitialized) { if (value == null) { throw new ArgumentNullException("value"); } objects [name] = new NamedObject(name, value, fullyInitialized); }
public void HasReadableDescription() { int index = 1; object value = new NamedObject("value"); var action = new SetIndexedParameterAction(index, value); AssertDescription.IsEqual(action, "set arg 1=<value>"); }
public void HasReadableDescription() { int index = 1; object value = new NamedObject("value"); SetIndexedParameterAction action = new SetIndexedParameterAction(index, value); AssertDescription.IsEqual(action, "set arg 1=<value>(NMockTests.NamedObject)"); }
public void HasReadableDescription() { string name = "param"; object value = new NamedObject("value"); var action = new SetNamedParameterAction(name, value); AssertDescription.IsEqual(action, "set param=<value>"); }
public void HasReadableDescription() { string name = "param"; object value = new NamedObject("value"); SetNamedParameterAction action = new SetNamedParameterAction(name, value); AssertDescription.IsEqual(action, "set param=<value>(NMockTests.NamedObject)"); }
public void CanSpecifyResultForOtherType() { var synth = new ResultSynthesizer(); var value = new NamedObject("value"); synth.SetResult(typeof(NamedObject), value); AssertReturnsValue(synth, typeof(NamedObject), value); }
public void TestThatNameTargetSetterThrowsArgumentNullExceptionIfValueIsNull() { var fixture = new Fixture(); var namedObject = new NamedObject(fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>()); Assert.That(namedObject, Is.Not.Null); Assert.Throws <ArgumentNullException>(() => namedObject.NameTarget = null); }
public void TestThatDescriptionSetterThrowsArgumentNullExceptionIfValueIsEmpty() { var fixture = new Fixture(); var namedObject = new NamedObject(fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>()); Assert.That(namedObject, Is.Not.Null); Assert.Throws <ArgumentNullException>(() => namedObject.Description = string.Empty); }
private static void TestNameOf() { NamedObject namedObject = new NamedObject("Nazwa"); string propertyName = namedObject.GetNameOf(x => x.Name); string propertyName2 = namedObject.Name.GetName(() => namedObject.Name); ConsoleUtils.WriteResult("Nazwa zmiennej Name z poziomu obiektu", propertyName); ConsoleUtils.WriteResult("Nazwa zmiennej Name bezpośrednio", propertyName2); }
public static object ResultOfAction(IAction action) { object receiver = new NamedObject("receiver"); MethodInfoStub methodInfo = new MethodInfoStub("method"); Invocation invocation = new Invocation(receiver, methodInfo, new object[0]); action.Invoke(invocation); return invocation.Result; }
public override bool Add(NamedObject ndo_obj) { bool success = base.Add(ndo_obj); if (true == success) { success = RecordHistory(ndo_obj, ActionType.Insert); } return(success); }
static bool ExportTextAsset(NamedObject obj, string exportPath) { var m_TextAsset = (TextAsset)(obj); string extension = ".txt"; var exportFullName = Path.Combine(exportPath, obj.m_Name + extension); Directory.CreateDirectory(Path.GetDirectoryName(exportFullName)); File.WriteAllBytes(exportFullName, m_TextAsset.m_Script); return(true); }
public override bool Equals(object obj) { NamedObject other = obj as NamedObject; if (other == null) { return(false); } return(StringComparer.Ordinal.Equals(Name, other.Name)); }
public static object ResultOfAction(IAction action) { object receiver = new NamedObject("receiver"); var methodInfo = new MethodInfoStub("method"); var invocation = new Invocation(receiver, methodInfo, new object[0]); action.Invoke(invocation); return invocation.Result; }
protected override bool Update(NamedObject ndo_changes, out NamedObject to_change) { bool success = base.Update(ndo_changes, out to_change); if (true == success) { success = RecordHistory(to_change, ActionType.Update); } return(success); }
public override bool Remove(NamedObject ndo_obj) { bool success = base.Remove(ndo_obj); if (true == success) { success = RecordHistory(ndo_obj, ActionType.Delete); } return(success); }
private void FetchUnitDataGUIBackgroundObject() { GUIUpdate guiUpdate = GlobalSingleton.GetGUIUpdateComponent() ; if( null == guiUpdate ) return ; if( true == m_IsMainCharacterUnitDataGUI ) m_UnitDataGUIBackgroundObject = guiUpdate.m_MainCharacterGUIBackground ; else m_UnitDataGUIBackgroundObject = guiUpdate.m_SelectTargetGUIBackground ; }
internal Size GetFoundation(NamedObject v) { if (_buildingTypes.HasObject(v)) { return(_buildingTypes.GetDrawable(v).Foundation); } else { return(_overlayTypes.GetDrawable(v).Foundation); } }
public void DoesNotMatchObjectIfPropertyMatcherDoesNotMatch() { var o = new ObjectWithProperties(); object aValue = new NamedObject("aValue"); object otherValue = new NamedObject("otherValue"); o.A = aValue; Matcher m = new PropertyMatcher("A", new SameMatcher(otherValue)); Assert.IsFalse(m.Matches(o), "should not match o"); }
public void MatchesObjectWithNamedPropertyAndMatchingPropertyValue() { ObjectWithProperties o = new ObjectWithProperties(); object aValue = new NamedObject("aValue"); o.A = aValue; Matcher m = new PropertyMatcher("A", Is.EqualTo(aValue)); Assert.IsTrue(m.Matches(o), "should match o"); }
public void Constructor2() { NamedObject namedObject = new NamedObject("Name"); MergeableNode<NamedObject> node = new MergeableNode<NamedObject>(namedObject); Assert.AreSame(namedObject, node.Content); Assert.IsNull(node.Parent); Assert.That(node.Children, Is.Null.Or.Empty); Assert.IsNull(node.Next); Assert.IsNull(node.Previous); Assert.That(node.MergePoints.Count(), Is.EqualTo(1)); Assert.That(node.MergePoints.First(), Is.EqualTo(new MergePoint(MergeOperation.Append, null))); }
public void GetRelativeNodeInGroup() { var namedObject = new NamedObject("Node"); var children = new[] { new MergeableNode<NamedObject>(new NamedObject("ChildA")), new MergeableNode<NamedObject>(new NamedObject("ChildB")), new MergeableNode<NamedObject>(new NamedObject("ChildC")), }; MergeableNode<NamedObject> node = new MergeableNode<NamedObject>(namedObject, children); Assert.IsNull(node.Children[0].Previous); Assert.AreSame(children[0], node.Children[1].Previous); Assert.AreSame(children[1], node.Children[2].Previous); Assert.AreSame(children[1], node.Children[0].Next); Assert.AreSame(children[2], node.Children[1].Next); Assert.IsNull(node.Children[2].Next); }
public void Constructor3() { var namedObject = new NamedObject("Node"); var children = new[] { new MergeableNode<NamedObject>(new NamedObject("ChildA")), new MergeableNode<NamedObject>(new NamedObject("ChildB")), new MergeableNode<NamedObject>(new NamedObject("ChildC")), }; MergeableNode<NamedObject> node = new MergeableNode<NamedObject>(namedObject, children); Assert.AreSame(namedObject, node.Content); Assert.IsNull(node.Parent); Assert.IsNotNull(node.Children); Assert.AreEqual(3, node.Children.Count); Assert.AreSame(children[0], node.Children[0]); Assert.AreSame(children[1], node.Children[1]); Assert.AreSame(children[2], node.Children[2]); Assert.IsNull(node.Next); Assert.IsNull(node.Previous); Assert.That(node.MergePoints.Count(), Is.EqualTo(1)); Assert.That(node.MergePoints.First(), Is.EqualTo(new MergePoint(MergeOperation.Append, null))); }
// 發射武器 protected override void FireWeapon( UnitWeaponSystem _weaponSys , NamedObject _TargetObject ) { string weaponComponent = "" ; // check phaser weaponComponent = _weaponSys.FindAbleWeaponComponent( RandomAWeaponKeyword() , _TargetObject.Name ) ; if( 0 == weaponComponent.Length ) { // no available weapon this.SetState( AI_Fire_State.MoveToTarget ) ; return ; } // fire if( true == _weaponSys.ActiveWeapon( weaponComponent , _TargetObject , ConstName.UnitDataComponentUnitIntagraty ) ) { this.SetState( AI_Fire_State.WaitForReload ) ; } }
internal void SetNamedObject (string name, object value, bool fullyInitialized) { if (value == null) throw new ArgumentNullException ("value"); objects [name] = new NamedObject (name, value, fullyInitialized); }
public NamedObject( NamedObject _src ) { m_Name = _src.m_Name ; m_GameObject = _src.m_GameObject ; }
private void SetupShuffleSpawnPosEvent() { #if DEBUG Debug.Log( "SetupShuffleSpawnPosEvent()" ) ; #endif for( int i = 0 ; i < 9 ; ++i ) { if( 4 == i ) continue ; string Key = string.Format( "SpawnPosition{0:00}" , i ) ; NamedObject spawnObj = new NamedObject( Key ) ; m_SpawnPosition.Add( spawnObj.Obj ) ; } }
private void SpawnBossDoEvent() { EnemyGenerator enemyGenerator = GlobalSingleton.GetEnemyGeneratorComponent() ; if( null == enemyGenerator ) return ; #if DEBUG Debug.Log( "SpawnBossDoEvent()" ) ; #endif UnitGenerationData addGenData = ChooseBySequence( m_BossTemplates ) ; addGenData.unitName = addGenData.unitName + ConstName.GenerateIterateString() ; addGenData.time = Time.timeSinceLevelLoad ; if( 0 < m_SpawnPosition.Count ) { int index = Random.Range( 0 , m_SpawnPosition.Count ) ; addGenData.initPosition.Setup( m_SpawnPosition[ index ].transform.position ) ; addGenData.initOrientation = m_SpawnPosition[ index ].transform.rotation ; #if DEBUG Debug.Log( m_SpawnPosition[ index ].name + " " + addGenData.initPosition ) ; #endif // 計算destination (相對面的spawnposition) index = m_SpawnPosition.Count - index - 1 ; m_BossDestination = new NamedObject( m_SpawnPosition[ index ] ) ; #if DEBUG Debug.Log( m_SpawnPosition[ index ].name + " " + m_BossDestination ) ; #endif Vector3 pos = m_BossDestination.Obj.transform.position ; addGenData.supplementalVec[ "RoutePosition0" ] = string.Format( "{0},{1},{2}" , pos.x , pos.y , pos.z ) ; } m_BossNow = new UnitObject( addGenData.unitName ) ; enemyGenerator.InsertEnemyGenerationTable( addGenData ) ; m_BossIsAlive = true ; PlayeAudio() ; }
public void SetUp() { arg = new NamedObject("arg"); stringMatcher = new MockMatcher(); matcher = new ToStringMatcher(stringMatcher); }
private void ShowBattleScore( bool _IsWin ) { BattleScoreManager manager = GlobalSingleton.GetBattleScoreManager() ; if( null != manager ) { manager.AddScore( ScoreType.ElapsedSec , Time.timeSinceLevelLoad ) ; manager.Active() ; } NamedObject battleScoreParentObj = new NamedObject( "GUI_BattleScore" ) ; if( null == battleScoreParentObj ) return ; ShowGUITexture.Show( battleScoreParentObj.Obj , true , true , true ) ; if( true == _IsWin ) { // 關閉 lose gui object ShowGUITexture.Show( "MessageCard_Lose" , false , true , true ) ; ShowGUITexture.Show( "MessageCard_End" , false , true , true ) ; } else { // 關閉 win gui object ShowGUITexture.Show( "MessageCard_Win" , false , true , true ) ; ShowGUITexture.Show( "Seven and the Doctor sing Klingon War Song Object" , false , true , true ) ; if( true == m_RealLose ) ShowGUITexture.Show( "MessageCard_End" , false , true , true ) ; else ShowGUITexture.Show( "MessageCard_Lose" , false , true , true ) ; } }
public void SetUp() { receiver = new NamedObject("receiver"); identityProvider = new NamedObject("identityProvider"); next = new MockInvokable(); id = new ProxiedObjectIdentity(identityProvider, next); }
private void TryActiveBattleEventCamera( GameObject _TargetObj ) { BattleEventCameraManager battleEventManager = GlobalSingleton.GetBattleEventCameraManager() ; GameObject mainChar = GlobalSingleton.GetMainCharacterObj() ; if( null != _TargetObj && null != mainChar && null != battleEventManager && false == battleEventManager.IsActive() ) { if( true == MathmaticFunc.IsInScreen( _TargetObj ) ) return ; Vector3 distVec = _TargetObj.transform.position - mainChar.transform.position ; int viewportindex = 0 ; if( Mathf.Abs( distVec.z ) >= Mathf.Abs( distVec.x ) ) { if( distVec.z >= 0 ) { viewportindex = 0 ; } else if( distVec.z < 0 ) { viewportindex = 1 ; } } else { if( distVec.x >= 0 ) { viewportindex = 3 ; } else if( distVec.x < 0 ) { viewportindex = 2 ; } } NamedObject obj = new NamedObject( _TargetObj ) ; battleEventManager.SetupByTime( obj , viewportindex , BaseDefine.BATTLE_EVENT_CAMERA_ELAPSED_SEC ) ; } }
public void GetFieldWithOutAttributes() { NamedObject n = new NamedObject(); FieldInfoCollection fi = ReflectionUtil.GetFieldsWithOutAttributes(n.GetType(), typeof(XmlElementAttribute), typeof(XmlIgnoreAttribute)); Assert.AreEqual(0, fi.Count, "Get fields without attributes found attributes even though they are marked!"); fi = ReflectionUtil.GetFieldsWithOutAttributes(n.GetType(), typeof(AssemblyFlagsAttribute), typeof(AssemblyKeyNameAttribute)); Assert.AreEqual(2, fi.Count, "Getfields without attributes didn't find all the fields, even though they are marked with other attribute"); fi = ReflectionUtil.GetFieldsWithOutAttributes(n.GetType(), typeof(XmlIgnoreAttribute)); Assert.AreEqual(1, fi.Count, "GetFields without attributes didn't filter correctly"); }
public void ImplementsEqualsByComparingInvocationReceiversForIdentity() { next.ExpectNotCalled(); var equalInvocation = new Invocation(receiver, EQUALS_METHOD, new[] {receiver}); id.Invoke(equalInvocation); Assert.IsTrue((bool) equalInvocation.Result, "should have returned true"); object other = new NamedObject("other"); var notEqualInvocation = new Invocation(receiver, EQUALS_METHOD, new[] {other}); id.Invoke(notEqualInvocation); Assert.IsFalse((bool) notEqualInvocation.Result, "should not have returned true"); }
public void MatchesObjectWithNamedPropertyAndMatchingPropertyValue() { var o = new ObjectWithProperties(); object aValue = new NamedObject("aValue"); o.A = aValue; Matcher m = new PropertyMatcher("A", Is.Same(aValue)); Assert.IsTrue(m.Matches(o), "should match o"); }
public void SetName() { NamedObject n = new NamedObject(); ReflectionUtil.SetName(n, "New Name"); Assert.AreEqual("New Name", n.name, "Can't set the name when it's a field"); TestForReflection t = new TestForReflection(); ReflectionUtil.SetName(t, "New Name (2)"); Assert.AreEqual("New Name (2)", t.Name, "Can't set the name when it's a property"); //This to check that we don't have an exception on fields without names ReflectionUtil.SetName(new object(), "object's name"); }
public NamedObjectPair( NamedObject _UnitObj , NamedObject _MiniMapObj ) { UnitObj = _UnitObj ; MiniMapObj = _MiniMapObj ; }
private string FindMostCloestWeaponComponent( UnitData _unitData , UnitWeaponSystem _weaponSys , NamedObject _possibleUnit , List<string> _possibleWeaponList , ref Dictionary<string , SelectInformation> _fireList ) { string ret = "" ; Dictionary<string,float> angleMap = new Dictionary<string, float>() ; foreach( string weaponComponentName in _possibleWeaponList ) { // Debug.Log( "weaponComponentName=" + weaponComponentName ) ; if( false == _weaponSys.m_WeaponDataMap.ContainsKey( weaponComponentName ) ) { continue ; } // no trackor beam if( -1 != weaponComponentName.IndexOf( ConstName.UnitDataComponentWeaponTrackorBeamPrefix ) ) { continue ; } if( true == _fireList.ContainsKey( weaponComponentName ) ) { // 如果已經用掉了就跳過不作 continue ; } if( 0 != ( _weaponSys.FindAbleWeaponComponent( weaponComponentName , _possibleUnit.Obj ) ).Length ) { WeaponDataSet weapenDataSet = _weaponSys.m_WeaponDataMap[ weaponComponentName ] ; Vector3 toTargetVec = _possibleUnit.Obj.transform.position - this.gameObject.transform.position ; Vector3 toComponentVec = weapenDataSet.Component3DObject.transform.position - this.gameObject.transform.position ; float angle = Vector3.Angle( toComponentVec , toTargetVec ) ; angleMap[ weaponComponentName ] = angle ; // Debug.Log( "toComponentVec=" + toComponentVec ) ; // Debug.Log( "toTargetVec=" + toTargetVec ) ; // Debug.Log( "angleMap[ weaponComponentName ]=" + angle ) ; } } // 尋找angle值最小的 float angleMin = 361.0f ; Dictionary<string,float>.Enumerator e = angleMap.GetEnumerator() ; while( e.MoveNext() ) { if( e.Current.Value < angleMin ) { angleMin = e.Current.Value ; ret = e.Current.Key ; } } // Debug.Log( "FindMostCloestWeaponComponent() ret=" + ret ) ; return ret ; }
public SelectInformation( SelectInformation _src ) { isValid = _src.isValid ; clickActiveTime = _src.clickActiveTime ; screenPosition = _src.screenPosition ; m_TargetComponentName = _src.m_TargetComponentName ; m_TargetUnit = new NamedObject( _src.m_TargetUnit ) ; }
// 發射武器 public bool ActiveWeapon( string _WeaponComponentName , NamedObject _TargetUnit , string _TargetComponentName ) { /* Debug.Log( "ActiveWeapon()" + this.gameObject.name + " " + _WeaponComponentName + " " + _TargetUnit.Name + " "+ _TargetComponentName ) ; //*/ SystemLogManager.AddLog( SystemLogManager.SysLogType.FireWeapon , this.gameObject.name + ":" + _WeaponComponentName + ":" + _TargetUnit.Name + ":" + _TargetComponentName ) ; // get weapon data UnitData unitData = this.gameObject.GetComponent<UnitData>() ; if( null == unitData ) { Debug.Log( "ActiveWeapon() null == unitData" ) ; return false ; } if( false == unitData.componentMap.ContainsKey( _WeaponComponentName ) ) { Debug.Log( "ActiveWeapon() no such component:" + _WeaponComponentName + ".") ; return false ; } UnitComponentData weaponComponent = unitData.componentMap[ _WeaponComponentName ] ; WeaponDataSet weaponSet = null ; if( false == this.m_WeaponDataMap.ContainsKey( _WeaponComponentName ) ) { Debug.Log( "false == this.m_WeaponDataMap.ContainsKey( _WeaponComponentName ):" + _WeaponComponentName ) ; return false ; } weaponSet = this.m_WeaponDataMap[ _WeaponComponentName ] ; WeaponParam weaponParam = weaponComponent.m_WeaponParam ; // weapon data float weapenDamage = weaponComponent.TotalEffect() ; // Debug.Log( "weapenDamage" + weapenDamage ) ; float weapenAccuracy = weaponParam.m_Accuracy ;// 0~1 // Debug.Log( "weapenAccuracy" + weapenAccuracy ) ; float weaponMissRage = 1.0f - weapenAccuracy ; float sceneMaximumMissDistance = 1.0f ; // check able to fire if( WeaponFireState.Ready != weaponSet.m_FireState ) { // Debug.Log( "WeaponFireState.Ready != weaponSet.m_FireState" ) ; return false ; } // get Target Unit Object : the unit contains data. if( null == _TargetUnit.Obj ) { Debug.Log( "null == weaponSet.TargetUnitObject" ) ; return false ; } // find out hit component name UnitDamageSystem unitDamageSys = _TargetUnit.Obj.GetComponent< UnitDamageSystem >() ; if( null == unitDamageSys ) { Debug.Log( "ActiveWeapon() : null == unitDamageSys" ) ; return false ; } // 取得被擊中的部件 string realUnitName = "" ; string realComponentObjectName = "" ; if( false == unitDamageSys.RetrieveRealTargetComponent( this.gameObject , _TargetComponentName , ref realUnitName , ref realComponentObjectName ) ) { Debug.Log( "unitDamageSys.RetrieveRealTargetComponent fail" ) ; return false ; } if( _TargetUnit.Name != realUnitName ) { NamedObject unit = new NamedObject( realUnitName ) ; unitDamageSys = unit.Obj.GetComponent< UnitDamageSystem >() ; if( null == unitDamageSys ) { Debug.Log( "ActiveWeapon() : null == unitDamageSys realUnitName=" + realUnitName ) ; return false ; } } weaponSet.SetupTarget( realUnitName , realComponentObjectName ) ; // true Hit Component Object , it may the same with target unit object. // Debug.Log( "weaponSet.TargetUnitName=" + weaponSet.TargetUnitName ) ; // Debug.Log( "weaponSet.TargetComponentObjectName=" + weaponSet.TargetComponentObjectName ) ; unitDamageSys = weaponSet.TargetUnitObject.GetComponent< UnitDamageSystem >() ; if( null == unitDamageSys ) { // Debug.Log( "ActiveWeapon() : null == unitDamageSys" ) ; return false ; } // Debug.Log( "ActiveWeapon() TargetComponentName" + realTargetComponentName ) ; // create corresponding weapong effect object if( null == weaponSet.Effect3DObject ) { Debug.Log( "null == weaponSet.Effect3DObject:" + weaponSet.Effect3DObjectName ) ; return false ; } float damageCause = 0.0f ; // calculate displacement { int randomMax = 100 ; int randomValue = Random.Range( 0 , randomMax ) ; int halfRandomValue = randomMax / 2 ; float randomRatio = (randomMax - randomValue) / (float) randomMax ; damageCause = weapenDamage * ( weapenAccuracy + randomRatio * weaponMissRage ) ; float halfValue = (float)( randomValue - halfRandomValue ) / (float) ( randomMax ); float randomDisplacement = 0.0f ; randomDisplacement = sceneMaximumMissDistance * halfValue ; float positiveInX = 1.0f; if( 1 == Random.Range( 0 , 1 ) ) positiveInX = -1.0f ; float positiveInZ = 1.0f; if( 1 == Random.Range( 0 , 1 ) ) positiveInZ = -1.0f ; weaponSet.m_Displacement = new Vector3( randomDisplacement * positiveInX , 0 , randomDisplacement * positiveInZ ) ; } weaponSet.m_CauseDamage = damageCause ; if( weaponSet.m_WeaponType == WeaponType.Phaser ) { weaponSet.m_FireTotalTime = 2.1f ;// 造成兩次觸發 weaponSet.m_FireStartTime = Time.time ; WeaponPhaserEffect phaserEffect = weaponSet.Effect3DObject.GetComponent< WeaponPhaserEffect >() ; if( null != phaserEffect ) { phaserEffect.Setup( weaponSet ) ; } // cause damage effect imidiatly if( null != unitDamageSys ) { string damageEffectName = unitDamageSys.ActiveDamageEffect( this.gameObject , weaponSet.TargetComponentObjectName ) ; if( 0 != damageEffectName.Length ) { RelativeDamageEffect relativeDamageEffect = new RelativeDamageEffect() ; relativeDamageEffect.m_TargetUnit = weaponSet.TargetUnitObject ; relativeDamageEffect.m_DamageEffectName = damageEffectName ; weaponSet.m_RelativeDamageEffectNames.Add( relativeDamageEffect ) ; } } } else if( weaponSet.m_WeaponType == WeaponType.TrakorBeam ) { WeaponTrackorBeamEffect trackorBeamEffect = weaponSet.Effect3DObject.GetComponent< WeaponTrackorBeamEffect >() ; if( null != trackorBeamEffect ) { weaponSet.m_CauseDamage = weaponComponent.TotalEffect() ; trackorBeamEffect.Setup( weaponSet ) ; } weaponSet.m_FireTotalTime = 999.0f ; weaponSet.m_FireStartTime = Time.time ; } else if( weaponSet.m_WeaponType == WeaponType.Torpedo ) { weaponSet.Effect3DObject.transform.position = weaponSet.Component3DObject.transform.position ; weaponSet.m_TargetDirection = weaponSet.TargetComponentObject.transform.position - weaponSet.Effect3DObject.transform.position ; weaponSet.m_TargetDirection.Normalize() ; WeaponPhotonTorpedoEffect torpedoEffect = weaponSet.Effect3DObject.GetComponent< WeaponPhotonTorpedoEffect >() ; if( null != torpedoEffect ) { torpedoEffect.Setup( weaponSet ) ; } weaponSet.m_FireTotalTime = 10.0f ; weaponSet.m_FireStartTime = Time.time ; } else if( weaponSet.m_WeaponType == WeaponType.Cannon ) { weaponSet.Effect3DObject.transform.position = weaponSet.Component3DObject.transform.position ; weaponSet.m_TargetDirection = weaponSet.TargetComponentObject.transform.position - weaponSet.Effect3DObject.transform.position ; weaponSet.m_TargetDirection.Normalize() ; WeaponCannonEffect cannonEffect = weaponSet.Effect3DObject.GetComponent< WeaponCannonEffect >() ; if( null != cannonEffect ) { cannonEffect.Setup( weaponSet ) ; } weaponSet.m_FireTotalTime = 10.0f ; weaponSet.m_FireStartTime = Time.time ; } else { Debug.Log( "weaponSet.m_WeaponType=" + weaponSet.m_WeaponType ) ; } ActiveEffect( weaponSet ) ; weaponSet.m_FireState = WeaponFireState.FireAnimating ; // weapn fire, clear the reload energy weaponComponent.m_ReloadEnergy.Clear() ; return true ; }
public void AddObject( NamedObject _Obj ) { m_Objects.Add( _Obj ) ; }