本文整理汇总了C#中UnityEngine.Object.GetInstanceID方法的典型用法代码示例。如果您正苦于以下问题:C# Object.GetInstanceID方法的具体用法?C# Object.GetInstanceID怎么用?C# Object.GetInstanceID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Object
的用法示例。
在下文中一共展示了Object.GetInstanceID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
internal static void Add(Object obj)
{
if (obj != null)
{
Add(obj.GetInstanceID());
}
}
示例2: GetAssetPreview
/// <summary>
/// <para>Returns a preview texture for an asset.</para>
/// </summary>
/// <param name="asset"></param>
public static Texture2D GetAssetPreview(Object asset)
{
if (asset != null)
{
return GetAssetPreview(asset.GetInstanceID());
}
return null;
}
示例3: InitEditorWindow
public static void InitEditorWindow(Object obj)
{
currentEditor = (ActorEditor)EditorWindow.GetWindow<ActorEditor>();
currentEditor.instanceId = obj.GetInstanceID();
currentEditor.title = "Actor Editor";
currentEditor.reader = (DialogueReader)EditorUtility.InstanceIDToObject(currentEditor.instanceId);
if (currentEditor.reader != null && currentEditor.reader.actors.Count > 0)
currentEditor.selectedActor = currentEditor.reader.actors[0];
}
示例4:
private bool this[Object obj]
{
get
{
var key = obj.GetInstanceID();
return expandList.Contains(key);
}
set
{
var key = obj.GetInstanceID();
if (this[obj] == value)
return;
if (value)
expandList.Add(key);
else
expandList.Remove(key);
}
}
示例5: Watch
/// <summary>
/// Monitors the object for property changes<br/>
/// Monitoring an object means putting it on the list which will be checked for changes after the play mode is stopped<br/>
/// When put on the list, all the original properties of the object are being saved (cloned)<br/>
/// When play mode stopped, properties are being read from all the monitored objects<br/>
/// For each property, the original and current value are being compared for change<br/>
/// and the changed value list is being made<br/>
/// Changed values are being applied to an object "resurrected" by Unity, after the play mode is stopped<br/>
/// Here we are monitoring eDriven.Gui COMPONENTS, not transforms or game objects<br/>
/// (however, they could also be monitored in some other scenario)<br/>
/// </summary>
/// <param name="target">Target (component) to monitor</param>
public void Watch(Object target)
{
/**
* 1. Get the instance ID because it is the key in the dictionary holding the monitored objects
* */
int instanceId = target.GetInstanceID();
//Debug.Log("* Monitoring: " + instanceId);
/**
* 2. We need to check if the object is already being monitored
* This is important because we must not overwrite the original values each time the component is being clicked
* because this might lead to the loss of data (only changes from the last component click would be then be saved as the original values)
* For instance, take a look at this scenario:
* - this component click. Changing the text to "foo".
* - other component click.
* - this component click. Changing the color to green.
* In play mode, all the changes would be accumulated, and there would seem to be no problems.
* But after the play mode is stopped, and started again, we would discover that only the component color is being changed to green,
* and no text has been changed - due to second component click rewriting the "original" values, thus deleting the change to "foo"
* */
if (_monitoredObjects.ContainsKey(instanceId))
return;
#if DEBUG
if (DebugMode)
{
ComponentAdapter componentAdapter = target as ComponentAdapter;
if (null != componentAdapter)
Debug.Log("Monitoring: " + GuiLookup.PathToString(componentAdapter.transform, " -> "), componentAdapter.transform);
}
#endif
/**
* 3. This is the first time we are monitoring this object
* Create a new PersistedComponent instance and add it to dictionary
* */
_monitoredObjects[instanceId] = new PersistedComponent(target);
//_currentInstanceId = target.GetInstanceID();
#if DEBUG
if (DebugMode)
{
Debug.Log(string.Format(" Added [{0}] to monitored objects list. Total: {1}", target.name, _monitoredObjects.Count), target);
}
#endif
//MonitoredObjectAddedSignal.Emit(target);
}
示例6: OnGUI
void OnGUI()
{
bmFontSrc = EditorGUILayout.ObjectField("BMFont Source", bmFontSrc, typeof(Object), false);
DistanceFieldScaleFactor = EditorGUILayout.IntSlider("Scale Factor", DistanceFieldScaleFactor, 1, 8);
DistanceField.SearchRadius = EditorGUILayout.IntSlider("Search Radius", DistanceField.SearchRadius, 1, 50);
if(GUILayout.Button("Generate")){
if (bmFontSrc == null) {
EditorUtility.DisplayDialog("Error", "Select BMFont file first.", "Ok");
}
else{
string path = AssetDatabase.GetAssetPath(bmFontSrc.GetInstanceID());
if (path.ToLower().EndsWith(".fnt")) {
Generate(path);
}
else {
EditorUtility.DisplayDialog("Unknown File Extension", "Only .fnt files are supported.", "Ok");
}
}
}
}
示例7: Remove
internal static void Remove(Object obj)
{
if (obj != null)
{
Remove(obj.GetInstanceID());
}
}
示例8: ShowCreatedAsset
public static void ShowCreatedAsset(Object o)
{
Selection.activeObject = o;
if (o != null)
{
FrameObjectInProjectWindow(o.GetInstanceID());
}
}
示例9: CreateAsset
public static void CreateAsset(Object asset, string pathName)
{
StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), ScriptableObject.CreateInstance<DoCreateNewAsset>(), pathName, AssetPreview.GetMiniThumbnail(asset), null);
}
示例10: ShowAtPosition
internal static bool ShowAtPosition(Object targetObj, Rect activatorRect, bool showLabelIcons)
{
int instanceID = targetObj.GetInstanceID();
long num2 = DateTime.Now.Ticks / 0x2710L;
bool flag = num2 < (s_LastClosedTime + 50L);
if ((instanceID != s_LastInstanceID) || !flag)
{
Event.current.Use();
s_LastInstanceID = instanceID;
if (s_IconSelector == null)
{
s_IconSelector = ScriptableObject.CreateInstance<IconSelector>();
}
s_IconSelector.Init(targetObj, activatorRect, showLabelIcons);
return true;
}
return false;
}
示例11: ReleaseResourceImmediate
/// <summary>
/// 强行释放资源
/// </summary>
/// <param name="obj"></param>
public static void ReleaseResourceImmediate(Object obj)
{
if (!obj)
return;
int id = obj.GetInstanceID();
if (m_resourceDic.ContainsKey(id))
{
string prefab = m_resourceDic[id];
m_assetMgr.Release(prefab, true);
m_resourceDic.Remove(id);
}
}
示例12: OnGUI
//.........这里部分代码省略.........
}
}
if (assetsPaths.IndexOf('\\') >= 0)
{
assetsPaths = assetsPaths.Replace('\\', '/');
}
if (destinationFolder != null)
{
string destpath = AssetDatabase.GetAssetPath(destinationFolder);
if (string.IsNullOrEmpty(destpath))
{
destinationFolder = null;
}
else if (!System.IO.Directory.Exists(destpath))
{
destpath = destpath.Substring(0, destpath.LastIndexOf('/'));
destinationFolder = AssetDatabase.LoadMainAssetAtPath(destpath);
}
}
}
GUILayout.BeginHorizontal("Toolbar"); GUILayout.Label(""); GUILayout.EndHorizontal();
templateAsset = EditorGUILayout.ObjectField("Template Asset", templateAsset, typeof(Object), false);
destinationFolder = EditorGUILayout.ObjectField("Destination Folder", destinationFolder, typeof(Object), false);
GUILayout.Label("Assets to be imported (Drag and drop, or write full path)");
GUILayout.Space(2);
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
assetsPaths = EditorGUILayout.TextArea(assetsPaths);
Event evt = Event.current;
Rect drop_area = GUILayoutUtility.GetLastRect();
switch (evt.type)
{
case EventType.DragUpdated:
case EventType.DragPerform:
if (!drop_area.Contains(evt.mousePosition))
return;
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (evt.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
StringBuilder sb = new StringBuilder();
foreach (var path in assetsPaths.Split('\n', '\r'))
{
if (string.IsNullOrEmpty(path)) continue;
sb.AppendFormat("{0}\n", path.ToString());
}
foreach (var path in DragAndDrop.paths)
{
if (string.IsNullOrEmpty(path)) continue;
sb.AppendFormat("{0}\n", path.ToString());
}
newAssetPath = sb.ToString();
}
break;
}
EditorGUILayout.EndScrollView();
if (GUILayout.Button("Import"))
{
var start = System.DateTime.Now;
string destpath;
if( destinationFolder != null )
{
destpath = AssetDatabase.GetAssetPath(destinationFolder);
}
else
{
destpath = AssetDatabase.GetAssetPath(templateAsset);
destpath = destpath.Substring(0,destpath.LastIndexOf('/'));
}
List<Object> assets = new List<Object>();
foreach (var assetPath in assetsPaths.Split('\n', '\r'))
{
if (string.IsNullOrEmpty(assetPath)) continue;
var assetDest = destpath + assetPath.Substring(assetPath.LastIndexOf('/'));
assetDest = AssetDatabase.GenerateUniqueAssetPath(assetDest);
AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(templateAsset.GetInstanceID()), assetDest);
System.IO.File.Copy(assetPath, assetDest, true);
//AssetDatabase.ImportAsset(assetDest);
assets.Add(AssetDatabase.LoadAssetAtPath(assetDest, templateAsset.GetType()));
}
AssetDatabase.SaveAssets();
Selection.instanceIDs = new int[0];
Selection.objects = assets.ToArray();
AssetDatabase.Refresh();
Debug.Log(string.Format("Asset Importer: Importing {0} assets took {1} seconds", assets.Count,(System.DateTime.Now - start).TotalSeconds));
}
GUILayout.Space(6);
}
示例13: AddPopupPreview
public static string AddPopupPreview(Object hoverCom)
{
return "|"+"#"+hoverCom.GetInstanceID();
}
示例14: DestroyInternal
/// <summary>
/// Puts the object back into the pool if it's being pooled
/// or destroys it if not.
/// </summary>
protected virtual void DestroyInternal( Object obj, float t )
{
if(obj == null)
return;
// Check if this prefab is in the ignore list or if it is not pooled and destroy it if condition is met
if(IgnoredPrefabs.FirstOrDefault(o => o.name == obj.name || o.name == obj.name+"(Clone)") != null || (!m_AvailableObjects.ContainsKey(obj.name) && !PoolOnDestroy))
{
Object.Destroy(obj, t);
return;
}
// handle timed destroy
if(t != 0)
{
vp_Timer.In(t, delegate { DestroyInternal(obj, 0); });
return;
}
// if the object isn't being pooled, add it
if(!m_AvailableObjects.ContainsKey(obj.name))
{
AddObjects(obj, Vector3.zero, Quaternion.identity);
return;
}
List<Object> availableObjects = null;
List<Object> usedObjects = null;
m_AvailableObjects.TryGetValue(obj.name, out availableObjects);
m_UsedObjects.TryGetValue(obj.name, out usedObjects);
// get the object
GameObject go = usedObjects.FirstOrDefault(o => o.GetInstanceID() == obj.GetInstanceID()) as GameObject;
if(go == null)
return;
// parent the object back to pooling manager
go.transform.parent = m_Transform;
// disable the object
vp_Utility.Activate(go, false);
// remove the object from the used list
usedObjects.Remove(go);
// add to the available objects list
availableObjects.Add(go);
}
示例15: ReleaseResource
/// <summary>
/// 销毁资源对象。
/// </summary>
/// <param name="go">资源对象</param>
public static void ReleaseResource(Object obj, bool releaseAsset = true)
{
if (!obj)
return;
int id = obj.GetInstanceID();
if (m_resourceDic.ContainsKey(id))
{
string prefab = m_resourceDic[id];
if (releaseAsset)
{
m_assetMgr.Release(prefab);
m_resourceDic.Remove(id);
}
}
}