RegType() public method

public RegType ( ICLS_Type type ) : void
type ICLS_Type
return void
Exemplo n.º 1
0
 public static void InitCSLight()
 {
     env = new CSLE.CLS_Environment(new Logger());
     //env.RegType(new CSLE.RegHelper_Type(typeof(GameObject)));
     env.RegType(new MYGameObject());
     //env.RegType(new CSLE.RegHelper_Type(typeof(Debug)));
     env.RegType(new MYDebug());
     //env.RegType(new CSLE.RegHelper_Type(typeof(Transform)));
     env.RegType(new MYTransform());
     env.RegType(new CSLE.RegHelper_Type(typeof(Camera)));
     env.RegType(new CSLE.RegHelper_Type(typeof(Vector3)));
 }
Exemplo n.º 2
0
    /// <summary>
    /// 这里注册脚本有权访问的类型,大部分类型用RegHelper_Type提供即可
    /// </summary>
    void RegTypes()
    {
        //大部分类型用RegHelper_Type提供即可
        env.RegType(new CSLE.RegHelper_Type(typeof(Vector2)));
        env.RegType(new CSLE.RegHelper_Type(typeof(Vector3)));
        env.RegType(new CSLE.RegHelper_Type(typeof(Vector4)));

        env.RegType(new CSLE.RegHelper_Type(typeof(Debug)));
        env.RegType(new CSLE.RegHelper_Type(typeof(GameObject)));
        env.RegType(new CSLE.RegHelper_Type(typeof(Component)));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Object)));
        env.RegType(new CSLE.RegHelper_Type(typeof(Transform)));
        //对于AOT环境,比如IOS,get set不能用RegHelper直接提供,就用AOTExt里面提供的对应类替换
        env.RegType(new CSLE.RegHelper_Type(typeof(int[]), "int[]"));          //数组要独立注册
        env.RegType(new CSLE.RegHelper_Type(typeof(List <int>), "List<int>")); //模板类要独立注册


        //每一种回调类型要独立注册
        //env.RegDeleType(new CSLE.RegHelper_DeleAction("Action"));
        env.RegDeleType(new CSLE.RegHelper_DeleAction <int>("Action<int>"));;
    }
Exemplo n.º 3
0
    /// <summary>
    /// 这里注册脚本有权访问的类型,大部分类型用RegHelper_Type提供即可
    /// </summary>
    void RegTypes()
    {
        //大部分类型用RegHelper_Type提供即可
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Vector2)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Vector3)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Vector4)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Time)));

        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Debug)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(GameObject)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Component)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Object)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Transform)));
        //对于AOT环境,比如IOS,get set不能用RegHelper直接提供,就用AOTExt里面提供的对应类替换
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(int[]), "int[]"));          //数组要独立注册
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(List <int>), "List<int>")); //模板类要独立注册



        //每一种回调类型要独立注册
        scriptEnv.RegDeleType(new CSLE.RegHelper_DeleAction("Action")); //unity 用的dotnet 2.0 没有Action
        scriptEnv.RegDeleType(new CSLE.RegHelper_DeleAction <int>("Action<int>"));;


        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(StateMgr)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(Rect)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(ScriptInstanceState)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(PrimitiveType)));
        scriptEnv.RegType(new CSLE.RegHelper_Type(typeof(App)));
    }
