Exemplo n.º 1
0
    // 赋值脚本静态成员
    public void SetMemberStatic(string className, string memName, object val)
    {
#if UNITY_EDITOR
        try
        {
            if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(memName))
            {
                return;
            }
#endif
        CLS_Type_Class type = m_clsEnv.GetTypeByKeywordQuiet(className) as CLS_Type_Class;
        if (type == null)
        {
            Debug.LogWarning(string.Format("CallStatic({0}.{1}): class not found!", className, memName));
            return;
        }
        type.function.StaticValueSet(m_clsContent, memName, val);
#if UNITY_EDITOR
    }

    catch (System.Exception ex)
    {
        Debug.LogError(DumpStack(ex));
        return;
    }
#endif
    }
Exemplo n.º 2
0
    // 即时编译class
    protected void RuntimeCompilerClass(string className, List <string> types = null)
    {
        CLS_Type_Class stype = m_clsEnv.GetTypeByKeywordQuiet(className) as CLS_Type_Class;

        if (stype == null || stype.compiled)
        {
            return;
        }

        if (types == null)
        {
            types = new List <string>();
        }
        if (!types.Contains(className))
        {
            types.Add(className);
        }

        IList <Token> tokens;

#if UNITY_EDITOR && !EDITOR_FORCE_ASSET_BUNDLE
        string code = System.IO.File.ReadAllText(((SType)stype.function).filename);
        tokens = m_clsEnv.ParserToken(code);
#else
        TextAsset codeText = m_clsAssetBundle.LoadAsset(className) as TextAsset;
        using (MemoryStream ms = new MemoryStream(codeText.bytes))
        {
            tokens = m_clsEnv.StreamToToken(ms);
        }
#endif
        RuntimeCompilerTokens(tokens, types);
        m_clsEnv.CompilerToken(className, tokens, m_scriptTokenDebug);
    }
Exemplo n.º 3
0
    public object Deserialize(Stream source, string className)
    {
        CLS_Type_Class sClass = m_clsEnv.GetTypeByKeywordQuiet(className) as CLS_Type_Class;

        if (sClass == null)
        {
            throw new NotImplementedException("未实现类型: " + className);
        }

        if (!sClass.compiled)
        {
            RuntimeCompilerClass(className);
        }

        CLS_Content.Value retVal    = (sClass.function as SType).New(m_clsContent, m_emptyParams);
        SInstance         sInstance = (SInstance)retVal.value;

        ProtoReader reader = null;

        try
        {
            reader = ProtoReader.Create(source, null, null, ProtoReader.TO_EOF);
            ReadSInstance(reader, sInstance, m_clsEnv);
            reader.CheckFullyConsumed();
            return(sInstance);
        }
        finally
        {
            ProtoReader.Recycle(reader);
        }
    }
Exemplo n.º 4
0
 // 即时编译token
 protected void RuntimeCompilerTokens(IList <Token> tokens, List <string> types = null)
 {
     for (int i = 0, count = tokens.Count; i < count; i++)
     {
         Token token = tokens[i];
         if (token.type == TokenType.TYPE)
         {
             string className     = token.text;
             CLS_Type_Class stype = m_clsEnv.GetTypeByKeywordQuiet(className) as CLS_Type_Class;
             if (stype != null && !stype.compiled)
             {
                 if (types != null && types.Contains(className))
                 {
                     continue;
                 }
                 RuntimeCompilerClass(className, types);
             }
         }
     }
 }
Exemplo n.º 5
0
    // 调用脚本静态函数
    public object CallStatic(string className, string funName, params object[] _params)
    {
#if UNITY_EDITOR
        try
        {
            if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(funName))
            {
                return(null);
            }
#endif
        CLS_Type_Class type = m_clsEnv.GetTypeByKeywordQuiet(className) as CLS_Type_Class;
        if (type == null)
        {
            Debug.LogWarning(string.Format("CallStatic({0}.{1}): class not found!", className, funName));
            return(null);
        }

        if (!type.compiled)
        {
            RuntimeCompilerClass(className);
        }

        BetterList <CLS_Content.Value> paramList = ScriptParamConvert(_params);
        CLS_Content.Value retVal = type.function.StaticCall(m_clsContent, funName, paramList);
        CLS_Content.PoolParamList(paramList);
        return(retVal != null ? retVal.value : null);

#if UNITY_EDITOR
    }

    catch (System.Exception ex)
    {
        Debug.LogError(DumpStack(ex));
        return(null);
    }
#endif
    }
Exemplo n.º 6
0
 object ReadField(ProtoReader reader, Type memberT, string sClassName, CLS_Environment environment)
 {
     if (memberT == typeof(int))
     {
         return(reader.ReadInt32());
     }
     else if (memberT == typeof(uint))
     {
         return(reader.ReadUInt32());
     }
     else if (memberT == typeof(bool))
     {
         return(reader.ReadBoolean());
     }
     else if (memberT == typeof(byte))
     {
         return(reader.ReadByte());
     }
     else if (memberT == typeof(sbyte))
     {
         return(reader.ReadSByte());
     }
     else if (memberT == typeof(float))
     {
         return(reader.ReadSingle());
     }
     else if (memberT == typeof(double))
     {
         return(reader.ReadDouble());
     }
     else if (memberT == typeof(short))
     {
         return(reader.ReadInt16());
     }
     else if (memberT == typeof(ushort))
     {
         return(reader.ReadUInt16());
     }
     else if (memberT == typeof(long))
     {
         return(reader.ReadInt64());
     }
     else if (memberT == typeof(ulong))
     {
         return(reader.ReadUInt64());
     }
     else if (memberT == typeof(string))
     {
         return(reader.ReadString());
     }
     else if (memberT == typeof(byte[]))
     {
         return(ProtoReader.AppendBytes(null, reader));
     }
     else if (memberT == typeof(SInstance))
     {
         SubItemToken   st     = ProtoReader.StartSubItem(reader);
         CLS_Type_Class sClass = environment.GetTypeByKeywordQuiet(sClassName) as CLS_Type_Class;
         if (!sClass.compiled)
         {
             RuntimeCompilerClass(sClassName);
         }
         CLS_Content       content = CLS_Content.NewContent(environment);
         CLS_Content.Value retVal  = sClass.function.New(content, m_emptyParams);
         CLS_Content.PoolContent(content);
         SInstance sInstance = (SInstance)retVal.value;
         ReadSInstance(reader, sInstance, environment);
         ProtoReader.EndSubItem(st, reader);
         return(sInstance);
     }
     else
     {
         throw new NotImplementedException("未实现类型: " + memberT);
     }
 }