Exemplo n.º 1
0
		public override void Start()
		{
			base.Start();

			wanderIdleTimer = 0.1f;
			currPatrolPoint = 0;

			_startupPathHelper = patrolPath;
			if (patrolPath == null && idleAction == UniRPGGlobal.AIBehaviour.Patrol)
			{
				Debug.LogError("IdleAction.Patrol selected but no Patrol Path specified.");
				enabled = false;
				IsPersistent = false;
				return;
			}

			if (SpawnPoint == null) SpawnLocation = _tr.position;

			// create detection trigger (eyes)
			eyes = new GameObject("_DETECT_PLAYER_");
			eyes.layer = gameObject.layer;
			eyes.transform.position = transform.position;
			eyes.transform.rotation = transform.rotation;
			eyes.transform.parent = transform;
			SphereCollider col = eyes.AddComponent<SphereCollider>();
			col.isTrigger = true;
			col.radius = detectionRadius;

			if (actorType != UniRPGGlobal.ActorType.Hostile)
			{	// no need for eyes to be active if not hostile
				eyes.SetActive(false);
			}

			if (GetComponent<Rigidbody>()) GetComponent<Rigidbody>().isKinematic = true;
		}
Exemplo n.º 2
0
		public override void SetSpawnPoint(SpawnPoint sp)
		{
			base.SetSpawnPoint(sp);

			// init AI
			idleAction = sp.idleAction;
			wanderInCricle = sp.wanderInCricle;
			wanderWH = sp.wanderWH;
			wanderRadius = sp.wanderRadius;
			SpawnLocation = sp.transform.position;
			wanderDelayMin = sp.wanderDelayMin;
			wanderDelayMax = sp.wanderDelayMax;
			patrolPath = sp.patrolPath;

			wanderIdleTimer = 0.1f;
			currPatrolPoint = 0;

			if (patrolPath == null && idleAction == UniRPGGlobal.AIBehaviour.Patrol)
			{
				Debug.LogError("IdleAction.Patrol selected but no Patrol Path specified.");
				enabled = false;
				IsPersistent = false;
				return;
			}
		}
Exemplo n.º 3
0
		protected override void LoadState()
		{
			base.LoadState();
			if (UniRPGGlobal.Instance.DoNotLoad) return;

			chaseSpeed = UniRPGGlobal.LoadFloat(saveKey + "chaseSpeed", chaseSpeed);
			_tr.position = UniRPGGlobal.LoadVector3(saveKey + "pos", _tr.position);

			if (idleAction != UniRPGGlobal.AIBehaviour.Stay)
			{
				_tr.position += new Vector3(0f, 0.1f, 0f); // for sanity sake cause sometimes it falls through floor after spawned
			}

			actorType = (UniRPGGlobal.ActorType)UniRPGGlobal.LoadInt(saveKey + "type", (int)actorType);
			idleAction = (UniRPGGlobal.AIBehaviour)UniRPGGlobal.LoadInt(saveKey + "idleAct", (int)idleAction);
			if (idleAction == UniRPGGlobal.AIBehaviour.Wander)
			{
				wanderInCricle = UniRPGGlobal.LoadBool(saveKey + "wndr_is_c", wanderInCricle);
				wanderWH = UniRPGGlobal.LoadVector3(saveKey + "wndr_rec", wanderWH);
				wanderRadius = UniRPGGlobal.LoadFloat(saveKey + "wndr_r", wanderRadius);
				wanderDelayMin = UniRPGGlobal.LoadFloat(saveKey + "wnrd_dmin", wanderDelayMin);
				wanderDelayMax = UniRPGGlobal.LoadFloat(saveKey + "wndr_dmax", wanderDelayMax);
			}
			if (idleAction == UniRPGGlobal.AIBehaviour.Patrol)
			{
				string s = UniRPGGlobal.LoadString(saveKey + "patrol", null);
				if (!string.IsNullOrEmpty(s))
				{	// find the path in the scene
					GameObject parent = GameObject.Find("PatrolPaths");
					if (parent)
					{
						GUID id = new GUID(s);
						if (!id.IsEmpty)
						{
							PatrolPath[] paths = parent.GetComponentsInChildren<PatrolPath>();
							for (int i = 0; i < paths.Length; i++)
							{
								if (paths[i].id == id)
								{
									patrolPath = paths[i];
								}
							}
						}
					}
				}
			}

		}