using System; using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; using System.Linq; using System.Text; //using System.Threading.Tasks; // VaM throws an error when this is left included. Not needed? namespace NoButYeaNS { class NBYControllerCollision2: MVRScript { private float nextActionTime = 0.0f; // just for logging every 10 seconds or so - avoid logs every frame public float period = 10; // log interval - number of seconds public override void Init() { pluginLabelJSON.val = "Controller Collision"; } // Runs once when plugin loads - after Init() protected void Start() { // check we have applied to a cube or sphere only if(!(containingAtom?.type == "Cube" || containingAtom?.type == "Sphere")) { SuperController.LogMessage("Add plugin to Cube or Sphere only"); return; } // show a message SuperController.LogMessage(pluginLabelJSON.val + " Loaded"); // change scale JSONStorableFloat jsonScale = containingAtom.GetStorableByID("scale")?.GetFloatJSONParam("scale"); if(jsonScale != null) jsonScale.val = 0.03f; // turn phyisics off - prevents the atom getting stuck when walking through walls etc. JSONStorableBool jsonPhysicsEnabled = containingAtom.GetStorableByID("control")?.GetBoolJSONParam("physicsEnabled"); if (jsonPhysicsEnabled != null) jsonPhysicsEnabled.val = false; // make semi transparrent here string matName = (containingAtom?.type == "Cube") ? "CubeMat" :"SphereMat"; // for a Sphere, the material name is different JSONStorableFloat jsonAlpha = containingAtom.GetStorableByID(matName)?.GetFloatJSONParam("Alpha Adjust"); if (jsonAlpha != null) jsonAlpha.val = -0.998f; // SuperController.LogMessage("Atom name: " + containingAtom.name); // SuperController.LogMessage("Atom type: " + containingAtom.type); } // A Unity thing - runs every physics cycle public void FixedUpdate() { // put code here } // Unity thing - runs every rendered frame public void Update() { // each frame, copy the camera position and rotation accross to the containing atom containingAtom.mainController.transform.position = CameraTarget.centerTarget.transform.position + new Vector3(0f, 0.05f, 0f); containingAtom.mainController.transform.rotation = CameraTarget.centerTarget.transform.rotation; // debug info... just prints position data every 10 seconds - left in for reference. /* if(Time.time > nextActionTime) { nextActionTime = Time.time + period; SuperController.LogMessage( "atom pos:" + containingAtom.mainController.transform.position.ToString() + ":: cam pos:" + CameraTarget.centerTarget.transform.position.ToString() + ":: type: " + containingAtom?.type ); } */ } } }