public bool IsOverTarget(TargetBehaviour target) { float distanceFinalTargetToSelectionPosition = Vector3.Distance(target.position, GetCursorPosition()); float maxDistanceToHitTarget = 0.5f * (target.localScale.x + this.transform.localScale.x); // this will only work for target and cursor represented as spheres return(distanceFinalTargetToSelectionPosition <= maxDistanceToHitTarget); }
public void CastRay() { muzzleSmoke.Play(); RaycastHit hit; if (Physics.Raycast(gunnerCam.transform.position, gunnerCam.transform.forward, out hit, range)) { if (Debugging) { Debug.Log(hit.transform.name); } TargetBehaviour target = hit.transform.GetComponent <TargetBehaviour>(); if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 2f); } }
public Mob(ContentManager content, Vector2 position, CharactersInRange charactersInRange, OnDeath onDeath, CollisionCheck collisionCheck, String monsterName) : base(content, position, SPEED, charactersInRange, onDeath, Constants.DEFAULT_HEALTH) { StaticDrawable2D character = getCharacterSprite(content, position, monsterName); base.init(character); BehaviourFinished idleCallback = delegate() { swapBehaviours(this.idleBehaviour, State.Idle); }; BehaviourFinished restartPathing = delegate() { #if DEBUG Debug.log("Restarting"); #endif //this.activeBehaviour.Target = this.LastKnownLocation; pathToWaypoint(this.LastKnownLocation); }; this.seekingBehaviour = new Tracking(position, SPEED, idleCallback, collisionCheck); this.lostTargetBehaviour = new LostTarget(this.seekingBehaviour.Position, this.seekingBehaviour.Position, SPEED, idleCallback); this.pathingBehaviour = new Pathing(position, SPEED, idleCallback, collisionCheck, restartPathing); this.idleBehaviour = new IdleBehaviour(position); this.activeBehaviour = this.idleBehaviour; this.CurrentState = State.Idle; updateBoundingSphere(); this.previousPoint = base.Position.toPoint(); this.LastKnownLocation = base.Position; this.skills = new List <Skill>(); this.explosionSfx = LoadingUtils.load <SoundEffect>(content, "CorpseExplosion"); initSkills(); }
public override void ExitTarget(TargetBehaviour target) { target.UnhighlightTarget(); currentTargetsCollidingWithCursor.Remove(target); // When a TargetBehaviour is destroyed while inside the HashSet, it will become a 'null' entry that must be removed currentTargetsCollidingWithCursor.RemoveWhere((TargetBehaviour t) => { return(t == null); }); if (currentTargetsCollidingWithCursor.Count > 0) { foreach (TargetBehaviour t in currentTargetsCollidingWithCursor) { currentHighlightedTarget = t; break; } } else { currentHighlightedTarget = null; } #if DEBUG_CURSOR Debug.Log("TargetExit: " + target.name + " pos= " + target.transform.position); #endif ExecuteForEachCursorListener((ICursorListener listener) => { listener.CursorExitedTarget(target); }); }
void SpawnTarget() { int idx = Random.Range(0, targets.Count);//Genera un número aleatorio entre 0 y targets.Count -1 TargetBehaviour target = targets[idx]; target.ShowTarget(); }
void SpawnTarget() { int index = Random.Range(0, targets.Count); TargetBehaviour target = targets[index]; target.ShowTarget(); }
void OnShoot() { RaycastHit hit; if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit)) { Destructable destruct = hit.transform.GetComponent <Destructable>(); TargetBehaviour target = hit.transform.GetComponent <TargetBehaviour>(); if (target != null) { target.TakeDamage(); } else if (destruct != null) { destruct.TakeDamage(); } else { GameObject shoot = Instantiate(shootingEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(shoot, 0.1f); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(hit.normal * addForce); } } }
public async Task ApplyToSelectedTarget(string text, GameObject target = null) { try { if (this.ms.selector.Target == null && target == null) { Debug.Log("You should select a target before compiling script to attach to target!"); return; } TargetBehaviour tb = null; if (this.ms.selector.Target != null) { tb = this.ms.selector.Target.GetComponent <TargetBehaviour>(); } if (tb != null && (tb.type == TargetType.Test || tb.type == TargetType.BattleMovement || tb.type == TargetType.BattleMoveSameDom)) { byte[] assBytes = await Task.Run(() => { var bytes = OtherAppDomainCompile(text); return(bytes); }); string result = string.Empty; if (tb.type == TargetType.Test) { result = (await tb.Test(assBytes)).ToString(); } else if (tb.type == TargetType.BattleMovement || tb.type == TargetType.BattleMoveSameDom) { tb.RegisterAI(assBytes); result = "AI Loaded!"; } Debug.Log("Test Result: " + result); } else { if (target == null) { target = this.ms.selector.Target; } var functions = await Task.Run(() => { var funcs = this.SameAppDomainCompile(text, true); return(funcs); }); var script = this.ms.attacher.AttachRuntimeMono(target, functions, text); } } catch (Exception ex) { Debug.LogError(ex.ToString()); } }
public void CursorExitedTarget(TargetBehaviour target) { if (lastTarget != null && target.targetId == lastTarget.targetId) { lastTarget = null; FinishSelection(); } }
public void Initialize() { attack = GetComponent <AttackBehaviour> (); target = GetComponent <TargetBehaviour> (); movement = GetComponent <MovementBehaviour> (); evade = GetComponent <EvadeBehaviour> (); individual = GetComponent <Individual> (); }
public void CursorTargetSelectionEnded(TargetBehaviour target) { if (target != null && target.type == TargetType.StartingTestTarget) { cursor.PlayCorrectAudio(); cursor.RemoveListener(this); StartTest(); } }
private void SendEvent() { TargetBehaviour componentInParent = this.collisionGameObject.GetComponentInParent <TargetBehaviour>(); if (componentInParent) { base.NewEvent <T>().Attach(this.TriggerEntity).Attach(componentInParent.TargetEntity).Schedule(); } }
// Use this for initialization void Start() { ship = gameObject.GetComponent <Ship> (); team = ship.GetTeam(); bullet = Resources.Load <GameObject> ("Bullet"); target = GetComponent <TargetBehaviour> (); evade = GetComponent <EvadeBehaviour> (); }
void SpawnTarget() { // Get a random target int index = Random.Range(0, targets.Count); TargetBehaviour target = targets[index]; // Show it target.ShowTarget(); }
public TrialController(int theTrialId, TargetBehaviour initialTarget, TargetBehaviour finalTarget, ITrialListener theListener, CursorBehaviour theCursor, TrialMeasurements lastTrial) { this.trialId = theTrialId; this.initialTarget = initialTarget; this.finalTarget = finalTarget; this.listener = theListener; this.cursor = theCursor; _lastTrial = lastTrial; InitializeTrial(); }
// Update is called once per frame void Update() { ray = new Ray(transform.position, transform.forward); hits = Physics.RaycastAll(ray, Mathf.Infinity); for (int i = hits.Length - 1; i >= 0; i--) { hit = hits[i]; Debug.Log(hit.transform.name); target = hit.transform.GetComponent<TargetBehaviour>(); target.hitTime += 0.05f; } }
void OnMouseDown() { if (Input.GetKey("space")) { GameObject target = GameObject.Find("Target"); TargetBehaviour trg = (TargetBehaviour)target.GetComponent("TargetBehaviour"); trg.GoToPosSmooth(this.transform.position); } else { Application.LoadLevel(Application.loadedLevel + 1); } }
public TrialMeasurements(int trialId, TargetBehaviour initialTarget, TargetBehaviour finalTarget, TrialMeasurements lastTrial) { this.lastTrial = lastTrial; this.trialId = trialId; this.initialTargetId = initialTarget.targetId; this.finalTargetId = finalTarget.targetId; this.initialTargetPosition = initialTarget.position; this.finalTargetPosition = finalTarget.position; this.initialTime = -1; this.timeActionStarted = -1; this.timeActionEnded = -1; this.trialDuration = -1; }
void Start () { _distanceVector = new Vector3(0.0f, 0.0f, -_distance); transform.position = newPos; actualTarget = new GameObject("Target"); actualTarget.transform.position = _target.position; trg = actualTarget.AddComponent<TargetBehaviour>(); trg.orb = this; this.Rotate(_x, _y); }
public void CursorEnteredTarget(TargetBehaviour target) { if (target.type == TargetType.NextTarget || target.type == TargetType.StartingTestTarget) { if (lastTarget == null || target.targetId != lastTarget.targetId) { lastTarget = target; selectionStarted = false; selectionEnded = false; timeEnteredLastTarget = Time.realtimeSinceStartup; } } }
public override void EnterTarget(TargetBehaviour target) { target.HighlightTarget(); currentTargetsCollidingWithCursor.Add(target); currentHighlightedTarget = target; #if DEBUG_CURSOR Debug.Log("TargetEnter: " + target.name + " pos= " + target.transform.position); #endif ExecuteForEachCursorListener((ICursorListener listener) => { listener.CursorEnteredTarget(target); }); }
private bool IsPointOccluded(ActiveTankNode activeTank, Vector3 splashCenter, Vector3 tankPosition) { RaycastHit hit; Vector3 vector = tankPosition - splashCenter; Vector3 normalized = vector.normalized; if (!Physics.Raycast(splashCenter, normalized, out hit, vector.magnitude, LayerMasks.GUN_TARGETING_WITHOUT_DEAD_UNITS)) { return(false); } TargetBehaviour componentInParent = hit.transform.gameObject.GetComponentInParent <TargetBehaviour>(); return(this.IsValidTarget(componentInParent) ? !ReferenceEquals(componentInParent.TargetEntity, activeTank.Entity) : true); }
void ManageSelectionInteraction(CursorSelectionTechnique selectionInteraction) { if (selectionInteraction.SelectionInteractionStarted()) { #if DRAG_START_WITH_CONTINUOUS_SELECTION numFramesSelectionIsActive = 0; #endif acquiredPosition = GetCursorPosition(); CursorTargetSelectionStarted(currentHighlightedTarget); } if (selectionInteraction.SelectionInteractionEnded()) { if (isDragging) { CursorDragTargetEnded(currentDraggedTarget, currentHighlightedTarget); #if DRAG_START_WITH_CONTINUOUS_SELECTION numFramesSelectionIsActive = 0; #endif currentDraggedTarget = null; isDragging = false; } CursorTargetSelectionEnded(currentHighlightedTarget); } else if (selectionInteraction.SelectionInteractionMantained()) { #if DRAG_START_WITH_CONTINUOUS_SELECTION numFramesSelectionIsActive++; if (!isDragging && numFramesSelectionIsActive > numFramesToStartDragInteraction) { #elif DRAG_START_WITH_CURSOR_MOVEMENT float distanceMoved = Vector3.Distance(acquiredPosition, GetCursorPosition()); if (!isDragging && distanceMoved > distanceToInitiateDrag) { #endif isDragging = true; currentDraggedTarget = currentHighlightedTarget; CursorDragTargetStarted(currentDraggedTarget); } } else { isDragging = false; #if DRAG_START_WITH_CONTINUOUS_SELECTION numFramesSelectionIsActive = 0; #endif } }
public override void CursorTargetSelectionEnded(TargetBehaviour target) { ExecuteForEachCursorListener((ICursorListener listener) => { listener.CursorTargetSelectionEnded(target); }); #if DEBUG_CURSOR if (target != null) { Debug.Log("Target selection ended: " + target.name); } else { Debug.Log("Target selection ended: none, cursor pos = " + cursorPositionController.GetCurrentCursorPosition()); } #endif }
public DragTestController(int theTrialId, TargetBehaviour initialTarget, TargetBehaviour finalTarget, ITrialListener theListener, CursorBehaviour theCursor, TrialMeasurements lastTrial) : base(theTrialId, initialTarget, finalTarget, theListener, theCursor, lastTrial) { draggableObject = Object.Instantiate(initialTarget.gameObject); var targetBehaviour = draggableObject.GetComponent <TargetBehaviour>(); targetBehaviour.UnhighlightTarget(); targetBehaviour.SetAsDraggableTarget(); Object.Destroy(targetBehaviour); draggableObject.transform.SetParent(cursor.transform); draggableObject.transform.localPosition = Vector3.zero; draggableObject.SetActive(false); }
public override void CursorTargetSelectionEnded(TargetBehaviour target) { //Debug.Log("Tapping CursorTargetSelectionEnded"); bool missedTarget = !cursor.IsOverTarget(finalTarget); if (missedTarget) { cursor.PlayErrorAudio(); } else { cursor.PlayCorrectAudio(); } ActionEnded(missedTarget); }
public void OnPointerUp(PointerEventData eventData) { if (!MouseDownOnMe) { return; } eventData.Use(); MouseDownOnMe = false; if (TargetBehaviour != null) { TargetBehaviour.OnFinalResize(); } UseDefaultCursor(); }
public override void CursorDragTargetStarted(TargetBehaviour target) { //Debug.Log("Drag CursorDragTargetStarted"); if (!isDraggingTarget && target != null && target.targetId == initialTarget.targetId && target.type == TargetType.DraggableTarget) { isDraggingTarget = true; draggableObject.SetActive(true); initialTarget.SetAsNormalTarget(); finalTarget.SetAsNextTarget(); trialData.ForceInitialTime(Time.realtimeSinceStartup); cursor.PlayCorrectAudio(); } else { cursor.PlayErrorAudio(); } ActionStarted(); }
private void swapBehaviours(TargetBehaviour newBehaviour, State state) { //if (!state.Equals(previousState)) { Debug.log("state changed from: " + previousState + "\t to: " + state); // reset the last known location ONLY if we were tracking if (isTracking()) { this.LastKnownLocation = this.activeBehaviour.Target; //this.tracking = null; } newBehaviour.Target = this.LastKnownLocation; newBehaviour.Position = this.activeBehaviour.Position; this.activeBehaviour = newBehaviour; this.CurrentState = state; // } if (!state.Equals(State.Pathing)) { // this.pathingBehaviour.stop(); } }
public override void Enter(Skill skill, EntityParent theOwner, GameSkillBase gameskill) { base.Enter(skill, theOwner, gameskill); //实例化箭头 if (ResourcePoolManager.singleton.dicEffectPool.ContainsKey(CommonDefineBase.TargetEffectPath)) { Transform prefab = ResourcePoolManager.singleton.dicEffectPool[CommonDefineBase.TargetEffectPath]; GameObject gameobject = PoolManager.Pools[PoolManager.EffectPoolName].Spawn(prefab).gameObject; if (gameSkill.Test) { gameobject.transform.position = Vector3.zero; gameobject.layer = LayerMask.NameToLayer("UI"); } else { gameobject.transform.position = new Vector3(12, 8, 0); gameobject.layer = LayerMask.NameToLayer("Default"); } TargetBehaviour = gameobject.GetComponent <TargetBehaviour>(); TargetBehaviour.text.gameObject.SetActive(true); TargetBehaviour.skill = gameskill as SelectDirSkill; } if (ResourcePoolManager.singleton.dicEffectPool.ContainsKey(CommonDefineBase.LineEffectPath)) { Transform prefab = ResourcePoolManager.singleton.dicEffectPool[CommonDefineBase.LineEffectPath]; GameObject gameobject = PoolManager.Pools[PoolManager.EffectPoolName].Spawn(prefab).gameObject; if (gameSkill.Test) { gameobject.layer = LayerMask.NameToLayer("UI"); Vector3 pos = gameobject.transform.position; pos.z = 24; gameobject.transform.position = pos; } else { gameobject.layer = LayerMask.NameToLayer("Default"); } line = gameobject.GetComponent <Line>(); line.Initialise((theOwner.bindNodeTable[CommonDefineBase.BindQiangkou] as Transform).position, TargetBehaviour.transform.position, 0.05f, Color.red);; } }
void Update() { if (info.IsAutomatic) { if (Input.GetButton("Fire1")) { RaycastHit hit; bool hitSuccess; (hitSuccess, hit) = controller.Shoot(); if (hitSuccess) { if (hit.transform.CompareTag("Target")) { TargetBehaviour target = hit.transform.GetComponent <TargetBehaviour>(); target.TakeDamage(Convert.ToSingle(info.Damage)); } } } } }
void Start() { _distanceVector = new Vector3(0.0f, 0.0f, -_distance); transform.position = newPos; actualTarget = new GameObject("Target"); actualTarget.transform.position = _target.position; trg = actualTarget.AddComponent<TargetBehaviour>(); trg.orb = this; this.Rotate(_x, _y); }