示例#1
0
        public Unit Load(UnitPrefab a_prefab, Vector3 a_pos, Vector3 a_rot)
        {
            // Properties
            Unit.Properties properties = new Unit.Properties();
            properties.pos = a_pos;
            properties.rot = a_rot;
            properties.health = a_prefab.health;
            properties.buildTime = a_prefab.buildTime;
            properties.cost = a_prefab.cost;
            properties.miniSize = a_prefab.miniMapSize;
            properties.ID = a_prefab.ID;
            properties.turnSpeed = a_prefab.turnSpeed;
            properties.speed = a_prefab.speed;
            properties.accel = a_prefab.accel;

            // Type
            Unit unit = null;
            switch (a_prefab.type)
            {
                case Unit.Type.DOZER:
                    unit = new Dozer(properties, a_prefab.model, a_prefab.texture);
                    break;

                //case Unit.Type.INFANTRY:
                    //unit = new Infantry(properties, a_prefab.model, a_prefab.texture);
                    //break;

                default:
                    unit = new Unit(properties, a_prefab.model, a_prefab.texture);
                    break;
            }

            return unit;
        }
示例#2
0
        public static void SavePlayerUnits(JsonWriter writer, Unit[] units)
        {
            if (writer == null) return;

            writer.WritePropertyName("Units");
            writer.WriteStartArray();
            foreach (Unit unit in units) {
                SaveWorldObject(writer, unit);
            }
            writer.WriteEndArray();
        }
示例#3
0
文件: Input.cs 项目: JJJohan/RTS
 // Select spawn unit
 public static void SpawnSelect(ref Unit a_unit)
 {
     a_unit.Select();
     m_selected.Add(a_unit);
     m_selectionType = Selection.UNIT;
     m_cursorMode = Cursor.ORDER;
 }
示例#4
0
 public static Building findClosestResourceStore(Building[] validBuildings, Unit unit)
 {
     Vector3 unitPosition = unit.gameObject.transform.position;
     float closestBuildingDistance = 0.0f;
     Building closestBuilding = null;
     for (int i = 0; i < validBuildings.Length; i++) {
         if (validBuildings[i]) {
             float distance = Vector3.Distance(unitPosition, validBuildings[i].gameObject.transform.position);
             if (closestBuilding) {
                 if (distance < closestBuildingDistance) {
                     closestBuilding = validBuildings[i];
                     closestBuildingDistance = distance;
                 }
             } else {
                 closestBuilding = validBuildings[i];
                 closestBuildingDistance = distance;
             }
         } else {
             break;
         }
     }
     return closestBuilding;
 }
 public override void DamageTaken(Unit Attacker)
 {
     ChargeTarget(Attacker, "DamageTaken");
 }