You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.9 KiB
77 lines
1.9 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class MapTile : MonoBehaviour |
|
{ |
|
public enum Type { None, Stone, Mud, Poison, Ice, Fire, Trap } |
|
|
|
public Vector2 idx; |
|
public Type type; |
|
[Space(10)] |
|
public MeshRenderer renderer; |
|
[Space(10)] |
|
public Collider col; |
|
PhysicMaterial physicMaterial; |
|
[Space(10)] |
|
public GameObject obstacle; |
|
private void OnDisable() |
|
{ |
|
if (obstacle != null) |
|
{ |
|
obstacle.gameObject.SetActive(false); |
|
obstacle = null; |
|
} |
|
} |
|
|
|
public void OnInitialized(Vector2 idx, Type type, Material mat) |
|
{ |
|
this.idx = idx; |
|
OnApply(type, mat); |
|
|
|
if (physicMaterial == null) |
|
{ |
|
physicMaterial = new PhysicMaterial(); |
|
|
|
physicMaterial.dynamicFriction = 0.5f; |
|
physicMaterial.staticFriction = 0.5f; |
|
physicMaterial.bounciness = 0.5f; |
|
|
|
physicMaterial.frictionCombine = PhysicMaterialCombine.Average; |
|
physicMaterial.bounceCombine = PhysicMaterialCombine.Average; |
|
|
|
col.material = physicMaterial; |
|
} |
|
|
|
switch (type) |
|
{ |
|
case Type.Mud: |
|
{ |
|
physicMaterial.dynamicFriction = 0.8f; |
|
physicMaterial.staticFriction = 0.8f; |
|
} |
|
break; |
|
case Type.Ice: |
|
{ |
|
physicMaterial.dynamicFriction = 0f; |
|
physicMaterial.staticFriction = 0f; |
|
} |
|
break; |
|
case Type.Trap: |
|
{ |
|
} |
|
break; |
|
} |
|
} |
|
public void OnApply(Type type, Material mat) |
|
{ |
|
this.type = type; |
|
renderer.material = mat; |
|
} |
|
#if UNITY_EDITOR |
|
public void OnMouseDown() |
|
{ |
|
EventManager.Instance.Invoke("OnSelectTile", this); |
|
} |
|
#endif |
|
}
|
|
|