コード例 #1
0
ファイル: NodeEvent.cs プロジェクト: unity3d-jp/AssetGraph
 public NodeEvent(EventType type, NodeGUI node, Vector2 localMousePos, ConnectionPointData point)
 {
     this.eventType = type;
     this.eventSourceNode = node;
     this.point = point;
     this.globalMousePosition = new Vector2(localMousePos.x + node.GetX(), localMousePos.y + node.GetY());
 }
コード例 #2
0
        private void AddNodeFromGUI(NodeKind kind, float x, float y)
        {
            string nodeName = AssetBundleGraphSettings.DEFAULT_NODE_NAME[kind] + nodes.Where(node => node.Kind == kind).ToList().Count;
            NodeGUI newNode = new NodeGUI(new NodeData(nodeName, kind, x, y));

            Undo.RecordObject(this, "Add " + AssetBundleGraphSettings.DEFAULT_NODE_NAME[kind] + " Node");

            AddNodeGUI(newNode);
        }
コード例 #3
0
        public void OnGUI()
        {
            DrawGUIToolBar();

            using (new EditorGUILayout.HorizontalScope()) {
                DrawGUINodeGraph();
                if(showErrors) {
                    DrawGUINodeErrors();
                }
            }

            /*
                Event Handling:
                - Supporting dragging script into window to create node.
                - Context Menu
                - NodeGUI connection.
                - Command(Delete, Copy, etc...)
            */
            switch (Event.current.type) {
                // detect dragging script then change interface to "(+)" icon.
                case EventType.DragUpdated: {
                    var refs = DragAndDrop.objectReferences;

                    foreach (var refe in refs) {
                        if (refe.GetType() == typeof(UnityEditor.MonoScript)) {
                            Type scriptTypeInfo = ((MonoScript)refe).GetClass();
                            Type inheritedTypeInfo = GetDragAndDropAcceptableScriptType(scriptTypeInfo);

                            if (inheritedTypeInfo != null) {
                                // at least one asset is script. change interface.
                                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                                break;
                            }
                        }
                    }
                    break;
                }

                // script drop on editor.
                case EventType.DragPerform: {
                    var pathAndRefs = new Dictionary<string, object>();
                    for (var i = 0; i < DragAndDrop.paths.Length; i++) {
                        var path = DragAndDrop.paths[i];
                        var refe = DragAndDrop.objectReferences[i];
                        pathAndRefs[path] = refe;
                    }
                    var shouldSave = false;
                    foreach (var item in pathAndRefs) {
                        var refe = (MonoScript)item.Value;
                        if (refe.GetType() == typeof(UnityEditor.MonoScript)) {
                            Type scriptTypeInfo = refe.GetClass();
                            Type inheritedTypeInfo = GetDragAndDropAcceptableScriptType(scriptTypeInfo);

                            if (inheritedTypeInfo != null) {
                                var dropPos = Event.current.mousePosition;
                                var scriptName = refe.name;
                                var scriptClassName = scriptName;
                                AddNodeFromCode(scriptName, scriptClassName, inheritedTypeInfo, dropPos.x, dropPos.y);
                                shouldSave = true;
                            }
                        }
                    }

                    if (shouldSave) {
                        SaveGraphWithReload();
                    }
                    break;
                }

                // show context menu
                case EventType.ContextClick: {
                    var rightClickPos = Event.current.mousePosition;
                    var menu = new GenericMenu();
                    foreach (var menuItemStr in AssetBundleGraphSettings.GUI_Menu_Item_TargetGUINodeDict.Keys) {
                        var kind = AssetBundleGraphSettings.GUI_Menu_Item_TargetGUINodeDict[menuItemStr];
                        menu.AddItem(
                            new GUIContent(menuItemStr),
                            false,
                            () => {
                                AddNodeFromGUI(kind, rightClickPos.x, rightClickPos.y);
                                SaveGraphWithReload();
                                Repaint();
                            }
                        );
                    }
                    menu.ShowAsContext();
                    break;
                }

                /*
                    Handling mouseUp at empty space.
                */
                case EventType.MouseUp: {
                    modifyMode = ModifyMode.NONE;
                    HandleUtility.Repaint();

                    if (activeObject.idPosDict.ReadonlyDict().Any()) {
                        Undo.RecordObject(this, "Unselect");

                        foreach (var activeObjectId in activeObject.idPosDict.ReadonlyDict().Keys) {
                            // unselect all.
                            foreach (var node in nodes) {
                                if (activeObjectId == node.Id) {
                                    node.SetInactive();
                                }
                            }
                            foreach (var connection in connections) {
                                if (activeObjectId == connection.Id) {
                                    connection.SetInactive();
                                }
                            }
                        }

                        activeObject = RenewActiveObject(new List<string>());

                    }

                    // clear inspector
                    if( Selection.activeObject is NodeGUIInspectorHelper || Selection.activeObject is ConnectionGUIInspectorHelper) {
                        Selection.activeObject = null;
                    }

                    break;
                }

                /*
                    scale up or down by command & + or command & -.
                */
                case EventType.KeyDown: {
                    if (Event.current.command) {
                        if (Event.current.shift && Event.current.keyCode == KeyCode.Semicolon) {
                            NodeGUI.scaleFactor = NodeGUI.scaleFactor + 0.1f;
                            if (NodeGUI.scaleFactor < NodeGUI.SCALE_MIN) NodeGUI.scaleFactor = NodeGUI.SCALE_MIN;
                            if (NodeGUI.SCALE_MAX < NodeGUI.scaleFactor) NodeGUI.scaleFactor = NodeGUI.SCALE_MAX;
                            Event.current.Use();
                            break;
                        }

                        if (Event.current.keyCode == KeyCode.Minus) {
                            NodeGUI.scaleFactor = NodeGUI.scaleFactor - 0.1f;
                            if (NodeGUI.scaleFactor < NodeGUI.SCALE_MIN) NodeGUI.scaleFactor = NodeGUI.SCALE_MIN;
                            if (NodeGUI.SCALE_MAX < NodeGUI.scaleFactor) NodeGUI.scaleFactor = NodeGUI.SCALE_MAX;
                            Event.current.Use();
                            break;
                        }
                    }
                    break;
                }

                case EventType.ValidateCommand:
                {
                    switch (Event.current.commandName) {
                    // Delete active node or connection.
                    case "Delete": {
                            if (activeObject.idPosDict.ReadonlyDict().Any()) {
                                Event.current.Use();
                            }
                            break;
                        }

                    case "Copy": {
                            if (activeObject.idPosDict.ReadonlyDict().Any()) {
                                Event.current.Use();
                            }
                            break;
                        }

                    case "Cut": {
                            if (activeObject.idPosDict.ReadonlyDict().Any()) {
                                Event.current.Use();
                            }
                            break;
                        }

                    case "Paste": {
                            if(copyField.datas == null)  {
                                break;
                            }

                            if (copyField.datas.Any()) {
                                Event.current.Use();
                            }
                            break;
                        }

                    case "SelectAll": {
                            Event.current.Use();
                            break;
                        }
                    }
                    break;
                }

                case EventType.ExecuteCommand:
                {
                    switch (Event.current.commandName) {
                        // Delete active node or connection.
                        case "Delete": {

                            if (!activeObject.idPosDict.ReadonlyDict().Any()) break;
                            Undo.RecordObject(this, "Delete Selection");

                            foreach (var targetId in activeObject.idPosDict.ReadonlyDict().Keys) {
                                DeleteNode(targetId);
                                DeleteConnectionById(targetId);
                            }

                            SaveGraphWithReload();

                            activeObject = RenewActiveObject(new List<string>());
                            UpdateActivationOfObjects(activeObject);

                            Event.current.Use();
                            break;
                        }

                        case "Copy": {
                            if (!activeObject.idPosDict.ReadonlyDict().Any()) {
                                break;
                            }

                            Undo.RecordObject(this, "Copy Selection");

                            var targetNodeIds = activeObject.idPosDict.ReadonlyDict().Keys.ToList();
                            var targetNodeJsonRepresentations = JsonRepresentations(targetNodeIds);
                            copyField = new CopyField(targetNodeJsonRepresentations, CopyType.COPYTYPE_COPY);

                            Event.current.Use();
                            break;
                        }

                        case "Cut": {
                            if (!activeObject.idPosDict.ReadonlyDict().Any()) {
                                break;
                            }

                            Undo.RecordObject(this, "Cut Selection");
                            var targetNodeIds = activeObject.idPosDict.ReadonlyDict().Keys.ToList();
                            var targetNodeJsonRepresentations = JsonRepresentations(targetNodeIds);
                            copyField = new CopyField(targetNodeJsonRepresentations, CopyType.COPYTYPE_CUT);

                            foreach (var targetId in activeObject.idPosDict.ReadonlyDict().Keys) {
                                DeleteNode(targetId);
                                DeleteConnectionById(targetId);
                            }

                            SaveGraphWithReload();
                            InitializeGraph();

                            activeObject = RenewActiveObject(new List<string>());
                            UpdateActivationOfObjects(activeObject);

                            Event.current.Use();
                            break;
                        }

                        case "Paste": {

                            if(copyField.datas == null)  {
                                break;
                            }

                            var nodeNames = nodes.Select(node => node.Name).ToList();
                            var duplicatingData = new List<NodeGUI>();

                            if (copyField.datas.Any()) {
                                var pasteType = copyField.type;
                                foreach (var copyFieldData in copyField.datas) {
                                    var nodeJsonDict = AssetBundleGraph.Json.Deserialize(copyFieldData) as Dictionary<string, object>;
                                    var pastingNode = new NodeGUI(new NodeData(nodeJsonDict));
                                    var pastingNodeName = pastingNode.Name;

                                    var nameOverlapping = nodeNames.Where(name => name == pastingNodeName).ToList();

              									switch (pasteType) {
              										case CopyType.COPYTYPE_COPY: {
                                            if (2 <= nameOverlapping.Count) {
                                                continue;
                                            }
              											break;
              										}
              										case CopyType.COPYTYPE_CUT: {
                                            if (1 <= nameOverlapping.Count) {
                                                continue;
                                            }
              											break;
              										}
              									}

              									duplicatingData.Add(pastingNode);
                                }
                            }
                            // consume copyField
                            copyField.datas = null;

                            if (!duplicatingData.Any()) {
                                break;
                            }

                            Undo.RecordObject(this, "Paste");
                            foreach (var newNode in duplicatingData) {
                                DuplicateNode(newNode);
                            }

                            SaveGraphWithReload();
                            InitializeGraph();

                            Event.current.Use();
                            break;
                        }

                        case "SelectAll": {
                            Undo.RecordObject(this, "Select All Objects");

                            var nodeIds = nodes.Select(node => node.Id).ToList();
                            activeObject = RenewActiveObject(nodeIds);

                            // select all.
                            foreach (var node in nodes) {
                                node.SetActive();
                            }
                            foreach (var connection in connections) {
                                connection.SetActive();
                            }

                            Event.current.Use();
                            break;
                        }

                        default: {
                            break;
                        }
                    }
                    break;
                }
            }
        }
