Exemplo n.º 1
0
        private void SavePreprocessShaders()
        {
            ShaderToolsSetting.GetInstance().PreprocessShadersSettings.Clear();
            for (int iPreprocessShaders = 0; iPreprocessShaders < m_PreprocessShadersForGUIs.Count; iPreprocessShaders++)
            {
                PreprocessShadersForGUI iterPreprocessShadersForGUI = m_PreprocessShadersForGUIs[iPreprocessShaders];
                if (iterPreprocessShadersForGUI.Script == null ||
                    iterPreprocessShadersForGUI.Setting == null)
                {
                    continue;
                }

                try
                {
                    iterPreprocessShadersForGUI.Setting.OnSaveByGUI();

                    PreprocessShadersSetting preprocessShadersSetting = new PreprocessShadersSetting();
                    preprocessShadersSetting.MonoScriptGUID         = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(iterPreprocessShadersForGUI.Script));
                    preprocessShadersSetting.MonoScriptTypeFullName = iterPreprocessShadersForGUI.Script.GetClass().FullName;
                    preprocessShadersSetting.SettingJson            = JsonUtility.ToJson(iterPreprocessShadersForGUI.Setting);
                    ShaderToolsSetting.GetInstance().PreprocessShadersSettings.Add(preprocessShadersSetting);
                }
                catch (Exception e)
                {
                    MDebug.LogWarning("Shader", $"保存Shader处理失败\n{e.ToString()}");
                }
            }
        }
Exemplo n.º 2
0
 void TriggerDelayed(Speech speech, float delay)
 {
     if (speech != null)
     {
         StartCoroutine(M_Math.ExecuteDelayed(delay, () => TriggerSpeech(m_Unit, speech.Lines)));
     }
     else
     {
         MDebug.LogWarning("speech not found");
     }
 }
        private static int Warning(IntPtr luaState)
        {
            int success = GetLog(luaState, out string tag, out string message);

            if (success == 1)
            {
                MDebug.LogWarning(tag, message);
            }

            return(success);
        }
Exemplo n.º 4
0
        public string Format(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                MDebug.LogWarning(LOG_TAG, $"Format string IsNullOrEmpty!  AssetPath:{AssetPath},");
            }
            m_FormatedCache.Clear();
            m_SignCache.Clear();

            bool isSign = false;

            for (int iChar = 0; iChar < text.Length; iChar++)
            {
                char iterChar = text[iChar];
                switch (iterChar)
                {
                case '{':
                    if (isSign)
                    {
                        throw new Exception("NameFormat Not Support : ‘{’ 嵌套");
                    }
                    isSign = true;
                    break;

                case '}':
                    if (!isSign)
                    {
                        throw new Exception("'{}' Need appear in pairs");
                    }
                    isSign = false;
                    string sign = m_SignCache.ToString().ToUpper();
                    m_SignCache.Clear();
                    AppendSign(sign);
                    break;

                default:
                    if (isSign)
                    {
                        m_SignCache.Append(iterChar);
                    }
                    else
                    {
                        m_FormatedCache.Append(iterChar);
                    }
                    break;
                }
            }

            return(m_FormatedCache.ToString());
        }
Exemplo n.º 5
0
        public void CheckMemoryLeak()
        {
            long currentTime = MDebug.GetMillisecondsSinceStartup();

            for (int iObject = 0; iObject < m_Using.Count; iObject++)
            {
                UsingObject usingObject = m_Using[iObject];
                if (currentTime - usingObject.WhenBeUse > m_MemoryLeakMilliseconds)
                {
                    MDebug.LogWarning("Pool"
                                      , $"Object in ObjectPool<{typeof(T).FullName}> be used {(currentTime - usingObject.WhenBeUse) * 0.001:F2} seconds ago, maybe memory leak!\n({usingObject.ToString()})");
                }
            }
        }
Exemplo n.º 6
0
        private void TryGenerateSetting(int preprocessShadersIndex
                                        , PreprocessShadersForGUI preprocessShadersForGUI)
        {
            for (int iPreprocessShaders = 0; iPreprocessShaders < m_PreprocessShadersForGUIs.Count; iPreprocessShaders++)
            {
                if (iPreprocessShaders == preprocessShadersIndex)
                {
                    continue;
                }
                PreprocessShadersForGUI iterPreprocessShadersForGUI = m_PreprocessShadersForGUIs[iPreprocessShaders];
                if (iterPreprocessShadersForGUI.Script == preprocessShadersForGUI.Script)
                {
                    MDebug.LogWarning("Shader", "不能选择两个相同的脚本");
                    preprocessShadersForGUI.Script = null;
                    return;
                }
            }

            Type type = preprocessShadersForGUI.Script.GetClass();

            if (type.IsAbstract)
            {
                MDebug.LogWarning("Shader", "不能是Abstract类");
                preprocessShadersForGUI.Script = null;
                return;
            }
            try
            {
                Type baseType = type;
                while (true)
                {
                    baseType = baseType.BaseType;
                    if (baseType.IsGenericType)
                    {
                        break;
                    }
                }
                Type   settingType = baseType.GenericTypeArguments[0];
                object preprocessShadersSetting = settingType.Assembly.CreateInstance(settingType.FullName);
                preprocessShadersForGUI.Setting = preprocessShadersSetting as BasePreprocessShadersSetting;
            }
            catch (Exception e)
            {
                MDebug.LogError("Shader", "生成Setting失败\n" + e.ToString());
                preprocessShadersForGUI.Script = null;
            }
        }
