void SetControllable(Controllable controllable) { if (this.controllable) { this.controllable.MoveHorizontally(0); } this.controllable = controllable; if (controllable) { follow.target = controllable.transform; var mergeable = controllable.GetComponent <Mergeable>(); if (mergeable) { mergeable.MergedInto += merged => { SetControllable(merged.GetComponent <Controllable>()); if (mergeSound) { audioSource?.PlayOneShot(mergeSound); } }; } var splitable = controllable.GetComponent <Splitable>(); if (splitable) { splitable.Splitted += (first, second) => { SetControllable(first.GetComponent <Controllable>()); if (splitSound) { audioSource?.PlayOneShot(splitSound); } }; } } }
protected override void AssignThisJob(Controllable assignee, bool? appendToTaskQueue) { base.AssignThisJob(assignee, appendToTaskQueue); if(!appendToTaskQueue.HasValue) { assignee.AddTaskInterruptAfterCurrent(new MoveResourceTask(assignee.GetComponent<MoveResourceTaskScript>(), this)); } else { assignee.AddTask(new MoveResourceTask(assignee.GetComponent<MoveResourceTaskScript>(), this), appendToTaskQueue.Value); } }
/// <summary> /// Sets the Controllable Object. /// </summary> /// <param name = "obj"> /// Object to be set as the controllable that is activated /// when action happens(non hero). /// </param> public static void SetControllableObject(Controllable obj) { if (obj.GetComponent <Hero>() == null) { controllableObject = obj; } }
/// <summary> /// Resets the Controllable Object. /// </summary> /// <param name = "obj"> /// Reset object to be controlled when action happens. /// While reset, no object will receive keyboard or camera focus. /// </param> public static void ResetControllableObject(Controllable obj) { if (obj.GetComponent <Hero>() != null) { controllableObject = null; } }
protected static bool GetOrigin(uLink.NetworkPlayer player, bool eyes, out Vector3 origin) { PlayerClient playerClient; Transform transforms; ServerManagement serverManagement = ServerManagement.Get(); if (serverManagement && serverManagement.GetPlayerClient(player, out playerClient)) { Controllable controllable = playerClient.controllable; if (controllable) { Character component = controllable.GetComponent <Character>(); if (!component) { transforms = controllable.transform; } else { transforms = (!eyes || !component.eyesTransformReadOnly ? component.transform : component.eyesTransformReadOnly); } origin = transforms.position; return(true); } } origin = new Vector3(); return(false); }
private void AbsorbStats() { Stats targetsStats = controllableTarget.GetComponent <Stats>(); if (targetsStats != null) { GetComponent <Stats>().ChangeStatsToTargets(targetsStats); } }
void SubscribeToSelectedObjectComponents(Controllable selectedObject) { selectedObjectPropertySubs.Clear(); // Clear disposes all the disposables, but le if (selectedObject == null) { selectedUnitHealthText.text = string.Empty; } else { var damManager = selectedObject.GetComponent <DamageManager>(); damManager.HitPointStream.SubscribeToText(selectedUnitHealthText, hp => "Health: " + hp.ToString()).AddTo(selectedObjectPropertySubs); } }
public void PlayerUse(Controllable controllable) { if (base.BelongsTo(controllable)) { if (!this.IsValidToSpawn()) { return; } if (controllable.GetComponent <Inventory>().AddItemAmount(DatablockDictionary.GetByName(this.giveItemName), 1) == 1) { return; } } }
private ActivationResult ActRoute(bool?on, Controllable controllable, ulong timestamp) { Character component; bool? nullable = on; if (!controllable) { component = null; } else { component = controllable.GetComponent <Character>(); } return(this.ActRoute(nullable, component, timestamp)); }
// Behavior when controlling a block // Entered from: Normal(sit button) // Exit to: Normal(sit button) void ControllingUpdate() { // used to steer the ship float x_val = input.LeftStickX * DRIVE_SPEED_X; float y_val = input.LeftStickY * DRIVE_SPEED_Y; controlled_block.GetComponent <Rigidbody2D>().velocity = new Vector3(x_val, y_val, 0f); transform.position = controlled_block.transform.position; FlipAllSprites(x_val); // Detach from the block if the user wants to if (!input.Action1.IsPressed) { DetachFromBlock(); return; } }
protected void UnstickMove(Vector3 point) { Transform transforms; PlayerClient playerClient = PlayerClient.localPlayerClient; if (playerClient) { Controllable controllable = playerClient.controllable; if (controllable) { Character component = controllable.GetComponent <Character>(); transforms = (!component ? controllable.transform : component.transform); if (transforms) { this.hasUnstickPosition = true; this.nextUnstickPosition = point; this.unstickTransform = transforms; this.UnstickInvoke(); base.Invoke("UnstickInvoke", 0.25f); } } } }
public void Update() { Vector3 zero = Vector3.zero; float speed = 0f; float height = 1024f; PlayerClient localPlayer = PlayerClient.GetLocalPlayer(); Controllable controllable = (localPlayer == null) ? null : localPlayer.controllable; if (controllable != null) { zero = controllable.transform.position; Vector3 vector2 = zero - vOldPosition; if ((vOldPosition != Vector3.zero) && (zero != Vector3.zero)) { speed = vector2.magnitude; } vOldPosition = zero; if (controllable.GetComponent <Character>() != null) { RaycastHit hit; if (Physics.SphereCast(new Ray(zero + ((Vector3)(Vector3.up * 0.5f)), Vector3.down), 0.3f, out hit, 256f, 0x20180403)) { height = hit.distance; } else { height = 1024f; } } } else { vOldPosition = Vector3.zero; } a7d4f2d0762c4d5f3cf94d9da25207d8(Application.loadedLevel, zero.x, zero.y, zero.z, height, speed, 1f / Time.smoothDeltaTime); SteamClient_Cycle(); }
protected override bool CanTakeThisJob(Controllable assignee) { return Assignees.Count == 0 && assignee.GetComponent<MoveResourceTaskScript>() != null && ResourceDepot.FindAllDepotsWithResource(Resource, Owner).Count > 0; }
public void UpdateGUIAmounts() { BlueprintDataBlock blueprintDataBlock; if (this._benchItem != null) { Controllable localPlayer = PlayerClient.GetLocalPlayer().controllable; if (localPlayer == null) { return; } Inventory component = localPlayer.GetComponent <Inventory>(); int num = 0; if (!this._benchItem.IsDamaged()) { this.needsLabel.text = "Does not need repairs"; this.needsLabel.color = Color.green; this.needsLabel.enabled = true; float single = this._benchItem.condition * 100f; string str = single.ToString("0"); float single1 = this._benchItem.maxcondition * 100f; string str1 = single1.ToString("0"); this.conditionLabel.text = string.Concat("Condition : ", str, "/", str1); this.conditionLabel.color = Color.green; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(false); UILabel[] uILabelArray = this._amountLabels; for (int i = 0; i < (int)uILabelArray.Length; i++) { UILabel empty = uILabelArray[i]; empty.text = string.Empty; empty.color = Color.white; } } else { if (BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(this._benchItem.datablock, out blueprintDataBlock)) { int num1 = 0; while (num1 < (int)blueprintDataBlock.ingredients.Length) { if (num < (int)this._amountLabels.Length) { BlueprintDataBlock.IngredientEntry ingredientEntry = blueprintDataBlock.ingredients[num1]; int num2 = Mathf.CeilToInt((float)blueprintDataBlock.ingredients[num1].amount * this._bench.GetResourceScalar()); if (num2 > 0) { bool flag = component.CanConsume(blueprintDataBlock.ingredients[num1].Ingredient, num2) > 0; this._amountLabels[num].text = string.Concat(num2, " ", blueprintDataBlock.ingredients[num1].Ingredient.name); this._amountLabels[num].color = (!flag ? Color.red : Color.green); num++; } num1++; } else { break; } } } this.needsLabel.color = Color.white; this.needsLabel.enabled = true; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(true); float single2 = this._benchItem.condition * 100f; string str2 = single2.ToString("0"); float single3 = this._benchItem.maxcondition * 100f; string str3 = single3.ToString("0"); this.conditionLabel.text = string.Concat("Condition : ", str2, "/", str3); this.conditionLabel.color = (this._benchItem.condition >= 0.6f ? Color.green : Color.yellow); if (this._benchItem.IsBroken()) { this.conditionLabel.color = Color.red; } } } else { UILabel[] uILabelArray1 = this._amountLabels; for (int j = 0; j < (int)uILabelArray1.Length; j++) { UILabel uILabel = uILabelArray1[j]; uILabel.text = string.Empty; uILabel.color = Color.white; } this.needsLabel.enabled = false; this.conditionLabel.enabled = false; this.repairButton.gameObject.SetActive(false); } }
// Update is called once per frame void Update() { if (Input.touchCount == 3) { Touch t1 = Input.GetTouch(0); Touch t2 = Input.GetTouch(1); Touch t3 = Input.GetTouch(2); bool startTimer = false; if (((t1.phase == TouchPhase.Began) || (t2.phase == TouchPhase.Began) || (t3.phase == TouchPhase.Began)) && colorTimer == .5f) { startTimer = true; foreach (GameObject g in walls) { if (!wallsAreGreen) { g.GetComponent <Renderer>().material.color = Color.green; } else { g.GetComponent <Renderer>().material.color = Color.magenta; } } } if (startTimer) { colorTimer -= Time.deltaTime; } if ((t1.phase == TouchPhase.Ended) || (t2.phase == TouchPhase.Ended) || (t3.phase == TouchPhase.Ended)) { colorTimer = .5f; wallsAreGreen = !wallsAreGreen; startTimer = false; } } if (Input.touchCount == 0) { timer = .3f; } if (Input.touchCount > 0) { holdOrTap = FingerType.Tap; timer -= Time.deltaTime; if (timer <= 0) { holdOrTap = FingerType.Hold; } } if (Input.touchCount == 1) { timer -= Time.deltaTime; Touch firstTouch = Input.GetTouch(0); Ray myRay = myCamera.ScreenPointToRay(firstTouch.position); Debug.DrawRay(myRay.origin, 20 * myRay.direction); if (firstTouch.phase == TouchPhase.Moved && holdOrTap == FingerType.Hold && noSelected == 0) { Debug.Log("Camera should about to move"); Vector2 touchPosition = firstTouch.deltaPosition; myCamera.transform.Translate(-touchPosition.x * cameraMoveSpeed, -touchPosition.y * cameraMoveSpeed, 0); } RaycastHit infoOnHit; if (Physics.Raycast(myRay, out infoOnHit)) { Controllable myScript = infoOnHit.transform.GetComponent <Controllable>(); if (myScript != selected && holdOrTap == FingerType.Tap) { if (noSelected < MAX_SELECTED) { noSelected = MAX_SELECTED; deSelected = myScript; selected = myScript; } deSelected = selected; deSelected.isSelected = false; selected = myScript; selected.isSelected = true; movableObject = selected.gameObject; dragDistance = Vector3.Distance(movableObject.transform.position, myCamera.transform.position); } if (noSelected != 0 && holdOrTap == FingerType.Hold) { if (firstTouch.phase == TouchPhase.Began) { } if (firstTouch.phase == TouchPhase.Moved) { Ray dragRay = myCamera.ScreenPointToRay(firstTouch.position); Vector3 newDestination = dragRay.GetPoint(dragDistance); movableObject.GetComponent <Controllable>().move(newDestination); } if (firstTouch.phase == TouchPhase.Ended) { } } } } if (Input.touchCount == 2) { Touch firstTouch = Input.GetTouch(0); Touch secondTouch = Input.GetTouch(1); if (noSelected == 0) { if (firstTouch.phase == TouchPhase.Began || secondTouch.phase == TouchPhase.Began) { initialFirstPos = firstTouch.position; initialSecondPos = secondTouch.position; initialDistance = Vector3.Distance(initialFirstPos, initialSecondPos); Vector2 distance = secondTouch.position - firstTouch.position; angleBetweenTouches = Mathf.Atan2(distance.x, distance.y); Quaternion originalRotation = myCamera.transform.rotation; } if (firstTouch.phase == TouchPhase.Moved || secondTouch.phase == TouchPhase.Moved) { Vector3 firstPos = firstTouch.position; Vector3 secondPos = secondTouch.position; float movingDistance = Vector3.Distance(firstTouch.position, secondTouch.position); float percentageOfScale = movingDistance / initialDistance; if (percentageOfScale > 1) { myCamera.transform.position += Vector3.forward * (Time.deltaTime * zoomSpeed); } else { myCamera.transform.position -= Vector3.forward * (Time.deltaTime * zoomSpeed); } Vector2 newDistance = secondTouch.position - firstTouch.position; float newAngleBetweenTouches = Mathf.Atan2(newDistance.x, newDistance.y); float differenceInAngles = newAngleBetweenTouches - angleBetweenTouches; myCamera.transform.rotation = originalRotation * Quaternion.AngleAxis(Mathf.Rad2Deg * (newAngleBetweenTouches - angleBetweenTouches), myCamera.transform.up); } } else { if ((firstTouch.phase == TouchPhase.Began) || (secondTouch.phase == TouchPhase.Began)) { initialFirstPos = firstTouch.position; initialSecondPos = secondTouch.position; initialDistance = Vector3.Distance(initialFirstPos, initialSecondPos); Vector2 distance = secondTouch.position - firstTouch.position; angleBetweenTouches = Mathf.Atan2(distance.x, distance.y); } if ((firstTouch.phase == TouchPhase.Moved || secondTouch.phase == TouchPhase.Moved)) { Vector3 firstPos = firstTouch.position; Vector3 secondPos = secondTouch.position; float movingDistance = Vector3.Distance(firstTouch.position, secondTouch.position); float percentageOfScale = movingDistance / initialDistance; selected.GetComponent <Controllable>().scale(percentageOfScale); Vector2 newDistance = secondTouch.position - firstTouch.position; float newAngleBetweenTouches = Mathf.Atan2(newDistance.x, newDistance.y); float differenceInAngles = newAngleBetweenTouches - angleBetweenTouches; selected.GetComponent <Controllable>().rotate(differenceInAngles); } } } }
public void GotKill (Controllable victim) { var scoreBoard = FindObjectOfType<ScoreBoard> (); var enemy = victim.GetComponent<Enemy> (); if (enemy == null) return; scoreBoard.AddScore (enemy.pointsWorth); if(Random.value < chanceForEnemyToDropHats) { var hat = GameObject.Instantiate (allHats [Random.Range (0, allHats.Length)]); hat.transform.position = victim.transform.position; } }
private ActivationResult ActRoute(bool?on, Controllable controllable, ulong timestamp) { return(this.ActRoute(on, (controllable == null) ? null : controllable.GetComponent <Character>(), timestamp)); }
public void UpdateGUIAmounts() { if (this._benchItem == null) { foreach (UILabel label in this._amountLabels) { label.text = string.Empty; label.color = Color.white; } this.needsLabel.enabled = false; this.conditionLabel.enabled = false; this.repairButton.gameObject.SetActive(false); } else { Controllable controllable = PlayerClient.GetLocalPlayer().controllable; if (controllable != null) { Inventory component = controllable.GetComponent <Inventory>(); int index = 0; if (!this._benchItem.IsDamaged()) { this.needsLabel.text = "Does not need repairs"; this.needsLabel.color = Color.green; this.needsLabel.enabled = true; string str3 = (this._benchItem.condition * 100f).ToString("0"); string str4 = (this._benchItem.maxcondition * 100f).ToString("0"); this.conditionLabel.text = "Condition : " + str3 + "/" + str4; this.conditionLabel.color = Color.green; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(false); foreach (UILabel label2 in this._amountLabels) { label2.text = string.Empty; label2.color = Color.white; } } else { BlueprintDataBlock block; if (BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(this._benchItem.datablock, out block)) { for (int i = 0; i < block.ingredients.Length; i++) { if (index >= this._amountLabels.Length) { break; } BlueprintDataBlock.IngredientEntry entry = block.ingredients[i]; int useCount = Mathf.CeilToInt(block.ingredients[i].amount * this._bench.GetResourceScalar()); if (useCount > 0) { bool flag = component.CanConsume(block.ingredients[i].Ingredient, useCount) > 0; this._amountLabels[index].text = useCount + " " + block.ingredients[i].Ingredient.name; this._amountLabels[index].color = !flag ? Color.red : Color.green; index++; } } } this.needsLabel.color = Color.white; this.needsLabel.enabled = true; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(true); string str = (this._benchItem.condition * 100f).ToString("0"); string str2 = (this._benchItem.maxcondition * 100f).ToString("0"); this.conditionLabel.text = "Condition : " + str + "/" + str2; this.conditionLabel.color = (this._benchItem.condition >= 0.6f) ? Color.green : Color.yellow; if (this._benchItem.IsBroken()) { this.conditionLabel.color = Color.red; } } } } }
protected override bool CanTakeThisJob(Controllable assignee) { return assignee.GetComponent<BuildTaskScript>() != null; }