Beispiel #1
0
        public static void CreateAsset(ActionId id)
        {
            var endName = EndNameEditAction.CreateInstance <ActionAssetEndNameEditAction>();

            endName.id = id;
            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, endName, $"{AssetDatabase.GetAssetPath(Selection.activeObject)}/ActionAsset", ActionAssetEditor.AssetIcon, null);
        }
        public static void CreatDefaultTweenUGUIViewScripts()
        {
            EndNameEditAction action = ScriptableObject.CreateInstance <CreateViewScripts>();
            Texture2D         icon   = EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D;

            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, action, "NewTweenView", icon, nameof(TweenUGUIView));
        }
        public bool BeginNewAssetCreation(int instanceID, EndNameEditAction newAssetEndAction, string filePath, Texture2D icon, string newAssetResourceFile)
        {
            string text;

            if (!filePath.StartsWith("assets/", StringComparison.CurrentCultureIgnoreCase))
            {
                text = AssetDatabase.GetUniquePathNameAtSelectedPath(filePath);
            }
            else
            {
                text = AssetDatabase.GenerateUniqueAssetPath(filePath);
            }
            if (!CreateAssetUtility.IsPathDataValid(text))
            {
                Debug.LogErrorFormat("Invalid generated unique path '{0}' (input path '{1}')", new object[]
                {
                    text,
                    filePath
                });
                this.Clear();
                return(false);
            }
            this.m_InstanceID      = instanceID;
            this.m_Path            = text;
            this.m_Icon            = icon;
            this.m_EndAction       = newAssetEndAction;
            this.m_ResourceFile    = newAssetResourceFile;
            Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID);
            return(true);
        }
        public static void StartNameEditingIfProjectWindowExists(int instanceID, EndNameEditAction endAction, string pathName, Texture2D icon, string resourceFile, bool selectAssetBeingCreated)
        {
            // instanceID 0 is used for assets that haven't been imported, which can conflict with
            // asset under creations, which might also use instanceID 0. To avoid this conflict the instanceID
            // is changed if 0.
            if (instanceID == 0)
            {
                instanceID = ProjectBrowser.kAssetCreationInstanceID_ForNonExistingAssets;
            }

            ProjectBrowser pb = GetProjectBrowserIfExists();

            if (pb)
            {
                pb.Focus();
                pb.BeginPreimportedNameEditing(instanceID, endAction, pathName, icon, resourceFile, selectAssetBeingCreated);
                pb.Repaint();
            }
            else
            {
                if (!pathName.StartsWith("assets/", StringComparison.CurrentCultureIgnoreCase))
                {
                    pathName = "Assets/" + pathName;
                }
                EndNameEditAction(endAction, instanceID, pathName, resourceFile, true);
                if (selectAssetBeingCreated)
                {
                    Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID);
                }
            }
        }