Exemplo n.º 4
0
    public static CLS_Environment CreateEnvironment()
    {
        CLS_Environment clsEnv = new CLS_Environment(new ScriptLogger());

        // 名空间注册
        clsEnv.RegType(new CLS_NameSpace("UnityEngine"));

        // 特殊类型注册
        clsEnv.RegType(new RegHelper_DeleAction<BaseEventData>(typeof(UnityAction<BaseEventData>), "UnityAction<BaseEventData>"));

        // gen start
        clsEnv.RegType(new ToCSLightBehaviour());
        clsEnv.RegType(new ToCSLightBoxCollider());
        clsEnv.RegType(new ToCSLightCollider());
        clsEnv.RegType(new ToCSLightColor());
        clsEnv.RegType(new ToCSLightComponent());
        clsEnv.RegType(new ToCSLightDebug());
        clsEnv.RegType(new ToCSLightGameObject());
        clsEnv.RegType(new ToCSLightMath());
        clsEnv.RegType(new ToCSLightMathf());
        clsEnv.RegType(new ToCSLightMonoBehaviour());
        clsEnv.RegType(new ToCSLightQuaternion());
        clsEnv.RegType(new ToCSLightSphereCollider());
        clsEnv.RegType(new ToCSLightTime());
        clsEnv.RegType(new ToCSLightTransform());
        clsEnv.RegType(new ToCSLightRandom());
        clsEnv.RegType(new ToCSLightVector2());
        clsEnv.RegType(new ToCSLightVector3());
        clsEnv.RegType(new RegHelper_DeleAction(typeof(Action), "Action"));
        clsEnv.RegType(new RegHelper_DeleAction<object>(typeof(Action<object>), "Action<object>"));
        clsEnv.RegType(new RegHelper_Type(typeof(Animator)));
        clsEnv.RegType(new RegHelper_Type(typeof(AnimatorStateInfo)));
        clsEnv.RegType(new RegHelper_Type(typeof(Application)));
        clsEnv.RegType(new RegHelper_Type(typeof(BaseEventData)));
        clsEnv.RegType(new RegHelper_Type(typeof(Button)));
        clsEnv.RegType(new RegHelper_Type(typeof(Button.ButtonClickedEvent), "Button.ButtonClickedEvent"));
        clsEnv.RegType(new RegHelper_Type(typeof(Camera)));
        clsEnv.RegType(new RegHelper_Type(typeof(Canvas)));
        clsEnv.RegType(new RegHelper_Type(typeof(CanvasGroup)));
        clsEnv.RegType(new RegHelper_Type(typeof(CanvasScaler)));
        clsEnv.RegType(new RegHelper_Type(typeof(Convert)));
        clsEnv.RegType(new RegHelper_Type(typeof(CSLightMng)));
        clsEnv.RegType(new RegHelper_Type(typeof(DateTime)));
        clsEnv.RegType(new CLS_Type_Enum(typeof(DayOfWeek)));
        clsEnv.RegType(new RegHelper_Type(typeof(Encoding)));
        clsEnv.RegType(new RegHelper_Type(typeof(EventTrigger)));
        clsEnv.RegType(new RegHelper_Type(typeof(EventTrigger.Entry), "EventTrigger.Entry"));
        clsEnv.RegType(new RegHelper_Type(typeof(EventTrigger.TriggerEvent), "EventTrigger.TriggerEvent"));
        clsEnv.RegType(new RegHelper_Type(typeof(Font)));
        clsEnv.RegType(new RegHelper_Type(typeof(Hashtable)));
        clsEnv.RegType(new RegHelper_Type(typeof(Image)));
        clsEnv.RegType(new RegHelper_Type(typeof(InputField)));
        clsEnv.RegType(new RegHelper_Type(typeof(Light)));
        clsEnv.RegType(new RegHelper_Type(typeof(MD5CryptoServiceProvider)));
        clsEnv.RegType(new RegHelper_Type(typeof(MemoryStream)));
        clsEnv.RegType(new RegHelper_Type(typeof(NavMeshAgent)));
        clsEnv.RegType(new RegHelper_Type(typeof(NavMeshHit)));
        clsEnv.RegType(new RegHelper_Type(typeof(NavMeshObstacle)));
        clsEnv.RegType(new RegHelper_Type(typeof(NavMeshPath)));
        clsEnv.RegType(new CLS_Type_Enum(typeof(ObstacleAvoidanceType)));
        clsEnv.RegType(new RegHelper_Type(typeof(ParticleSystem)));
        clsEnv.RegType(new RegHelper_Type(typeof(PointerEventData)));
        clsEnv.RegType(new CLS_Type_Enum(typeof(PrimitiveType)));
        clsEnv.RegType(new RegHelper_Type(typeof(QualitySettings)));
        clsEnv.RegType(new RegHelper_Type(typeof(Rect)));
        clsEnv.RegType(new RegHelper_Type(typeof(RectTransform)));
        clsEnv.RegType(new RegHelper_Type(typeof(Resources)));
        clsEnv.RegType(new RegHelper_Type(typeof(Rigidbody)));
        clsEnv.RegType(new CLS_Type_Enum(typeof(RuntimePlatform)));
        clsEnv.RegType(new RegHelper_Type(typeof(Screen)));
        clsEnv.RegType(new CLS_Type_Enum(typeof(SeekOrigin)));
        clsEnv.RegType(new RegHelper_Type(typeof(Slider)));
        clsEnv.RegType(new CLS_Type_Enum(typeof(Space)));
        clsEnv.RegType(new RegHelper_Type(typeof(Sprite)));
        clsEnv.RegType(new RegHelper_Type(typeof(StringBuilder)));
        clsEnv.RegType(new RegHelper_Type(typeof(Text)));
        clsEnv.RegType(new RegHelper_Type(typeof(Toggle)));
        clsEnv.RegType(new RegHelper_Type(typeof(Toggle.ToggleEvent), "Toggle.ToggleEvent"));
        clsEnv.RegType(new RegHelper_Type(typeof(Type)));
        clsEnv.RegType(new RegHelper_DeleAction(typeof(UnityAction), "UnityAction"));
        clsEnv.RegType(new RegHelper_DeleAction<bool>(typeof(UnityAction<bool>), "UnityAction<bool>"));
        clsEnv.RegType(new RegHelper_Type(typeof(UnityEngine.Object), "UnityEngine.Object"));
        clsEnv.RegType(new RegHelper_Type(typeof(Vector4)));
        clsEnv.RegType(new RegHelper_Type(typeof(WWW)));
        clsEnv.RegType(new CLS_Type_Array<Behaviour>("Behaviour[]"));
        clsEnv.RegType(new CLS_Type_List<Behaviour>("List<Behaviour>"));
        clsEnv.RegType(new CLS_Type_Array<BoxCollider>("BoxCollider[]"));
        clsEnv.RegType(new CLS_Type_List<BoxCollider>("List<BoxCollider>"));
        clsEnv.RegType(new CLS_Type_Array<Collider>("Collider[]"));
        clsEnv.RegType(new CLS_Type_List<Collider>("List<Collider>"));
        clsEnv.RegType(new CLS_Type_Array<Color>("Color[]"));
        clsEnv.RegType(new CLS_Type_List<Color>("List<Color>"));
        clsEnv.RegType(new CLS_Type_Array<Component>("Component[]"));
        clsEnv.RegType(new CLS_Type_List<Component>("List<Component>"));
        clsEnv.RegType(new CLS_Type_Array<GameObject>("GameObject[]"));
        clsEnv.RegType(new CLS_Type_List<GameObject>("List<GameObject>"));
        clsEnv.RegType(new CLS_Type_Array<MonoBehaviour>("MonoBehaviour[]"));
        clsEnv.RegType(new CLS_Type_List<MonoBehaviour>("List<MonoBehaviour>"));
        clsEnv.RegType(new CLS_Type_Array<Quaternion>("Quaternion[]"));
        clsEnv.RegType(new CLS_Type_List<Quaternion>("List<Quaternion>"));
        clsEnv.RegType(new CLS_Type_Array<SphereCollider>("SphereCollider[]"));
        clsEnv.RegType(new CLS_Type_List<SphereCollider>("List<SphereCollider>"));
        clsEnv.RegType(new CLS_Type_Array<Transform>("Transform[]"));
        clsEnv.RegType(new CLS_Type_List<Transform>("List<Transform>"));
        clsEnv.RegType(new CLS_Type_Array<Vector2>("Vector2[]"));
        clsEnv.RegType(new CLS_Type_List<Vector2>("List<Vector2>"));
        clsEnv.RegType(new CLS_Type_Array<Vector3>("Vector3[]"));
        clsEnv.RegType(new CLS_Type_List<Vector3>("List<Vector3>"));
        clsEnv.RegType(new CLS_Type_Array<Animator>("Animator[]"));
        clsEnv.RegType(new CLS_Type_List<Animator>("List<Animator>"));
        clsEnv.RegType(new CLS_Type_Array<AnimatorStateInfo>("AnimatorStateInfo[]"));
        clsEnv.RegType(new CLS_Type_List<AnimatorStateInfo>("List<AnimatorStateInfo>"));
        clsEnv.RegType(new CLS_Type_Array<Button>("Button[]"));
        clsEnv.RegType(new CLS_Type_List<Button>("List<Button>"));
        clsEnv.RegType(new CLS_Type_Array<Camera>("Camera[]"));
        clsEnv.RegType(new CLS_Type_List<Camera>("List<Camera>"));
        clsEnv.RegType(new CLS_Type_Array<EventTrigger.Entry>("EventTrigger.Entry[]"));
        clsEnv.RegType(new CLS_Type_List<EventTrigger.Entry>("List<EventTrigger.Entry>"));
        clsEnv.RegType(new CLS_Type_Array<Image>("Image[]"));
        clsEnv.RegType(new CLS_Type_List<Image>("List<Image>"));
        clsEnv.RegType(new CLS_Type_Array<InputField>("InputField[]"));
        clsEnv.RegType(new CLS_Type_List<InputField>("List<InputField>"));
        clsEnv.RegType(new CLS_Type_Array<ParticleSystem>("ParticleSystem[]"));
        clsEnv.RegType(new CLS_Type_List<ParticleSystem>("List<ParticleSystem>"));
        clsEnv.RegType(new CLS_Type_Array<Rect>("Rect[]"));
        clsEnv.RegType(new CLS_Type_List<Rect>("List<Rect>"));
        clsEnv.RegType(new CLS_Type_Array<RectTransform>("RectTransform[]"));
        clsEnv.RegType(new CLS_Type_List<RectTransform>("List<RectTransform>"));
        clsEnv.RegType(new CLS_Type_Array<Slider>("Slider[]"));
        clsEnv.RegType(new CLS_Type_List<Slider>("List<Slider>"));
        clsEnv.RegType(new CLS_Type_Array<Sprite>("Sprite[]"));
        clsEnv.RegType(new CLS_Type_List<Sprite>("List<Sprite>"));
        clsEnv.RegType(new CLS_Type_Array<Text>("Text[]"));
        clsEnv.RegType(new CLS_Type_List<Text>("List<Text>"));
        clsEnv.RegType(new CLS_Type_Array<Toggle>("Toggle[]"));
        clsEnv.RegType(new CLS_Type_List<Toggle>("List<Toggle>"));
        clsEnv.RegType(new CLS_Type_Array<Type>("Type[]"));
        clsEnv.RegType(new CLS_Type_List<Type>("List<Type>"));
        clsEnv.RegType(new CLS_Type_Array<UnityEngine.Object>("UnityEngine.Object[]"));
        clsEnv.RegType(new CLS_Type_List<UnityEngine.Object>("List<UnityEngine.Object>"));
        clsEnv.RegType(new CLS_Type_Array<Vector4>("Vector4[]"));
        clsEnv.RegType(new CLS_Type_List<Vector4>("List<Vector4>"));
        clsEnv.RegType(new CLS_Type_Array<WWW>("WWW[]"));
        clsEnv.RegType(new CLS_Type_List<WWW>("List<WWW>"));
        // gen end

        return clsEnv;
    }
