//---------------------------------------------------------------------------------------------------------------- // set object color internal void setColor(Color color) { if (ctunity == null) { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // async? } // Debug.Log(name + ": setColor(" + color + "), autoColor: " + autoColor+", ctunity: "+ctunity+", clear: "+Color.clear); if (autoColor && color == Color.clear && ctunity != null) { color = ctunity.objectColor(gameObject); // Debug.Log(">setColor(" + color + "), autoColor: " + autoColor); } if (color == Color.clear) { return; // use default color } myColor = color; Renderer rend = gameObject.GetComponent <Renderer>(); if (rend != null) { rend.material.color = color; } // apply color to any model component labelled "Trim": Component[] renderers = GetComponentsInChildren(typeof(Renderer)); foreach (Renderer childRenderer in renderers) { if (childRenderer.material.name.StartsWith("Trim")) // clugy { childRenderer.material.color = color; } } }
//---------------------------------------------------------------------------------------------------------------- // detect collisions void OnCollisionEnter(Collision collision) { if (debug) { Debug.Log(CTunity.fullName(gameObject) + ", Collision with: " + CTunity.fullName(collision.collider.gameObject)); } if (!showHP) { return; } ScoreBoard tkso = collision.collider.gameObject.GetComponent <ScoreBoard>(); if (debug) { // Debug.Log(gameObject.name + ", activePlayer: " + ctunity.activePlayer(gameObject) + ", activeWrite: " + CTunity.activeWrite + ", newSession: " + ctunity.newSession + ", localP: " + ctunity.localPlayer(gameObject)); // Debug.Log("ctplayer: " + ctunity.ctplayer + ", paused: " + ctunity.gamePaused + ", replayActive: " + ctunity.replayActive + ", Player: " + ctunity.Player); } if (tkso != null && ctunity.activePlayer(gameObject) && !ctunity.localPlayer(collision.gameObject)) { kso = tkso; thisCollider = collision.collider; targetScale = transform.localScale; stopWatch = damageInterval; // quick hit to start if (debug) { Debug.Log("HIT! thisCollider: " + thisCollider); } } }
static internal String custom = null; // "global" params (shared between objects) // Use this for initialization void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); ctclient = GetComponent <CTclient>(); // if (showHP) int.TryParse(ctclient.getCustom("HP", HP + ""), out HP); if (showHP) { initialHP = HP; // init to static global value int hp = ctclient.getCustom("HP", 0); // Debug.Log(name+",startup HP: "+HP+", hp: " + hp + ", custom: " + ctclient.custom); if (hp != 0) { HP = hp; // over-ride baked-in if custom present initialHP = HP; } if (HP == 0) { showHP = false; // nope } } initialScale = transform.localScale; stopWatch = 0; // Debug.Log(name + ", showHP: " + showHP); mainCamera = Camera.main; // up front for efficiency }
//---------------------------------------------------------------------------------------------------------------- // Update is called once per frame void Update() { if (ctunity == null || ctclient == null) { Debug.Log(name + ", oops no ctunity/ctlient!"); return; // async } if (!ctunity.activePlayer(gameObject)) { return; } launchInterval = ctclient.getCustom("dt", launchInterval); stopWatch += Time.deltaTime; if (stopWatch >= launchInterval) { String missile = ctclient.getCustom("M", Missile); // optional custom missile Ilaunch = ctclient.getCustom("N", Ilaunch); Nlaunch = ctclient.getCustom("Nmax", Nlaunch); // Debug.Log(name + ": Nlaunch: " + Nlaunch+", launchInterval: "+launchInterval); if (Nlaunch != 0 && Ilaunch >= Nlaunch) { return; } ctunity.deployInventory(missile, CTunity.fullName(gameObject) + "/R-" + Ilaunch); Ilaunch++; ctclient.putCustom("N", Ilaunch); stopWatch = 0; } }
// Use this for initialization void Start() { // ctunity = GameObject.Find("CTunity"); ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); targetPos = transform.position; mainCamera = Camera.main; // up front for efficiency }
public Boolean keyToggleReplay = false; // set true for down/up arrow key toggle RT-Replay //---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { slider = GameObject.Find("Slider").GetComponent <Slider> (); ctunity = GameObject.Find("CTunity").GetComponent <CTunity> (); // reference CTunity script replayText.supportRichText = true; setStateText(pausedLabel); }
//---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { // ctclient = GetComponent<CTclient>(); ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTgroupstate script // random = new System.Random(); random = new System.Random(Guid.NewGuid().GetHashCode()); // unique seed }
private Color myColor = Color.clear; // clear means use default color // Use this for initialization void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script ctclient = GetComponent <CTclient>(); lineR1 = gameObject.AddComponent <LineRenderer>(); // Color myColor = ctunity.Text2Color(name, 1F); setLineProps(lineR1, Color.black, Color.clear); // KISS }
// Use this for initialization void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); winText.text = ""; countText.text = ""; winText.supportRichText = true; countText.supportRichText = true; }
//---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { // Debug.Log (CTunity.fullName(gameObject)+": Hello World!"); ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script rb = GetComponent <Rigidbody>(); baseRotation = transform.rotation; // for relative rotation setting mainCamera = Camera.main; // up front for efficiency }
// Use this for initialization void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script ctclient = GetComponent <CTclient>(); lineR1 = gameObject.AddComponent <LineRenderer>(); Color myColor = ctunity.objectColor(gameObject); setLineProps(lineR1, myColor, myColor); }
void OnCollisionExit(Collision collision) { if (debug) { Debug.Log(CTunity.fullName(gameObject) + ", END Collision with: " + collision.collider.name); } if (thisCollider == collision.collider) { thisCollider = null; } }
void OnTriggerExit(Collider collider) { if (debug) { Debug.Log(CTunity.fullName(gameObject) + ", END Trigger with: " + collider.name); } if (thisCollider == collider) { thisCollider = null; } }
//---------------------------------------------------------------------------------------------------------------- void doCollision(Collider other) { if (debug) { Debug.Log(name + ": doCollision, showHP: " + showHP + ", kso: " + kso); } if (!showHP || kso == null) { return; // no game } // if (!showHP || kso == null || !ctunity.activePlayer(gameObject)) return; // no game String myName = CTunity.fullName(gameObject); String otherName = CTunity.fullName(other.gameObject); if (ctunity == null) { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); } if (other.gameObject == null || ctunity == null) { Debug.Log(name + ": OnTrigger null other object: " + other.name); return; } // compare hit levels to see who wins HP = ctclient.getCustom("HP", HP); int damage = (int)Math.Ceiling((float)kso.ATK / (float)AC); HP -= damage; if (HP < 0) { HP = 0; } ctclient.putCustom("HP", HP); if (HP <= 0) { if (killParent) // can't destroyImmediate inside collision callback { ctunity.clearObject(gameObject.transform.parent.gameObject, false); } else { ctunity.clearObject(gameObject, false); } } // Debug.Log(myName + ", collide with: " + otherName+", damage: "+damage+", kso.ATK: "+kso.ATK+", AC: "+AC); if (scaleSize) { targetScale = initialScale * (0.1f + 0.9f * ((float)(HP) / (float)initialHP)); } }
/// <summary> /// Create a CSV serialized version of the player information. /// </summary> /// <param name="ctunityI">Source of the information to be serialized.</param> /// <returns>Serialized player information.</returns> private static string serialize_csv(CTunity ctunityI) { // header line: string CTstateString = "#" + ctunityI.replayText + ":" + ctunityI.ServerTime().ToString() + ":" + ctunityI.Player + "\n"; string delim = ";"; int objectCount = 0; foreach (GameObject ct in ctunityI.CTlist.Values) { if (ct == null) { continue; } CTclient ctp = ct.GetComponent <CTclient>(); if (ctp == null) { continue; } // UnityEngine.Debug.Log("CTput: " + ct.name+", active: "+ct.activeSelf); String prefab = ctp.prefab; if (prefab.Equals("Ghost")) { continue; // no save ghosts } // if (!ctunityI.replayActive && !ct.name.StartsWith(ctunityI.Player)) continue; // only save locally owned objects if (!ctunityI.localPlayer(ct)) { continue; // only save locally owned objects } CTstateString += ct.name; // CTstateString += (delim + ct.tag); CTstateString += (delim + prefab); CTstateString += (delim + (ct.activeSelf ? "1" : "0")); CTstateString += (delim + ct.transform.localPosition.ToString("F4")); CTstateString += (delim + ct.transform.localRotation.eulerAngles.ToString("F4")); if (ctp.link != null && ctp.link.Length > 0) { CTstateString += (delim + ctp.link); } CTstateString += "\n"; objectCount++; } if (objectCount == 0) { return(null); // no objects, don't bother } return(CTstateString); }
public String TrackTarget = null; // child target (player.tracktarget) // Use this for initialization void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script ctclient = GetComponent <CTclient>(); // myScale = transform.localScale; // scale not set until enabled? transform.localScale = new Vector3(0.01f, 0.01f, 0.01f); // hide at startup // ctclient.custom = TrackTarget; if (TrackTarget == null || TrackTarget.Equals("")) { TrackTarget = ctunity.Player + "/Ball"; } }
/// <summary> /// Deserialize a string into a List of one or more CTworld objects. /// This method supports parsing ".txt"/csv and JSON strings. /// </summary> /// <param name="strI">The serialized world objects.</param> /// <returns>A List of CTworlds, parsed from the given string.</returns> public static List <CTworld> deserialize(CTunity ctunityI, string strI) { List <CTworld> worlds = null; if (strI[0] == '#') { worlds = CTserdes.deserialize_csv(strI); } else if (strI[0] == '{') { worlds = CTserdes.deserialize_json(ctunityI, strI); } return(worlds); }
/// <summary> /// Create a serialized version of the player information. /// This method supports serializing to ".txt"/csv and JSON formats. /// </summary> /// <param name="ctunityI">Source of the information to be serialized.</param> /// <param name="formatI">Specifies the desired output serialization format.</param> /// <returns>Serialized player information.</returns> public static string serialize(CTunity ctunityI, Format formatI) { string serStr = null; if (formatI == Format.CSV) { serStr = serialize_csv(ctunityI); } else if (formatI == Format.JSON) { serStr = serialize_json(ctunityI); } return(serStr); }
private Dictionary <String, String> kvdict = null; // local dictionary of custom key-values //---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { rb = GetComponent <Rigidbody>(); ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script // if (autoColor) setColor(); // set default color based on object name fullName = CTunity.fullName(gameObject); // get once in advance ctunity.CTregister(gameObject); // register with CTunity... trail = GetComponent <TrailRenderer>(); // optional trail track // Debug.Log(name+": start ctunity: " + ctunity); if (LookAtMe) { GameObject.Find("Main Camera").GetComponent <maxCamera>().setTarget(transform); } }
//---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTgroupstate script ctclient = GetComponent <CTclient>(); if (ctclient == null) { ctclient = transform.parent.GetComponent <CTclient>(); // try parent (e.g. RocketPlane/Launcher) } if (ctclient == null) { Debug.Log("Launcher no CTclient!"); } stopWatch = 0; }
//---------------------------------------------------------------------------------------------------------------- // detect triggers void OnTriggerEnter(Collider collider) { if (debug) { Debug.Log(CTunity.fullName(gameObject) + ", Trigger with: " + collider.name); } if (!showHP) { return; } ScoreBoard tkso = collider.gameObject.GetComponent <ScoreBoard>(); // if(tkso != null) Debug.Log("new kso.ATK: " + tkso.ATK + ", thisCollider: " + thisCollider); if (tkso != null && ctunity.activePlayer(gameObject) && !ctunity.localPlayer(collider.gameObject)) { kso = tkso; thisCollider = collider; targetScale = transform.localScale; stopWatch = damageInterval; // quick hit to start } }
// string[] xvals = null, yvals = null; void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script ctclient = GetComponent <CTclient>(); // interactive CT updates foreach (Transform child in transform) { if (child.name == "Chart1") { Chart1 = child.gameObject; Chart1.AddComponent <LineRenderer> (); lineR1 = Chart1.GetComponent <LineRenderer>(); } if (child.name == "Chart2") { Chart2 = child.gameObject; Chart2.AddComponent <LineRenderer> (); lineR2 = Chart2.GetComponent <LineRenderer>(); } } setLineProps(lineR1, Color.blue); setLineProps(lineR2, Color.red); }
//---------------------------------------------------------------------------------------------------------------- void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script // Init(); }
/// <summary> /// Deserialize the given JSON string into a List of CTworld objects. /// The given string may contain one or a concatenation of several "world" objects. /// /// JSON example: /// {"mode":"Live","time":1.536844452785E9,"name":"Blue","objects":[{"id":"Blue","prefab":"Ball","state":true,"pos":[-8.380356788635254,0.25,3.8628578186035156],"rot":[0.0,0.0,0.0],"custom":""}]} /// /// </summary> /// <param name="strI">The JSON serialized world objects.</param> /// <returns>A List of CTworlds, parsed from the given string.</returns> private static List <CTworld> deserialize_json(CTunity ctunityI, string strI) { if ((strI == null) || (strI.Length < 10)) { return(null); } List <CTworld> worlds = new List <CTworld>(); // Break up the given string into different "world" objects // NOTE: This assumes that "player" is the first field in the JSON string List <int> indexes = AllIndexesOf(strI, @"{""player"":"""); if (indexes.Count == 0) { return(null); } for (int i = 0; i < indexes.Count; ++i) { int startIdx = indexes[i]; int endIdx = strI.Length - 1; if (i < (indexes.Count - 1)) { endIdx = indexes[i + 1]; } string nextWorldStr = strI.Substring(startIdx, endIdx - startIdx); CTworldJson dataFromJson = null; try { dataFromJson = JsonUtility.FromJson <CTworldJson>(nextWorldStr); } catch (Exception e) { UnityEngine.Debug.Log("Exception deserializing JSON: " + e.Message); continue; } if (dataFromJson == null || dataFromJson.objects == null) { continue; } // skip active local player ( save the effort here and in MergeWorlds() ) // ?? seems to have issues PB <--> RT ?? // if(ctunityI.activePlayer(dataFromJson.player)) continue; // Create CTworld object from CTworldJson (these classes are very similar but there are differences, see definitions above) CTworld jCTW = new CTworld(); jCTW.player = dataFromJson.player; jCTW.time = dataFromJson.time; // jCTW.mode = dataFromJson.mode; jCTW.objects = new Dictionary <String, CTobject>(); foreach (CTobjectJson ctobject in dataFromJson.objects) { CTobject cto = new CTobject(); cto.id = ctobject.id; // legacy format conversion: // if (cto.id.Equals(jCTW.player)) cto.id = cto.id + "/" + cto.id; // convert old top-level player // else if (cto.id.StartsWith(jCTW.player + ".")) cto.id = cto.id.Remove(0, jCTW.player.Length + 1); // Debug.Log("deserialize id: " + cto.id); cto.model = ctobject.model; // cto.state = ctobject.state; // cto.link = ctobject.link; cto.pos = new Vector3((float)ctobject.pos[0], (float)ctobject.pos[1], (float)ctobject.pos[2]); cto.rot = Quaternion.Euler((float)ctobject.rot[0], (float)ctobject.rot[1], (float)ctobject.rot[2]); cto.scale = new Vector3((float)ctobject.scale[0], (float)ctobject.scale[1], (float)ctobject.scale[2]); cto.color = new Color((float)ctobject.color[0], (float)ctobject.color[1], (float)ctobject.color[2], (float)ctobject.color[3]); cto.custom = ctobject.custom; jCTW.objects.Add(cto.id, cto); } worlds.Add(jCTW); } if (worlds.Count == 0) { return(null); } return(worlds); }
/// <summary> /// Create a JSON serialized version of the player information. /// </summary> /// <param name="ctunityI">Source of the information to be serialized.</param> /// <returns>Serialized player information.</returns> private static string serialize_json(CTunity ctunityI) { CTworldJson world = new CTworldJson(); world.player = ctunityI.Player; world.time = ctunityI.ServerTime(); // world.mode = ctunityI.replayText; world.objects = new List <CTobjectJson>(); int objectCount = 0; foreach (GameObject ct in ctunityI.CTlist.Values) { if (!ctunityI.localPlayer(ct)) { continue; // only save locally owned objects } // Debug.Log("CTserdes ct.name: " + fullName); if (ct == null) { continue; } CTclient ctp = ct.GetComponent <CTclient>(); if (ctp == null) { continue; } String prefab = ctp.prefab; if (prefab.Equals("Ghost")) { continue; // no save ghosts } // if (!ctunityI.replayActive && !ct.name.StartsWith(ctunityI.Player)) continue; // only save locally owned objects // if (!ctunityI.doCTwrite(fullName)) continue; // only save locally owned objects CTobjectJson obj = new CTobjectJson(); // obj.id = ct.name; // strip leading world-name from embedded object name String fullName = CTunity.fullName(ct); if (fullName.StartsWith(world.player + "/")) { fullName = fullName.Remove(0, world.player.Length + 1); } // Debug.Log("CTserdes obj.id: " + obj.id + ", world.player: " + world.player+", fullName: "+fullName); obj.id = fullName; obj.model = prefab; // obj.state = (ct.activeSelf ? true : false); // NOTE: limit floating point values to 4 decimal places obj.pos = new List <Double>(); obj.pos.Add(LimitPrecision(ct.transform.localPosition.x, 4)); // was .position obj.pos.Add(LimitPrecision(ct.transform.localPosition.y, 4)); obj.pos.Add(LimitPrecision(ct.transform.localPosition.z, 4)); obj.rot = new List <Double>(); obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.x, 4)); // was .rotation obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.y, 4)); obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.z, 4)); obj.scale = new List <Double>(); obj.scale.Add(LimitPrecision(ct.transform.localScale.x, 4)); obj.scale.Add(LimitPrecision(ct.transform.localScale.y, 4)); obj.scale.Add(LimitPrecision(ct.transform.localScale.z, 4)); Renderer renderer = ct.transform.gameObject.GetComponent <Renderer>(); if (renderer != null) { // Color mycolor = renderer.material.color; // this NG for multi-part prefabs (e.g. biplane) Color mycolor = ctp.myColor; // NG? obj.color = new List <Double>(); obj.color.Add(LimitPrecision(mycolor.r, 4)); obj.color.Add(LimitPrecision(mycolor.g, 4)); obj.color.Add(LimitPrecision(mycolor.b, 4)); obj.color.Add(LimitPrecision(mycolor.a, 4)); } // if (ctp.link != null && ctp.link.Length > 0) obj.link = ctp.link; if (ctp.custom != null && ctp.custom.Length > 0) { obj.custom = ctp.custom; } world.objects.Add(obj); objectCount++; } // Debug.Log("serialize: "+ world.player+", count: "+ objectCount); // if (objectCount == 0) return null; // notta. (returning no-object string writes header-only) string jsonData = null; try { jsonData = JsonUtility.ToJson(world); } catch (Exception e) { UnityEngine.Debug.Log("Exception serializing JSON: " + e.Message); return(null); } // jsonData = jsonData.Replace("},", "},\n"); // for readability jsonData = jsonData.Replace("{\"id", "\n{\"id"); // for readability return(jsonData); }
//---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { ctplayer = GetComponent <CTclient>(); ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script }
//---------------------------------------------------------------------------------------------------------------- // Take a shot immediately void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); StartCoroutine("SaveJPG"); }
// Use this for initialization void Start() { gameOptions = GameObject.Find("Setup").gameObject; ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTgroupstate script setColor(); }
//---------------------------------------------------------------------------------------------------------------- void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); rawimage = GetComponent <RawImage>(); }
//---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { replayControl = GameObject.Find("replayControl"); ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTgroupstate script gameOptions = GameObject.Find("Setup").gameObject; // define menu objects myCamera = GameObject.Find("Main Camera").GetComponent <maxCamera>(); Server = GameObject.Find("Server"); Session = GameObject.Find("Session"); Player = GameObject.Find("Player1"); Deploy = GameObject.Find("Deploy"); Login = GameObject.Find("Login"); User = GameObject.Find("User"); Password = GameObject.Find("Password"); // setup callbacks Button[] buttons = gameObject.GetComponentsInChildren <Button>(); foreach (Button b in buttons) { switch (b.name) { case "Login": b.onClick.AddListener(loginButton); break; case "Quit": b.onClick.AddListener(quitButton); break; } } Dropdown[] drops = gameObject.GetComponentsInChildren <Dropdown>(); foreach (Dropdown d in drops) { switch (d.name) { case "Session": // ctunity.Session = d.GetComponent<Dropdown>().options[d.value].text; // initialize // add listener to update session settings d.onValueChanged.AddListener(delegate { ctunity.Session = d.GetComponent <Dropdown>().options[d.value].text; // set selected session updateSession(); myCamera.setTarget(null); // reset cam target to default myCamera.Init(); if (playerDrop != null) { ctunity.Player = playerDrop.GetComponent <Dropdown>().options[0].text; ctunity.serverConnect(); // reset player path playerDrop.value = 0; } }); break; case "Deploy": // add listener to deploy new world d.onValueChanged.AddListener(delegate { if (d.value != 0) { string svalue = d.GetComponent <Dropdown>().options[d.value].text; if (svalue.Equals(ctunity.Save)) { ctunity.SnapShot(); // StartCoroutine("getInventoryList"); // update list of "World" prefabs } else if (svalue.Equals(ctunity.Clear)) { ctunity.clearWorld(); } else if (svalue.Equals(ctunity.Load)) { ctunity.clearWorld(); ctunity.loadWorld(); } else { ctunity.deployInventory(svalue); } d.value = 0; // reset to blank } }); break; case "Player1": playerDrop = d; ctunity.Player = d.GetComponent <Dropdown>().options[d.value].text; // init? // playerDrop.GetComponent<Button>().onClick.AddListener(onClick); d.onValueChanged.AddListener(delegate { String player = d.GetComponent <Dropdown>().options[d.value].text; // Debug.Log("onValueChanged, d.value: " + d.value + ", ctunity.Player: " + ctunity.Player + ", player: " + player); if (!player.Equals(ctunity.Player)) { updateSession(); // avoid new player set as child of prior player? ctunity.Player = player; // Debug.Log("new Player: " + player + ", d.value: " + d.value); ctunity.serverConnect(); // reset player path } replayControl.SetActive(ctunity.observerMode()); }); break; } } modeSelect(); }