AddComponent() public method

public AddComponent ( Type componentType ) : Component
componentType System.Type
return Component
Example #1
0
    private TriggerParent triggerParent; //this is a utility class, that lets us check if the player is close to the coins "bounds sphere trigger"

    #endregion Fields

    #region Methods

    //private GUIManager gui;
    //setup
    void Awake()
    {
        //gui = FindObjectOfType(typeof(GUIManager)) as GUIManager ;
        if(tag != "Pickup")
        {
            tag = "Pickup";

        }
        bubbleBlowing = GameObject.FindGameObjectWithTag("Player").GetComponent<BubbleBlowing>();
        GetComponent<Collider>().isTrigger = true;
        triggerParent = GetComponentInChildren<TriggerParent>();
        //if no trigger bounds are attached to coin, set them up
        if(!triggerParent)
        {
            GameObject bounds = new GameObject();
            bounds.name = "Bounds";
            bounds.AddComponent<SphereCollider>();
            bounds.GetComponent<SphereCollider>().radius = 3f;
            bounds.GetComponent<SphereCollider>().isTrigger = true;
            bounds.transform.parent = transform;
            bounds.transform.position = transform.position;
            bounds.AddComponent<TriggerParent>();
            triggerParent = GetComponentInChildren<TriggerParent>();
            triggerParent.tagsToCheck = new string[1];
            triggerParent.tagsToCheck[0] = "Player";
        }
        for(int i = 0; i < transform.childCount; i++)
        {
            this.transform.GetChild(i).gameObject.layer = LayerMask.NameToLayer("Items");
        }
    }
Example #2
0
        public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale)
        {
            GameObject decal = new GameObject();
            decal.name = "Decal" + decal.GetInstanceID();

            decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale);
            decal.AddComponent<MeshRenderer>().sharedMaterial = mat;

            #if UNITY_5
            decal.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            #else
            decal.GetComponent<MeshRenderer>().castShadows = false;
            #endif

            qd_Decal decalComponent = decal.AddComponent<qd_Decal>();

            decalComponent.SetScale(scale);
            decalComponent.SetTexture( (Texture2D)mat.mainTexture );
            decalComponent.SetUVRect(uvCoords);

            #if DEBUG
            decal.AddComponent<qd_DecalDebug>();
            #endif

            return decal;
        }
    void DrawBarrier()
    {
        for (int i = 0; i < points.Count; i++)
        {
            Vector3 p = points[i];
            p -= new Vector3(0.5f, 0.5f, 0);
            p.x *= (float) Screen.width / Screen.height;
            p *= 15;
            points[i] = p;
        }

        GameObject container = new GameObject();
        container.transform.parent = topSideTran;
        container.AddComponent<Mover>();
        DrawDestruct dd = container.AddComponent<DrawDestruct>();
        dd.cost = points.Count * energyCost;
        dd.drawClass = this;
        dd.bonusScore = 5;
        Destroy(container, selfDestructTime);

        for (int i = 0; i < points.Count - 1; i++)
        {
            GameObject obj = (GameObject) GameObject.Instantiate(linePrefab, points[i], Quaternion.identity);

            obj.transform.position = Vector3.Lerp(points[i], points[i+1], 0.5f);
            obj.tag = "Barrier";
            obj.transform.LookAt(points[i+1]);
            Vector3 s = obj.transform.localScale;
            obj.transform.localScale = new Vector3(s.x, s.y, Vector3.Distance(points[i], points[i+1]));
            obj.transform.parent = container.transform;
        }
    }
Example #4
0
    public static void UseExistingOrCreateNewMainCamera()
    {
        GameObject tempCamera;
        GameObject targetLookAt;
        TP_Camera myCamera;

        if (Camera.mainCamera != null)
        {
            tempCamera = Camera.mainCamera.gameObject;
        }
        else
        {
            tempCamera = new GameObject("Main Camera");
            tempCamera.AddComponent("Camera");
            tempCamera.tag = "MainCamera";
            tempCamera.AddComponent("TP_Camera");
        }
        myCamera = tempCamera.GetComponent("TP_Camera") as TP_Camera;

        targetLookAt = GameObject.Find("targetLookAt") as GameObject;

        if (targetLookAt == null)
        {
            targetLookAt = new GameObject("targetLookAt");
            targetLookAt.transform.position = Vector3.zero;
        }

        myCamera.TargetLookAt = targetLookAt.transform;
    }
