public void When_type_is_not_null_returns_its_full_name()
            {
                Type exampleType = typeof(ClassExample);
                var  typeRef     = new ClassTypeReference(exampleType);

                Assert.That(typeRef.ToString(), Is.EqualTo(exampleType.FullName));
            }
            public void When_a_class_type_is_passed_creates_instance_with_this_type()
            {
                var classType = typeof(ClassExample);
                var typeRef   = new ClassTypeReference(classType);

                Assert.That(typeRef.Type, Is.EqualTo(classType));
            }
            public void Type_can_be_converted_to_ClassTypeReference()
            {
                Type classType             = typeof(ClassExample);
                ClassTypeReference typeRef = classType;

                Assert.That(typeRef.Type, Is.EqualTo(classType));
            }
            public void When_not_assembly_qualified_name_string_is_passed_creates_instance_with_null_type()
            {
                string typeName = "wrongTypeName";
                var    typeRef  = new ClassTypeReference(typeName);

                Assert.That(typeRef.Type, Is.Null);
            }
    public void CreateTeamAIFactory(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        if (!m_SetupDone)
        {
            return;
        }

        if (i_TeamIndex < 0 || i_TeamIndex >= m_AIFactories.Length || i_TeamIndex >= m_TeamSizes.Length)
        {
            return;
        }

        if (i_TeamDescription == null)
        {
            return;
        }

        ClassTypeReference newAIFactoryType = (i_TeamIndex % 2 == 0) ? m_EvenTeamAIFactoryType : m_OddTeamAIFactoryType;

        tnBaseSubbuteoMatchAIFactory newAIFactory = CSharpUtils.Cast <tnBaseSubbuteoMatchAIFactory>(Activator.CreateInstance(newAIFactoryType));

        if (newAIFactory != null)
        {
            newAIFactory.Configure(i_TeamDescription);
        }

        m_AIFactories[i_TeamIndex] = newAIFactory;
        m_TeamSizes[i_TeamIndex]   = i_TeamDescription.charactersCount;
    }
            public void When_type_full_name_is_null_returns_empty_string()
            {
                var genericType = typeof(GenericClass <>)
                                  .GetGenericArguments()
                                  .First();

                Assert.That(ClassTypeReference.GetClassGUID(genericType), Is.EqualTo(string.Empty));
            }
            public void ClassTypeReference_can_be_converted_to_Type()
            {
                Type initialType   = typeof(ClassExample);
                var  typeRef       = new ClassTypeReference(initialType);
                Type convertedType = typeRef;

                Assert.That(convertedType, Is.EqualTo(initialType));
            }
            public void When_assembly_qualified_class_name_string_is_passed_creates_instance_with_this_type()
            {
                Type   classType = typeof(ClassExample);
                string typeName  = classType.AssemblyQualifiedName;
                var    typeRef   = new ClassTypeReference(typeName);

                Assert.That(typeRef.Type, Is.EqualTo(classType));
            }
            public void When_type_is_passed_returns_string_that_contains_full_type_name_and_assembly_name()
            {
                var    exampleType     = typeof(ClassExample);
                string typeAndAssembly = ClassTypeReference.GetTypeNameAndAssembly(exampleType);

                Assert.That(typeAndAssembly.Contains(exampleType.FullName));
                Assert.That(typeAndAssembly.Contains(exampleType.Assembly.GetName().Name));
            }
            public void When_not_a_class_type_is_passed_throws_ArgumentException()
            {
                var notAClassType = typeof(NotAClass);

                Assert.Throws <ArgumentException>(() =>
                {
                    var typeRef = new ClassTypeReference(notAClassType);
                });
            }
        private static void OnSelectedTypeName(object userData)
        {
            var selectedType = userData as Type;

            SelectedTypeNameAndAssembly = ClassTypeReference.GetTypeNameAndAssembly(selectedType);
            Event typeReferenceUpdated = EditorGUIUtility.CommandEvent(ReferenceUpdatedCommandName);

            EditorWindow.focusedWindow.SendEvent(typeReferenceUpdated);
        }
