Пример #1
0
 public override void DeleteAsset(UnityEngine.Object Asset)
 {
     if (Asset != null && AssetInstanceIDList_.Contains(Asset.GetInstanceID()))
     {
         AssetInstanceIDList_.Remove(Asset.GetInstanceID());
         UnityEngine.Object.Destroy(Asset);
         DecRef();
     }
 }
Пример #2
0
        public static UpdateTask UpdateWhile(this UnityEngine.Object sender, Action action, Func <bool> endCondition, Action then = null, UpdateType updateType = UpdateType.normal)
        {
            var task = new UpdateTask(action, endCondition, then, sender ? sender.GetInstanceID() : 0);

            AnilUpdate.Register(task, updateType);
            return(task);
        }
Пример #3
0
        static bool IsNativeObjectAlive(UnityEngine.Object o)
        {
            if (o.GetCachedPtr() != IntPtr.Zero)
            {
                return(true);
            }

            //Ressurection of assets is complicated.
            //For almost all cases, if you have a c# wrapper for an asset like a material,
            //if the material gets moved, or deleted, and later placed back, the persistentmanager
            //will ensure it will come back with the same instanceid.
            //in this case, we want the old c# wrapper to still "work".
            //we only support this behaviour in the editor, even though there
            //are some cases in the player where this could happen too. (when unloading things from assetbundles)
            //supporting this makes all operator== slow though, so we decided to not support it in the player.
            //
            //we have an exception for assets that "are" a c# object, like a MonoBehaviour in a prefab, and a ScriptableObject.
            //in this case, the asset "is" the c# object,  and you cannot actually pretend
            //the old wrapper points to the new c# object. this is why we make an exception in the operator==
            //for this case. If we had a c# wrapper to a persistent monobehaviour, and that one gets
            //destroyed, and placed back with the same instanceID,  we still will say that the old
            //c# object is null.
            if (o is MonoBehaviour || o is ScriptableObject)
            {
                return(false);
            }

            return(DoesObjectWithInstanceIDExist(o.GetInstanceID()));
        }
Пример #4
0
        internal UnityEngine.Object NewObject(UnityEngine.Object prefab, float timeToRecycle)
        {
            UnityEngine.Object obj = null;
            if (null != prefab)
            {
                float curTime = UnityEngine.Time.time;
                float time    = timeToRecycle;
                if (timeToRecycle > 0)
                {
                    time += curTime;
                }
                int resId = prefab.GetInstanceID();
                obj = NewFromUnusedResources(resId);
                if (null == obj)
                {
                    obj = UnityEngine.GameObject.Instantiate(prefab);
                }
                if (null != obj)
                {
                    AddToUsedResources(obj, resId, time);

                    InitializeObject(obj);
                }
            }
            return(obj);
        }
Пример #5
0
        /// <summary> Gets EditorKey representing an Editor with the given target. </summary>
        /// <param name="target"> Editor target. This cannot be null. </param>
        /// <param name="isAssetImporterEditor"> True is Editor is an asset importer editor. </param>
        public EditorKey([NotNull] Object target, bool isAssetImporterEditor)
        {
            if (ReferenceEquals(target, null))
            {
                hash = 1;
            }
            else
            {
                unchecked                 // Overflow is fine, just wrap
                {
                    hash = 761 + target.GetInstanceID();

                    // This was needed to distinguish between GameObjectInspector and ModelImporterEditor,
                    // since both refer to same GameObject target.
                    if (isAssetImporterEditor)
                    {
                        hash = hash * 761;
                    }
                                        #if DEV_MODE && PI_ASSERTATIONS
                    else
                    {
                        UnityEngine.Debug.Assert(!(target is UnityEditor.AssetImporter), StringUtils.TypeToString(target) + " was an AssetImporter but isAssetImporterEditor was " + StringUtils.False);
                    }
                                        #endif
                }
            }
        }
 public static string ToHyperLink(this UnityEngine.Object obj)
 {
     if (string.IsNullOrEmpty(obj.name))
     {
         return(string.Empty);
     }
     return($"<a {k_InstanceID}=\"{obj.GetInstanceID()}\">{obj.name}</a>");
 }