Example #5
0
    private CapsuleCollider AddHipCollider(GameObject hipObject) {
        Rigidbody rb = hipObject.AddComponent<Rigidbody>();
        if (rb != null) {
            rb.mass = 1;
            rb.useGravity = false;
            rb.isKinematic = true;
            //rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
        }

        CapsuleCollider collider = hipObject.AddComponent<CapsuleCollider>();
        if (collider != null) {
            collider.isTrigger = true;
            if (proximitySpeed) {
                collider.height = 0.80f;
                collider.radius = 1f;
            } else {
                collider.height = 1.60f;
                collider.radius = 0.20f;
            }
            collider.center = new Vector3(-hipObject.transform.localPosition.x, 0.2f, -hipObject.transform.localPosition.z);
        }


        return collider;
    }
Example #6
0
    void BuildingSphereField()
    {
        for(int y=0; y<fieldHeight; y++)
        {
            for(int z=0; z<fieldDepth; z++)
            {
                shiftX = 0.0f;

                for(int x=0; x<fieldWidth; x++){
                    int randomNumber = Random.Range(1,3);
                    float randomSize = Mathf.Round(Random.Range(0.3f,0.6f) * 100.0f) / 100.0f;
                    shiftX += (randomSize + 0.2f);
                    switch(randomNumber)
                    {
                    case 1: fieldPart = GameObject.CreatePrimitive (PrimitiveType.Sphere);
                            fieldPart.GetComponent<SphereCollider>().material = Resources.Load("darkroom/BouncingBob") as PhysicMaterial;
                            break;
                    case 2: fieldPart = GameObject.CreatePrimitive (PrimitiveType.Cube);
                        fieldPart.GetComponent<BoxCollider>().material = Resources.Load("darkroom/BouncingBob") as PhysicMaterial;
                            break;
                    }

                    fieldPart.transform.localScale = new Vector3 (randomSize, randomSize, randomSize);
                    fieldPart.GetComponent<MeshRenderer>().material = Resources.Load("darkroom/darkroom") as Material;
                    fieldPart.AddComponent<BallBehavior>();
                    Rigidbody rb = fieldPart.AddComponent<Rigidbody> ();
                    rb.useGravity = false;
                    fieldPart.transform.parent = transform;
                    fieldPart.transform.localPosition = new Vector3 (-shiftX, y*-0.7f, z*-0.7f);
                    fieldPart.name = "lightBall";
                    fieldPart.layer = LayerMask.NameToLayer("Ignore Raycast");
                }
            }
        }
    }
Example #7
0
        public void Substract()
        {
            var stopWatch = new Stopwatch();
            stopWatch.Start();

            var csgA = new CSG.CSG();
            csgA.Construct(A.GetComponent<MeshFilter>().sharedMesh, A.transform, 0);

            var csgB = new CSG.CSG();
            csgB.Construct(B.GetComponent<MeshFilter>().sharedMesh, B.transform, 1);

            var substract = csgA.Substract(csgB);
            var newMesh = substract.ToMesh();

            Result = new GameObject("Substract");
            var defObj = Result.AddComponent<DefaultObject>();
            var meshFilter = Result.AddComponent<MeshFilter>();
            meshFilter.sharedMesh = newMesh;
            var renderer = Result.AddComponent<MeshRenderer>();
            renderer.sharedMaterials = new Material[] { A.GetComponent<MeshRenderer>().sharedMaterial, B.GetComponent<MeshRenderer>().sharedMaterial };

            if (DeleteOriginal)
            {
                Object.DestroyImmediate(A);
                Object.DestroyImmediate(B);
            }

            stopWatch.Stop();
            defObj.GenerationTimeMS = stopWatch.ElapsedMilliseconds;
        }
