Commit e25267cf authored by You're Perfect 's avatar You're Perfect

new pier graphics, improve AI slightly

parent 4c927f75
......@@ -30,7 +30,7 @@ public class FishFactory : MonoBehaviour {
else
newFish = Instantiate(Instance.fishPrefabs[Random.Range(0, (Instance.fishPrefabs.Length) - 1)], newVect, Quaternion.identity, Instance.transform);
newFish.layer = Instance.FishLayer.value;
//newFish.layer = 10;
}
}
......
/*
* Copyright (C) Catherine. All rights reserved.
* Licensed under the BSD 3-Clause License.
* See LICENSE file in the project root for full license information.
* See CONTRIBUTORS file in the project root for full list of contributors.
*/
using System;
using System.Collections.Generic;
using UnityEngine;
public static class Utility
{
static string _lastLogMessage;
/// <summary>
/// Take a string in the form of (0,0,0) or 0,0,0 and converts
/// it into a Vector 3
/// </summary>
/// <param name="vector"></param>
/// <returns></returns>
public static Vector3 StringToVector3(string vector)
{
//TODO error checking
// Remove the parentheses
if (vector.StartsWith("(") && vector.EndsWith(")"))
{
vector = vector.Substring(1, vector.Length - 2);
}
// split the items
string[] array = vector.Split(',');
// store as a Vector3
Vector3 result = new Vector3(
float.Parse(array[0]),
float.Parse(array[1]),
float.Parse(array[2]));
return result;
}
public static void DebugLogOnce(string message)
{
if (_lastLogMessage != message)
{
_lastLogMessage = message;
Debug.Log(message);
}
}
public static bool AlmostEquals(this double double1, double double2, double precision)
{
return (Math.Abs(double1 - double2) <= precision);
}
public static Vector3 Round(Vector3 vector, int places)
{
return new Vector3((float)Math.Round(vector.x, places), (float)Math.Round(vector.y, places), (float)Math.Round(vector.z, places));
}
public static Vector2 Round(Vector2 vector, int places)
{
return new Vector2((float)Math.Round(vector.x, places), (float)Math.Round(vector.y, places));
}
public static void AddIfNotNull<T>(this IList<T> list, T value)
{
if ((object)value != null)
list.Add(value);
}
private static Collider[] _colliderBuffer = new Collider[30];
public static T GetGameObjectAt<T>(Vector3 position, float radius = 0.01f) where T : MonoBehaviour
{
int number = Physics.OverlapSphereNonAlloc(position, radius, _colliderBuffer);
for (int i = 0; i < number; ++i)
{
T obj = _colliderBuffer[i].GetComponent<T>();
if (obj != null && obj.transform.position == position)
return obj;
}
return null;
}
private static Collider2D[] _collider2DBuffer = new Collider2D[30];
public static T GetGameObjectAt<T>(Vector2 position, float radius = 0.01f) where T : MonoBehaviour
{
int number = Physics2D.OverlapCircleNonAlloc(position, radius, _collider2DBuffer);
for (int i = 0; i < number; ++i)
{
T obj = _collider2DBuffer[i].GetComponent<T>();
if (obj != null && obj.transform.position.x == position.x && obj.transform.position.y == position.y)
return obj;
}
return null;
}
public static T GetGameObjectNear<T>(Vector3 position, float radius = 0.01f) where T : MonoBehaviour
{
int number = Physics.OverlapSphereNonAlloc(position, radius, _colliderBuffer);
for (int i = 0; i < number; ++i)
{
T obj = _colliderBuffer[i].GetComponent<T>();
if (obj != null)
return obj;
}
return null;
}
public static T GetGameObjectNear<T>(Vector2 position, float radius = 0.01f) where T : MonoBehaviour
{
int number = Physics2D.OverlapCircleNonAlloc(position, radius, _collider2DBuffer);
for (int i = 0; i < number; ++i)
{
T obj = _collider2DBuffer[i].GetComponent<T>();
if (obj != null)
return obj;
}
return null;
}
public static List<T> GetGameObjectsNear<T>(Vector3 position, float radius = 0.01f) where T : MonoBehaviour
{
List<T> ret = new List<T>();
int number = Physics.OverlapSphereNonAlloc(position, radius, _colliderBuffer);
for (int i = 0; i < number; ++i)
{
ret.AddIfNotNull(_colliderBuffer[i].GetComponent<T>());
}
return ret;
}
public static List<T> GetGameObjectsNear<T>(Vector2 position, float radius = 0.01f) where T : MonoBehaviour
{
List<T> ret = new List<T>();
int number = Physics2D.OverlapCircleNonAlloc(position, radius, _collider2DBuffer);
for (int i = 0; i < number; ++i)
{
ret.AddIfNotNull(_collider2DBuffer[i].GetComponent<T>());
}
return ret;
}
public static void SortChildrenByYCoord(GameObject o)
{
var children = new List<Transform>(o.GetComponentsInChildren<Transform>(true));
children.Remove(o.transform);
children.Sort(CompareYCoord);
for (int i = 0; i < children.Count; i++)
children[i].SetSiblingIndex(i);
}
private static int CompareYCoord(Transform lhs, Transform rhs)
{
if (lhs == rhs) return 0;
var test = rhs.gameObject.activeInHierarchy.CompareTo(lhs.gameObject.activeInHierarchy);
if (test != 0) return test;
if (lhs.localPosition.y < rhs.localPosition.y) return -1;
if (lhs.localPosition.y > rhs.localPosition.y) return 1;
return 0;
}
}
fileFormatVersion: 2
guid: 3e835b0d04039d0439449b032a9f56f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -13,16 +13,20 @@ public class AIbear : MonoBehaviour {
void SearchFish(Vector2 center,Vector2 boxsize, float angle)
{
Collider2D hit = Physics2D.OverlapBox(center,boxsize,angle,fishlayer);
if (hit == null || hit.gameObject == null)
//List<Fish> fishList = Utility.GetGameObjectsNear<Fish>(center, boxsize.y);
BaseFish[] fishList = GameObject.FindObjectsOfType<BaseFish>();
if (fishList.Length == 0)
{
Debug.Log("NoFish");
target = null;
}
else
target = hit.gameObject;
//target =targets [Random.Range (0, targets.Length - 1)].gameObject ;
{
//target = hit.gameObject;
target = fishList[Random.Range(0, fishList.Length - 1)].gameObject;
}
if (target.transform.position.x < 0)
target = null;
}
void Start () {
GameObject o1 = GameObject.Find ("line2");
......@@ -80,6 +84,8 @@ public class AIbear : MonoBehaviour {
else
{
targetTimeout = 5;
vert.value = -0.1f;
horiz.value = -0.1f;
SearchFish(new Vector2(transform.position.x, transform.position.y), size, angle);
}
}
......
fileFormatVersion: 2
guid: 9bd8fef14d838e44cb2bb9ab43edaf1f
TextureImporter:
fileIDToRecycleName:
21300000: pier2_0
21300002: pier2_1
externalObjects: {}
serializedVersion: 7
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 32
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: pier2_0
rect:
serializedVersion: 2
x: 133
y: 35
width: 32
height: 32
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: ad1b8e2ecff0e6347838c531166c7e24
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: pier2_1
rect:
serializedVersion: 2
x: 10
y: 35
width: 96
height: 32
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 185cc72bc2902804e87175d5b4e30513
vertices: []
indices:
edges: []
weights: []
outline: []
physicsShape: []
bones: []
spriteID: 9a799a625dc75834ebfa1ccfd40c04ed
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,7 +5,7 @@ EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
- enabled: 0
path: Assets/Scenes/SampleScene.unity
guid: 2cda990e2423bbf4892e6590ba056729
- enabled: 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment