예제 #1
0
 public void SaveToDatabase()
 {
     if (Death.ValidValues())
     {
         Death.CreateDeath();
         MessageBox.Show("Záznam vytvořen.");
         AnimalModel.AnimalDied((int)AnimalID);
         if (Prnt != null)
         {
             Prnt.IsWorking = false;
         }
         if (Prnt1 != null)
         {
             Prnt1.IsWorking = false;
             Prnt1.FilterDeaths();
         }
         TryClose();
     }
     else
     {
         MessageBox.Show("Vyplňte prosím platné ID zvířete.");
     }
 }
        /// <summary>
        /// Draw all the window graphics.
        /// </summary>
        private void OnGUI()
        {
            //GUI.DrawTexture(new Rect(0,0,350,100), _unitFactoryLogo);
            //Space(15);
            Tip("Create new Agent here giving some general idea of his \nparameters." +
                "You can always adjust them in the inspector \nof already created Agent.");
            Space();

            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
            Header("General");
            _name   = EditorGUILayout.TextField("Agent's name: ", _name);
            _team   = EditorGUILayout.TextField("Team: ", _team);
            _weight = EditorGUILayout.FloatField("Weight: ", _weight);
            Space(2);
            Header("Perception");
            _seeDistance    = EditorGUILayout.FloatField("Perception range:", _seeDistance);
            _seeFOV         = EditorGUILayout.FloatField("Field of view: ", _seeFOV);
            _seeResolution  = (UnitFactoryOptions)EditorGUILayout.EnumPopup("Accuracy of perception: ", _seeResolution);
            _memoryDuration = EditorGUILayout.IntField("Memory duration: ", _memoryDuration);
            Space(2);
            Header("Motion");
            _motionEngine = (MotionEngine)EditorGUILayout.EnumPopup("Motion engine: ", _motionEngine);
            //_canMove = EditorGUILayout.Toggle("Should it move?", _canMove);
            _moveSpeed = (UnitFactoryOptions)EditorGUILayout.EnumPopup("Move speed: ", _moveSpeed);
            _canRun    = EditorGUILayout.Toggle("Can it run?", _canRun);
            _canDodge  = EditorGUILayout.Toggle("Can it dodge?", _canDodge);
            Space(2);
            Header("Resources");
            _isMortal = EditorGUILayout.Toggle("Is it mortal?", _isMortal);
            if (_isMortal)
            {
                _maxHealth = EditorGUILayout.IntField("Health capacity: ", _maxHealth);
            }
            _useEnergy = EditorGUILayout.Toggle("Does it use energy?", _useEnergy);
            if (_useEnergy)
            {
                _maxEnergy = EditorGUILayout.IntField("Energy capacity: ", _maxEnergy);
            }
            Space(2);
            Header("Other");
            _graphics  = (GameObject)EditorGUILayout.ObjectField("Graphics: ", _graphics, typeof(GameObject), false);
            _ragdoll   = (GameObject)EditorGUILayout.ObjectField("Ragdoll: ", _ragdoll, typeof(GameObject), false);
            _behaviour = (EliotBehaviour)EditorGUILayout.ObjectField("Behaviour: ", _behaviour, typeof(EliotBehaviour), false);
            _waypoints = (WaypointsGroup)EditorGUILayout.ObjectField("Waypoints: ", _waypoints, typeof(WaypointsGroup), true);
            Space(2);
            Header("Skills");
            if (_skills.Count > 0)
            {
                for (var i = _skills.Count - 1; i >= 0; i--)
                {
                    EditorGUILayout.BeginHorizontal();
                    _skills[i] = (Skill)EditorGUILayout.ObjectField(_skills[i], typeof(Skill), false);
                    if (GUILayout.Button("Remove"))
                    {
                        _skills.RemoveAt(i);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            if (GUILayout.Button("Add skill"))
            {
                _skills.Add(null);
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Create"))
            {
                //Resources
                var resources = Resources.CreateResources(_isMortal, _maxHealth, _useEnergy, _maxEnergy);

                //Memory
                var memory = Memory.CreateMemory(_memoryDuration);

                //See
                var resolution = 0;
                switch (_seeResolution)
                {
                case UnitFactoryOptions.Low: resolution = 7; break;

                case UnitFactoryOptions.Medium: resolution = 15; break;

                case UnitFactoryOptions.High: resolution = 35; break;
                }
                var perception = Perception.CreatePerception(_seeDistance, _seeFOV, resolution);

                //Move
                var speed = 0f;
                switch (_moveSpeed)
                {
                case UnitFactoryOptions.Low: speed = 1.5f; break;

                case UnitFactoryOptions.Medium: speed = 3f; break;

                case UnitFactoryOptions.High: speed = 5f; break;
                }
                var motion = Motion.CreateMotion(_motionEngine, speed, _canRun, _canDodge);
                motion.Weight = _weight;

                //Death
                var death = Death.CreateDeath(_ragdoll);

                //Settings
                var stats = Settings.CreateSettings();

                var newAgent = Agent.CreateAgent(_name, resources, memory, perception, motion, death, stats, _skills, _graphics);
                newAgent.Behaviour = _behaviour;
                newAgent.GetComponent <Unit>().Team = _team;
                newAgent.Waypoints          = _waypoints;
                newAgent.transform.position = SceneView.lastActiveSceneView.pivot;

                Selection.activeObject = newAgent;
            }
            EditorGUILayout.EndScrollView();
        }