Example #8
0
    void Awake()
    {
        // create empty(transform only) game object in scene with default position (0,0,0)
        GameObject myObj = new GameObject();
        myObj.transform.position = new Vector3(0, 3, 0);
        // add sprite renderer component
        myObj.AddComponent<SpriteRenderer>();

        // create texture from resource file
        myTexture = Resources.Load<Texture2D>("ProceduralSprite/100_px") as Texture2D;

        // A) store sprite > store component > assign spite to component property
        mySprite = Sprite.Create(myTexture, new Rect(25,25,75,75), new Vector2(0f, 0f));
        SpriteRenderer myObjComponent = myObj.GetComponent<SpriteRenderer>();
        myObjComponent.sprite = mySprite;

        // B) direct assign
        // myObj.GetComponent<SpriteRenderer>().sprite = Sprite.Create(myTexture, new Rect(0, 0, myTexture.width, myTexture.height), new Vector2(0.5f, 0f));

        // 1)----
        // load previously created animator controller as runtimeAnimationConroller
        myRTimeAnimator = Resources.Load<RuntimeAnimatorController>("ProceduralSprite/Cube") as RuntimeAnimatorController;
        // add animator component to GO and assign animator controller
        myObj.AddComponent<Animator>();
        myObj.GetComponent<Animator>().runtimeAnimatorController = myRTimeAnimator;

        // 2)----
        // alternative way (direct assing)
        // myObj.AddComponent<Animator>();
        // myObj.GetComponent<Animator>().runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("ProceduralSprite/Cube") as RuntimeAnimatorController;

    }
		public void CreatePrefab()
		{
			if (prefabAtmosphere == null)
			{
				prefabAtmosphere = new GameObject ("RefractiveAtmosphere");
				prefabAtmosphere.SetActive (false);
				var mf = prefabAtmosphere.AddComponent<MeshFilter> ();
				var mr = prefabAtmosphere.AddComponent<MeshRenderer> ();
				mr.castShadows = false;
				mr.receiveShadows = false;

				var material = new Material (Shaders.RefractiveAtmosphere);
				var _normals = new Texture2D (4, 4, TextureFormat.ARGB32, false);
				_normals.LoadImage (Textures.RefractiveAtmosphereNormals);
				material.SetTexture ("_BumpMap", _normals);
				material.SetTextureScale ("_BumpMap", new Vector2 (4f, 4f));
				material.SetVector ("_BumpMapOffset", new Vector4 (0, 0, 1, 0));

				mr.sharedMaterial = material;

				var sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere);
				var sphereMesh = sphere.GetComponent<MeshFilter> ().mesh;
				DestroyImmediate (sphere);
				mf.sharedMesh = sphereMesh;

				var behaviour = prefabAtmosphere.AddComponent<RefractiveAtmosphere> ();

				prefabAtmosphere.transform.localScale = Vector3.one * 1250f;

				DontDestroyOnLoad (prefabAtmosphere);
			}
		}
Example #10
0
    public GUITextObj GetGUIText(int LayerNum)
    {
        int Count = 0;
        GUITextObj TmpTextObj;
        GameObject tmpGameObj;

        //Search guitext buffer for available object
        for (Count=0;Count<pTextBuffer.Count;Count++)
        {
            TmpTextObj = (GUITextObj) pTextBuffer[Count];
            if (TmpTextObj.GUIActive == false)
            {
                //Flag the object as used
                TmpTextObj.GUIActive = true;
                //Set the objects layer
                TmpTextObj.GameObj.layer = LayerNum;
                //Return object
                return TmpTextObj;
            }
        }

        //No available object, so allocate more
        int BuffIdx = 0;
        int BuffSize = pTextBuffer.Count;
        for (Count=0;Count<AllocBlockSize;Count++)
        {
            //Create new guitext object
            tmpGameObj = new GameObject();
            BuffIdx = BuffSize + Count;
            tmpGameObj.name = "GUIText" + BuffIdx.ToString();
            tmpGameObj.AddComponent("GUIText");
            tmpGameObj.AddComponent("Animator");
            tmpGameObj.AddComponent("GUITextObj");

            //Set a child of guitextmgr
            tmpGameObj.transform.parent = gameObject.transform;

            //Add to buffer
            TmpTextObj = (GUITextObj) tmpGameObj.GetComponent(typeof(GUITextObj));
            TmpTextObj.GUIActive = false;
            pTextBuffer.Add(TmpTextObj);
        }

        //Search guitext buffer for available object
        for (Count=0;Count<pTextBuffer.Count;Count++)
        {
            TmpTextObj = (GUITextObj) pTextBuffer[Count];
            if (TmpTextObj.GUIActive == false)
            {
                //Flag the object as used
                TmpTextObj.GUIActive = true;
                //Set the objects layer
                TmpTextObj.GameObj.layer = LayerNum;
                //Return object
                return TmpTextObj;
            }
        }

        return null;
    }