Beispiel #5
0
        // Selection changes when calling BeginNewAsset if it succeeds
        public bool BeginNewAssetCreation(int instanceID, EndNameEditAction newAssetEndAction, string filePath, Texture2D icon, string newAssetResourceFile)
        {
            //Sanitize input
            string sanitizedFilePath = filePath != null?filePath.ConvertSeparatorsToUnity() : filePath;

            string sanitizedNewAssetResourceFile = newAssetResourceFile != null?newAssetResourceFile.ConvertSeparatorsToUnity() : newAssetResourceFile;

            string uniquePath;

            if (!sanitizedFilePath.StartsWith("assets/", System.StringComparison.CurrentCultureIgnoreCase))
            {
                uniquePath = AssetDatabase.GetUniquePathNameAtSelectedPath(sanitizedFilePath);
            }
            else
            {
                uniquePath = AssetDatabase.GenerateUniqueAssetPath(sanitizedFilePath);
            }

            if (!IsPathDataValid(uniquePath))
            {
                Debug.LogErrorFormat("Invalid generated unique path '{0}' (input path '{1}')", uniquePath, sanitizedFilePath);
                Clear();
                return(false);
            }

            m_InstanceID   = instanceID;
            m_Path         = uniquePath;
            m_Icon         = icon;
            m_EndAction    = newAssetEndAction;
            m_ResourceFile = sanitizedNewAssetResourceFile;

            // Change selection to none or instanceID
            Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID);
            return(true);
        }
 public void Clear()
 {
     this.m_EndAction    = null;
     this.m_InstanceID   = 0;
     this.m_Path         = "";
     this.m_Icon         = null;
     this.m_ResourceFile = "";
 }
 public void Clear()
 {
     this.m_EndAction    = (EndNameEditAction)null;
     this.m_InstanceID   = 0;
     this.m_Path         = string.Empty;
     this.m_Icon         = (Texture2D)null;
     this.m_ResourceFile = string.Empty;
 }
 public void Clear()
 {
     this.m_EndAction    = null;
     this.m_InstanceID   = 0;
     this.m_Path         = string.Empty;
     this.m_Icon         = null;
     this.m_ResourceFile = string.Empty;
 }
 internal static void EndNameEditAction(EndNameEditAction action, int instanceId, string pathName, string resourceFile)
 {
     pathName = AssetDatabase.GenerateUniqueAssetPath(pathName);
     if (action != null)
     {
         action.Action(instanceId, pathName, resourceFile);
         action.CleanUp();
     }
 }
 internal static void EndNameEditAction(EndNameEditAction action, int instanceId, string pathName, string resourceFile)
 {
     pathName = AssetDatabase.GenerateUniqueAssetPath(pathName);
     if (!((UnityEngine.Object)action != (UnityEngine.Object)null))
     {
         return;
     }
     action.Action(instanceId, pathName, resourceFile);
     action.CleanUp();
 }
Beispiel #11
0
 public virtual void BeginCreateNewAsset(int instanceID, EndNameEditAction endAction, string pathName, Texture2D icon, string resourceFile)
 {
     this.ClearRenameAndNewNodeState();
     this.GetCreateAssetUtility().BeginNewAssetCreation(instanceID, endAction, pathName, icon, resourceFile);
     this.SyncFakeItem();
     if (!base.GetRenameOverlay().BeginRename(this.GetCreateAssetUtility().originalName, instanceID, 0f))
     {
         Debug.LogError("Rename not started (when creating new asset)");
     }
 }
        public void EndNewAssetCreation(string name)
        {
            string            pathName  = this.folder + "/" + name + this.extension;
            EndNameEditAction endAction = this.m_EndAction;
            int    instanceID           = this.m_InstanceID;
            string resourceFile         = this.m_ResourceFile;

            this.Clear();
            ProjectWindowUtil.EndNameEditAction(endAction, instanceID, pathName, resourceFile);
        }
 public virtual void BeginCreateNewAsset(int instanceID, EndNameEditAction endAction, string pathName, Texture2D icon, string resourceFile)
 {
     ClearRenameAndNewItemState();
     //if (!this.GetCreateAssetUtility().BeginNewAssetCreation(instanceID, endAction, pathName, icon, resourceFile))
     //    return;
     SyncFakeItem();
     // if (this.GetRenameOverlay().BeginRename(this.GetCreateAssetUtility().originalName, instanceID, 0.0f))
     //return;
     Debug.LogError((object)"Rename not started (when creating new asset)");
 }
Beispiel #14
0
        public static void CreatNewLua()
        {
            int instanceId = 0;
            EndNameEditAction endNameEditAction = ScriptableObject.CreateInstance <CreateLuaAsset> ();
            string            pathName          = Path.Combine(GetSelectedPathOrFallback(), "NewLuaScript.lua");
            Texture2D         texture2D         = null;
//			Texture2D texture2D = AssetDatabase.LoadAssetAtPath("Assets/CreateLuaScripts/Editor/luaicon.png", typeof(Texture2D)) as Texture2D;
            string resourceFile = "Assets/CreateLuaScripts/Editor/TemplateLua.lua";

            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(instanceId, endNameEditAction, pathName, texture2D, resourceFile);
        }
