GetInstanceID() public method

public GetInstanceID ( ) : int
return int
コード例 #1
0
 internal static void Add(Object obj)
 {
     if (obj != null)
     {
         Add(obj.GetInstanceID());
     }
 }
コード例 #2
0
 static public int GetInstanceID(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Object self = (UnityEngine.Object)checkSelf(l);
         var ret = self.GetInstanceID();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #3
0
ファイル: DebuggerTracer.cs プロジェクト: substence/UnityVS3
    public static VisualScriptingFrameTrace GetData(int frameCount, Object vsGraphModel)
    {
        var           instanceId = vsGraphModel.GetInstanceID();
        TraceRecorder recorder   = null;

        s_Data?.TryGetValue(instanceId, out recorder);
        return(recorder?.Get(frameCount) as VisualScriptingFrameTrace);
    }
コード例 #4
0
 private LogLocation()
 {
     UnityEngine.Object debuggerFile = AssetDatabase.LoadAssetAtPath(DEBUGERFILEPATH, typeof(UnityEngine.Object));
     m_DebugerFileInstanceId = debuggerFile.GetInstanceID();
     m_ConsoleWindowType     = Type.GetType("UnityEditor.ConsoleWindow,UnityEditor");
     m_ActiveTextInfo        = m_ConsoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic);
     m_ConsoleWindowFileInfo = m_ConsoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic);
 }
コード例 #5
0
 /// <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;
 }
コード例 #6
0
ファイル: ActorEditor.cs プロジェクト: musngikd/LD33
 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];
 }
コード例 #7
0
		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);
			}
		}
コード例 #8
0
ファイル: Object.cs プロジェクト: zlhtech/unity-decompiled
 private static bool IsNativeObjectAlive(Object o)
 {
     if (o.GetCachedPtr() != IntPtr.Zero)
     {
         return(true);
     }
     if (o is MonoBehaviour || o is ScriptableObject)
     {
         return(false);
     }
     return(Object.DoesObjectWithInstanceIDExist(o.GetInstanceID()));
 }
