示例#1
0
        void CreateBirdFormGos()
        {
            if (birdgoes == null)
            {
                birdgoes                  = new GameObject();
                birdgoes.name             = "Birds";
                birdgoes.transform.parent = sman.rgo.transform;
            }
            if (birdformgo != null)
            {
                Destroy(birdformgo);
                birdformgo = null;
            }
            var curpos = birdgo.transform.position;
            var currot = birdgo.transform.localRotation;

            switch (birdform)
            {
            case BirdFormE.sphere:
            {
                birdformgo = GraphUtil.CreateMarkerSphere("sphere", Vector3.zero, size: 0.3f, clr: "yellow");
                birdformgo.transform.localRotation = currot;
                birdformgo.transform.localPosition = curpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                birdgo.name = "Sphere";
                break;
            }

            case BirdFormE.longsphere:
            {
                birdformgo = GraphUtil.CreateMarkerSphere("sphere", Vector3.zero, size: 0.2f, clr: "yellow");
                var nosept = new Vector3(0, 0, 0.1f);

                var gonose = GraphUtil.CreateMarkerSphere("nose", nosept, size: 0.1f, clr: "red");
                gonose.transform.parent = birdformgo.transform;

                birdformgo.transform.localScale    = new Vector3(0.25f, 0.25f, 0.5f);      // somehow adding the nose made the sphere bigger ??
                birdformgo.transform.localRotation = currot;
                birdformgo.transform.localPosition = curpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                //                        birdformgo.transform.Rotate(90, 0, 0);
                birdgo.name = "Olive";
                break;
            }

            default:
            case BirdFormE.hummingbird:
            {
                var objPrefab = Resources.Load <GameObject>("hummingbird");
                birdformgo = Instantiate <GameObject>(objPrefab) as GameObject;
                var s = 0.5e-3f;
                birdformgo.transform.localScale    = new Vector3(s, s, s);
                birdformgo.transform.localRotation = currot;
                birdformgo.transform.localPosition = curpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                birdgo.name = "Bird";
                break;
            }

            case BirdFormE.person:
            {
                //if (birdresourcename=="")
                //{
                //    birdresourcename = "girl004";
                //}
                birdformgo = person.LoadPersonGo("-ava-bc");
                if (person.hasHololens)
                {
                    person.ActivateHololens(true);
                }
                var s = 1.0f;
                birdformgo.transform.localScale    = new Vector3(s, s, s);
                birdformgo.transform.localRotation = currot;
                //var noise = GraphAlgos.GraphUtil.GetRanFloat(0, 0.6f,"jnygen");
                var newpos = new Vector3(curpos.x + 0.3f, curpos.y - 1.55f, curpos.z);
                birdformgo.transform.localPosition = newpos;
                movingAnimationScript  = "Animations/PersonWalk";
                restingAnimationScript = "Animations/PersonIdle";
                //BirdFlyHeight = 1.5f;
                birdgo.name = birdresourcename;
                if (person)
                {
                    if (person.hasCamera)
                    {
                        person.AddCamera(birdformgo, "BirdCtrl CreateBirdFormGos");
                    }
                    if (person.grabbedMainCamera)
                    {
                        person.GrabMainCamera();
                    }
                }
                break;
            }

            case BirdFormE.car:
            {
                //Debug.Log("Loading car resourcename:" + birdresourcename);
                if (birdresourcename == "")
                {
                    birdresourcename = "car001";
                }
                //var objPrefab = Resources.Load<GameObject>("Cars/"+birdresourcename);
                //birdformgo = Instantiate<GameObject>(objPrefab);
                birdformgo = VehicleMan.LoadCarGo(birdgo, birdresourcename);
                //var s = 1.0f;
                //birdformgo.transform.localScale = new Vector3(s, s, s);
                birdformgo.transform.localRotation = currot;
                var noise  = GraphAlgos.GraphUtil.GetRanFloat(0, 0.5f, "jnygen");
                var newpos = new Vector3(curpos.x + 1.2f + noise, curpos.y - 1.55f, curpos.z);
                birdformgo.transform.localPosition += newpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                birdgo.name = birdresourcename;
                if (person)
                {
                    if (person.hasCamera)
                    {
                        person.AddCamera(birdformgo, "BirdCtrl CreateBirdFormGos");
                    }
                    if (person.grabbedMainCamera)
                    {
                        person.GrabMainCamera();
                    }
                }
                break;
            }
            }
//            birdformgo.transform.parent = birdgo.transform;
            birdformgo.transform.SetParent(birdgo.transform, true);// should be false....

            lastbirdform = birdform;
        }
