public GameObjectRegisterUi(BitActionSwitchWindowViewModel viewModel, BitActionSwitchItem bitActionSwitchItem)
        {
            this.bitActionSwitchItem = bitActionSwitchItem;

            this.reorderableList = new ReorderableList(bitActionSwitchItem.gameObjects, typeof(GameObject), true, false,
                                                       true, true);

            this.reorderableList.drawHeaderCallback += rect =>
            {
                EditorGUI.LabelField(rect, L10n.Tr("Target Game Objects"));
            };

            this.reorderableList.drawElementCallback += (rect, index, active, focused) =>
            {
                var toggleFieldRect = rect;
                toggleFieldRect.width  = 16f;
                toggleFieldRect.height = EditorGUIUtility.singleLineHeight + 2;

                var objectFieldRect = rect;
                objectFieldRect.x     += toggleFieldRect.width + 2;
                objectFieldRect.y     += 1;
                objectFieldRect.width -= toggleFieldRect.width + 2;
                objectFieldRect.height = EditorGUIUtility.singleLineHeight;

                if (bitActionSwitchItem.gameObjects[index] != null)
                {
                    EditorCustomGUI.Toggle(toggleFieldRect, "", bitActionSwitchItem.gameObjects[index].activeSelf,
                                           x => bitActionSwitchItem.gameObjects[index].SetActive(x));
                }

                EditorCustomGUI.ObjectField(objectFieldRect, "", bitActionSwitchItem.gameObjects[index], true, true, x =>
                {
                    bitActionSwitchItem.gameObjects[index] = x;
                }, () => viewModel.IsErrorRegisterGameObject(bitActionSwitchItem.gameObjects[index]));
            };

            this.reorderableList.onAddCallback += list => bitActionSwitchItem.gameObjects.Add(null);
        }
        public void OnGUI(Rect position)
        {
            var staticActive = position;

            staticActive.height = EditorGUIUtility.singleLineHeight;

            var staticInactive = position;

            staticInactive.y     += staticActive.height + 2;
            staticInactive.height = EditorGUIUtility.singleLineHeight;

            var active = staticInactive;

            active.y     += staticInactive.height + 2;
            active.height = EditorGUIUtility.singleLineHeight;

            var inactive = active;

            inactive.y     += active.height + 2;
            inactive.height = EditorGUIUtility.singleLineHeight;

            EditorCustomGUI.ObjectField(staticActive, "Static Default", this.bitActionSwitchItem.staticDefaultClip,
                                        false, true, x => this.bitActionSwitchItem.staticDefaultClip = x,
                                        () => this.bitActionSwitchItem.staticDefaultClip != null);

            EditorCustomGUI.ObjectField(staticInactive, "Static NonDefault",
                                        this.bitActionSwitchItem.staticNonDefaultClip, false, true,
                                        x => this.bitActionSwitchItem.staticNonDefaultClip = x,
                                        () => this.bitActionSwitchItem.staticNonDefaultClip != null);

            EditorCustomGUI.ObjectField(active, "Default", this.bitActionSwitchItem.defaultClip, true, false,
                                        x => this.bitActionSwitchItem.defaultClip = x);

            EditorCustomGUI.ObjectField(inactive, "NonDefault", this.bitActionSwitchItem.nonDefaultClip, true,
                                        false, x => this.bitActionSwitchItem.nonDefaultClip = x);
        }