コード例 #9
0
 static public int GetInstanceID(IntPtr l)
 {
     try {
         UnityEngine.Object self = (UnityEngine.Object)checkSelf(l);
         var ret = self.GetInstanceID();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #10
0
 static int GetInstanceID(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.Object obj = (UnityEngine.Object)ToLua.CheckObject(L, 1, typeof(UnityEngine.Object));
         int o = obj.GetInstanceID();
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #11
0
        private static bool IsNativeObjectAlive(Object o)
        {
            bool flag = o.GetCachedPtr() != IntPtr.Zero;
            bool result;

            if (flag)
            {
                result = true;
            }
            else
            {
                bool flag2 = o is MonoBehaviour || o is ScriptableObject;
                result = (!flag2 && Object.DoesObjectWithInstanceIDExist(o.GetInstanceID()));
            }
            return(result);
        }
コード例 #12
0
		/// <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);
		}
コード例 #13
0
    void Update()
    {
        MecanimEvent[] events = MecanimEventManager.GetEvents(animatorController.GetInstanceID(), animator);

        foreach (MecanimEvent e in events)
        {
            MecanimEvent.SetCurrentContext(e);

            switch (emitType)
            {
            case MecanimEventEmitTypes.Upwards:
                if (e.paramType != MecanimEventParamTypes.None)
                {
                    SendMessageUpwards(e.functionName, e.parameter, SendMessageOptions.DontRequireReceiver);
                }
                else
                {
                    SendMessageUpwards(e.functionName, SendMessageOptions.DontRequireReceiver);
                }
                break;

            case MecanimEventEmitTypes.Broadcast:
                if (e.paramType != MecanimEventParamTypes.None)
                {
                    BroadcastMessage(e.functionName, e.parameter, SendMessageOptions.DontRequireReceiver);
                }
                else
                {
                    BroadcastMessage(e.functionName, SendMessageOptions.DontRequireReceiver);
                }
                break;

            default:
                if (e.paramType != MecanimEventParamTypes.None)
                {
                    SendMessage(e.functionName, e.parameter, SendMessageOptions.DontRequireReceiver);
                }
                else
                {
                    SendMessage(e.functionName, SendMessageOptions.DontRequireReceiver);
                }
                break;
            }
        }
    }
コード例 #14
0
        public static AssetTarget Load(Object o)
        {
            AssetTarget target = null;

            if (o != null)
            {
                int instanceId = o.GetInstanceID();

                if (_object2target.ContainsKey(instanceId))
                {
                    target = _object2target[instanceId];
                }
                else
                {
                    string assetPath = AssetDatabase.GetAssetPath(o);
                    string key       = assetPath;
                    //Builtin,内置素材,path为空
                    if (string.IsNullOrEmpty(assetPath))
                    {
                        key = string.Format("Builtin______{0}", o.name);
                    }
                    else
                    {
                        key = string.Format("{0}/{1}", assetPath, instanceId);
                    }

                    if (_assetPath2target.ContainsKey(key))
                    {
                        target = _assetPath2target[key];
                    }
                    else
                    {
                        if (assetPath.StartsWith("Resources"))
                        {
                            assetPath = string.Format("{0}/{1}.{2}", assetPath, o.name, o.GetType().Name);
                        }
                        FileInfo file = new FileInfo(Path.Combine(ProjectPath, assetPath));
                        target = new AssetTarget(o, file, assetPath);
                        _object2target[instanceId] = target;
                        _assetPath2target[key]     = target;
                    }
                }
            }
            return(target);
        }
コード例 #15
0
    private static int GetInstanceID(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            UnityEngine.Object @object = (UnityEngine.Object)ToLua.CheckObject(L, 1, typeof(UnityEngine.Object));
            int instanceID             = @object.GetInstanceID();
            LuaDLL.lua_pushinteger(L, instanceID);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #16
0
        private void _RegisterSceneObject(long id, UnityObject obj)
        {
            int intId = ToInt(id);

            if (!m_persistentIDToSceneObject.ContainsKey(intId))
            {
                m_persistentIDToSceneObject.Add(intId, obj);
            }

            if (obj != null)
            {
                int instanceId = obj.GetInstanceID();
                if (!m_sceneObjectIDToPersistentID.ContainsKey(instanceId))
                {
                    m_sceneObjectIDToPersistentID.Add(instanceId, intId);
                }
            }
        }
コード例 #17
0
        //Method for getting path of selected object or folder in project window
        private static string GetPath(Object obj)
        {
            string path;

            if (obj == null)
            {
                return("");
            }

            //Getting path of the selected object
            path = AssetDatabase.GetAssetPath(obj.GetInstanceID( ));
            if (path.Length > 0)
            {
                return(Directory.Exists(path) ? path : AssetDatabase.GetAssetPath(obj));
            }

            return("");
        }
コード例 #18
0
ファイル: UIDebugStats.cs プロジェクト: zhuoweip/FrameScript
    public void StartPanelWidget(UnityEngine.Object p)
    {
        if (!enabled)
        {
            return;
        }

        int          pInstID = p.GetInstanceID();
        UITimingDict td      = null;

        if (!m_widgetTicks.TryGetValue(pInstID, out td))
        {
            td = new UITimingDict();
            m_widgetTicks.Add(pInstID, td);
        }

        td.StartTiming();
    }
コード例 #19
0
    /// <summary>
    /// 同步获取实例
    /// </summary>
    /// <param name="abName"></param>
    /// <param name="assetName"></param>
    /// <param name="onLoad"></param>
    public UnityEngine.Object GetInstanceSync(string abName, string assetName, System.Action <UnityEngine.Object> onLoad)
    {
        UnityEngine.Object obj = GetPrefabSync(abName, assetName);
        if (obj == null)
        {
            string str = string.Format("ResourcesManager.GetInstance:abName {0}, assetName {1} 加载失败", abName, assetName);
            Debug.LogError(str);
            return(null);
        }

        obj = UnityEngine.Object.Instantiate(obj);
        m_DictInstanceIDABName.Add(obj.GetInstanceID(), abName);
        if (onLoad != null)
        {
            onLoad(obj);
        }
        return(obj);
    }
コード例 #20
0
        public static bool DoesSelectedFolderContainOnlyScenes(UnityEngine.Object selectedFolder)
        {
            string path = Path.GetFullPath(AssetDatabase.GetAssetPath(selectedFolder.GetInstanceID()));

            string[] files = Directory.GetFiles(path);

            string[] sceneFiles     = Directory.GetFiles(path, "*.unity");
            string[] sceneMetaFiles = Directory.GetFiles(path, "*.unity.meta");

            if (files.Length == sceneFiles.Length + sceneMetaFiles.Length)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #21
0
        internal static bool ShowAtPosition(UnityEngine.Object targetObj, Rect activatorRect, bool showLabelIcons)
        {
            int  instanceId = targetObj.GetInstanceID();
            bool flag       = DateTime.Now.Ticks / 10000L < IconSelector.s_LastClosedTime + 50L;

            if (instanceId == IconSelector.s_LastInstanceID && flag)
            {
                return(false);
            }
            Event.current.Use();
            IconSelector.s_LastInstanceID = instanceId;
            if ((UnityEngine.Object)IconSelector.s_IconSelector == (UnityEngine.Object)null)
            {
                IconSelector.s_IconSelector = ScriptableObject.CreateInstance <IconSelector>();
            }
            IconSelector.s_IconSelector.Init(targetObj, activatorRect, showLabelIcons);
            return(true);
        }
コード例 #22
0
    /// <summary>
    /// 缓存资源项
    /// </summary>
    private void CacheResourceItem(string path, ref ResourceItem item, uint crc, UnityEngine.Object obj, int addRefCount = 1)
    {
        WashOut();

        if (item == null)
        {
            Debug.LogError("item is null in path :" + path); return;
        }
        if (obj == null)
        {
            Debug.LogError("obj is null in path :" + path); return;
        }
        item.m_Obj            = obj;
        item.m_GUID           = obj.GetInstanceID();
        item.m_LastUseTime    = Time.realtimeSinceStartup;
        item.RefCount        += addRefCount;
        AssetDict[item.m_Crc] = item;
    }
コード例 #23
0
 public static void UnloadAsset(UnityEngine.Object go, bool releaseAsset = true)
 {
     if (go != 0)
     {
         int instanceID = go.GetInstanceID();
         if (m_gameObjectNameMapping.ContainsKey(instanceID))
         {
             if (releaseAsset)
             {
                 m_assetMgr.UnloadAsset(m_gameObjectNameMapping[instanceID]);
             }
         }
         else
         {
             LoggerHelper.Warning("go not in mapping: " + go.name, true);
         }
     }
 }
コード例 #24
0
 private UnityEngine.Object NewFromUnusedResources(string resname)
 {
     UnityEngine.Object obj = null;
     if (kUnusedResources.ContainsKey(resname))
     {
         Queue <UnityEngine.Object> queue = kUnusedResources[resname];
         if (queue.Count > 0)
         {
             obj = queue.Dequeue();
             int objId = obj.GetInstanceID();
             if (kDestoryResources.ContainsKey(objId))
             {
                 kDestoryResources.Remove(objId);
             }
         }
     }
     return(obj);
 }
コード例 #25
0
ファイル: Classes.cs プロジェクト: hagusen/AI-Testing
        public override string ToString()
        {
            string msg;

            if (string.IsNullOrEmpty(Message) && InnerException != null)
            {
                msg = InnerException.ToString();
            }
            else
            {
                msg = base.ToString();
            }
            if (graphReference != null)
            {
                msg = msg.AddLineInEnd().Add(KEY_REFERENCE + graphReference?.GetInstanceID());
            }
            return(msg);
        }
コード例 #26
0
        /// <summary>
        /// Given a UnityEngine.Object whose == operator returns true when compared against null, this
        /// attempts to make it not be null, but trying to find instance again using the target's Instance ID.
        /// </summary>
        /// <param name="obj"> [in,out] The null object. </param>
        /// <returns> True if it succeeds, false if it fails. </returns>
        public static bool TryToFixNull(ref Object obj)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(obj == null);
                        #endif

                        #if UNITY_EDITOR
            // if reference not actually null try to recover UnityEngine.Object reference using target InstanceID
            if (!ReferenceEquals(obj, null))
            {
                var id = obj.GetInstanceID();
                obj = EditorUtility.InstanceIDToObject(id);
                return(obj);
            }
                        #endif

            return(false);
        }
コード例 #27
0
    /// <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);
            }
        }
    }