示例#12
0
        /// <summary>
        /// Called when [selected type name].
        /// </summary>
        /// <param name="userData">The user data.</param>
        private static void OnSelectedTypeName(object userData)
        {
            var selectedType = userData as Type;

            s_SelectedClassRef = ClassTypeReference.GetClassRef(selectedType);
            var typeReferenceUpdatedEvent = EditorGUIUtility.CommandEvent("TypeReferenceUpdated");

            EditorWindow.focusedWindow.SendEvent(typeReferenceUpdatedEvent);
        }
            public void When_assembly_qualified_struct_name_string_is_passed_throws_ArgumentException()
            {
                Type   classType = typeof(NotAClass);
                string typeName  = classType.AssemblyQualifiedName;

                Assert.Throws <ArgumentException>(() =>
                {
                    var typeRef = new ClassTypeReference(typeName);
                });
            }
示例#14
0
 void OnEnable()
 {
     Window       = this;
     DatabasePath = EditorPrefs.GetString(databasePathKey, Application.dataPath);
     LoadDatabaseFromPath(DatabasePath);
     _databaseType = new ClassTypeReference(EditorPrefs.GetString(databaseTypeKey));
     if (_databaseType.Type == null)
     {
         _databaseType = typeof(DefaultLSDatabase);
     }
 }
示例#15
0
 void OnEnable()
 {
     Window = this;
     this.LoadDatabase(LSFSettingsManager.GetSettings().Database);
     if (this.Database != null)
     {
         _databaseType = LSFSettingsManager.GetSettings().Database.GetType();
         if (_databaseType.Type == null)
         {
             _databaseType = typeof(DefaultLSDatabase);
         }
     }
 }
示例#16
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        Rect main = new Rect(position.x, position.y, position.width, position.height);


        ClassTypeParentAttribute attr = null;

        object[] attributes = fieldInfo.GetCustomAttributes(typeof(ClassTypeParentAttribute), false);
        if (attributes.Length > 0)
        {
            attr = (ClassTypeParentAttribute)attributes.First();

            List <Type> types = new List <Type>();
            PopulateEntries(attr);
            int index = GetIndexOfType(property);

            int newIndex = EditorGUI.Popup(main, index, entries.ToArray());

            if (index != newIndex)
            {
                Type t = tEntries[newIndex];
                property.FindPropertyRelative("_classRef").stringValue = ClassTypeReference.GetClassRef(t);
            }
        }
        else
        {
            EditorGUI.LabelField(main, "Please use ClassTypeParentAttribute");
        }



        // Set indent back to what it was
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }
        private string GetTestReferencePropertyPath(ClassTypeReference testReference)
        {
            return(string.Format("TestGroups.Array.data[{0}].Tests.Array.data[{1}].TestReference", GroupIndex, ListIndex));

            /*
             *
             * TestSuiteConfig config = (TestSuiteConfig)target;
             * for (int i = 0; i < config.TestGroups.Count; i++) {
             *  var groups = config.TestGroups[i];
             *
             *  for (int j = 0; j < groups.Tests.Count; j++) {
             *      var testRef = groups.Tests[j];
             *      Debug.Log(testReference.GetHashCode() + " / " + testRef.GetHashCode());
             *      if (testRef.Equals(testReference)) {
             *         string path = string.Format("TestGroups.Array.data[{0}].Tests.Array.data[{1}].TestReference", i, j);
             *         return path;
             *      }
             *  }
             * }
             *
             * return string.Empty;*/
        }