コード例 #4
0
        /**
            create new connection if same relationship is not exist yet.
        */
        private void AddConnection(string label, NodeGUI startNode, ConnectionPointData startPoint, NodeGUI endNode, ConnectionPointData endPoint)
        {
            Undo.RecordObject(this, "Add Connection");

            var connectionsFromThisNode = connections
                .Where(con => con.OutputNodeId == startNode.Id)
                .Where(con => con.OutputPoint == startPoint)
                .ToList();
            if (connectionsFromThisNode.Any()) {
                var alreadyExistConnection = connectionsFromThisNode[0];
                DeleteConnectionById(alreadyExistConnection.Id);
            }

            if (!connections.ContainsConnection(startPoint, endPoint)) {
                connections.Add(ConnectionGUI.CreateConnection(label, startPoint, endPoint));
            }
        }
コード例 #5
0
        private void UpdateNodeName(NodeGUI node)
        {
            var newName = EditorGUILayout.TextField("Node Name", node.Name);

            if( NodeGUIUtility.allNodeNames != null ) {
                var overlapping = NodeGUIUtility.allNodeNames.GroupBy(x => x)
                    .Where(group => group.Count() > 1)
                    .Select(group => group.Key);
                if (overlapping.Any() && overlapping.Contains(newName)) {
                    EditorGUILayout.HelpBox("This node name already exist. Please put other name:" + newName, MessageType.Error);
                    AssetBundleGraphEditorWindow.AddNodeException(new NodeException("Node name " + newName + " already exist.", node.Id ));
                }
            }

            if (newName != node.Name) {
                using(new RecordUndoScope("Change Node Name", node, true)){
                    node.Name = newName;
                }
            }
        }