コード例 #28
0
    public static int GetInstanceID(IntPtr l)
    {
        int result;

        try
        {
            UnityEngine.Object @object = (UnityEngine.Object)LuaObject.checkSelf(l);
            int instanceID             = @object.GetInstanceID();
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, instanceID);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
コード例 #29
0
    internal void ReturnObject(UnityEngine.Object obj)
    {
        var isGo  = obj is GameObject;
        var insId = obj.GetInstanceID();

        if (isGo)
        {
            if (objectDic.ContainsKey(insId))
            {
                var findObj = objectDic[insId];
                findObj.Return();
            }
            else
            {
                Logx.LogWarning("the insId is not found : " + insId);
            }
        }
    }
コード例 #30
0
        public void DependOnAsset(GameObject dependent, Object dependsOn)
        {
            if (dependent == null)
            {
                throw new ArgumentNullException(nameof(dependent));
            }
            if (dependsOn == null)
            {
                throw new ArgumentNullException(nameof(dependsOn));
            }
            if (!dependsOn.IsAsset() && !dependsOn.IsPrefab())
            {
                throw new ArgumentException($"The target object {dependsOn.name} is not an asset.", nameof(dependsOn));
            }
            int index = RegisterDependentGameObject(dependent);

            AssetDependentsByInstanceId.Add(dependsOn.GetInstanceID(), index);
        }
コード例 #31
0
        private HierarchyProperty GetLastSelected()
        {
            int num = -1;
            HierarchyProperty result = null;

            UnityEngine.Object[] objects = Selection.objects;
            for (int i = 0; i < objects.Length; i++)
            {
                UnityEngine.Object @object           = objects[i];
                HierarchyProperty  hierarchyProperty = new HierarchyProperty(HierarchyType.Assets);
                if (hierarchyProperty.Find(@object.GetInstanceID(), this.m_ExpandedArray) && hierarchyProperty.row > num)
                {
                    num    = hierarchyProperty.row;
                    result = hierarchyProperty;
                }
            }
            return(result);
        }
コード例 #32
0
        public void SerializeUnityObject(UnityEngine.Object ob)
        {
            if (ob == null)
            {
                writer.Write(int.MaxValue);
                return;
            }

            int    inst = ob.GetInstanceID();
            string name = ob.name;
            string type = ob.GetType().AssemblyQualifiedName;
            string guid = "";

            //Write scene path if the object is a Component or GameObject
            Component  component = ob as Component;
            GameObject go        = ob as GameObject;

            if (component != null || go != null)
            {
                if (component != null && go == null)
                {
                    go = component.gameObject;
                }

                UnityReferenceHelper helper = go.GetComponent <UnityReferenceHelper>();

                if (helper == null)
                {
                    Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + ob.name + "'");
                    helper = go.AddComponent <UnityReferenceHelper>();
                }

                //Make sure it has a unique GUID
                helper.Reset();

                guid = helper.GetGUID();
            }


            writer.Write(inst);
            writer.Write(name);
            writer.Write(type);
            writer.Write(guid);
        }
