1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
| using System.Collections; using System.Collections.Generic; using UnityEngine; using Mydirector;
namespace Mycontroller{
public class BoatController { private GameObject boat; private Vector3 From = new Vector3 (4,0,0); private Vector3 To = new Vector3 (8, 0, 0); private Vector3[] from_positions; private Vector3[] to_positions; int is_from; CharacterController[] characters = new CharacterController[2]; private Move move; public float speed = 30;
public BoatController() { is_from = 1;
from_positions = new Vector3[] { new Vector3 (4.5F,0.5F,0), new Vector3 (3.5F,0.5F,0) }; to_positions = new Vector3[] { new Vector3 (8.5F, 0.5F, 0), new Vector3 (7.5F, 0.5F, 0) };
boat = Object.Instantiate (Resources.Load ("Prefab/boat", typeof(GameObject)), From, Quaternion.identity, null) as GameObject; boat.name = "boat";
move = boat.AddComponent (typeof(Move)) as Move; boat.AddComponent (typeof(UserClick)); } public bool is_empty(){ for (int i = 0; i < characters.Length; i++) { if (characters [i] != null) { return false; } } return true; }
public Vector3 Move_to() { if (is_from == -1) { is_from = 1; return From; } else { is_from = -1; return To; } }
public int getEmptyIndex() { for (int i = 0; i < characters.Length; i++) { if (characters [i] == null) { return i; } } return -1; }
public Vector3 getEmptyPosition() { Vector3 pos; int emptyIndex = -1; for (int i = 0; i < characters.Length; i++) { if (characters [i] == null) { emptyIndex = i; } } if (is_from == -1) { pos = to_positions[emptyIndex]; } else { pos = from_positions[emptyIndex]; } return pos; }
public void GetOnBoat(CharacterController characterCtrl) { int index = -1; for (int i = 0; i < characters.Length; i++) { if (characters [i] == null) { index = i;
} } characters [index] = characterCtrl; }
public CharacterController GetOffBoat(string characters_name) { for (int i = 0; i < characters.Length; i++) { if (characters [i] != null && characters [i].getName () == characters_name) { CharacterController cc = characters [i]; characters [i] = null; return cc; } } return null; }
public GameObject getGameobj() { return boat; }
public int get_is_from() { return is_from; }
public int[] getCharacterNum() { int[] count = {0, 0}; for (int i = 0; i < characters.Length; i++) { if (characters [i] == null) continue; if (!characters [i].Is_Devil ()) { count[0]++; } else { count[1]++; } } return count; }
public void reset() { if (is_from == -1) { Move_to (); } boat.transform.position = From; characters = new CharacterController[2]; } }
public class CoastController{ private GameObject coast; private Vector3 From = new Vector3 (0, 0, 0); private Vector3 To = new Vector3(12,0,0); private Vector3[] positions; private int is_from; private CharacterController[] characters; public CoastController(string Where){ positions = new Vector3[] {new Vector3 (2.5F,1.25F,0),new Vector3 (1.5F,1.25F,0), new Vector3 (0.5F,1.25F,0),new Vector3 (-0.5F,1.25F,0),new Vector3 (-1.5F,1.25F,0),new Vector3 (-2.5F,1.25F,0) }; characters = new CharacterController[6]; if (Where == "from") { coast = Object.Instantiate (Resources.Load ("Prefab/stone", typeof(GameObject)), From, Quaternion.identity, null) as GameObject; coast.name = "from"; is_from = 1; } else if(Where == "to"){ coast = Object.Instantiate (Resources.Load ("Prefab/stone", typeof(GameObject)), To, Quaternion.identity, null) as GameObject; coast.name = "to"; is_from = -1; } } public Vector3 getEmptyPos(){ int index = -1; for (int i = 0; i < characters.Length; i++) { if (characters [i] == null) { index = i; break; } } Vector3 pos = positions [index];
if(is_from==-1) pos.x +=12;
return pos; } public void getOnCoast(CharacterController character_ctrl){ int index = -1; for (int i = 0; i < characters.Length; i++) { if (characters [i] == null) { index = i; break; } } characters [index] = character_ctrl; }
public CharacterController getOffCoast(string character_name){ for (int i = 0; i < characters.Length; i++) { if (characters [i] != null && characters [i].getName () == character_name) { CharacterController cc = characters [i]; characters [i] = null; return cc; } } return null; } public int get_is_from(){ return is_from; } public int[] get_character_num(){ int[] num = { 0, 0 }; for (int i = 0; i < characters.Length; i++) { if (characters [i] == null) continue; if (!characters[i].Is_Devil ()) { num [0]++; } else { num [1]++; } } return num; } public void reset(){ characters = new CharacterController[6]; } }
public class CharacterController{ private GameObject character; private Move move; private UserClick click; private bool is_devil; private bool is_on_boat = false; private CoastController coast; public float move_speed = 30; public CharacterController(string name){ if(name == "priest"){ character = Object.Instantiate(Resources.Load("Prefab/priest",typeof(GameObject)),Vector3.zero,Quaternion.identity,null) as GameObject; is_devil = false; }else if(name == "devil"){ character = Object.Instantiate(Resources.Load("Prefab/devil",typeof(GameObject)),Vector3.zero,Quaternion.identity,null) as GameObject; is_devil = true; } move = character.AddComponent(typeof(Move))as Move; click = character.AddComponent(typeof(UserClick))as UserClick; click.setController(this); } public void setName(string _name){ character.name = _name; } public string getName(){ return character.name; } public bool Is_Devil(){ return is_devil; } public bool Is_On_Boat(){ return is_on_boat; } public void setPos(Vector3 pos){ character.transform.position = pos; } public Vector3 getPos(){ return character.transform.position; }
public GameObject getGameobj(){ return character; }
public CoastController getCoastController() { return coast; } public void getOnBoat(BoatController boatCtrl) { coast = null; character.transform.parent = boatCtrl.getGameobj().transform; is_on_boat = true; }
public void getOnCoast(CoastController coastCtrl) { coast = coastCtrl; character.transform.parent = null; is_on_boat = false; } public void reset() { coast = (Director.getInstace ().current as FirstController).fromCoast; getOnCoast (coast); setPos (coast.getEmptyPos()); coast.getOnCoast (this); }
} }
|