コード例 #6
0
ファイル: SaveScope.cs プロジェクト: unity3d-jp/AssetGraph
 public SaveScope(NodeGUI node)
 {
     this.node = node;
 }
コード例 #7
0
        public void UpdateRegion(NodeGUI node, int index, int max)
        {
            var parentRegion = node.Region;
            if(IsInput){

                var initialY = (AssetBundleGraphGUISettings.NODE_BASE_HEIGHT - AssetBundleGraphGUISettings.INPUT_POINT_HEIGHT) / 2f;
                var marginY  = initialY + AssetBundleGraphGUISettings.FILTER_OUTPUT_SPAN * (index);

                buttonRect = new Rect(
                    0,
                    marginY,
                    AssetBundleGraphGUISettings.INPUT_POINT_WIDTH,
                    AssetBundleGraphGUISettings.INPUT_POINT_HEIGHT);
            } else {

                var initialY = (AssetBundleGraphGUISettings.NODE_BASE_HEIGHT - AssetBundleGraphGUISettings.OUTPUT_POINT_HEIGHT) / 2f;
                var marginY  = initialY + AssetBundleGraphGUISettings.FILTER_OUTPUT_SPAN * (index);

                buttonRect = new Rect(
                    parentRegion.width - AssetBundleGraphGUISettings.OUTPUT_POINT_WIDTH + 1f,
                    marginY,
                    AssetBundleGraphGUISettings.OUTPUT_POINT_WIDTH,
                    AssetBundleGraphGUISettings.OUTPUT_POINT_HEIGHT);
            }
        }
コード例 #8
0
        private EditorGUI.DisabledScope DrawOverrideTargetToggle(NodeGUI node, bool status, Action<bool> onStatusChange)
        {
            if( currentEditingGroup == BuildTargetUtility.DefaultTarget ) {
                return new EditorGUI.DisabledScope(false);
            }

            bool newStatus = GUILayout.Toggle(status,
                "Override for " + NodeGUIUtility.GetPlatformButtonFor(currentEditingGroup).ui.tooltip);

            if(newStatus != status && onStatusChange != null) {
                onStatusChange(newStatus);
            }
            return new EditorGUI.DisabledScope(!newStatus);
        }
コード例 #9
0
        public Vector2 GetGlobalPosition(NodeGUI node)
        {
            var x = 0f;
            var y = 0f;

            var baseRect = node.Region;

            if (IsInput) {
                x = baseRect.x;
                y = baseRect.y + buttonRect.y + (buttonRect.height / 2f) - 1f;
            }

            if (IsOutput) {
                x = baseRect.x + baseRect.width;
                y = baseRect.y + buttonRect.y + (buttonRect.height / 2f) - 1f;
            }

            return new Vector2(x, y);
        }
コード例 #10
0
 //        public int OrderPriority {
 //            get {
 //                return orderPriority;
 //            }
 //        }
 //        public bool ShowLabel {
 //            get {
 //                return showLabel;
 //            }
 //        }
 // returns rect for outside marker
 public Rect GetGlobalRegion(NodeGUI node)
 {
     var baseRect = node.Region;
     return new Rect(
         baseRect.x + buttonRect.x,
         baseRect.y + buttonRect.y,
         buttonRect.width,
         buttonRect.height
     );
 }
コード例 #11
0
 // returns rect for connection dot
 public Rect GetGlobalPointRegion(NodeGUI node)
 {
     if(IsInput) {
         return GetInputPointRect(node);
     } else {
         return GetOutputPointRect(node);
     }
 }
コード例 #12
0
 public RecordUndoScope(string message, NodeGUI node, bool saveOnScopeEnd)
 {
     this.node = node;
     this.saveOnScopeEnd = saveOnScopeEnd;
     NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_RECORDUNDO, message));
 }
