72 lines
1.7 KiB
C#
72 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace ScarletMansion {
|
|
public class FloorCleanup : MonoBehaviour {
|
|
|
|
[Header("References")]
|
|
public MeshRenderer targetRenderer;
|
|
public GameObject targerGameObject;
|
|
public int bitValueCheck;
|
|
|
|
[Header("Logic")]
|
|
public GameObject[] neighbors;
|
|
|
|
public int[] stateValues;
|
|
public Material[] stateMaterials;
|
|
public float[] stateRotations;
|
|
|
|
public State[] states;
|
|
|
|
[System.Serializable]
|
|
public class State {
|
|
public int value;
|
|
public Material material;
|
|
public float rotation;
|
|
}
|
|
|
|
void Reset(){
|
|
targetRenderer = GetComponent<MeshRenderer>();
|
|
targerGameObject = gameObject;
|
|
}
|
|
|
|
public bool UpdateRender(){
|
|
|
|
var value = 0;
|
|
var maxValue = (1 << neighbors.Length) - 1;
|
|
for(var i = 0; i < neighbors.Length; ++i){
|
|
var n = neighbors[i];
|
|
if (n != null && neighbors[i].activeSelf) value += 1 << i;
|
|
}
|
|
|
|
if (value == maxValue) return false;
|
|
|
|
for(var i = 0; i < stateValues.Length; ++i){
|
|
if (stateValues[i] == value) {
|
|
targetRenderer.material = stateMaterials[i];
|
|
targetRenderer.transform.localEulerAngles = new Vector3(0f, stateRotations[i], 0f);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
var wasActive = targerGameObject.activeSelf;
|
|
targerGameObject.SetActive(false);
|
|
return wasActive;
|
|
}
|
|
|
|
void OnDrawGizmosSelected(){
|
|
Gizmos.color = Color.green;
|
|
for(var i = 0; i < neighbors.Length; ++i){
|
|
if ((bitValueCheck & (1 << i)) > 0) {
|
|
Gizmos.DrawCube(neighbors[i].transform.position, Vector3.one);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|