UnityExtensions拓展方法

2021-09-11 16:47:23 字數 4560 閱讀 2489

可以寫一些自己需要經常呼叫的方法在unityextensions指令碼中,方便自己的開發:

比如給物體新增指令碼,順帶檢測該物體是否已經掛載掛該指令碼,避免重複掛載。

static public t addmissingcomponent(this gameobject go) where t : component

#if unity_flash

return (t)comp;

#else

return comp;

#endif

}

using unityengine;

using system;

using system.collections;

using system.collections.generic;

public static class unityextension

static public void switchat(this ilist list,int i1,int i2)

/// /// 設定y,只改變y c

///

///

///

static public void sety(this transform trans, float y)

/// /// 設定z,只改變z c

///

///

///

static public void setz(this transform trans, float z)

/// /// 設定localx,只改變localx c

///

///

///

static public void setlocalx(this transform trans, float x)

/// /// 設定localy,只改變localy c

///

///

///

static public void setlocaly(this transform trans, float y)

/// /// 設定localz,只改變localz c

///

///

///

static public void setlocalz(this transform trans, float z)

/// /// 在遊戲中,朝向的時候只朝向某個座標,不低頭 c

///

///

///

static public void lookatxz(this transform trans, vector3 target)

/// /// 遍歷go c

///

///

///

static public void iterategameobject(this gameobject go, actionhandle)

if (handle != null)}}

/// /// 得到100公尺範圍內腳下地面位置

///

///

///

static public vector3 getgroundpos(this vector3 p)

)))return p;

}/// /// 設定go層級關係 c

///

///

///

static public void setalllayer(this gameobject go,int layer));}

/// /// 只返回平面距離 c

///

///

///

///

static public float distancexz(this vector3 pos, vector3 target)

/// /// 只返回平面距離 c

///

///

///

///

static public float distancexy(this vector3 pos, vector3 target)

/// /// 重置某個物體的三圍等 c

///

///

static public void reset(this gameobject go)

/// /// 給某個物體建立子物體 c

///

///

///

///

static public gameobject creategameobject(this gameobject go,string name)

/// /// 每一幀的移動

///

///

///

///

static public void movetoperframe(this transform t, vector3 p,float speed)

/// /// 刪除某個節點下所有子物體

///

///

static public void deleteallchildren(this transform t)

}/// /// 將z置為負z

///

///

///

static public vector3 reversez(this vector3 v)

/// /// 遍歷往上尋溯com

///

///

///

///

public static t getcomfromparent(this gameobject go) where t:component

else

else}}

return null;

}public static t getparentcomponent(this transform t) where t : component

if (t.parent.getcomponent() != null)

return getparentcomponent(t.parent);

}/// 重置transform

///

public static void resettransformview ( this transform t )

public static material getmaterial ( this renderer render )

#region 碰撞檢測

static public listcheckinsphere(this vector3 startpos, float radius)where t:component

}return list;

}static public listcheckin********(this vector3 startpos, vector3 endpos, float angle) where t:component

}return list;

}static bool isin********(vector3 point, vector3 v0, vector3 v1, vector3 v2)

else

}static float ********area(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y)

static public listcheckinrect(this vector3 startpos, vector3 endpos, float width)where t:component}}

return resultenemies;

}static public bool isinarea(this vector3 p, listpos)

return inside;

}else

}static public vector2 ignorey(this vector3 p)

/// /// 需要自己判斷nan

///

///

///

///

///

static public vector3 getverticalpointofline(this vector3 p,vector3 p1,vector3 p2)

float k = (p2.z - p1.z) / x;

k = mathf.clamp(k, float.minvalue, float.maxvalue);

vector3 pproject = p;

if (k == 0) //垂線斜率不存在情況

else

return pproject;

}static public vector3 getcenter(this listvets)

return new vector3(x / ((float)vets.count), vets[0].y, y / ((float)vets.count));

}#endregion

}

windows 無拓展名檔案設定預設開啟方式

最近重灌了下電腦,出於強迫症想設定無字尾檔案的預設開啟方式,記之。管理員狀態下執行cmd,檢視無拓展的關聯型別 assoc 自定義無字尾檔案對應的檔案型別 此處為no extension,可以自定義 設定關聯 assoc no extension注意在等號後面是沒有空格的!可以發現在設定關聯之前,資...

Linux記憶體拓展(記憶體不足SWAP解決方案)

swap是linux下的交換分割槽,類似windows的虛擬記憶體,當物理記憶體不足時,系統可把一些記憶體中不常用到的程式放入swap,解決物理記憶體不足的情況。若系統安裝時開闢的swap空間太小,可通過手動建立swap檔案。一 建立檔案 dd if dev zero of etc swapfile...

BFS拓展 康拓展開

原諒我我實在不想粘題目了 這道題吧,本來不想加進來的。其實就是對於八數碼問題的乙個補充,上面可愛的出題人已經將康拓展開講的很清楚了。照著敲就行。include using namespace std typedef long long ll inline ll read const ll maxn ...