Exemplo n.º 5
0
    // 从资源包初始化脚本环境
    public void InitializeFromAssetBundle(AssetBundle scriptsAssetBundle)
    {
        m_clsAssetBundle = scriptsAssetBundle;

        #if UNITY_EDITOR
        float timeStart = Time.realtimeSinceStartup;
        uint monoStart = Profiler.GetMonoUsedSize();
        #endif

        // 获取默认的脚本实例
        m_clsEnv = ToCSLight.CreateEnvironment();
        m_clsContent = m_clsEnv.CreateContent();

        // 预注册脚本类
        #if UNITY_EDITOR && !EDITOR_FORCE_ASSET_BUNDLE
        string rootPath = Application.dataPath + "/CSLight/Editor/CSLogic";
        string[] files = System.IO.Directory.GetFiles(rootPath, "*.cs", System.IO.SearchOption.AllDirectories);
        foreach (var file in files)
        {
            string className = System.IO.Path.GetFileNameWithoutExtension(file);
            m_clsEnv.RegType(new CLS_Type_Class(className, file.Replace('\\', '/')));
        }
        #else
        StringHolder classHolder = m_clsAssetBundle.LoadAsset("class", typeof(StringHolder)) as StringHolder;
        foreach (string className in classHolder.content)
        {
            m_clsEnv.RegType(new CLS_Type_Class(className, className));
        }
        #endif

        #if UNITY_EDITOR
        Debug.Log("script init cost time: " + (Time.realtimeSinceStartup - timeStart));
        Debug.Log(string.Format("script init cost memory: {0:0.00}MB", (Profiler.GetMonoUsedSize() - monoStart) / (1024f * 1024f)));
        timeStart = Time.realtimeSinceStartup;
        #endif
    }