Пример #7
0
 public PreviewableKey([NotNull] Type setPreviewType, [NotNull] Object setTarget)
 {
     unchecked             // Overflow is fine, just wrap
     {
         hash = 761 + setTarget.GetInstanceID();
         hash = hash * 1777 + setPreviewType.GetHashCode();
     }
 }
Пример #8
0
 internal void RemovePersistentListener(UnityEngine.Object target, MethodInfo method)
 {
     if (method != null && !method.IsStatic && !(target == null) && target.GetInstanceID() != 0)
     {
         this.m_PersistentCalls.RemoveListeners(target, method.Name);
         this.DirtyPersistentCalls();
     }
 }
Пример #9
0
        /// <summary>
        /// Creates an event target associated with the supplied Unity Object.
        /// </summary>
        /// <param name="obj">The object to associate the target with.</param>
        /// <returns>The new target.</returns>
        public static EventTarget CreateTarget(Object obj)
        {
            if (obj == null)
            {
                return(NULL_TARGET);
            }

            return(new EventTarget(obj.GetInstanceID()));
        }
Пример #10
0
 internal void RemovePersistentListener(UnityEngine.Object target, MethodInfo method)
 {
     if (method == null || method.IsStatic || target == null || target.GetInstanceID() == 0)
     {
         return;
     }
     this.m_PersistentCalls.RemoveListeners(target, method.Name);
     this.DirtyPersistentCalls();
 }
Пример #11
0
        /// <summary>
        /// wait while condition false then action
        /// </summary>
        public static WaitUntilTask WaitUntil(Func <bool> endCondition, Action then, UnityEngine.Object calledInstance = null)
        {
#if UNITY_EDITOR
            int id   = calledInstance ? calledInstance.GetInstanceID() : 0;
            var task = new WaitUntilTask(endCondition, then, id);
#else
            var task = new WaitUntilTask(endCondition, then);
#endif
            AnilUpdate.Register(task, UpdateType.normal);
            return(task);
        }
Пример #12
0
        /// <summary>
        /// this allows you update action, <b>you can recive input</b>
        /// </summary>
        /// <param name="action"><param>will be updated action</param>
        /// <param name="endCnd"><param>do while this condition true</param>
        /// <param name="then">then do</param>
        public static UpdateTask UpdateWhile(Action action, Func <bool> endCnd, Action then = null, UnityEngine.Object calledInstance = null, UpdateType updateType = UpdateType.normal)
        {
#if UNITY_EDITOR
            int id   = calledInstance ? calledInstance.GetInstanceID() : 0;
            var task = new UpdateTask(action, endCnd, then, id);
#else
            var task = new UpdateTask(action, endCondition, then);
#endif
            AnilUpdate.Register(task, updateType);
            return(task);
        }
Пример #13
0
 internal void PreloadResource(UnityEngine.Object prefab, int count)
 {
     if (null != prefab)
     {
         for (int i = 0; i < count; ++i)
         {
             UnityEngine.Object obj = UnityEngine.GameObject.Instantiate(prefab);
             AddToUnusedResources(prefab.GetInstanceID(), obj);
         }
     }
 }
Пример #14
0
 private static bool IsNativeObjectAlive(UnityEngine.Object o)
 {
     if (o.GetCachedPtr() != IntPtr.Zero)
     {
         return(true);
     }
     if ((o is MonoBehaviour) || (o is ScriptableObject))
     {
         return(false);
     }
     return(DoesObjectWithInstanceIDExist(o.GetInstanceID()));
 }
Пример #15
0
 public static void InitInstanceId()
 {
     foreach (LogConfig item in logConfigList)
     {
         if (item.instanceId > 0)
         {
             return;
         }
         Object asset = AssetDatabase.LoadAssetAtPath <Object>(item.path);
         item.instanceId = asset.GetInstanceID();
     }
 }
