I have a class that I need to connect with a few other classes and libraries. One of these libs requires a webcam. Problem is that this requirement is done in a static (I suspect a constructor of a static) and this library is in binairy form so I cannot edit it. Now if no webcam is pressent I don't want to use this library but if it is present I want to use this library. What I have tried so far is by setting up an interface between the two (like this except a lot more complete)
interface caminterface {
void dostuff();//executes lib function
}
class cam{
void dostuff();
}
class main{
private caminterface;
void start(){
if(haswebcam())
caminterface=new cam();
}
}
note that all 3 of these classes/interface were in their own files. But this did not work and the variables kept on loading.
A more full example is this:
namespace Projection
{
using System.Diagnostics.CodeAnalysis;
using UnityEngine;
/// <summary>
/// Marks which marker is used for the basis of the level by the meta one
/// </summary>
public class BaseForLevel : MonoBehaviour
{
private MetaMarkerInterface metaMarker;
public bool activeMarkers; //we have a cam
public void Start()
{
if(this.activeMarkers){
this.metaMarker= new MetaMarker();
this.metaMarker.RegisterMeta();
}
}
}
using UnityEngine;
using System.Collections;
namespace Projection{
public interface MetaMarkerInterface {
void RegisterMeta();
bool MoveTransformToMarker(int loc , Transform trans);
}
}
using UnityEngine; using System.Collections; using Meta; namespace Projection {
public class MetaMarker : MonoBehaviour , MetaMarkerInterface{ /// /// meta object required for tracking /// private GameObject markerdetectorGO;
/// <summary>
/// meta object required for tracking
/// </summary>
private MarkerTargetIndicator marketTargetindicator;
/// <summary>
/// sets up the detector and marker indicator to find this marker/
/// </summary>
public void RegisterMeta(){
this.markerdetectorGO = MarkerDetector.Instance.gameObject;
// hide markerindicator
this.marketTargetindicator = this.markerdetectorGO.GetComponent<MarkerTargetIndicator>();
this.marketTargetindicator.enabled = false;
}
///<summary>
///orignally from the metaExample script, heavily edited and returns true
///if the marker was seen if it is then it also moves the object to the marker position
///</summary>
public bool MoveTransformToMarker(int id,Transform trans){
if (!this.markerdetectorGO.activeSelf)
{
this.markerdetectorGO.SetActive(true);
}
if (MarkerDetector.Instance != null)
{
// check if we can see this marker
if (MarkerDetector.Instance.updatedMarkerTransforms.Contains(id))
{
// if we can then move this marker to that position
MarkerDetector.Instance.GetMarkerTransform(id, ref trans);
return true;
}
}
return false;
}
}
}