예제 #1
0
        void SwitchOption(UpgradeValidator validator, int i, bool forcedValue = false)
        {
            Selection.activeGameObject = validator.gameObject;
            var currentSettings = validator.ObjectSettings.Find(x => x.Prefab == validator.CurrentObject);
            var currentIndex    = validator.ObjectSettings.IndexOf(currentSettings);

            if (!forcedValue)
            {
                currentIndex += i;
                if (currentIndex < 0)
                {
                    currentIndex = validator.ObjectSettings.Count - 1;
                }
                else if (currentIndex >= validator.ObjectSettings.Count)
                {
                    currentIndex = 0;
                }
            }
            else
            {
                if (currentIndex == i)
                {
                    return;
                }
                currentIndex = i;
            }

            GameObject go = validator.ObjectSettings[currentIndex].Prefab;

            validator.ApplyUpgrade(go, true);

            EditorUtility.SetDirty(validator.gameObject);
        }
        public void SetTarget(UpgradeValidator validator)
        {
            label.text     = validator.ValidatorType.ToString();
            image.sprite   = validator.CurrentObject.GetComponent <SpriteRenderer>().sprite;
            this.validator = validator;

            dropdown.ClearOptions();
            int i = 0;

            foreach (var item in validator.ObjectSettings)
            {
                var text       = validator.ValidatorType.ToString() + " " + i++;
                var optionData = new TMPro.TMP_Dropdown.OptionData(text);
                dropdown.onValueChanged.AddListener(UpdateSelection);
                dropdown.options.Add(optionData);
            }
        }
예제 #3
0
        void DrawValidator(UpgradeValidator validator)
        {
            int i = 0;

            EditorGUILayout.LabelField(validator.name, EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(40 * validator.ObjectSettings.Count));

            // Draw Left Button
            if (DrawSwitchButton(EditorIcons.ArrowLeft))
            {
                SwitchOption(validator, -1);
            }

            foreach (var item in validator.ObjectSettings)
            {
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("    " + i++, GUILayout.Width(35), GUILayout.Height(10));
                var rect = EditorGUILayout.GetControlRect(GUILayout.Height(30), GUILayout.Width(35));
                if (item.Prefab == validator.CurrentObject)
                {
                    DrawBoxForSelectedObject(rect);
                }
                SirenixEditorFields.PreviewObjectField <GameObject>(rect, item.Prefab, true, false, false, false);

                if (DidClickOccur(rect))
                {
                    SwitchOption(validator, i - 1, true);
                    Debug.Log("Was Clicked");
                }

                EditorGUILayout.EndVertical();
            }

            // Draw Right Button
            if (DrawSwitchButton(EditorIcons.ArrowRight))
            {
                SwitchOption(validator, 1);
            }

            EditorGUILayout.EndHorizontal();
        }