您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
104 行
3.0 KiB
104 行
3.0 KiB
using System;
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
using Object = UnityEngine.Object;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace BoatAttack.Boat
|
|
{
|
|
/// <summary>
|
|
/// This is an overall controller for a boat
|
|
/// </summary>
|
|
public class BoatController : MonoBehaviour
|
|
{
|
|
//Boat stats
|
|
public bool Human; // Is human
|
|
public bool RandomizeColors = true;
|
|
public Color PrimaryColor; // Boat primary colour
|
|
public Color TrimColor; // Boat secondary colour
|
|
public Renderer boatRenderer; // The renderer for the boat mesh
|
|
|
|
void OnValidate()
|
|
{
|
|
Random.InitState(this.gameObject.GetInstanceID() + DateTime.Now.Millisecond + DateTime.UtcNow.Second);
|
|
Randomize();
|
|
Colourize(); // Update the colour material property block
|
|
}
|
|
|
|
// Use this for initialization
|
|
void Start()
|
|
{
|
|
Colourize();
|
|
if (Human == true)
|
|
gameObject.AddComponent<HumanController>(); // Adds a human controller if human
|
|
else
|
|
gameObject.AddComponent<AIcontroller>(); // Adds an AI controller if AI
|
|
}
|
|
|
|
/// <summary>
|
|
/// This sets both the primary and secondary colour and assigns via a MPB
|
|
/// </summary>
|
|
void Colourize()
|
|
{
|
|
if (boatRenderer)
|
|
{
|
|
if (Application.isEditor)
|
|
{
|
|
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
|
|
mpb.SetColor("_Color1", PrimaryColor);
|
|
mpb.SetColor("_Color2", TrimColor);
|
|
boatRenderer.SetPropertyBlock(mpb);
|
|
}
|
|
else
|
|
{
|
|
boatRenderer.material.SetColor("_Color1", PrimaryColor);
|
|
boatRenderer.material.SetColor("_Color2", TrimColor);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Randomize()
|
|
{
|
|
if (RandomizeColors)
|
|
{
|
|
var H = Random.Range(0f, 1f);
|
|
var S = 0f;
|
|
var V = 0.9f;
|
|
|
|
var rand = Random.insideUnitCircle;
|
|
|
|
if (rand.x > 0.5f)
|
|
S = 0f;
|
|
else
|
|
S = 0.9f;
|
|
|
|
if (rand.y > 0.8f)
|
|
V = 0f;
|
|
else
|
|
V = Random.Range(0.5f, 0.9f);
|
|
|
|
var h2 = Mathf.Repeat(H + (rand.x + rand.y > 0 ? 0.5f : 0f), 1f);
|
|
var s2 = S <= 0.1f ? 0.9f : Random.Range(0.5f, 0.9f);
|
|
|
|
PrimaryColor = Color.HSVToRGB(H, S, V);
|
|
TrimColor = Color.HSVToRGB(h2, s2, 1f - V);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class BoatData
|
|
{
|
|
public string boatName;
|
|
//public BoatType boatType = BoatType.Interceptor;
|
|
public Object boatPrefab;
|
|
public bool Human = false;
|
|
}
|
|
|
|
[Serializable]
|
|
public enum BoatType
|
|
{
|
|
Interceptor,
|
|
Classic,
|
|
}
|
|
}
|