Beispiel #15
0
        // The asset is created here
        public void EndNewAssetCreation(string name)
        {
            string            path      = folder + "/" + name + extension;
            EndNameEditAction endAction = m_EndAction;
            int    instanceID           = m_InstanceID;
            string resourceFile         = m_ResourceFile;

            Clear(); // Ensure clear if anything goes bad in EndNameEditAction and gui is exited.

            ProjectWindowUtil.EndNameEditAction(endAction, instanceID, path, resourceFile);
        }
Beispiel #16
0
        // Not part of interface because it is very specific to creating assets
        virtual public void BeginCreateNewAsset(int instanceID, EndNameEditAction endAction, string pathName, Texture2D icon, string resourceFile)
        {
            ClearRenameAndNewItemState();

            if (GetCreateAssetUtility().BeginNewAssetCreation(instanceID, endAction, pathName, icon, resourceFile))
            {
                SyncFakeItem();

                // Start nameing the asset
                bool renameStarted = GetRenameOverlay().BeginRename(GetCreateAssetUtility().originalName, instanceID, 0f);
                if (!renameStarted)
                {
                    Debug.LogError("Rename not started (when creating new asset)");
                }
            }
        }
        // The asset is created here
        public void EndNewAssetCreation(string name)
        {
            string path = folder + "/" + name;

            if ((!String.IsNullOrEmpty(extension)) && (!path.EndsWith(extension, System.StringComparison.OrdinalIgnoreCase)))
            {
                path = path + extension;
            }
            EndNameEditAction endAction = m_EndAction;
            int    instanceID           = m_InstanceID;
            string resourceFile         = m_ResourceFile;

            Clear(); // Ensure clear if anything goes bad in EndNameEditAction and gui is exited.

            ProjectWindowUtil.EndNameEditAction(endAction, instanceID, path, resourceFile, true);
        }
Beispiel #18
0
 public void BeginNewAssetCreation(int instanceID, EndNameEditAction newAssetEndAction, string pathName, Texture2D icon, string newAssetResourceFile)
 {
     if (!pathName.StartsWith("assets/", StringComparison.CurrentCultureIgnoreCase))
     {
         pathName = AssetDatabase.GetUniquePathNameAtSelectedPath(pathName);
     }
     else
     {
         pathName = AssetDatabase.GenerateUniqueAssetPath(pathName);
     }
     this.m_InstanceID      = instanceID;
     this.m_Path            = pathName;
     this.m_Icon            = icon;
     this.m_EndAction       = newAssetEndAction;
     this.m_ResourceFile    = newAssetResourceFile;
     Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID);
 }
        public static void StartNameEditingIfProjectWindowExists(int instanceID, EndNameEditAction endAction, string pathName, Texture2D icon, string resourceFile)
        {
            ProjectBrowser projectBrowserIfExists = ProjectWindowUtil.GetProjectBrowserIfExists();

            if (projectBrowserIfExists)
            {
                projectBrowserIfExists.Focus();
                projectBrowserIfExists.BeginPreimportedNameEditing(instanceID, endAction, pathName, icon, resourceFile);
                projectBrowserIfExists.Repaint();
            }
            else
            {
                if (!pathName.StartsWith("assets/", StringComparison.CurrentCultureIgnoreCase))
                {
                    pathName = "Assets/" + pathName;
                }
                ProjectWindowUtil.EndNameEditAction(endAction, instanceID, pathName, resourceFile);
                Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID);
            }
        }
 public static void StartNameEditingIfProjectWindowExists(int instanceID, EndNameEditAction endAction, string pathName, Texture2D icon, string resourceFile)
 {
     StartNameEditingIfProjectWindowExists(instanceID, endAction, pathName, icon, resourceFile, true);
 }