本文整理汇总了C#中Transform.GetInstanceID方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.GetInstanceID方法的具体用法?C# Transform.GetInstanceID怎么用?C# Transform.GetInstanceID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transform
的用法示例。
在下文中一共展示了Transform.GetInstanceID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckState
public void CheckState(Transform trans)
{
if(trans != null)
{
if(trans.gameObject.layer == LayerMask.NameToLayer("AvailableTile"))
{
if(!G.i.StageM.UsedTileMap.ContainsKey(trans.GetInstanceID().ToString()))
{
SetAvailableState();
}
else
{
SetImpossibleState();
}
}
else if(trans.gameObject.layer == LayerMask.NameToLayer("ImpossibleTile"))
{
SetImpossibleState();
}
else if(trans.gameObject.layer == LayerMask.NameToLayer("Tower"))
{
SetImpossibleState();
}
}
}
示例2: waiteForVisualContact
public bool waiteForVisualContact(Transform target)
{
if (visSensor.LatestDetectedObject != null)
{
if (visSensor.LatestDetectedObject.GetInstanceID() == target.GetInstanceID()) return true;
else return false;
}
else return false;
}
示例3: EnterPlanetGravity
public void EnterPlanetGravity(Transform _enteredPlanet)
{
if(!_isInPlanetGravity) {
_currentPlanetInstanceID = _enteredPlanet.GetInstanceID();
_planetGravityDistance = Vector3.Distance(transform.position, _enteredPlanet.position);
_isInPlanetGravity = true;
_planet = _enteredPlanet;
}
}
示例4: ukloniCilj
public void ukloniCilj(Transform cilj)
{
for (int i = 0; i < ciljeviLista.Count; i++) {
if (ciljeviLista [i].GetInstanceID() == cilj.GetInstanceID()) {
ciljeviLista.Remove (cilj);
}
}
}
示例5: ExitPlanetGravity
public void ExitPlanetGravity(Transform _exitPlanet)
{
if(_isInPlanetGravity) {
if(_currentPlanetInstanceID == _exitPlanet.GetInstanceID()) {
_currentPlanetInstanceID = 0;
_planetGravityDistance = 0;
_isInPlanetGravity = false;
_planet = null;
}
}
}
示例6: FindAllNeighbors
public static void FindAllNeighbors(Transform deletingAttachment, Transform startingFrom = null)
{
//excluding self, can all other pieces connect to the center?
if (startingFrom == null)
startingFrom = GameObject.FindGameObjectWithTag("Player").transform; //set our starting node
if (!visitedNodes.Contains(deletingAttachment.GetInstanceID()))
visitedNodes.Add(deletingAttachment.GetInstanceID()); //add the node we're trying to delete, so we skip over it
//start at center at linecast in every direction
RaycastHit2D[] hits;
float distance = 0.9f; // may want to play with this value, as it might reach too far and catch attachments that shouldn't be caught
for (int i = 0; i < BuildingManager.Directions.Count; i++)
{
float[] localDir = new float[2] { BuildingManager.ToDirFromSpot(i)[0], BuildingManager.ToDirFromSpot(i)[1] };
localDir[0] *= 0.9f;
localDir[1] *= 0.9f;
hits = Physics2D.LinecastAll(new Vector2(startingFrom.position.x + localDir[0], startingFrom.position.y + localDir[1]),
new Vector2(startingFrom.position.x + (localDir[0] * distance), startingFrom.position.y + (localDir[1] * distance)));
// see where the linecast is going
//Debug.DrawLine(new Vector3(startingFrom.position.x + localDir[0], startingFrom.position.y + localDir[1]),
// new Vector3(startingFrom.position.x + (localDir[0] * distance), startingFrom.position.y + (localDir[1] * distance)), Color.blue, 10.0f, false);
for (var j = 0; j < hits.Length; j++)
{
Transform attachment = hits[j].collider.transform.parent; // 'parent' because it's hitting the child 2D collider
if (attachment.GetComponent<Attachments>() != null && // is actually an attachment
!visitedNodes.Contains(attachment.GetInstanceID())) // haven't visited it
{
visitedNodes.Add(attachment.GetInstanceID());
attachment.GetComponent<Attachments>().wasFound = true; //set all the attachments to 'found' if they're part of our hit list
FindAllNeighbors(deletingAttachment, attachment); //recurse into them
}
}
}
}
示例7: DeleteEnemy
public void DeleteEnemy(Transform dead)
{
Transform[] newEnemies = new Transform[enemies.Length - 1];
int j = 0;
for(int i=0; i<enemies.Length; i++){
Transform t = enemies[i];
if(t.GetInstanceID() != dead.GetInstanceID()){
newEnemies[j] = enemies[i];
j++;
}
}
enemies = newEnemies;
}
示例8: CheckDirectSightOnTransform
protected bool CheckDirectSightOnTransform(Transform target) {
Vector3 direction = target.transform.position - transform.position;
float angle = Vector3.Angle(direction, transform.forward);
//Debug.Log(angle);
if (angle < LOSAngle * 0.5f) {
RaycastHit hit;
if (Physics.Raycast(transform.position, direction.normalized, out hit, SightRange)) {
//Debug.Log(hit.collider.tag + " " + hit.collider.name);
//Debug.DrawLine(transform.position, hit.point, Color.cyan, 10f);
if (hit.collider.transform.GetInstanceID() == target.GetInstanceID()) {
//Debug.Log("Found enemy");
if (OverWatchOn) {
OverWatchResponse(target);
}
return true;
}
}
}
return false;
}
示例9: RectRotateControl
// A few draggable corner points (rotation), returns change in angle (around 0,0 local to Rect)
public static float RectRotateControl( int controlId, Rect r, Transform t, List<int> hideCornerPts) {
Event ev = Event.current;
bool guiChanged = false;
GUIStyle style = tk2dEditorSkin.RotateHandle;
r.xMin *= t.localScale.x;
r.yMin *= t.localScale.y;
r.xMax *= t.localScale.x;
r.yMax *= t.localScale.y;
Vector3 cachedScale = t.localScale;
t.localScale = new Vector3(1.0f, 1.0f, 1.0f);
r = PositiveRect(r);
Vector2[] corners = { new Vector2(0.0f, 0.0f), new Vector2(1.0f, 0.0f),
new Vector2(0.0f, 1.0f), new Vector2(1.0f, 1.0f)};
Vector2[] handleCursorN = new Vector2[] {
new Vector2(1.0f, -1.0f), new Vector2(1.0f, 1.0f),
new Vector2(-1.0f, -1.0f), new Vector2(-1.0f, 1.0f)
};
Vector3[] worldPts = new Vector3[4];
Vector2[] guiPts = new Vector2[4];
for (int i = 0; i < 4; ++i) {
Vector3 p = new Vector3( r.xMin + r.width * corners[i].x, r.yMin + r.height * corners[i].y, 0);
worldPts[i] = t.TransformPoint (p);
guiPts[i] = HandleUtility.WorldToGUIPoint(worldPts[i]);
}
// Exit early if handle screen distance is too small
{
float edgeLengthBottom = (guiPts[0] - guiPts[1]).magnitude;
float edgeLengthLeft = (guiPts[0] - guiPts[2]).magnitude;
if (edgeLengthBottom < handleClosenessClip || edgeLengthLeft < handleClosenessClip) {
return 0.0f; // no rotation
}
}
float result = 0.0f;
for (int i = 0; i < 4; ++i) {
if (!hideCornerPts.Contains (i)) {
Vector3 p = new Vector3( r.xMin + r.width * corners[i].x, r.yMin + r.height * corners[i].y, 0);
Vector3 worldPt = worldPts[i];
MouseCursor cursor = GetHandleCursor(handleCursorN[i], t);
EditorGUI.BeginChangeCheck();
Vector3 newWorldPt = MoveHandle(controlId + t.GetInstanceID() + "Rotate".GetHashCode() + i, worldPt, t.forward, style, cursor);
if (EditorGUI.EndChangeCheck()) {
Vector3 d0 = p;
Vector3 d1 = t.InverseTransformPoint (newWorldPt);
d0.Normalize();
d1.Normalize();
float ang = Mathf.Acos(Vector3.Dot(d0, d1)) * Mathf.Rad2Deg;
float sgn = Mathf.Sign(Vector3.Dot( Vector3.Cross(t.forward, d0), d1));
result = ang * sgn;
guiChanged = true;
HandleUtility.Repaint();
}
}
}
t.localScale = cachedScale;
if (ev.shift) {
float snapAngle = 9.0f;
result = (float)((int)(result / snapAngle)) * snapAngle;
}
if (guiChanged) {
GUI.changed = true;
}
return result;
}
示例10: processMesh
static string processMesh(Transform t)
{
StringBuilder meshString = new StringBuilder();
Terrain terrain = t.gameObject.GetComponent<Terrain>();
if (!terrain)
{
MeshFilter mf = t.GetComponent<MeshFilter>();
if (mf)
{
long idTriangleMesh;
triangleMeshIds.TryGetValue(t.GetInstanceID(), out idTriangleMesh);
meshString.Append(ExportToPhysXScript.MeshToString(mf.sharedMesh, idTriangleMesh));
}
for (int i = 0; i < t.childCount; i++)
{
meshString.Append(processMesh(t.GetChild(i)));
}
}
else
{
long idTriangleMesh;
triangleMeshIds.TryGetValue(t.GetInstanceID(), out idTriangleMesh);
Mesh m = ExportToPhysXScript.createMesh(terrain.terrainData, t.position);
meshString.Append(ExportToPhysXScript.MeshToString(m, idTriangleMesh));
}
return meshString.ToString();
}
示例11: HandleMoveSprites
public static void HandleMoveSprites(Transform t, Rect rect) {
Event ev = Event.current;
// Only enable in View mode, if requested
if (!tk2dPreferences.inst.enableMoveHandles && Tools.current != Tool.View) {
return;
}
// Break out if vertex modifier is active
if (IsSnapToVertexActive()) {
return;
}
int controlId = t.GetInstanceID();
Plane plane = new Plane(t.forward, t.position);
Ray mouseRay = HandleUtility.GUIPointToWorldRay(ev.mousePosition);
rect = PositiveRect(rect);
if (ev.type == EventType.MouseDown && ev.button == 0 && !ev.control && !ev.alt && !ev.command) {
float hitD = 0.0f;
if (plane.Raycast(mouseRay, out hitD)) {
Vector3 intersect = mouseRay.GetPoint(hitD);
Vector3 pLocal = t.InverseTransformPoint (intersect);
if (pLocal.x >= rect.xMin && pLocal.x <= rect.xMax &&
pLocal.y >= rect.yMin && pLocal.y <= rect.yMax) {
// Mousedown on our sprite
// Store current selected objects transforms
dragObjCachedTransforms.Clear();
dragObjStartPos.Clear();
for (int i = 0; i < Selection.gameObjects.Length; ++i) {
Transform objTransform = Selection.gameObjects[i].transform;
dragObjCachedTransforms.Add(objTransform);
dragObjStartPos.Add(objTransform.position);
}
dragOrigin = intersect;
GUIUtility.hotControl = controlId;
ev.Use();
}
}
}
if (GUIUtility.hotControl == controlId) { // Handle drag / mouseUp
switch (ev.GetTypeForControl(controlId)) {
case EventType.MouseDrag: {
float hitD = 0.0f;
if (plane.Raycast(mouseRay, out hitD)) {
Vector3 intersect = mouseRay.GetPoint(hitD);
Vector3 offset = intersect - dragOrigin;
if (ev.shift) {
float x = Mathf.Abs (Vector3.Dot (offset, t.right));
float y = Mathf.Abs (Vector3.Dot (offset, t.up));
offset = Vector3.Project (offset, (x > y) ? t.right : t.up);
}
offset.z = 0.0f;
Undo.RegisterUndo(dragObjCachedTransforms.ToArray(), "Move");
for (int i = 0; i < Selection.gameObjects.Length; ++i) {
Selection.gameObjects[i].transform.position = dragObjStartPos[i] + offset;
}
}
break;
}
case EventType.MouseUp: {
GUIUtility.hotControl = 0;
ev.Use();
break;
}
}
}
}
示例12: CanSenseFactionMember
public bool CanSenseFactionMember(Transform member) {
bool sensed = false;
foreach (Transform teamMember in _TeamMembers) {
Vector3 direction = member.position - teamMember.position;
float angle = Vector3.Angle(direction, teamMember.forward);
if (angle < teamMember.GetComponent<SquadMember>().LOSAngle * 0.5f) {
RaycastHit hit;
//Color color;
if (Physics.Raycast(teamMember.position, direction.normalized, out hit, teamMember.GetComponent<SquadMember>().SightRange)) {
//Debug.Log(hit.collider.tag + " " + hit.collider.name);
//Debug.DrawLine(transform.position, hit.point, Color.cyan, 2f);
if (hit.collider.transform.GetInstanceID() == member.GetInstanceID()) {
if(teamMember.GetComponent<SquadMember>().OverWatchOn) {
teamMember.GetComponent<SquadMember>().OverWatchResponse(member);
}
sensed = true;
//Debug.Log("Sensed Enemy");
//color = Color.green;
break;
} //else
// color = Color.yellow;
}
//else
// color = Color.red;
//Debug.DrawRay(teamMember.position, direction, color, 3f);
}
}
return sensed;
}
示例13: processTransform
static string processTransform(Transform t, Vector3 parentGlobalPosition)
{
StringBuilder meshString = new StringBuilder();
Vector3 globalPosition = t.localPosition + parentGlobalPosition;
Terrain terrain = t.gameObject.GetComponent<Terrain>();
if (!terrain)
{
MeshFilter mf = t.GetComponent<MeshFilter>();
if (mf)
{
int key;
long idRigidStatic, idTriangleMesh, idMaterial;
sharedMaterialIds.TryGetValue(t.GetInstanceID(), out key);
materialIds.TryGetValue(key, out idMaterial);
triangleMeshIds.TryGetValue(t.GetInstanceID(), out idTriangleMesh);
rigidStaticIds.TryGetValue(t.GetInstanceID(), out idRigidStatic);
meshString.Append(ExportToPhysXScript.TransformToString(t, idRigidStatic, idTriangleMesh, idMaterial, globalPosition));
}
for (int i = 0; i < t.childCount; i++)
{
meshString.Append(processTransform(t.GetChild(i), globalPosition));
}
}
else
{
int key;
long idRigidStatic, idTriangleMesh, idMaterial;
sharedMaterialIds.TryGetValue(t.GetInstanceID(), out key);
materialIds.TryGetValue(key, out idMaterial);
triangleMeshIds.TryGetValue(t.GetInstanceID(), out idTriangleMesh);
rigidStaticIds.TryGetValue(t.GetInstanceID(), out idRigidStatic);
meshString.Append(ExportToPhysXScript.TransformToString(t, idRigidStatic, idTriangleMesh, idMaterial, globalPosition));
}
return meshString.ToString();
}
示例14: PlaceTile
public void PlaceTile( Transform tile, float x = 0.0f, float z = 0.0f, bool preventAddToRecord = false, int oldInstanceID = 0, bool createNewTile = true ){ // optional parameters!
if (tile == null)
return;
float y = tile.position.y - scaleModifier;
// do not allow the object to be placed if we are currently under the drawn grid.
// if ( y < GameObject.Find ("DrawnGridManager").GetComponent<DrawnGridManager>().GetCurrentHeight() ){
// return;
// }
// do not allow the object to be placed if we are targeting a block beyond our current dimensions.
if ( (Mathf.Abs(x) > (m_CurrentDimensions.x/2) ) || Mathf.Abs (y) > m_CurrentDimensions.y || (Mathf.Abs (z) > (m_CurrentDimensions.z/2)) ){
return;
}
// If this tile has a limit, ensure that the limit has not been reached. If it has, delete a tile to make room.
if ( tile.GetComponent<TileProperties>().tileLimit > -1 ){
int count = 1;
List<int> tilesToDelete = new List<int>();
foreach( var pair in m_CurrentPlacedTileList ){
int instanceID = pair.Key;
Transform tileData = pair.Value;
if ( tileData.name == tile.name ){
count++;
if ( count > tile.GetComponent<TileProperties>().tileLimit ){
tilesToDelete.Add (instanceID);
}
}
}
// destroy all the keys we have collected in the list.
foreach (int instanceID in tilesToDelete){
Transform tileToDelete;
m_CurrentPlacedTileList.TryGetValue(instanceID, out tileToDelete);
RemoveOperationFromList( tileToDelete.GetInstanceID() );
Destroy (tileToDelete.gameObject);
m_CurrentPlacedTileList.Remove (instanceID);
}
}
tile.GetComponent<TileProperties>().SetRendererEnabled(true);
// now that the tile has been placed and has a finalized rotation, set it here.
tile.GetComponent<TileProperties>().SetInitialRotation( tile.rotation.eulerAngles );
tile.GetComponent<TileProperties>().SetInitialRotationQuat( tile.rotation );
// add the new tile.
m_CurrentPlacedTileList.Add( tile.GetInstanceID(), tile );
// add the operation to the recorded actions list.
if ( !preventAddToRecord ){
// AddOperationToList( OperationID.Add, tile, tile.GetComponent<TileProperties>().tileID );
}
// if a old instance ID has been passed in, we want to modify the operation list to use the new id.
if ( oldInstanceID != 0 ){
ModifyOperationListInstanceID( oldInstanceID, tile.GetInstanceID() );
}
Vector3 scale = tile.localScale;
scale.x = scale.x + scaleModifier;
scale.y = scale.y + scaleModifier;
scale.z = scale.z + scaleModifier;
tile.localScale = scale;
// set the kinematics type.
tile.GetComponent<TileProperties>().SetIsKinematic( true );
// when placing the tile, make it not a trigger.
tile.GetComponent<TileProperties>().SetIsTrigger( false );
// if this is the start tile, inform the character manager that the start pos has changed.
if ( tile.name.StartsWith( "Start_Locator" ) == true ) {
Vector3 startPos = tile.position;
startPos.y += tile.localScale.y;
AGFEventObj eventObj = new AGFEventObj( AGFEventObj.SetStartPosAndRot );
eventObj.arguments["startPos"] = startPos;
eventObj.arguments["startRot"] = tile.rotation;
FindObjectOfType<EventHandler>().dispatchEvent( eventObj );
}
// Update this tile with the necessary data from its TileDataStruct.
tile.GetComponent<TileProperties>().SetFromSaveString( m_CurrentRecordedActions[m_CurrentRecordedActionsPointer].customString );
if ( m_CustomCodeManager != null ){
m_CustomCodeManager.OnTileInstantiated( tile.gameObject );
}
tile.GetComponent<TileProperties>().OnTilePlaced();
// if we're placing tiles while in the editor, trim off the "clone" modifier.
#if UNITY_EDITOR
tile.name = Main.TrimEndFromString( tile.name, "(Clone)" );
#endif
}
示例15: RectControl
// 8 draggable points around the border (resizing)
public static Rect RectControl( int controlId, Rect r, Transform t ) {
Event ev = Event.current;
// Break out if vertex modifier is active
if (IsSnapToVertexActive()) {
return r;
}
bool guiChanged = false;
GUIStyle style = tk2dEditorSkin.MoveHandle;
Vector2 rSign = new Vector2(Mathf.Sign (r.width), Mathf.Sign (r.height));
r = PositiveRect(r);
constrainRectTemp = r;
constrainRectMatrixTemp = t.localToWorldMatrix;
Vector3[] localPts = new Vector3[] {
new Vector3(r.xMin + r.width * 0.0f, r.yMin + r.height * 0.0f, 0),
new Vector3(r.xMin + r.width * 0.5f, r.yMin + r.height * 0.0f, 0),
new Vector3(r.xMin + r.width * 1.0f, r.yMin + r.height * 0.0f, 0),
new Vector3(r.xMin + r.width * 0.0f, r.yMin + r.height * 0.5f, 0),
new Vector3(r.xMin + r.width * 1.0f, r.yMin + r.height * 0.5f, 0),
new Vector3(r.xMin + r.width * 0.0f, r.yMin + r.height * 1.0f, 0),
new Vector3(r.xMin + r.width * 0.5f, r.yMin + r.height * 1.0f, 0),
new Vector3(r.xMin + r.width * 1.0f, r.yMin + r.height * 1.0f, 0),
};
Vector3[] worldPts = new Vector3[8];
Vector2[] guiPts = new Vector2[8];
bool[] handleVisible = new bool[8];
for (int i = 0; i < 8; ++i) {
worldPts[i] = t.TransformPoint(localPts[i]);
guiPts[i] = HandleUtility.WorldToGUIPoint(worldPts[i]);
handleVisible[i] = true;
}
// Hide handles if screen distance gets too small
{
float edgeLengthBottom = (guiPts[0] - guiPts[2]).magnitude;
float edgeLengthTop = (guiPts[5] - guiPts[7]).magnitude;
float edgeLengthLeft = (guiPts[0] - guiPts[5]).magnitude;
float edgeLengthRight = (guiPts[2] - guiPts[7]).magnitude;
if (edgeLengthBottom < handleClosenessClip || edgeLengthTop < handleClosenessClip ||
edgeLengthLeft < handleClosenessClip || edgeLengthRight < handleClosenessClip)
{
for (int i = 0; i < 8; ++i) {
handleVisible[i] = false;
}
}
else {
if (edgeLengthBottom < 2.0f * handleClosenessClip || edgeLengthTop < 2.0f * handleClosenessClip) {
handleVisible[1] = handleVisible[6] = false;
}
if (edgeLengthLeft < 2.0f * handleClosenessClip || edgeLengthRight < 2.0f * handleClosenessClip) {
handleVisible[3] = handleVisible[4] = false;
}
}
}
Vector2[] handleCursorN = new Vector2[] {
new Vector2(-1.0f, -1.0f), new Vector2(0.0f, -1.0f), new Vector2(1.0f, -1.0f),
new Vector2(-1.0f, 0.0f), new Vector2(1.0f, 0.0f),
new Vector2(-1.0f, 1.0f), new Vector2(0.0f, 1.0f), new Vector2(1.0f, 1.0f)
};
for (int i = 0; i < 8; ++i) {
if ((Event.current.type == EventType.Repaint || Event.current.type == EventType.MouseDown) && !handleVisible[i]) continue;
Vector3 worldPt = worldPts[i];
MouseCursor cursor = GetHandleCursor(handleCursorN[i], t);
EditorGUI.BeginChangeCheck();
Vector3 newWorldPt = MoveHandle( controlId + t.GetInstanceID() + "Handle".GetHashCode() + i, worldPt, t.forward, style, cursor );
if (EditorGUI.EndChangeCheck()) {
Vector3 localPt = ev.shift ? constrainRectMatrix.inverse.MultiplyPoint(newWorldPt) : t.InverseTransformPoint(newWorldPt);
Vector3 v0 = new Vector3(r.xMin, r.yMin, 0);
Vector3 v1 = v0 + new Vector3(r.width, r.height, 0);
// constrain axis
if (i == 3 || i == 4) localPt.y = localPts[i].y;
if (i == 1 || i == 6) localPt.x = localPts[i].x;
// calculate new extrema
if (!ev.shift) {
if (i == 0 || i == 3 || i == 5) v0.x = Mathf.Min(v1.x, localPt.x);
if (i == 0 || i == 1 || i == 2) v0.y = Mathf.Min(v1.y, localPt.y);
if (i == 2 || i == 4 || i == 7) v1.x = Mathf.Max(v0.x, localPt.x);
if (i == 5 || i == 6 || i == 7) v1.y = Mathf.Max(v0.y, localPt.y);
} else {
// constrain proportions
v0 = new Vector3(constrainRect.xMin, constrainRect.yMin, 0);
v1 = v0 + new Vector3(constrainRect.width, constrainRect.height, 0);
if (i == 0 || i == 3 || i == 5) {
v0.x = Mathf.Min(v1.x, localPt.x);
float sy0 = (i == 0) ? 1.0f : ((i == 3) ? 0.5f : 0.0f);
float dy = constrainRect.height * ((v1.x - v0.x) / constrainRect.width - 1.0f);
v0.y -= dy * sy0;
v1.y += dy * (1.0f - sy0);
//.........这里部分代码省略.........