public List <UnitSpawner> GetSpawners(List <int> unique_ids, int for_id) { int id = for_id == 0 ? M_Math.GetRandomObject(unique_ids) : for_id; unique_ids.Remove(id); return(GetSpawners(id)); }
IEnumerator DoAction( ) { TargetPosition.y = 0; Active = true; Vector3 delta = TargetPosition - M_Math.GetCameraCenter(); MDebug.Log("^cameraStart Panning " + TargetPosition.ToString()); while (delta.magnitude > 0.1f) { delta = TargetPosition - M_Math.GetCameraCenter(); float speed = Speed; if (delta.magnitude < DistanceSpeedFalloffStart) { speed *= SpeedFalloff.Evaluate((DistanceSpeedFalloffStart - delta.magnitude) / DistanceSpeedFalloffStart); } transform.Translate(Vector3.ClampMagnitude(delta.normalized * speed * Time.deltaTime, delta.magnitude), Space.World); Debug.DrawLine(M_Math.GetCameraCenter(), TargetPosition, Color.red); yield return(null); } MDebug.Log("^cameraEndPanning " + TargetPosition.ToString()); Active = false; Callback(); }
public IEnumerator CamInputControl() { // MDebug.Log(" Cam Input Start"); inputEnabled = true; startDragPos = M_Math.GetInputPos(); while (inputEnabled && (Input.touchCount > 0 || Input.GetMouseButton(0) || Input.GetAxis("Mouse ScrollWheel") != 0)) { Vector3 mousePos = M_Math.GetInputPos(); if (Input.touchCount > 1 || Input.GetAxis("Mouse ScrollWheel") != 0) { StartCoroutine(Zooming()); yield break; } if ((startDragPos - mousePos).magnitude > 0.5f) { StartCoroutine(Pan()); yield break; } yield return(null); } }
void OnClose(Unit u) { target_enemy.OnIdentify -= OnClose; StartCoroutine(M_Math.ExecuteDelayed(3f, () => ToastNotification.SetToastMessage1("A prisoner?! He must have escaped from the mines."))); StartCoroutine(M_Math.ExecuteDelayed(4f, Complete)); }
IEnumerator Pan() { drag = true; startDragPos = M_Math.GetInputPos(); while (inputEnabled && (Input.touchCount == 1 || Input.GetMouseButton(0))) { Vector3 mousePos = M_Math.GetInputPos(); Vector3 delta = mousePos - startDragPos; smoothMove = delta * Time.deltaTime * 10; transform.position = transform.position - smoothMove; yield return(null); } StartCoroutine(DelayedStopDrag()); if (inputEnabled && (Input.touchCount == 2)) { smoothMove *= 0.2f; StartCoroutine(Zooming()); } yield break; }
IEnumerator Rotate(float delta) { if (rotating) { yield break; } rotating = true; float rotated = 0; float t = 0; while (Mathf.Abs(rotated) < Mathf.Abs(delta)) { float target_rot = Mathf.Lerp(0, delta, t); float dr = target_rot - rotated; rotated += dr; t += Time.deltaTime * 3; transform.RotateAround(M_Math.GetCameraCenter(), Vector3.up, dr); yield return(null); } transform.RotateAround(M_Math.GetCameraCenter(), Vector3.up, rotated - delta); rotating = false; }
void OnStatUpdated(Stat s) { if (s.StatType == StatType.adrenaline && m_action.GetRequirements().Select(si => si.StatType).ToList().Contains(s.StatType)) { M_Math.ExecuteDelayed(StatUpdateDelay, SetBaseState); } }
void Show() { gameObject.SetUIAlpha(0); StartCoroutine(M_Math.ExecuteDelayed(m_Item.GetIndex() == 0 ? 0.5f : 4f, () => StartCoroutine(M_Extensions.YieldT((f) => { gameObject.SetUIAlpha(f); }, 0.5f)) )); }
public void SetTutorialState() { MissionSystem.OnCompleteMission += OnComplete; if (MissionSystem.HasCompletedGlobal("find_enemy")) { Unit.GetAllUnitsOfOwner(0, true)[0].Identify(null); } if (MissionSystem.HasCompletedGlobal("move_to")) { Unit.GetAllUnitsOfOwner(1, true)[0].Identify(Unit.GetAllUnitsOfOwner(0, true)[0]); Tile close_to_enemy = TileManager.Instance.GetEdgeTiles(M_Math.GetListFromObject(Unit.GetAllUnitsOfOwner(1, true)[0].currentTile), 1, TileManager.Instance).First(); Unit.GetAllUnitsOfOwner(0, true)[0].SetTile(close_to_enemy, true); } if (MissionSystem.HasCompletedGlobal("loot")) { SpawnNext(); SpawnNext(); List <Tile> lastRow = TileManager.Instance.GetRow(TileManager.Instance.GridHeight - 1); Tile r = lastRow.FirstOrDefault(t => t.isAccessible); Unit.GetAllUnitsOfOwner(0, true)[0].SetTile(r, true); ; } }
void OnDrawGizmos() { if (Config != null) { M_Math.SceneViewText(Config.ID, transform.position); } }
IEnumerator PanToWorldPos(Vector3 pos, float speed, EventHandler _cb) { MDebug.Log("Start Pan"); pos.y = 0; drag = true; event_callback = _cb; Vector3 delta = pos - M_Math.GetCameraCenter(); while (delta.magnitude > 0.1f) { transform.Translate((pos - M_Math.GetCameraCenter()).normalized * speed * Time.deltaTime, Space.World); delta = pos - M_Math.GetCameraCenter(); Debug.DrawLine(M_Math.GetCameraCenter(), pos, Color.red); yield return(null); } if (event_callback != null) { event_callback(); event_callback = null; } inputEnabled = true; drag = false; }
public override void Remove() { m_Item.OnCancel -= Remove; m_Item.OnComplete -= Updated; StartCoroutine(M_Math.ExecuteDelayed(1.5f, Removed)); }
Tile GetPatrolTile(Tile start) { List <Tile> tiles_in_range = TileManager.Instance.GetRandomTilesAroundCenter(start, Constants.AI_PATROL_DISTANCE); // MDebug.Log("PATROL query tiles in range = " + tiles_in_range.Count); tiles_in_range.RemoveAll(t => !t.isAccessible || !t.isEnabled || t.isCamp || t.isCrumbling); return(M_Math.GetRandomObject(tiles_in_range)); }
private void SpawnSetups() { if (AllowedToComplete(this) && Setups == null && !Config.Setup.IsNullOrEmpty()) { MDebug.Log("SPAWN SETUP"); Setups = M_Math.SpawnFromList(Config.Setup); Setups.ForEach(setup => setup.Init()); } }
List <SpeechManager_Unit> getSpeeches(int owner, int min, int max, Unit exclude) { List <Unit> units = Unit.GetAllUnitsOfOwner(owner, true); int count = Mathf.Min(Random.Range(min, max + 1), units.Count); List <Unit> picked = M_Math.GetRandomObjects(new List <Unit>(units).Where(u => u != exclude).ToList(), count); return(picked.Select(p => p.GetComponent <SpeechManager_Unit>()).ToList()); }
void CheckSpeech(Unit u, string[] texts, string arg) { if (u == m_Unit) { StopAllCoroutines(); TF.text = string.Format(texts[0], arg); TextPlate.SetActive(true); StartCoroutine(M_Math.ExecuteDelayed(texts.Length * 0.5f + 2.5f, () => TextPlate.SetActive(false))); } }
void _update(float time) { if (_spawnedArrow == null && Arrow != null) { Vector3 center = TileManager.Instance.GetTileList().Where(t => t.isCamp).Select(t => t.transform).ToList().Center(); Transform parent = M_Math.GetClosestGameObject(center, TileManager.Instance.GetTileList().Where(t => t.isCamp).Select(t => t.gameObject).ToArray()).transform; _spawnedArrow = Arrow.Instantiate(parent, true); } }
public override Speech GetSpeech() { if (M_Math.Roll(Chance)) { return(M_Weightable.GetWeighted(Speeches)); } return(null); }
protected void AttemptMove(Vector3 move) { if (Bounds != null) { transform.AttemptMoveInBounds(Bounds.Bounds(), move, M_Math.GetCameraCenter()); } else { transform.Translate(move, Space.World); } }
public virtual Speech GetSpeech(string trigger) { SpeechTriggerConfigIDGroupConfig _speech = Groups.FirstOrDefault(gr => gr.ID == trigger); if (_speech != null && M_Math.Roll(_speech.Chance)) { return(M_Weightable.GetWeighted(_speech.Speeches)); } return(null); }
void TriggerDelayed(Speech speech, float delay) { if (speech != null) { StartCoroutine(M_Math.ExecuteDelayed(delay, () => TriggerSpeech(m_Unit, speech.Lines))); } else { MDebug.LogWarning("speech not found"); } }
public LootConfig GetLootConfig(LootCategory cat) { List <LootConfig> configs = LootConfigs.Where(lc => lc.Category == cat).ToList(); /* List<WeightedRegion> configs = Regions.Where( r => ..... ) ).ToList(); * * WeightedRegion wr = WeightableFactory.GetWeighted(configs);*/ LootConfig conf = M_Math.GetRandomObject(configs); return(conf); }
void UpdateToNewTile(Tile t) { if (t == null) { return; } m_CurrentTile = t; m_CurrentTile.OnTileCrumble += OnMyTileUpdate; m_BorderGO.transform.position = M_Math.GetTransformBoundPositionTop(t.transform)[m_Corner]; }
public static Sequence SpawnBullet(BulletConfig Bullet, Transform start, Transform target) { if (Bullet.projectile == null) { return(DOTween.Sequence()); } // MDebug.Log("spawn bullet"); float distance = (start.position - target.position).magnitude; float time = distance / Bullet.speed; Vector3 offset_target = Random.insideUnitSphere * Bullet.randomOffset; Transform new_target = new GameObject().transform; M_Math.CopyTransform(target, new_target); new_target.SetParent(target); if (offset_target.magnitude > 0) { new_target.localPosition += offset_target; } GameObject bullet = GameObject.Instantiate(Bullet.projectile, start.position, start.rotation) as GameObject; //just to be safe we run an own sequence that is just based on time (and will be hooked to game logic) // Sequence delayed_call_back = DOTween.Sequence(); // delayed_call_back.AppendInterval(time); Sequence emit = DOTween.Sequence(); emit.Append(bullet.transform.DOMove(new_target.position, time).SetEase(Bullet.Animation_Curve)); // MDebug.Log("start move "+emit.Duration()); emit.AppendCallback(() => { // MDebug.Log("start kaputt"); bullet.transform.Translate(new_target.position - bullet.transform.position); }); emit.AppendInterval(0.1f); emit.AppendCallback(() => { bullet.transform.GetComponentsInChildren <ParticleSystem>().ToList().ForEach(b => b.StopAll()); bullet.transform.GetComponentsInChildren <ParticleSystem>().ToList().ForEach(b => b.RemoveAllParticlesWhenInactive()); bullet.transform.DetachChildren(); GameObject.Destroy(new_target.gameObject); GameObject.Destroy(bullet); }); return(emit); ; }
public static List <GameObject> SpawnSkinnedMeshToUnit(GameObject target_unit, GameObject head, GameObject suit) { Transform target_skeleton_root = target_unit.transform.FindDeepChild("humanoid"); List <SkinnedMeshRenderer> suitobjects = suit.GetComponentsInChildren <SkinnedMeshRenderer>().ToList(); suitobjects.AddRange(head.GetComponentsInChildren <SkinnedMeshRenderer>()); List <GameObject> skinned_objects = M_Math.InsantiateObjects(suitobjects.Select(skn => skn.gameObject).ToList()); skinned_objects.ForEach(obj => SkinnedMeshTools.AddSkinnedMeshTo(obj.gameObject, target_skeleton_root)); // MDebug.Log("spawn skinned " + skinned_objects.Count); return(skinned_objects); }
public IEnumerator TurnToTargetPositiom(Transform _target, EventHandler callback) { //cache the callback so we can call it before stopping coroutine if (callback != null) { handlers.Add(callback); } // MDebug.Log("Turn to"); yield return(new WaitForRotation(m_rotated.transform, M_Math.RotateToYSnapped(m_rotated.transform.position, _target.transform.position, 45), 0.35f)); // MDebug.Log("Rotated"); if (callback != null) { callback(); handlers.Remove(callback); } yield return(null); }
public void OnLoot(Unit _u) { int lootable_amount = GetLootableAmount(_u); if (lootable_amount > 0) { item_lootable.SetCount(item_lootable.GetCount() - lootable_amount); GetInventory(_u).ModifyItem(item_lootable.GetItemType(), lootable_amount); } crate.GetComponent <Animator>().SetTrigger("bOpened"); if (item_lootable.GetCount() == 0) { StartCoroutine(M_Math.ExecuteDelayed(2f, RemoveLoot)); // MDebug.Log("^loot removing loot soon"); } }
/// <summary> /// Moves the transform by a clamped move from a reference point. /// </summary> /// <param name="transform"></param> /// <param name="bounds"></param> /// <param name="move"></param> public static void AttemptMoveInBounds(this Transform transform, Bounds bounds, Vector3 move, Vector3 reference) { Vector3 targetCenterPos = reference + move; Debug.DrawLine(reference, targetCenterPos, Color.magenta); Vector3 clampedTargetCenterPos = M_Math.ClampInBounds(targetCenterPos, bounds); Debug.DrawLine(targetCenterPos, clampedTargetCenterPos, Color.red); move = clampedTargetCenterPos - reference; //StartCoroutine(M_Math.ExecuteDelayed(0.05f, () => Debug.Break())); Debug.DrawRay(reference, move, Color.yellow); // MDebug.Log(move); transform.Translate(move, Space.World); }
IEnumerator WaitForInput() { _waitingForInput = true; Vector3 startDragPos = M_Math.GetInputPos(); // MDebug.Log("Wait for input"); while (CanStartInput() && (startDragPos - M_Math.GetInputPos()).magnitude < PanThreshold) { yield return(null); } if (CanStartInput()) { StartCoroutine("DoPan"); } _waitingForInput = false; }
void OnSceneGUI(SceneView sceneView) { // Do your drawing here using Handles. Handles.BeginGUI(); if (weighted != null && Grid != null) { float sum_weights = weighted.Select(t => t.weight).Sum(); foreach (TileWeighted tw in weighted) { float percent = (tw.weight / sum_weights) * 100; if (percent > 0) { M_Math.SceneViewText(percent.ToString("00.00") + "%", Grid.Tiles[tw.tilePos.x, tw.tilePos.z].GetPosition(), Color.black); } } } Handles.EndGUI(); }