private void ChildActorsTest() { Debug.Log(LogLevel.Display, "Starting " + MethodBase.GetCurrentMethod().Name + "..."); Actor actor = new Actor(); ChildActorComponent childActorComponent = new ChildActorComponent(actor, setAsRoot: true); TriggerBox childActor = childActorComponent.SetChildActor <TriggerBox>(); if (childActor == null) { Debug.Log(LogLevel.Error, "Child actor obtainment check failed!"); return; } BoxComponent boxComponent = childActor.GetComponent <BoxComponent>(); Vector3 initialExtent = new Vector3(100.0f, 100.0f, 100.0f); boxComponent.InitBoxExtent(initialExtent); if (initialExtent != boxComponent.GetUnscaledBoxExtent()) { Debug.Log(LogLevel.Error, "Child actor box extent check failed!"); return; } Debug.Log(LogLevel.Display, "Test passed successfully"); }
private void Start() { if (instance == null) { instance = this; DontDestroyOnLoad(this.gameObject); } else { Destroy(this.gameObject); } BoxComponent = BoxInventory.GetComponent <InventoryManager>(); SaveInvenstr = ""; SaveEquipstr = ""; itemoffsetList = new List <Item>(); itemoffsetList = LoadJsonFile <List <Item> >(Application.dataPath + "/SaveData", "Offset"); for (int i = 0; i < itemoffsetList.Count; ++i) { itemoffsetList[i].Print(); GameObject obj = CreateItemObject(itemoffsetList[i]); BoxComponent.AddItem(obj); } }
public BoxComponent GetClosestBox(Vector2 position, float preferredHeightDifference = 1.0f) { BoxComponent foundBox = null; float distance = int.MaxValue; if (_component.InstantiatedBoxes.Count > 0) { foreach (BoxComponent box in _component.InstantiatedBoxes) { if (Mathf.Abs(box.transform.position.y - position.y) < preferredHeightDifference) { float newDistance = Vector2.Distance(box.transform.position, position); if (distance > newDistance) { distance = newDistance; foundBox = box; } } } if (foundBox == null) { return(GetClosestBox(position, float.MaxValue)); } } return(foundBox); }
private void Release() { grabbedObject.Release(this); grabbedObject = null; currentFocus = null; Destroy(joint); fpc.setSpeed(5f, 10.0f); }
public bool IsMergable(BoxComponent box) { if ((!IsEmpty) && (merger == null)) { return(hold.level == box.level); } return(false); }
public BoxComponent CreateBox(Vector2 position) { BoxComponent newBox = Instantiate(Box, position, Quaternion.identity, transform); newBox.gameObject.SetActive(true); InstantiatedBoxes.Add(newBox); return(newBox); }
public void SetPosition(BoxComponent box) { if (IsEmpty) { hold = box; hold.transform.localPosition = transform.localPosition; } }
public static void OnBeginPlay() { Debug.AddOnScreenMessage(-1, 3.0f, Color.LightGreen, MethodBase.GetCurrentMethod().DeclaringType + " system started!"); World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera")); World.SetOnActorBeginOverlapCallback(OnActorBeginOverlap); World.SetOnActorEndOverlapCallback(OnActorEndOverlap); World.SetOnActorHitCallback(OnActorHit); World.SetOnComponentBeginOverlapCallback(OnComponentBeginOverlap); World.SetOnComponentEndOverlapCallback(OnComponentEndOverlap); World.SetOnComponentHitCallback(OnComponentHit); const float linesThickness = 3.0f; TriggerBox triggerBox = new TriggerBox(); BoxComponent collisionComponent = triggerBox.GetComponent <BoxComponent>(); Vector3 collisionLocation = new Vector3(0.0f, 0.0f, 0.0f); Vector3 collisionShape = new Vector3(200.0f, 200.0f, 200.0f); collisionComponent.GetLocation(ref collisionLocation); collisionComponent.SetBoxExtent(collisionShape); Debug.DrawBox(collisionLocation, collisionShape, Quaternion.Identity, Color.Aqua, true, thickness: linesThickness); leftActor.RegisterEvent(ActorEventType.OnActorBeginOverlap); leftActor.RegisterEvent(ActorEventType.OnActorEndOverlap); leftActor.RegisterEvent(ActorEventType.OnActorHit); leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginOverlap); leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndOverlap); leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentHit); leftStaticMeshComponent.SetGenerateOverlapEvents(true); leftStaticMeshComponent.SetGenerateHitEvents(true); leftStaticMeshComponent.SetStaticMesh(StaticMesh.Cube); leftStaticMeshComponent.SetMaterial(0, material); leftStaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("Color", LinearColor.Green); leftStaticMeshComponent.SetWorldLocation(new Vector3(0.0f, -startY, 0.0f)); leftStaticMeshComponent.SetEnableGravity(false); leftStaticMeshComponent.SetSimulatePhysics(true); rightActor.RegisterEvent(ActorEventType.OnActorBeginOverlap); rightActor.RegisterEvent(ActorEventType.OnActorEndOverlap); rightActor.RegisterEvent(ActorEventType.OnActorHit); rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginOverlap); rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndOverlap); rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentHit); rightStaticMeshComponent.SetGenerateOverlapEvents(true); rightStaticMeshComponent.SetGenerateHitEvents(true); rightStaticMeshComponent.SetStaticMesh(StaticMesh.Cube); rightStaticMeshComponent.SetMaterial(0, material); rightStaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("Color", LinearColor.Yellow); rightStaticMeshComponent.SetWorldLocation(new Vector3(0.0f, startY, 0.0f)); rightStaticMeshComponent.SetEnableGravity(false); rightStaticMeshComponent.SetSimulatePhysics(true); }
public void ReserveMerger(BoxComponent box) { if (IsMergable(box)) { merger = box; //translate box } }
public void ReserveHold(BoxComponent box) { if (IsEmpty) { hold = box; //translate box } }
// Use this for initialization void Start() { boxProduct = new BoxProductSelector(); GameObject box = Instantiate <GameObject>(boxPrefab); BoxComponent boxComponent = box.GetComponent <BoxComponent>(); str_boxProduct = boxProduct.GetSuitableBoxProduct(boxComponent.mySize); boxComponent.InitializeBox(str_boxProduct); }
private void OnTriggerExit(Collider other) { BoxComponent box = other.GetComponent <BoxComponent>(); if (box != null) { box.AddSuccionAceleration(); } }
/// <summary> /// push alle entities aus dem boden hinaus /// </summary> /// <param name="b"></param> private void HandleCollision(BoxComponent b) { if (b.GameObject is Floor) { return; } GameObject obj = b.GameObject; MoveComponent move = obj.GetComponent <MoveComponent>(); if (move == null) { return; } b.OnCollision?.Invoke(this.GetComponent <BoxComponent>()); if (move.Y > 0) { move.OnGround = true; } Vector delta = default; if (obj.Y + obj.Height > Y && obj.Y + obj.Height < Y + Height) { delta.Y = Y - obj.Height - 1; } if (obj.Y <= Y + Height && obj.Y + obj.Height > Y + Height) { delta.Y = Y + Height + 1; } if (obj.X + obj.Width > X && obj.X + obj.Width < X + Width) { delta.X = X - obj.Width - 1; } if (obj.X < X + Width && obj.X + obj.Width > X + Width) { delta.X = X + Width + 1; } //zur nächsten seite hinaus pushen if (Abs(obj.X - delta.X) > Abs(obj.Y - delta.Y)) { delta.X = obj.X; move.Y = 0; } else if (Abs(obj.X - delta.X) < Abs(obj.Y - delta.Y)) { delta.Y = obj.Y; } obj.Position = delta; }
private void ChildActorsTest() { Debug.Log(LogLevel.Display, "Starting " + MethodBase.GetCurrentMethod().Name + "..."); Actor actor = new(); ChildActorComponent childActorComponent = new(actor, setAsRoot : true); TriggerBox childActor = childActorComponent.SetChildActor <TriggerBox>(); if (childActor == null) { Debug.Log(LogLevel.Error, "Child actor obtainment check failed!"); return; } BoxComponent boxComponent = childActor.GetComponent <BoxComponent>(); Vector3 initialExtent = new(100.0f, 100.0f, 100.0f); boxComponent.InitBoxExtent(initialExtent); if (initialExtent != boxComponent.GetUnscaledBoxExtent()) { Debug.Log(LogLevel.Error, "Child actor box extent check failed!"); return; } int attachedActorCount = 0; Action <Actor> OnAttachedActor = (actor) => attachedActorCount++; actor.ForEachAttachedActor(OnAttachedActor); if (attachedActorCount != 1) { Debug.Log(LogLevel.Error, "Batched attached actor check failed!"); return; } int childActorCount = 0; Action <Actor> OnChildActor = (actor) => childActorCount++; actor.ForEachChildActor(OnChildActor); if (childActorCount != 1) { Debug.Log(LogLevel.Error, "Batched child actor check failed!"); return; } Debug.Log(LogLevel.Display, "Test passed successfully"); }
private void SpawnBoxes() { for (int i = 0; i < _component.BoxesToSpawn; i++) { Vector2 point = MathUtils.GetRandomPointWithinBounds(_component.BoxSpawnArea.bounds); BoxComponent box = _component.CreateBox(point); box.OnDestroyed += BoxDestroyed; } _shouldSpawn = false; }
public void OnErase(SlotComponent slot) { BoxComponent box = slot.box; slot.Clear(); boxCount--; boxes.Remove(box.id); GameObject.DestroyImmediate(box.gameObject); // AudioPlayerComponent.Play ("fx_combo"); // EffectComponent.Show (effectBang [0], slot.transform.position); blocked = false; }
public DynamicEvents() { playerController = World.GetFirstPlayerController(); triggerBox = new(); triggerCollisionComponent = triggerBox.GetComponent <BoxComponent>(); leftActor = new("LeftActor"); rightActor = new("RightActor"); leftStaticMeshComponent = new(leftActor, "LeftActorComponent", true); rightStaticMeshComponent = new(rightActor, "RightActorComponent", true); material = Material.Load("/Game/Tests/BasicMaterial"); stopTranslation = false; }
public void CreateBoxComponent(Size size, IActor owner) { Rect boundingRect = new Rect( owner.TC.Position.X - size.Width / 2.0, owner.TC.Position.Y - size.Height / 2.0, size.Width, size.Height); BoxComponent bc = new BoxComponent(boundingRect, owner); BoxComponents.Add(bc); owner.BC = bc; }
public void BoxThrown(BoxComponent box) { boxes.Remove(box); weightExcess -= (float)box.mySize; if (weightExcess <= 0 && weightProblem) { weightProblem = false; timeForWeightProblem = Random.Range(minimumTimePerWeightProblem, maxSecondsPerWeightProblem); timePassedInWeightProblem = 0; screenEvents.SetKGAlarm(ScreenEvents.State.Solution); } }
private void Update() { if (grabbedObject != null) { if (joint == null) { joint = handler.AddComponent <FixedJoint>(); joint.connectedBody = grabbedObject.GetComponent <Rigidbody>(); this.joint.connectedAnchor = grabbedObject.transform.position; this.joint.enableCollision = false; this.joint.anchor = this.handler.transform.position; } } RaycastHit hit; Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward, Color.red); if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward * maxDistanceGrab, out hit, maxDistanceGrab)) { if (currentFocus == null && hit.transform.gameObject.GetComponent <IInteractable>() != null && hit.transform.gameObject.GetComponent <IInteractable>() is BoxComponent) { BoxComponent box = (BoxComponent)hit.transform.gameObject.GetComponent <IInteractable>(); currentFocus = box; currentFocus.ChangeMaterial(true); } if (currentFocus != null && currentFocus == grabbedObject) { currentFocus.ChangeMaterial(false); } if (currentFocus != null && hit.transform.gameObject.GetComponent <BoxComponent>() != null && currentFocus != hit.transform.gameObject.GetComponent <BoxComponent>()) { currentFocus.ChangeMaterial(false); currentFocus = hit.transform.gameObject.GetComponent <BoxComponent>(); currentFocus.ChangeMaterial(true); } } else { if (currentFocus != null && currentFocus is BoxComponent) { currentFocus.ChangeMaterial(false); currentFocus = null; } } }
public void OnMerge(SlotComponent slot) { BoxComponent box1 = slot.box; BoxComponent box2 = slot.target; int level = box1.level + 1; if (level >= boxPrefabs.Length) { Debug.LogError("biggest box can't merge"); return; } slot.Clear(); boxCount -= 2; boxes.Remove(box1.id); boxes.Remove(box2.id); GameObject.DestroyImmediate(box1.gameObject); GameObject.DestroyImmediate(box2.gameObject); New(level, slot); // insert score increament bool isWin = AppendScore(level); // Vector3 pos = slot.transform.position; // insert effect 'bang' // EffectComponent.Show (effectBang [level], pos); // insert coin increment // if (EffectComponent.Show (effectCoin [level], pos) != null) { // AudioPlayerComponent.Play ("fx_coin"); // game.AppendCoin(); // } // insert effect 'combo' // if (EffectComponent.Show (effectCombo [(Mathf.Min(combo, effectCombo.Length-1))], pos) != null) { // AudioPlayerComponent.Play ("fx_combo"); // } if (isWin) { Victory(); blocked = true; } else { OnMoved(slot); } }
private void OnCollisionEnter(Collision2D other) { BoxComponent boxComponent = other.gameObject.GetComponent <BoxComponent>(); if (boxComponent != null) { _component.MovementDirection = RobotComponent.HorizontalDirection.Stationary; _state = State.Throwing; boxComponent.Transform.position = _component.transform.position + Vector3.up; // TODO animate ContainerComponent container = _level.GetContainer(boxComponent.Color); float throwDistance = container.transform.position.x - _component.transform.position.x; // TODO make better estimate float throwDirection = Mathf.Sign(throwDistance); float throwForce = Mathf.Abs(throwDistance) + 3; float throwY = throwDistance < 1 ? 2 : 1; boxComponent.RigidBody.velocity = throwForce * new Vector2(throwDirection, throwY).normalized; _state = State.Idle; } }
public void CheckCollisions() { Collisions.Clear(); for (int i = 0; i < BoxComponents.Count; i++) { for (int j = i + 1; j < BoxComponents.Count; j++) { BoxComponent bc1 = BoxComponents[i]; BoxComponent bc2 = BoxComponents[j]; if (bc1.BoundingRect.IntersectsWith(bc2.BoundingRect)) { Collisions.Add(new Collision(bc1.Owner, bc2.Owner)); } } } }
public void HandleMove(BoxComponent box) { if (merger != null) { if (merger == box) { core.OnMerge(this); } } else if (hold != null) { core.OnMoved(this); } else { // error ! Debug.LogError("????? (id:" + id + ")"); } }
public TaskWindow(int taskId) : this() { this.ID = "TaskWindow_" + taskId; this.taskId = taskId; var ctx = this.DBContext; var task = (from t in ctx.Tasks where t.ID == taskId select t).First(); this.Title = "Task - " + task.Title.Ellipsis(40); if (task.Completed) { BoxComponent msg = (BoxComponent)this.formPanel.Items[0]; msg.Hidden = false; msg.AutoEl.Html = "This task was completed on " + task.CompletedDate.Value.ToString("dddd, MMMM dd, yyyy"); } this.toolbar.Items[0].Hidden = task.Completed; this.toolbar.Items[1].Hidden = !task.Completed; this.cbxReminder.Disabled = task.Completed; this.dfReminder.Disabled = task.Completed; if (!task.Completed) { this.cbxReminder.Checked = task.Reminder.HasValue; if (task.Reminder.HasValue) { this.dfReminder.SelectedDate = task.Reminder.Value; } } this.taskSubject.Text = task.Title; this.dueDate.SelectedDate = task.DueDate; this.taskCategory.Text = task.Category.Name; this.taskCategory.UnderlyingValue = task.Category.ID.ToString(); this.description.Text = task.Description; this.CustomConfig.Add(new ConfigItem("taskId", taskId.ToString(), ParameterMode.Raw)); this.InitLogic(); }
public SlotComponent MostDown(BoxComponent box) { if (DOWN != null) { if (DOWN.IsEmpty) { return(DOWN.MostDown(box)); } else if (DOWN.IsMergable(box)) { return(DOWN); } else { return(this); } } else { return(this); } }
private void FindBoxAndMoveTowardIt() { BoxComponent box = _level.GetClosestBox(_component.transform.position); if (box != null) { _state = State.Moving; if (box.Transform.position.x - _component.transform.position.x > 0) // box is on the right { _component.MovementDirection = RobotComponent.HorizontalDirection.Right; } else // box is on the left { _component.MovementDirection = RobotComponent.HorizontalDirection.Left; } } else { _state = State.Idle; _component.MovementDirection = RobotComponent.HorizontalDirection.Stationary; } }
public void Down() { int count = 0; if (IsMovable()) { for (int y = ROW - 1; y >= 0; y--) { for (int x = COLUMN - 1; x >= 0; x--) { BoxComponent box = slots[y * COLUMN + x].box; if (box) { if (box.Down()) { count++; } } } } } }
public void Up() { int count = 0; if (IsMovable()) { for (int y = 0; y < ROW; y++) { for (int x = 0; x < COLUMN; x++) { BoxComponent box = slots[y * COLUMN + x].box; if (box) { if (box.Up()) { count++; } } } } } }
public void Right() { int count = 0; if (IsMovable()) { for (int x = COLUMN - 1; x >= 0; x--) { for (int y = 0; y < ROW; y++) { BoxComponent box = slots[y * COLUMN + x].box; if (box) { if (box.Right()) { count++; } } } } } }
public void Init() { _box = new BoxComponent(); _box.Id( "box" ); _result = new Str(); }