Initial commit

This commit is contained in:
Senad Uka
2020-01-11 07:32:13 +01:00
commit c43739e158
517 changed files with 456377 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
using UnityEngine;
using System;
namespace PolyPerfect
{
[Serializable]
public class AIState
{
public string stateName = "New State";
public string animationBool = string.Empty;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d932b51a9415b264486b132858bb0b80
timeCreated: 1513899975
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PolyPerfect
{
[CreateAssetMenu(fileName = "New AI Stats", menuName = "PolyPerfect/AIStats", order = 1)]
public class AIStats : ScriptableObject
{
[SerializeField, Tooltip("How dominent this animal is in the food chain, agressive animals will attack less dominant animals.")]
public int dominance = 1;
[SerializeField, Tooltip("How many seconds this animal can run for before it gets tired.")]
public float stamina = 10f;
[SerializeField, Tooltip("How much this damage this animal does to another animal.")]
public float power = 10f;
[SerializeField, Tooltip("How much health this animal has.")]
public float toughness = 5f;
[SerializeField, Tooltip("Chance of this animal attacking another animal."), Range(0f, 99f)]
public float agression = 0f;
[SerializeField, Tooltip("How quickly the animal does damage to another animal (every 'attackSpeed' seconds will cause 'power' amount of damage).")]
public float attackSpeed = 0.5f;
[SerializeField, Tooltip("If true, this animal will attack other animals of the same specices.")]
public bool territorial = false;
[SerializeField, Tooltip("Stealthy animals can't be detected by other animals.")]
public bool stealthy = false;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8f927d6b4cc0cbd4081f82a261f44ab2
timeCreated: 1552753245
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
using UnityEngine;
using System;
namespace LowPolyAnimalPack
{
[Serializable]
public class AnimalState
{
public string stateName = "New State";
public string animationBool = string.Empty;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9cc0f5d97a4184c2481c8648cd7a0199
timeCreated: 1572684685
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,97 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PolyPerfect
{
public class AudioManager : MonoBehaviour
{
private static AudioManager instance;
[SerializeField]
private bool muteSound;
[SerializeField]
private int objectPoolLength = 20;
[SerializeField]
private float soundDistance = 7f;
[SerializeField]
private bool logSounds = false;
private List<AudioSource> pool = new List<AudioSource>();
private void Awake()
{
instance = this;
for (int i = 0; i < objectPoolLength; i++)
{
GameObject soundObject = new GameObject();
soundObject.transform.SetParent(instance.transform);
soundObject.name = "Sound Effect";
AudioSource audioSource = soundObject.AddComponent<AudioSource>();
audioSource.spatialBlend = 1f;
audioSource.minDistance = instance.soundDistance;
audioSource.gameObject.SetActive(false);
pool.Add(audioSource);
}
}
public static void PlaySound(AudioClip clip, Vector3 pos)
{
if (!instance)
{
Debug.LogError("No Audio Manager found in the scene, make sure to add one if you want sound");
return;
}
if(instance.muteSound)
{
return;
}
if (!clip)
{
Debug.LogError("Clip is null");
return;
}
if (instance.logSounds)
{
Debug.Log("Playing Audio: " + clip.name);
}
for (int i = 0; i < instance.pool.Count; i++)
{
if (!instance.pool[i].gameObject.activeInHierarchy)
{
instance.pool[i].clip = clip;
instance.pool[i].transform.position = pos;
instance.pool[i].gameObject.SetActive(true);
instance.pool[i].Play();
instance.StartCoroutine(instance.ReturnToPool(instance.pool[i].gameObject, clip.length));
return;
}
}
GameObject soundObject = new GameObject();
soundObject.transform.SetParent(instance.transform);
soundObject.name = "Sound Effect";
AudioSource audioSource = soundObject.AddComponent<AudioSource>();
audioSource.spatialBlend = 1f;
audioSource.minDistance = instance.soundDistance;
instance.pool.Add(audioSource);
audioSource.clip = clip;
soundObject.transform.position = pos;
audioSource.Play();
instance.StartCoroutine(instance.ReturnToPool(soundObject, clip.length));
}
private IEnumerator ReturnToPool(GameObject obj, float delay)
{
yield return new WaitForSeconds(delay);
obj.SetActive(false);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e66c6dbaf05274147910cdaa765a7871
timeCreated: 1523056765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2fb3624c20da2384bba41df08d0718bd
folderAsset: yes
timeCreated: 1521553644
licenseType: Store
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,390 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace PolyPerfect
{
public class StatsTable : EditorWindow
{
static List<AIStats> stats = new List<AIStats>();
static public Dictionary<AIStats, int> selectionValue = new Dictionary<AIStats, int>();
static string pathFolder = "";
bool toggleAnimalName = true;
bool toggleDominance = true;
bool toggleAgression = true;
bool toggleAttackSpeed = true;
bool togglePower = true;
bool toggleStamina = true;
bool toggleStealthy = true;
bool toggleToughness = true;
bool toggleTeritorial = true;
GUIStyle folderStyle = new GUIStyle();
GUIStyle Explanation = new GUIStyle();
GUIStyle toggleField = new GUIStyle();
// Add menu named "My Window" to the Window menu
[MenuItem("PolyPerfect/Stats Table")]
static void Init()
{
// Get existing open window or if none, make a new one:
StatsTable window = (StatsTable)EditorWindow.GetWindow(typeof(StatsTable));
window.Show();
//If the window has been open before then clear the stats list and make a new one
SortLists();
}
static void SortLists()
{
//Find all the animal stats in the project
var animalStats = (AIStats[])Resources.FindObjectsOfTypeAll(typeof(AIStats));
//If the window has been open before then clear the stats list and make a new one
stats.Clear();
selectionValue.Clear();
foreach (var item in animalStats)
{
//Debug.Log(item.name);
selectionValue.Add(item, -1);
stats.Add(item);
}
}
void OnDestroy()
{
stats.Clear();
selectionValue.Clear();
}
void CreateNewAnimalStats()
{
var animalStats = (AIStats[])Resources.FindObjectsOfTypeAll(typeof(AIStats));
AIStats newAnimalStats = ScriptableObject.CreateInstance<AIStats>();
if (AssetDatabase.GetMainAssetTypeAtPath(pathFolder + "/New Animal Stats.asset") != null)
{
AssetDatabase.CreateAsset(newAnimalStats, pathFolder + "/New Animal Stats" + animalStats.Length.ToString() + ".asset");
}
else
{
AssetDatabase.CreateAsset(newAnimalStats, pathFolder + "/New Animal Stats.asset");
}
}
void OnGUI()
{
folderStyle.normal.textColor = Color.black;
Explanation.alignment = TextAnchor.MiddleCenter;
pathFolder = "Assets";
//Get the stats logo
var mainTexture = Resources.Load<Texture2D>("StatsLogo");
//Main Image
GUILayout.BeginHorizontal();
GUILayout.Label(mainTexture);
GUILayout.EndHorizontal();
GUILayout.Label("See a side by side comparison of the animal stats, use the boxes below to re order the list into the highest value of the category", Explanation);
var filters = new List<string>();
filters.Add("Animal Name");
filters.Add("Dominance");
filters.Add("Agression");
filters.Add("AttackSpeed");
filters.Add("Power");
filters.Add("Stamina");
filters.Add("Stealthy");
filters.Add("Toughness");
filters.Add("territorial");
var buttonSize = (position.width / 9.5f);
GUILayout.Space(20f);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Animal Name", GUILayout.Width(buttonSize)))
{
//Re order by the animals name
ReOrderFloatList(0);
}
if (GUILayout.Button("Dominance", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(1);
}
if (GUILayout.Button("Agression", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(2);
}
if (GUILayout.Button("AttackSpeed", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(3);
}
if (GUILayout.Button("Power", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(4);
}
if (GUILayout.Button("Stamina", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(5);
}
if (GUILayout.Button("Stealthy", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(6);
}
if (GUILayout.Button("Toughness", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(7);
}
if (GUILayout.Button("territorial", GUILayout.Width(buttonSize)))
{
ReOrderFloatList(8);
}
GUILayout.EndHorizontal();
GUILayout.Space(20f);
foreach (var item in stats)
{
BuildWindow(item);
}
if (GUILayout.Button("Add New Stats"))
{
if (AssetDatabase.IsValidFolder(pathFolder))
{
CreateNewAnimalStats();
}
else
{
Debug.Log("Please enter a valid path");
}
SortLists();
}
GUILayout.Space(20f);
}
void BuildWindow(AIStats animalStats)
{
if (animalStats == null)
{
stats.Remove(animalStats);
}
toggleField.alignment = TextAnchor.MiddleCenter;
Repaint();
if (selectionValue.ContainsKey(animalStats))
{
GUILayout.BeginHorizontal();
var previousName = animalStats.name;
var newName = GUILayout.TextField(animalStats.name, GUILayout.Width(position.width / 8.5f));
animalStats.name = newName;
if (previousName != animalStats.name)
{
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(animalStats), animalStats.name);
stats.Clear();
SortLists();
}
animalStats.dominance = int.Parse(GUILayout.TextField(animalStats.dominance.ToString(), GUILayout.Width(position.width / 9)));
animalStats.agression = Mathf.Clamp(float.Parse(GUILayout.TextField(animalStats.agression.ToString(), GUILayout.Width(position.width / 9))), 0, 99);
animalStats.attackSpeed = float.Parse(GUILayout.TextField(animalStats.attackSpeed.ToString(), GUILayout.Width(position.width / 9)));
animalStats.power = float.Parse(GUILayout.TextField(animalStats.power.ToString(), GUILayout.Width(position.width / 9)));
animalStats.stamina = float.Parse(GUILayout.TextField(animalStats.stamina.ToString(), GUILayout.Width(position.width / 9)));
animalStats.stealthy = GUILayout.Toggle(animalStats.stealthy, animalStats.stealthy.ToString(), GUILayout.Width(position.width / 9));
animalStats.toughness = float.Parse(GUILayout.TextField(animalStats.toughness.ToString(), GUILayout.Width(position.width / 9)));
animalStats.territorial = GUILayout.Toggle(animalStats.territorial, animalStats.territorial.ToString(), toggleField, GUILayout.Width(position.width / 9));
GUILayout.EndHorizontal();
}
}
void ReOrderFloatList(int filterID)
{
switch (filterID)
{
case 0:
if (toggleAnimalName)
{
stats = (stats.OrderBy(p => p.name).Reverse()).ToList();
toggleAnimalName = !toggleAnimalName;
}
else
{
stats = stats.OrderBy(p => p.name).ToList();
toggleAnimalName = !toggleAnimalName;
}
break;
case 1:
if (toggleDominance)
{
stats = (stats.OrderBy(p => p.dominance).Reverse()).ToList();
toggleDominance = !toggleDominance;
}
else
{
stats = stats.OrderBy(p => p.dominance).ToList();
toggleDominance = !toggleDominance;
}
break;
case 2:
if (toggleAgression)
{
stats = (stats.OrderBy(p => p.agression).Reverse()).ToList();
toggleAgression = !toggleAgression;
}
else
{
stats = stats.OrderBy(p => p.agression).ToList();
toggleAgression = !toggleAgression;
}
break;
case 3:
if (toggleAttackSpeed)
{
stats = (stats.OrderBy(p => p.attackSpeed).Reverse()).ToList();
toggleAttackSpeed = !toggleAttackSpeed;
}
else
{
stats = stats.OrderBy(p => p.attackSpeed).ToList();
toggleAttackSpeed = !toggleAttackSpeed;
}
break;
case 4:
if (togglePower)
{
stats = (stats.OrderBy(p => p.power).Reverse()).ToList();
togglePower = !togglePower;
}
else
{
stats = stats.OrderBy(p => p.power).ToList();
togglePower = !togglePower;
}
break;
case 5:
if (toggleStamina)
{
stats = (stats.OrderBy(p => p.stamina).Reverse()).ToList();
toggleStamina = !toggleStamina;
}
else
{
stats = stats.OrderBy(p => p.stamina).ToList();
toggleStamina = !toggleStamina;
}
break;
case 6:
if (toggleStealthy)
{
stats = (stats.OrderBy(p => p.stealthy).Reverse()).ToList();
toggleStealthy = !toggleStealthy;
}
else
{
stats = stats.OrderBy(p => p.stealthy).ToList();
toggleStealthy = !toggleStealthy;
}
break;
case 7:
if (toggleToughness)
{
stats = (stats.OrderBy(p => p.toughness).Reverse()).ToList();
toggleToughness = !toggleToughness;
}
else
{
stats = stats.OrderBy(p => p.toughness).ToList();
toggleToughness = !toggleToughness;
}
break;
case 8:
if (toggleTeritorial)
{
stats = (stats.OrderBy(p => p.territorial).Reverse()).ToList();
toggleTeritorial = !toggleTeritorial;
}
else
{
stats = stats.OrderBy(p => p.territorial).ToList();
toggleTeritorial = !toggleTeritorial;
}
break;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c09ec0cbba516c5419b64102e129baf3
timeCreated: 1568925623
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace PolyPerfect
{
[CustomEditor(typeof(WanderManager))]
public class WanderManagerEditor : Editor
{
public override void OnInspectorGUI()
{
//Load a Texture (Assets/Resources/Textures/texture01.png)
var mainTexture = Resources.Load<Texture2D>("ManagerLogo");
GUILayout.BeginHorizontal();
GUILayout.Label(mainTexture);
GUILayout.EndHorizontal();
WanderManager animalManager = (WanderManager)target;
if (!Application.isPlaying)
{
base.OnInspectorGUI();
return;
}
GUILayout.Space(10);
animalManager.PeaceTime = EditorGUILayout.Toggle("Peace Time", animalManager.PeaceTime);
GUILayout.Space(5);
if (GUILayout.Button("Kill 'Em All"))
{
animalManager.Nuke();
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6815a2eb8bd6ec54bb5139dbefa6fb8a
timeCreated: 1521553633
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,158 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
namespace PolyPerfect
{
[CustomEditor(typeof(WanderScript))]
[CanEditMultipleObjects]
public class WanderScriptEditor : Editor
{
static bool AnimationStates, AIControls, DEBUGToggle, StateEvents = false;
public override void OnInspectorGUI()
{
WanderScript myWanderScript = (WanderScript)target;
serializedObject.Update();
//Get Lists
SerializedProperty idleStates = serializedObject.FindProperty("idleStates");
SerializedProperty movementStates = serializedObject.FindProperty("movementStates");
SerializedProperty attackingStates = serializedObject.FindProperty("attackingStates");
SerializedProperty deathStates = serializedObject.FindProperty("deathStates");
//Death Unity Event
SerializedProperty deathEvent = serializedObject.FindProperty("deathEvent");
SerializedProperty attackingEvent = serializedObject.FindProperty("attackingEvent");
SerializedProperty idleEvent = serializedObject.FindProperty("idleEvent");
SerializedProperty movementEvent = serializedObject.FindProperty("movementEvent");
//Get Strings
SerializedProperty species = serializedObject.FindProperty("species");
//Get Animal Stats
SerializedProperty stats = serializedObject.FindProperty("stats");
//Get AI Controls
SerializedProperty wanderSize = serializedObject.FindProperty("wanderZone");
SerializedProperty awareness = serializedObject.FindProperty("awareness");
SerializedProperty scent = serializedObject.FindProperty("scent");
SerializedProperty constainedToWanderZone = serializedObject.FindProperty("constainedToWanderZone");
SerializedProperty nonAgressiveTowards = serializedObject.FindProperty("nonAgressiveTowards");
SerializedProperty surfaceRotationSpeed = serializedObject.FindProperty("surfaceRotationSpeed");
SerializedProperty matchSurfaceRotation = serializedObject.FindProperty("matchSurfaceRotation");
///DEBUG
SerializedProperty logChanges = serializedObject.FindProperty("logChanges");
SerializedProperty showGizmos = serializedObject.FindProperty("showGizmos");
SerializedProperty drawWanderRange = serializedObject.FindProperty("drawWanderRange");
SerializedProperty drawScentRange = serializedObject.FindProperty("drawScentRange");
SerializedProperty drawAwarenessRange = serializedObject.FindProperty("drawAwarenessRange");
//Load a Texture (Assets/Resources/Textures/texture01.png)
var mainTexture = Resources.Load<Texture2D>("WanderScriptLogo");
//Main Image
GUILayout.BeginHorizontal();
GUILayout.Label(mainTexture);
GUILayout.EndHorizontal();
//Draw The Species Name
EditorGUILayout.PropertyField(species);
EditorGUILayout.PropertyField(stats);
if (GUILayout.Button("Show Animation States",GUILayout.MaxWidth(Screen.width - 30)))
{
AnimationStates = !AnimationStates;
}
if (AnimationStates)
{
GUILayout.BeginHorizontal();
//GUILayout.Label(idleTexture);
GUILayout.EndHorizontal();
EditorGUILayout.PropertyField(idleStates, true);
GUILayout.BeginHorizontal();
//GUILayout.Label(movementTexture);
GUILayout.EndHorizontal();
EditorGUILayout.PropertyField(movementStates, true);
GUILayout.BeginHorizontal();
//GUILayout.Label(attackingTexture);
GUILayout.EndHorizontal();
EditorGUILayout.PropertyField(attackingStates, true);
GUILayout.BeginHorizontal();
//GUILayout.Label(deathTexture);
GUILayout.EndHorizontal();
EditorGUILayout.PropertyField(deathStates, true);
}
if (GUILayout.Button("Show State Unity Events", GUILayout.MaxWidth(Screen.width - 30)))
{
StateEvents = !StateEvents;
}
if (StateEvents)
{
var width = GUILayout.MaxWidth(Screen.width);
EditorGUILayout.PropertyField(idleEvent, width);
EditorGUILayout.PropertyField(movementEvent, width);
EditorGUILayout.PropertyField(attackingEvent, width);
EditorGUILayout.PropertyField(deathEvent, width);
}
if (GUILayout.Button("Show AI Controls", GUILayout.MaxWidth(Screen.width - 30)))
{
AIControls = !AIControls;
}
if (AIControls)
{
GUILayout.BeginHorizontal();
//GUILayout.Label(AITexture);
GUILayout.EndHorizontal();
EditorGUILayout.PropertyField(wanderSize);
EditorGUILayout.PropertyField(awareness);
EditorGUILayout.PropertyField(scent);
EditorGUILayout.PropertyField(constainedToWanderZone);
EditorGUILayout.PropertyField(nonAgressiveTowards, true);
EditorGUILayout.PropertyField(matchSurfaceRotation, true);
EditorGUILayout.PropertyField(surfaceRotationSpeed, true);
}
if (GUILayout.Button("Show DEBUG Options",GUILayout.MaxWidth(Screen.width - 30)))
{
DEBUGToggle = !DEBUGToggle;
}
if (DEBUGToggle)
{
EditorGUILayout.PropertyField(logChanges);
EditorGUILayout.PropertyField(showGizmos);
EditorGUILayout.PropertyField(drawWanderRange);
EditorGUILayout.PropertyField(drawScentRange);
EditorGUILayout.PropertyField(drawAwarenessRange, true);
}
serializedObject.ApplyModifiedProperties();
//DrawDefaultInspector();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 38c081c40ba641f4bb06b1d5564600ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using UnityEngine;
using System;
namespace PolyPerfect
{
[Serializable]
public class IdleState : AIState
{
public float minStateTime = 20f;
public float maxStateTime = 40f;
[Tooltip("Chance of it choosing this state, in comparion to other state weights.")]
public int stateWeight = 20;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7de5573661591024696ee25ba7f61720
timeCreated: 1521248350
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
using System;
namespace PolyPerfect
{
[Serializable]
public class MovementState : AIState
{
public float maxStateTime = 40f;
public float moveSpeed = 3f;
public float turnSpeed = 120f;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fd6295ba611e7ce4695f06f47767ff32
timeCreated: 1521236335
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
using UnityEngine;
namespace PolyPerfect
{
public class SurfaceRotation : MonoBehaviour
{
private string terrainLayer = "Terrain";
private int layer;
private bool rotate = true;
private Quaternion targetRotation;
private float rotationSpeed = 2f;
private void Awake()
{
layer = LayerMask.GetMask(terrainLayer);
}
private void Start()
{
RaycastHit hit;
Vector3 direction = transform.parent.TransformDirection(Vector3.down);
if (Physics.Raycast(transform.parent.position, direction, out hit, 50f, layer))
{
float distance = hit.distance;
Quaternion surfaceRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
transform.rotation = surfaceRotation * transform.parent.rotation;
}
}
private void Update()
{
if (!rotate)
return;
RaycastHit hit;
Vector3 direction = transform.parent.TransformDirection(Vector3.down);
if (Physics.Raycast(transform.parent.position, direction, out hit, 50f, layer))
{
float distance = hit.distance;
Quaternion surfaceRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
targetRotation = surfaceRotation * transform.parent.rotation;
}
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
}
public void SetRotationSpeed(float speed)
{
if (speed > 0f)
rotationSpeed = speed;
}
private void OnBecameVisible()
{
rotate = true;
}
private void OnBecameInvisible()
{
rotate = false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dede56aeabf6774479128da8ed3f01a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,80 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PolyPerfect
{
public class WanderManager : MonoBehaviour
{
[SerializeField]
private bool peaceTime;
public bool PeaceTime
{
get
{
return peaceTime;
}
set
{
SwitchPeaceTime(value);
}
}
private static WanderManager instance;
public static WanderManager Instance
{
get
{
return instance;
}
}
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
Debug.LogError("Two Wander Managers were found in the scene, Make sure there is only ever one!");
return;
}
instance = this;
}
private void Start()
{
StopAllCoroutines();
if (peaceTime)
{
Debug.Log("AnimalManager: Peacetime is enabled, all animals are non-agressive.");
SwitchPeaceTime(true);
}
}
public void SwitchPeaceTime(bool enabled)
{
if (enabled == peaceTime)
{
return;
}
peaceTime = enabled;
Debug.Log(string.Format("AnimalManager: Peace time is now {0}.", enabled ? "On" : "Off"));
foreach (WanderScript animal in WanderScript.AllAnimals)
{
animal.SetPeaceTime(enabled);
}
}
public void Nuke()
{
foreach (WanderScript animal in WanderScript.AllAnimals)
{
animal.Die();
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 56e0a4c5243c75944b7f4cdc7614bd1a
timeCreated: 1521548302
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c31d813974da4df4d9a86f1828bae3e7
timeCreated: 1506884329
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: