public List <T> GetScriptsInChildren <T>(MochaInterface.GameObject g)
        {
            if (g == null)
            {
                Logger.Log("Null GameObject passed on invoke class to find: ");
                return(null);
            }
            List <T> scripts = new List <T>();

            foreach (MochaInterface.CTransform ct in g.transform.children)
            {
                if (ScriptSubsystemManaged.getInstance().gameObjectToBoundScriptsLookup.ContainsKey(ct.gameObject))
                {
                    foreach (BoundScript bs in ScriptSubsystemManaged.getInstance().gameObjectToBoundScriptsLookup[ct.gameObject])
                    {
                        if (bs == null || bs.scriptObject == null)
                        {
                            continue;
                        }
                        if (bs.scriptObject.GetType() == typeof(T))
                        {
                            scripts.Add((T)bs.scriptObject);
                        }
                    }
                }
            }

            return(scripts);
        }
 public object GetScriptClass <T>(MochaInterface.GameObject g)
 {
     if (g == null)
     {
         Logger.Log("Null GameObject passed on invoke class to find: ");
         return(null);
     }
     if (gameObjectToBoundScriptsLookup.ContainsKey(g))
     {
         var bslist = gameObjectToBoundScriptsLookup[g];
         foreach (var bs in bslist)
         {
             if (bs == null)
             {
                 continue;
             }
             object c = null;
             try
             {
                 c = (T)bs.scriptObject;
             }
             catch (InvalidCastException)
             {
                 c = null;
             }
             if (c != null)
             {
                 return(bs.scriptObject);
             }
         }
     }
     return(null);
 }
        //to all scripts on game object
        public void Invoke(MochaInterface.GameObject g, string funcname, bool requireReceiver)
        {
            if (g == null)
            {
                throw new ScriptException("Invoke on null object for function: " + funcname);
            }
            if (gameObjectToBoundScriptsLookup.ContainsKey(g))
            {
                var bslist = gameObjectToBoundScriptsLookup[g];
                foreach (BoundScript bs in bslist)
                {
                    MethodInfo mi;
                    try
                    {
                        mi = bs.scriptObject.GetType().GetMethod(funcname);
                    }
                    catch (AmbiguousMatchException)
                    {
                        Logger.Log("Ambiguous invoke for function: " + funcname + " on script target: " + bs.scriptObject.GetType().Name + " on obj: " + g.GetName());
                        return;
                    }
                    catch (ArgumentNullException)
                    {
                        Logger.Log("Invalid function name invoke for function: " + funcname + " on script target: " + bs.scriptObject.GetType().Name + " on obj: " + g.GetName());
                        return;
                    }
                    if (mi == null)
                    {
                        if (requireReceiver)
                        {
                            Logger.Log("Function to Invoke not found: function: " + funcname + " on script target: " + bs.scriptObject.GetType().Name + " on obj: " + g.GetName());
                        }
                        return;
                    }

                    try
                    {
                        mi.Invoke(bs.scriptObject, null);
                    }
                    catch (Exception e)
                    {
                        Logger.Log("Invoke failed during invoke on function: " + funcname + " on script target: " +
                                   bs.scriptObject.GetType().Name + " on obj: " + g.GetName() + " with msg: [" + e.Message + "]");
                    }
                }
            }
        }
 public object GetScript(MochaInterface.GameObject g, string scriptname)
 {
     if (g == null)
     {
         Logger.Log("Null GameObject passed on invoke to: " + scriptname);
         return(null);
     }
     if (gameObjectToBoundScriptsLookup.ContainsKey(g))
     {
         var bslist = gameObjectToBoundScriptsLookup[g];
         var bs     = bslist.Find(x => x.scriptName == scriptname);
         if (bs == null)
         {
             Logger.Log("No Script found for object: " + g.GetName() + " while looking for: " + scriptname);
             return(null);
         }
         return(bs.scriptObject);
     }
     return(null);
 }
        public List <T> GetScripts <T>(MochaInterface.GameObject g)
        {
            if (g == null)
            {
                Logger.Log("Null GameObject passed on invoke class to find: ");
                return(null);
            }

            List <T> scripts = new List <T>();

            if (gameObjectToBoundScriptsLookup.ContainsKey(g))
            {
                var bslist = gameObjectToBoundScriptsLookup[g];
                foreach (var bs in bslist)
                {
                    if (bs == null)
                    {
                        continue;
                    }
                    T c = default(T);
                    try
                    {
                        c = (T)bs.scriptObject;
                    }
                    catch (InvalidCastException)
                    {
                        c = default(T);
                    }
                    if (c != null)
                    {
                        scripts.Add(c);
                    }
                }
            }
            return(scripts);
        }
Exemplo n.º 6
0
 public UnderlyingObject()
 {
     _gameObject = MochaInterface.ObjectFactory.getInstance().MakeNewGameObject("Control");
     _renderer   = _gameObject.RequireComponent <MochaInterface.CDiffuseRenderer>();
 }
Exemplo n.º 7
0
 public UnderlyingObject()
 {
     _gameObject = MochaInterface.ObjectFactory.getInstance().MakeNewGameObject("Control");
     _renderer = _gameObject.RequireComponent<MochaInterface.CDiffuseRenderer>();
 }