Exemplo n.º 1
0
    private void OnGUI()
    {
        GUILayout.Label("Specify the name of the new GameEvent");
        eventName = EditorGUILayout.TextField("New name:", eventName);

        if (GUILayout.Button("Create"))
        {
            gameEvent = (GameEvent)ScriptableObject.CreateInstance(typeof(GameEvent));
            if (!AssetDatabase.IsValidFolder("Assets/Events/Resources"))
            {
                if (!AssetDatabase.IsValidFolder("Assets/Events"))
                {
                    AssetDatabase.CreateFolder("Assets", "Events");
                }
                AssetDatabase.CreateFolder("Assets/Events", "Resources");
            }
            var eventPath = "Assets/Events/Resources/" + eventName + ".asset";
            AssetDatabase.CreateAsset(gameEvent, eventPath);

            eventDataName = eventName + "Data";
            var    eventDataScript = CustomDataGenerator.Generate(eventDataName);
            string path            = $"{Application.dataPath}/Events/CustomData";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path += "/" + eventDataName + ".cs";
            File.WriteAllText(path, eventDataScript);

            var reletivePath = "Assets/Events/CustomData/" + eventDataName + ".cs";
            AssetDatabase.ImportAsset(reletivePath, ImportAssetOptions.ForceSynchronousImport);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
Exemplo n.º 2
0
        public void CustomProperty()
        {
            var custom  = new CustomDataGenerator();
            var wrapped = Wrap.Type <User>()
                          .WithSourceProperties()
                          .WithProperty("Custom", i => custom.GetCustomData(i))
                          .Instance(_user);

            AssertUserIsFine(wrapped, out Type wrappedType);

            var customProperty = (string)wrappedType.GetProperty("Custom").GetValue(wrapped);

            Assert.Equal("http://example.com/Users/42", customProperty);
        }