Exemplo n.º 6
0
    public void BeginInit()
    {
        env = new CSLE.CLS_Environment(this);
        Log_Warn("C#Light Ver:" + env.version);

        //System
        env.RegType(new CSLE.RegHelper_Type(typeof(NotImplementedException), "NotImplementedException"));
        env.RegType(new CSLE.RegHelper_Type(typeof(Exception), "Exception"));
        env.RegType(new CSLE.RegHelper_Type(typeof(object), "object"));

        //Framework
        env.RegType(new CSLE.RegHelper_Type(typeof(IScreenForModel), "IScreenForModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IGameForModel), "IGameForModel"));

        env.RegType(new CSLE.RegHelper_Type(typeof(IGameModel), "IGameForModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IScriptModel), "IScriptModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IUIToolModel), "IUIToolModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IBlockSceneModel), "IBlockSceneModel"));

        //UnityEngine
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Debug), "Debug"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.GameObject), "GameObject"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Object), "Object"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Transform), "Transform"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.UI.Text), "Text"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.RectTransform), "RectTransform"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Vector2), "Vector2"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Vector3), "Vector3"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Vector4), "Vector4"));



        //直接编译模式
        string[] files = System.IO.Directory.GetFiles(Application.streamingAssetsPath + "/script", "*.cs", System.IO.SearchOption.AllDirectories);
        Dictionary <string, IList <CSLE.Token> > tokens = new Dictionary <string, IList <CSLE.Token> >();

        foreach (var f in files)
        {
            string code = System.IO.File.ReadAllText(f);
            var    t    = env.ParserToken(code);
            tokens[f] = t;
        }

        env.Project_Compiler(tokens, true);


        inited = true;
    }
Exemplo n.º 7
0
 public static void InitCSLight()
 {
     env = new CSLE.CLS_Environment(new Logger());
     //env.RegType(new CSLE.RegHelper_Type(typeof(GameObject)));
     env.RegType(new MYGameObject());
     //env.RegType(new CSLE.RegHelper_Type(typeof(Debug)));
     env.RegType(new MYDebug());      
     //env.RegType(new CSLE.RegHelper_Type(typeof(Transform)));
     env.RegType(new MYTransform());
     env.RegType(new CSLE.RegHelper_Type(typeof(Camera)));
     env.RegType(new CSLE.RegHelper_Type(typeof(Vector3)));
 }