Exemple #1
0
    private void Awake()
    {
        waypointsGroup = GetComponent <WaypointsGroup>();

        //Spawn soldiers
        for (int i = 0; i < soldierCounts.Count; i++)
        {
            for (int sc = 0; sc < soldierCounts[i].count; sc++)
            {
                Soldier soldier = Instantiate(soldierCounts[i].soldier, transform.position + (transform.rotation * GetPositionInFormation(soldiers.Count, soldierCounts.Sum(s => s.count))), transform.rotation);
                soldier.squad = this;
                soldier.Team  = team;
                soldier.name += " " + sc;
                soldiers.Add(soldier);
            }
        }

        //Update target position and formation
        if (waypointsGroup.waypoints.Count > 0)
        {
            transform.position = waypointsGroup.waypoints[0].GetPosition();
            if (waypointsGroup.waypoints.Count > 1)
            {
                transform.forward = waypointsGroup.waypoints[1].GetPosition() - transform.position;
            }
        }
        SetTargetPosition(transform.position, new Vector2(transform.forward.x, transform.forward.z));
    }
Exemple #2
0
        /// <summary>
        /// Apply changes to Agent component according to Waypoint's settings.
        /// </summary>
        /// <param name="waypoint"></param>
        public void SetWaypointChanges(Waypoint waypoint)
        {
            // But do it only if both Waypoint and Agent agree to do the change.
            if (!_applyChangesOnWaypoints)
            {
                return;
            }
            if (!waypoint.MakeChangesToAgent)
            {
                return;
            }

            if (waypoint.NewBehaviour)
            {
                SetBehaviour(waypoint.NewBehaviour);
            }
            if (waypoint.NewWaypoints)
            {
                _waypoints = waypoint.NewWaypoints;
            }
        }
        /// <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();
        }
Exemple #4
0
 private void OnEnable()
 {
     waypointsGroup = target as WaypointsGroup;
     waypoints      = waypointsGroup.GetWaypointChildren();
 }