コード例 #33
0
        private void CreateGameObjectContextClick(GenericMenu menu, int contextClickedItemID)
        {
            menu.AddItem(EditorGUIUtility.TextContent("Copy"), false, new GenericMenu.MenuFunction(this.CopyGO));
            menu.AddItem(EditorGUIUtility.TextContent("Paste"), false, new GenericMenu.MenuFunction(this.PasteGO));
            menu.AddSeparator(string.Empty);
            if (!base.hasSearchFilter && this.m_TreeViewState.selectedIDs.Count == 1)
            {
                menu.AddItem(EditorGUIUtility.TextContent("Rename"), false, new GenericMenu.MenuFunction(this.RenameGO));
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Rename"));
            }
            menu.AddItem(EditorGUIUtility.TextContent("Duplicate"), false, new GenericMenu.MenuFunction(this.DuplicateGO));
            menu.AddItem(EditorGUIUtility.TextContent("Delete"), false, new GenericMenu.MenuFunction(this.DeleteGO));
            menu.AddSeparator(string.Empty);
            bool flag = false;

            if (this.m_TreeViewState.selectedIDs.Count == 1)
            {
                GameObjectTreeViewItem gameObjectTreeViewItem = this.treeView.FindNode(this.m_TreeViewState.selectedIDs[0]) as GameObjectTreeViewItem;
                if (gameObjectTreeViewItem != null)
                {
                    UnityEngine.Object prefab = PrefabUtility.GetPrefabParent(gameObjectTreeViewItem.objectPPTR);
                    if (prefab != null)
                    {
                        menu.AddItem(EditorGUIUtility.TextContent("Select Prefab"), false, delegate
                        {
                            Selection.activeObject = prefab;
                            EditorGUIUtility.PingObject(prefab.GetInstanceID());
                        });
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Select Prefab"));
            }
            menu.AddSeparator(string.Empty);
            this.AddCreateGameObjectItemsToMenu(menu, (from t in Selection.transforms
                                                       select t.gameObject).ToArray <GameObject>(), false, false, 0);
            menu.ShowAsContext();
        }
コード例 #34
0
ファイル: AssetBundleUtil.cs プロジェクト: xfilson/dn_asset
        public static AssetTarget Load(FileInfo file, System.Type t)
        {
            AssetTarget target   = null;
            string      fullPath = file.FullName;
            int         index    = fullPath.IndexOf("Assets");

            if (index != -1)
            {
                string assetPath = fullPath.Substring(index);
                if (_assetPath2target.ContainsKey(assetPath))
                {
                    target = _assetPath2target[assetPath];
                }
                else
                {
                    UnityEngine.Object o = null;
                    if (t == null)
                    {
                        o = AssetDatabase.LoadMainAssetAtPath(assetPath);
                    }
                    else
                    {
                        o = AssetDatabase.LoadAssetAtPath(assetPath, t);
                    }

                    if (o != null)
                    {
                        int instanceId = o.GetInstanceID();
                        if (_object2target.ContainsKey(instanceId))
                        {
                            target = _object2target[instanceId];
                        }
                        else
                        {
                            target = new AssetTarget(o, file, assetPath);
                            string key = string.Format("{0}/{1}", assetPath, instanceId);
                            _assetPath2target[key]     = target;
                            _object2target[instanceId] = target;
                        }
                    }
                }
            }
            return(target);
        }
コード例 #35
0
    public void Find()
    {
        EditorUtility.DisplayProgressBar("Find Reference", "Finding...", 0);

        var instanceId = Res.GetInstanceID();

        var gos = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);

        string log = "";


        int i = 0;

        try
        {
            foreach (var go in gos)
            {
                var assetPath = AssetDatabase.GetAssetPath(go.GetInstanceID());
                var paths     = AssetDatabase.GetDependencies(new[] { assetPath });
                foreach (var path in paths)
                {
                    var res = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
                    if (res.GetInstanceID() == instanceId)
                    {
                        log += assetPath;
                        log += "\n";
                    }
                }
                EditorUtility.DisplayProgressBar("Find Reference", assetPath, i / gos.Length);
                i++;
            }
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }


        Debug.Log(log);
    }
コード例 #36
0
    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");
                }
            }
        }
    }