コード例 #13
0
 public RecordUndoScope(string message, NodeGUI node)
 {
     this.node = node;
     NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_RECORDUNDO, message));
 }
コード例 #14
0
        private void DoInspectorModifierGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("Modifier: Modify asset settings.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {

                Type incomingType = FindIncomingAssetType(node.Data.InputPoints[0]);

                if(incomingType == null) {
                    // if there is no asset input to determine incomingType,
                    // retrieve from assigned Modifier.
                    incomingType = ModifierUtility.GetModifierTargetType(node.Data.ScriptClassName);

                    if(incomingType == null) {
                        EditorGUILayout.HelpBox("Modifier needs a single type of incoming assets.", MessageType.Info);
                        return;
                    }
                }

                var map = ModifierUtility.GetAttributeClassNameMap(incomingType);
                if(map.Count > 0) {
                    using(new GUILayout.HorizontalScope()) {
                        GUILayout.Label("Modifier");
                        var guiName = ModifierUtility.GetModifierGUIName(node.Data.ScriptClassName);
                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f))) {
                            var builders = map.Keys.ToList();

                            if(builders.Count > 0) {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                    {
                                        using(new RecordUndoScope("Change Modifier class", node, true)) {
                                            m_modifier = ModifierUtility.CreateModifier(selectedGUIName, incomingType);
                                            if(m_modifier != null) {
                                                node.Data.ScriptClassName = ModifierUtility.GUINameToClassName(selectedGUIName, incomingType);
                                                node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                            }
                                        }
                                    }
                                );
                            }
                        }
                    }

                } else {
                    string[] menuNames = AssetBundleGraphSettings.GUI_TEXT_MENU_GENERATE_MODIFIER.Split('/');
                    EditorGUILayout.HelpBox(
                        string.Format(
                            "No CustomModifier found for {3} type. \n" +
                            "You need to create at least one Modifier script to select script for Modifier. " +
                            "To start, select {0}>{1}>{2} menu and create a new script.",
                            menuNames[1],menuNames[2], menuNames[3], incomingType.FullName
                        ), MessageType.Info);
                }

                GUILayout.Space(10f);

                if(DrawPlatformSelector(node)) {
                    // if platform tab is changed, renew modifierModifierInstance for that tab.
                    m_modifier = null;
                }
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = DrawOverrideTargetToggle(node, node.Data.InstanceData.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                        if(enabled) {
                            node.Data.InstanceData[currentEditingGroup] = node.Data.InstanceData.DefaultValue;
                        } else {
                            node.Data.InstanceData.Remove(currentEditingGroup);
                        }
                        m_modifier = null;
                    });

                    using (disabledScope) {
                        //reload modifierModifier instance from saved modifierModifier data.
                        if (m_modifier == null) {
                            m_modifier = ModifierUtility.CreateModifier(node.Data, currentEditingGroup);
                            if(m_modifier != null) {
                                node.Data.ScriptClassName = m_modifier.GetType().FullName;
                                if(node.Data.InstanceData.ContainsValueOf(currentEditingGroup)) {
                                    node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                }
                            }
                        }

                        if (m_modifier != null) {
                            Action onChangedAction = () => {
                                using(new RecordUndoScope("Change Modifier Setting", node)) {
                                    node.Data.ScriptClassName = m_modifier.GetType().FullName;
                                    if(node.Data.InstanceData.ContainsValueOf(currentEditingGroup)) {
                                        node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                    }
                                }
                            };

                            m_modifier.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
コード例 #15
0
 private Rect GetOutputPointRect(NodeGUI node)
 {
     var baseRect = node.Region;
     return new Rect(
         baseRect.x + baseRect.width - 8f,
         baseRect.y + buttonRect.y + 1f,
         AssetBundleGraphGUISettings.CONNECTION_POINT_MARK_SIZE,
         AssetBundleGraphGUISettings.CONNECTION_POINT_MARK_SIZE
     );
 }
コード例 #16
0
        private void DoInspectorPrefabBuilderGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("PrefabBuilder: Create prefab with given assets and script.", MessageType.Info);
            UpdateNodeName(node);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {

                var map = PrefabBuilderUtility.GetAttributeClassNameMap();
                if(map.Count > 0) {
                    using(new GUILayout.HorizontalScope()) {
                        GUILayout.Label("PrefabBuilder");
                        var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(node.Data.ScriptClassName);

                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f))) {
                            var builders = map.Keys.ToList();

                            if(builders.Count > 0) {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                    {
                                        using(new RecordUndoScope("Change PrefabBuilder class", node, true)) {
                                            m_prefabBuilder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName);
                                            if(m_prefabBuilder != null) {
                                                node.Data.ScriptClassName = PrefabBuilderUtility.GUINameToClassName(selectedGUIName);
                                                node.Data.InstanceData.DefaultValue = m_prefabBuilder.Serialize();
                                            }
                                        }
                                    }
                                );
                            }
                        }
                    }
                } else {
                    if(!string.IsNullOrEmpty(node.Data.ScriptClassName)) {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", node.Data.ScriptClassName), MessageType.Info);
                    } else {
                        string[] menuNames = AssetBundleGraphSettings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one PrefabBuilder script to use PrefabBuilder node. To start, select {0}>{1}>{2} menu and create new script from template.",
                                menuNames[1],menuNames[2], menuNames[3]
                            ), MessageType.Info);
                    }
                }

                GUILayout.Space(10f);

                if(DrawPlatformSelector(node)) {
                    // if platform tab is changed, renew prefabBuilder for that tab.
                    m_prefabBuilder = null;
                }
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = DrawOverrideTargetToggle(node, node.Data.InstanceData.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                        if(enabled) {
                            node.Data.InstanceData[currentEditingGroup] = node.Data.InstanceData.DefaultValue;
                        } else {
                            node.Data.InstanceData.Remove(currentEditingGroup);
                        }
                        m_prefabBuilder = null;
                    });

                    using (disabledScope) {
                        //reload prefabBuilder instance from saved instance data.
                        if (m_prefabBuilder == null) {
                            m_prefabBuilder = PrefabBuilderUtility.CreatePrefabBuilder(node.Data, currentEditingGroup);
                            if(m_prefabBuilder != null) {
                                node.Data.ScriptClassName = m_prefabBuilder.GetType().FullName;
                                if(node.Data.InstanceData.ContainsValueOf(currentEditingGroup)) {
                                    node.Data.InstanceData[currentEditingGroup] = m_prefabBuilder.Serialize();
                                }
                            }
                        }

                        if (m_prefabBuilder != null) {
                            Action onChangedAction = () => {
                                using(new RecordUndoScope("Change PrefabBuilder Setting", node)) {
                                    node.Data.ScriptClassName = m_prefabBuilder.GetType().FullName;
                                    if(node.Data.InstanceData.ContainsValueOf(currentEditingGroup)) {
                                        node.Data.InstanceData[currentEditingGroup] = m_prefabBuilder.Serialize();
                                    }
                                }
                            };

                            m_prefabBuilder.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
コード例 #17
0
        private void DoInspectorBundleConfiguratorGUI(NodeGUI node)
        {
            if (node.Data.BundleNameTemplate == null) return;

            EditorGUILayout.HelpBox("BundleConfigurator: Create asset bundle settings with given group of assets.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            //Show target configuration tab
            DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = DrawOverrideTargetToggle(node, node.Data.BundleNameTemplate.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                    using(new RecordUndoScope("Remove Target Bundle Name Template Setting", node, true)){
                        if(enabled) {
                            node.Data.BundleNameTemplate[currentEditingGroup] = node.Data.BundleNameTemplate.DefaultValue;
                        } else {
                            node.Data.BundleNameTemplate.Remove(currentEditingGroup);
                        }
                    }
                });

                using (disabledScope) {
                    var bundleNameTemplate = EditorGUILayout.TextField("Bundle Name Template", node.Data.BundleNameTemplate[currentEditingGroup]).ToLower();

                    if (bundleNameTemplate != node.Data.BundleNameTemplate[currentEditingGroup]) {
                        using(new RecordUndoScope("Change Bundle Name Template", node, true)){
                            node.Data.BundleNameTemplate[currentEditingGroup] = bundleNameTemplate;
                        }
                    }
                }
            }

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                GUILayout.Label("Variants:");
                var variantNames = node.Data.Variants.Select(v => v.Name).ToList();
                Variant removing = null;
                foreach (var v in node.Data.Variants) {
                    using (new GUILayout.HorizontalScope()) {
                        if (GUILayout.Button("-", GUILayout.Width(30))) {
                            removing = v;
                        }
                        else {
                            GUIStyle s = new GUIStyle((GUIStyle)"TextFieldDropDownText");
                            Action makeStyleBold = () => {
                                s.fontStyle = FontStyle.Bold;
                                s.fontSize = 12;
                            };

                            IntegratedGUIBundleConfigurator.ValidateVariantName(v.Name, variantNames,
                                makeStyleBold,
                                makeStyleBold,
                                makeStyleBold);

                            var variantName = EditorGUILayout.TextField(v.Name, s);

                            if (variantName != v.Name) {
                                using(new RecordUndoScope("Change Variant Name", node, true)){
                                    v.Name = variantName;
                                }
                            }
                        }
                    }
                }
                if (GUILayout.Button("+")) {
                    using(new RecordUndoScope("Add Variant", node, true)){
                        node.Data.AddVariant(AssetBundleGraphSettings.BUNDLECONFIG_VARIANTNAME_DEFAULT);
                    }
                }
                if(removing != null) {
                    using(new RecordUndoScope("Remove Variant", node, true)){
                        // event must raise to remove connection associated with point
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_DELETED, node, Vector2.zero, removing.ConnectionPoint));
                        node.Data.RemoveVariant(removing);
                    }
                }
            }
        }
