Example #1
0
        public static ActiveEditorTracker GetActiveEditorTrackerForSelectedObject()
        {
            var inspectorWindow = GetInspectorWindow();

            if (inspectorWindow == null)
            {
                return(null);
            }
            if (CSReflectionTools.inspectorWindowType == null)
            {
                return(null);
            }

            inspectorWindow.Repaint();

            ActiveEditorTracker result = null;

            var trackerProperty = CSReflectionTools.GetPropertyInfo(CSReflectionTools.inspectorWindowType, "tracker");

            if (trackerProperty != null)
            {
                result = (ActiveEditorTracker)trackerProperty.GetValue(inspectorWindow, null);
            }
            else
            {
                Debug.LogError(Maintainer.ConstructError("Can't get ActiveEditorTracker from the InspectorWindow!"));
            }

            return(result);
        }
Example #2
0
        public static Object GetInSceneRenderSettings()
        {
            var mi = CSReflectionTools.GetGetRenderSettingsMethodInfo();

            if (mi != null)
            {
                return((Object)mi.Invoke(null, null));
            }

            Debug.LogError(Maintainer.ConstructError("Can't retrieve RenderSettings object via reflection!"));
            return(null);
        }
Example #3
0
        public static int GetMainAssetInstanceID(string path)
        {
            var mi = CSReflectionTools.GetGetMainAssetInstanceIDMethodInfo();

            if (mi != null)
            {
                return((int)mi.Invoke(null, new object[] { path }));
            }

            Debug.LogError(Maintainer.ConstructError("Can't retrieve InstanceID From path via reflection!"));
            return(-1);
        }
Example #4
0
        internal static long GetLocalIdentifierInFileForObject(Object unityObject)
        {
            long id = -1;

            if (unityObject == null)
            {
                return(id);
            }

            SerializedObject serializedObject = new SerializedObject(unityObject);

            CSReflectionTools.GetInspectorModePropertyInfo().SetValue(serializedObject, InspectorMode.Debug, null);
            SerializedProperty serializedProperty = serializedObject.FindProperty("m_LocalIdentfierInFile");

#if UNITY_5_PLUS
            id = serializedProperty.longValue;
#else
            id = serializedProperty.intValue;
#endif
            if (id <= 0)
            {
                PrefabType prefabType = PrefabUtility.GetPrefabType(unityObject);
                if (prefabType != PrefabType.None)
                {
                    id = GetLocalIdentifierInFileForObject(PrefabUtility.GetPrefabParent(unityObject));
                }
                else
                {
                    // this will work for the new objects in scene which weren't saved yet
                    id = unityObject.GetInstanceID();
                }
            }

            if (id <= 0)
            {
                GameObject go = unityObject as GameObject;
                if (go != null)
                {
                    id = go.transform.GetSiblingIndex();
                }
            }

            return(id);
        }
Example #5
0
        private static long GetLocalIdentifierInFile(Object unityObject)
        {
            var go = unityObject as GameObject;

            if (go != null)
            {
                unityObject = go;
            }

            var serializedObject = new SerializedObject(unityObject);

            try
            {
                CSReflectionTools.SetInspectorToDebug(serializedObject);
                var serializedProperty = serializedObject.FindProperty("m_LocalIdentfierInFile");
                return(serializedProperty.longValue);
            }
            catch (Exception e)
            {
                Debug.LogWarning(Maintainer.ConstructWarning("Couldn't get data from debug inspector for object " + unityObject.name + " due to this error:\n" + e));
                return(-1);
            }
        }