Пример #16
0
    public static int GetInstanceID(System.IntPtr L)
    {
        int nargs = LuaAPI.GetTop(L);

        if (nargs == 1 && LuaAPI.IsObject(L, 1))
        {
            UnityEngine.Object arg0 = (UnityEngine.Object)LuaCallback.ToObject(L, 1);
            System.Int32       res  = arg0.GetInstanceID();
            LuaCallback.PushNumber(L, res);
            return(1);
        }
        return(0);
    }
Пример #17
0
        ///////////////////////////////////////////////////////////////
        // Utility methods
        ///////////////////////////////////////////////////////////////

        private static string GetSelectedFolderPath()
        {
            Object obj = Selection.activeObject;

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

            string path = AssetDatabase.GetAssetPath(obj.GetInstanceID());

            return(!Directory.Exists(path) ? null : path);
        }
Пример #18
0
        public static int GetInstanceID(IntPtr L)
        {
            int result = 1;
            int count  = LuaDLL.lua_gettop(L);

            if (count != 1)
            {
                LuaStatic.traceback(L, "count not enough");
                LuaDLL.lua_error(L);
                return(result);
            }
            UnityEngine.Object obj = LuaStatic.GetObj(L, 1) as UnityEngine.Object;
            LuaDLL.lua_pushnumber(L, obj.GetInstanceID());
            return(result);
        }
Пример #19
0
        static StackObject *GetInstanceID_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.Object instance_of_this_method = (UnityEngine.Object) typeof(UnityEngine.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetInstanceID();

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method;
            return(__ret + 1);
        }
Пример #20
0
        int UnityEngineObject_m_GetInstanceID(RealStatePtr L, int gen_param_count)
        {
            ObjectTranslator translator = this;


            UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)translator.FastGetCSObj(L, 1);


            {
                int gen_ret = gen_to_be_invoked.GetInstanceID(  );
                LuaAPI.xlua_pushinteger(L, gen_ret);



                return(1);
            }
        }
Пример #21
0
        protected bool ValidateRegistration(MethodInfo method, object targetObj, PersistentListenerMode mode, Type argumentType)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method", UnityString.Format("Can not register null method on {0} for callback!", new object[]
                {
                    targetObj
                }));
            }
            UnityEngine.Object @object = targetObj as UnityEngine.Object;
            if (@object == null || @object.GetInstanceID() == 0)
            {
                throw new ArgumentException(UnityString.Format("Could not register callback {0} on {1}. The class {2} does not derive from UnityEngine.Object", new object[]
                {
                    method.Name,
                    targetObj,
                    (targetObj != null) ? targetObj.GetType().ToString() : "null"
                }));
            }
            if (method.IsStatic)
            {
                throw new ArgumentException(UnityString.Format("Could not register listener {0} on {1} static functions are not supported.", new object[]
                {
                    method,
                    base.GetType()
                }));
            }
            bool result;

            if (this.FindMethod(method.Name, targetObj, mode, argumentType) == null)
            {
                Debug.LogWarning(UnityString.Format("Could not register listener {0}.{1} on {2} the method could not be found.", new object[]
                {
                    targetObj,
                    method,
                    base.GetType()
                }));
                result = false;
            }
            else
            {
                result = true;
            }
            return(result);
        }