コード例 #37
0
ファイル: sObject.cs プロジェクト: jlonardi/igp-DnM
 public sObject(Object o)
 {
     hideFlags = o.hideFlags;
     name = o.name;
     instanceID = o.GetInstanceID();
 }
コード例 #38
0
 /// <summary>
 /// <para>Returns whether an object is contained in the current selection.</para>
 /// </summary>
 /// <param name="instanceID"></param>
 /// <param name="obj"></param>
 public static bool Contains(Object obj)
 {
     return Contains(obj.GetInstanceID());
 }
コード例 #39
0
ファイル: Logger.cs プロジェクト: Kartoshka/Crabby-Pulse-2
	public static void LogSingleInstance(Object instanceToLog, params object[] toLog) {
		if (instanceDict.ContainsKey(instanceToLog.GetType())) {
			if (instanceDict[instanceToLog.GetType()] == instanceToLog.GetInstanceID()) {
				Log(toLog);
			}
		}
		else {
			instanceDict[instanceToLog.GetType()] = instanceToLog.GetInstanceID();
			Log(toLog);
		}
	}
コード例 #40
0
    void OnGUI()
    {
        if (Event.current.type == EventType.Layout)
        {
            if (newAssetPath != null)
            {
                GUIUtility.keyboardControl = 0;
                GUIUtility.hotControl = 0;
                assetsPaths = newAssetPath;
                newAssetPath = null;
            }
            if (assetsPaths == null)
            {
                assetsPaths = "\n";
            }
            else
            {
                if (!assetsPaths.EndsWith("\n"))
                {
                    assetsPaths = assetsPaths + "\n";
                }
            }
            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);
    }
