public void TestPluginInterfaceUnknown()
        {
            var index = new PluginPackageIndex
            {
                PluginArchiveVersion        = PluginArchive.CurrentPluginArchiveVersion,
                ImplementedPluginInterfaces = new List <PluginInterfaceImplementation>
                {
                    new PluginInterfaceImplementation
                    {
                        InterfaceVersion  = 1,
                        InterfaceTypename = typeof(IFancyPantsInterface).FullName                         //< That interface won't be loaded by the PluginArchiverLoader because it's not part of the API project
                    }
                }
            };

            PluginGroup.FindCompatibilityErrors(index).Should().BeEquivalentTo(new object[]
            {
                new PluginError($"The plugin implements an unknown interface '{typeof(IFancyPantsInterface).FullName}' which is probably part of a newer tailviewer version. The plugin should target the current version in order to be usable!")
            });
        }
        public void TestPluginInterfaceTooNew()
        {
            var index = new PluginPackageIndex
            {
                PluginArchiveVersion        = PluginArchive.CurrentPluginArchiveVersion,
                ImplementedPluginInterfaces = new List <PluginInterfaceImplementation>
                {
                    new PluginInterfaceImplementation
                    {
                        InterfaceVersion  = 11,                        // It's a newer code, sir, and doesn't check out
                        InterfaceTypename = typeof(IDataSourceAnalyserPlugin).FullName
                    }
                }
            };

            PluginGroup.FindCompatibilityErrors(index).Should().BeEquivalentTo(new object[]
            {
                new PluginError($"The plugin implements a newer version of '{typeof(IDataSourceAnalyserPlugin).FullName}'. It must target the current version in order to be usable!")
            });
        }
Example #3
0
        private IEnumerable <Plugin> LoadPluginsFrom(string path, PluginGroup group)
        {
            if (!Directory.Exists(path))
            {
                yield break;
            }

            foreach (string fullDir in Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly))
            {
                Plugin plugin = Plugin.CreateFromFolder(fullDir, group, out string error);

                if (plugin == null)
                {
                    loadErrors.Add(group.GetIdentifierPrefix() + Path.GetFileName(fullDir) + ": " + error);
                }
                else
                {
                    yield return(plugin);
                }
            }
        }
Example #4
0
 public int CountPluginByGroup(PluginGroup group)
 {
     return(plugins.Count(plugin => plugin.Group == group));
 }
