public static void AddObject(HouseHoldItem_monobehaviour obj) { if (!allObjects.Contains(obj)) { allObjects.Add(obj); } }
public static void RemoveObject(HouseHoldItem_monobehaviour obj) { if (allObjects.Contains(obj)) { allObjects.Remove(obj); } }
public void Upgrade() { var interacting = CanvasUI_Main_cs.GetInteracting(); var h = interacting.HouseHoldItemData; if (interacting != null && interacting.HouseHoldItemData.Upgrade != null) { MainGameManager.Cash -= interacting.HouseHoldItemData.upgradeCost; Vector3 p = interacting.transform.position; Quaternion r = interacting.transform.rotation; bool canMove = interacting.CanMove, canDelete = interacting.CanDelete; GameObject.Destroy(interacting.gameObject); GameObject obj = GameObject.Instantiate(h.Upgrade.prefab); obj.name = h.Upgrade.name; obj.transform.position = p; obj.transform.rotation = r; var placementObj = obj.AddComponent <PlacementObject>(); Vector2 wd = CalculateWidthAndDepth(h.Upgrade); placementObj.width = wd.x; placementObj.depth = wd.y; var houseHoldItem = obj.AddComponent <HouseHoldItem_monobehaviour>(); houseHoldItem.SetHouseHoldItemDataID(h.Upgrade.ID); houseHoldItem.CanMove = canMove; houseHoldItem.CanDelete = canDelete; _this.currently_buying = houseHoldItem; _this.currentlyPlacing = placementObj; var transforms = currently_buying.gameObject.GetComponentsInChildren <Transform>(); foreach (var t in transforms) { if (t.GetComponent <MeshCollider>() == null) { var collider = t.gameObject.AddComponent <MeshCollider>(); collider.sharedMesh = t.gameObject.GetComponent <MeshFilter>().sharedMesh; collider.convex = true; } } currently_buying = null; currentlyPlacing = null; CanvasUI_Main_cs.RequestCloseUpgrade(); } }
public static void SetInteracting(HouseHoldItem_monobehaviour m) { if (m != _this.interactionAndUpgradeOptions.interacting) { _this.interactionAndUpgradeOptions.interacting = m; if (m != null) { _this.OpenInteraction(); } else { _this.CloseInteraction(); _this.CloseUpgrade(); } } }
private IEnumerator MoveCoroutine(HouseHoldItem_monobehaviour m, PlacementObject o) { var wait = new WaitForEndOfFrame(); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); Vector3 startPos = m.transform.position; Quaternion startRot = m.transform.rotation; string axis = "Fire1"; string rotateAxis = "Horizontal"; float rotateSpeed = 90f; float placementHelpOffset = -100; placementHelp.transform.position = CameraControl.RootPosition + new Vector3(0, placementHelpOffset, 0); float inpWas = Input.GetAxis(axis); do { if (Input.GetAxis("Cancel") > 0) { m.transform.position = startPos; m.transform.rotation = startRot; m.visualMaterial = HouseHoldItem_monobehaviour.VisualMaterial.normalMaterial; OptionsMenu.PreventOpening(); break; } m.transform.Rotate(Vector3.up * Input.GetAxis(rotateAxis) * rotateSpeed * Time.smoothDeltaTime); if (stopwatch.ElapsedMilliseconds >= 5) { var cameraRay = CameraControl.Camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Vector3 placementPos = m.transform.position; if (placementHelp.Raycast(new Ray(cameraRay.origin + new Vector3(0, placementHelpOffset, 0), cameraRay.direction), out hit, Mathf.Abs(1000 * placementHelpOffset))) { placementPos = hit.point + new Vector3(0, -placementHelpOffset, 0); } var placementDots = PlacementManager.GetPlacementDots(placementPos, m.transform.rotation, o.width, o.depth); if (placementDots.Count > 0) { m.transform.position = placementPos; } var canPlace = PlacementManager.CanPlace(placementDots); m.visualMaterial = canPlace ? HouseHoldItem_monobehaviour.VisualMaterial.canPlace : HouseHoldItem_monobehaviour.VisualMaterial.cannotPlace; if (inpWas >= 0.5f && Input.GetAxis(axis) < 0.5f && !CanvasUI_Main_cs.EventSystem.IsPointerOverGameObject()) { if (canPlace) { o.SetUsedDots(placementDots); m.visualMaterial = HouseHoldItem_monobehaviour.VisualMaterial.normalMaterial; AudioEffectManager.Play(AudioEffectManager.Instance.objectPlaced); break; } } stopwatch.Reset(); stopwatch.Start(); } inpWas = Input.GetAxis(axis); yield return(wait); }while (m != null && o != null); }
public static void Move(HouseHoldItem_monobehaviour m, PlacementObject o) { CanvasUI_Main_cs.RequestCloseInteraction(); _this.StartCoroutine(_this.MoveCoroutine(m, o)); }
private IEnumerator BuyCoroutine() { var wait = new WaitForEndOfFrame(); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); string axis = "Fire1"; string rotateAxis = "Horizontal"; float rotateSpeed = 90f; float placementHelpOffset = -100; placementHelp.transform.position = CameraControl.RootPosition + new Vector3(0, placementHelpOffset, 0); float inpWas = Input.GetAxis(axis); do { if (Input.GetAxis("Cancel") > 0) { ShopManager.CancelBuy(); OptionsMenu.PreventOpening(); break; } currently_buying.transform.Rotate(Vector3.up * Input.GetAxis(rotateAxis) * rotateSpeed * Time.smoothDeltaTime); if (stopwatch.ElapsedMilliseconds >= 5) { var cameraRay = CameraControl.Camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Vector3 placementPos = currently_buying.transform.position; if (placementHelp.Raycast(new Ray(cameraRay.origin + new Vector3(0, placementHelpOffset, 0), cameraRay.direction), out hit, Mathf.Abs(1000 * placementHelpOffset))) { placementPos = hit.point + new Vector3(0, -placementHelpOffset, 0); } var placementDots = PlacementManager.GetPlacementDots(placementPos, currently_buying.transform.rotation, currentlyPlacing.width, currentlyPlacing.depth); if (placementDots.Count > 0) { currently_buying.transform.position = placementPos; } var canPlace = PlacementManager.CanPlace(placementDots); currently_buying.visualMaterial = canPlace ? HouseHoldItem_monobehaviour.VisualMaterial.canPlace : HouseHoldItem_monobehaviour.VisualMaterial.cannotPlace; if (inpWas >= 0.5f && Input.GetAxis(axis) < 0.5f && !CanvasUI_Main_cs.EventSystem.IsPointerOverGameObject()) { if (canPlace) { MainGameManager.Cash -= currently_buying.HouseHoldItemData.purchaseCost; currentlyPlacing.SetUsedDots(placementDots); currently_buying.visualMaterial = HouseHoldItem_monobehaviour.VisualMaterial.normalMaterial; var transforms = currently_buying.gameObject.GetComponentsInChildren <Transform>(); foreach (var t in transforms) { if (t.GetComponent <MeshCollider>() == null) { var collider = t.gameObject.AddComponent <MeshCollider>(); collider.sharedMesh = t.gameObject.GetComponent <MeshFilter>().sharedMesh; collider.convex = true; } } AudioEffectManager.Play(AudioEffectManager.Instance.objectBuy); currently_buying = null; currentlyPlacing = null; break; } } stopwatch.Reset(); stopwatch.Start(); } inpWas = Input.GetAxis(axis); yield return(wait); }while (currently_buying != null); }
public static float CalculateEnergyCosts() { float ret = 0; foreach (var o in allObjects) { o.HouseHoldItemData.Alert(Data); o.ResetInfluence(); } if (allObjects.Count > 0) { HouseHoldItem_monobehaviour currObject = allObjects[0]; for (int i = 0; i < allObjects.Count; i++, currObject = (allObjects.Count > i ? allObjects[i] : null)) { if (currObject == null) { continue; } var affectedObjects = currObject.HouseHoldItemData.affectedObjects; List <int> affectedIDs = new List <int>(); foreach (var aO in affectedObjects) { affectedIDs.Add(aO.affectedObjectId); } HouseHoldItem_monobehaviour otherObject = allObjects[0]; for (int o = 0; o < allObjects.Count; o++, otherObject = (allObjects.Count > o ? allObjects[o] : null)) { if (currObject != otherObject && otherObject != null) { if (affectedIDs.Contains(otherObject.HouseHoldItemData.ID)) { var effect = affectedObjects[affectedIDs.IndexOf(otherObject.HouseHoldItemData.ID)]; if (Vector3.Distance(currObject.transform.position, otherObject.transform.position) <= effect.effectRadius) { switch (CurrentSeason) { case Season.Summer: otherObject.AddInfluence(effect.summerElectricityPercentage); break; case Season.Fall: otherObject.AddInfluence(effect.fallElectricityPercentage); break; case Season.Winter: otherObject.AddInfluence(effect.winterElectricityPercentage); break; case Season.Spring: otherObject.AddInfluence(effect.springElectricityPercentage); break; } } } } } } foreach (var o in allObjects) { ret += o.CalculateTotalEnergyCost(); } } MonoBehaviour.print("This seasons energy cost: " + ret); return(ret); }