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 }
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>(); // reference CTunity script ctclient = GetComponent <CTclient>(); lineR1 = gameObject.AddComponent <LineRenderer>(); Color myColor = ctunity.objectColor(gameObject); setLineProps(lineR1, myColor, myColor); }
/// <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"; } }
//---------------------------------------------------------------------------------------------------------------- // 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; }
private void setState(String objectID, CTobject ctobject, GameObject ct) { if (ct == null || !ct.activeSelf) { return; } CTclient ctp = ct.GetComponent <CTclient>(); if (ctp != null) { ctp.setState(ctobject, replayActive, playPaused); if (newSession) { ctp.jumpState(); // do it now (don't wait for next ctclient.Update cycle) } } }
//------------------------------------------------------------------------------------------------------- // disable objects that are in CTlist but go missing from CTworld list public void clearMissing(CTworld ctworld) { if (newSession) { return; } List <String> destroyList = new List <String>(); // make copy; avoid sync error foreach (KeyValuePair <string, GameObject> entry in CTlist) // cycle through objects in world { GameObject go = entry.Value; String goName = entry.Key; if ((go == null) || !go.activeSelf) // prune inactive objects { destroyList.Add(goName); } else { // don't deactivate locally owned Player objects (might be instantiated but not yet seen in ctworld) if (!activeWrite || !goName.StartsWith(Player)) { if (!ctworld.objects.ContainsKey(goName)) { CTclient ctc = go.GetComponent <CTclient>(); if (!(ctc != null && ctc.isRogue)) // let Rogue objects persist { destroyList.Add(goName); } } } } } // clear out destroylist foreach (String t in destroyList) { // Debug.Log("clearMissing: " + t); clearObject(t); // destroy while iterating wrecks list } }
// 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); }
//---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTgroupstate script ctclient = GetComponent <CTclient>(); random = new System.Random(Guid.NewGuid().GetHashCode()); // unique seed }
// Use this for initialization void Start() { ctclient = transform.parent.GetComponent <CTclient>(); rbc = transform.parent.parent.GetComponent <Rigidbody>(); // presumes chart is grandchild of vehicle InputField[] fields = gameObject.GetComponentsInChildren <InputField>(); foreach (InputField c in fields) { switch (c.name) { case "Server": c.text = Server; break; case "Source": c.text = Source; break; case "Chan1": c.text = Chan1; break; case "Chan2": c.text = Chan2; break; case "Duration": c.text = Duration + ""; break; // case "MaxPts": // c.text = MaxPts+""; // break; } } Dropdown mode = gameObject.GetComponentInChildren <Dropdown> (); List <Dropdown.OptionData> modes = mode.GetComponent <Dropdown> ().options; if (modes[0].text == "StripChart") { mode.value = 0; // crude, hard-wired } else { mode.value = 1; } Button[] buttons = gameObject.GetComponentsInChildren <Button> (); foreach (Button b in buttons) { switch (b.name) { case "Submit": b.onClick.AddListener(submitButton); break; case "Cancel": b.onClick.AddListener(cancelButton); break; } } }
private GameObject newGameObject(CTobject ctobject, Boolean requireParent) { // define parameters String objID = ctobject.id; String prefab = ctobject.model; Vector3 position = ctobject.pos; Quaternion rotation = ctobject.rot; Vector3 scale = ctobject.scale; Color color = ctobject.color; // Debug.Log("newGameObject: " + objID+", prefab: "+prefab+", custom: "+ctobject.custom+", prefab: "+prefab+", color: "+color); if (prefab.Equals("")) { return(null); // in-game player without prefab } // already exists? if (CTlist.ContainsKey(objID)) { GameObject go = CTlist[objID]; if (go != null) { go.SetActive(true); // let setState activate? CTclient ctc = go.gameObject.transform.GetComponent <CTclient>(); string ctpf = (ctc == null) ? "" : CTlist[objID].gameObject.transform.GetComponent <CTclient>().prefab; if (!ctpf.Equals(prefab) || scale == Vector3.zero) // prefab changed! { // Debug.Log(objID+": new prefab: " + prefab +", old pf: "+ctpf); position = go.transform.localPosition; // rebuild to new prefab (in-place) rotation = go.transform.localRotation; clearObject(objID); } else { // Debug.Log("newGameObject, replacing existing object: " + objID); clearObject(objID, true); // replace vs: // return CTlist[objID]; // maintain if already there } } } GameObject tgo = GameObject.Find(objID); if (tgo != null) { Debug.Log("Warning, existing object: " + objID); // unregistered prefabs hit this check // clearObject(tgo); // clear vs leave in place? return(tgo); } // load prefab GameObject pfgo = ((GameObject)getPrefab(prefab)); if (pfgo == null) { Debug.Log("NULL prefab: " + prefab); return(null); } // pfgo.SetActive(isactive); // build hierarchical path to new object: Players/<Player>/object-path String parent = "Players"; String fullpath = parent + "/" + objID; char[] delims = { '/', ':' }; String[] pathparts = fullpath.Split(delims); GameObject pgo = GameObject.Find(parent); // "Players" at this point // Debug.Log("create objID: " + objID+", fullpath: "+fullpath); for (int i = 1; i < pathparts.Length - 1; i++) { parent = parent + "/" + pathparts[i]; GameObject cgo = GameObject.Find(parent); if (cgo == null) { if (requireParent && i > 1) // sorry clugey. can happen with async deployInventory (e.g. Launcher) { Debug.Log("Null parent! " + objID); // this can strand empty grandparent (benign) return(null); } // Debug.Log("Create empty parent: " + pathparts[i]); cgo = new GameObject(); // empty gameObject; trunk-node in hierarchy cgo.name = pathparts[i]; cgo.transform.SetParent(pgo.transform, true); } pgo = cgo; } pgo = GameObject.Find(parent); if (pgo == null) // parent missing { Debug.Log("Missing parent: " + parent + ", child: " + objID); // init issue, catch it next update... return(null); } Transform tparent = pgo.transform; Transform pf = pfgo.transform; // Instantiate! // Transform newp = Instantiate(pf, position, rotation * pf.rotation, tparent); // rez prefab with set parent Transform newp = Instantiate(pf, tparent, false); // rez prefab with set parent newp.localPosition = position /* + pf.position */; // offset by prefab built-in position? newp.localRotation = rotation * pf.rotation; // Debug.Log(objID + ": instantiate child at: " + position+", parent: "+tparent.name); if (scale.Equals(Vector3.zero)) { newp.localScale = pf.localScale; } else { newp.localScale = scale; // zero scale means use initial prefab scale } newp.name = pathparts[pathparts.Length - 1]; CTclient myctc = newp.GetComponent <CTclient>(); if (myctc != null) { myctc.newCustom(ctobject.custom); // set this now vs waiting for setState myctc.prefab = prefab; myctc.setColor(color); } // make sure in CTlist (inactive objects won't call CTregister...) CTregister(newp.gameObject); return(newp.gameObject); }
//---------------------------------------------------------------------------------------------------------------- // Use this for initialization void Start() { ctplayer = GetComponent <CTclient>(); ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script }
/// <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() { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script ctclient = transform.parent.GetComponent <CTclient>(); // interactive CT updates startTexture = GetComponent <Renderer> ().material.GetTexture("_MainTex"); }