本文整理汇总了C#中UnityEngine.GameObject.GetInstanceID方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetInstanceID方法的具体用法?C# GameObject.GetInstanceID怎么用?C# GameObject.GetInstanceID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.GameObject
的用法示例。
在下文中一共展示了GameObject.GetInstanceID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDecal
public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale)
{
GameObject decal = new GameObject();
decal.name = "Decal" + decal.GetInstanceID();
decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale);
decal.AddComponent<MeshRenderer>().sharedMaterial = mat;
#if UNITY_5
decal.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
#else
decal.GetComponent<MeshRenderer>().castShadows = false;
#endif
qd_Decal decalComponent = decal.AddComponent<qd_Decal>();
decalComponent.SetScale(scale);
decalComponent.SetTexture( (Texture2D)mat.mainTexture );
decalComponent.SetUVRect(uvCoords);
#if DEBUG
decal.AddComponent<qd_DecalDebug>();
#endif
return decal;
}
示例2: GetObstacle
/// <summary>
///Returns a SphericalObstacle from the current gameObject
/// </summary>
/// <param name="gameObject">
/// A game object to create the obstacle from<see cref="GameObject"/>
/// </param>
/// <returns>
/// A SphericalObstacle encompassing the game object<see cref="Obstacle"/>
/// </returns>
public static Obstacle GetObstacle( GameObject gameObject )
{
SphericalObstacle obstacle;
int id = gameObject.GetInstanceID();
Component[] colliders;
float radius = 0.0f, currentRadius;
if(!ObstacleCache.ContainsKey( id ))
{
var obstacleData = gameObject.GetComponent<SphericalObstacleData>();
// If the object provides his own spherical obstacle information,
// use it instead of calculating a sphere that encompasses the
// whole collider.
if (obstacleData != null)
{
ObstacleCache[id] = new SphericalObstacle(obstacleData.Radius, gameObject.transform.position + obstacleData.Center);
}
else
{
colliders = gameObject.GetComponentsInChildren<Collider>();
if( colliders == null )
{
Debug.LogError( "Obstacle '" + gameObject.name + "' has no colliders" );
return null;
}
foreach( Collider collider in colliders )
{
if( collider.isTrigger )
{
continue;
}
// Get the maximum extent to create a sphere that encompasses the whole obstacle
float maxExtents = Mathf.Max(Mathf.Max(collider.bounds.extents.x, collider.bounds.extents.y),
collider.bounds.extents.z);
/*
* Calculate the displacement from the object center to the
* collider, and add in the maximum extents of the bounds.
* Notice that we don't need to multiply by the object's
* local scale, since that is already considered in the
* bounding rectangle.
*/
float distanceToCollider = Vector3.Distance(gameObject.transform.position, collider.bounds.center);
currentRadius = distanceToCollider + maxExtents;
if( currentRadius > radius )
{
radius = currentRadius;
}
}
ObstacleCache[id] = new SphericalObstacle( radius, gameObject.transform.position );
}
}
obstacle = ObstacleCache[ id ] as SphericalObstacle;
return obstacle;
}
示例3: CreateInstance
public static PolydrawObject CreateInstance()
{
GameObject go = new GameObject();
go.name = "Polydraw"+go.GetInstanceID();
go.AddComponent<MeshFilter>();
go.AddComponent<MeshRenderer>();
return go.AddComponent<PolydrawObject>();
}
示例4: CreateDecal
public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale)
{
GameObject decal = new GameObject();
decal.name = "Decal" + decal.GetInstanceID();
decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale);
decal.AddComponent<MeshRenderer>().sharedMaterial = mat;
qd_Decal decalComponent = decal.AddComponent<qd_Decal>();
decalComponent.SetScale(scale);
decalComponent.SetTexture( (Texture2D)mat.mainTexture );
decalComponent.SetUVRect(uvCoords);
#if DEBUG
decal.AddComponent<qd_DecalDebug>();
#endif
return decal;
}
示例5: AddClick
// 添加单击事件
public void AddClick(GameObject go)
{
if (go == null) return;
string btnKey = go.name + go.GetInstanceID();
buttons.Add(btnKey, go.name);
go.GetComponent<Button>().onClick.AddListener(
delegate() {
luaMgr.CallFunction("DialogClickEvent.OnClick", btnKey);
}
);
}
示例6: GetID
string GetID(GameObject gameObject)
{
var key = gameObject.GetInstanceID();
if (!uniqueGuids.ContainsKey(key))
{
uniqueGuids[key] = Guid.NewGuid().ToString();
}
return uniqueGuids[key];
}
示例7: SetFoldValueForGameObjectInHiearchyRecursive
private static void SetFoldValueForGameObjectInHiearchyRecursive(GameObject gameObject, FoldValue fv) {
var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow");
var methodInfo = type.GetMethod("SetExpandedRecursive");
EditorApplication.ExecuteMenuItem("Window/Hierarchy");
EditorWindow window = EditorWindow.focusedWindow;
methodInfo.Invoke(window, new object[] {
gameObject.GetInstanceID(),
fv.BoolValue()
});
}
示例8: RemoveClick
public void RemoveClick(GameObject go)
{
if (go == null) return;
string btnKey = go.name + go.GetInstanceID();
if(buttons.ContainsKey(btnKey))
{
buttons.Remove(btnKey);
}
else
{
Debug.Log("Empty Operation: RemoveClick target is empty");
return;
}
go.GetComponent<Button>().onClick.RemoveAllListeners();
}
示例9: InvokeOnTarget
public void InvokeOnTarget(GameObject target)
{
UnityAction call;
int id = target.GetInstanceID ();
//try for runtime added listeners
if(m_Calls.TryGetValue(id,out call)){
call.Invoke();
}else{//try persistant(editor) added listeners
int listenerNumber = this.GetPersistentEventCount();
if(listenerNumber!=m_PersistentCallsDelegate.Length)
m_PersistentCallsDelegate=new PersistantCallDelegate[listenerNumber];
MonoBehaviour listener;
for (int i=0; i<listenerNumber; i++) {
listener=this.GetPersistentTarget(i) as MonoBehaviour;
if(listener.gameObject==target){
PersistantCallDelegate callDelegate=m_PersistentCallsDelegate[i];
if(callDelegate==null){
MethodInfo methodInfo=listener.GetType().GetMethod(this.GetPersistentMethodName(i));
//Call thru reflection is slow
//methodInfo.Invoke(listener,new object[]{damage,null});
m_PersistentCallsDelegate[i]=callDelegate=System.Delegate.CreateDelegate(typeof(PersistantCallDelegate),listener,methodInfo) as PersistantCallDelegate;
}
callDelegate.Invoke();
}
}
}
}
示例10: Instantiate
public GameObject Instantiate(GameObject original, Vector3 position, Quaternion rotation)
{
int instanceID = original.GetInstanceID(); // 缓存池创建时不检查GUID参数,因为外部可能进行改变
ObjectPoolItem item;
if (!ObjectPoolItems.TryGetValue(instanceID, out item))
{
var newObj = GameObject.Instantiate(original, position, rotation) as GameObject;
var parameter = newObj.AddMissingComponent<ObjectPoolParameter>();
parameter.InstanceID = instanceID;
newObj.BroadcastMessage("OnSpawned", SendMessageOptions.DontRequireReceiver);
return newObj;
}
var obj = item.GameObjects.Pop();
if (item.GameObjects.Count == 0)
ObjectPoolItems.Remove(instanceID);
obj.transform.SetParent(null, false);
obj.transform.position = position;
obj.transform.rotation = rotation;
obj.BroadcastMessage("OnSpawned", SendMessageOptions.DontRequireReceiver);
return obj;
}
示例11: CameraSetup
private void CameraSetup(int index, string sourceName)
{
Camera sourceCam = JUtil.GetCameraByName(sourceName);
if (sourceCam != null)
{
var cameraBody = new GameObject();
cameraBody.name = typeof(RasterPropMonitor).Name + index + cameraBody.GetInstanceID();
cameraObject[index] = cameraBody.AddComponent<Camera>();
// Just in case to support JSITransparentPod.
cameraObject[index].cullingMask &= ~(1 << 16 | 1 << 20);
cameraObject[index].CopyFrom(sourceCam);
cameraObject[index].enabled = false;
cameraObject[index].targetTexture = screenTexture;
cameraObject[index].aspect = cameraAspect;
}
}
示例12: recordListener
// record listener, if not already recorded
private bool recordListener(string eventType, GameObject listener, string function)
{
if (!checkForListener(eventType, listener)) {
ArrayList listenerList = _listeners[eventType] as ArrayList;
EventListener callback = new EventListener();
callback.name = listener.GetInstanceID().ToString();
callback.listener = listener;
callback.function = function;
listenerList.Add(callback);
return true;
} else {
if (allowWarningOutputs) {
Debug.LogWarning("Event Manager: Listener: " + listener.name + " is already in list for event: " + eventType);
}
return false;
}
}
示例13: checkForListener
// check if listener exists
private bool checkForListener(string eventType, GameObject listener)
{
if (!checkForEvent(eventType)) {
recordEvent(eventType);
}
ArrayList listenerList = _listeners[eventType] as ArrayList;
foreach (EventListener callback in listenerList) {
if (callback.name == listener.GetInstanceID().ToString()) return true;
}
return false;
}
示例14: removeEventListener
// Remove event listener
public bool removeEventListener(string eventType, GameObject listener)
{
if (!checkForEvent(eventType)) return false;
ArrayList listenerList = _listeners[eventType] as ArrayList;
foreach (EventListener callback in listenerList) {
if (callback.name == listener.GetInstanceID().ToString()) {
listenerList.Remove(callback);
return true;
}
}
return false;
}
示例15: Start
public void Start()
{
if (HighLogic.LoadedSceneIsEditor)
return;
try {
// Parse bloody KSPField colors.
if (!string.IsNullOrEmpty(backgroundColor))
backgroundColorValue = ConfigNode.ParseColor32(backgroundColor);
if (!string.IsNullOrEmpty(ballColor))
ballColorValue = ConfigNode.ParseColor32(ballColor);
if (!string.IsNullOrEmpty(progradeColor))
progradeColorValue = ConfigNode.ParseColor32(progradeColor);
if (!string.IsNullOrEmpty(maneuverColor))
maneuverColorValue = ConfigNode.ParseColor32(maneuverColor);
if (!string.IsNullOrEmpty(targetColor))
targetColorValue = ConfigNode.ParseColor32(targetColor);
if (!string.IsNullOrEmpty(normalColor))
normalColorValue = ConfigNode.ParseColor32(normalColor);
if (!string.IsNullOrEmpty(radialColor))
radialColorValue = ConfigNode.ParseColor32(radialColor);
if (!string.IsNullOrEmpty(dockingColor))
dockingColorValue = ConfigNode.ParseColor32(dockingColor);
Shader unlit = Shader.Find("KSP/Alpha/Unlit Transparent");
overlayMaterial = new Material(unlit);
overlayMaterial.mainTexture = GameDatabase.Instance.GetTexture(staticOverlay.EnforceSlashes(), false);
if (!string.IsNullOrEmpty(headingBar)) {
headingMaterial = new Material(unlit);
headingMaterial.mainTexture = GameDatabase.Instance.GetTexture(headingBar.EnforceSlashes(), false);
}
horizonTex = GameDatabase.Instance.GetTexture(horizonTexture.EnforceSlashes(), false);
gizmoTexture = JUtil.GetGizmoTexture();
// Ahaha, that's clever, does it work?
stockNavBall = GameObject.Find("NavBall").GetComponent<NavBall>();
// ...well, it does, but the result is bizarre,
// apparently, because the stock BALL ITSELF IS MIRRORED.
navBall = GameDatabase.Instance.GetModel(navBallModel.EnforceSlashes());
Destroy(navBall.collider);
navBall.name = "RPMNB" + navBall.GetInstanceID();
navBall.layer = drawingLayer;
navBall.transform.position = Vector3.zero;
navBall.transform.rotation = Quaternion.identity;
navBall.transform.localRotation = Quaternion.identity;
if (ballIsEmissive) {
navBall.renderer.material.shader = Shader.Find("KSP/Emissive/Diffuse");
navBall.renderer.material.SetTexture("_MainTex", horizonTex);
navBall.renderer.material.SetTextureOffset("_Emissive", navBall.renderer.material.GetTextureOffset("_MainTex"));
navBall.renderer.material.SetTexture("_Emissive", horizonTex);
navBall.renderer.material.SetColor("_EmissiveColor", ballColorValue);
} else {
navBall.renderer.material.shader = Shader.Find("KSP/Unlit");
navBall.renderer.material.mainTexture = horizonTex;
navBall.renderer.material.color = ballColorValue;
}
navBall.renderer.material.SetFloat("_Opacity", ballOpacity);
markerPrograde = BuildMarker(0, 2, progradeColorValue);
markerRetrograde = BuildMarker(1, 2, progradeColorValue);
markerManeuver = BuildMarker(2, 0, maneuverColorValue);
markerManeuverMinus = BuildMarker(1, 2, maneuverColorValue);
markerTarget = BuildMarker(2, 1, targetColorValue);
markerTargetMinus = BuildMarker(2, 2, targetColorValue);
markerNormal = BuildMarker(0, 0, normalColorValue);
markerNormalMinus = BuildMarker(1, 0, normalColorValue);
markerRadial = BuildMarker(1, 1, radialColorValue);
markerRadialMinus = BuildMarker(0, 1, radialColorValue);
markerDockingAlignment = BuildMarker(0, 2, dockingColorValue);
// Non-moving parts...
cameraBody = new GameObject();
cameraBody.name = "RPMPFD" + cameraBody.GetInstanceID();
cameraBody.layer = drawingLayer;
ballCamera = cameraBody.AddComponent<Camera>();
ballCamera.enabled = false;
ballCamera.orthographic = true;
ballCamera.clearFlags = CameraClearFlags.Nothing;
ballCamera.eventMask = 0;
ballCamera.farClipPlane = 3f;
ballCamera.orthographicSize = cameraSpan;
ballCamera.cullingMask = 1 << drawingLayer;
ballCamera.clearFlags = CameraClearFlags.Depth;
// -2,0,0 seems to get the orientation exactly as the ship.
// But logically, forward is Z+, right?
// Which means that
ballCamera.transform.position = new Vector3(0, 0, 2);
ballCamera.transform.LookAt(Vector3.zero, Vector3.up);
ballCamera.transform.position = new Vector3(cameraShift.x, cameraShift.y, 2);
overlay = CreateSimplePlane("RPMPFDOverlay" + internalProp.propID, 1f, drawingLayer);
overlay.layer = drawingLayer;
overlay.transform.position = new Vector3(0, 0, 1.5f);
overlay.renderer.material = overlayMaterial;
//.........这里部分代码省略.........