コード例 #18
0
        /*
         *  Return true if Platform is changed
         */
        private bool DrawPlatformSelector(NodeGUI node)
        {
            BuildTargetGroup g = currentEditingGroup;
            bool editGroupChanged = false;

            EditorGUI.BeginChangeCheck();
            using (new EditorGUILayout.HorizontalScope()) {
                var choosenIndex = -1;
                for (var i = 0; i < NodeGUIUtility.platformButtons.Length; i++) {
                    var onOffBefore = NodeGUIUtility.platformButtons[i].targetGroup == currentEditingGroup;
                    var onOffAfter = onOffBefore;

                    GUIStyle toolbarbutton = new GUIStyle("toolbarbutton");

                    if(NodeGUIUtility.platformButtons[i].targetGroup == BuildTargetUtility.DefaultTarget) {
                        onOffAfter = GUILayout.Toggle(onOffBefore, NodeGUIUtility.platformButtons[i].ui, toolbarbutton);
                    } else {
                        var width = Mathf.Max(32f, toolbarbutton.CalcSize(NodeGUIUtility.platformButtons[i].ui).x);
                        onOffAfter = GUILayout.Toggle(onOffBefore, NodeGUIUtility.platformButtons[i].ui, toolbarbutton, GUILayout.Width( width ));
                    }

                    if (onOffBefore != onOffAfter) {
                        choosenIndex = i;
                        break;
                    }
                }

                if (EditorGUI.EndChangeCheck()) {
                    g = NodeGUIUtility.platformButtons[choosenIndex].targetGroup;
                }
            }

            if (g != currentEditingGroup) {
                currentEditingGroup = g;
                editGroupChanged = true;
                GUI.FocusControl(string.Empty);
            }

            return editGroupChanged;
        }