Example #5
0
 public IEnumerable <Plugin> GetPluginsByGroup(PluginGroup group)
 {
     return(plugins.Where(plugin => plugin.Group == group));
 }
    private void CreateMap()
    {
        OnlineMaps map    = CreateMapGameObject();
        GameObject go     = map.gameObject;
        Sprite     sprite = null;

        Control   control   = activeControl;
        Component component = go.AddComponent(control.type);

        if (control.resultType == OnlineMapsTarget.texture)
        {
            map.redrawOnPlay = true;

            string    texturePath;
            Texture2D texture = CreateTexture(map, out texturePath);

            if (control.useSprite)
            {
                TextureImporter textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
                textureImporter.textureType = TextureImporterType.Sprite;
                textureImporter.SaveAndReimport();

                sprite = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Sprite)) as Sprite;

                if (component is OnlineMapsSpriteRendererControl)
                {
                    SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();
                    spriteRenderer.sprite = sprite;
                    go.AddComponent <BoxCollider>();
                }
            }

            if (component is OnlineMapsUIImageControl || component is OnlineMapsUIRawImageControl)
            {
                RectTransform rectTransform = go.AddComponent <RectTransform>();
                rectTransform.SetParent(uGUIParent.transform as RectTransform);
                go.AddComponent <CanvasRenderer>();
                rectTransform.localPosition = Vector3.zero;
                rectTransform.anchorMax     = rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                rectTransform.pivot         = new Vector2(0.5f, 0.5f);
                rectTransform.sizeDelta     = new Vector2(textureWidth, textureHeight);

                if (component is OnlineMapsUIImageControl)
                {
                    Image image = go.AddComponent <Image>();
                    image.sprite = sprite;
                }
                else
                {
                    RawImage image = go.AddComponent <RawImage>();
                    image.texture = texture;
                }
            }

            if (component is OnlineMapsNGUITextureControl)
            {
#if NGUI
                go.layer = NGUIParent.layer;
                UITexture uiTexture = go.AddComponent <UITexture>();
                uiTexture.mainTexture      = texture;
                uiTexture.width            = textureWidth;
                uiTexture.height           = textureHeight;
                go.transform.parent        = NGUIParent.transform;
                go.transform.localPosition = Vector3.zero;
                go.transform.localScale    = Vector3.one;
                go.transform.localRotation = Quaternion.Euler(Vector3.zero);
                BoxCollider boxCollider = go.AddComponent <BoxCollider>();
                boxCollider.size = new Vector3(textureWidth, textureHeight, 0);
#endif
            }
            if (component is OnlineMapsTextureControl)
            {
                Renderer renderer = go.GetComponent <Renderer>();
                renderer.sharedMaterial             = new Material(Shader.Find("Diffuse"));
                renderer.sharedMaterial.mainTexture = texture;
                map.redrawOnPlay = true;
            }
        }
        else
        {
            OnlineMapsControlBaseDynamicMesh control3D = component as OnlineMapsControlBaseDynamicMesh;
            map.width             = tilesetWidth;
            map.height            = tilesetHeight;
            control3D.sizeInScene = sizeInScene;
            map.renderInThread    = false;

            OnlineMapsTileSetControl tsControl = component as OnlineMapsTileSetControl;
            if (tsControl != null)
            {
                tsControl.tileMaterial   = tileMaterial;
                tsControl.markerMaterial = markerMaterial;
                tsControl.tilesetShader  = tilesetShader;
                tsControl.drawingShader  = drawingShader;
                tsControl.markerShader   = markerShader;
            }

            if (moveCameraToMap)
            {
                GameObject cameraGO = activeCamera.gameObject;
                float      minSide  = Mathf.Min(sizeInScene.x, sizeInScene.y);
                Vector3    pos      = new Vector3(sizeInScene.x / -2, minSide, sizeInScene.y / 2);
                cameraGO.transform.position = pos;
                cameraGO.transform.rotation = Quaternion.Euler(90, 180, 0);
            }
        }

        foreach (IPlugin plugin in control.plugins)
        {
            if (plugin is Plugin)
            {
                Plugin p = plugin as Plugin;
                if (p.enabled)
                {
                    go.AddComponent(p.type);
                }
            }
            else if (plugin is PluginGroup)
            {
                PluginGroup g = plugin as PluginGroup;
                if (g.selected > 0)
                {
                    go.AddComponent(g.plugins.First(p => p.title == g.titles[g.selected]).type);
                }
            }
        }

        EditorGUIUtility.PingObject(go);
        Selection.activeGameObject = go;
    }
Example #7
0
 /// <summary>
 ///   Creates a plugin group based on the given info.
 /// </summary>
 /// <param name="p_xndGroup">The configuration file node corresponding to the group to add.</param>
 /// <returns>The added group.</returns>
 protected override PluginGroup parseGroup(XmlNode p_xndGroup)
 {
   var strName = p_xndGroup.Attributes["name"].InnerText;
   var gtpType = (GroupType) Enum.Parse(typeof (GroupType), p_xndGroup.Attributes["type"].InnerText);
   var strPluginOrder = SortOrder.None;
   switch (p_xndGroup.FirstChild.Attributes["order"].InnerText)
   {
     case "Ascending":
       strPluginOrder = SortOrder.Ascending;
       break;
     case "Descending":
       strPluginOrder = SortOrder.Descending;
       break;
   }
   var pgpGroup = new PluginGroup(strName, gtpType, strPluginOrder);
   var xnlPlugins = p_xndGroup.FirstChild.ChildNodes;
   foreach (XmlNode xndPlugin in xnlPlugins)
   {
     var pifPlugin = parsePlugin(xndPlugin);
     pgpGroup.addPlugin(pifPlugin);
   }
   return pgpGroup;
 }