コード例 #41
0
 /// <summary>
 ///     Creates a new PlayModeChangesHelper.
 /// </summary>
 /// <param name="persistChangesKey">
 ///     an optional key if you want to enable / disable changes just
 ///     for a specific object
 /// </param>
 /// <param name="target">the target this operates on</param>
 public PlayModeChangesHelper(Object target, string persistChangesKey = "PersistChanges")
 {
     this.componentName = target.GetType().Name;
     this.persistChangesKey = persistChangesKey;
     this.target = target;
     counterForInstance = counter++;
     #if DEBUG_PERSIST_PLAYMODE_CHANGES
     Debug.Log(string.Format("Instantiated PlaymodeChangesHelper {0}={1}, {2}, {3}", target.name, target.GetInstanceID(), persistChangesKey, counterForInstance));
     #endif
     EditorApplication.update += new EditorApplication.CallbackFunction(EditorUpdate);
     EditorApplication.playmodeStateChanged += new EditorApplication.CallbackFunction(PlayModeChanged);
 }
コード例 #42
0
ファイル: FXMakerTooltip.cs プロジェクト: sylafrs/rugby
 public static string AddPopupPreview(Object hoverCom)
 {
     return "|"+"#"+hoverCom.GetInstanceID();
 }
コード例 #43
0
 /// <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);
 
 }
コード例 #44
0
 private bool FrameObject(Object target)
 {
     if (target != null)
     {
         HierarchyProperty property = new HierarchyProperty(HierarchyType.Assets);
         if (property.Find(target.GetInstanceID(), null))
         {
             while (property.Parent())
             {
                 this.SetExpanded(property.instanceID, true);
             }
         }
         property.Reset();
         if (property.Find(target.GetInstanceID(), this.m_ExpandedArray))
         {
             this.ScrollTo((m_RowHeight * property.row) + this.m_SpaceAtTheTop);
             return true;
         }
     }
     return false;
 }
コード例 #45
0
 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;
 }
コード例 #46
0
 public static void CreateAsset(Object asset, string pathName)
 {
     StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), ScriptableObject.CreateInstance<DoCreateNewAsset>(), pathName, AssetPreview.GetMiniThumbnail(asset), null);
 }
コード例 #47
0
 public static void ShowCreatedAsset(Object o)
 {
     Selection.activeObject = o;
     if (o != null)
     {
         FrameObjectInProjectWindow(o.GetInstanceID());
     }
 }
コード例 #48
0
ファイル: AssetCacheMgr.cs プロジェクト: lbddk/ahzs-client
 /// <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);
     }
 }
コード例 #49
0
ファイル: AssetBundleUtils.cs プロジェクト: tangzx/ABSystem
        public static AssetTarget Load(Object o)
        {
            AssetTarget target = null;
            if (o != null)
            {
                int instanceId = o.GetInstanceID();

                if (_object2target.ContainsKey(instanceId))
                {
                    target = _object2target[instanceId];
                }
                else
                {
                    string assetPath = AssetDatabase.GetAssetPath(o);
                    string key = assetPath;
                    //Builtin,内置素材,path为空
                    if (string.IsNullOrEmpty(assetPath))
                        key = string.Format("Builtin______{0}", o.name);
                    else
                        key = string.Format("{0}/{1}", assetPath, instanceId);

                    if (_assetPath2target.ContainsKey(key))
                    {
                        target = _assetPath2target[key];
                    }
                    else
                    {
                        if (assetPath.StartsWith("Resources"))
                        {
                            assetPath = string.Format("{0}/{1}.{2}", assetPath, o.name, o.GetType().Name);
                        }
                        FileInfo file = new FileInfo(Path.Combine(ProjectPath, assetPath));
                        target = new AssetTarget(o, file, assetPath);
                        _object2target[instanceId] = target;
                        _assetPath2target[key] = target;
                    }
                }
            }
            return target;
        }
