/// <summary>
        /// Do a editor layout of wire
        /// </summary>
        /// <returns>Should Remove or Not,if true ,should remove</returns>
        public void DoInoutMapperEditingLayout(List <BaseModule> modules)
        {
            EditorGUILayout.BeginHorizontal();
            bool collapseButtonClicked = GUILayout.Button(editorFolded ? "+" : "-", GUILayout.Height(15f), GUILayout.Width(15f));

            if (collapseButtonClicked)
            {
                editorFolded = !editorFolded;
            }

            EditorGUILayout.LabelField(mapName + ":" + Type.ToString());
            EditorGUILayout.EndHorizontal();

            InoutPort prevPort = target.port;

            if (!editorFolded)
            {
                target.DoConnectionLayout(modules);
                if (prevPort != target.port)
                {
                    Validate();
                }
            }
        }
 public InoutMapper(BaseModule sourceModule, InoutPort source)
 {
     this.sourceModule = sourceModule;
     this.source       = source;
     this.mapName      = this.source.name;
 }
        public bool DoConnectionLayout(List <BaseModule> modules)
        {
            var preModule = module;
            var prePort   = port;

            //Module selection
            if (modules == null || modules.Count == 0)
            {
                EditorGUILayout.LabelField("Modules are empty");
                return(true);
            }


            if (module == null)
            {
                module = modules[0];
            }

            if (!modules.Exists(p => p == module))
            {
                module = modules[0];
            }

            List <string> names  = new List <string>(from m in modules select m.moduleName);
            List <int>    indexs = new List <int>();

            for (int i = 0; i < modules.Count; i++)
            {
                indexs.Add(i);
            }

            int selected = modules.FindIndex(p => p == module);

            selected = EditorGUILayout.IntPopup(selected, names.ToArray(), indexs.ToArray());
            module   = modules[selected];


            //Ports selection
            List <InoutPort> ports = module.GetPortsByType <InoutPort>();

            if (ports == null || ports.Count == 0)
            {
                return(true);
            }

            if (port == null)
            {
                port = ports[0];
            }

            if (!ports.Exists(p => p == port))
            {
                port = ports[0];
            }

            indexs.Clear();
            names = new List <string>(from p in ports select p.name);
            for (int i = 0; i < ports.Count; i++)
            {
                indexs.Add(i);
            }
            selected = ports.FindIndex(p => p == port);
            selected = EditorGUILayout.IntPopup(selected, names.ToArray(), indexs.ToArray());
            port     = ports[selected];

            //Value changed
            if (module != preModule || port != prePort)
            {
                return(true);
            }

            return(false);
        }