示例#1
0
        public static CompositeModule FindOwner(BaseModule module)
        {
            if (module == null)
            {
                return(null);
            }

            if (module is CompositeModule)
            {
                return(module.transform.parent.GetComponentInParent <CompositeModule>());
            }
            else
            {
                return(module.GetComponentInParent <CompositeModule>());
            }
        }
        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);
        }