public void BroadcastItemAdd(Pickupable pickupable, Transform containerTransform) { NitroxId itemId = NitroxEntity.GetId(pickupable.gameObject); byte[] bytes = SerializationHelper.GetBytesWithoutParent(pickupable.gameObject); NitroxId ownerId = InventoryContainerHelper.GetOwnerId(containerTransform); ItemData itemData; Plantable plant = pickupable.GetComponent <Plantable>(); if (plant && plant.currentPlanter) { // special case: we want to remember the time when the plant was added, so we can simulate growth itemData = new PlantableItemData(ownerId, itemId, bytes, DayNightCycle.main.timePassedAsDouble); } else { itemData = new ItemData(ownerId, itemId, bytes); } if (packetSender.Send(new ItemContainerAdd(itemData))) { Log.Debug($"Sent: Added item {pickupable.GetTechType()} to container {containerTransform.gameObject.GetHierarchyPath()}"); } }
private static GrowingPlant GetGrowingPlant(Plantable plantable) { int slot = plantable.GetSlotID(); Planter planter = plantable.currentPlanter; if (!planter) { Log.Error($"GetGrowingPlant: plant not inside a Planter!"); return(null); } // int smallSlotCount = pp.slots.Length; int bigSlotCount = planter.bigSlots.Length; // for all the planters I have seen, the logic is the same: Available slots are numbered starting with the big slots if (slot < bigSlotCount) { // index 0 .. #big-1 return(planter.bigSlots[slot].GetComponentInChildren <GrowingPlant>()); } else { // index #big .. #big+#small-1 return(planter.slots[slot - bigSlotCount].GetComponentInChildren <GrowingPlant>()); } }
public void PlantSaveTest() { var planteableObj_2 = Object.Instantiate(planteableObj); Plantable plant_2 = planteableObj_2.GetComponent <Plantable>(); Assert.AreEqual(SectionData.Current.PlantDatas.Count, 0); plant.Save(); Assert.AreEqual(SectionData.Current.PlantDatas.Count, 1); plant.Save(); // because SaveData contains the plant already, saving it should not add it again. Assert.AreEqual(SectionData.Current.PlantDatas.Count, 1); plant_2.Save(); Assert.AreEqual(SectionData.Current.PlantDatas.Count, 2); plant.Grow(completeGrowth); plant.OnHarvest(ToolTypes.Sickle, null); // after harvesting the plant should no longer be saved. Assert.AreEqual(SectionData.Current.PlantDatas.Count, 1); plant_2.Grow(completeGrowth); plant_2.OnHarvest(ToolTypes.Sickle, null); Assert.AreEqual(SectionData.Current.PlantDatas.Count, 0); }
public IEnumerator HarvestTest() { // load the test scene EditorSceneManager.LoadSceneInPlayMode ( "Assets/Resources/Scenes/Test_Scene.unity", new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.Physics2D) ); yield return(TestUtilities.AssertSceneLoaded("Assets/Resources/Scenes/Test_Scene.unity")); Inventory inventory = Object.FindObjectOfType <Inventory>(); NodeGrid grid = Object.FindObjectOfType <NodeGrid>(); LoadingOrder loadingOrder = Object.FindObjectOfType <LoadingOrder>(); ItemType itemType = Resources.Load("SO/Potato") as ItemType; // wait till grid is loaded while (!grid.LoadedSection) { yield return(null); } // wait till all data is loaded while (!loadingOrder.LoadedAll) { yield return(null); } if (itemType == null) { Debug.LogError("There is no ItemType scriptable object at path: SO/Potato"); } // get the node we are going to plant on Node nodeToPlant = grid.GetNodeFromXY(0, 0); // plant the prefab bool succesfulPlanting = false; nodeToPlant.Interactable.OnInteract(ToolTypes.Hoe); nodeToPlant.Interactable.OnInteract(ToolTypes.Other, prefab, () => succesfulPlanting = true); Assert.IsTrue(succesfulPlanting); // get the single plant we made in this scene Plantable plant = Object.FindObjectOfType <Plantable>(); // Harvest the plant plant.Grow(completeGrowth); plant.OnHarvest(ToolTypes.Sickle, null); // check if the items dropped WorldItem[] worldItems = Object.FindObjectsOfType <WorldItem>(); Assert.IsTrue(worldItems.Length >= 2 && worldItems.Length <= 5); yield return(null); // plant object should be destroyed Assert.IsTrue(plant == null); }
/// <summary> /// 批复工作计划 /// </summary> /// <param name="id">工作计划ID</param> /// <param name="issue">批复意见(非必填)</param> /// <param name="state">工作计划状态 0:等待审核,1:已通过,2:等待修正,3:已修正,4:已驳回</param> public void ReplyWorkPlan(int id, string issue, uint state) { Plantable plantable = plantableRepository.Query(id); plantable.State = state; if (!string.IsNullOrEmpty(issue)) //issue非必填,有内容再修改 { plantable.Issue = issue; } plantableRepository.Update(plantable); }
public static void Postfix(GameObject __result, Plantable __instance) { //if(!__instance.model.name.Equals("Coral_reef_purple_mushrooms_01_04(Clone)") || // !__instance.model.name.Equals("Coral_reef_jelly_plant_01_01(Clone)") || // !__instance.model.name.Equals("Coral_reef_small_blue_fans_01_01(Clone)")) //{} __result.transform.localRotation = Quaternion.Euler(__result.transform.localRotation.x, UnityEngine.Random.Range(0, 360), __result.transform.localRotation.z); ///ErrorMessage.AddMessage("Plant spawned "+__instance.model.name+" Tag: "+__result.tag.ToString()); }
public void SetUp() { if (prefab == null) { Debug.LogError("There is no unit test prefab at path: Prefabs/UnitTests/PotatoUnitTest"); } prefab.transform.position = Vector3.zero; planteableObj = Object.Instantiate(prefab); plant = planteableObj.GetComponent <Plantable>(); }
public void Upload(string fileAddress, string fileName, string teacherId, string issue) { using (oaContext context = new oaContext()) { Plantable upload = new Plantable(); upload.Filepath = fileAddress; upload.Filename = fileName; upload.Teacherid = teacherId; upload.Committime = DateTime.Now; upload.Issue = issue; context.Plantable.Add(upload); context.SaveChanges(); } }
public void OnProtoSerialize(ProtobufSerializer serializer) { #if DEBUG_COVE_TREE Logger.Log("DEBUG: OnProtoSerialize covetree: Entry"); #endif // Retrieve prefab unique ID PrefabIdentifier id = GetComponentInParent <PrefabIdentifier>(); if (id == null) { if ((id = GetComponent <PrefabIdentifier>()) == null) { return; } } #if DEBUG_COVE_TREE Logger.Log("DEBUG: OnProtoSerialize covetree: Get save folder"); #endif string saveFolder = FilesHelper.GetSaveFolderPath(); if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } Plantable plant = this.gameObject.GetComponent <Plantable>(); GrownPlant grownPlant = this.gameObject.GetComponent <GrownPlant>(); if (grownPlant == null && plant != null && plant.linkedGrownPlant != null) { grownPlant = plant.linkedGrownPlant; } if (grownPlant != null) { GameObject eggs = grownPlant.gameObject.FindChild("lost_river_cove_tree_01").FindChild("lost_river_cove_tree_01_eggs"); #if DEBUG_COVE_TREE Logger.Log("DEBUG: OnProtoSerialize covetree: Found grown plant. Eggs active=[" + eggs.activeSelf + "]"); #endif File.WriteAllText(FilesHelper.Combine(saveFolder, "covetree_" + id.Id + ".txt"), eggs.activeSelf ? "1" : "0", Encoding.UTF8); } #if DEBUG_COVE_TREE else { Logger.Log("DEBUG: OnProtoSerialize covetree: Cannot find grown plant"); } #endif }
public override void process(GameObject item, ItemData itemData) { PlantableItemData plantableData = itemData as PlantableItemData; if (plantableData == null) { // nothing to do; false alarm return; } Plantable plant = item.GetComponent <Plantable>(); if (plant == null) { Log.Error($"FixPlantGrowth: Item for Plantable {plantableData.ItemId} is not a Plantable!"); return; } GrowingPlant grower = GetGrowingPlant(plant); if (grower == null) { Log.Error($"FixPlantGrowth: Could not find GrowingPlant for Plantable {plantableData.ItemId}!"); return; } // time in seconds double elapsedGrowthTime = (DayNightCycle.main.timePassedAsDouble - plantableData.PlantedGameTime); if (elapsedGrowthTime > grower.growthDuration) { // should be ready Log.Debug($"FixPlantGrowth: Finishing {item.name} {plantableData.ItemId} that has grown for {elapsedGrowthTime} seconds"); grower.SetProgress(1.0f); } else { Log.Debug($"FixPlantGrowth: Growing {item.name} {plantableData.ItemId} that has grown for {elapsedGrowthTime} seconds"); grower.SetProgress(Convert.ToSingle(elapsedGrowthTime / grower.growthDuration)); } }
public void Update() { #if (DEBUG_FLORA || DEBUG_FLORA_ENTRY || DEBUG_FLORA_ANIMATION) PrefabIdentifier id = GetComponent <PrefabIdentifier>(); #endif #if DEBUG_FLORA_ENTRY if (id != null) { Logger.Log("DEBUG: Entering PlantGenericController.Update() for gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); } else { Logger.Log("DEBUG: Entering PlantGenericController.Update() for gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); } #endif if (_plant == null) { _plant = GetComponent <Plantable>(); } if (_grownPlant == null) { _grownPlant = GetComponent <GrownPlant>(); } if (_grownPlant == null && _plant != null) { if (_plant.linkedGrownPlant != null) { #if DEBUG_FLORA Logger.Log("DEBUG: PlantGenericController.Update() Associating grown plant in gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); #endif _grownPlant = _plant.linkedGrownPlant; _grownPlant.seed = _plant; } } if (_grownPlant != null) { if (!Running) { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Initializing"); } else { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Initializing"); } #endif // Hide seed model and show plant model PrefabsHelper.ShowPlantAndHideSeed(_grownPlant.gameObject.transform); // Store init values _initTimeValue = DayNightCycle.main.timePassed; foreach (Transform tr in _grownPlant.gameObject.transform) { _origScale = new Vector3(tr.localScale.x, tr.localScale.y, tr.localScale.z); break; } // If we need to add a temporary collider, do it before scaling if (EnableColliders) { var coveTreeModel = _grownPlant.gameObject.FindChild("lost_river_cove_tree_01"); if (coveTreeModel != null) { _tmpCollider = coveTreeModel.AddComponent <BoxCollider>(); if (_tmpCollider != null) { _tmpCollider.size = new Vector3(7.0f, 20.0f, 7.0f); _tmpCollider.center = new Vector3(_tmpCollider.center.x, _tmpCollider.center.y + 10.0f, _tmpCollider.center.z); } } } // Init tree/plant size foreach (Transform tr in _grownPlant.gameObject.transform) { if (tr.name != "Generic_plant_seed") { tr.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f); } } // Init colliders size if (RestoreColliders) { Collider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <Collider>(); foreach (Collider collider in colliders) { collider.transform.localScale *= 1000.0f; collider.enabled = true; } } if (RestoreRadius) { SphereCollider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <SphereCollider>(); foreach (SphereCollider collider in colliders) { collider.radius *= 1000.0f; collider.enabled = true; } } if (RestoreBoxColliders) { BoxCollider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <BoxCollider>(); foreach (BoxCollider collider in colliders) { collider.size *= 1000.0f; collider.enabled = true; } } Running = true; } else { // Animation _progress = ((float)(DayNightCycle.main.timePassed - _initTimeValue) / GrowthDuration) + _passedProgress; #if DEBUG_FLORA_ANIMATION if (id != null) { Logger.Log("DEBUG: PlantGenericController.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "]"); } else { Logger.Log("DEBUG: PlantGenericController.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "]"); } #endif if (_grownPlant.gameObject.transform.localPosition.x > 4500.0f && _grownPlant.gameObject.transform.localPosition.z > 4500.0f) { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component"); } else { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component"); } #endif this.enabled = false; } else { if (_progress < 1.0f) { foreach (Transform tr in _grownPlant.gameObject.transform) { if (tr.name != "Generic_plant_seed") { tr.localScale = new Vector3(_origScale.x * _progress, _origScale.y * _progress, _origScale.z * _progress); } } } else { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Set final size"); } else { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Set final size"); } #endif // Set final size _progress = 1.0f; foreach (Transform tr in _grownPlant.gameObject.transform) { if (tr.name != "Generic_plant_seed") { tr.localScale = new Vector3(_origScale.x, _origScale.y, _origScale.z); } } // Set final colliders if (EnableColliders) { // Disable temporary collider if (_tmpCollider != null) { _tmpCollider.enabled = false; GameObject.DestroyImmediate(_tmpCollider); } // Enable origin colliders Collider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <Collider>(); foreach (Collider collider in colliders) { collider.enabled = true; } } // Enable knifeable LiveMixin liveMixin = _grownPlant.gameObject.GetComponent <LiveMixin>(); liveMixin.data.knifeable = Knifeable; // Disable controller this.enabled = false; } } } } else { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Disabling controller"); } else { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Disabling controller"); } #endif this.enabled = false; } }
public void OnProtoSerialize(ProtobufSerializer serializer) { PrefabIdentifier id = this.gameObject.GetComponent <PrefabIdentifier>(); if (id == null) { return; } #if DEBUG_FLORA Logger.Log("DEBUG: Entering onProtoSerialize for gameobject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); #endif Plantable plant = this.gameObject.GetComponent <Plantable>(); if (plant.linkedGrownPlant != null) { PlantGenericController plantController = plant.linkedGrownPlant.gameObject.GetComponent <PlantGenericController>(); LandTree1Controller treeController = plant.linkedGrownPlant.gameObject.GetComponent <LandTree1Controller>(); PlantMonoTransformController plantMonoTransformController = plant.linkedGrownPlant.GetComponent <PlantMonoTransformController>(); float progress = -1.0f; if (plantController != null && plantController._progress >= 0.0f) { progress = plantController._progress; #if DEBUG_FLORA Logger.Log("DEBUG: LinkedGrownPlant) plantController) Saving progress=[" + progress + "] for gameObject name=[" + this.gameObject.name + "]"); #endif } else if (treeController != null && treeController._progress >= 0.0f) { progress = treeController._progress; #if DEBUG_FLORA Logger.Log("DEBUG: LinkedGrownPlant) treeController) Saving progress=[" + progress + "] for gameObject name=[" + this.gameObject.name + "]"); #endif } else if (plantMonoTransformController != null && plantMonoTransformController._progress >= 0.0f) { progress = plantMonoTransformController._progress; #if DEBUG_FLORA Logger.Log("DEBUG: LinkedGrownPlant) plantMonoTransformController) Saving progress=[" + progress + "] for gameObject name=[" + this.gameObject.name + "]"); } else { Logger.Log("DEBUG: LinkedGrownPlant) No controller found for gameObject name=[" + this.gameObject.name + "]"); } #else } #endif if (progress >= 0.0f) { // Open save directory string saveFolder = FilesHelper.GetSaveFolderPath(); if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } // Save custom flora state File.WriteAllText(Path.Combine(saveFolder, "customflora_" + id.Id + ".txt"), Convert.ToString(progress)); } }
//public static bool CanDropItemHere(Pickupable item, bool notify = false) public static bool CanDropItemHere_Prefix(bool __result, Pickupable item, bool notify = false) { bool isPlant = false; #if DEBUG_DROP_ITEM Logger.Log("DEBUG: Entering CanDropItemHere_Prefix() for item name=[" + item.gameObject.name + "]"); #endif // Check if current item is a plant Plantable plant = item.gameObject.GetComponent <Plantable>(); if (plant != null) { isPlant = true; } else { #if DEBUG_DROP_ITEM Logger.Log("DEBUG: A) Cannot find plant"); #endif GrownPlant grownPlant = item.gameObject.GetComponent <GrownPlant>(); if (grownPlant != null) { isPlant = true; } #if DEBUG_DROP_ITEM else { Logger.Log("DEBUG: B) Cannot find grownplant"); } #endif } if (isPlant) { // Check if current plant is one of our custom plants PrefabIdentifier id = item.gameObject.GetComponent <PrefabIdentifier>(); if (id != null) { if (!String.IsNullOrEmpty(id.ClassId) && _plants.Contains(id.ClassId)) { // If yes, set result value to false (cannot drop item) and return false to // prevent original function from being called __result = false; return(false); } #if DEBUG_DROP_ITEM else { Logger.Log("DEBUG: E) Cannot find class ID"); } } else { Logger.Log("DEBUG: D) Cannot find prefab ID"); } } else { Logger.Log("DEBUG: C) Item is not a plant"); } #else }
public void Update() { #if (DEBUG_FLORA || DEBUG_FLORA_ENTRY || DEBUG_FLORA_ANIMATION) PrefabIdentifier id = GetComponent <PrefabIdentifier>(); #endif #if DEBUG_FLORA_ENTRY if (id != null) { Logger.Log("DEBUG: A) Entering PlantMonoTransformController.Update() for gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); } else { Logger.Log("DEBUG: A) Entering PlantMonoTransformController.Update() for gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); } #endif if (_plant == null) { _plant = GetComponent <Plantable>(); } if (_grownPlant == null) { _grownPlant = GetComponent <GrownPlant>(); } if (_grownPlant == null && _plant != null) { if (_plant.linkedGrownPlant != null) { #if DEBUG_FLORA Logger.Log("DEBUG: PlantMonoTransformController.Update() Associating grown plant in gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); #endif _grownPlant = _plant.linkedGrownPlant; _grownPlant.seed = _plant; } } if (_grownPlant != null) { #if DEBUG_FLORA_ENTRY if (id == null) { id = _grownPlant.gameObject.GetComponent <PrefabIdentifier>(); if (id != null) { Logger.Log("DEBUG: B) Entering PlantMonoTransformController.Update() for gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "]"); } else { Logger.Log("DEBUG: B) Entering PlantMonoTransformController.Update() for gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "]"); } } #endif if (!Running) { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Initializing"); } else { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Initializing"); } #endif // Hide seed model GameObject seed = _grownPlant.gameObject.FindChild("Generic_plant_seed"); if (seed != null) { seed.GetComponent <MeshRenderer>().enabled = false; } // Store init values _initTimeValue = DayNightCycle.main.timePassed; if (_origScale == Vector3.zero) { _origScale = new Vector3(_grownPlant.gameObject.transform.localScale.x, _grownPlant.gameObject.transform.localScale.y, _grownPlant.gameObject.transform.localScale.z); } // Init tree size _grownPlant.gameObject.transform.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f); Running = true; } else { // Animation _progress = ((float)(DayNightCycle.main.timePassed - _initTimeValue) / GrowthDuration) + _passedProgress; #if DEBUG_FLORA_ANIMATION if (id != null) { Logger.Log("DEBUG: PlantMonoTransformController.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "]"); } else { Logger.Log("DEBUG: PlantMonoTransformController.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "]"); } #endif if (_grownPlant.gameObject.transform.localPosition.x > 4900.0f && _grownPlant.gameObject.transform.localPosition.x < 5100.0f && _grownPlant.gameObject.transform.localPosition.z > 4900.0f && _grownPlant.gameObject.transform.localPosition.z < 5100.0f) { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component"); } else { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component"); } #endif this.enabled = false; } else { if (_progress < 1.0f) { _grownPlant.gameObject.transform.localScale = new Vector3(_origScale.x * _progress, _origScale.y * _progress, _origScale.z * _progress); } else { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Set final size"); } else { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Set final size"); } #endif // Set final size _progress = 1.0f; _grownPlant.gameObject.transform.localScale = new Vector3(_origScale.x, _origScale.y, _origScale.z); // Enable knifeable LiveMixin liveMixin = _grownPlant.gameObject.GetComponent <LiveMixin>(); liveMixin.data.knifeable = Knifeable; // Disable controller this.enabled = false; } } } } else { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Replacing seed by plant"); } else { Logger.Log("DEBUG: PlantMonoTransformController.Update(): gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Replacing seed by plant"); } #endif this.enabled = false; } }
public void Update() { #if (DEBUG_FLORA || DEBUG_FLORA_ENTRY || DEBUG_FLORA_ANIMATION) PrefabIdentifier id = GetComponent <PrefabIdentifier>(); #endif #if DEBUG_FLORA_ENTRY if (id != null) { Logger.Log("DEBUG: Entering LandTree1Controller.Update() for gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); } else { Logger.Log("DEBUG: Entering LandTree1Controller.Update() for gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); } #endif if (_plant == null) { _plant = GetComponent <Plantable>(); } if (_grownPlant == null) { _grownPlant = GetComponent <GrownPlant>(); } if (_grownPlant == null && _plant != null) { if (_plant.linkedGrownPlant != null) { #if DEBUG_FLORA Logger.Log("DEBUG: LandTree1Controller.Update() Associating grown plant in gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); #endif _grownPlant = _plant.linkedGrownPlant; _grownPlant.seed = _plant; } } if (_grownPlant != null) { if (!Running) { InitAnimation(_grownPlant.gameObject); } else { // Animation _progress = ((float)(DayNightCycle.main.timePassed - _initTimeValue) / GrowthDuration) + _passedProgress; #if DEBUG_FLORA_ANIMATION if (id != null) { Logger.Log("DEBUG: LandTree1Controller.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "]"); } else { Logger.Log("DEBUG: LandTree1Controller.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "]"); } #endif if (_grownPlant.gameObject.transform.localPosition.x > 4900.0f && _grownPlant.gameObject.transform.localPosition.x < 5100.0f && _grownPlant.gameObject.transform.localPosition.z > 4900.0f && _grownPlant.gameObject.transform.localPosition.z < 5100.0f) { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component"); } else { Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component"); } #endif this.enabled = false; } else { if (_progress < 1.0f) { foreach (Transform tr in _grownPlant.gameObject.transform) { if (tr.name.StartsWith("Land_tree_01_static", true, CultureInfo.InvariantCulture)) { tr.localScale = new Vector3(_origStaticScale.x * _progress, _origStaticScale.y * _progress, _origStaticScale.z * _progress); } } } else { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Set final size"); } else { Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Set final size"); } #endif // Set final size _progress = 1.0f; foreach (Transform tr in _grownPlant.gameObject.transform) { if (!tr.name.StartsWith("Land_tree_01_static", true, CultureInfo.InvariantCulture)) { tr.localScale = new Vector3(_origScale.x, _origScale.y, _origScale.z); } } // Enable knifeable LiveMixin liveMixin = _grownPlant.gameObject.GetComponent <LiveMixin>(); liveMixin.data.knifeable = Knifeable; // Disable static part this.StaticPrefab.SetActive(false); // Disable controller this.enabled = false; } } } } else { #if DEBUG_FLORA if (id != null) { Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Disabling controller"); } else { Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Disabling controller"); } #endif this.enabled = false; } }
public Plant(TaskQueue queue, Plantable plantable) : base(queue, plantable) { }