Skip to content

Instantly share code, notes, and snippets.

@luxuia
luxuia / getprocesstcplistenport.cs
Created May 21, 2020 02:45
get all process listenr and port like netstat but use winapi iphelper
static void GetTCPPort() {
//UnityEngine.Debug.Log("Active Connections");
// UnityEngine.Debug.Log(" Proto Local Address Foreign Address State PID");
var curid = Process.GetCurrentProcess().Id;
var ports = new List<int>();
foreach (TcpRow tcpRow in ManagedIpHelper.GetExtendedTcpTable(true)) {
if (tcpRow.State == TcpState.Listen && tcpRow.ProcessId == curid && tcpRow.LocalEndPoint.Address.ToString().StartsWith("127.0.0.1")) {
try {
Process process = Process.GetProcessById(tcpRow.ProcessId);
材质格式从 [prop_name]: value 转成 -first: name:prop_name second value: xxx
- (.*):\n m_Texture: (.*)
- first:\n name: $1\n second:\n m_Texture: $2
find . -type f -name '*.prefab' -exec sed -i '' -e 's/m_IsPrefabAsset/m_IsPrefabParent/g' {} \;
find . -type f -name '*.unity' -exec sed -i '' -e 's/m_IsPrefabAsset/m_IsPrefabParent/g' {} \;
@luxuia
luxuia / unity_title_change.cs
Last active April 22, 2019 04:38
change editor window's titile.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace lss.editor {
@luxuia
luxuia / set_path by bat.bat
Created December 13, 2018 08:18
set_path by bat.bat
@echo off
::设置要永久加入到path环境变量中的路径
set My_PATH=D:\a2_game\game_res\config\convertor\tools\lua\
set PATH=%PATH%;%My_PATH%
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" /t REG_EXPAND_SZ /d "%PATH%" /f
exit
@luxuia
luxuia / bash.sh
Created December 11, 2018 07:56
add timestamp in log
tail -f file | awk '{now=strftime("%F %T%z\t");sub(/^/, now);print}'
@luxuia
luxuia / file_count_subdir.sh
Created December 11, 2018 07:55
file count in subdir
find . -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -type f | wc -l)" file\(s\)' \;
@luxuia
luxuia / real_assets_file_with_jni.cs
Created November 15, 2018 08:39
sometime need read apk file in unity, with out know file path
public static string ReadFileInAPK(string filepath) {
//取得应用的Activity
var activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
//从Activity取得AssetManager实例
var assetManager = activity.Call<AndroidJavaObject>("getAssets");
//打开文件流
@luxuia
luxuia / create and use obb as zip.cs
Last active November 15, 2018 06:56
unity create obb by hand
[MenuItem("Demo/Build Bundle")]
static void Build()
{
BuildPipeline.BuildAssetBundles("Assets", BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.Android);
FileUtil.DeleteFileOrDirectory ("obb.zip");
var obbFile = ZipFile.Create ("obb.zip");
obbFile.BeginUpdate ();
obbFile.Add ("Assets/bundle", CompressionMethod.Stored);
@luxuia
luxuia / alpha_split.cs
Created November 9, 2018 08:25
unity split alpha channel
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Linq;
namespace USplitAlpha
{
public class SplitAlphaTextureCreator : AssetPostprocessor
@luxuia
luxuia / obb_md5_computer.py
Created November 1, 2018 09:15
计算obb hash的python方法
#!/usr/bin/python
#coding: utf8
import os
import sys
print(str(sys.argv))
obb =sys.argv[1]
def md5(file):