Custom editor plugin

Hi!
I’ve been trying to create a plugin for Cocos Creator. I’ve got some basic stuff running from package-examples on git and I can modify currently open scene accessing the root node with cc.director.getScene(). However I can’t figure out how to script my plugin to do stuff I usually do manually in editor.

  • How do I save changes made to scene?
  • How do I create new assets - save node as prefab and import external files?
  • Most important - how do I access existing assets? I can fiddle with fsPath, url and uuid of an asset converting it one to another with Editor.assetdb but how do I get an actual, let’s say, cc.SpriteFrame object so I can set it as a spriteFrame property for a newly created cc.Sprite component?

Thanks!

3 Likes

I’ve found some docs for an older version containing Editor.assetdb API so I now can import external files as assets :slight_smile:
But it turns out I can’t access cc instance of running scene the same way I did it from developer tools. So I have a new question - how can I access currently open in editor scene (and Cocos runtime in general) from inside the package’s main.js script?

I want to know also. Cocos creator features looks 90% like Unity’s one and it would be cool if I can extends the editor using Editor Script as Unity does !

Hi, everybody :slight_smile:

I’ve come to a point where I have raise the question of creating custom plugins again. I have several scripts (like exporting data from .psd files) that I use extensively, launching them from webkit console built in Creator Editor (upper menu -> Developer -> Developer Tools). It works for me, but I need to share this tool with other people on my team, but console usage is too ugly. So I want to wrap this functionality into a plug-in.

I’ve ran through some old Fireball documentation and came up with a following info:
There are to separate javascript proccesses runing in an editor instance:

  1. Editor proccess - editor panels, asset db and core editor logic live here. Plug-in code runs here.
  2. Render proccess - cc module instance with current open scene lives here. Webkit console attaches to this proccess, and my tools are run in this proccess (because they use cc module to edit open scene)

Now, I have a plug-in that pops up a fancy window with drag-and-drop selections for input external files and pretty checkbox parameters. It all runs in editor proccess.
I have a script that performs some work on some input files. That script must be run in render proccess, because it edits open scene.

How can I run my script in render proccess, but to invoke it from plug-in code that runs in editor proccess?

1 Like

Ok, I’ve finally figured it out and it was really stupid >_<
Your plug-in window needs to be docked into main editor window, then you can access currently open scene through cc.director.getScene() and edit it

1 Like

I’m sorry to respond to an old post, but this is the closest information I have found to what I am searching for.

What I want to do is make editor extensions / plugins with visualization in the game scene editor window. For example, I am using path navigation for enemies. I would like to have lines in the scene editor visualizing the paths. Optimally, I would even like to have handles to edit the path visually, rather than change numbers in the properties panel.

Is this possible?

Thanks for any help.

Hi, there is no plug-in API documentation that I know of, so it would be pretty difficult as for now :frowning:
As a suggestion, I thnik you can achieve something like that with executeInEditMode scripts. Creator has a (undocumented?) feature:

cc.Class({
    extends: cc.Component,
	editor : CC_EDITOR && {
		executeInEditMode : true
	},

these components will have their life-cycle callbacks called in editor. So with some elaborate use of CC_EDITOR flag, you can create a component, that will add empty nodes visualizing path points or whatever you need to move around. Then add event listeners “position-changed” to these nodes, so path data will get updated when you move them

1 Like

Thank you. That is what I’m doing now. Finally figured it out after a few hours of deconstructing source code. On the plus side, I now know a lot about how the editor and engine work!