public virtual void Init() { GameObject go = (GameObject)Instantiate(ComradeManager.Instance.GetObjectByType(leaderType), transform); head = go.GetComponent <BaseBody>(); if (head) { head.leader = true; head.recorder = new List <PathRecorder>(); recorder = head.recorder; head.speed = speed; head.linePlayer = this; } bodies.Add(go); Vector3 pos = head.transform.position; pos.y += startDistance * follower.Count * distance; for (int i = 0; i <= follower.Count * distance; i++) { recorder.Add(new PathRecorder(pos, head.dir)); pos.y -= startDistance; } for (int i = 0; i < follower.Count; i++) { AddBody(follower[i], bodies.Count); } }
public static BaseBody Spawn(BaseBody body, Vector3 pos, Quaternion rot) { BaseBody spawnedBody = Instantiate(body, pos, rot); _instance._bodies.Add(spawnedBody); spawnedBody.OnInit(); return(spawnedBody); }
public override void Think(BaseBody body) { IMoveX bodyMoveX = body as IMoveX; //IHaveDirections directions = body as IHaveDirections; Vector3 currentTarget; if (bodyMoveX != null) { if (body.Remember <bool>("goingToEnd")) { currentTarget = body.Remember <Vector3>("patrolEnd"); } else { currentTarget = body.Remember <Vector3>("patrolStart"); } if (Mathf.Abs(body.transform.position.x - currentTarget.x) <= moveDeadZone.constValue) { //if(Vector3.Magnitude(body.transform.position - currentTarget) < moveDeadZone.constValue) { Debug.Log("Switch Target"); if (body.Remember <bool>("goingToEnd")) { Debug.Log("Switch to Start"); body.Remember("goingToEnd", false); } else { Debug.Log("Switch to End"); body.Remember("goingToEnd", true); } } if (body.transform.position.x - currentTarget.x > moveDeadZone.constValue) { bodyMoveX.MoveX(-1f); } else if (body.transform.position.x - currentTarget.x < moveDeadZone.constValue) { bodyMoveX.MoveX(1f); } Debug.Log(currentTarget); } //if(directions != null) { // Vector3 heading = body.Remember<Vector3>("currentTarget") - body.transform.position; // float dot = Vector3.Dot(heading, directions.forward); //} }
// chạm vào player void OnTriggerEnter2D(Collider2D col) { target = col.GetComponent <BaseBody>(); if (target == null) { // không phải player return; } GivePlayer(); OnEat(); }
// Use this for initialization void Start() { if (_hasFirstUpdate) { return; } _hasFirstUpdate = true; if (_playerPath != null) { BaseBody player = Resources.Load <BaseBody>(_playerPath); SpawnManager.Spawn(player, Vector3.zero, Quaternion.identity); } }
public virtual void AddBody(ComradeType type, int number) { Vector3 pos = new Vector3(100, 100); GameObject body = (GameObject)Instantiate(ComradeManager.Instance.GetObjectByType(type), pos, Quaternion.identity, transform); BaseBody baseBody = body.GetComponent <BaseBody>(); try { baseBody.recorder = bodies[0].GetComponent <BaseBody>().recorder; baseBody.SetNumber(number, distance); baseBody.speed = speed; baseBody.linePlayer = this; baseBody.Turn(Direction.FOLLOW); } catch (Exception e) { Debug.Log("Error Create"); } bodies.Add(body); }
// Use this for initialization void Start() { player = transform.parent.parent.GetComponent <BaseBody>(); }
public static Message BodyParse(BaseMessage message) { var buffer = message.Content; try { var bodies = new List <BaseBody>(); do { var msgId = buffer.ReadInt(); var srcTime = buffer.ReadInt(); var targetTime = TimeUtil.BuildTime(srcTime); var msgType = buffer.ReadUnsignedShort(); var opsType = buffer.ReadUnsignedShort(); var msgAttr = buffer.ReadUnsignedShort(); var ackSuccess = (msgAttr >> 15 & 1) == 0; var infoValueTypeValue = msgAttr >> 13 & 3; var infoValueType = EnumUtil.ToEnum <InfoValueType>(infoValueTypeValue); var dataSize = (msgAttr >> 10 & 7) + 1; var reportTypeValue = msgAttr >> 8 & 3; var reportType = EnumUtil.ToEnum <ReportType>(reportTypeValue); var isTest = (msgAttr >> 7 & 1) == 1; var isHistory = (msgAttr >> 6 & 1) == 1; var isRepeat = (msgAttr >> 5 & 1) == 1; var force = (msgAttr >> 4 & 1) == 1; var digitType = msgAttr & 7; var attr = new Attribute(); attr.AckSuccess = ackSuccess; attr.ValueType = infoValueType; attr.DataSize = dataSize; attr.ReportType = reportType; attr.IsTest = isTest; attr.IsHistory = isHistory; attr.IsRepeat = isRepeat; attr.Force = force; attr.DigitType = EnumUtil.ToEnum <DigitType>(digitType); var coreContentLen = buffer.ReadUnsignedShort(); var serial = buffer.ReadInt(); var coreContent = new byte[coreContentLen - 4]; buffer.ReadBytes(coreContent); var body = new BaseBody(); body.IdType = EnumUtil.ToEnum <IdType>(msgId); body.Time = targetTime; body.MsgType = EnumUtil.ToEnum <MsgType>(msgType); body.OpsType = EnumUtil.ToEnum <OpsType>(opsType); body.Attribute = attr; body.Length = coreContentLen; body.SerialNumber = serial; body.CoreMsg = coreContent; bodies.Add(body); } while (buffer.ReadableBytes > 0); return(new Message { Header = message.Header, Bodies = bodies }); } finally { buffer.SafeRelease(); } }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); baseBody = GetComponent <BaseBody>(); }
public static void Despawn(BaseBody body) { _instance._bodies.Remove(body); body.OnDestroy(); Destroy(body.gameObject); }
static async Task MonitoringApi(Api api, BaseBody @base) { _newRead = new ReadDAO(); int minute = 60000; HttpResponseMessage response; using (HttpClient client = new HttpClient()) { try { while (true) { response = await client.GetAsync(api.EndPoint); //Faz a requisição @base.ValidateStatusCode(response.StatusCode); //Valida o status code retornado da requisição if (@base.IsOnline) { Console.WriteLine("API Online!"); } else { Console.WriteLine("API Offline :("); } @base.ValidateResponseBody(await response.Content.ReadAsStringAsync());//Valida o corpo da requisição if (@base.IsValid) { Console.WriteLine("Resposta da API validada!"); } else { Console.WriteLine("Resposta da API ínvalida! :("); } //Instanciando um novo objeto de leitura Read read = new Read { Active = @base.IsOnline, Valid = @base.IsValid, ReadMoment = DateTime.Now, IdApi = api.Id }; //Inserindo a leitura no banco _newRead.Insert(read); Thread.Sleep(minute);//Tempo de delay de monitoramento, a validar. //ACRESCENTAR TIMER AO INVES DE THREAD.SLEEP Console.WriteLine("");//Quebra de linha para o próximo monitoramento } } catch (HttpRequestException e) { //tratamento de exceção Console.WriteLine("\nOcorreu uma exceção!"); Console.WriteLine("Mensagem :{0} ", e.Message); } } }
static void Main(string[] args) { #region Tablica jednowymiarowa //int[] a = new int[3]; //a[0] = 1; //a[1] = 3; //a[2] = 5; //for (int i = 0; i < a.Length; i++) //{ // Console.WriteLine(a[i]); //} #endregion #region Tablica dwuwymiarowa //int[,] b = new int[10, 10]; //b[0, 0] = 10; //b[0, 2] = 20; //b[1, 3] = 30; //b[2, 4] = 40; //b[5, 6] = 50; //for (int i = 0; i < 10; i++) //{ // for (int j = 0; j < 10; j++) // { // Console.WriteLine(b[i,j]); // } //} #endregion #region Tablica wyszczerbiona //int[][] c = new int[5][]; //c[0] = new int[3]; //c[1] = new int[5]; //c[2] = new int[2]; //c[3] = new int[4]; //c[4] = new int[2]; //c[0][0] = 1; //c[0][1] = 1; //c[0][2] = 1; //c[1][0] = 2; //c[1][1] = 2; //c[1][2] = 2; //c[1][3] = 2; //c[1][4] = 2; //c[2][0] = 3; //c[2][1] = 3; //c[3][0] = 4; //c[3][1] = 4; //c[3][2] = 4; //c[3][3] = 4; //c[4][0] = 5; //c[4][1] = 5; //for (int i = 0; i < c.Length; i++) //{ // for (int j = 0; j < c[i].Length; j++) // { // Console.WriteLine(c[i][j]); // } //} #endregion #region Guid //int x = default(int); // defaultowo 0; //Console.WriteLine("x = " + x); //Guid y = new Guid(); //y = default(Guid); // defaultowo 000-000-000000.... itd //Console.WriteLine("y = " + y); #endregion #region Dictionary //klucz nie moze sie powtarzac //Dictionary<int, TestClass> a = new Dictionary<int, TestClass>(); //a.Add(1, new TestClass { TestClassID = 1, TestClassName = "test1" }); //a.Add(2, new TestClass { TestClassID = 11, TestClassName = "test2" }); //a.Add(3, new TestClass { TestClassID = 111, TestClassName = "test3" }); //a.Add(4, new TestClass { TestClassID = 1111, TestClassName = "test4" }); //foreach (var i in a) //{ // Console.WriteLine(i.Key + " | " + i.Value.TestClassID + " | " + i.Value.TestClassName); //} //Console.WriteLine(a[1].TestClassName); //pierwszyy element wg klucza (indeksu) //Console.WriteLine(a.ElementAt(0).Value.TestClassName; // pierwszy element wg indeksu jak dla tablic #endregion #region KeyValuePair //klucz moze sie powtarzac //KeyValuePair<int, TestClass> collectionA = new KeyValuePair<int, TestClass>(1, new TestClass { TestClassID = 1, TestClassName = "uwemheh1" }); //KeyValuePair<int, TestClass> collectionB = new KeyValuePair<int, TestClass>(1, new TestClass { TestClassID = 2, TestClassName = "uwemheh2" }); //List<KeyValuePair<int, TestClass>> listofKVP = new List<KeyValuePair<int, TestClass>>(); //listofKVP.Add(collectionA); //listofKVP.Add(collectionB); #endregion #region HermeryzacjaStatyczna //Console.WriteLine(Dodawanie(2,3)); //Console.WriteLine(Dodawanie(2,3,5)); #endregion #region OdwolanieDoEnuma //Console.WriteLine((int)TestEnum.Wtorek); //TestEnum nowyEnum = TestEnum.Wtorek; //switch(nowyEnum) //{ // case TestEnum.Poniedzialek: // break; // case TestEnum.Wtorek: // break; // case TestEnum.Sroda: // break; // default: // break; //} #endregion #region POLIMORFIZM DYNAMICZNY BaseBody bb = new BaseBody(); //bb.CreateBase("Baza bazowa", 20.4f, 31.4f); //bo stworzylem konstruktor MilitaryBase mb = new MilitaryBase("Wojskowa", 9.9f, 2.2f); //mb.CreateBase("Wojskowa", 9.9f, 2.2f); //bo stworzylem konstruktor MilitaryBase mb2 = new MilitaryBase("Bazwa wojskowa z ochrona", 11.1f, 22.2f, 100); //mb2.CreateBase("Bazwa wojskowa z ochrona", 11.1f, 22.2f, 100); //bo stworzylem konstruktor BaseBody mbb = new MilitaryBase("base body o ksztalcie military base", 21.1f, 32.2f); //mbb.CreateBase("base body o ksztalcie military base", 21.1f, 32.2f); //bo stworzylem konstruktor //BaseBody mbb2 = new MilitaryBase(); //mbb2.CreateBase("base body o ksztalcie military base", 21.1f, 32.2f, 200); //NIE MOZNA WYKONAC BO ROBIMY BASEBODY NA KSZTALT MILITARYBODY A TAM NIE MA METODY POLIMORFICZNEJ (DYNAMICZNEJ-NADPISYWANEJ) Z PRZECIAZENIEM TZN. Z WALLRESISTANCE //MilitaryBase mbbb() = new BaseBody(); //NIE DZIALA BO POLIMORFIZM DYNAMICZNY DZIALA ZAWSZE W DOL NIGDY W GORE, NP. DZIECIAK NIGDY NIE MOZE PRZYJAC KSZTALTU RODZICA ALE RODZIC ZAWSZE MOZE PRZYJAC KSZTALT DZIECKA #endregion Console.ReadKey(); }