public TurretUndeployingState(GameObject npc, CannonController[] cannonControllers, BodyController baseController, AnimationController animationController): base(npc) { stateID = StateID.UnDeploying; turretActor = npc.GetComponent<SuperTurret>(); this.cannonControllers = cannonControllers; this.baseController = baseController; this.animationController = animationController; }
/// <summary> /// Main actor will call this method. /// </summary> /// <param name="actor"> /// Turret actor where controller gets info, /// </param> public void setTurretActor(SuperTurret actor) { turretActor=actor; }
public TurretAttackingState(GameObject npc):base(npc) { stateID = StateID.Attacking; turretActor = npc.GetComponent<SuperTurret>(); }
public TurretIdleState(GameObject obj):base(obj) { stateID = StateID.Idle; turretActor = obj.GetComponent<SuperTurret>(); }
/// <summary> /// Add or remove targeting area to the turret. /// </summary> /// <param name='turret'> /// Turret. /// </param> void TargetingArea (SuperTurret turret) { if(turret.hasTargetingArea) { Handles.color = Color.yellow; SphereCollider sphereCollider; if(turret.targetingArea == null) { GameObject newTargetingArea = new GameObject("TargetingArea"); newTargetingArea.layer = LayerMask.NameToLayer("Ignore Raycast"); newTargetingArea.transform.parent = turret.transform; newTargetingArea.transform.localPosition = Vector3.zero; sphereCollider = newTargetingArea.AddComponent<SphereCollider>(); Area scriptArea = newTargetingArea.AddComponent<Area>(); turret.targetingArea = scriptArea; sphereCollider.radius = turret.attackArea.GetComponent<SphereCollider>().radius+10;; sphereCollider.isTrigger = true; sphereCollider.radius = Handles.RadiusHandle(turret.transform.rotation,turret.transform.position,sphereCollider.radius,true); }else{ sphereCollider = turret.targetingArea.GetComponent<Collider>() as SphereCollider; sphereCollider.radius = Handles.RadiusHandle(turret.transform.rotation,turret.transform.position,sphereCollider.radius,true); } // Targeting area mus be always major than attack area turret.targetingArea.GetComponent<SphereCollider>().radius = Mathf.Clamp(turret.targetingArea.GetComponent<SphereCollider>().radius,turret.attackArea.GetComponent<SphereCollider>().radius,float.MaxValue); Handles.color = new Color(Color.yellow.r,Color.yellow.g,Color.yellow.b,0.05f); Handles.DrawSolidDisc(turret.transform.position,turret.transform.up,sphereCollider.radius ); Handles.Label(turret.transform.position+(Vector3.up*sphereCollider.radius),"Targeting Area"); Handles.Label(turret.transform.position+(Vector3.left*sphereCollider.radius),"Targeting Area"); Handles.Label(turret.transform.position+(Vector3.right*sphereCollider.radius),"Targeting Area"); Handles.Label(turret.transform.position+(Vector3.down*sphereCollider.radius),"Targeting Area"); }else{ if(turret.targetingArea != null) { DestroyImmediate(turret.targetingArea.gameObject); } } }
/// <summary> /// Create an attacking area the first time and manage attacking area radius. /// </summary> /// <param name='turret'> /// Turret. /// </param> void AttackingArea(SuperTurret turret) { Handles.color = Color.red; SphereCollider sphereCollider; // Attacking area is needed if(turret.attackArea == null) { GameObject newAttackingArea = new GameObject("AttakingArea"); newAttackingArea.layer = LayerMask.NameToLayer("Ignore Raycast"); newAttackingArea.transform.parent = turret.transform; newAttackingArea.transform.localPosition = Vector3.zero; sphereCollider = newAttackingArea.AddComponent<SphereCollider>(); sphereCollider.isTrigger = true; sphereCollider.radius = 10; Area scriptArea = newAttackingArea.AddComponent<Area>(); turret.attackArea = scriptArea; }else{ sphereCollider = turret.attackArea.GetComponent<Collider>() as SphereCollider; } sphereCollider.radius = Handles.RadiusHandle(turret.transform.rotation,turret.transform.position,sphereCollider.radius,true); // Attack area must be always major than minimum distance and minnor than tagreting area if (turret.hasTargetingArea) turret.attackArea.GetComponent<SphereCollider>().radius = Mathf.Clamp(turret.attackArea.GetComponent<SphereCollider>().radius,turret.minimumDistance,turret.targetingArea.GetComponent<SphereCollider>().radius); else turret.attackArea.GetComponent<SphereCollider>().radius = Mathf.Clamp(turret.attackArea.GetComponent<SphereCollider>().radius,turret.minimumDistance,float.MaxValue); Handles.color = new Color(Color.red.r,Color.red.g,Color.red.b,0.06f); Handles.DrawSolidDisc(turret.transform.position,turret.transform.up,sphereCollider.radius ); Handles.Label(turret.transform.position+(Vector3.up*sphereCollider.radius),"Attacking Area"); Handles.Label(turret.transform.position+(Vector3.left*sphereCollider.radius),"Attacking Area"); Handles.Label(turret.transform.position+(Vector3.right*sphereCollider.radius),"Attacking Area"); Handles.Label(turret.transform.position+(Vector3.down*sphereCollider.radius),"Attacking Area"); }
/// <summary> /// Control the minimum distance of turret to attack. /// </summary> /// <param name='turret'> /// Turret. /// </param> void MinimumAttackDistance(SuperTurret turret) { Handles.color = new Color(Color.blue.r,Color.blue.g,Color.blue.b,1f); if (turret.minimumDistance == 0) { if (turret.bodyController != null) { float width = turret.attackArea.GetComponent<SphereCollider>().radius / 4f; turret.minimumDistance = width; } } turret.minimumDistance = Handles.ScaleValueHandle(turret.minimumDistance, turret.transform.position+(Vector3.right*turret.minimumDistance), turret.transform.rotation, 2, Handles.SphereCap, 2); turret.minimumDistance = Handles.ScaleValueHandle(turret.minimumDistance, turret.transform.position+(Vector3.left*turret.minimumDistance), turret.transform.rotation, 2, Handles.SphereCap, 2); turret.minimumDistance = Mathf.Clamp(turret.minimumDistance,2,turret.attackArea.GetComponent<SphereCollider>().radius); //turret.minimumDistance = Handles.RadiusHandle(turret.transform.rotation,turret.transform.position,turret.minimumDistance,false); Handles.color = new Color(Color.blue.r,Color.blue.g,Color.blue.b,0.05f); Handles.DrawSolidDisc(turret.transform.position,turret.transform.up,turret.minimumDistance); Handles.color = new Color(Color.blue.r,Color.blue.g,Color.blue.b,1f); Handles.Label(turret.transform.position+(Vector3.left*turret.minimumDistance),"Minimum distance"); Handles.Label(turret.transform.position+(Vector3.right*turret.minimumDistance),"Minimum distance"); }
void InspectorTags(SuperTurret turret) { turret.tagsExpanded = EditorGUILayout.Foldout( turret.tagsExpanded,"Tags"); if(turret.tagsExpanded) { EditorGUILayout.HelpBox("The turret will attack all enemies with a tag contained in your tag list. Wich target to attack first depends on your target selection strategy.",MessageType.Info); turret.tagsNumber = EditorGUILayout.IntField("Number of tags",turret.tagsNumber); if(turret.targetTags.Length != turret.tagsNumber) { string[] tags = new string[turret.tagsNumber]; for (int x = 0; x< turret.tagsNumber; x++) { if (turret.targetTags.Length > x) tags[x] = turret.targetTags[x]; } turret.targetTags = tags; } for (int x =0; x < turret.targetTags.Length; x++) { turret.targetTags[x] = EditorGUILayout.TagField("Enemy Tag "+x,turret.targetTags[x]); } } }
void InspectorCannons(SuperTurret turret) { turret.cannonsExpanded = EditorGUILayout.Foldout( turret.cannonsExpanded,"Cannons"); if(turret.cannonsExpanded) { turret.cannonsNumber = EditorGUILayout.IntField("Number of cannons",turret.cannonsNumber); if(turret.cannonsNumber == 0) // 1 canon minimum turret.cannonsNumber = 1; if(turret.cannonControllers.Length != turret.cannonsNumber) { CannonController[] cannons = new CannonController[turret.cannonsNumber]; for (int x = 0; x< turret.cannonsNumber; x++) { if (turret.cannonControllers.Length > x) cannons[x] = turret.cannonControllers[x]; } turret.cannonControllers = cannons; } for (int x =0; x < turret.cannonControllers.Length; x++) { turret.cannonControllers[x] = EditorGUILayout.ObjectField("Cannon "+x, turret.cannonControllers[x], typeof(CannonController),true) as CannonController; } } }