public static void RenameBehaviourMode(ICECreatureControl _control, BehaviourModeObject _mode) { if (m_BehaviourRenameMode == null || m_BehaviourRenameMode != _mode) { return; } ICEEditorLayout.Label("Rename Behaviour Mode", true); EditorGUI.indentLevel++; ICEEditorLayout.BeginHorizontal(); m_BehaviourRenameKey = EditorGUILayout.TextField("Mode Key", _control.Creature.Behaviour.GetFixedBehaviourModeKey(m_BehaviourRenameKey)); if (ICEEditorLayout.Button("RENAME")) { if (_control.Creature.Behaviour.BehaviourModeExists(m_BehaviourRenameKey) == false) { m_BehaviourRenameMode.Key = m_BehaviourRenameKey; m_BehaviourRenameKey = ""; m_BehaviourRenameMode = null; } } if (ICEEditorLayout.Button("CANCEL")) { m_BehaviourRenameKey = ""; m_BehaviourRenameMode = null; } ICEEditorLayout.EndHorizontal(Info.BEHAVIOUR_MODE_RENAME); EditorGUI.indentLevel--; EditorGUILayout.Separator(); }
/// <summary> /// Creates automatically a die behaviour rule. /// </summary> /// <param name="_control">Control.</param> /// <param name="_key">Key.</param> public static void CreateBehaviourRuleDie(ICECreatureControl _control, BehaviourModeObject _behaviour) { if (_behaviour == null) { return; } _behaviour.NextRule(); if (_behaviour.Rule != null) { _behaviour.Rule.Move.Enabled = false; _behaviour.Rule.Move.Foldout = false; _behaviour.Rule.Move.Motion.Velocity = Vector3.zero; _behaviour.Rule.Move.Motion.AngularVelocity = Vector3.zero; if (!_control.Creature.Essentials.IgnoreAnimationDead) { _behaviour.Rule.Animation.Copy(_control.Creature.Essentials.AnimationDead); _behaviour.Rule.Animation.Enabled = true; _behaviour.Rule.Animation.Foldout = true; } else if (!_control.Creature.Essentials.IgnoreAnimationIdle) { _behaviour.Rule.Animation.Copy(_control.Creature.Essentials.AnimationIdle); _behaviour.Rule.Animation.Enabled = true; _behaviour.Rule.Animation.Foldout = true; } } }
/// <summary> /// Creates automatically an walk behaviour rule. /// </summary> /// <param name="_control">Control.</param> /// <param name="_key">Key.</param> public static void CreateBehaviourRuleWalk(ICECreatureControl _control, BehaviourModeObject _behaviour) { if (_behaviour == null) { return; } _behaviour.NextRule(); if (_behaviour.Rule != null) { _behaviour.Rule.Move.Enabled = true; _behaviour.Rule.Move.Foldout = true; _behaviour.Rule.Move.Motion.AngularVelocity.y = _control.Creature.Essentials.DefaultTurningSpeed; if (!_control.Creature.Essentials.IgnoreAnimationWalk) { _behaviour.Rule.Move.Motion.Velocity.z = _control.Creature.Essentials.DefaultWalkingSpeed; _behaviour.Rule.Animation.Copy(_control.Creature.Essentials.AnimationWalk); _behaviour.Rule.Animation.Enabled = true; _behaviour.Rule.Animation.Foldout = true; } else if (!_control.Creature.Essentials.IgnoreAnimationRun) { _behaviour.Rule.Move.Motion.Velocity.z = _control.Creature.Essentials.DefaultRunningSpeed; _behaviour.Rule.Animation.Copy(_control.Creature.Essentials.AnimationRun); _behaviour.Rule.Animation.Enabled = true; _behaviour.Rule.Animation.Foldout = true; } else { _behaviour.Rule.Move.Motion.Velocity.z = _control.Creature.Essentials.DefaultWalkingSpeed; } } }
/// <summary> /// Behaviours the popup. /// </summary> /// <returns>The popup.</returns> /// <param name="_creature_control">Creature control.</param> /// <param name="_title">Title.</param> /// <param name="_hint">Hint.</param> /// <param name="_key">Key.</param> public static string BehaviourPopup(ICECreatureControl _creature_control, string _title, string _hint, string _key, ref bool _key_exists) { string _new_key = ""; if (_creature_control.Creature.Behaviour.BehaviourModes.Count == 0) { EditorGUILayout.LabelField(_title); return(_new_key); } else { GUIContent[] _options = new GUIContent[_creature_control.Creature.Behaviour.BehaviourModes.Count + 1]; int _options_index = 0; _options[0] = new GUIContent(" "); for (int i = 0; i < _creature_control.Creature.Behaviour.BehaviourModes.Count; i++) { BehaviourModeObject _mode = _creature_control.Creature.Behaviour.BehaviourModes[i]; int _index = i + 1; _options[_index] = new GUIContent(_mode.Key); if (_mode.Key == _key) { _options_index = _index; } } if (_options_index == 0 && !string.IsNullOrEmpty(_key) && _key.Trim() != "") { GUIContent[] _new_options = new GUIContent[_options.Length + 1]; int _new_options_index = _options.Length; for (int i = 0; i < _options.Length; i++) { _new_options[i] = new GUIContent(_options[i].text); } _new_options[_new_options_index] = new GUIContent(_key); GUI.backgroundColor = Color.yellow; _new_options_index = EditorGUILayout.Popup(new GUIContent(_title, _hint), _new_options_index, _new_options); GUI.backgroundColor = ICEEditorLayout.DefaultBackgroundColor; _new_key = _new_options[_new_options_index].text; _key_exists = false; } else { _options_index = EditorGUILayout.Popup(new GUIContent(_title, _hint), _options_index, _options); _new_key = _options[_options_index].text; _key_exists = true; } } return(_new_key); }
public static BehaviourModeObject LoadBehaviourModeFromFile(BehaviourModeObject _object) { m_Path = Load("cc_behaviour_mode"); if (m_Path.Length == 0) { return(_object); } return(LoadObjectFromFile <BehaviourModeObject>(_object)); }
public static void SaveBehaviourModeToFile(BehaviourModeObject _object, string owner) { m_Path = Save(owner, "cc_behaviour_mode"); if (m_Path.Length == 0) { return; } SaveObjectToFile <BehaviourModeObject>(_object); }
public virtual void DoBehaviourModeChanged(GameObject _sender, BehaviourModeObject _new_mode, BehaviourModeObject _last_mode) { if (DebugLogIsEnabled) { PrintDebugLog("DoBehaviourModeChanged - creature changed behaviour from " + (_last_mode != null ? _last_mode.Key:"UNKNOWN") + " to " + (_new_mode != null ? _new_mode.Key:"UNKNOWN") + "!"); } if (OnBehaviourModeChanged != null) { OnBehaviourModeChanged(_sender, _new_mode, _last_mode); } }
/// <summary> /// Draws the content of the behaviour mode. /// </summary> /// <param name="_control">Control.</param> /// <param name="_mode">Mode.</param> public static void DrawBehaviourModeContent(ICECreatureControl _control, BehaviourModeObject _mode) { if (_mode == null) { return; } EditorHeaderType _header = EditorHeaderType.FOLDOUT_ENABLED_BOLD; EditorGUI.indentLevel++; CreatureObjectEditor.DrawBehaviourModeFavouredObject(_control, _mode.Favoured, _header, Info.BEHAVIOUR_MODE_FAVOURED); EditorGUI.indentLevel--; if (_mode.Rules.Count > 1) { ICEEditorLayout.Label("Rules", true, Info.BEHAVIOUR_MODE_RULE); EditorGUI.indentLevel++; ICEEditorLayout.BeginHorizontal(); _mode.RulesOrderType = (SequenceOrderType)ICEEditorLayout.EnumPopup("Order Type", "", _mode.RulesOrderType); EditorGUI.BeginDisabledGroup(_mode.RulesOrderType != SequenceOrderType.CYCLE); _mode.RulesOrderInverse = ICEEditorLayout.CheckButtonMiddle("INVERSE", "", _mode.RulesOrderInverse); EditorGUI.EndDisabledGroup(); ICEEditorLayout.EndHorizontal(Info.BEHAVIOUR_MODE_RULES_ORDER); EditorGUI.indentLevel--; } for (int i = 0; i < _mode.Rules.Count; i++) { DrawBehaviourModeRule(_control, _mode, i, _mode.Rules, _mode.Key); } if (_mode.Rules.Count == 1) { ICEEditorStyle.SplitterByIndent(EditorGUI.indentLevel + 1); ICEEditorLayout.BeginHorizontal(); EditorGUILayout.LabelField("Add or Copy Behaviour Rule", EditorStyles.miniLabel); if (ICEEditorLayout.AddButton("Add Behaviour Rule")) { _mode.Rules.Add(new BehaviourModeRuleObject()); } if (ICEEditorLayout.CopyButtonMiddle("Copy Behaviour Rule")) { _mode.Rules.Add(new BehaviourModeRuleObject(_mode.Rules[0])); } ICEEditorLayout.EndHorizontal("Add or Copy Behaviour Rule"); } else { ICEEditorLayout.DrawListAddLine <BehaviourModeRuleObject>(_mode.Rules, new BehaviourModeRuleObject(), true, "Add Behaviour Rule", Info.BEHAVIOUR_MODE_RULE_ADD); } //EditorGUILayout.Separator(); }
void OnBehaviourModeChanged(GameObject _sender, BehaviourModeObject _new_mode, BehaviourModeObject _last_mode) { if (_new_mode == null) { return; } string _text = ""; if (m_Dialog.TryGetValue(_new_mode.Key, out _text)) { m_DialogText.text = _text; } }
public static string WizardBehaviour(ICECreatureControl _control, string _key) { _key = _control.Creature.Behaviour.AddBehaviourMode(_key); BehaviourModeObject _behaviour = _control.Creature.Behaviour.GetBehaviourModeByKey(_key); if (!WizardAnimation(_control, _behaviour)) { return(_key); } return(_key); }
public static void DrawBehaviourEditor(ICECreatureControl _control, ref string _key) { if (string.IsNullOrEmpty(_key) || _key.Trim() == "") { return; } BehaviourModeObject _mode = _control.Creature.Behaviour.GetBehaviourModeByKey(_key); if (_mode == null) { return; } EditorGUILayout.BeginVertical("box"); DrawBehaviourMode(_control, _mode, true); EditorGUILayout.EndVertical(); _key = _mode.Key; }
/// <summary> /// Creates automatically an attack behaviour rule. /// </summary> /// <param name="_control">Control.</param> /// <param name="_key">Key.</param> public static void CreateBehaviourRuleAttack(ICECreatureControl _control, BehaviourModeObject _behaviour) { if (_behaviour == null) { return; } _behaviour.NextRule(); if (_behaviour.Rule != null) { _behaviour.Rule.Move.Enabled = true; _behaviour.Rule.Move.Foldout = true; _behaviour.Rule.Move.Motion.Velocity = Vector3.zero; _behaviour.Rule.Move.Motion.AngularVelocity.y = _control.Creature.Essentials.DefaultTurningSpeed; _behaviour.Rule.Move.ViewingDirection = ViewingDirectionType.CENTER; if (!_control.Creature.Essentials.IgnoreAnimationAttack) { _behaviour.Rule.Animation.Copy(_control.Creature.Essentials.AnimationAttack); _behaviour.Rule.Animation.Enabled = true; _behaviour.Rule.Animation.Foldout = true; } } }
/// <summary> /// Behaviours the popup. /// </summary> /// <returns>The popup.</returns> /// <param name="_creature_control">Creature control.</param> /// <param name="_key">Key.</param> public static string BehaviourPopup(ICECreatureControl _creature_control, string _key) { string _new_key = ""; if (_creature_control.Creature.Behaviour.BehaviourModes.Count == 0) { EditorGUILayout.LabelField(""); return(_new_key); } else { GUIContent[] _options = new GUIContent[_creature_control.Creature.Behaviour.BehaviourModes.Count + 1]; int _options_index = 0; _options[0] = new GUIContent(" "); for (int i = 0; i < _creature_control.Creature.Behaviour.BehaviourModes.Count; i++) { BehaviourModeObject _mode = _creature_control.Creature.Behaviour.BehaviourModes[i]; int _index = i + 1; _options[_index] = new GUIContent(_mode.Key); if (_mode.Key == _key) { _options_index = _index; } } _options_index = EditorGUILayout.Popup(_options_index, _options); _new_key = _options[_options_index].text; } return(_new_key); }
public static bool WizardAnimation(ICECreatureControl _control, BehaviourModeObject _behaviour) { if (_behaviour == null) { return(false); } _behaviour.NextRule(); if (_behaviour.Rule == null) { return(false); } if (_behaviour.Key == "RUN" || _behaviour.Key == "TRAVEL" || _behaviour.Key == "JOURNEY" || _behaviour.Key == "HUNT" || _behaviour.Key == "ESCAPE" || _behaviour.Key == "FLEE") { _behaviour.Rule.Move.Enabled = true; _behaviour.Rule.Move.Motion.Velocity.z = _control.Creature.Essentials.DefaultRunningSpeed; _behaviour.Rule.Move.Motion.AngularVelocity.y = _control.Creature.Essentials.DefaultTurningSpeed; } else if (_behaviour.Key == "WALK" || _behaviour.Key == "LEISURE" || _behaviour.Key == "AVOID") { _behaviour.Rule.Move.Enabled = true; _behaviour.Rule.Move.Motion.Velocity.z = _control.Creature.Essentials.DefaultWalkingSpeed; _behaviour.Rule.Move.Motion.AngularVelocity.y = _control.Creature.Essentials.DefaultTurningSpeed; } else { _behaviour.Rule.Move.Enabled = false; _behaviour.Rule.Move.Motion.Velocity.z = 0; _behaviour.Rule.Move.Motion.AngularVelocity.y = 0; } if (_control.GetComponent <Animator>() != null && _control.GetComponent <Animator>().runtimeAnimatorController != null) { AnimationClip[] _clips = AnimationTools.GetAnimationClips(_control.GetComponent <Animator>()); int _index = 0; foreach (AnimationClip _clip in _clips) { if (AnimationIsSuitable(_behaviour.Key, _clip.name)) { _behaviour.Rule.Animation.InterfaceType = AnimationInterfaceType.MECANIM; _behaviour.Rule.Animation.Animator.Type = AnimatorControlType.DIRECT; _behaviour.Rule.Animation.Animator.Name = _clip.name; _behaviour.Rule.Animation.Animator.Index = _index; break; } _index++; } } else if (_control.GetComponentInChildren <Animation>() != null) { Animation _animation = _control.GetComponentInChildren <Animation>(); int _index = 0; foreach (AnimationState _state in _animation) { if (AnimationIsSuitable(_behaviour.Key, _state.name)) { _behaviour.Rule.Animation.InterfaceType = AnimationInterfaceType.LEGACY; _behaviour.Rule.Animation.Animation.Name = _state.name; _behaviour.Rule.Animation.Animation.Index = _index; } _index++; } } return(true); }
/// <summary> /// Draws the behaviour mode rule. /// </summary> /// <param name="_index">_index.</param> /// <param name="_list">_list.</param> public static void DrawBehaviourModeRule(ICECreatureControl _control, BehaviourModeObject _mode, int _index, List <BehaviourModeRuleObject> _list, string _key) { BehaviourModeRuleObject _rule = _list[_index]; if (_rule == null) { return; } if (_list.Count > 1) { EditorGUI.indentLevel++; ICEEditorStyle.SplitterByIndent(EditorGUI.indentLevel); ICEEditorLayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(_rule.Enabled == false); _rule.Foldout = EditorGUILayout.Foldout(_rule.Foldout, _key + " Rule #" + (_index + 1), ICEEditorStyle.Foldout); EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); ICEEditorLayout.StatusButton("ACTIVE", _rule.Active == false, Color.green); if (ICEEditorLayout.CopyButtonMiddle()) { _list.Add(new BehaviourModeRuleObject(_rule)); } GUILayout.Space(5); if (ICEEditorLayout.ListDeleteButton <BehaviourModeRuleObject>(_list, _rule, "Removes this rule.")) { return; } if (ICEEditorLayout.ListUpDownButtons <BehaviourModeRuleObject>(_list, _list.IndexOf(_rule))) { return; } _rule.Enabled = ICEEditorLayout.EnableButton("Enables/disables this rule", _rule.Enabled); ICEEditorLayout.EndHorizontal(Info.BEHAVIOUR_MODE_RULE); } else { _rule.Foldout = true; _rule.Enabled = true; } if (_rule.Foldout) { EditorHeaderType _header = EditorHeaderType.FOLDOUT_ENABLED_BOLD; EditorHeaderType _sub_header = EditorHeaderType.FOLDOUT_ENABLED_BOLD; EditorGUI.BeginDisabledGroup(_rule.Enabled == false); // WEIGHTEDRANDOM BEGIN if (_list.Count > 1 && _mode.RulesOrderType == SequenceOrderType.WEIGHTEDRANDOM) { _rule.Weight = ICEEditorLayout.DefaultSlider("Weight", "Weight Value for WEIGHTEDRANDOM Sequence Type, relative to other rules weight value", _rule.Weight, Init.DECIMAL_PRECISION, 0, 100, 1, Info.BEHAVIOUR_MODE_RULE_WEIGHT); } // WEIGHTEDRANDOM END EditorGUI.indentLevel++; // CUSTOM LENGTH BEGIN if (_list.Count > 1 || _rule.Link.Enabled) { DrawBehaviourCustomLength(_control, _rule, _header); } // CUSTOM LENGTH END CreatureBehaviourEditor.DrawBehaviourAnimation(_control, _mode, _rule, _header); CreatureBehaviourEditor.DrawBehaviourMove(_control, _mode, _rule, _header); CreatureObjectEditor.DrawInfluenceObject(_mode, _rule.Influences, _header, _control.Creature.Status.UseAdvanced, _control.Creature.Status.InitialDurabilityMax, Info.BEHAVIOUR_INFLUENCES); CreatureObjectEditor.DrawInventoryActionObject(_control, _rule.Inventory, _header, Info.BEHAVIOUR_INVENTORY); CreatureObjectEditor.DrawAudioObject(_rule.Audio, _header, Info.BEHAVIOUR_AUDIO); CreatureObjectEditor.DrawEventsObject(_control, _rule.Events, _header, _sub_header, Info.BEHAVIOUR_EVENTS); CreatureObjectEditor.DrawLookDataObject(_rule.Look, _header, Info.BEHAVIOUR_LOOK); CreatureObjectEditor.DrawEffectObject(_control, _rule.Effect, _header, Info.BEHAVIOUR_EFFECT); CreatureBehaviourEditor.DrawBehaviourModeRuleLinkObject(_control, _list, _rule.Link, _header, Info.BEHAVIOUR_LINK, "", "", _key + "_" + _index); EditorGUILayout.Separator(); EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; } if (_list.Count > 1) { EditorGUI.indentLevel--; } }
/// <summary> /// Draws a behaviour mode. /// </summary> /// <param name="_mode">_mode.</param> /// <param name="_index">_index.</param> public static bool DrawBehaviourMode(ICECreatureControl _control, BehaviourModeObject _mode, bool _editor = false) { if (_mode == null) { return(false); } int _indent = EditorGUI.indentLevel; if (_editor) { EditorGUILayout.Separator(); _mode.Foldout = true; EditorGUI.indentLevel = 1; } else { ICEEditorStyle.SplitterByIndent(EditorGUI.indentLevel); } string _title = _mode.Key + " (" + _mode.Rules.Count + (_mode.Rules.Count == 1?" Rule)":" Rules)"); ICEEditorLayout.BeginHorizontal(); if (_editor) { EditorGUILayout.PrefixLabel(_title, "Button", EditorStyles.boldLabel); } else { _mode.Foldout = ICEEditorLayout.Foldout(_mode.Foldout, _title); } GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(m_BehaviourRenameMode == _mode); if (ICEEditorLayout.Button("RENAME")) { m_BehaviourRenameKey = _mode.Key; m_BehaviourRenameMode = _mode; } EditorGUI.EndDisabledGroup(); GUILayout.Space(5); if (ICEEditorLayout.SaveButtonSmall("Saves selected behaviour mode to file.")) { CreatureEditorIO.SaveBehaviourModeToFile(_mode, _control.name + "_" + _mode.Key); } if (ICEEditorLayout.LoadButtonSmall("Loads a behaviour mode from file.")) { _mode.Copy(CreatureEditorIO.LoadBehaviourModeFromFile(new BehaviourModeObject())); } if (ICEEditorLayout.CopyButtonSmall("Creates a copy of the selected behaviour mode.")) { _control.Creature.Behaviour.CopyBehaviourMode(_mode); } if (ICEEditorLayout.ResetButtonSmall("Resets the selected behaviour mode.")) { _mode.Copy(new BehaviourModeObject(_mode.Key)); } //EditorGUI.EndDisabledGroup(); GUILayout.Space(5); if (ICEEditorLayout.ListDeleteButton <BehaviourModeObject>(_control.Creature.Behaviour.BehaviourModes, _mode, "Removes selected behaviour mode.")) { return(true); } GUILayout.Space(5); if (ICEEditorLayout.ListUpDownButtons <BehaviourModeObject>(_control.Creature.Behaviour.BehaviourModes, _control.Creature.Behaviour.BehaviourModes.IndexOf(_mode))) { return(true); } EditorGUI.BeginDisabledGroup(_mode.Rules.Count < 2); ICEEditorLayout.ListFoldoutButtonsMini(_mode.Rules); EditorGUI.EndDisabledGroup(); GUILayout.Space(3); ICEEditorLayout.EndHorizontal(ref _mode.ShowInfoText, ref _mode.InfoText, Info.BEHAVIOUR_MODE); RenameBehaviourMode(_control, _mode); //EditorGUILayout.Separator(); if (_mode.Foldout) { DrawBehaviourModeContent(_control, _mode); } if (_editor) { EditorGUI.indentLevel = _indent; } return(false); }