1
  Type type = Type.GetType(typeof(Texture).FullName);

Unityで上記のC#のスクリプトの帰り値がnullになります。

1 件の回答 1

2

以下のanswer.unity3dに回答がありました。

http://answers.unity3d.com/questions/206665/typegettypestring-does-not-work-in-unity.html

以下のwrapperで対応する事が推奨されています。

public class WrapClass
{
        public static Type GetType (string typeName)
        {

                // Try Type.GetType() first. This will work with types defined
                // by the Mono runtime, in the same assembly as the caller, etc.
                var type = Type.GetType (typeName);

                // If it worked, then we're done here
                if (type != null)
                        return type;

                // If the TypeName is a full name, then we can try loading the defining assembly directly
                if (typeName.Contains (".")) {

                        // Get the name of the assembly (Assumption is that we are using 
                        // fully-qualified type names)
                        var assemblyName = typeName.Substring (0, typeName.IndexOf ('.'));

                        // Attempt to load the indicated Assembly
                        var assembly = Assembly.Load (assemblyName);
                        if (assembly == null)
                                return null;

                        // Ask that assembly to return the proper Type
                        type = assembly.GetType (typeName);
                        if (type != null)
                                return type;

                }

                // If we still haven't found the proper type, we can enumerate all of the 
                // loaded assemblies and see if any of them define the type
                var currentAssembly = Assembly.GetExecutingAssembly ();
                var referencedAssemblies = currentAssembly.GetReferencedAssemblies ();
                foreach (var assemblyName in referencedAssemblies) {

                        // Load the referenced assembly
                        var assembly = Assembly.Load (assemblyName);
                        if (assembly != null) {
                                // See if that assembly defines the named type
                                type = assembly.GetType (typeName);
                                if (type != null)
                                        return type;
                        }
                }

                // The type just couldn't be found...
                return null;
        }
}

なお Unity5(beta)でも問題は解決していませんでした。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。