Пример #1
0
    void AddVisualElement()
    {
        var element = Instantiate(FFResource.Load_Prefab("RopeVisualElement")).transform;

        element.SetParent(transform);
        visualElements.Add(element);
    }
Пример #2
0
    // Net Object comming in from another client
    private static void OnNetObjectCreatedEvent(NetObjectCreatedEvent e)
    {
        GameObject go = null;

        if (e.prefabName != null)
        {
            singleton._GameObjecttRegistryIsLocked = true;
            go = GameObject.Instantiate(FFResource.Load_Prefab(e.prefabName));
            singleton._GameObjecttRegistryIsLocked = false;

            if (go == null)
            {
                Debug.Log("Error in FFMessageSystem.OnNewObjectCreatedEvent, failed to Instantiate prefabName as gameobject");
                return;
            }
            int id = go.GetInstanceID();

            var trans = go.transform;
            trans.position   = e.pos;
            trans.rotation   = e.rot;
            trans.localScale = e.scale;

            //Debug.LogError("New Net Object Created");//debug
            GameObjectData ffgoData = new GameObjectData(go, e.clientOwnerNetId, e.gameObjectNetId, id);
            singleton._localIdToGameObjectData.Add(id, ffgoData);
            singleton._netIdToGameObjectData.Add(e.gameObjectNetId, ffgoData);
        }
    }
Пример #3
0
    void OnGUI()
    {
        GUILayout.Label("Ground Creator", EditorStyles.boldLabel);

        int tempSeed = EditorGUILayout.IntField("Seed", seed);

        if (seed != tempSeed)
        {
            SetSeed(tempSeed);
        }

        dimensions  = EditorGUILayout.IntSlider("Dimensions", dimensions, 16, 256);
        noiseScale  = EditorGUILayout.Slider("Noise Scale", noiseScale, 0.01f, 0.75f);
        heightDelta = EditorGUILayout.Slider("Height Delta", heightDelta, 0.5f, 50.0f);

        string groundPrefabNameTemp = EditorGUILayout.TextField("groundPrefabPath (Resources//...)", groundPrefabName);

        if (groundPrefabNameTemp != groundPrefabName ||
            groundPrefab == null)
        {
            groundPrefabName = groundPrefabNameTemp;
            groundPrefab     = FFResource.Load_Prefab(groundPrefabNameTemp);
        }

        string planePrefabNameTemp = EditorGUILayout.TextField("planePrefabPath (Resources//...)", planePrefabName);

        if (planePrefabNameTemp != planePrefabName ||
            planePrefab == null)
        {
            planePrefabName = planePrefabNameTemp;
            planePrefab     = FFResource.Load_Prefab(planePrefabNameTemp);
        }

        bool createGround = false;

        createGround = EditorGUILayout.Toggle("CreateGroundButton", createGround);

        if (createGround)
        {
            Create();
        }
    }
Пример #4
0
    void PlaceWallAtMouse()
    {
        // Raycast, delete walls if its there
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            Destroy(hit.collider.gameObject);
        }

        var wallPos = new Vector3(
            ray.origin.x,
            0,
            ray.origin.z);


        var wallPrefab = FFResource.Load_Prefab("Wall");
        var wallObj    = Instantiate(wallPrefab);

        wallObj.transform.position = wallPos;
    }
Пример #5
0
 void CreatePlayer()
 {
     // TODO add start position to Player Spawn
     GameObject.Instantiate(FFResource.Load_Prefab("Player"));
 }
Пример #6
0
    private void OnSceneGUI(SceneView sceneView)
    {
        DrawGrid();

        Event cur = Event.current;

        //Debug.Log("OnSceneGUI: button" + cur.button);

        Vector3 mousePos = (Vector3)cur.mousePosition;

        mousePos.y = sceneView.camera.pixelHeight - mousePos.y;
        Vector3 worldPos = sceneView.camera.ScreenToWorldPoint(mousePos);

        int buttonPressed = cur.button;

        // left Mouse, Place Wall
        var isMouse =
            cur.type == EventType.MouseDown ||
            cur.type == EventType.MouseDrag ||
            cur.type == EventType.DragUpdated ||
            cur.type == EventType.DragExited ||
            cur.type == EventType.DragPerform;



        if (isMouse && buttonPressed == 0 && state == State.Draw)
        {
            //Debug.Log(sceneView.camera.transform.position);
            // Raycast, delete walls if its there
            Ray        ray = sceneView.camera.ScreenPointToRay(mousePos);
            RaycastHit hit;

            Vector3 wallPos      = Vector3.zero;
            bool    hitSomething = false;
            if (Physics.Raycast(ray, out hit))
            {
                hitSomething = true;
                if (hit.collider.name.Contains("Wall"))
                {
                    Debug.Log("Hit Wall");
                    wallPos = hit.collider.transform.position;
                    Undo.DestroyObjectImmediate(hit.collider.gameObject);
                }
                else
                {
                    wallPos = new Vector3(
                        Mathf.Floor(hit.point.x + 0.5f),
                        0,
                        Mathf.Floor(hit.point.z + 0.5f));
                }
            }

            var floorRoot = GameObject.Find("WallsRoot");
            {// Get or Add FloorRoot
                if (floorRoot == null)
                {
                    floorRoot = new GameObject("WallsRoot");
                }
            }

            if (hitSomething)
            {
                var wallPrefab = FFResource.Load_Prefab("Wall");
                var wallObj    = Instantiate(wallPrefab);
                wallObj.transform.position = wallPos;
                wallObj.transform.SetParent(floorRoot.transform);
                Undo.RegisterCreatedObjectUndo(wallObj, wallObj.transform.name);
            }
        }

        // right Mouse
        else if (isMouse && buttonPressed == 0 && state == State.Erase)
        {
            Ray        ray = sceneView.camera.ScreenPointToRay(mousePos);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.name.Contains("Wall"))
                {
                    Undo.DestroyObjectImmediate(hit.collider.gameObject);
                }
            }
        }

        //mousePos.y = Camera.current.pixelHeight - mousePos.y;
        //Vector3 worldPos = sceneView.camera.ScreenToWorldPoint(mousePos);
        //
        //UpdateMouse(mousePos);
        //
        //EditorMousePos editorMoseuPos = GameObject.FindGameObjectWithTag("EditorMousePos").GetComponent<EditorMousePos>();
        //editorMoseuPos.editorMousePos = mousePos;
        //editorMoseuPos.editorMouseWorldPos = worldPos;
    }