コード例 #19
0
        private void DoInspectorExporterGUI(NodeGUI node)
        {
            if (node.Data.ExporterExportPath == null) {
                return;
            }

            EditorGUILayout.HelpBox("Exporter: Export given files to output directory.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            //Show target configuration tab
            DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = DrawOverrideTargetToggle(node, node.Data.ExporterExportPath.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                    using(new RecordUndoScope("Remove Target Export Settings", node, true)){
                        if(enabled) {
                            node.Data.ExporterExportPath[currentEditingGroup] = node.Data.ExporterExportPath.DefaultValue;
                        }  else {
                            node.Data.ExporterExportPath.Remove(currentEditingGroup);
                        }
                    }
                } );

                using (disabledScope) {
                    EditorGUILayout.LabelField("Export Path:");
                    var newExportPath = EditorGUILayout.TextField(
                        SystemDataUtility.GetProjectName(),
                        node.Data.ExporterExportPath[currentEditingGroup]
                    );

                    var exporterrNodePath = FileUtility.GetPathWithProjectPath(newExportPath);
                    if(IntegratedGUIExporter.ValidateExportPath(
                        newExportPath,
                        exporterrNodePath,
                        () => {
                            // TODO Make text field bold
                        },
                        () => {
                            using (new EditorGUILayout.HorizontalScope()) {
                                EditorGUILayout.LabelField(exporterrNodePath + " does not exist.");
                                if(GUILayout.Button("Create directory")) {
                                    using(new SaveScope(node)) {
                                        Directory.CreateDirectory(exporterrNodePath);
                                    }
                                }
                            }
                            EditorGUILayout.Space();

                            EditorGUILayout.LabelField("Available Directories:");
                            string[] dirs = Directory.GetDirectories(Path.GetDirectoryName(exporterrNodePath));
                            foreach(string s in dirs) {
                                EditorGUILayout.LabelField(s);
                            }
                        }
                    )) {
                        using (new EditorGUILayout.HorizontalScope()) {
                            GUILayout.FlexibleSpace();
                            #if UNITY_EDITOR_OSX
                            string buttonName = "Reveal in Finder";
                            #else
                            string buttonName = "Show in Explorer";
                            #endif
                            if(GUILayout.Button(buttonName)) {
                                EditorUtility.RevealInFinder(exporterrNodePath);
                            }
                        }
                    }

                    if (newExportPath != node.Data.ExporterExportPath[currentEditingGroup]) {
                        using(new RecordUndoScope("Change Export Path", node, true)){
                            node.Data.ExporterExportPath[currentEditingGroup] = newExportPath;
                        }
                    }
                }
            }
        }
コード例 #20
0
        private void DoInspectorBundleBuilderGUI(NodeGUI node)
        {
            if (node.Data.BundleBuilderBundleOptions == null) {
                return;
            }

            EditorGUILayout.HelpBox("BundleBuilder: Build asset bundles with given asset bundle settings.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            //Show target configuration tab
            DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = DrawOverrideTargetToggle(node, node.Data.BundleBuilderBundleOptions.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                    using(new RecordUndoScope("Remove Target Bundle Options", node, true)){
                        if(enabled) {
                            node.Data.BundleBuilderBundleOptions[currentEditingGroup] = node.Data.BundleBuilderBundleOptions.DefaultValue;
                        }  else {
                            node.Data.BundleBuilderBundleOptions.Remove(currentEditingGroup);
                        }
                    }
                } );

                using (disabledScope) {
                    int bundleOptions = node.Data.BundleBuilderBundleOptions[currentEditingGroup];

                    bool isDisableWriteTypeTreeEnabled  = 0 < (bundleOptions & (int)BuildAssetBundleOptions.DisableWriteTypeTree);
                    bool isIgnoreTypeTreeChangesEnabled = 0 < (bundleOptions & (int)BuildAssetBundleOptions.IgnoreTypeTreeChanges);

                    // buildOptions are validated during loading. Two flags should not be true at the same time.
                    UnityEngine.Assertions.Assert.IsFalse(isDisableWriteTypeTreeEnabled && isIgnoreTypeTreeChangesEnabled);

                    bool isSomethingDisabled = isDisableWriteTypeTreeEnabled || isIgnoreTypeTreeChangesEnabled;

                    foreach (var option in AssetBundleGraphSettings.BundleOptionSettings) {

                        // contains keyword == enabled. if not, disabled.
                        bool isEnabled = (bundleOptions & (int)option.option) != 0;

                        bool isToggleDisabled =
                            (option.option == BuildAssetBundleOptions.DisableWriteTypeTree  && isIgnoreTypeTreeChangesEnabled) ||
                            (option.option == BuildAssetBundleOptions.IgnoreTypeTreeChanges && isDisableWriteTypeTreeEnabled);

                        using(new EditorGUI.DisabledScope(isToggleDisabled)) {
                            var result = EditorGUILayout.ToggleLeft(option.description, isEnabled);
                            if (result != isEnabled) {
                                using(new RecordUndoScope("Change Bundle Options", node, true)){
                                    bundleOptions = (result) ?
                                        ((int)option.option | bundleOptions) :
                                        (((~(int)option.option)) & bundleOptions);
                                    node.Data.BundleBuilderBundleOptions[currentEditingGroup] = bundleOptions;
                                }
                            }
                        }
                    }
                    if(isSomethingDisabled) {
                        EditorGUILayout.HelpBox("'Disable Write Type Tree' and 'Ignore Type Tree Changes' can not be used together.", MessageType.Info);
                    }
                }
            }
        }