Example #11
0
    public IStack initialise(Vector3 centroid, Vector3 stackTwist, float scale, Color stackColour)
    {
        stack = new GameObject("Torus");
        torus = stack.AddComponent<TorusPrimitive>();

        torus.OuterRadius = scale;
        torus.InnerRadius = 0.2f * scale;
        //torus.Sides = 32;
        //torus.Segments = 32;

        torus.UpdatePrimitive ();

        stackRigidBody = stack.AddComponent<Rigidbody>();
        stackRigidBody.useGravity = false;
        stackRigidBody.detectCollisions = false;

        stack.transform.position = centroid;

        currentRotationX = stackTwist.x;
        currentRotationY = stackTwist.y;
        currentRotationZ = stackTwist.z;
        stack.transform.Rotate (stackTwist);

        stack.transform.localScale = new Vector3(scale, scale, scale);

        stack.GetComponent<Renderer>().material.color = stackColour;
        return this;
    }
    void AddNewMoving(GameObject obj)
    {
        Destroy (obj.GetComponent<Moving> ());

        obj.AddComponent<RotateObject> ();
        obj.AddComponent<JumpSlerpObject> ();
    }
Example #13
0
    void CreateCanvas()
    {
        if( !_didCreateUiStuff )
        {
            _didCreateUiStuff = true;

            //Create the UI canvas game object
            canvasRoot = new GameObject( "Canvas" );
            var canvas = canvasRoot.AddComponent<Canvas>();
            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            var cs = canvasRoot.AddComponent<CanvasScaler>();
            cs.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            cs.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
            cs.referenceResolution = new Vector2(800,600);

            //create our ui prefab
            uiPrefab = new GameObject( "UItext" );
            uiPrefab.transform.position = new Vector3( 1000, 10000 );
            var txt = uiPrefab.AddComponent<Text>();
            txt.font = Resources.GetBuiltinResource( typeof( Font ), "Arial.ttf" ) as Font;
            txt.text = "Some text";
            txt.horizontalOverflow = HorizontalWrapMode.Overflow;
            txt.color = Color.white;
            txt.resizeTextForBestFit = true;

            // Make a recycle bin for it
            var recycleBin = new TrashManRecycleBin()
            {
                prefab = uiPrefab
            };
            TrashMan.manageRecycleBin( recycleBin );
        }
    }
Example #14
0
    void create()
    {
        //creation de la fenetre
        GameObject newCanvas = new GameObject("Canvas");
        Canvas ca = newCanvas.AddComponent<Canvas>();
        ca.renderMode = RenderMode.ScreenSpaceOverlay;
        //ajout de ces composents
        newCanvas.AddComponent<CanvasScaler>();
        newCanvas.AddComponent<GraphicRaycaster>();
        //ajout du panel
        GameObject panel = new GameObject("Panel");
        panel.AddComponent<CanvasRenderer>();
        Image i = panel.AddComponent<Image>();
        i.color = new Color(0, 0, 0, 0.4f);
        //le panel appartient a la fenetre
        panel.transform.SetParent(newCanvas.transform, false);

        // position et taille de la barre de spell
        panel.transform.position = new Vector3((Screen.width / 2), 1, 0);
        panel.GetComponent<RectTransform>().sizeDelta = new Vector2(Screen.width - (Screen.width / 7), Screen.height / 5);

        //ajout des cases de spell pour chaque capacité du joueur
        for (int ic = 0; ic < transform.GetComponents<capacity>().Length; ic++)
        {
            GameObject text = new GameObject(transform.GetComponents<capacity>()[ic].name);
            text.AddComponent<Text>().name = transform.GetComponents<capacity>()[ic].name;
            text.GetComponent<Text>().text = transform.GetComponents<capacity>()[ic].K.ToString();
            text.GetComponent<Text>().font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
            text.transform.SetParent(newCanvas.transform, false);
            text.transform.position = new Vector3(((Screen.width - (Screen.width / 7)) / transform.GetComponents<capacity>().Length) * ic + (Screen.width / 7), 1, 0);
            LC.Add(transform.GetComponents<capacity>()[ic]);
            transform.GetComponents<capacity>()[ic].T = text.GetComponent<Text>();
        }
    }
