Exemple #1
0
 public HouseBuildJob(float time, PositionScript position, int number)
 {
     fullTime = timeLeft = time;
     this.position = position;
     houseNumber = number;
     tile = position.EnterTile - position.ToUp.normalized;
 }
 // Use this for initialization
 void OnEnable() {
     lackOrderList = new List<Order>();
     overOrderList = new List<Order>();
     resourceList = new Dictionary<Resource, int>();
     reservedResources = new Dictionary<Resource, int>();
     position = GetComponent<PositionScript>();
     
 }
	public void AddHouseJob(float time, PositionScript position, int number) {
        HouseBuildJob job = new HouseBuildJob(time, position, number);
        houseBuildQueue.Add(job);
        List<Vector2> tiles = position.GetTiles();
        foreach (Vector2 curr in tiles)
        {
            busyTiles.Add(curr, job);
        }
    }
Exemple #4
0
 // Use this for initialization
 void Start() {
     //GameObject gameScript = GameObject.Find("GameScript");
     name = "Ghost";
     renderer = GetComponentInChildren<Renderer>();
     renderer.material = BuildMode.Instance.ghostGreen;
     renderer.receiveShadows = false;
     gameObject.layer = LayerMask.NameToLayer("Ghost");
     renderer.gameObject.layer = LayerMask.NameToLayer("Ghost");
     positionScript = GetComponent<PositionScript>();
     leftCorner = positionScript.LeftCorner();
     jobInfo = GetComponent<JobInfo>();
     MouseController.Instance.RegisterTileChanged(ChangePosition);
     MouseController.Instance.ghost = this;
     MouseController.Instance.TurnOnHouseMode();
 }
Exemple #5
0
 public static ResourceAgent lookForAgent(PositionScript pos, Resource resource)
 {
     ResourceAgent[] agentList = pos.GetComponents<ResourceAgent>();
     if (agentList.Length == 0)
     {
         return null;
     }
     foreach (ResourceAgent ra in agentList)
     {
         if (ra.myRes == resource)
         {
             return ra;
         }
     }
     Debug.LogError("No suitable ResourceAgent found");
     return null;
 }
Exemple #6
0
    //改變位置
    private IEnumerator ChangePositionEnumerator(PositionScript info)
    {
        bool  playing     = true;
        float timer       = 0;                     //計時器
        float endTime     = info.GetEndTime();     //動畫結束時間
        float denominator = info.GetDenominator(); //動畫進度分母

        bool worldOrLocal = info.worldOrLocal;     //世界座標or本地座標

        Vector3[] alteration = new Vector3[2] {
            info.insOutsPositions.Length == 2 ? info.insOutsPositions[0] : (worldOrLocal ? this.transform.position : this.transform.localPosition), info.insOutsPositions[info.insOutsPositions.Length - 1]
        };
        info.insOutsPositions = alteration;

        while (playing) //變化過程
        {
            timer = timer + Time.fixedDeltaTime > endTime ? endTime : timer + Time.fixedDeltaTime;

            float x = alteration[0].x + ((alteration[1].x - alteration[0].x) * (info.GetNumerator(timer) / denominator));
            float y = alteration[0].y + ((alteration[1].y - alteration[0].y) * (info.GetNumerator(timer) / denominator));
            float z = alteration[0].z + ((alteration[1].z - alteration[0].z) * (info.GetNumerator(timer) / denominator));
            if (worldOrLocal)
            {
                this.transform.position = new Vector3(x, y, z);
            }
            else
            {
                this.transform.localPosition = new Vector3(x, y, z);
            }

            if (timer == endTime)
            {
                playing = false;
            }
            yield return(new WaitForFixedUpdate());
        }

        info.isPlaying = false;

        yield return(null);
    }
Exemple #7
0
 public void SynchronizePosition(PositionScript another)
 {
     
     enterTile = another.enterTile;
     upTile = another.upTile;
     Debug.Log("SynchronizePosition: Enter tile " + enterTile);
 }
 public void InstantiateHouse(int number, PositionScript position)
 {
     GameObject newHouse = Instantiate(BuildMode.Instance.objects[number]) as GameObject;
     newHouse.gameObject.name = BuildMode.Instance.objects[number].name;
     newHouse.GetComponent<PositionScript>().SynchronizePosition(position);
     
     Vector2 coord = position.EnterTile;
     Vector3 coordCenter = new Vector3(coord.x + MapController.TILE_SIZE / 2, MapController.Instance.mapData.GetHeight(coord), coord.y + MapController.TILE_SIZE / 2);
     newHouse.transform.position = coordCenter;
     Vector3 forward = new Vector3(position.ToUp.x, 0f, position.ToUp.y);
     newHouse.transform.rotation = Quaternion.LookRotation(forward);
     if (number == BuildMode.Instance.storeNumber)
     {
         player.AddStore(newHouse.GetComponent<ResourceController>());
         Debug.Log("InstantiateHouse: Added store to storeList. Is it null? " + (newHouse.GetComponent<ResourceController>() == null).ToString());
     } else
     {
         
         player.AddHouse(newHouse.GetComponent<House>());
         //Debug.Log("InstantiateHouse: School " + (sc == null).ToString());
         //Debug.Log("InstantiateHouse: resAg " + (sc.resourceAgent == null).ToString());
     }
     
     newHouse.GetComponent<House>().OnBuild();
     Debug.Log("InstantiateHouse " + newHouse.GetComponent<PositionScript>().enterTile);
 }
Exemple #9
0
 public Order(Resource resource, PositionScript position)
 {
     this.resource = resource;
     this.position = position;
 }
Exemple #10
0
 public DeliveryJob(Resource res, PositionScript start, PositionScript end)
 {
     this.resource = res;
     this.startPosition = start;
     this.endPosition = end;
 }
 private void CreateExploration(int kid, PositionScript birth, List<object> paramList = null)
 {
     if (birth != null)
     {
         Exploration expl = ExplorationFactory.Create(kid, paramList);
         expl.SetPosition(birth.transform.position);
         expl.SetRotation(birth.transform.eulerAngles.y);
         explorationProxy.AddInHall(expl);
     }
 }