*
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
public class AIJob {
|
||||
public Action<HumanoidAI, AIJob> OnEnter;
|
||||
public Action<HumanoidAI, AIJob> OnExit;
|
||||
public Action<HumanoidAI, AIJob> OnUpdate;
|
||||
public Action<HumanoidAI, AIJob> OnFixedUpdate;
|
||||
public bool done;
|
||||
}
|
||||
|
||||
public class HumanoidAI : MonoBehaviour {
|
||||
public HumanController human;
|
||||
public float viewFov = 60;
|
||||
public float viewDistance = 2;
|
||||
public PlayerSensor viewSensor;
|
||||
|
||||
private Queue<AIJob> _actionQueue = new Queue<AIJob>();
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
void OnValidate() {
|
||||
var pc = human.eyes.GetComponent<PolygonCollider2D>();
|
||||
if (pc == null) {
|
||||
pc = human.eyes.AddComponent<PolygonCollider2D>();
|
||||
|
||||
}
|
||||
|
||||
pc.isTrigger = true;
|
||||
int circleSegments = 5;
|
||||
|
||||
|
||||
var points = new Vector2[1 + (circleSegments + 1)];
|
||||
points[0] = new Vector2(0, 0);
|
||||
|
||||
for (int i = 0; i <= circleSegments; ++i) {
|
||||
float angle = viewFov/circleSegments*i;
|
||||
points[i + 1] = Quaternion.AngleAxis(-0.5f * viewFov + angle, Vector3.forward) * new Vector3(1, 0, 0) * viewDistance;
|
||||
}
|
||||
pc.points = points;
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
var pos = human.eyes.transform.position;
|
||||
var eyesTf = human.eyes.transform.localToWorldMatrix;
|
||||
var right = eyesTf.MultiplyVector(Vector3.right).normalized;
|
||||
|
||||
var d0 = Quaternion.AngleAxis(viewFov * 0.5f, Vector3.forward) * right;
|
||||
var d1 = Quaternion.AngleAxis(viewFov * -0.5f, Vector3.forward) * right;
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawLine(pos, pos + d0 * viewDistance);
|
||||
Gizmos.DrawLine(pos, pos + d1 * viewDistance);
|
||||
|
||||
int sections = 15;
|
||||
int innerSections = 5;
|
||||
for (int i = 0; i < sections; ++i) {
|
||||
|
||||
float angle0 = (viewFov / (float)sections * i) - (viewFov / 2);
|
||||
float angle1 = (viewFov / (float)sections * (i + 1)) - (viewFov / 2);
|
||||
|
||||
var p0 = Quaternion.AngleAxis(angle0, Vector3.forward) * right;
|
||||
var p1 = Quaternion.AngleAxis(angle1, Vector3.forward) * right;
|
||||
|
||||
|
||||
Gizmos.DrawLine(pos + p0 * viewDistance, pos + p1 * viewDistance);
|
||||
}
|
||||
|
||||
Gizmos.color = new Color(0,0,1,0.4f);
|
||||
for (int i = 0; i < sections; ++i) {
|
||||
|
||||
for (int j = 0; j < innerSections; ++j) {
|
||||
float dist = (viewDistance / (innerSections + 1)) * (j + 1);
|
||||
|
||||
float angle0 = (viewFov / (float)sections * i) - (viewFov / 2);
|
||||
float angle1 = (viewFov / (float)sections * (i + 1)) - (viewFov / 2);
|
||||
|
||||
var p0 = Quaternion.AngleAxis(angle0, Vector3.forward) * right;
|
||||
var p1 = Quaternion.AngleAxis(angle1, Vector3.forward) * right;
|
||||
|
||||
|
||||
Gizmos.DrawLine(pos + p0 * dist, pos + p1 * dist);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c78e7a6bf9dc52c429ebecae89101590
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class RotationAnimator : MonoBehaviour {
|
||||
public Vector3 Rotation;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
var rotation = transform.localRotation;
|
||||
rotation.eulerAngles += Rotation * Time.deltaTime;
|
||||
transform.localRotation = rotation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f6f17afb4739354fbe7dd27dd61b387
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
Reference in New Issue
Block a user