Example #8
0
 /// <summary>
 /// Creates a plugin group based on the given info.
 /// </summary>
 /// <param name="p_xndGroup">The configuration file node corresponding to the group to add.</param>
 /// <returns>The added group.</returns>
 protected virtual PluginGroup parseGroup(XmlNode p_xndGroup)
 {
     string strName = p_xndGroup.Attributes["name"].InnerText;
     GroupType gtpType = (GroupType)Enum.Parse(typeof(GroupType), p_xndGroup.Attributes["type"].InnerText);
     PluginGroup pgpGroup = new PluginGroup(strName, gtpType, SortOrder.Ascending);
     XmlNodeList xnlPlugins = p_xndGroup.FirstChild.ChildNodes;
     foreach (XmlNode xndPlugin in xnlPlugins)
     {
         PluginInfo pifPlugin = parsePlugin(xndPlugin);
         pgpGroup.addPlugin(pifPlugin);
     }
     return pgpGroup;
 }
Example #9
0
        private static Plugin FromFolder(string name, string pathRoot, string pathData, PluginGroup group)
        {
            Plugin.Builder builder = new Plugin.Builder(group, name, pathRoot, pathData);

            foreach (var environment in Directory.EnumerateFiles(pathRoot, "*.js", SearchOption.TopDirectoryOnly).Select(Path.GetFileName).Select(EnvironmentFromFileName))
            {
                builder.AddEnvironment(environment);
            }

            string metaFile = Path.Combine(pathRoot, ".meta");

            if (!File.Exists(metaFile))
            {
                throw new ArgumentException("Plugin is missing a .meta file.");
            }

            string?currentTag      = null;
            string currentContents = string.Empty;

            foreach (string line in File.ReadAllLines(metaFile, Encoding.UTF8).Concat(EndTag).Select(static line => line.TrimEnd()).Where(static line => line.Length > 0))
Example #10
0
        public static IEnumerable <Result <Plugin> > AllInFolder(string pluginFolder, string pluginDataFolder, PluginGroup group)
        {
            string path = Path.Combine(pluginFolder, group.GetSubFolder());

            if (!Directory.Exists(path))
            {
                yield break;
            }

            foreach (string fullDir in Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly))
            {
                string name   = Path.GetFileName(fullDir);
                string prefix = group.GetIdentifierPrefix();

                if (string.IsNullOrEmpty(name))
                {
                    yield return(new Result <Plugin>(new DirectoryNotFoundException($"{prefix}(?): Could not extract directory name from path: {fullDir}")));

                    continue;
                }

                Result <Plugin> result;

                try {
                    result = new Result <Plugin>(FromFolder(name, fullDir, Path.Combine(pluginDataFolder, prefix, name), group));
                } catch (Exception e) {
                    result = new Result <Plugin>(new Exception($"{prefix}{name}: {e.Message}", e));
                }

                yield return(result);
            }
        }
        public static Plugin FromFolder(string name, string pathRoot, string pathData, PluginGroup group)
        {
            Plugin.Builder builder = new Plugin.Builder(group, name, pathRoot, pathData);

            foreach (var environment in Directory.EnumerateFiles(pathRoot, "*.js", SearchOption.TopDirectoryOnly).Select(Path.GetFileName).Select(EnvironmentFromFileName))
            {
                builder.AddEnvironment(environment);
            }

            string metaFile = Path.Combine(pathRoot, ".meta");

            if (!File.Exists(metaFile))
            {
                throw new ArgumentException("Plugin is missing a .meta file");
            }

            string?currentTag      = null;
            string currentContents = string.Empty;

            foreach (string line in File.ReadAllLines(metaFile, Encoding.UTF8).Concat(EndTag).Select(line => line.TrimEnd()).Where(line => line.Length > 0))
            {
                if (line[0] == '[' && line[line.Length - 1] == ']')
                {
                    if (currentTag != null)
                    {
                        SetProperty(builder, currentTag, currentContents);
                    }

                    currentTag      = line.Substring(1, line.Length - 2).ToUpper();
                    currentContents = string.Empty;

                    if (line.Equals(EndTag[0]))
                    {
                        break;
                    }
                }
                else if (currentTag != null)
                {
                    currentContents = currentContents.Length == 0 ? line : currentContents + Environment.NewLine + line;
                }
                else
                {
                    throw new FormatException($"Missing metadata tag before value: {line}");
                }
            }

            return(builder.BuildAndSetup());
        }