static ScriptableObject ReplaceSO(ScriptableObject item) { if (!item) { return(null); } if (refDict.ContainsValue(item)) { Debug.LogWarning("The object '" + item.name + ", " + item.GetInstanceID() + "' is already replaced."); return(item); } ScriptableObject clonedObj; if (refDict.TryGetValue(item.GetInstanceID(), out clonedObj)) { //Debug.Log ("Replaced: " + item.name + ", " + item.GetInstanceID () + " to " + clonedObj.GetInstanceID ()); return(clonedObj); } else if (CloneAndAddToList(item)) { Debug.LogWarning("The object '" + item.name + ", " + item.GetInstanceID() + "' was not cloned. Returning a properly cloned object and added the object to list."); item = ReplaceSO(item); ReplaceRefs(item); return(item); } else { throw new UnityException(); } }
static bool CloneAndAddToList(ScriptableObject item) { if (refDict.ContainsKey(item.GetInstanceID())) { return(false); } refDict.Add(item.GetInstanceID(), Clone(item)); return(true); }
public static void DisposeRuntimePanel(ScriptableObject ownerObject) { Panel panel; if (UIElementsUtility.TryGetPanel(ownerObject.GetInstanceID(), out panel)) { panel.Dispose(); RemoveCachedPanelInternal(ownerObject.GetInstanceID()); } }
internal static Panel FindOrCreateEditorPanel(ScriptableObject ownerObject) { Panel panel; if (!s_UIElementsCache.TryGetValue(ownerObject.GetInstanceID(), out panel)) { panel = Panel.CreateEditorPanel(ownerObject); RegisterCachedPanel(ownerObject.GetInstanceID(), panel); } else { Debug.Assert(ContextType.Editor == panel.contextType, "Panel is not an editor panel."); } return panel; }
internal static Panel FindOrCreatePanel(ScriptableObject ownerObject, ContextType contextType, IDataWatchService dataWatch = null) { Panel panel; if (!UIElementsUtility.s_UIElementsCache.TryGetValue(ownerObject.GetInstanceID(), out panel)) { panel = new Panel(ownerObject, contextType, dataWatch, UIElementsUtility.eventDispatcher); UIElementsUtility.s_UIElementsCache.Add(ownerObject.GetInstanceID(), panel); } else { Debug.Assert(contextType == panel.contextType, "Context type mismatch"); } return(panel); }
internal static Panel FindOrCreatePanel(ScriptableObject ownerObject, ContextType contextType) { Panel panel; if (!s_UIElementsCache.TryGetValue(ownerObject.GetInstanceID(), out panel)) { panel = new Panel(ownerObject, contextType); RegisterCachedPanel(ownerObject.GetInstanceID(), panel); } else { Debug.Assert(contextType == panel.contextType, "Context type mismatch"); } return(panel); }
static void CreateCache() { Debug.Log("One-time construction of the Ferr component cache, this may take a little while on large projects!"); for (int i = 0; i < trackTypes.Count; i++) { List <object> coms = GetPrefabsOfTypeSlow(trackTypes[i]); for (int t = 0; t < coms.Count; t++) { if (coms[t] is ScriptableObject) { ScriptableObject so = coms[i] as ScriptableObject; AddComponent(trackTypes[i], AssetDatabase.GetAssetPath(so.GetInstanceID()), so); } else { Component com = coms[t] as Component; if (com != null) { AddComponent(trackTypes[i], AssetDatabase.GetAssetPath(com.gameObject.GetInstanceID()), com.gameObject); } } } } SaveCache(); Debug.Log("Ferr component cache construction completed!"); }
/// <summary> /// <para>Crear ScriptableObject.</para> /// </summary> private void Crear() // Crear ScriptableObject { ScriptableObject asset = ScriptableObject.CreateInstance(tipos[scriptSeleccionado]); ProjectWindowUtil.StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), ScriptableObject.CreateInstance <EndNameEdit>(), string.Format("{0}.asset", nombres[scriptSeleccionado]), AssetPreview.GetMiniThumbnail(asset), null); Close(); }
private static void EditName(ScriptableObject asset, string name) { ProjectWindowUtil.StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), ScriptableObject.CreateInstance <EndNameEdit>(), string.Format("{0}.asset", name), AssetPreview.GetMiniThumbnail(asset), null); }
public AssetInfo(ScriptableObject asset) { var assetPath = AssetDatabase.GetAssetPath(asset); path = Path.GetDirectoryName(assetPath); path = (path.Length > AssetsPath.Length) ? path.Substring(AssetsPath.Length) : string.Empty; name = Path.GetFileNameWithoutExtension(assetPath); instanceID = asset.GetInstanceID(); }
public static IPanel FindOrCreateRuntimePanel(ScriptableObject ownerObject) { Panel panel; if (!UIElementsUtility.TryGetPanel(ownerObject.GetInstanceID(), out panel)) { panel = new RuntimePanel(ownerObject, s_RuntimeDispatcher) { IMGUIEventInterests = new EventInterests { wantsMouseMove = true, wantsMouseEnterLeaveWindow = true } }; RegisterCachedPanelInternal(ownerObject.GetInstanceID(), panel); } else { Debug.Assert(ContextType.Player == panel.contextType, "Panel is not a runtime panel."); } return panel; }
/// <summary> /// Deletes the .asset file for a scriptable object that is passed in /// </summary> /// <param name="objectToDelete">The scriptableobject to delete</param> public static void DeleteScriptableObject(ScriptableObject objectToDelete) { string assetPath = AssetDatabase.GetAssetPath(objectToDelete.GetInstanceID()); if (!string.IsNullOrEmpty(assetPath)) { AssetDatabase.DeleteAsset(assetPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
public static void CreateScriptableOfType(Type type, string name) { ScriptableObject asset = ScriptableObject.CreateInstance(type); ProjectWindowUtil.StartNameEditingIfProjectWindowExists( asset.GetInstanceID(), ScriptableObject.CreateInstance <EndNameEdit>(), string.Format("{0}.asset", name), AssetPreview.GetMiniThumbnail(asset), null); }
public static BaseRuntimePanel FindOrCreateRuntimePanel(ScriptableObject ownerObject, CreateRuntimePanelDelegate createDelegate) { if (UIElementsUtility.TryGetPanel(ownerObject.GetInstanceID(), out Panel cachedPanel)) { if (cachedPanel is BaseRuntimePanel runtimePanel) { return(runtimePanel); } RemoveCachedPanelInternal(ownerObject.GetInstanceID()); // Maybe throw exception instead? } var panel = createDelegate(ownerObject); panel.IMGUIEventInterests = new EventInterests { wantsMouseMove = true, wantsMouseEnterLeaveWindow = true }; RegisterCachedPanelInternal(ownerObject.GetInstanceID(), panel); onCreatePanel?.Invoke(panel); return(panel); }
public static Panel FindOrCreate(ScriptableObject ownerObject) { var id = ownerObject.GetInstanceID(); Panel panel; if (UIElementsUtility.TryGetPanel(id, out panel)) { return(panel); } panel = new EditorPanel(ownerObject); UIElementsUtility.RegisterCachedPanel(id, panel); return(panel); }
public static string RenameAsset(ScriptableObject asset, string newName) { string assetPath = AssetDatabase.GetAssetPath(asset.GetInstanceID()); string output = AssetDatabase.RenameAsset(assetPath, newName); if (output.Length > 0) { return(output); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(""); }
/// <summary> /// Creates a new content element and releases any existing element /// </summary> /// <param name="rType"></param> /// <returns></returns> public virtual ScriptableObject CreateContent(Type rType) { // Remove the asset that represents the node if (_Content != null) { DestroyContent(); } // Create a new instance of the content if (rType != null) { // If we're dealing with a scriptable object, store it if (com.ootii.Helpers.ReflectionHelper.IsAssignableFrom(typeof(ScriptableObject), rType)) //if (typeof(ScriptableObject).IsAssignableFrom(rType)) { _Content = ScriptableObject.CreateInstance(rType) as ScriptableObject; if (_Content is NodeContent) { ((NodeContent)_Content).Node = this; } #if UNITY_EDITOR if (_Content != null) { // Add the action as an asset. However, we have to name it this: // http://answers.unity3d.com/questions/1164341/can-a-scriptableobject-contain-a-list-of-scriptabl.html _Content.name = "z " + rType.Name + " " + _Content.GetInstanceID().ToString(); _Content.hideFlags = HideFlags.HideInHierarchy; UnityEditor.AssetDatabase.AddObjectToAsset(_Content, Canvas.RootAsset); UnityEditor.EditorUtility.SetDirty(_Content); UnityEditor.EditorUtility.SetDirty(this); Canvas.SetDirty(); } #endif } // Otherwise, just create the instance else { _Content = Activator.CreateInstance(rType) as ScriptableObject; } } // Return the content return(_Content); }
/// <summary> /// Renames a scriptable object's file name with the provided new one /// </summary> /// <param name="objectToRename">The scriptable object to change</param> /// <param name="fileName">The new file name </param> public static void RenameScriptableObjectFile(ScriptableObject objectToRename, string fileName) { string assetPath = AssetDatabase.GetAssetPath(objectToRename.GetInstanceID()); if (!string.IsNullOrEmpty(assetPath)) { // Check to make sure that a file name was given, if not default it if (string.IsNullOrWhiteSpace(fileName)) { fileName = "UnNamedScriptableObject"; } AssetDatabase.RenameAsset(assetPath, fileName); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
private void I18NStringPass(Type classType, Type type, ScriptableObject obj) { var fields = from field in classType.GetFields() from attr in field.GetAttributes() where attr is I18NStringAttribute select field; fields.ForEach(field => { var path = $"Database[{type.ToString()}]:/InstanceID:{obj.GetInstanceID()}/FieldName:{field.Name}"; var text = field.GetValue(obj) as string; if (I18NStrings.ContainsKey(text ?? throw new InvalidOperationException())) { I18NStrings[text].PathList.Add(path); }
public static string GetName(this ScriptableObject so) { var path = AssetDatabase.GetAssetPath(so.GetInstanceID()); return(Path.GetFileNameWithoutExtension(path)); }
/// <summary> /// Provides the file name without extension for a scriptable object /// </summary> /// <param name="objectToName">The scriptable object that file name is needed</param> /// <returns>A string with the file name and no extension</returns> public static string GetScriptableObjectFileName(ScriptableObject objectToName) { string fullPath = AssetDatabase.GetAssetPath(objectToName.GetInstanceID()); return(Path.GetFileNameWithoutExtension(fullPath)); }
static void OnUpdate() { if (m_currentToolbar == null) { var toolbars = Resources.FindObjectsOfTypeAll(m_toolbarType); m_currentToolbar = toolbars.Length > 0 ? (ScriptableObject)toolbars[0] : null; // UnityEngine.Debug.Log(m_currentToolbar != null); } // If the windows layour reloaded, we need to re create our GUI if (m_currentToolbar != null && parent != null && m_currentToolbar.GetInstanceID() != lastInstanceID) { parent.RemoveFromHierarchy(); parent = null; lastInstanceID = m_currentToolbar.GetInstanceID(); } if (m_currentToolbar != null && parent == null) { // foreach (var item in m_currentToolbar.GetType().GetRuntimeFields()) // UnityEngine.Debug.Log(item.Name + " " + item.FieldType + " " + item.IsPublic); var root = m_currentToolbar.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance); // UnityEngine.Debug.Log(root); if (root != null) { var rawRoot = root.GetValue(m_currentToolbar); // UnityEngine.Debug.Log(rawRoot != null); if (rawRoot != null) { // UnityEngine.Debug.Log("Attaching"); // UnityEngine.Debug.Log(rawRoot.GetType()); var mRoot = rawRoot as VisualElement; // UnityEngine.Debug.Log(mRoot.name); var toolbarZoneLeftAlign = mRoot.Q("ToolbarZoneLeftAlign"); if (parent != null) { parent.RemoveFromHierarchy(); } parent = null; parent = new VisualElement() { style = { flexGrow = 1, flexDirection = FlexDirection.Row, } }; parent.Add(new VisualElement() { style = { flexGrow = 1, } }); OnAttachToToolbar(parent); toolbarZoneLeftAlign.Add(parent); } } } }
private string GetFilePath(ScriptableObject obj) { return(string.Format("{0}/{1}.pso", Application.persistentDataPath, obj.GetInstanceID())); }
// Special method to remove a track that is in a broken state. i.e. the script won't load internal static bool RemoveBrokenTrack(PlayableAsset parent, ScriptableObject track) { var parentTrack = parent as TrackAsset; var parentTimeline = parent as TimelineAsset; if (parentTrack == null && parentTimeline == null) { throw new ArgumentException("parent is not a valid parent type", "parent"); } // this object must be a Unity null, but not actually null; object trackAsObject = track; if (trackAsObject == null || track != null) // yes, this is correct { throw new ArgumentException("track is not in a broken state"); } // this belongs to a parent track if (parentTrack != null) { int index = parentTrack.subTracksObjects.FindIndex(t => t.GetInstanceID() == track.GetInstanceID()); if (index >= 0) { TimelineUndo.PushUndo(parentTrack, "Remove Track"); parentTrack.subTracksObjects.RemoveAt(index); parentTrack.Invalidate(); Undo.DestroyObjectImmediate(track); return(true); } } else if (parentTimeline != null) { int index = parentTimeline.trackObjects.FindIndex(t => t.GetInstanceID() == track.GetInstanceID()); if (index >= 0) { TimelineUndo.PushUndo(parentTimeline, "Remove Track"); parentTimeline.trackObjects.RemoveAt(index); parentTimeline.Invalidate(); Undo.DestroyObjectImmediate(track); return(true); } } return(false); }
public static void AddToPreloadedAssets(this ScriptableObject scriptableObject) { #if UNITY_EDITOR var preloadedAssets = PlayerSettings.GetPreloadedAssets().ToList(); if (preloadedAssets.Any(preloadedAsset => preloadedAsset && preloadedAsset.GetInstanceID() == scriptableObject.GetInstanceID())) { // Already being preloaded return; } preloadedAssets.Add(scriptableObject); PlayerSettings.SetPreloadedAssets(preloadedAssets.ToArray()); #endif }
// +-----------------------------------------------------------------------------------------------------------+ // | EDITOR METHODS: | // +-----------------------------------------------------------------------------------------------------------+ #if UNITY_EDITOR // PUBLIC METHODS: --------------------------------------------------------------------------------------------- public static bool ProjectContains(ScriptableObject instance) { return(!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(instance.GetInstanceID()))); }