public void Awake() { animator = GetComponentInChildren <Animator>(); locomotion = GetComponent <Locomotion>(); locomotionWasEnabled = locomotion.isActiveAndEnabled; ecoTarget = GetComponent <EcoTarget>(); animatorLink = GetComponentInChildren <AnimatorLink>(); rb = GetComponent <Rigidbody>(); modelRoot = GetComponentInChildren <Renderer>().gameObject; iceMaterial = Player.main.GetComponent <PlayerFrozenMixin>().GetPrivateField("iceMaterial") as Material; }
private void OnTriggerEnter(Collider collider) { if (creature.Hunger.Value < 0.2f) { return; } GameObject nibbleGameObject = collider.gameObject; if (liveMixin.IsAlive() && !frozen) { timeStartNibbling = Time.time; EcoTarget ecoTarget = nibbleGameObject.GetComponentInParent <EcoTarget>(); LiveMixin lm = nibbleGameObject.GetComponentInParent <LiveMixin>(); bool isDead = (lm != null && !lm.IsAlive()) || (ecoTarget != null && ecoTarget.type == EcoTargetType.DeadMeat); bool isSpecialConsumable = ecoTarget != null && ecoTarget.type == QPatch.clownPincherSpecialEdible; if (isDead || isSpecialConsumable) { objectEating = collider.gameObject; } } }
public override GameObject GetGameObject() { GameObject prefab = GameObject.Instantiate(this.GameObject); prefab.name = this.ClassID; // Translate foreach (Transform tr in prefab.transform) { tr.localPosition = new Vector3(tr.localPosition.x, tr.localPosition.y + 0.25f, tr.localPosition.z); } // Update TechTag var techTag = prefab.GetComponent <TechTag>(); if (techTag == null) { if ((techTag = prefab.GetComponentInChildren <TechTag>()) == null) { techTag = prefab.AddComponent <TechTag>(); } } techTag.type = this.TechType; // Remove unwanted components EntityTag entityTag = prefab.GetComponent <EntityTag>(); if (entityTag != null) { GameObject.DestroyImmediate(entityTag); } EcoTarget ecoTarget = prefab.GetComponent <EcoTarget>(); if (ecoTarget != null) { GameObject.DestroyImmediate(ecoTarget); } ResourceTracker resourceTracker = prefab.GetComponent <ResourceTracker>(); if (resourceTracker != null) { GameObject.DestroyImmediate(resourceTracker); } WorldForces worldForces = prefab.GetComponent <WorldForces>(); if (worldForces != null) { GameObject.DestroyImmediate(worldForces); } // Update prefab ID var prefabId = prefab.GetComponent <PrefabIdentifier>(); if (prefabId == null) { if ((prefabId = prefab.GetComponentInChildren <PrefabIdentifier>()) == null) { prefabId = prefab.AddComponent <PrefabIdentifier>(); } } prefabId.ClassId = this.ClassID; // Remove Cube object to prevent physics GameObject cube = prefab.FindChild("Cube"); if (cube != null) { GameObject.DestroyImmediate(cube); } // Remove rigid body to prevent physics bugs var rb = prefab.GetComponent <Rigidbody>(); if (rb != null) { GameObject.DestroyImmediate(rb); } // Add box collider var collider = prefab.GetComponent <BoxCollider>(); if (collider == null) { Collider[] colliders = prefab.GetComponentsInChildren <Collider>(); if (colliders != null) { foreach (Collider c in colliders) { GameObject.DestroyImmediate(c); } } collider = prefab.AddComponent <BoxCollider>(); } collider.size = new Vector3(0.7f, 0.7f, 0.7f); collider.center = new Vector3(collider.center.x - 0.15f, collider.center.y + 1.0f, collider.center.z - 1.0f); collider.isTrigger = true; // We can pick this item var pickupable = prefab.GetComponent <Pickupable>(); if (pickupable == null) { pickupable = prefab.AddComponent <Pickupable>(); } pickupable.isPickupable = true; pickupable.randomizeRotationWhenDropped = true; // We can place this item prefab.AddComponent <CustomPlaceToolController>(); var placeTool = prefab.GetComponent <PlaceTool>(); if (placeTool != null) { GameObject.DestroyImmediate(placeTool); } placeTool = prefab.AddComponent <GenericPlaceTool>(); placeTool.allowedInBase = true; placeTool.allowedOnBase = true; placeTool.allowedOnCeiling = false; placeTool.allowedOnConstructable = true; placeTool.allowedOnGround = true; placeTool.allowedOnRigidBody = true; placeTool.allowedOnWalls = true; placeTool.allowedOutside = ConfigSwitcher.AllowPlaceOutside; placeTool.rotationEnabled = true; placeTool.enabled = true; placeTool.hasAnimations = false; placeTool.hasBashAnimation = false; placeTool.hasFirstUseAnimation = false; placeTool.mainCollider = collider; placeTool.pickupable = pickupable; // Update sky applier PrefabsHelper.ReplaceSkyApplier(prefab, true); // Add fabricating animation var fabricating = prefab.AddComponent <VFXFabricating>(); fabricating.localMinY = -0.2f; fabricating.localMaxY = 0.6f; fabricating.posOffset = new Vector3(0.1f, 0.141f, 0.3f); fabricating.eulerOffset = new Vector3(0f, 0f, 0f); fabricating.scaleFactor = 0.2f; return(prefab); }