public void Awake() { Running = false; // Init values _initTimeValue = DayNightCycle.main.timePassed; _progress = 0.0f; // Disable knifeable LiveMixin liveMixin = GetComponent <LiveMixin>(); if (liveMixin == null) { _grownPlant = GetComponent <GrownPlant>(); if (_grownPlant != null) { liveMixin = _grownPlant.gameObject.GetComponent <LiveMixin>(); } } if (liveMixin != null) { liveMixin.data.knifeable = Knifeable; } #if DEBUG_FLORA_ENTRY Logger.Log("DEBUG: PlantGenericController.Awake() for gameObject name=[" + this.gameObject.name + "] controllerEnabled=[" + this.enabled + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]"); #endif this.enabled = true; }
public static bool OnHandClick_Prefix(GrownPlant __instance, GUIHand hand) { if (__instance.seed != null && __instance.seed.gameObject != null) { PrefabIdentifier prefabID = __instance.seed.gameObject.GetComponent <PrefabIdentifier>(); if (prefabID == null) { return(true); } if (prefabID.ClassId == "MarbleMelonTiny") { PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); } if (controllerA != null && controllerA._progress >= 1.0f) { if (__instance.seed.currentPlanter != null && Inventory.Get().HasRoomFor(1, 1)) { __instance.seed.currentPlanter.RemoveItem(__instance.seed); if (global::Utils.GetSubRoot() != null) { __instance.seed.pickupable.destroyOnDeath = false; } SkyEnvironmentChanged.Send(__instance.seed.pickupable.gameObject, Player.main.GetSkyEnvironment()); UnityEngine.Object.Destroy(__instance.seed.pickupable.gameObject); CraftData.AddToInventorySync(CrafterLogicFixer.MarbleMelonTinyFruit, 1, false, false); hand.player.PlayGrab(); } } return(false); } else if (prefabID.ClassId == "MarbleMelonTinyFruit") { if (__instance.seed.currentPlanter != null && __instance.seed.pickupable != null && Inventory.Get().HasRoomFor(__instance.seed.pickupable)) { PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); } if (controllerA != null && controllerA._progress >= 1.0f) { __instance.seed.currentPlanter.RemoveItem(__instance.seed); Inventory.Get().Pickup(__instance.seed.pickupable, false); hand.player.PlayGrab(); } } return(false); } } return(true); }
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 static void OnHandHover_Postfix(GrownPlant __instance, GUIHand hand) { // If current plant is valid if (__instance.seed != null && __instance.seed.pickupable != null && __instance.seed.currentPlanter != null) { bool showMelonTooltip = false; // Get prefab ID PrefabIdentifier prefabID = __instance.seed.gameObject.GetComponent <PrefabIdentifier>(); if (prefabID == null) { return; } // If current plant is one of our custom plants bool isSmallMelon = prefabID.ClassId == "MarbleMelonTiny" || prefabID.ClassId == "MarbleMelonTinyFruit"; if (CustomFlora.AllPlants.Contains(prefabID.ClassId)) { LiveMixin liveMixin = null; bool componentEnabled = false; float progress = -1.0f; PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); if (controllerA != null) { liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerA == null) { PlantMonoTransformController controllerB = __instance.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB == null) { controllerB = __instance.seed.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB != null) { liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerB == null) { LandTree1Controller controllerC = __instance.gameObject.GetComponent <LandTree1Controller>(); if (controllerC == null) { controllerC = __instance.seed.gameObject.GetComponent <LandTree1Controller>(); if (controllerC != null) { liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerC != null) { progress = controllerC._progress; componentEnabled = controllerC.enabled; } } else { progress = controllerB._progress; componentEnabled = controllerB.enabled; } } else { progress = controllerA._progress; componentEnabled = controllerA.enabled; } if (componentEnabled) { if (progress >= 0.0f && progress < 1.0f) { // Display growing tooltip HandReticle.main.SetIcon(HandReticle.IconType.Progress, 1f); HandReticle.main.SetProgress(progress); // Fix knifeable if (liveMixin != null && liveMixin.data != null && liveMixin.knifeable) { liveMixin.data.knifeable = false; } } else if (isSmallMelon && progress >= 1.0f) { showMelonTooltip = true; } } else if (isSmallMelon && progress >= 1.0f) { showMelonTooltip = true; } } else if (isSmallMelon) { showMelonTooltip = true; } if (showMelonTooltip) { HandReticle.main.SetIcon(HandReticle.IconType.Hand, 1f); if (!Player.main.HasInventoryRoom(1, 1)) { #if BELOWZERO HandReticle.main.SetText(HandReticle.TextType.Hand, LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), false, GameInput.Button.None); HandReticle.main.SetText(HandReticle.TextType.HandSubscript, "InventoryFull", true, GameInput.Button.None); #else HandReticle.main.SetInteractText(LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), "InventoryFull", false, true, HandReticle.Hand.None); #endif } else { #if BELOWZERO HandReticle.main.SetText(HandReticle.TextType.Hand, LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), false, GameInput.Button.None); #else HandReticle.main.SetInteractText(LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), string.Empty, false, false, HandReticle.Hand.None); #endif } } } }
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 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 void OnHandHover(GUIHand hand) public static void OnHandHover_Postfix(GrownPlant __instance, GUIHand hand) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A"); #endif // If current plant is valid if (__instance.seed != null && __instance.seed.pickupable != null && __instance.seed.currentPlanter != null) { // Get prefab ID PrefabIdentifier prefabID = __instance.seed.gameObject.GetComponent <PrefabIdentifier>(); // If current plant is one of our custom plants if (prefabID != null && InventoryFixer._plants.Contains(prefabID.ClassId)) { LiveMixin liveMixin = null; bool componentEnabled = false; float progress = -1.0f; PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); if (controllerA != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN SEED A"); #endif liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN A"); #endif liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } PlantMonoTransformController controllerB = __instance.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB == null) { controllerB = __instance.seed.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN SEED B"); #endif liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN B"); #endif liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } LandTree1Controller controllerC = __instance.gameObject.GetComponent <LandTree1Controller>(); if (controllerC == null) { controllerC = __instance.seed.gameObject.GetComponent <LandTree1Controller>(); if (controllerC != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN SEED C"); #endif liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN C"); #endif liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerA != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A1 enabled=[" + controllerA.enabled + "] progress=[" + controllerA._progress + "] passedProgress=[" + controllerA._passedProgress + "]"); #endif progress = controllerA._progress;// + controllerA._passedProgress; componentEnabled = controllerA.enabled; } else if (controllerB != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A2 enabled=[" + controllerB.enabled + "] progress=[" + controllerB._progress + "] passedProgress=[" + controllerB._passedProgress + "]"); #endif progress = controllerB._progress;// + controllerB._passedProgress; componentEnabled = controllerB.enabled; } else if (controllerC != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A3 enabled=[" + controllerC.enabled + "] progress=[" + controllerC._progress + "] passedProgress=[" + controllerC._passedProgress + "]"); #endif progress = controllerC._progress;// + controllerC._passedProgress; componentEnabled = controllerC.enabled; } #if DEBUG_GROWNPLANT_FIXER else { Logger.Log("DEBUG: TEST A4"); } #endif if (componentEnabled && progress >= 0.0f && progress < 1.0f) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A5 progress=[" + progress + "]"); #endif // Display growing tooltip HandReticle.main.SetIcon(HandReticle.IconType.Progress, 1f); HandReticle.main.SetProgress(progress); // Fix knifeable if (liveMixin != null && liveMixin.data != null && liveMixin.knifeable) { liveMixin.data.knifeable = false; } } } #if DEBUG_GROWNPLANT_FIXER else { Logger.Log("DEBUG: TEST B4"); } } else { Logger.Log("DEBUG: TEST C"); } #else }