示例#18
0
    public void EmitParticles(ClassTypeReference skillUsed)
    {
        ParticleSystem particleSystem = GetComponent <ParticleSystem>();

        ParticleSystem.ShapeModule shape = particleSystem.shape;
        ParticleSystem.VelocityOverLifetimeModule velocity = particleSystem.velocityOverLifetime;
        Vector3 curRot = shape.rotation;

        if (velocity.enabled == false)
        {
            velocity.enabled = true;
        }

        if (skillUsed.Type == typeof(AttackLeft))
        {
            shape.rotation = new Vector3((int)Direction.LEFT, curRot.y, curRot.z);
        }

        else if (skillUsed.Type == typeof(AttackRight))
        {
            shape.rotation = new Vector3((int)Direction.RIGHT, curRot.y, curRot.z);
        }

        else if (skillUsed.Type == typeof(AttackUp))
        {
            shape.rotation = new Vector3((int)Direction.UP, curRot.y, curRot.z);
        }

        else if (skillUsed.Type == typeof(AttackDown))
        {
            shape.rotation   = new Vector3((int)Direction.DOWN, curRot.y, curRot.z);
            velocity.enabled = false;
        }


        particleSystem.Play();
    }
        private ReorderableList GetList(SerializedProperty aProperty)
        {
            if (_list == null)
            {
                var nullGUIContent = new GUIContent();
                var listProperty   = aProperty.FindPropertyRelative(LIST_PROPERTY_NAME);
                _list = new ReorderableList(aProperty.serializedObject, listProperty);

                _list.drawHeaderCallback = ( Rect aRect ) => { EditorGUI.LabelField(aRect, "条件定义"); };

                _list.onSelectCallback = ( ReorderableList list ) => {
                    AIScenarioConditionItem item = (AIScenarioConditionItem)listProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative(TYPE_PROPERTY).GetValue();
                    ClassTypeReference      type = item.type;

                    if (type == null || type.Type == null)
                    {
                        _currentEditType     = null;
                        _currentEditInstance = null;
                        return;
                    }

                    if (true)
                    {
                        bool   needCreateInstance = false;
                        object instance           = item.typeInstance;

                        if (instance == null)
                        {
                            needCreateInstance = true;
                        }
                        else
                        {
                            if (instance.GetType() != type.Type)
                            {
                                needCreateInstance = true;
                            }
                        }

                        if (needCreateInstance)
                        {
//							instance = type.Type.Assembly.CreateInstance ( type.Type.ToString () );
                            item.typeInstance = item.Load();
                            item.publicFields = type.Type.GetFields(BindingFlags.Instance | BindingFlags.Public);
                        }

                        _currentEditType     = type.Type;
                        _currentEditInstance = item;
                    }
                };

                _list.onReorderCallbackWithDetails = (ReorderableList list, int oldIndex, int newIndex) => {
                    // bug ref issus
                    object temp   = _self.conditions.list[oldIndex].typeInstance;
                    var    temp_2 = _self.conditions.list[oldIndex].publicFields;
                    _self.conditions.list[oldIndex].typeInstance = _self.conditions.list[newIndex].typeInstance;
                    _self.conditions.list[oldIndex].publicFields = _self.conditions.list[newIndex].publicFields;
                    _self.conditions.list[newIndex].typeInstance = temp;
                    _self.conditions.list[newIndex].publicFields = temp_2;
//					Debug.Log ( $"onReorderCallbackWithDetails old[{oldIndex}]:{_self.conditions.list[ oldIndex ].typeInstance.GetHashCode()} new[{newIndex}]:{_self.conditions.list[ newIndex ].typeInstance.GetHashCode()}" );
                };

                _list.onRemoveCallback = ( ReorderableList list ) => {
//					int id = 0;
//					AIScenarioCondition cond = (AIScenarioCondition)listProperty.GetValue ();
//					foreach ( var item in cond.list ) {
//						item.id = id++;
//					}
//
//					cond.serialId = id;

//					List<int> indexToRemove = new List< int >();
//					List<AIScenarioItem> items = new List< AIScenarioItem >();
//
//					for ( var i = 0; i < _self.actions.Length; ++i ) {
//
//						var action = _self.actions[ i ];
//						var pre = serializedObject.FindProperty ( "actions" ).GetArrayElementAtIndex ( i )
//						                          .FindPropertyRelative ( PRE_PROPERTY );
//						var post = serializedObject.FindProperty ( "actions" ).GetArrayElementAtIndex ( i )
//						                          .FindPropertyRelative ( POST_PROPERTY );
//
//						foreach ( var condition in action.pre ) {
//							if ( !_self.conditions.Has ( condition.id ) ) {
//								indexToRemove.Add ( Array.IndexOf ( action.pre, condition ) );
//							}
//						}
//						foreach ( var index in indexToRemove ) {
//							pre.DeleteArrayElementAtIndex ( index );
//						}
//						indexToRemove.Clear ();
//
//						foreach ( var condition in action.post ) {
//							if ( !_self.conditions.Has ( condition.id ) ) {
//								indexToRemove.Add ( Array.IndexOf ( action.post, condition ) );
//							}
//						}
//						foreach ( var index in indexToRemove ) {
//							post.DeleteArrayElementAtIndex ( index );
//						}
//						indexToRemove.Clear ();
//					}
//
//					for ( var i = 0; i < _self.goals.Length; ++i ) {
//
//						var conds = serializedObject.FindProperty ( "goals" ).GetArrayElementAtIndex ( i )
//						                          .FindPropertyRelative ( CONDS_PROPERTY );
//
//						foreach ( var condition in _self.goals[ i ].conditions ) {
//							if ( !_self.conditions.Has ( condition.id ) ) {
//								indexToRemove.Add ( Array.IndexOf ( _self.goals[ i ].conditions, condition ) );
//							}
//						}
//						foreach ( var index in indexToRemove ) {
//							conds.DeleteArrayElementAtIndex ( index );
//						}
//						indexToRemove.Clear ();
//					}
//
//					indexToRemove.Clear ();
//					items.Clear ();

                    var conditions = aProperty.FindPropertyRelative(LIST_PROPERTY_NAME);
                    conditions.DeleteArrayElementAtIndex(list.index);
                };

                _list.drawElementCallback = (Rect aRect, int aIndex, bool aIsActive, bool aIsFocused) => {
                    aRect.y += FIELD_PADDING;
                    string name = listProperty.GetArrayElementAtIndex(aIndex).FindPropertyRelative(NAME_PROPERTY).stringValue;
                    Rect   r    = new Rect(aRect.x, aRect.y, aRect.width * 0.35f, EditorGUIUtility.singleLineHeight);
                    listProperty.GetArrayElementAtIndex(aIndex).FindPropertyRelative(NAME_PROPERTY).stringValue = EditorGUI.TextField(r, name);

                    r.x    += aRect.width * 0.35f;
                    r.width = aRect.width * 0.65f;
                    EditorGUI.PropertyField(r, listProperty.GetArrayElementAtIndex(aIndex).FindPropertyRelative(TYPE_PROPERTY), nullGUIContent);
                };

                _list.onAddCallback = ( ReorderableList aList ) => {
                    var conditions = aProperty.FindPropertyRelative(LIST_PROPERTY_NAME);
//					int id         = aProperty.FindPropertyRelative ( SERIAL_ID_PROPERTY ).intValue;
//					aProperty.FindPropertyRelative ( SERIAL_ID_PROPERTY ).intValue = ++id;

                    int length = conditions.arraySize;
                    conditions.InsertArrayElementAtIndex(length);
                    conditions.GetArrayElementAtIndex(length).FindPropertyRelative(ID_PROPERTY).intValue      = conditions.GetArrayElementAtIndex(length).GetHashCode();
                    conditions.GetArrayElementAtIndex(length).FindPropertyRelative(NAME_PROPERTY).stringValue = "<Unnamed>";

//					Array.Resize ( ref _self.conditions.list, _self.conditions.list.Length + 1 );
//
//					_self.conditions.list[ _self.conditions.list.Length - 1 ] = new AIScenarioConditionItem ();
//
//					if ( _self.conditions.list.Length > 1 ) {
//						var up = _self.conditions.list[ _self.conditions.list.Length - 2 ];
//						_self.conditions.list[ _self.conditions.list.Length - 1 ] = new AIScenarioConditionItem ();
//						_self.conditions.list[ _self.conditions.list.Length - 1 ].id = _self.conditions.list[ _self.conditions.list.Length - 1 ].GetHashCode ();
//						_self.conditions.list[ _self.conditions.list.Length - 1 ].name = "<Unnamed>";
//						_self.conditions.list[ _self.conditions.list.Length - 1 ].type = up.type != null ? new ClassTypeReference ( up.type.Type ) : null;
//					}
                };
            }

            return(_list);
        }
 protected override sealed void OnInject(object[] data)
 {
     Type type = (Type)data[0];
     _script = type;
     this._name = type.Name;
 }
            public void When_empty_string_is_passed_creates_instance_with_null_type()
            {
                var typeRef = new ClassTypeReference(string.Empty);

                Assert.That(typeRef.Type, Is.Null);
            }
 public void BeforeEveryTest()
 {
     _typeRef = new ClassTypeReference();
 }
            public void When_null_type_is_passed_creates_instance_with_null_type()
            {
                var typeRef = new ClassTypeReference((Type)null);

                Assert.That(typeRef.Type, Is.Null);
            }
            public void When_no_arguments_are_passed_creates_instance_with_null_type()
            {
                var typeRef = new ClassTypeReference();

                Assert.That(typeRef.Type, Is.Null);
            }
            public void When_type_is_null_returns_NoneElement()
            {
                var nullTypeRef = new ClassTypeReference((Type)null);

                Assert.That(nullTypeRef.ToString(), Is.EqualTo(ClassTypeReference.NoneElement));
            }
            public void When_null_is_passed_returns_empty_string()
            {
                string typeAndAssembly = ClassTypeReference.GetTypeNameAndAssembly(null);

                Assert.That(typeAndAssembly, Is.EqualTo(string.Empty));
            }
        // Update is called once per frame
        private void Update()
        {
            ++_frames;
            float timeNow = Time.realtimeSinceStartup;

            if (Context.IsReady)
            {
                if (timeNow > _lastInterval + UpdateInterval)
                {
                    _fps            = (float)(_frames / (timeNow - _lastInterval));
                    _frames         = 0;
                    _lastInterval   = timeNow;
                    AverageFps.text = '\u00D8' + " FPS: " + _fps;
                    Debug.Log('\u00D8' + " FPS: " + _fps);
                }
                Context.CollisionTextureRenderer.UpdateDepthTexture();
                Context.WindManager.Update();
                //Context.ProceduralWind.Update();
                //Context.WindFieldRenderer.Update();
                Context.PatchContainer.Draw();
                //Context.BillboardTexturePatchContainer.Draw();
            }

            for (int i = 0; i < _switchSimulationTexture.Length; i++)
            {
                if (Input.GetKeyDown(_switchSimulationTexture[i]))
                {
                    _simulationTextureResolution = (int)Mathf.Pow(2, 3 + i);
                    UpdateDebugInfo("Set SimulationTexture Resolution to " + _simulationTextureResolution);
                }
            }

            for (int i = 0; i < _testSettings.Length; i++)
            {
                if (Input.GetKeyDown(_testSettings[i]))
                {
                    LoadTestSettings(i);
                }
            }

            if (Input.GetKeyDown(_printDebugInfo))
            {
                UpdateDebugInfo(Context.PrintDebugInfo(), 30f);
            }
            if (Input.GetKeyDown(_toggleBlossoms))
            {
                UpdateDebugInfo(Context.BladeContainer.Blades[0].HasBlossom ? "Deactivate Blossoms" : "Activate Blossoms");
                Context.BladeContainer.Blades[0].HasBlossom = !Context.BladeContainer.Blades[0].HasBlossom;
            }
            if (Input.GetKeyDown(_forceBlossoms))
            {
                if (!Context.BladeContainer.Blades[0].HasBlossom)
                {
                    if (Context.BlossomCount == 0)
                    {
                        UpdateDebugInfo("Force Blossoms rendering.");
                        Context.BlossomCount = 1;
                    }
                    else
                    {
                        UpdateDebugInfo("Deactivate force Blossoms rendering.");
                        Context.BlossomCount = 0;
                    }
                }
                else
                {
                    UpdateDebugInfo("Cannot Force Blossoms because there are blossoms.");
                }
            }

            if (Input.GetKeyDown(_toggleDebugColors))
            {
                _debugColors = !_debugColors;
                Shader.SetGlobalInt("RenderDebugColor", _debugColors ? 1 : 0);
            }
            if (Input.GetKeyDown(_toggleTerrain))
            {
                FindObjectOfType <Terrain>().enabled = !FindObjectOfType <Terrain>().enabled;
            }
            if (Input.GetKeyDown(_switchCamera))
            {
                if (!Context.Camera.GetComponent <Animator>().enabled)
                {
                    _cameraBackupPos = Context.Camera.transform.position;
                    _cameraBackupRot = Context.Camera.transform.rotation;
                }
                else
                {
                    Context.Camera.transform.position = _cameraBackupPos;
                    Context.Camera.transform.rotation = _cameraBackupRot;
                }
                Context.Camera.GetComponent <Animator>().enabled = !Context.Camera.GetComponent <Animator>().enabled;
            }

            if (Input.GetKeyDown(_switchGrassMapInput))
            {
                if (Context.GrassMapInput.GetType() == typeof(RandomGrassMapInput))
                {
                    UpdateDebugInfo("Switch to Texture GrassMap Input");
                    Context.GrassMapInput          = _textureGrassMapInput;
                    Context.GrassMapInputType.Type = _textureGrassMapInputType;
                }
                else
                {
                    UpdateDebugInfo("Switch to Uniform GrassMap Input");
                    _textureGrassMapInput     = Context.GrassMapInput;
                    _textureGrassMapInputType = Context.GrassMapInputType;

                    Context.GrassMapInput          = Activator.CreateInstance(typeof(RandomGrassMapInput)) as RandomGrassMapInput;
                    Context.GrassMapInputType.Type = typeof(RandomGrassMapInput);
                }
            }
        }
 public void When_type_is_null_returns_empty_string()
 {
     Assert.That(ClassTypeReference.GetClassGUID(null), Is.EqualTo(string.Empty));
 }