コード例 #21
0
        private void DoInspectorFilterGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("Filter: Filter incoming assets by keywords and types. You can use regular expressions for keyword field.", MessageType.Info);
            UpdateNodeName(node);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                GUILayout.Label("Filter Settings:");
                FilterEntry removing = null;
                for (int i= 0; i < node.Data.FilterConditions.Count; ++i) {
                    var cond = node.Data.FilterConditions[i];

                    Action messageAction = null;

                    using (new GUILayout.HorizontalScope()) {
                        if (GUILayout.Button("-", GUILayout.Width(30))) {
                            removing = cond;
                        }
                        else {
                            var newContainsKeyword = cond.FilterKeyword;

                            GUIStyle s = new GUIStyle((GUIStyle)"TextFieldDropDownText");

                            using (new EditorGUILayout.HorizontalScope()) {
                                newContainsKeyword = EditorGUILayout.TextField(cond.FilterKeyword, s, GUILayout.Width(120));
                                if (GUILayout.Button(cond.FilterKeytype , "Popup")) {
                                    var ind = i;// need this because of closure locality bug in unity C#
                                    NodeGUI.ShowFilterKeyTypeMenu(
                                        cond.FilterKeytype,
                                        (string selectedTypeStr) => {
                                            using(new RecordUndoScope("Modify Filter Type", node, true)){
                                                node.Data.FilterConditions[ind].FilterKeytype = selectedTypeStr;
                                            }
                                        }
                                    );
                                }
                            }

                            if (newContainsKeyword != cond.FilterKeyword) {
                                using(new RecordUndoScope("Modify Filter Keyword", node, true)){
                                    cond.FilterKeyword = newContainsKeyword;
                                    // event must raise to propagate change to connection associated with point
                                    NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_LABELCHANGED, node, Vector2.zero, cond.ConnectionPoint));
                                }
                            }
                        }
                    }

                    if(messageAction != null) {
                        using (new GUILayout.HorizontalScope()) {
                            messageAction.Invoke();
                        }
                    }
                }

                // add contains keyword interface.
                if (GUILayout.Button("+")) {
                    using(new RecordUndoScope("Add Filter Condition", node)){
                        node.Data.AddFilterCondition(
                            AssetBundleGraphSettings.DEFAULT_FILTER_KEYWORD,
                            AssetBundleGraphSettings.DEFAULT_FILTER_KEYTYPE);
                    }
                }

                if(removing != null) {
                    using(new RecordUndoScope("Remove Filter Condition", node, true)){
                        // event must raise to remove connection associated with point
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_DELETED, node, Vector2.zero, removing.ConnectionPoint));
                        node.Data.RemoveFilterCondition(removing);
                    }
                }
            }
        }
コード例 #22
0
 public void DuplicateNode(NodeGUI node)
 {
     var newNode = node.Duplicate(
         node.GetX() + 10f,
         node.GetY() + 10f
     );
     AddNodeGUI(newNode);
 }
コード例 #23
0
        private void DoInspectorGroupingGUI(NodeGUI node)
        {
            if (node.Data.GroupingKeywords == null) {
                return;
            }

            EditorGUILayout.HelpBox("Grouping: Create group of assets.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            //Show target configuration tab
            DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = DrawOverrideTargetToggle(node, node.Data.GroupingKeywords.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                    using(new RecordUndoScope("Remove Target Grouping Keyword Settings", node, true)){
                        if(enabled) {
                            node.Data.GroupingKeywords[currentEditingGroup] = node.Data.GroupingKeywords.DefaultValue;
                        } else {
                            node.Data.GroupingKeywords.Remove(currentEditingGroup);
                        }
                    }
                });

                using (disabledScope) {
                    var newGroupingKeyword = EditorGUILayout.TextField("Grouping Keyword",node.Data.GroupingKeywords[currentEditingGroup]);
                    EditorGUILayout.HelpBox(
                        "Grouping Keyword requires \"*\" in itself. It assumes there is a pattern such as \"ID_0\" in incoming paths when configured as \"ID_*\" ",
                        MessageType.Info);

                    if (newGroupingKeyword != node.Data.GroupingKeywords[currentEditingGroup]) {
                        using(new RecordUndoScope("Change Grouping Keywords", node, true)){
                            node.Data.GroupingKeywords[currentEditingGroup] = newGroupingKeyword;
                        }
                    }
                }
            }
        }
コード例 #24
0
        /**
         * Creates Graph structure with NodeGUI and ConnectionGUI from SaveData
         */
        private static void ConstructGraphFromSaveData(SaveData saveData, out List<NodeGUI> nodes, out List<ConnectionGUI> connections)
        {
            var currentNodes = new List<NodeGUI>();
            var currentConnections = new List<ConnectionGUI>();

            foreach (var node in saveData.Nodes) {
                var newNodeGUI = new NodeGUI(node);
                newNodeGUI.WindowId = GetSafeWindowId(currentNodes);
                currentNodes.Add(newNodeGUI);
            }

            // load connections
            foreach (var c in saveData.Connections) {
                var startNode = currentNodes.Find(node => node.Id == c.FromNodeId);
                if (startNode == null) {
                    continue;
                }

                var endNode = currentNodes.Find(node => node.Id == c.ToNodeId);
                if (endNode == null) {
                    continue;
                }
                var startPoint = startNode.Data.FindConnectionPoint (c.FromNodeConnectionPointId);
                var endPoint = endNode.Data.FindConnectionPoint (c.ToNodeConnectionPointId);

                currentConnections.Add(ConnectionGUI.LoadConnection(c.Label, c.Id, startPoint, endPoint));
            }

            nodes = currentNodes;
            connections = currentConnections;
        }
