コード例 #1
0
        public T Instantiate <T>(uint tag) where T : IView
        {
            Binding       binding = _bindings[typeof(T)];
            BindingTarget target  = binding.Targets.Find(x => x.Tag == tag);
            GameObject    obj     = GameObject.Instantiate(target.Prefab);

            return(GetComponent <T>(obj));
        }
コード例 #2
0
        private void DrawTarget(TargetView view, Type viewType)
        {
            EditorGUILayout.BeginHorizontal();

            BindingTarget target = view.Target;

            // Tag Selector
            TagTypeData tagData;

            if (_tagTypes.TryGetValue(viewType, out tagData))
            {
                int previouslySelected = view.TagIndex;
                int selectedIndex      = EditorGUILayout.Popup(
                    previouslySelected,
                    tagData.DisplayNames
                    );
                if (selectedIndex != previouslySelected)
                {
                    view.TagIndex = selectedIndex;
                    target.Tag    = tagData.Values[selectedIndex];
                }
            }

            // Prefab field
            target.Prefab = EditorGUILayout.ObjectField(
                target.Prefab, typeof(GameObject),
                allowSceneObjects: false
                ) as GameObject;

            // Remove button
            if (GUILayout.Button("-", GUILayout.MaxWidth(32)))
            {
                _targetToRemove = view;
            }

            EditorGUILayout.EndHorizontal();
        }
コード例 #3
0
        private void DrawBinding(BindingView view)
        {
            TypeBinding binding = view.Binding;

            // Fold
            EditorGUILayout.BeginHorizontal();
            bool   isFoldOpen = view.IsFoldOpen;
            string foldName   = _typeDisplayNamesArray[view.TypeIndex];

            isFoldOpen      = EditorGUILayout.Foldout(isFoldOpen, foldName);
            view.IsFoldOpen = isFoldOpen;

            // Add button
            if (isFoldOpen)
            {
                if (GUILayout.Button("Add Target"))
                {
                    var target = new BindingTarget();
                    binding.Targets.Add(target);
                    view.TargetViews.Add(new TargetView()
                    {
                        Target = target
                    });
                }
            }

            if (GUILayout.Button("-", GUILayout.MaxWidth(32)))
            {
                _bindingToRemove = view;
            }

            EditorGUILayout.EndHorizontal();

            // Fold Contents
            if (isFoldOpen)
            {
                // Type selector
                int oldSelectedIndex = view.TypeIndex;
                int selectedIndex    = EditorGUILayout.Popup(
                    oldSelectedIndex,
                    _typeDisplayNamesArray
                    );
                Type bindingType = GetTypeFromIndex(selectedIndex);
                if (selectedIndex != oldSelectedIndex)
                {
                    if (bindingType != null)
                    {
                        binding.TypeName = bindingType.AssemblyQualifiedName;
                    }
                    view.TypeIndex = selectedIndex;
                }

                ++EditorGUI.indentLevel;
                if (bindingType != null)
                {
                    foreach (TargetView targetView in view.TargetViews)
                    {
                        DrawTarget(targetView, bindingType);
                    }
                }

                if (_targetToRemove != null)
                {
                    binding.Targets.Remove(_targetToRemove.Target);
                    view.TargetViews.Remove(_targetToRemove);
                    _targetToRemove = null;
                }
                --EditorGUI.indentLevel;
                EditorGUILayout.Space();
            }
        }