Beispiel #1
0
 private void LateUpdate()
 {
     if ((Object)targetTransform == (Object)null)
     {
         base.gameObject.SetActive(false);
     }
     else
     {
         Vector3     position  = targetTransform.GetPosition();
         KCollider2D component = targetTransform.GetComponent <KCollider2D>();
         if ((Object)component != (Object)null)
         {
             Vector3 center = component.bounds.center;
             position.x = center.x;
             Vector3 center2 = component.bounds.center;
             float   y       = center2.y;
             Vector3 size    = component.bounds.size;
             position.y = y + size.y / 2f + 0.1f;
         }
         else
         {
             position.y += 2f;
         }
         Vector3 b = new Vector3(0f, (Mathf.Sin(Time.unscaledTime * 4f) + 1f) * animationOffset, 0f);
         base.transform.SetPosition(position + b);
     }
 }
    public FallerComponent(Transform transform, Vector2 initial_velocity)
    {
        this.transform      = transform;
        transformInstanceId = transform.GetInstanceID();
        isFalling           = false;
        initialVelocity     = initial_velocity;
        partitionerEntry    = default(HandleVector <int> .Handle);
        solidChangedCB      = null;
        cellChangedCB       = null;
        KCircleCollider2D component = transform.GetComponent <KCircleCollider2D>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            offset = component.radius;
        }
        else
        {
            KCollider2D component2 = transform.GetComponent <KCollider2D>();
            if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
            {
                Vector3 position = transform.GetPosition();
                float   y        = position.y;
                Vector3 min      = component2.bounds.min;
                offset = y - min.y;
            }
            else
            {
                offset = 0f;
            }
        }
    }
            public static void Postfix(BuildingComplete __instance)
            {
                GameObject go = __instance.gameObject;

                if (__instance.name == "DirtTileComplete")
                {
                    Debug.Log("[DIRT] <BuildingComplete_OnSpawn> __instance.name: " + __instance.name);

                    Vector3 pos         = go.transform.position;
                    float   temperature = go.GetComponent <PrimaryElement>().Temperature;
                    float   mass        = Settings.BlockMass; // 50kg
                    byte    disease_idx = byte.MaxValue;
                    int     cell        = Grid.PosToCell(pos);
                    SimMessages.ReplaceAndDisplaceElement(cell, SimHashes.Dirt, null, mass, temperature, disease_idx, 0, -1); // spawn Dirt Block

                    Debug.Log($"[DIRT] <BuildingComplete_OnSpawn> pos: {pos}, temperature: {temperature}, cell: {cell}");

                    // NOTE: Displace pickupables needs to be watched for possibly slowing down the game during late game
                    int origCell = cell;
                    foreach (Pickupable pickupable in Components.Pickupables)
                    {
                        if (Grid.PosToCell(pickupable) == origCell)
                        {
                            Debug.Log($"[DIRT] <BuildingComplete_OnSpawn> pickupable: {pickupable}");

                            for (int i = 0; i < _displacementOffsets.Length; i++)
                            {
                                int offsetCell = Grid.OffsetCell(cell, _displacementOffsets[i]);
                                if (Grid.IsValidCell(offsetCell) && !Grid.Solid[offsetCell])
                                {
                                    Vector3     position  = Grid.CellToPosCBC(offsetCell, Grid.SceneLayer.Move);
                                    KCollider2D component = pickupable.GetComponent <KCollider2D>();
                                    if (component != null)
                                    {
                                        position.y += pickupable.transform.GetPosition().y - component.bounds.min.y;
                                    }
                                    pickupable.transform.SetPosition(position);
                                    cell = offsetCell;

                                    Traverse.Create(pickupable).Method("RemoveFaller", new Type[] { }).GetValue();
                                    Traverse.Create(pickupable).Method("AddFaller", new Type[] { typeof(Vector2) }).GetValue(Vector2.zero);

                                    break;
                                }
                            }
                        }
                    }

                    go.DeleteObject(); // remove Dirt Tile
                }
            }
Beispiel #4
0
        public CollisionResolver(GravityComponent grav, Vector2 desiredPosition)
        {
            this.grav            = grav;
            this.currentPosition = grav.transform.position;
            this.desiredPosition = desiredPosition;

            bestDistance = float.PositiveInfinity;
            bestPosition = currentPosition;

            KCollider2D collider = grav.transform.GetComponent <KCollider2D>();

            if (collider != null)
            {
                this.bounds = collider.bounds;
                bounds.Expand(0.05f); // Apply breathing room
            }
        }
