Ejemplo n.º 1
0
        static int _m_FindIndex(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.Collections.Generic.List <string> gen_to_be_invoked = (System.Collections.Generic.List <string>)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && translator.Assignable <System.Predicate <string> >(L, 2))
                {
                    System.Predicate <string> _match = translator.GetDelegate <System.Predicate <string> >(L, 2);

                    int gen_ret = gen_to_be_invoked.FindIndex(
                        _match);
                    LuaAPI.xlua_pushinteger(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 3 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && translator.Assignable <System.Predicate <string> >(L, 3))
                {
                    int _startIndex = LuaAPI.xlua_tointeger(L, 2);
                    System.Predicate <string> _match = translator.GetDelegate <System.Predicate <string> >(L, 3);

                    int gen_ret = gen_to_be_invoked.FindIndex(
                        _startIndex,
                        _match);
                    LuaAPI.xlua_pushinteger(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 4 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && translator.Assignable <System.Predicate <string> >(L, 4))
                {
                    int _startIndex = LuaAPI.xlua_tointeger(L, 2);
                    int _count      = LuaAPI.xlua_tointeger(L, 3);
                    System.Predicate <string> _match = translator.GetDelegate <System.Predicate <string> >(L, 4);

                    int gen_ret = gen_to_be_invoked.FindIndex(
                        _startIndex,
                        _count,
                        _match);
                    LuaAPI.xlua_pushinteger(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to System.Collections.Generic.List<string>.FindIndex!"));
        }
Ejemplo n.º 2
0
        internal static int ListIndexOf(System.Collections.Generic.List <IBluetoothDeviceInfo> list, IBluetoothDeviceInfo item)
        {
            int idx = list.FindIndex(
                delegate(IBluetoothDeviceInfo cur) { return(item.DeviceAddress.Equals(cur.DeviceAddress)); });

            return(idx);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 搜索指定的对象的索引位置(名称唯一模式时,按名称匹配)。
 /// </summary>
 /// <param name="item">为null直接返回-1。</param>
 /// <returns>返回搜索到的索引位置,未找到时返回-1。</returns>
 public int IndexOf(IParameterInfo item)
 {
     if (item == null || _list.Count == 0)
     {
         return(-1);
     }
     if (_nameOnly)
     {
         StringComparison comparison = _ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
         return(_list.FindIndex(p => string.Equals(p.Name, item.Name, comparison)));
     }
     return(_list.IndexOf(item));
 }
Ejemplo n.º 4
0
 static public int FindIndex(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             System.Collections.Generic.List <WWWRequest> self = (System.Collections.Generic.List <WWWRequest>)checkSelf(l);
             System.Predicate <WWWRequest> a1;
             checkDelegate(l, 2, out a1);
             var ret = self.FindIndex(a1);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 3)
         {
             System.Collections.Generic.List <WWWRequest> self = (System.Collections.Generic.List <WWWRequest>)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             System.Predicate <WWWRequest> a2;
             checkDelegate(l, 3, out a2);
             var ret = self.FindIndex(a1, a2);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 4)
         {
             System.Collections.Generic.List <WWWRequest> self = (System.Collections.Generic.List <WWWRequest>)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             System.Int32 a2;
             checkType(l, 3, out a2);
             System.Predicate <WWWRequest> a3;
             checkDelegate(l, 4, out a3);
             var ret = self.FindIndex(a1, a2, a3);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function FindIndex to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        public Student Update(int id, Student student)
        {
            if (student == null)
            {
                return(null);
            }
            int index = _students.FindIndex(student => student.Id == id);

            if (index == -1)
            {
                return(null);
            }
            _students.RemoveAt(index);
            _students.Add(student);
            return(student);
        }
Ejemplo n.º 6
0
 public static void Update(int ID, string Name, IPAddress IP, string Serial, string Ver)
 {
     if (Players.Find(x => x.ID == ID) != null)
     {
         Players.RemoveAt(Players.FindIndex(x => x.ID == ID));
         Players.Add(new BPlayer()
         {
             ID = ID, Name = Name, IP = IP, Serial = Serial, GameVersion = Ver
         });
     }
     else
     {
         Players.Add(new BPlayer()
         {
             ID = ID, Name = Name, IP = IP, Serial = Serial, GameVersion = Ver
         });
     }
 }
Ejemplo n.º 7
0
        public override void ModifyInterfaceLayers(System.Collections.Generic.List <GameInterfaceLayer> layers)
        {
            int MouseTextIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));

            if (MouseTextIndex != -1)
            {
                layers.Insert(MouseTextIndex, new LegacyGameInterfaceLayer(
                                  "DrakSolz: Souls",
                                  delegate {
                    if (SoulUI.visible)
                    {
                        userInterface.Update(Main._drawInterfaceGameTime);
                        ui.Draw(Main.spriteBatch);
                    }
                    return(true);
                },
                                  InterfaceScaleType.UI));
            }
        }
        /// <summary>
        /// 设置shader相关,shader特殊打包设置
        /// </summary>
        public static void SetShaderSettings()
        {
            // 手动添加的一些要使用到的shader,将会被设置到alwaysIncludedShaders里面
            string[] originShaders = new string[0] {
                //"Nature/Terrain/Diffuse",
            };

            // 不会被设置到alwaysIncludedShaders里面得shader
            System.Collections.Generic.List <string> ignoreShaderList = new System.Collections.Generic.List <string>();
            ignoreShaderList.Add("Standard");
            ignoreShaderList.Add("Hidden/InternalErrorShader");

            // 遍历Application.dataPath/ResourcesCopy文件夹,查找所有的自建shader
            System.Collections.Generic.List <string> customShaderNameList     = new System.Collections.Generic.List <string>();
            System.Collections.Generic.List <string> customShaderFilePathList = new System.Collections.Generic.List <string>();

            string[] filePaths = Directory.GetFiles(Application.dataPath + resToBundleDir, "*.shader", SearchOption.AllDirectories);
            if (filePaths != null &&
                filePaths.Length > 0)
            {
                for (int i = 0; i < filePaths.Length; i++)
                {
                    string str = File.ReadAllText(filePaths[i]);

                    // 查找shader名字的字符串
                    System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("^( *)Shader( *)\"(.*?)\"",
                                                                                                       System.Text.RegularExpressions.RegexOptions.Compiled
                                                                                                       | System.Text.RegularExpressions.RegexOptions.Multiline);
                    System.Text.RegularExpressions.MatchCollection matches = rx.Matches(str);

                    if (matches.Count == 1)
                    {
                        string title = matches[0].Value;
                        // 查找shader名字的字符串
                        System.Text.RegularExpressions.Regex realNameRx = new System.Text.RegularExpressions.Regex("\"(.*?)\"",
                                                                                                                   System.Text.RegularExpressions.RegexOptions.Compiled);
                        System.Text.RegularExpressions.MatchCollection realNamematches = realNameRx.Matches(title);
                        if (realNamematches.Count == 1)
                        {
                            // 去掉前后引号
                            string shaderName = realNamematches[0].Value;
                            shaderName = shaderName.Substring(1, shaderName.Length - 2);

                            // 检查重复shader
                            if (customShaderNameList.Contains(shaderName))
                            {
                                int    index  = customShaderNameList.FindIndex(s => s.Equals(shaderName));
                                string logStr = string.Format("有重复的shader name:{0} \n, path: {1}\npath: {2}", customShaderNameList[i], filePaths[i], customShaderFilePathList[index]);
                                Debug.LogError(logStr);
                                return;
                            }

                            customShaderNameList.Add(shaderName);
                            customShaderFilePathList.Add(filePaths[i]);
                            Debug.Log("shader name:" + shaderName + " path: " + filePaths[i]);
                        }
                        else
                        {
                            Debug.LogError("shader name analysis error! " + realNamematches.Count + filePaths[i]);
                        }
                    }
                    else
                    {
                        Debug.LogError("shader name analysis error! " + matches.Count + filePaths[i]);
                    }
                }
            }

            // 查找在工程中已经被material引用到的shader
            System.Collections.Generic.List <string> usedShaderNameList = new System.Collections.Generic.List <string>();
            string objPath = Application.dataPath + resToBundleDir;

            string[] directoryEntries;
            try
            {
                directoryEntries = System.IO.Directory.GetFiles(objPath, "*", SearchOption.AllDirectories);

                for (int i = 0; i < directoryEntries.Length; i++)
                {
                    string   p         = directoryEntries[i];
                    string[] tempPaths = p.Split(new string[] { "/Assets/" }, System.StringSplitOptions.None);
                    int      length    = tempPaths.Length;
                    if (length >= 1 &&
                        tempPaths[length - 1].EndsWith(".mat"))
                    {
                        Material mat = AssetDatabase.LoadAssetAtPath("Assets/" + tempPaths[length - 1], typeof(Material)) as Material;
                        // 检查是否使用了Standard shader,抛出错误
                        if (mat != null &&
                            ignoreShaderList.Contains(mat.shader.name))
                        {
                            Debug.LogError("禁止使用" + mat.shader.name + " shader, Material path: " + "Assets/" + tempPaths[length - 1]);
                        }

                        if (mat != null &&
                            usedShaderNameList.Contains(mat.shader.name) == false)
                        {
                            usedShaderNameList.Add(mat.shader.name);
                        }
                    }
                }
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                Debug.Log("The path encapsulated in the " + objPath + "Directory object does not exist.");
            }

            // 找出使用到的内置shader,加入到AlwaysIncludedShaders
            System.Collections.Generic.List <string> buildInToIncludeShaders = new System.Collections.Generic.List <string>();
            for (int i = 0; i < usedShaderNameList.Count; i++)
            {
                if (customShaderNameList.Contains(usedShaderNameList[i]) == false &&
                    ignoreShaderList.Contains(usedShaderNameList[i]) == false)
                {
                    buildInToIncludeShaders.Add(usedShaderNameList[i]);
                    Debug.Log("build in shader: " + usedShaderNameList[i]);
                }
            }

            // 将在工程中未被引用到的自建shader加入到AlwaysIncludedShaders
            //for (int i = 0; i < customShaderNameList.Count; i++)
            //{
            //    if (usedShaderNameList.Contains(customShaderNameList[i]) == false)
            //    {
            //        buildInToIncludeShaders.Add(customShaderNameList[i]);
            //    }
            //}

            // 手动添加的shader加入到AlwaysIncludedShaders
            for (int i = 0; i < originShaders.Length; i++)
            {
                if (buildInToIncludeShaders.Contains(originShaders[i]) == false &&
                    ignoreShaderList.Contains(originShaders[i]) == false)
                {
                    buildInToIncludeShaders.Add(originShaders[i]);
                    Debug.Log("orgin shader: " + originShaders[i]);
                }
            }

            // 过滤掉重复的shader
            for (int i = 0; i < buildInToIncludeShaders.Count; i++)
            {
                for (int j = i + 1; j < buildInToIncludeShaders.Count;)
                {
                    if (buildInToIncludeShaders[i].Equals(buildInToIncludeShaders[j]))
                    {
                        buildInToIncludeShaders.RemoveAt(j);
                    }
                    else
                    {
                        j++;
                    }
                }
            }

            // 设置AlwaysIncludedShaders
            SerializedObject   graphicsSettings = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/GraphicsSettings.asset")[0]);
            SerializedProperty it = graphicsSettings.GetIterator();
            SerializedProperty dataPoint;

            while (it.NextVisible(true))
            {
                if (it.name == "m_AlwaysIncludedShaders")
                {
                    it.ClearArray();

                    for (int i = 0; i < buildInToIncludeShaders.Count; i++)
                    {
                        if (ignoreShaderList.Contains(buildInToIncludeShaders[i]) == false)
                        {
                            it.InsertArrayElementAtIndex(i);
                            dataPoint = it.GetArrayElementAtIndex(i);
                            dataPoint.objectReferenceValue = Shader.Find(buildInToIncludeShaders[i]);
                        }
                    }

                    graphicsSettings.ApplyModifiedProperties();
                }
            }

            // 设置自建shader文件包名
            for (int i = 0; i < customShaderNameList.Count; i++)
            {
                if (customShaderFilePathList.Count > i)
                {
                    _SetAssetBundleNameAndVariant(customShaderFilePathList[i], false, false, "shader/src/" + customShaderNameList[i]);
                }
            }

            Debug.Log("set shader settings success!");
        }
Ejemplo n.º 9
0
 public int FindIndex(Predicate <T> match)
 {
     return(list.FindIndex(match));
 }