コード例 #25
0
        private void DoInspectorImportSettingGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("ImportSetting: Force apply import settings to given assets.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            /*
                importer node has no platform key.
                platform key is contained by Unity's importer inspector itself.
            */
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                Type incomingType = FindIncomingAssetType(node.Data.InputPoints[0]);
                IntegratedGUIImportSetting.ConfigStatus status =
                    IntegratedGUIImportSetting.GetConfigStatus(node.Data);

                if(incomingType == null) {
                    // try to retrieve incoming type from configuration
                    if(status == IntegratedGUIImportSetting.ConfigStatus.GoodSampleFound) {
                        incomingType = IntegratedGUIImportSetting.GetReferenceAssetImporter(node.Data).GetType();
                    } else {
                        EditorGUILayout.HelpBox("ImportSetting needs a single type of incoming assets.", MessageType.Info);
                        return;
                    }
                }

                switch(status) {
                case IntegratedGUIImportSetting.ConfigStatus.NoSampleFound:
                    // IntegratedGUIImportSetting.Setup() must run to grab another sample to configure.
                    EditorGUILayout.HelpBox("Press Refresh to configure.", MessageType.Info);
                    break;
                case IntegratedGUIImportSetting.ConfigStatus.GoodSampleFound:
                    if (GUILayout.Button("Configure Import Setting")) {
                        Selection.activeObject = IntegratedGUIImportSetting.GetReferenceAssetImporter(node.Data);
                    }
                    if (GUILayout.Button("Reset Import Setting")) {
                        IntegratedGUIImportSetting.ResetConfig(node.Data);
                    }
                    break;
                case IntegratedGUIImportSetting.ConfigStatus.TooManySamplesFound:
                    if (GUILayout.Button("Reset Import Setting")) {
                        IntegratedGUIImportSetting.ResetConfig(node.Data);
                    }
                    break;
                }
            }
        }
コード例 #26
0
        private void AddNodeFromCode(string name, string scriptClassName, Type scriptBaseType, float x, float y)
        {
            NodeGUI newNode = null;

            if (scriptBaseType == typeof(IModifier)) {
                var modifier = ModifierUtility.CreateModifier(scriptClassName);
                UnityEngine.Assertions.Assert.IsNotNull(modifier);

                newNode = new NodeGUI(new NodeData(name, NodeKind.MODIFIER_GUI, x, y));
                newNode.Data.ScriptClassName = scriptClassName;
                newNode.Data.InstanceData.DefaultValue = modifier.Serialize();
            }
            if (scriptBaseType == typeof(IPrefabBuilder)) {
                var builder = PrefabBuilderUtility.CreatePrefabBuilderByClassName(scriptClassName);
                UnityEngine.Assertions.Assert.IsNotNull(builder);

                newNode = new NodeGUI(new NodeData(name, NodeKind.PREFABBUILDER_GUI, x, y));
                newNode.Data.ScriptClassName = scriptClassName;
                newNode.Data.InstanceData.DefaultValue = builder.Serialize();
            }

            if (newNode == null) {
                Debug.LogError("Could not add node from code. " + scriptClassName + "(base:" + scriptBaseType +
                    ") is not supported to create from code.");
                return;
            }

            AddNodeGUI(newNode);
        }
コード例 #27
0
        private void DoInspectorLoaderGUI(NodeGUI node)
        {
            if (node.Data.LoaderLoadPath == null) {
                return;
            }

            EditorGUILayout.HelpBox("Loader: Load assets in given directory path.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            //Show target configuration tab
            DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = DrawOverrideTargetToggle(node, node.Data.LoaderLoadPath.ContainsValueOf(currentEditingGroup), (bool b) => {
                    using(new RecordUndoScope("Remove Target Load Path Settings", node, true)) {
                        if(b) {
                            node.Data.LoaderLoadPath[currentEditingGroup] = node.Data.LoaderLoadPath.DefaultValue;
                        } else {
                            node.Data.LoaderLoadPath.Remove(currentEditingGroup);
                        }
                    }
                });

                using (disabledScope) {
                    EditorGUILayout.LabelField("Load Path:");
                    var newLoadPath = EditorGUILayout.TextField(
                        SystemDataUtility.GetProjectName() + AssetBundleGraphSettings.ASSETS_PATH,
                        node.Data.LoaderLoadPath[currentEditingGroup]
                    );
                    if (newLoadPath !=	node.Data.LoaderLoadPath[currentEditingGroup]) {
                        using(new RecordUndoScope("Load Path Changed", node, true)){
                            node.Data.LoaderLoadPath[currentEditingGroup] = newLoadPath;
                        }
                    }
                }
            }
        }
コード例 #28
0
        private void AddNodeGUI(NodeGUI newNode)
        {
            int id = -1;

            foreach(var node in nodes) {
                if(node.WindowId > id) {
                    id = node.WindowId;
                }
            }

            newNode.WindowId = id + 1;

            nodes.Add(newNode);
        }
コード例 #29
0
 public void UpdateNode(NodeGUI node)
 {
     this.node = node;
 }