Exemplo n.º 7
0
        private void LoadPreprocessShaders()
        {
            m_PreprocessShadersForGUIs.Clear();
            List <PreprocessShadersSetting> preprocessShadersSettings = ShaderToolsSetting.GetInstance().PreprocessShadersSettings;

            for (int iPreprocessShaders = 0; iPreprocessShaders < preprocessShadersSettings.Count; iPreprocessShaders++)
            {
                PreprocessShadersSetting iterPreprocessShadersSetting = preprocessShadersSettings[iPreprocessShaders];
                try
                {
                    PreprocessShadersForGUI preprocessShadersForGUI = new PreprocessShadersForGUI();
                    preprocessShadersForGUI.Script = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(iterPreprocessShadersSetting.MonoScriptGUID)) as MonoScript;
                    if (preprocessShadersForGUI.Script == null)
                    {
                        continue;
                    }

                    Type baseType = preprocessShadersForGUI.Script.GetClass();
                    while (true)
                    {
                        baseType = baseType.BaseType;
                        if (baseType.IsGenericType)
                        {
                            break;
                        }
                    }
                    Type settingType = baseType.GenericTypeArguments[0];
                    preprocessShadersForGUI.Setting = JsonUtility.FromJson(iterPreprocessShadersSetting.SettingJson
                                                                           , settingType) as BasePreprocessShadersSetting;
                    if (preprocessShadersForGUI.Setting == null)
                    {
                        continue;
                    }

                    preprocessShadersForGUI.Setting.OnLoadByGUI();

                    m_PreprocessShadersForGUIs.Add(preprocessShadersForGUI);
                }
                catch (Exception e)
                {
                    MDebug.LogWarning("Shader", $"加载Shader处理失败\n{e.ToString()}");
                }
            }
        }
        protected static T Load <T>(string settingName)
            where T : BaseProjectSetting, new()
        {
            T      setting     = null;
            string settingPath = string.Format(SETTING_PATH_FORMAT, settingName);

            try
            {
                setting = JsonUtility.FromJson <T>(File.ReadAllText(settingPath));
            }
            catch (Exception e)
            {
                MDebug.LogWarning("Setting", $"Load BuildSetting({settingPath}) Exception:\n{e.ToString()}");
            }

            if (setting == null)
            {
                setting = new T();
                setting.Initialize();
            }
            return(setting);
        }
Exemplo n.º 9
0
        public override object OnTaskUpdate_Thread(object input, float deltaTime)
        {
            unsafe
            {
                int   bufferLength = CallLuaAPI.lua_gfloginternal_getbufferlength();
                byte *logBuffer    = (byte *)CallLuaAPI.lua_gfloginternal_getbuffer().ToPointer();
                CallLuaAPI.lua_gfloginternal_swapbuffer();
                while (bufferLength > 0)
                {
                    logBuffer = ConvertToIntFromLogBuffer(logBuffer, ref bufferLength, out int type);
                    logBuffer = ConvertToStringFromLogBuffer(logBuffer, ref bufferLength, out string tag);
                    logBuffer = ConvertToStringFromLogBuffer(logBuffer, ref bufferLength, out string message);

                    switch (type)
                    {
                    case LOGTYPE_VERBOSE:
                        MDebug.LogVerbose(tag, message);
                        break;

                    case (int)LogType.Log:
                        MDebug.Log(tag, message);
                        break;

                    case (int)LogType.Warning:
                        MDebug.LogWarning(tag, message);
                        break;

                    case (int)LogType.Error:
                        MDebug.LogError(tag, message);
                        break;

                    default:
                        throw new Exception("Not handle LogType: " + type);
                    }
                }
            }
            return(null);
        }
        public static void RegistStartupTabs()
        {
            List <ReflectionUtility.TypeAndAttributeData> tabTypes = new List <ReflectionUtility.TypeAndAttributeData>();

            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            for (int iAssembly = 0; iAssembly < assemblies.Length; iAssembly++)
            {
                ReflectionUtility.CollectionTypeWithAttribute(tabTypes
                                                              , assemblies[iAssembly]
                                                              , typeof(StartupTabAttribute)
                                                              , false);
            }

            for (int iTab = 0; iTab < tabTypes.Count; iTab++)
            {
                ReflectionUtility.TypeAndAttributeData iterTabData = tabTypes[iTab];
                try
                {
                    StartupTabAttribute iterAttribute = (StartupTabAttribute)iterTabData.Attribute;
                    if (iterAttribute.OnlyRuntime &&
                        Application.isEditor)
                    {
                        continue;
                    }
                    ITab iterTab = (ITab)iterTabData.Type.Assembly.CreateInstance(iterTabData.Type.FullName);
                    _ms_Instance.RegistGUI(iterAttribute.TabName
                                           , iterTab.DoGUI
                                           , iterAttribute.OnlyRuntime);
                }
                catch (Exception e)
                {
                    MDebug.LogWarning("DebugPanel"
                                      , $"加载DebugPanel.Tab({iterTabData.Type.FullName})失败\n{e.ToString()}");
                }
            }
        }