Example #15
0
    public static void createInstance()
    {
        GameObject tmpObj = GameObject.Find("PersistentObj");
        if(tmpObj != null)
        {
            instance = tmpObj;
        }
        else
        {
            // Basic object shell.
            instance = new GameObject("PersistentObj");
            instance.transform.position = new Vector3(0,0,0);

            // Persistent object components.
            // (Other components may be attached from within other scripts once you obtain an instance via getInstance())
            //instance.AddComponent<ServerComRequester>();
            instance.AddComponent<SoundPlayerScript>();
            DatastoreScript ds = instance.AddComponent<DatastoreScript>();

            // Store versioning info in memory. (Primarily needed by the saving system to detect old or new save data).
            int dayValue = 6;//23;
            int monthValue = 1;//10;
            int yearValue = 2015;//2014;
            int versionForDay = 0;

            ds.insertData("GameVersionData",new SaveVersioningInfo(dayValue,monthValue,yearValue,versionForDay,""));

            // Make sure that the object is not destroyed when new scenes are loaded.
            UnityEngine.MonoBehaviour.DontDestroyOnLoad(instance);
        }
    }
Example #16
0
    private void SpawnPlayer()
    {
        GameObject groundMesh = GameObject.Find("groundMesh");
        if(groundMesh == null || player != null){
            return;
        }

        float x = 175.0f; //groundMesh.renderer.bounds.max.x+(groundMesh.renderer.bounds.min.x*0.5f);
        float y = groundMesh.renderer.bounds.max.y+(groundMesh.renderer.bounds.min.y*0.5f);
        float z = 175.0f; //groundMesh.renderer.bounds.max.z+(groundMesh.renderer.bounds.min.z);

         player = GameObject.CreatePrimitive(PrimitiveType.Capsule);

        player.transform.localScale = new Vector3(3.469746f,4.222249f,3.469746f);
        float height = player.renderer.bounds.max.y-player.renderer.bounds.min.y;
        Vector3 center = new Vector3(x,y+height,z);
        player.transform.position = center;
        player.AddComponent<Rigidbody>();
        Rigidbody rb = player.GetComponent<Rigidbody>();
        rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ |  RigidbodyConstraints.FreezePositionX |  RigidbodyConstraints.FreezePositionZ ;
        //transform.parent = player.transform;

        player.AddComponent<CameraTraveler>();
        player.GetComponent<CameraTraveler>().player = player;
    }
Example #17
0
    void Awake()
    {
        var sky = GetComponent<Skybox>();
        Material skymat = sky != null ? sky.material : RenderSettings.skybox;
        if (skymat == null) {
          enabled = false;
          return;
        }

        skybox = new GameObject(skymat.name + "SkyMesh");
        skybox.transform.parent = transform;
        skybox.transform.localPosition = Vector3.zero;
        skybox.layer = layer;

        var filter = skybox.AddComponent<MeshFilter>();
        filter.mesh = _CreateSkyboxMesh();

        Material mat = new Material(Shader.Find("Cardboard/SkyboxMesh"));
        var render = skybox.AddComponent<MeshRenderer>();
        render.sharedMaterials = new Material[] {
        new Material(mat) { mainTexture = skymat.GetTexture("_FrontTex") },
        new Material(mat) { mainTexture = skymat.GetTexture("_LeftTex")  },
        new Material(mat) { mainTexture = skymat.GetTexture("_BackTex")  },
        new Material(mat) { mainTexture = skymat.GetTexture("_RightTex") },
        new Material(mat) { mainTexture = skymat.GetTexture("_UpTex")    },
        new Material(mat) { mainTexture = skymat.GetTexture("_DownTex")  }
        };
        render.castShadows = false;
        render.receiveShadows = false;
    }
