本文整理汇总了C#中GameObject.GetInstanceID方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetInstanceID方法的具体用法?C# GameObject.GetInstanceID怎么用?C# GameObject.GetInstanceID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetInstanceID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddMesh
public bool AddMesh(GameObject go)
{
if (_lut.ContainsKey(go.GetInstanceID())) {
return true;
}
// returns false if renderer is not available
if (go.GetComponent<Renderer>() == null) {
return false;
}
// returns false if not a mesh
MeshFilter mf = (MeshFilter)go.GetComponent (typeof(MeshFilter));
if (mf == null) {
return false;
}
MeshData md = new MeshData ();
md._instID = go.GetInstanceID ();
md._vertCount = mf.mesh.vertexCount;
md._triCount = mf.mesh.triangles.Length / 3;
md._materialCount = go.GetComponent<Renderer>().sharedMaterials.Length;
md._boundSize = go.GetComponent<Renderer>().bounds.size.magnitude;
_lut.Add (md._instID, md);
return true;
}
示例2: RecycleGO
public static bool RecycleGO(GameObject prefab,GameObject instGO)
{
if (msPoolsDict == null)
{
msPoolsDict = new Dictionary<int, Pool_GameObj>();
}
//�ҳ���Ӧ��PoolGameObject
if(prefab == null)
{
IPoolObj poolObj = instGO.GetComponent(typeof(IPoolObj)) as IPoolObj;
prefab = poolObj.Prefab;
if (prefab == null)
{
//Debug.LogWarning("noPrefab ="+instGO.name);
return false;
}
}
Pool_GameObj poolGo = null;
if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo))
{
poolGo = new Pool_GameObj(prefab);
msPoolsDict.Add(prefab.GetInstanceID(), poolGo);
}
poolGo.RecycleGO(instGO);
return true;
}
示例3: GetObject
/// <summary>
/// プールからオブジェクトを取得する
/// </summary>
/// <param name="prefab">プーリングしたゲームオブジェクト</param>
/// <param name="position">セットする座標</param>
/// <param name="rotation">セットする回転</param>
/// <param name="parent">parentに設定するGameObjectのTransform</param>
/// <returns>Active状態にしたゲームオブジェクト</returns>
public GameObject GetObject(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent = null)
{
// キーが存在しない
if (!pooledObject.ContainsKey(prefab.GetInstanceID()))
{
return null;
}
// プールを取得
List<GameObject> pool = pooledObject[prefab.GetInstanceID()];
// 既に生成した分で足りている場合
foreach (var list in pool)
{
if (!list.activeInHierarchy)
{
list.transform.position = position;
list.transform.rotation = rotation;
list.transform.parent = parent;
list.SetActive(true);
return list;
}
}
// 不足していた場合
var obj = Instantiate(prefab, position, rotation) as GameObject;
obj.transform.parent = parent;
pool.Add(obj);
return obj;
}
示例4: Request
public GameObject Request(GameObject prefab, Transform parent, Vector3 position, Quaternion rotation)
{
if (id == 0) id = prefab.GetInstanceID ();
if(id != prefab.GetInstanceID())
{
Debug.LogError(string.Format("Cannot create an isntance of {0} from pool {1}", prefab.name, id));
return null;
}
GameObject instance;
if(free.Count > 0)
{
instance = free[0];
free.Remove(instance);
}
else
{
instance = (GameObject)GameObject.Instantiate(prefab);
}
PlaceObject(instance.transform, parent, position, rotation);
used.Add(instance);
instance.name = prefab.name;
return instance;
}
示例5: castSpell
public void castSpell(GameObject target)
{
if(target.GetComponent("Enchantable") == null)
{
TraceLogger.LogKVtime("attempt", getSpellName());
TraceLogger.LogKV("target", target.GetInstanceID().ToString()+", "+target.name+", "+target.transform.position);
TraceLogger.LogKV("player", ""+ObjectManager.FindById("Me").transform.position);
(GameObject.Find("Popup").GetComponent("Popup") as Popup).popup("Target ("+target.name+") immune to magic.");
SetHidden(false);
return;
}
TraceLogger.LogKVtime("spell", getSpellName());
ProgramLogger.LogKVtime("spell", getSpellName());
TraceLogger.LogKV("target", target.GetInstanceID().ToString()+", "+target.name+", "+target.transform.position);
TraceLogger.LogKV("player", ""+ObjectManager.FindById("Me").transform.position);
June june = new June(target, file_name);
SetHidden(false);
item_name = "Blank";
file_name = "";
animate = false;
inventoryTexture = Resources.Load( "Textures/Scroll") as Texture2D;
(target.GetComponent("Enchantable") as Enchantable).enchant(june, delegate(GameObject t){absorbSpell(t); });
}
示例6: PoolCollectionForGameObject
public static PoolCollection PoolCollectionForGameObject(GameObject go)
{
if( instance._instanceIdToPoolCollection.ContainsKey(go.GetInstanceID())) {
return instance._instanceIdToPoolCollection[go.GetInstanceID()];
}
return null;
}
示例7: SetObject
/// <summary>
/// 新しいプールを生成する
/// </summary>
/// <param name="prefab">プーリングするオブジェクト</param>
/// <param name="createCount">プーリングする数</param>
public void SetObject(GameObject prefab, int createCount)
{
// 連想配列にセット
pooledObject.Add(prefab.GetInstanceID(), new List<GameObject>());
// プーリング
for (int i = 0; i < createCount; i++)
{
GameObject obj = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
pooledObject[prefab.GetInstanceID()].Add(obj);
obj.SetActive(false);
}
}
示例8: PrefabsWillNotGetNewIds
public void PrefabsWillNotGetNewIds()
{
GameObject go = new GameObject(true);
TestComponent cmp = new TestComponent();
go.AddComponent(cmp);
int oldId = go.GetInstanceID();
int oldCmpId = cmp.GetInstanceID();
go.SetNewId(new Dictionary<int, UnityObject>());
Assert.That(go.GetInstanceID(), Is.EqualTo(oldId));
Assert.That(cmp.GetInstanceID(), Is.EqualTo(oldCmpId));
}
示例9: ProducePart
public void ProducePart( GameInfo gameInfo, GameObject myGO, int amount = 1 )
{
int myGOTeam = myGO.GetComponent<Generic_Team>().TeamNum;
if (isServer)
{
List<GameObject> parts = new List<GameObject>();
for ( int i = 0; i < amount; i++ )
{
parts.Add(MakePart( new Vector2( i, 0 ), Vector2.zero, 0.0f, myGOTeam ));
}
List<GameObject> myGO_parts;
myGO_parts = myGO.GetComponent<Unit_PartPlacement>().parts;
myGO_parts.Clear();
int gOID = myGO.GetInstanceID();
//u16 playerID = blob.getPlayer().getNetworkID();
for (int i = 0; i < parts.Count; i++)
{
GameObject gO = parts[i];
myGO_parts.Add( gO );
gO.GetComponent<Part_Info>().OwnerID = gOID;
//b.set_u16( "playerID", playerID );
gO.GetComponent<Part_Info>().ShipID = -1; // don't push on ship
}
}
}
示例10: OnLightEnter
private void OnLightEnter(Light2D l, GameObject g)
{
if (g.GetInstanceID() == id){
c += l.LightColor;
AudioSource.PlayClipAtPoint(hitSound, transform.position, 0.1f);
}
}
示例11: RemoveCache
public void RemoveCache(GameObject tmp)
{
if (cachedItem != null && tmp != null)
if (tmp.GetInstanceID() == cachedItem.GetInstanceID())
tmp = null;
}
示例12: OnLightStay
void OnLightStay(Light2D l, GameObject g)
{
if (g.GetInstanceID() == id)
{
isDetected = true;
}
}
示例13: RopeTubeRenderer
public RopeTubeRenderer(GameObject _gameObject, bool useMeshOnly)
{
if (!useMeshOnly)
{
this._gameObject = _gameObject;
this._transform = _gameObject.transform;
// ensure necessary components //
MeshFilter filter = _gameObject.GetComponent<MeshFilter>();
if (filter == null) filter = _gameObject.AddComponent<MeshFilter>();
MeshRenderer renderer = _gameObject.GetComponent<MeshRenderer>();
if (renderer == null) renderer = _gameObject.AddComponent<MeshRenderer>();
_mesh = new Mesh();
_mesh.name = "RopeTube_" + _gameObject.GetInstanceID();
_mesh.hideFlags = HideFlags.HideAndDontSave;
filter.mesh = _mesh;
if (renderer.sharedMaterial == null)
renderer.sharedMaterial = (Material)Resources.Load("Materials/Rope", typeof(Material));
}
else
{
this._gameObject = _gameObject;
this._transform = _gameObject.transform;
_mesh = new Mesh();
_mesh.name = "RopeTube_" + _gameObject.GetInstanceID();
_mesh.hideFlags = HideFlags.HideAndDontSave;
}
}
示例14: DetectMatches
// here is the function we call from Spawnscript
// scan the array created by the above events
// return a match number
public int DetectMatches(GameObject other)
{
int matches = 0;
if (!other) {
Debug.Log("missing gameobject (other)");
return 0;
}
foreach (GameObject collided in CollidingWith) {
if (!collided) {
Debug.Log("missing gameobject (collided)");
continue;
}
if (other.GetInstanceID() == collided.GetInstanceID()) {
Debug.Log("Avoid nasty hard loop");
continue;
}
if (other.tag == collided.tag) {
matches++;
CurrentMatches.Add(collided);
//CellScript cScript = collided.GetComponent<CellScript>();
//matches += cScript.DetectMatches(collided);
//Debug.Log("Matched: " + matches);
}
}
return matches;
}
示例15: GetGameObject
public GameObject GetGameObject(GameObject prefab, Vector3 position, Quaternion rotation)
{
// 受け取ったprefabのインスタンスIDをkeyとする
int key = prefab.GetInstanceID ();
// オブジェクトプールに指定のKeyなければ新しく生成する
if (pooledGameObjects.ContainsKey (key) == false) {
pooledGameObjects.Add(key, new List<GameObject>());
}
List<GameObject> gameObjects = pooledGameObjects[key];
// ゲームオブジェクトが非アクティブなものを探す
foreach (var tmpGO in gameObjects) {
if(tmpGO.activeInHierarchy == false) {
tmpGO.transform.position = position;
tmpGO.transform.rotation = rotation;
tmpGO.SetActive(true);
return tmpGO;
}
}
// 使用できるものがないのでゲームオブジェクトを新しく生成する
GameObject go = (GameObject)Instantiate (prefab, position, rotation);
go.transform.parent = this.transform;
return go;
}