Beispiel #1
0
 public TypeTransform(Type type)
 {
     _type = type;
     if (_type.IsGenericTypeDefinition)
     {
         bindingFlags = TypeBindingFlags.Default & ~TypeBindingFlags.BindingCode;
     }
 }
Beispiel #2
0
        public CodeGenerator(BindingManager bindingManager, TypeBindingFlags typeBindingFlags)
        {
            this.typeBindingFlags = typeBindingFlags;
            this.bindingManager   = bindingManager;
            var tab     = this.bindingManager.prefs.tab;
            var newline = this.bindingManager.prefs.newline;

            cs        = new TextGenerator(newline, tab);
            tsDeclare = new TextGenerator(newline, tab);
        }
Beispiel #3
0
        public TypeTransform(Type type)
        {
            _type = type;
            if (_type.IsGenericTypeDefinition)
            {
                bindingFlags = TypeBindingFlags.Default & ~TypeBindingFlags.BindingCode;
            }

            if (UnityHelper.IsExplicitEditorType(type))
            {
                EditorRuntime();
            }
        }
        public TypeBindingInfo(BindingManager bindingManager, Type type, TypeBindingFlags bindingFlags)
        {
            this.bindingManager = bindingManager;
            this.type           = type;
            this.bindingFlags   = bindingFlags;
            this.transform      = bindingManager.GetTypeTransform(type);
            var naming          = this.transform?.GetTypeNaming() ?? GetNamingAttribute(type);
            var indexOfTypeName = naming.LastIndexOf('.');

            if (indexOfTypeName >= 0) // 内部类
            {
                this.jsNamespace = naming.Substring(0, indexOfTypeName);
                this.jsName      = naming.Substring(indexOfTypeName + 1);
            }
            else
            {
                if (type.DeclaringType != null)
                {
                    if (string.IsNullOrEmpty(type.Namespace))
                    {
                        this.jsNamespace = type.DeclaringType.Name;
                    }
                    else
                    {
                        this.jsNamespace = $"{type.Namespace}.{type.DeclaringType.Name}";
                    }
                }
                else
                {
                    this.jsNamespace = type.Namespace ?? "";
                }

                if (type.IsGenericType)
                {
                    this.jsName = naming.Substring(0, naming.IndexOf('`'));
                    foreach (var gp in type.GetGenericArguments())
                    {
                        this.jsName += "_" + gp.Name;
                    }
                }
                else
                {
                    this.jsName = naming;
                }
            }

            this.name         = bindingManager.prefs.typeBindingPrefix + (this.jsNamespace + "_" + this.jsName).Replace('.', '_').Replace('+', '_').Replace('<', '_').Replace('>', '_');
            this.constructors = new ConstructorBindingInfo(type);
        }
Beispiel #5
0
        public CSPlatformCodeGen(CodeGenerator cg, TypeBindingFlags bf)
        {
            this.cg     = cg;
            this.bf     = bf;
            this.predef = string.Empty;

#if !JSB_UNITYLESS
            if ((this.bf & TypeBindingFlags.BuildTargetPlatformOnly) != 0)
            {
                var buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
                switch (buildTarget)
                {
                case UnityEditor.BuildTarget.Android:
                    predef = "UNITY_ANDROID";
                    break;

                case UnityEditor.BuildTarget.iOS:
                    predef = "UNITY_IOS";
                    break;

                case UnityEditor.BuildTarget.WSAPlayer:
                    predef = "UNITY_WSA";     // not supported
                    break;

                case UnityEditor.BuildTarget.StandaloneWindows:
                case UnityEditor.BuildTarget.StandaloneWindows64:
                    predef = "UNITY_STANDALONE_WIN";
                    break;

                case UnityEditor.BuildTarget.StandaloneOSX:
                    predef = "UNITY_STANDALONE_OSX";
                    break;

                default:
                    predef = string.Format("false // {0} is not supported", buildTarget);
                    break;
                }
            }
#endif

            if (!string.IsNullOrEmpty(this.predef))
            {
                cg.cs.AppendLineL("#if {0}", this.predef);
            }
        }
Beispiel #6
0
 /// <summary>
 /// 标记此类型不限制于目标平台编译
 /// </summary>
 public TypeTransform SystemRuntime()
 {
     bindingFlags &= ~TypeBindingFlags.BuildTargetPlatformOnly;
     return(this);
 }
 public TypeTransform UnsetRuntime(TypeBindingFlags bf)
 {
     bindingFlags &= ~bf;
     return(this);
 }
 public TypeTransform SetRuntime(TypeBindingFlags bf)
 {
     bindingFlags |= bf;
     return(this);
 }
 public TypeTransform SystemRuntime()
 {
     bindingFlags &= ~TypeBindingFlags.UnityRuntime;
     return(this);
 }
Beispiel #10
0
 public TypeTransform EditorRuntime()
 {
     bindingFlags |= TypeBindingFlags.UnityEditorRuntime;
     return(this);
 }