Beispiel #5
0
    public void GetSelectablesUnderCursor(List <KSelectable> hits)
    {
        if ((UnityEngine.Object)hoverOverride != (UnityEngine.Object)null)
        {
            hits.Add(hoverOverride);
        }
        Camera  main      = Camera.main;
        Vector3 mousePos  = KInputManager.GetMousePos();
        float   x2        = mousePos.x;
        Vector3 mousePos2 = KInputManager.GetMousePos();
        float   y2        = mousePos2.y;
        Vector3 position  = main.transform.GetPosition();
        Vector3 position2 = new Vector3(x2, y2, 0f - position.z);
        Vector3 pos       = main.ScreenToWorldPoint(position2);
        Vector2 pos2      = new Vector2(pos.x, pos.y);
        int     cell      = Grid.PosToCell(pos);

        if (Grid.IsValidCell(cell) && Grid.IsVisible(cell))
        {
            Game.Instance.statusItemRenderer.GetIntersections(pos2, hits);
            ListPool <ScenePartitionerEntry, SelectTool> .PooledList pooledList = ListPool <ScenePartitionerEntry, SelectTool> .Allocate();

            GameScenePartitioner.Instance.GatherEntries((int)pos2.x, (int)pos2.y, 1, 1, GameScenePartitioner.Instance.collisionLayer, pooledList);
            pooledList.Sort((ScenePartitionerEntry x, ScenePartitionerEntry y) => SortHoverCards(x, y));
            foreach (ScenePartitionerEntry item in pooledList)
            {
                KCollider2D kCollider2D = item.obj as KCollider2D;
                if (!((UnityEngine.Object)kCollider2D == (UnityEngine.Object)null) && kCollider2D.Intersects(new Vector2(pos2.x, pos2.y)))
                {
                    KSelectable kSelectable = kCollider2D.GetComponent <KSelectable>();
                    if ((UnityEngine.Object)kSelectable == (UnityEngine.Object)null)
                    {
                        kSelectable = kCollider2D.GetComponentInParent <KSelectable>();
                    }
                    if (!((UnityEngine.Object)kSelectable == (UnityEngine.Object)null) && kSelectable.isActiveAndEnabled && !hits.Contains(kSelectable) && kSelectable.IsSelectable)
                    {
                        hits.Add(kSelectable);
                    }
                }
            }
            pooledList.Recycle();
        }
    }
Beispiel #6
0
    public static float GetRadius(Transform transform)
    {
        KCircleCollider2D component = transform.GetComponent <KCircleCollider2D>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            return(component.radius);
        }
        KCollider2D component2 = transform.GetComponent <KCollider2D>();

        if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
        {
            Vector3 position = transform.GetPosition();
            float   y        = position.y;
            Vector3 min      = component2.bounds.min;
            return(y - min.y);
        }
        return(0f);
    }
Beispiel #7
0
	public void TryToOffsetIfBuried()
	{
		if (!KPrefabID.HasTag(GameTags.Stored) && !KPrefabID.HasTag(GameTags.Equipped))
		{
			int num = Grid.PosToCell(this);
			if (Grid.IsValidCell(num))
			{
				if ((base.gameObject.GetSMI<DeathMonitor.Instance>()?.IsDead() ?? true) && ((Grid.Solid[num] && Grid.Foundation[num]) || Grid.Properties[num] != 0))
				{
					for (int i = 0; i < displacementOffsets.Length; i++)
					{
						int num2 = Grid.OffsetCell(num, displacementOffsets[i]);
						if (Grid.IsValidCell(num2) && !Grid.Solid[num2])
						{
							Vector3 position = Grid.CellToPosCBC(num2, Grid.SceneLayer.Move);
							KCollider2D component = GetComponent<KCollider2D>();
							if ((UnityEngine.Object)component != (UnityEngine.Object)null)
							{
								float y = position.y;
								Vector3 position2 = base.transform.GetPosition();
								float y2 = position2.y;
								Vector3 min = component.bounds.min;
								position.y = y + (y2 - min.y);
							}
							base.transform.SetPosition(position);
							num = num2;
							RemoveFaller();
							AddFaller(Vector2.zero);
							break;
						}
					}
				}
				HandleSolidCell(num);
			}
		}
	}
