Ejemplo n.º 1
0
        void OnGUI()
        {
            var types = PubSubMessages.GetAllMessageTypes();

            foreach (var type in types)
            {
                EditorGUILayout.LabelField(type.ToString());
            }
        }
Ejemplo n.º 2
0
        private void PubSubMessageGUI()
        {
            var binding = (SingleTargetedBinding)target;
            var types   = PubSubMessages.GetAllMessageTypes();
            var names   = types.Select(x => x.Name).ToList();

            var idx = names.IndexOf(binding.targetVariableName);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("TargetMessage");
            var newIdx = EditorGUILayout.Popup(0, names.ToArray());

            EditorGUILayout.EndHorizontal();

            var selectedType = types[newIdx];

            if (acceptedTypes.Length == 1 && acceptedTypes[0] == typeof(bool))
            {
                idx = binding.emitTrue ? 0 : 1;
                EditorGUILayout.BeginHorizontal();
                binding.fireOnMessage = EditorGUILayout.Toggle(binding.fireOnMessage);
                GUI.enabled           = binding.fireOnMessage;
                EditorGUILayout.LabelField("trigger (", GUILayout.MaxWidth(50));
                newIdx = EditorGUILayout.Popup(idx, new string[] { "true", "false" });
                EditorGUILayout.LabelField(") when received");
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();

                binding.emitTrue = newIdx == 0 ? true : false;

                EditorGUI.indentLevel++;
                GUI.enabled = !binding.fireOnMessage;
            }

            var props     = selectedType.GetProperties();
            var propNames = props.Select(x => x.Name).ToList();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Property");
            newIdx = EditorGUILayout.Popup(0, propNames.ToArray());
            EditorGUILayout.EndHorizontal();

            if (acceptedTypes.Length == 1 && acceptedTypes[0] == typeof(bool))
            {
                GUI.enabled = true;
                EditorGUI.indentLevel--;
            }

            binding.targetMessageTypeName = selectedType.FullName;
            binding.targetVariableName    = propNames[newIdx];
        }
Ejemplo n.º 3
0
        private void OnPubSubMessage()
        {
            scroll = EditorGUILayout.BeginScrollView(scroll);
            foreach (var message in PubSubMessages.GetAllMessageTypes())
            {
                var prev   = selectedTypes.Contains(message);
                var toggle = EditorGUILayout.ToggleLeft(message.Name, prev);

                if (toggle && prev == false)
                {
                    selectedTypes.Add(message);
                }
                else if (toggle == false && prev == true)
                {
                    selectedTypes.Remove(message);
                }
            }
            EditorGUILayout.EndScrollView();

            var allObjects      = GameObject.FindObjectsOfTypeAll(typeof(GameObject));
            var selectedObjects = new List <UnityEngine.Object>();

            foreach (GameObject obj in allObjects)
            {
                var bindings = obj.GetComponents <SingleTargetedBinding>();
                if (bindings.Length == 0)
                {
                    continue;
                }

                foreach (var binding in bindings)
                {
                    if (binding.subscriptionType == SubscriptionType.PubSubMessage &&
                        selectedTypes.Any(x => x.FullName == binding.targetMessageTypeName))
                    {
                        selectedObjects.Add(obj);
                        break;
                    }
                }
            }

            Selection.objects = selectedObjects.ToArray();
        }