示例#2
0
        public void CreateObjects()
        {
            // have to defer
            //Debug.Log("start slot");

            if (slotformgo != null)
            {
                DeleteGos();
                //Debug.Log("opps slotformgo should be null:" + slotformgo.name);
            }

            this.slotformgo = new GameObject(name + "_formgo_" + instance);
            instance++;
            slotformgo.transform.parent = this.transform;
            var gm = garage.gm;
            var slotformselector = gm.slotform;
            //Debug.Log("Generating slotform:" + slotformselector);
            bool createfloor   = gm.showFloor;
            bool createparkbox = gm.showParkbox;
            bool createsign    = gm.showSign;
            bool createnode    = gm.showNode;
            bool createraspi   = gm.showRaspi;
            bool createcam     = gm.showCam;

            createcam = false; // this is a performance killer as it creates very very many cameras - turning off for now
            bool createcar = gm.showCar;

            if (createfloor)
            {
                floor = GameObject.CreatePrimitive(PrimitiveType.Cube);
                floor.transform.parent = slotformgo.transform;
                floor.name             = "floor";
                var floorwid = 2.0f;
                floorwid = garage.slot2slotdist;
                floor.transform.localScale = new Vector3(slotlen, 0.01f, floorwid);
                var crenderer = floor.GetComponent <Renderer>();
                crenderer.material.color  = Color.gray;
                crenderer.material.shader = Shader.Find("Diffuse");
                var clrdr = floor.GetComponent <Collider>();
                clrdr.enabled = false;
                //map.AddDrawingElement(new OnlineMapsDrawingRect(new Vector2(2, 2), new Vector2(1, 1), Color.green, 1,Color.blue));
            }
            if (createparkbox)
            {
                parkbox = GameObject.CreatePrimitive(PrimitiveType.Cube);
                parkbox.transform.parent     = slotformgo.transform;
                parkbox.transform.localScale = new Vector3(slotlen, slothit, slotwid);
                parkbox.transform.position   = new Vector3(0f, 0.9f, 0f);
                parkbox.name = "parkbox";
                var pbrenderer = parkbox.GetComponent <Renderer>();
                pbrenderer.material.color  = new Color(0.5f, 0.5f, 0.5f, 0.5f); // transparent gray
                pbrenderer.material.shader = Shader.Find("Transparent/Diffuse");
                var clrdr = parkbox.GetComponent <Collider>();
                clrdr.enabled = false;
            }
            if (createsign)
            {
                sign = GameObject.CreatePrimitive(PrimitiveType.Cube);
                sign.transform.parent     = slotformgo.transform;
                sign.name                 = "sign";
                sign.transform.localScale = new Vector3(0.1f, 0.5f, 1f);
                //        sign.transform.rotation = Quaternion.Euler(0, 90, 0);
                sign.transform.position = new Vector3(slotlen / 2, 1.2f, 0);
                SetSlotState(slotstate);
                var clrdr = sign.GetComponent <Collider>();
                clrdr.enabled = false;
            }
            if (createraspi)
            {
                raspibox = GameObject.CreatePrimitive(PrimitiveType.Cube);
                raspibox.transform.parent     = slotformgo.transform;
                raspibox.name                 = "raspibox";
                raspibox.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                raspibox.transform.position   = new Vector3(slotlen / 2, 0.62f, 0);
                var rrenderer = raspibox.GetComponent <Renderer>();
                rrenderer.material.color = Color.white;
                var clrdr = raspibox.GetComponent <Collider>();
                clrdr.enabled = false;
            }
            if (createcam)
            {
                // this is wrong
                // see this: https://gamedev.stackexchange.com/questions/57841/creating-multiple-instances-of-a-camera-at-run-time

                //var original = GameObject.FindWithTag("MainCamera");
                //var cam = (Camera)Camera.Instantiate(
                //    original.GetComponent<Camera>(),
                //    raspibox.transform.position,
                //    Quaternion.FromToRotation(Vector3.forward, Vector3.left));
                //cam.name = "raspicam";

                var camgo = new GameObject("raspicam");
                var cam   = camgo.AddComponent <Camera>();
                cam.transform.position = raspibox.transform.position;
                cam.transform.rotation = Quaternion.FromToRotation(Vector3.forward, Vector3.left);
                cam.transform.parent   = raspibox.transform;
                cam.fieldOfView        = 30f;
                cam.nearClipPlane      = 0.1f; // 10 cm
                cam.targetDisplay      = 8;
            }
            if (createnode)
            {
                //var node = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                var clr  = (occupied ? "red" : "cyan");
                var node = GraphAlgos.GraphUtil.CreateMarkerSphere("slotnode", Vector3.zero, size: 0.5f, clr: clr);
                node.transform.parent = slotformgo.transform;
                var rrenderer = node.GetComponent <Renderer>();
                //rrenderer.material.color = (occupied ? Color.red : Color.cyan);
                var clrdr = node.GetComponent <Collider>();
                clrdr.enabled = false;
            }

            if (createcar && occupied)
            {
                //carname = "hummingbird";
                // carname = "Car003";
                //var objPrefab = getcargo(carformname);
                //cargo = Instantiate<GameObject>(objPrefab);
                cargo = VehicleMan.LoadCarGo(slotformgo, carformname);
                neutercargo(cargo);
                //cargo.transform.parent = slotformgo.transform;
                //cargo.transform.position = slotformgo.transform.position + cargo.transform.position;
                //cargo.transform.rotation = slotformgo.transform.rotation;
                //cargo.transform.Rotate(new Vector3(0, 90, 0));
                //cargo.transform.Translate(new Vector3(0, 0, -0.4f));
            }
            calcVeks();
            slotformgo.transform.position = new Vector3(x, 0, z);
            slotformgo.transform.rotation = Quaternion.Euler(0, ang + 90, 0);
        }