コード例 #50
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="target">The target</param>
		internal PersistedComponent(Object target)
		{
			/**
			 * 1. Save metadata
			 * */
			_target = target;
			_type = _target.GetType();
			_instanceId = _target.GetInstanceID();

			var adapter = _target as ComponentAdapter;
			if (null != adapter)
				ComponentRegistry.Instance.Register(_instanceId, adapter);

#if DEBUG
			if (DebugMode)
			{
				_sb = new StringBuilder();
				foreach (MemberInfo memberInfo in _type.GetMembers())
				{
					var attributes = CoreReflector.GetMemberAttributes<SaveableAttribute>(memberInfo);
					//foreach (Attribute attr in memberInfo.GetCustomAttributes(typeof(SaveableAttribute), true))
					foreach (var attribute in attributes)
					{
						if (attribute.IsSaveable)
						{
							_sb.AppendLine(string.Format("    - {0}; {1}", memberInfo.Name, memberInfo));
						}
					}
				}

				Debug.Log(string.Format(@"[{0}] SaveableMembers: {1}
{2}", _target, SaveableMembers.Count(_type), _sb), _target);
			}
#endif

			/**
			 * 2. Adding the new member info to SaveableMembers dictionary
			 * This is done for each saveable type in the component
			 * Each member that must be persisted should be decorated with [Saveable]
			 * */
			foreach (MemberInfo memberInfo in _type.GetMembers())
			{
				var attributes = CoreReflector.GetMemberAttributes<SaveableAttribute>(memberInfo);
				foreach (SaveableAttribute attribute in attributes)
				{
					if (attribute.IsSaveable)
					{
						// doesn't add anything if it already exists
						SaveableMembers.Put(_type, memberInfo);
					}
				}
			}

			/**
			 * 3. Take a snapshot of the original values
			 * */
			TakeSnapshot(_originalValues);
		}
コード例 #51
0
 /// <summary>
 ///     Call this in 
 ///     <a href="http://docs.unity3d.com/Documentation/ScriptReference/ScriptableObject.OnEnable.html?from=Editor">OnEnable()</a> 
 ///     of your custom inspector.
 /// </summary>
 /// <param name="target">
 ///     the object being inspected, see 
 ///     <a href="http://docs.unity3d.com/Documentation/ScriptReference/Editor-target.html">Editor.target</a>
 /// </param>
 public void InspectorEnabled(Object target)
 {
     #if DEBUG_PERSIST_PLAYMODE_CHANGES
     if (this.target != target || this.target.GetInstanceID() != target.GetInstanceID()) {
         Debug.Log(string.Format("New target: {0}, {1} ({2})", target.name, target.GetInstanceID(), counterForInstance));
     } else {
         Debug.Log(string.Format("Kept target: {0}, {1} ({2})", target.name, target.GetInstanceID(), counterForInstance));
     }
     #endif
     this.target = target;
     firstInspectorGUIAfterEnable = true;
 }
コード例 #52
0
 internal void Show(Object obj, Type requiredType, SerializedProperty property, bool allowSceneObjects, List<int> allowedInstanceIDs)
 {
     this.m_AllowSceneObjects = allowSceneObjects;
     this.m_IsShowingAssets = true;
     this.m_AllowedIDs = allowedInstanceIDs;
     string requiredClassName = "";
     if (property != null)
     {
         requiredClassName = property.objectReferenceTypeString;
         obj = property.objectReferenceValue;
         this.m_ObjectBeingEdited = property.serializedObject.targetObject;
         if ((this.m_ObjectBeingEdited != null) && EditorUtility.IsPersistent(this.m_ObjectBeingEdited))
         {
             this.m_AllowSceneObjects = false;
         }
     }
     else if (requiredType != null)
     {
         requiredClassName = requiredType.Name;
     }
     if (this.m_AllowSceneObjects)
     {
         if (obj != null)
         {
             if (typeof(Component).IsAssignableFrom(obj.GetType()))
             {
                 obj = ((Component) obj).gameObject;
             }
             this.m_IsShowingAssets = EditorUtility.IsPersistent(obj) || GuessIfUserIsLookingForAnAsset(requiredClassName, false);
         }
         else
         {
             this.m_IsShowingAssets = GuessIfUserIsLookingForAnAsset(requiredClassName, true);
         }
     }
     else
     {
         this.m_IsShowingAssets = true;
     }
     this.m_DelegateView = GUIView.current;
     this.m_RequiredType = requiredClassName;
     this.m_SearchFilter = "";
     this.m_OriginalSelection = obj;
     this.m_ModalUndoGroup = Undo.GetCurrentGroup();
     ContainerWindow.SetFreezeDisplay(true);
     base.ShowWithMode(ShowMode.AuxWindow);
     base.titleContent = new GUIContent("Select " + requiredClassName);
     Rect position = base.m_Parent.window.position;
     position.width = EditorPrefs.GetFloat("ObjectSelectorWidth", 200f);
     position.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390f);
     base.position = position;
     base.minSize = new Vector2(200f, 335f);
     base.maxSize = new Vector2(10000f, 10000f);
     this.SetupPreview();
     base.Focus();
     ContainerWindow.SetFreezeDisplay(false);
     this.m_FocusSearchFilter = true;
     base.m_Parent.AddToAuxWindowList();
     int initialSelectedTreeViewItemID = (obj == null) ? 0 : obj.GetInstanceID();
     if ((property != null) && property.hasMultipleDifferentValues)
     {
         initialSelectedTreeViewItemID = 0;
     }
     if (ShouldTreeViewBeUsed(requiredClassName))
     {
         this.m_ObjectTreeWithSearch.Init(base.position, this, new UnityAction<ObjectTreeForSelector.TreeSelectorData>(this.CreateAndSetTreeView), new UnityAction<TreeViewItem>(this.TreeViewSelection), new UnityAction(this.ItemWasDoubleClicked), initialSelectedTreeViewItemID, 0);
     }
     else
     {
         this.InitIfNeeded();
         int[] selectedInstanceIDs = new int[] { initialSelectedTreeViewItemID };
         this.m_ListArea.InitSelection(selectedInstanceIDs);
         if (initialSelectedTreeViewItemID != 0)
         {
             this.m_ListArea.Frame(initialSelectedTreeViewItemID, true, false);
         }
     }
 }
コード例 #53
0
ファイル: KeyEditor.cs プロジェクト: musngikd/LD33
 public static void InitEditorWindow(Object obj)
 {
     currentEditor = (KeyEditor)EditorWindow.GetWindow<KeyEditor>();
     currentEditor.instanceId = obj.GetInstanceID();
     currentEditor.title = "Key Editor";
 }
コード例 #54
0
        internal static GameObject   GetPlaceholderGameObject( Object placeHolder )
        {
            if ( !placeHolder )
                return null;

            int owningID = UnityEditorInternal.InternalEditorUtility.GetGameObjectInstanceIDFromComponent( placeHolder.GetInstanceID() );
            GameObject owningGameObj = UnityEditor.EditorUtility.InstanceIDToObject(owningID) as GameObject;
            if ( !owningGameObj )
                owningGameObj = placeHolder as GameObject;

            return owningGameObj;
        }
コード例 #55
0
ファイル: AssetCacheMgr.cs プロジェクト: lbddk/ahzs-client
 /// <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);
         }
     }
 }
コード例 #56
0
ファイル: DebugHelper.cs プロジェクト: RabitBox/FlickBattler
 public static int GetDebugId(Object obj)
 {
     return int.MinValue + (obj.GetInstanceID() << 10);
 }
コード例 #57
0
ファイル: AssetCacheMgr.cs プロジェクト: lbddk/ahzs-client
 public static void UnloadAsset(Object go, bool releaseAsset = true)
 {
     if (go)
     {
         int guid = go.GetInstanceID();
         if (m_gameObjectNameMapping.ContainsKey(guid))
         {
             if (releaseAsset)
                 m_assetMgr.UnloadAsset(m_gameObjectNameMapping[guid]);
             //m_gameObjectNameMapping.Remove(guid);
         }
         else
         {
             LoggerHelper.Warning("go not in mapping: " + go.name);
         }
     }
 }
コード例 #58
0
 internal static void Remove(Object obj)
 {
     if (obj != null)
     {
         Remove(obj.GetInstanceID());
     }
 }