|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using UnityEngine; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Xml; |
| 7 | +using System.Xml.Linq; |
| 8 | +using Depender.Types.FlatRides; |
| 9 | +using Depender.AnimationMotors; |
| 10 | +using Depender.AnimationEvents; |
| 11 | + |
| 12 | +public class FlatRideLoader |
| 13 | +{ |
| 14 | + public static List<motor> LoadMotors(XmlNode ObjNode, GameObject GO) |
| 15 | + { |
| 16 | + List<motor> motors = new List<motor>(); |
| 17 | + |
| 18 | + foreach (XmlNode motorN in ObjNode.SelectSingleNode("Animation/motors").ChildNodes) |
| 19 | + { |
| 20 | + switch (motorN.Name) |
| 21 | + { |
| 22 | + |
| 23 | + case "Rotator": |
| 24 | + RotatorHP R = GO.AddComponent<RotatorHP>(); |
| 25 | + R.Identifier = motorN["Identifier"].InnerText; |
| 26 | + R.axisPath = motorN["axis"].InnerText; |
| 27 | + R.axis = GO.transform.FindChild(motorN["axis"].InnerText); |
| 28 | + R.maxSpeed = float.Parse(motorN["maxSpeed"].InnerText); |
| 29 | + R.accelerationSpeed = float.Parse(motorN["accelerationSpeed"].InnerText); |
| 30 | + R.rotationAxis = getVector3(motorN["rotationAxis"].InnerText); |
| 31 | + motors.Add(R); |
| 32 | + break; |
| 33 | + case "RotateBetween": |
| 34 | + RotateBetweenHP RB = GO.AddComponent<RotateBetweenHP>(); |
| 35 | + RB.Identifier = motorN["Identifier"].InnerText; |
| 36 | + RB.axisPath = motorN["axis"].InnerText; |
| 37 | + RB.axis = GO.transform.FindChild(motorN["axis"].InnerText); |
| 38 | + RB.rotationAxis = getVector3(motorN["rotationAxis"].InnerText); |
| 39 | + RB.duration = float.Parse(motorN["duration"].InnerText); |
| 40 | + motors.Add(RB); |
| 41 | + break; |
| 42 | + case "Mover": |
| 43 | + MoverHP M = GO.AddComponent<MoverHP>(); |
| 44 | + M.Identifier = motorN["Identifier"].InnerText; |
| 45 | + M.axisPath = motorN["axis"].InnerText; |
| 46 | + M.axis = GO.transform.FindChild(motorN["axis"].InnerText); |
| 47 | + M.toPosition = getVector3(motorN["toPosition"].InnerText); |
| 48 | + M.duration = float.Parse(motorN["duration"].InnerText); |
| 49 | + motors.Add(M); |
| 50 | + break; |
| 51 | + case "MultipleRotations": |
| 52 | + MultipleRotationsHP MR = GO.AddComponent<MultipleRotationsHP>(); |
| 53 | + MR.Identifier = motorN["Identifier"].InnerText; |
| 54 | + MR.axisPath = motorN["MainAxis"].InnerText; |
| 55 | + XmlNodeList axisNs = motorN.SelectNodes("axis"); |
| 56 | + foreach (XmlNode axisN in axisNs) |
| 57 | + { |
| 58 | + MR.AxissPath.Add(axisN.InnerText); |
| 59 | + } |
| 60 | + motors.Add(MR); |
| 61 | + break; |
| 62 | + case "PendulumRotator": |
| 63 | + PendulumRotatorHP PR = GO.AddComponent<PendulumRotatorHP>(); |
| 64 | + PR.Identifier = motorN["Identifier"].InnerText; |
| 65 | + PR.axisPath = motorN["axis"].InnerText; |
| 66 | + PR.axis = GO.transform.FindChild(motorN["axis"].InnerText); |
| 67 | + PR.maxSpeed = float.Parse(motorN["maxSpeed"].InnerText); |
| 68 | + PR.accelerationSpeed = float.Parse(motorN["accelerationSpeed"].InnerText); |
| 69 | + PR.rotationAxis = getVector3(motorN["rotationAxis"].InnerText); |
| 70 | + PR.angularFriction = float.Parse(motorN["angularFriction"].InnerText); |
| 71 | + PR.gravity = float.Parse(motorN["gravity"].InnerText); |
| 72 | + PR.pendulum = Boolean.Parse(motorN["pendulum"].InnerText); |
| 73 | + PR.armLength = float.Parse(motorN["armLength"].InnerText); |
| 74 | + motors.Add(PR); |
| 75 | + break; |
| 76 | + |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + return motors; |
| 81 | + throw new NotImplementedException(); |
| 82 | + } |
| 83 | + public static List<Phase> LoadPhases(XmlNode ObjNode, GameObject GO) |
| 84 | + { |
| 85 | + List<Phase> Phases = new List<Phase>(); |
| 86 | + |
| 87 | + foreach (XmlNode PhaseN in ObjNode.SelectSingleNode("Animation/phases").ChildNodes) |
| 88 | + { |
| 89 | + |
| 90 | + Phase phase = GO.AddComponent<Phase>(); |
| 91 | + foreach (XmlNode EventN in PhaseN.SelectSingleNode("events").ChildNodes) |
| 92 | + { |
| 93 | + switch (EventN.Name) |
| 94 | + { |
| 95 | + case "Wait": |
| 96 | + Wait W = GO.AddComponent<Wait>(); |
| 97 | + W.seconds = float.Parse(EventN["Seconds"].InnerText); |
| 98 | + phase.Events.Add(W); |
| 99 | + break; |
| 100 | + case "StartRotator": |
| 101 | + StartRotator SR = GO.AddComponent<StartRotator>(); |
| 102 | + SR.identifierMotor = EventN["Identifier"].InnerText; |
| 103 | + phase.Events.Add(SR); |
| 104 | + break; |
| 105 | + case "SpinRotator": |
| 106 | + SpinRotater SpR = GO.AddComponent<SpinRotater>(); |
| 107 | + SpR.identifierMotor = EventN["Identifier"].InnerText; |
| 108 | + SpR.spin = Boolean.Parse(EventN["spin"].InnerText); |
| 109 | + SpR.spins = float.Parse(EventN["spins"].InnerText); |
| 110 | + phase.Events.Add(SpR); |
| 111 | + break; |
| 112 | + case "StopRotator": |
| 113 | + StopRotator StR = GO.AddComponent<StopRotator>(); |
| 114 | + StR.identifierMotor = EventN["Identifier"].InnerText; |
| 115 | + phase.Events.Add(StR); |
| 116 | + break; |
| 117 | + case "FromToRot": |
| 118 | + FromToRot FTR = GO.AddComponent<FromToRot>(); |
| 119 | + FTR.identifierMotor = EventN["Identifier"].InnerText; |
| 120 | + phase.Events.Add(FTR); |
| 121 | + break; |
| 122 | + case "ToFromRot": |
| 123 | + ToFromRot TFR = GO.AddComponent<ToFromRot>(); |
| 124 | + TFR.identifierMotor = EventN["Identifier"].InnerText; |
| 125 | + phase.Events.Add(TFR); |
| 126 | + break; |
| 127 | + case "FromToMove": |
| 128 | + FromToMove FTM = GO.AddComponent<FromToMove>(); |
| 129 | + FTM.identifierMotor = EventN["Identifier"].InnerText; |
| 130 | + phase.Events.Add(FTM); |
| 131 | + break; |
| 132 | + case "ToFromMove": |
| 133 | + ToFromMove TFM = GO.AddComponent<ToFromMove>(); |
| 134 | + TFM.identifierMotor = EventN["Identifier"].InnerText; |
| 135 | + phase.Events.Add(TFM); |
| 136 | + break; |
| 137 | + case "ApplyRotation": |
| 138 | + ApplyRotation AR = GO.AddComponent<ApplyRotation>(); |
| 139 | + AR.identifierMotor = EventN["Identifier"].InnerText; |
| 140 | + phase.Events.Add(AR); |
| 141 | + break; |
| 142 | + case "ChangePendulum": |
| 143 | + ChangePendulum CP = GO.AddComponent<ChangePendulum>(); |
| 144 | + CP.identifierMotor = EventN["Identifier"].InnerText; |
| 145 | + CP.Friction = float.Parse(EventN["Friction"].InnerText); |
| 146 | + CP.Pendulum = Boolean.Parse(EventN["Pendulum"].InnerText); |
| 147 | + phase.Events.Add(CP); |
| 148 | + break; |
| 149 | + default: |
| 150 | + Debug.Log("Couln't detect the right event called: " + EventN.Name); |
| 151 | + break; |
| 152 | + |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + Phases.Add(phase); |
| 157 | + } |
| 158 | + return Phases; |
| 159 | + |
| 160 | + throw new NotImplementedException(); |
| 161 | + } |
| 162 | + |
| 163 | + public static Vector3 getVector3(string rString) |
| 164 | + { |
| 165 | + string[] temp = rString.Substring(1, rString.Length - 2).Split(','); |
| 166 | + float x = float.Parse(temp[0]); |
| 167 | + float y = float.Parse(temp[1]); |
| 168 | + float z = float.Parse(temp[2]); |
| 169 | + Vector3 rValue = new Vector3(x, y, z); |
| 170 | + return rValue; |
| 171 | + } |
| 172 | +} |
| 173 | + |
0 commit comments