Example #3
0
        public void OnGUI(Rect position, int index)
        {
            if (this.titleStyle == null)
            {
                this.titleStyle = new GUIStyle(GUI.skin.box)
                {
                    fontStyle = FontStyle.Bold, normal = { textColor = EditorGUIUtility.isProSkin ? Color.white : Color.black }
                };
            }

            var backgroundRect = new Rect(position)
            {
                height = 20
            };
            var labelRect = backgroundRect;

            labelRect.xMin  += 32f;
            labelRect.xMax  -= 20f;
            labelRect.y     += 2;
            labelRect.height = 16f;

            var foldoutRect = backgroundRect;

            foldoutRect.y     += 1f;
            foldoutRect.width  = 13f;
            foldoutRect.height = 13f;

            var indicatorRect = backgroundRect;

            indicatorRect.x      = position.width + 17f;
            indicatorRect.y     += 3f;
            indicatorRect.width  = 13f;
            indicatorRect.height = 13f;

            GUI.Box(position, string.Format(L10n.Tr("Group {0}"), index + 1), this.titleStyle);

            // Background
            EditorGUI.DrawRect(backgroundRect, EditorCustomGUI.HeaderBackgroundColor);

            // Title
            EditorGUI.LabelField(labelRect, "");

            // foldout
            this.bitActionSwitchGroup.fold = GUI.Toggle(foldoutRect, this.bitActionSwitchGroup.fold, GUIContent.none, EditorStyles.foldout);

            var e = Event.current;

            if (e.type == EventType.MouseDown)
            {
                if (labelRect.Contains(e.mousePosition))
                {
                    if (e.button == 0)
                    {
                        this.bitActionSwitchGroup.fold = !this.bitActionSwitchGroup.fold;
                    }

                    e.Use();
                }
            }

            if (!this.bitActionSwitchGroup.fold)
            {
                return;
            }

            var objectField = position;

            objectField.height = EditorGUIUtility.singleLineHeight;
            objectField.y     += 22;

            var variableNameField = objectField;

            variableNameField.y += objectField.height + 2f;

            var reorderable = variableNameField;

            reorderable.x     += 4;
            reorderable.width -= 4;
            reorderable.y     += variableNameField.height + 2;

            EditorCustomGUI.ObjectField(objectField, L10n.Tr("Menu"), this.bitActionSwitchGroup.expressionsMenu, false, true,
                                        x => { this.bitActionSwitchGroup.expressionsMenu = x; }, () => this.viewModel.IsErrorExpressionMenu(this.bitActionSwitchGroup));

            EditorGUI.BeginDisabledGroup(true);
            EditorCustomGUI.TextField(variableNameField, L10n.Tr("Variable"), this.bitActionSwitchGroup.variableName,
                                      x => this.bitActionSwitchGroup.variableName = x, () => this.viewModel.IsErrorVariableName(this.bitActionSwitchGroup.variableName));
            EditorGUI.EndDisabledGroup();

            this.reorderableList.DoList(reorderable);

            this.reorderableList.displayAdd = this.bitActionSwitchGroup.bitActionSwitchItems.Count < 8 &&
                                              (this.bitActionSwitchGroup.expressionsMenu == null ? 0 :
                                               this.bitActionSwitchGroup.expressionsMenu.controls
                                               .Count(x => x.parameter.name != null && !x.parameter.name.StartsWith(ActionSwitchParameters.PREFIX))) +
                                              this.bitActionSwitchGroup.bitActionSwitchItems.Count < 8;
        }
Example #4
0
        public void OnGUI(Rect position)
        {
            var backgroundRect = new Rect(position)
            {
                height = 20
            };
            var labelRect = backgroundRect;

            labelRect.xMin  += 32f;
            labelRect.xMax  -= 20f;
            labelRect.y     += 2;
            labelRect.height = 16f;

            var foldoutRect = backgroundRect;

            foldoutRect.y     += 1f;
            foldoutRect.width  = 13f;
            foldoutRect.height = 13f;

            var indicatorRect = backgroundRect;

            indicatorRect.x      = position.width + 17f;
            indicatorRect.y     += 3f;
            indicatorRect.width  = 13f;
            indicatorRect.height = 13f;

            var boxRect = position;

            boxRect.height -= this.bitActionSwitchItem.fold ? 12f : 1f;
            GUI.Box(boxRect, "");

            // Background
            EditorGUI.DrawRect(backgroundRect, EditorCustomGUI.HeaderBackgroundColor);

            // Title
            EditorCustomGUI.TextField(labelRect, "", this.bitActionSwitchItem.name,
                                      x => this.bitActionSwitchItem.name = x,
                                      () => this.viewModel.IsErrorGroupItemName(this.bitActionSwitchItem.name));

            // foldout
            this.bitActionSwitchItem.fold = GUI.Toggle(foldoutRect, this.bitActionSwitchItem.fold, GUIContent.none, EditorStyles.foldout);

            if (!this.bitActionSwitchItem.fold)
            {
                return;
            }

            var cachedLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 125;

            var iconRect = position;

            iconRect.width  = 48;
            iconRect.height = 48;
            iconRect.x     += 3;
            iconRect.y     += 22;

            var enumRect = position;

            enumRect.x     += iconRect.width + 8;
            enumRect.width -= iconRect.width + 12;
            enumRect.height = EditorGUIUtility.singleLineHeight + 2;
            enumRect.y      = iconRect.y;

            var objectRect = enumRect;

            objectRect.y += EditorGUIUtility.singleLineHeight + 2;

            EditorCustomGUI.ObjectField(iconRect, "", this.bitActionSwitchItem.icon, false, false,
                                        x => { this.bitActionSwitchItem.icon = x; });

            EditorCustomGUI.EnumPopup <BitActionSwitchItem.RegisterType>(enumRect, L10n.Tr("Register Type"),
                                                                         this.bitActionSwitchItem.registerType, x => this.bitActionSwitchItem.registerType = x);


            if (this.bitActionSwitchItem.registerType == BitActionSwitchItem.RegisterType.GameObject)
            {
                this.gameObjectRegisterUi.OnGUI(objectRect, this.targetAvatar);
            }
            else
            {
                this.customAnimRegisterUi.OnGUI(objectRect);
            }

            EditorGUIUtility.labelWidth = cachedLabelWidth;
        }