Пример #22
0
        static int _m_GetInstanceID(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            UnityEngine.Object __cl_gen_to_be_invoked = (UnityEngine.Object)translator.FastGetCSObj(L, 1);


            try {
                {
                    int __cl_gen_ret = __cl_gen_to_be_invoked.GetInstanceID(  );
                    LuaAPI.xlua_pushinteger(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
Пример #23
0
        public AssetBuildInfo Load(FileInfo fileInfo, Type type)
        {
            AssetBuildInfo assetBuildInfo = null;
            string         fullPath       = fileInfo.FullName();
            int            indexEnd       = fullPath.IndexEndOf(FilePathConst.ProjectPath);

            if (indexEnd != -1)
            {
                string assetPath = fullPath.Substring(indexEnd + 1);

                if (_assetPath2buildInfo.ContainsKey(assetPath))
                {
                    assetBuildInfo = _assetPath2buildInfo[assetPath];
                }
                else
                {
                    Object obj = type == null
                                                ? AssetDatabase.LoadMainAssetAtPath(assetPath)
                                                : AssetDatabase.LoadAssetAtPath(assetPath, type);

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

                        if (_object2buildInfo.ContainsKey(instanceId))
                        {
                            assetBuildInfo = _object2buildInfo[instanceId];
                        }
                        else
                        {
                            assetBuildInfo = new AssetBuildInfo(obj, fileInfo, assetPath);
                            _assetPath2buildInfo[assetPath] = assetBuildInfo;
                            _object2buildInfo[instanceId]   = assetBuildInfo;
                        }
                    }
                }
            }

            return(assetBuildInfo);
        }
Пример #24
0
 protected bool ValidateRegistration(MethodInfo method, object targetObj, PersistentListenerMode mode, System.Type argumentType)
 {
     if (method == null)
     {
         throw new ArgumentNullException("method", UnityString.Format("Can not register null method on {0} for callback!", targetObj));
     }
     UnityEngine.Object @object = targetObj as UnityEngine.Object;
     if (@object == (UnityEngine.Object)null || @object.GetInstanceID() == 0)
     {
         throw new ArgumentException(UnityString.Format("Could not register callback {0} on {1}. The class {2} does not derive from UnityEngine.Object", (object)method.Name, targetObj, (object)(targetObj != null ? targetObj.GetType().ToString() : "null")));
     }
     if (method.IsStatic)
     {
         throw new ArgumentException(UnityString.Format("Could not register listener {0} on {1} static functions are not supported.", (object)method, (object)this.GetType()));
     }
     if (this.FindMethod(method.Name, targetObj, mode, argumentType) != null)
     {
         return(true);
     }
     Debug.LogWarning((object)UnityString.Format("Could not register listener {0}.{1} on {2} the method could not be found.", targetObj, (object)method, (object)this.GetType()));
     return(false);
 }
Пример #25
0
        private void AddToUsedResources(UnityEngine.Object obj, int resId, float recycleTime)
        {
            int objId = obj.GetInstanceID();

            if (!m_UsedResources.Contains(objId))
            {
                UsedResourceInfo info = ObjectCache.Instance.Get <UsedResourceInfo>();
                info.m_ObjId       = objId;
                info.m_Object      = obj;
                info.m_ResId       = resId;
                info.m_RecycleTime = recycleTime;
                if (m_UseResourcesCount.ContainsKey(obj.name))
                {
                    m_UseResourcesCount[obj.name]++;
                }
                else
                {
                    m_UseResourcesCount.Add(obj.name, 1);
                }
                m_UsedResources.AddLast(objId, info);
            }
        }
Пример #26
0
        /// <summary>
        /// 登録
        /// </summary>
        public static void Register(Object obj)
        {
            var id    = obj.GetInstanceID();
            var type  = obj.GetType();
            var count = 0;

            foreach (var method in type.GetMethods(Flags).Where(m => m.GetCustomAttributes <DebugMethodAttribute>().Any()))
            {
                foreach (var attr in method.GetCustomAttributes <DebugMethodAttribute>())
                {
                    count++;
                    AddDic(attr.Path, new DebugMethodInfo(id, type, attr, method));
                }
            }

            foreach (var field in type.GetFields(Flags).Where(m => m.GetCustomAttributes <DebugFieldAttribute>().Any()))
            {
                foreach (var attr in field.GetCustomAttributes <DebugFieldAttribute>())
                {
                    count++;
                    AddDic(attr.Path, new DebugFieldInfo(id, type, attr, field));
                }
            }

            foreach (var property in type.GetProperties(Flags).Where(m => m.GetCustomAttributes <DebugPropertyAttribute>().Any()))
            {
                foreach (var attr in property.GetCustomAttributes <DebugPropertyAttribute>())
                {
                    count++;
                    AddDic(attr.Path, new DebugPropertyInfo(id, type, attr, property));
                }
            }

            if (count > 0)
            {
                _registerObjects.Add(obj);
            }
        }
Пример #27
0
        internal bool RecycleObject(UnityEngine.Object obj)
        {
            bool ret = false;

            if (null != obj)
            {
                int objId = obj.GetInstanceID();
                if (m_UsedResources.Contains(objId))
                {
                    UsedResourceInfo resInfo = m_UsedResources[objId];
                    if (null != resInfo)
                    {
                        FinalizeObject(resInfo.m_Object);
                        RemoveFromUsedResources(objId);
                        AddToUnusedResources(resInfo.m_ResId, obj);
                        resInfo.Recycle();
                        ObjectCache.Instance.Push <UsedResourceInfo>(resInfo);
                        ret = true;
                    }
                }
            }
            return(ret);
        }
Пример #28
0
        private int GetIdInternal(Object target)
        {
            if (target == null)
            {
                return(0);
            }

            BiDictionary <int, Object> ids;

            Scene scene;
            var   go = target.GameObject();

            if (go != null)
            {
                scene = go.scene;
                if (!scene.IsValid())
                {
                    scene = default(Scene);
                }
            }
            else
            {
                scene = default(Scene);
            }

            if (!instanceIdsByScene.TryGetValue(scene, out ids))
            {
                ids = new BiDictionary <int, Object>();
            }

            int id = target.GetInstanceID();

            ids[id] = target;

            return(id);
        }
Пример #29
0
        internal static bool CheckForKeyWords(string searchString, SearchFilter filter, int quote1, int quote2)
        {
            bool parsed = false;

            // Support: 't:type' syntax (e.g 't:Texture2D' will show Texture2D objects)
            int index = searchString.IndexOf("t:");

            if (index == 0)
            {
                string        type = searchString.Substring(index + 2);
                List <string> tmp  = new List <string>(filter.classNames);
                tmp.Add(type);
                filter.classNames = tmp.ToArray();
                parsed            = true;
            }

            // Support: 'l:assetlabel' syntax (e.g 'l:architecture' will show assets with AssetLabel 'architecture')
            index = searchString.IndexOf("l:");
            if (index == 0)
            {
                string        label = searchString.Substring(index + 2);
                List <string> tmp   = new List <string>(filter.assetLabels);
                tmp.Add(label);
                filter.assetLabels = tmp.ToArray();
                parsed             = true;
            }

            // Support: 'v:versionState' syntax
            index = searchString.IndexOf("v:");
            if (index >= 0)
            {
                string        versionStateString = searchString.Substring(index + 2);
                List <string> tmp = new List <string>(filter.versionControlStates);
                tmp.Add(versionStateString);
                filter.versionControlStates = tmp.ToArray();
                parsed = true;
            }

            // Support: 's:softLockState' syntax
            index = searchString.IndexOf("s:");
            if (index >= 0)
            {
                string        softLockStateString = searchString.Substring(index + 2);
                List <string> tmp = new List <string>(filter.softLockControlStates);
                tmp.Add(softLockStateString);
                filter.softLockControlStates = tmp.ToArray();
                parsed = true;
            }

            // Support: 'a:area' syntax
            index = searchString.IndexOf("a:");
            if (index >= 0)
            {
                string areaString = searchString.Substring(index + 2);
                if (string.Compare(areaString, "all", true) == 0)
                {
                    filter.searchArea = SearchFilter.SearchArea.AllAssets;
                    parsed            = true;
                }
                else if (string.Compare(areaString, "assets", true) == 0)
                {
                    filter.searchArea = SearchFilter.SearchArea.InAssetsOnly;
                    parsed            = true;
                }
                else if (string.Compare(areaString, "packages", true) == 0)
                {
                    filter.searchArea = SearchFilter.SearchArea.InPackagesOnly;
                    parsed            = true;
                }
            }

            // Support: 'b:assetBundleName' syntax (e.g 'b:materialAssetBundle' will show assets within assetBundle 'materialAssetBundle')
            index = searchString.IndexOf("b:");
            if (index == 0)
            {
                string        assetBundleName = searchString.Substring(index + 2);
                List <string> tmp             = new List <string>(filter.assetBundleNames);
                tmp.Add(assetBundleName);
                filter.assetBundleNames = tmp.ToArray();
                parsed = true;
            }

            // Support: 'ref[:id]:path' syntax (e.g 'ref:1234' will show objects that references the object with instanceID 1234)
            index = searchString.IndexOf("ref:");
            if (index == 0)
            {
                int instanceID = 0;

                int firstColon  = index + 3;
                int secondColon = searchString.IndexOf(':', firstColon + 1);
                if (secondColon >= 0)
                {
                    // Instead of resolving a passed-in pathname to an instance-id, use a supplied one.
                    // The pathname is effectively just a UI hint of whose references we're filtering out.
                    string refString = searchString.Substring(firstColon + 1, secondColon - firstColon - 1);
                    int    id;
                    if (System.Int32.TryParse(refString, out id))
                    {
                        instanceID = id;
                    }
                    //else
                    //  Debug.Log ("Not valid refString to case to Integer " + refString); // outcomment for debugging
                }
                else
                {
                    string assetPath;
                    if (quote1 != -1 && quote2 != -1)
                    {
                        int startIndex = quote1 + 1;
                        int count      = quote2 - quote1 - 1;
                        if (count < 0 || quote2 == -1)
                        {
                            count = searchString.Length - startIndex;
                        }

                        // Strip filepath from quotes, don't prefix with Assets/, we need to support Packages/ (https://fogbugz.unity3d.com/f/cases/1161019/)
                        assetPath = searchString.Substring(startIndex, count);
                    }
                    else
                    {
                        // Otherwise use string from colon to end, don't prefix with Assets/, we need to support Packages/ (https://fogbugz.unity3d.com/f/cases/1161019/)
                        assetPath = searchString.Substring(firstColon + 1);
                    }

                    Object obj = AssetDatabase.LoadMainAssetAtPath(assetPath);
                    if (obj == null)
                    {
                        // Backward compatibility, in case Assets/ was strip from path
                        obj = AssetDatabase.LoadMainAssetAtPath("Assets/" + assetPath);
                    }

                    if (obj != null)
                    {
                        instanceID = obj.GetInstanceID();
                    }
                    //else
                    //  Debug.Log ("Not valid assetPath " + assetPath); // outcomment for debugging
                }

                filter.referencingInstanceIDs = new[] { instanceID };
                parsed = true;
            }

            // Support: 'glob:path' syntax (e.g 'glob:Assets/**/*.{png|PNG}' will show objects in any subfolder with name ending by .png or .PNG)
            index = searchString.IndexOf("glob:");
            if (index == 0)
            {
                string globValue = searchString.Substring(5);
                if (quote1 != -1 && quote2 != -1)
                {
                    int startIndex = quote1 + 1;
                    int count      = quote2 - quote1 - 1;
                    if (count < 0 || quote2 == -1)
                    {
                        count = searchString.Length - startIndex;
                    }
                    globValue = searchString.Substring(startIndex, count);
                }
                var globs = new List <string>(filter.globs);
                globs.Add(globValue);
                filter.globs = globs.ToArray();
                parsed       = true;
            }

            return(parsed);
        }
Пример #30
0
 private static bool InstanceIDEquals(UnityEngine.Object o1, UnityEngine.Object o2)
 {
     return(o1.GetInstanceID() == o2.GetInstanceID());
 }