Exemplo n.º 11
0
        public static Dictionary <string, MethodInfo> GetOrCollectAllStaticMethods()
        {
            if (ms_AllStaticMethods == null)
            {
                ms_AllStaticMethods = new Dictionary <string, MethodInfo>();

                List <ReflectionUtility.MethodAndAttributeData> staticMethodDatas = new List <ReflectionUtility.MethodAndAttributeData>();
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                for (int iAssembly = 0; iAssembly < assemblies.Length; iAssembly++)
                {
                    ReflectionUtility.CollectionMethodWithAttribute(staticMethodDatas
                                                                    , assemblies[iAssembly]
                                                                    , BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public
                                                                    , typeof(StaticMethodAttribute)
                                                                    , false);
                }

                StringBuilder methodSignBuilder = StringUtility.AllocStringBuilder();
                for (int iMethod = 0; iMethod < staticMethodDatas.Count; iMethod++)
                {
                    ReflectionUtility.MethodAndAttributeData iterStaticMethodData = staticMethodDatas[iMethod];
                    StaticMethodAttribute iterAttribute = iterStaticMethodData.Attribute as StaticMethodAttribute;
                    methodSignBuilder.Append(string.IsNullOrEmpty(iterAttribute.Alias)
                        ? iterStaticMethodData.Method.Name
                        : iterAttribute.Alias);

                    ParameterInfo[] parameterInfos = iterStaticMethodData.Method.GetParameters();
                    for (int iParameter = 0; iParameter < parameterInfos.Length; iParameter++)
                    {
                        ParameterInfo iterParameter     = parameterInfos[iParameter];
                        Type          iterParameterType = iterParameter.ParameterType;
                        if (iterParameterType.IsValueType)
                        {
                            if (iterParameterType == typeof(byte))
                            {
                                AppendValueType(methodSignBuilder, ValueType.Byte);
                            }
                            else if (iterParameterType == typeof(int))
                            {
                                AppendValueType(methodSignBuilder, ValueType.Int);
                            }
                            else if (iterParameterType == typeof(short))
                            {
                                AppendValueType(methodSignBuilder, ValueType.Short);
                            }
                            else if (iterParameterType == typeof(long))
                            {
                                AppendValueType(methodSignBuilder, ValueType.Long);
                            }
                            else if (iterParameterType == typeof(float))
                            {
                                AppendValueType(methodSignBuilder, ValueType.Float);
                            }
                            else if (iterParameterType == typeof(double))
                            {
                                AppendValueType(methodSignBuilder, ValueType.Double);
                            }
                            // struct
                            else if (!iterParameterType.IsPrimitive)
                            {
                                MDebug.Assert(false
                                              , "Rpc"
                                              , $"Not support ParameterType {iterParameterType}");
                            }
                            else
                            {
                                MDebug.LogWarning("Rpc"
                                                  , $"Not support ParameterType: {iterParameterType} (IsValueType). But maybe we can support it.");
                            }
                        }
                        else if (iterParameterType.IsArray)
                        {
                            AppendValueType(methodSignBuilder, ValueType.FixedValueTypeArray);
                        }
                        else
                        {
                            MDebug.Assert(false
                                          , "Rpc"
                                          , $"Not support ParameterType {iterParameterType}");
                        }
                    }

                    string methodSign = methodSignBuilder.ToString();
                    methodSignBuilder.Clear();
#if GF_DEBUG
                    MDebug.Assert(!ms_AllStaticMethods.ContainsKey(methodSign)
                                  , "Rpc"
                                  , "!ms_AllStaticMethods.ContainsKey(methodSign)");
#endif
                    ms_AllStaticMethods[methodSign] = iterStaticMethodData.Method;
                }

                methodSignBuilder.Clear();
                foreach (KeyValuePair <string, MethodInfo> kv in ms_AllStaticMethods)
                {
                    methodSignBuilder.AppendLine(kv.Key);
                }
                MDebug.Log("Rpc"
                           , "All static methods:\n" + methodSignBuilder);
            }

            return(ms_AllStaticMethods);
        }