Hi.
I have moved a lot of my scripts into a c# DLL that is in my Assets folder. It opens up just like a folder and I can see most of my scripts there.
Except I cant see those scripts that through inheritance uses generics. Example:
public class StopAnimation : AbstractTriggerableAnimation<string>
{
public override TriggerResult UseAnimation(Animation animation, string animationToUse)
{
if (animation)
{
if (animationToUse.Length > 0)
{
animation.Stop(animationToUse);
}
else
{
animation.Stop();
}
return new TriggerResult();
}
return new TriggerResult(0.0f, false);
}
}
AbstractGenericEntity inherits from MonoBehaviour again, so that is not the problem (ofcourse).
All other scripts that inherits from other abstract classes work. The funny thing is that if I try to add the components via code by using this example:
public override void OnPress(ScriptFile file)
{
Type scriptType = file.Type;
if (scriptType.IsSubclassOf(typeof(MonoBehaviour)))
{
UnityEngine.Object obj = UnityEngine.Object.FindObjectOfType(scriptType);
MonoBehaviour mono = obj as MonoBehaviour;
GameObject go = new GameObject(scriptType.Name);
if (Selection.gameObjects.Length > 0)
{
go = Selection.gameObjects[0];
}
Component comp = go.AddComponent(scriptType);
}
}
... then it appears in the Inspector with no name, but the gameobject that is created gets the correct name. Is this a unity bug? Am I doing something wrong?:

Edit 1: When closing down unity and opening it again, the gameobject in question lists the script as "none" (missing).
Edit 2: Answer to the question below about how I set the type:
private static Directory GetScriptsFromAssembly()
{
Assembly assembly = Assembly.LoadFrom(name);
Directory root = new Directory();
Type[] types = assembly.GetTypes();
length = types.Length;
progress = 0f;
foreach (Type type in types)
{
CheckType(root, type);
}
root.Sort();
return root;
}
This is the complete chain of inheritance with one of the scripts: using UnityEngine; using System.Collections; using EseTriggers;
[EseTriggersMenu("Entity/Behaviour/Animation/Stop Animation")]
public class StopAnimation : AbstractTriggerableAnimation<string>
{
public override TriggerResult UseAnimation(Animation animation, string animationToUse)
{
...
}
}
to
using UnityEngine;
using System.Collections;
using EseTriggers;
public abstract class AbstractTriggerableAnimation<T> : AbstractGenericEntity<Animation>
{
public T[] AnimationsToUse = new T[1];
protected override TriggerResult Trigger(Animation component)
{
...
}
public abstract TriggerResult UseAnimation(Animation animation, T animationToUse);
}
to
using UnityEngine;
using EseTriggers;
public abstract class AbstractGenericEntity<T> : AbstractEntity
{
public T[] Targets = new T[1];
protected override TriggerResult OnActivatedByTrigger(object value)
{
...
}
protected abstract TriggerResult Trigger(T target);
}
to
using UnityEngine;
using EseTriggers;
using System;
using System.Linq;
public abstract class AbstractEntity : AbstractConditionableMonobehaviourEntity
{
public AbstractCondition[] ConditionsToCheck;
public override bool IsConditionMet()
{
...
}
public override void SetCondition(bool isConditionMet)
{
...
}
}
to
using UnityEngine;
using EseTriggers;
using System;
public abstract class AbstractConditionableMonobehaviourEntity : AbstractConditionableMonoBehaviour, IEntity
{
public TriggerResult DoActivateTrigger(System.Object value)
{
...
}
protected abstract TriggerResult OnActivatedByTrigger(object value);
protected bool CanActivateTrigger()
{
...
}
}
to
using EseTriggers;
using UnityEngine;
public abstract class AbstractConditionableMonoBehaviour : EseTriggerMonoBehaviour, ICondition
{
public abstract bool IsConditionMet();
public abstract void SetCondition(bool isConditionMet);
}
to
using UnityEngine;
public class EseTriggerMonoBehaviour : MonoBehaviour
{
/// <summary>
/// Help text to display for the user setting up the triggers.
/// </summary>
public string Comment = "";
public float xPosition = 0;
public float XPosition { get { return xPosition; } set { xPosition = value; } }
public float yPosition = 0;
public float YPosition { get { return yPosition; } set { yPosition = value; } }
public virtual void Start()
{
if (!Application.isEditor)
{
Comment = null;
xPosition = 0;
yPosition = 0;
}
}
}
Edit 3: If you have Visual Studio installed then you can take a look at a small test project I uploaded here: http://dl.dropbox.com/u/1972432/Generics_bug.rar