Beispiel #8
0
    private void GetObjectUnderCursor2D <T>(List <Intersection> intersections, Func <T, bool> condition, int layer_mask) where T : MonoBehaviour
    {
        Camera  main      = Camera.main;
        Vector3 mousePos  = KInputManager.GetMousePos();
        float   x         = mousePos.x;
        Vector3 mousePos2 = KInputManager.GetMousePos();
        float   y         = mousePos2.y;
        Vector3 position  = main.transform.GetPosition();
        Vector3 position2 = new Vector3(x, y, 0f - position.z);
        Vector3 pos       = main.ScreenToWorldPoint(position2);
        Vector2 pos2      = new Vector2(pos.x, pos.y);

        if ((UnityEngine.Object)hoverOverride != (UnityEngine.Object)null)
        {
            intersections.Add(new Intersection
            {
                component = hoverOverride,
                distance  = -100f
            });
        }
        int cell = Grid.PosToCell(pos);

        if (Grid.IsValidCell(cell) && Grid.IsVisible(cell))
        {
            Game.Instance.statusItemRenderer.GetIntersections(pos2, intersections);
            ListPool <ScenePartitionerEntry, SelectTool> .PooledList pooledList = ListPool <ScenePartitionerEntry, SelectTool> .Allocate();

            int x2 = 0;
            int y2 = 0;
            Grid.CellToXY(cell, out x2, out y2);
            GameScenePartitioner.Instance.GatherEntries(x2, y2, 1, 1, GameScenePartitioner.Instance.collisionLayer, pooledList);
            foreach (ScenePartitionerEntry item in (List <ScenePartitionerEntry>)pooledList)
            {
                KCollider2D kCollider2D = item.obj as KCollider2D;
                if (!((UnityEngine.Object)kCollider2D == (UnityEngine.Object)null) && kCollider2D.Intersects(new Vector2(pos.x, pos.y)))
                {
                    T val = kCollider2D.GetComponent <T>();
                    if ((UnityEngine.Object)val == (UnityEngine.Object)null)
                    {
                        val = kCollider2D.GetComponentInParent <T>();
                    }
                    if (!((UnityEngine.Object)val == (UnityEngine.Object)null) && ((1 << val.gameObject.layer) & layer_mask) != 0 && !((UnityEngine.Object)val == (UnityEngine.Object)null) && (condition == null || condition(val)))
                    {
                        Vector3 position3 = val.transform.GetPosition();
                        float   num       = position3.z - pos.z;
                        bool    flag      = false;
                        for (int i = 0; i < intersections.Count; i++)
                        {
                            Intersection value = intersections[i];
                            if ((UnityEngine.Object)value.component.gameObject == (UnityEngine.Object)val.gameObject)
                            {
                                value.distance   = Mathf.Min(value.distance, num);
                                intersections[i] = value;
                                flag             = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            intersections.Add(new Intersection
                            {
                                component = val,
                                distance  = num
                            });
                        }
                    }
                }
            }
            pooledList.Recycle();
        }
    }
            public static void Postfix(BuildingComplete __instance)
            {
                GameObject go = __instance.gameObject;

                if (__instance.name == "NaturalTileComplete")
                {
                    LogDebug($"__instance.name: {__instance.name}");

                    Vector3        pos         = go.transform.position;
                    PrimaryElement element     = go.GetComponent <PrimaryElement>();
                    float          temperature = element.Temperature;
                    float          mass        = Settings.BlockMass;
                    int            cell        = Grid.PosToCell(pos);
                    LogDebug($"{element}");

                    LogDebug($"pos: {pos}, temperature: {temperature}, cell: {cell}");

                    // SimMessages.ReplaceAndDisplaceElement(
                    //     int gameCell, SimHashes new_element, CellElementEvent ev,
                    //     float mass, float temperature = -1f, byte disease_idx = 255,
                    //     int disease_count = 0, int callbackIdx = -1
                    // )
                    SimMessages.ReplaceAndDisplaceElement(cell, element.ElementID,
                                                          null, mass, temperature, byte.MaxValue, 0, -1); // spawn Natural Block

                    // Error randomly showing up after creation of natural block
                    // NullReferenceException: Object reference not set to an instance of an object
                    // at ObjectLayerListItem.Refresh(System.Int32 new_cell)[0x00149]
                    //      in C:\jenkins_workspace\workspace\SimGame_Windows\game\Assets\
                    //      scripts\game\ObjectLayerListItem.cs:59
                    // at ObjectLayerListItem.Update(System.Int32 cell)[0x00001]
                    //      in C:\jenkins_workspace\workspace\SimGame_Windows\game\Assets\
                    //      scripts\game\ObjectLayerListItem.cs:72
                    // at Pickupable.OnCellChange()[0x000d1] in C:\jenkins_workspace\workspace\
                    //      SimGame_Windows\game\Assets\scripts\components\Pickupable.cs:479
                    // at CellChangeMonitor.RenderEveryTick()[0x00143] in C:\jenkins_workspace\
                    //      workspace\SimGame_Windows\game\Assets\Plugins\Klei\util\
                    //      CellChangeMonitor.cs:194
                    // at Game.Update()[0x00091] in C:\jenkins_workspace\workspace\SimGame_Windows\
                    //      game\Assets\scripts\game\Game.cs:1341

                    // NOTE: Displace pickupables needs to be watched for possibly slowing down the game during late game
                    int origCell = cell;
                    foreach (Pickupable pickupable in Components.Pickupables)
                    {
                        if (Grid.PosToCell(pickupable) == origCell)
                        {
                            LogDebug($"pickupable: {pickupable}");

                            for (int i = 0; i < _displacementOffsets.Length; i++)
                            {
                                int offsetCell = Grid.OffsetCell(cell, _displacementOffsets[i]);
                                if (Grid.IsValidCell(offsetCell) && !Grid.Solid[offsetCell])
                                {
                                    Vector3     position  = Grid.CellToPosCBC(offsetCell, Grid.SceneLayer.Move);
                                    KCollider2D component = pickupable.GetComponent <KCollider2D>();
                                    if (component != null)
                                    {
                                        position.y += pickupable.transform.GetPosition().y - component.bounds.min.y;
                                    }
                                    pickupable.transform.SetPosition(position);
                                    cell = offsetCell;

                                    Traverse.Create(pickupable).Method("RemoveFaller", new Type[] { }).GetValue();
                                    Traverse.Create(pickupable).Method("AddFaller", new Type[] { typeof(Vector2) }).GetValue(Vector2.zero);

                                    break;
                                }
                            }
                        }
                    }

                    go.DeleteObject(); // remove Natural Tile
                }
            }