Example #18
0
 void Start()
 {
     lCamera = new GameObject( "lCamera" );
     lCamera.AddComponent<Camera>();
     lCamera.AddComponent<GUILayer>();
     lCamera.AddComponent("FlareLayer");
     lCamera.camera.CopyFrom(Camera.main);
     rCamera = (GameObject) Instantiate(lCamera, transform.position, transform.rotation);
     rCamera.name = "rCamera";
     lCamera.transform.parent = Camera.main.transform;
     rCamera.transform.parent = Camera.main.transform;
     parallax = new GameObject( "parallax" );
     parallax.transform.parent = Camera.main.transform;
     parallax.transform.localPosition = Vector3.zero;
     Vector3 parallaxPosition = parallax.transform.localPosition;
     parallaxPosition.z = parallaxDistance;
     parallax.transform.localPosition = parallaxPosition;
     camera.enabled = false;
     lCamera.camera.rect = new Rect(0, 0, 0.5f, 1);
     rCamera.camera.rect = new Rect(0.5f, 0, 0.5f, 1);
     lCamera.transform.localPosition = Vector3.zero;
     rCamera.transform.localPosition = Vector3.zero;
     Vector3 cameraPosition = lCamera.transform.localPosition;
     cameraPosition.x = -eyeDistance;
     lCamera.transform.localPosition = cameraPosition;
     cameraPosition.x = eyeDistance;
     rCamera.transform.localPosition = cameraPosition;
 }
Example #19
0
 void OnEnable()
 {
     GameObject go = new GameObject ("One Shot Audio");
     go.AddComponent<TimedDestruction> ().seconds = clip.length;
     go.AddComponent<AudioSource> ().clip = clip;
     go.GetComponent<AudioSource> ().Play ();
 }
Example #20
0
    public static GameObject CreatePlane(Vector2 size)
    {
        size *= 0.5f;
        Mesh planeMesh = new Mesh();
        planeMesh.name = "CustomPlane";

        //set vertices
        Vector3[] vertices = {
            new Vector3(-size.x, -size.y, 0f),
            new Vector3(size.x, -size.y, 0f),
            new Vector3(size.x, size.y, 0f),
            new Vector3(-size.x, size.y, 0f)};
        planeMesh.vertices = vertices;
        //set uvs
        Vector2[] uvs = {Vector2.zero, Vector2.up, Vector2.one, Vector2.right};
        planeMesh.uv = uvs;
        //set triangles
        int[] triangles = {0, 1, 2, 0, 2, 3};
        planeMesh.triangles = triangles;
        planeMesh.RecalculateNormals();

        //Create gameobject
        GameObject plane = new GameObject("CustomPlane");
        MeshFilter _meshFilter = plane.AddComponent<MeshFilter>();
        _meshFilter.mesh = planeMesh;
        plane.AddComponent<MeshRenderer>();
        plane.AddComponent<MeshCollider>();
        plane.transform.position = Vector3.zero;

        return plane;
    }
