Ejemplo n.º 1
0
        /// <summary>
        /// Draws the target object.
        /// </summary>
        /// <param name="_control">Control.</param>
        /// <param name="_target">Target.</param>
        /// <param name="_title">Title.</param>
        /// <param name="_help">Help.</param>
        public static void DrawTargetObject(ICECreatureControl _control, TargetObject _target, string _title, string _help = "")
        {
            if (_control == null || _target == null)
            {
                return;
            }

            _target.SetIsPrefab(EditorTools.IsPrefab(_target.TargetGameObject));

            // PREPARATION END

            if (!Application.isPlaying && !EditorTools.IsPrefab(_control.gameObject))
            {
                // TARGET OBJECT LINE BEGIN
                ICEEditorLayout.BeginHorizontal();

                if (_target.TargetGameObject == null)
                {
                    GUI.backgroundColor = Color.red;
                }
                else if (_target.Active)
                {
                    GUI.backgroundColor = Color.green;
                }

                string _target_title = "Target Object " + (_target.IsValid?(_target.IsPrefab?"(prefab)":"(scene)"):"(null)");

                if (_target.AccessType == TargetAccessType.NAME)
                {
                    _target.SetTargetByName(Popups.TargetPopup(_target_title, "", _target.TargetName, ""));
                }
                else if (_target.AccessType == TargetAccessType.TAG)
                {
                    _target.SetTargetByTag(EditorGUILayout.TagField(new GUIContent(_target_title, ""), _target.TargetTag));
                }
                else if (_target.AccessType == TargetAccessType.TYPE)
                {
                    _target.SetTargetByType((EntityClassType)EditorGUILayout.EnumPopup(new GUIContent(_target_title, ""), _target.TargetEntityType));
                }
                else
                {
                    _target.SetTargetByGameObject((GameObject)EditorGUILayout.ObjectField(_target_title, _target.TargetGameObject, typeof(GameObject), true));
                }


                GUI.backgroundColor = ICEEditorLayout.DefaultBackgroundColor;

                // Type Enum Popup
                int _indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;
                _target.AccessType    = (TargetAccessType)EditorGUILayout.EnumPopup(_target.AccessType, ICEEditorStyle.Popup, GUILayout.Width(50));
                EditorGUI.indentLevel = _indent;


                if (_target.TargetGameObject != null)
                {
                    ICEEditorLayout.ButtonDisplayObject(_target.TargetGameObject.transform.position);
                    ICEEditorLayout.ButtonSelectObject(_target.TargetGameObject, ICEEditorStyle.CMDButtonDouble);

                    //_target.UseChildObjects = ICEEditorLayout.CheckButtonSmall( "CHD", "Allows the selection of own child objects", _target.UseChildObjects, ICEEditorLayout.SelectionOptionGroup3Color, ICEEditorLayout.SelectionOptionGroup3SelectedColor );

                    //if( _target.TargetGameObject.GetComponent<ICECreatureTargetAttribute>() != null )
                    {
                        EditorGUI.BeginDisabledGroup(_target.ReadTargetAttributeData() == null);
                        GUI.backgroundColor = Color.green;
                        if (ICEEditorLayout.ButtonSmall("TAV", "Use target attribute values"))
                        {
                            _target.SetTargetDefaultValues(_target.ReadTargetAttributeData());
                        }
                        GUI.backgroundColor = ICEEditorLayout.DefaultBackgroundColor;
                        EditorGUI.EndDisabledGroup();
                    }
                }
                else
                {
                    if (ICEEditorLayout.AutoButton("Creates an empty GameObject as target with default settings"))
                    {
                        WizardEditor.WizardRandomTarget(_control, _target);
                    }
                }

                ICEEditorLayout.EndHorizontal(Info.TARGET_OBJECT);
                // TARGET OBJECT LINE END
            }
            else
            {
                DrawTargetObjectBlind(_target);
            }
        }
        public static string BehaviourPopup(ICECreatureControl _control, string _title, string _hint, string _key, ref bool _editor, string _default_key, bool _show_color, string _help = "")
        {
            string _hash = _default_key.GetHashCode().ToString();

            if (!m_BehaviourSelectEditor.ContainsKey(_hash))
            {
                m_BehaviourSelectEditor.Add(_hash, false);
            }
            _editor = (bool)m_BehaviourSelectEditor[_hash];

            bool _backup_key_exists = m_BehaviourBackupKeys.ContainsKey(_hash);

            if (_control.Creature.Behaviour.BehaviourModes.Count > 0 && !_backup_key_exists)
            {
                bool _key_exists = false;

                if (!IsValid(_key) && _show_color)
                {
                    GUI.backgroundColor = Color.red;
                }
                _key = Popups.BehaviourPopup(_control, _title, _hint, _key, ref _key_exists);
                GUI.backgroundColor = ICEEditorLayout.DefaultBackgroundColor;

                if (_key_exists)
                {
                    if (ICEEditorLayout.NewButton("Creates a new Behaviour Mode"))
                    {
                        m_BehaviourBackupKeys.Add(_hash, _key);
                        _key = "";
                    }
                }
                else
                {
                    _editor = false;
                    if (ICEEditorLayout.AddButton("Creates a new Behaviour Mode"))
                    {
                        _key    = _control.Creature.Behaviour.AddBehaviourMode(_key);
                        _editor = true;
                    }
                }


                if (IsValid(_key))
                {
                    EditorGUI.BeginDisabledGroup(_key_exists == false);
                    _editor = ICEEditorLayout.EditButton(_editor, "Shows/hides the Behaviour Mode Editor");
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(IsValid(_default_key) == false);
                    if (ICEEditorLayout.AutoButton("Generates a new behaviour mode automatically."))
                    {
                        _key = WizardEditor.WizardBehaviour(_control, _default_key);
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }
            else
            {
                if (!IsValid(_key) && _show_color)
                {
                    GUI.backgroundColor = Color.red;
                }
                string _new_key = EditorGUILayout.TextField(new GUIContent(_title, "Name of a new Behaviour"), _key);
                GUI.backgroundColor = ICEEditorLayout.DefaultBackgroundColor;

                if (_key != _new_key)
                {
                    if (!_backup_key_exists)
                    {
                        m_BehaviourBackupKeys.Add(_hash, _key);
                    }

                    _key = _new_key;
                }


                EditorGUI.BeginDisabledGroup(IsValid(_key) == false);
                if (ICEEditorLayout.AddButton("Adds new behaviour mode"))
                {
                    _key = _control.Creature.Behaviour.AddBehaviourMode(_key);

                    if (IsValid(_key))
                    {
                        if (_backup_key_exists)
                        {
                            m_BehaviourBackupKeys.Remove(_hash);
                        }

                        _editor = true;
                    }
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(_backup_key_exists == false);
                if (ICEEditorLayout.BackButton("Cancels this process"))
                {
                    _key = m_BehaviourBackupKeys[_hash].ToString();
                    m_BehaviourBackupKeys.Remove(_hash);
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(IsValid(_default_key) == false);
                if (ICEEditorLayout.AutoButton("Generates a new behaviour mode automatically."))
                {
                    _key = WizardEditor.WizardBehaviour(_control, _default_key);
                }
                EditorGUI.EndDisabledGroup();
            }

            m_BehaviourSelectEditor[_hash] = _editor;

            return(_key.Trim());
        }