Example #21
0
    // Use this for initialization
    void Start()
    {
        //general setup
        menu = GetComponentInParent<Menu>();
        options = new List<MenuViewOptionBasic>();
        GetComponentsInChildren<MenuViewOptionBasic>(options);
        toDraw = true;
        if(options == null) options = new List<MenuViewOptionBasic>();
        //Setup view
        viewObject = new GameObject("MenuViewBasic");
        viewObject.transform.SetParent(transform);
        canvas = viewObject.AddComponent<Canvas>();
        canvas.renderMode = RenderMode.ScreenSpaceCamera;
        canvas.worldCamera = drawCamera;
        canvas.planeDistance = 1f;
        viewObject.AddComponent<CanvasScaler>();
        viewObject.AddComponent<GraphicRaycaster>();
        //Setup textbox
        textbox = new GameObject("TextBox");
        textPosition = textbox.AddComponent<RectTransform>();
        textPosition.SetParent(viewObject.transform);
        textPosition.localPosition = new Vector3(position.x,position.y, 0);
        textbox.AddComponent<CanvasRenderer>();

        text = textbox.AddComponent<Text>();
        text.font = textFont;
        text.alignment = TextAnchor.MiddleCenter;
        text.color = new Color(color.r, color.g, color.b);
        if(options.Count > 0) text.text = options[menu.CurOption].optionText;
    }
	static void AddHeatMap ()
	{
		GameObject go = new GameObject("GA_HeatMap");
		go.AddComponent<GA_HeatMapRenderer>();
		go.AddComponent<GA_HeatMapDataFilter>();
		Selection.activeObject = go;
	}
    // Update is called once per frame
    void Update()
    {
        if (leftController == -1) {
            leftController = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
            if (leftController != -1 && leftController != 0)
            {
                Debug.Log("Left controller is: " + leftController);

                leftControllerObject = GameObject.Find("Device" + leftController.ToString());
                leftControllerObject.AddComponent<BoxCollider>();
                leftControllerObject.AddComponent<controllerIndexKeeper>().controllerIndex = leftController;
                leftControllerObject.tag = "controller";
            }

        }
        if (rightController == -1)
        {
            rightController = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);

            if (rightController != -1 && rightController != 0)
            {
                Debug.Log("Right controller is: " + rightController);

                rightControllerObject = GameObject.Find("Device" + rightController.ToString());
                rightControllerObject.AddComponent<BoxCollider>();
                rightControllerObject.AddComponent<controllerIndexKeeper>().controllerIndex = rightController;
                rightControllerObject.tag = "controller";
            }

        }
    }
        public EditorModel(GameObject assetPrefab)
        {
            prefab = assetPrefab;

            saveAssetFolder = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(prefab));

            assetInstance = GameObject.Instantiate(assetPrefab) as GameObject;
            assetInstance.name = assetPrefab.name;
            assetInstance.SetActive(true);

            // Check for LocalSettings on the prefab and use that if possible
            LocalSettings = assetInstance.GetComponentInChildren<LocalSettings>();
            if (LocalSettings != null) {
            UseLocalSettings = true;
            BlobModel = assetInstance.AddComponent<ABlobModel>().InitWithExistingBlob(LocalSettings.gameObject);
            } else {
            Mesh blobMesh = AssetDatabase.LoadAssetAtPath("Assets/BlobOMatic/BlobMesh.asset", typeof(Mesh)) as Mesh;
            BlobModel = assetInstance.AddComponent<ABlobModel>().Init(blobMesh);
            if (!ICanHasShadow) return; // Not a valid model, bugger off!

            LocalSettings = BlobModel.BlobRenderer.gameObject.AddComponent<LocalSettings>().CopyGlobalSettings();

            saveAssetFolder +=  "/" + prefab.name + "WithBlob";
            }

            // Collect original layers and set everything to blob layer
            foreach (Transform t in assetInstance.GetComponentsInChildren<Transform>(true))
            originalLayers[t.gameObject] = t.gameObject.layer;
            assetInstance.SetLayerRecursively(BlobOMatic.EditorLayer);

            assetInstance.SetActive(false);
            assetInstance.SetHideFlagsRecursively(HideFlags.HideAndDontSave);

            RenderBlob();
        }
	GameObject CreateChild (int x, int z)
	{
		GameObject lvObject = new GameObject ();
		
		lvObject.name = "Grid Cell";
		lvObject.transform.parent = transform;
		lvObject.transform.localPosition = new Vector3 ((float)x, 0.0f, (float)z);

		lvObject.AddComponent<MeshRenderer> ();

		lvObject.GetComponent<MeshRenderer> ().material = cellMaterialValid;

		CellStatus cellStatus = lvObject.AddComponent<CellStatus> ();
		cellStatus.avaiable = true;
		cellStatus.CellId = GetGridId (x, z);
	
		Mesh lvMesh = CreateMesh ();
		lvMesh.vertices = new Vector3[] {
			MeshVertex (0, 0),
			MeshVertex (0, 1),
			MeshVertex (1, 0),
			MeshVertex (1, 1),
		};

		lvObject.AddComponent<MeshFilter> ().mesh = lvMesh;
		lvObject.tag = "GridCell";
		lvObject.AddComponent<MeshCollider> ();
		
		return lvObject;
	}
Example #26
0
        public static void CreateNewUI()
        {
            GameObject mainCamera = GameObject.Find("Main Camera");
            if (mainCamera != null)
                GameObject.DestroyImmediate(mainCamera);

            GameObject uiObj = new GameObject("UI");
            uiObj.layer = (int)UnityLayerDef.UI;
            var canvas = uiObj.AddComponent<Canvas>();
            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            uiObj.AddComponent<CanvasScaler>();
            uiObj.AddComponent<GraphicRaycaster>();

            var evtSystemObj = new GameObject("EventSystem");
            evtSystemObj.AddComponent<EventSystem>();
            evtSystemObj.AddComponent<StandaloneInputModule>();
            evtSystemObj.AddComponent<TouchInputModule>();

            GameObject cameraObj = new GameObject("Camera");
            cameraObj.layer = (int)UnityLayerDef.UI;

            Camera camera = cameraObj.AddComponent<Camera>();
            camera.clearFlags = CameraClearFlags.Skybox;
            camera.depth = 0;
            camera.backgroundColor = Color.grey;
            camera.cullingMask = 1 << (int)UnityLayerDef.UI;
            camera.orthographicSize = 1f;
            camera.orthographic = true;
            camera.nearClipPlane = -2f;
            camera.farClipPlane = 2f;

            camera.gameObject.AddComponent<AudioListener>();

            Selection.activeGameObject = uiObj;
        }
 public static void CreateSpriteGameObject()
 {
     GameObject n = new GameObject ();
     n.AddComponent<SpriteRenderer> ();
     n.AddComponent<SpriteAnimation> ();
     n.name = "New Animated Sprite";
 }
Example #28
0
		public static Far Create (VoxelTerrain land)
		{
			GameObject obj = new GameObject("Far");
			obj.transform.parent = land.transform;
			obj.transform.localPosition = Vector3.zero;
			
			Far far = obj.AddComponent<Far>();
			far.land = land;
			
			obj.AddComponent<MeshRenderer>();
			far.filter = obj.AddComponent<MeshFilter>();
			//far.filter.sharedMesh = new Mesh();
			
			far.GetComponent<Renderer>().sharedMaterial = land.terrainMaterial;
//			if (land.hideChunks) far.transform.hideFlags = HideFlags.HideInHierarchy;

			//hiding wireframe
			#if UNITY_EDITOR
			UnityEditor.EditorUtility.SetSelectedWireframeHidden(obj.GetComponent<Renderer>(), land.hideWire);
			
			//copy static flag
			UnityEditor.StaticEditorFlags flags = UnityEditor.GameObjectUtility.GetStaticEditorFlags(land.gameObject);
			UnityEditor.GameObjectUtility.SetStaticEditorFlags(obj, flags);
			#endif

			return far;
		}
    void AddClusterScripts(GameObject iObject, bool iChildren)
    {
        //MiddleVRTools.Log("AddCluster to " + iObject);
        //print("AddCluster to " + iObject);
        {
            if (iObject.GetComponent<VRShareTransform>() == null)
            {
                VRShareTransform script = iObject.AddComponent<VRShareTransform>() as VRShareTransform;
                script.Start();
            }

            if (iObject.GetComponent<VRApplySharedTransform>() == null)
            {
                VRApplySharedTransform script = iObject.AddComponent<VRApplySharedTransform>() as VRApplySharedTransform;
                script.Start();
            }
        }

        if( iChildren == true )
        {
            foreach (Transform child in iObject.transform)
            {
                GameObject childObject = child.gameObject;

                //print("Child : " + childObject);
                AddClusterScripts(childObject, true);
            }
        }
    }
Example #30
0
        /// <summary>
        /// Creates a blocker that covers the entire screen.
        /// </summary>
        /// <param name="onClosed">The callback which is called whenever the blocker is clicked and closed</param>
        /// <param name="sortingOrder">The SortingOrder for the blocker canvas, this value should be higher then any canvas that shouldn't receive input and lower then any canvas that should receive input</param>
        /// <param name="sortingLayerID">The layerID for the blocker canvas</param>
        public static void CreateBlocker(UnityAction onClosed, int sortingOrder, int sortingLayerID)
        {
            GameObject go = new GameObject("BlockerCanvas");
            Canvas canvas = go.AddComponent<Canvas>();
            go.AddComponent<GraphicRaycaster>();

            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            canvas.sortingLayerID = sortingLayerID;
            canvas.sortingOrder = sortingOrder;

            GameObject blocker = new GameObject("Blocker");

            RectTransform transform = blocker.AddComponent<RectTransform>();
            transform.SetParent(go.transform, false);
            transform.anchorMin = Vector3.zero;
            transform.anchorMax = Vector3.one;
            transform.offsetMin = transform.offsetMax = Vector2.zero;

            Image image = blocker.AddComponent<Image>();
            image.color = Color.clear;

            Button button = blocker.AddComponent<Button>();
            button.onClick.AddListener(() =>
            {
                UnityEngine.Object.Destroy(go);
                onClosed();
            });
        }