Exemplo n.º 1
0
    //private int hueSwitch = 1;

    // Use this for initialization
    void Start()
    {
        m_JellyMesh = GetComponent <JellyMesh>();
        re          = GetComponent <Renderer>();
        colNext     = Color.grey;
        colPrev     = Color.grey;
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        _petMovement = GetComponent <PetMovement>();
        _jellyMesh   = GetComponent <JellyMesh>();
        _renderer    = GetComponent <MeshRenderer>();
        _animator    = GetComponent <Animator>();
        _foodSpawner = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>();
        _interactor  = GetComponent <PetInteractor>();
        _sounds      = GetComponent <PetSounds>();
        _stats       = GetComponent <PetStats>();

        string debugActionList = "";

        // Use reflection to find every type that inherits from BasePetAction, instansiate it, and stick it in _actions
        foreach (var type in System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(BasePetAction)))
        {
            var action = (BasePetAction)Activator.CreateInstance(type);
            action.Init(gameObject);
            _actions.Add(action);
            debugActionList += type.ToString() + " ";
        }

        Debug.Log("Loaded " + _actions.Count + " pet actions: " + debugActionList);

        StartCoroutine(Tick());
    }
Exemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        _petMovement   = GetComponent <PetMovement>();
        _jellyMesh     = GetComponent <JellyMesh>();
        _renderer      = GetComponent <MeshRenderer>();
        _animator      = GetComponent <Animator>();
        _foodSpawner   = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>();
        _stockpileArea = GameObject.Find("StockpileArea").GetComponent <StockpileArea>();
        _interactor    = GetComponent <PetInteractor>();
        _sounds        = GetComponent <PetSounds>();

        StartCoroutine(Tick());
    }
    /// <summary>
    /// Start this instance.
    /// </summary>
    void Start()
    {
        m_JellyMesh = GetComponent<JellyMesh>();
        m_BounceTimer = UnityEngine.Random.Range(m_MinBounceTime, m_MaxBounceTime);
        m_EyeLeft = transform.FindChild("Eye Left");
        m_EyeRight = transform.FindChild("Eye Right");

        if(m_EyeLeft)
        {
            m_EyeInitialRotation = m_EyeLeft.localRotation;
        }

        m_StartEyeRotation = m_EyeInitialRotation * Quaternion.Euler(Vector3.zero);
        m_EndEyeRotation = m_EyeInitialRotation * Quaternion.Euler(Vector3.zero);
    }
Exemplo n.º 5
0
    /// <summary>
    /// Start this instance.
    /// </summary>
    void Start()
    {
        m_JellyMesh   = GetComponent <JellyMesh>();
        m_BounceTimer = UnityEngine.Random.Range(m_MinBounceTime, m_MaxBounceTime);
        m_EyeLeft     = transform.FindChild("Eye Left");
        m_EyeRight    = transform.FindChild("Eye Right");

        if (m_EyeLeft)
        {
            m_EyeInitialRotation = m_EyeLeft.localRotation;
        }

        m_StartEyeRotation = m_EyeInitialRotation * Quaternion.Euler(Vector3.zero);
        m_EndEyeRotation   = m_EyeInitialRotation * Quaternion.Euler(Vector3.zero);
    }
Exemplo n.º 6
0
    protected void UpdateHandles()
    {
        if (!Application.isPlaying)
        {
            JellyMesh jellyMesh = (JellyMesh)target;

            if (jellyMesh.m_Style == JellyMesh.PhysicsStyle.Free)
            {
                if (jellyMesh.m_FreeModeBodyPositions != null)
                {
                    Transform transform = jellyMesh.transform;

                    for (int i = 0; i < jellyMesh.m_FreeModeBodyPositions.Count; i++)
                    {
                        Handles.color = jellyMesh.m_FreeModeBodyKinematic[i]? Color.red : Color.green;

                        Vector3 point       = transform.TransformPoint(jellyMesh.m_FreeModeBodyPositions[i]);
                        Vector3 newPosition = transform.InverseTransformPoint(Handles.FreeMoveHandle(point, Quaternion.identity, HandleUtility.GetHandleSize(point) * 0.05f, Vector3.zero, Handles.DotCap));

                        if (jellyMesh.m_FreeModeBodyPositions[i] != newPosition)
                        {
                            Undo.RecordObject(target, "Adjusted Jelly Mesh Body Position");
                            jellyMesh.m_FreeModeBodyPositions[i] = newPosition;
                        }

                        if (i > 0)
                        {
                            float newRadius = Handles.RadiusHandle(Quaternion.identity, point, jellyMesh.m_FreeModeBodyRadii[i]);

                            if (jellyMesh.m_FreeModeBodyRadii[i] != newRadius)
                            {
                                Undo.RecordObject(target, "Adjusted Jelly Mesh Body Radius");
                                jellyMesh.m_FreeModeBodyRadii[i] = newRadius;
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 7
0
        public JellySimulation(SceneManager sceneManager, ShaderProvider shaderProvider)
        {
            _sceneManager   = sceneManager;
            _shaderProvider = shaderProvider;

            ControlFrame         = new Node(new Transform(Vector3.Zero, Quaternion.Identity /* Quaternion.FromEulerAngles(1.0f, 1.0f, 0.0f)*/, Vector3.One), "controlFrame");
            ControlFrameRenderer = new LineRenderer(shaderProvider.DefaultShader);
            var jellyControlFrame = new JellyControlFrame(ControlFrameRenderer, 1.0);

            ControlFrame.AttachComponents(ControlFrameRenderer, jellyControlFrame);

            Jelly = new Node(new Transform(Vector3.Zero, Quaternion.Identity, Vector3.One), "jelly");

            var boundingBoxRenderer = new LineRenderer(shaderProvider.DefaultShader);
            var jellyBoundingBox    = new JellyBoundingBox(boundingBoxRenderer, 5.0);

            var jellyData = new JellyData();

            JellyRenderer   = new DynamicPatchRenderer(shaderProvider.SurfaceShaderBezier, new Mesh(VertexLayout.Type.Position), jellyData);
            JellyController = new JellyController(jellyControlFrame);

            WireframeRenderer = new LineRenderer(shaderProvider.DefaultShader);
            var jellyCPVisualizer = new JellyControlPointVisualizer(WireframeRenderer);

            Jelly.AttachComponents(jellyData, JellyRenderer, JellyController, boundingBoxRenderer, jellyBoundingBox,
                                   WireframeRenderer, jellyCPVisualizer);


            _sceneManager.CurrentScene.AttachChild(Jelly);
            _sceneManager.CurrentScene.AttachChild(ControlFrame);

            var meshData  = MeshLoader.LoadObj("monkey2.obj");
            var monkey    = new Node(new Transform(Vector3.Zero, Quaternion.Identity, Vector3.One), "monkey");
            var jellyMesh = new JellyMesh(jellyData, meshData.positions, meshData.normals);

            JellyMeshRenderer = new DynamicMeshRenderer(shaderProvider.PhongShader, meshData.mesh);

            monkey.AttachComponents(JellyMeshRenderer, jellyMesh);
            _sceneManager.CurrentScene.AttachChild(monkey);
        }
Exemplo n.º 8
0
    /// <summary>
    /// Turn all the debug sprite renderers on/off
    /// </summary>
    void SetSpriteRenderersEnabled(bool enabled)
    {
        foreach (GameObject gameObject in m_BlobObjects)
        {
            JellyMesh jellyMesh = gameObject.GetComponent <JellyMesh>();

            if (jellyMesh)
            {
                jellyMesh.GetComponent <MeshRenderer>().enabled = !enabled;

                foreach (JellyMesh.ReferencePoint referencePoint in jellyMesh.ReferencePoints)
                {
                    GameObject refPointObject = referencePoint.GameObject;

                    if (refPointObject && referencePoint.GameObject.transform.childCount > 0)
                    {
                        referencePoint.GameObject.transform.GetChild(0).gameObject.SetActive(enabled);
                    }
                }
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     forwardVector           = transform.forward;
     jellyMesh               = GetComponent <JellyMesh>();
     speedCurve.postWrapMode = WrapMode.ClampForever;
 }
Exemplo n.º 10
0
    protected virtual void DisplayInspectorGUI()
    {
        JellyMesh targetObject = this.target as JellyMesh;

        EditorGUILayout.PropertyField(m_SourceMesh, new GUIContent("Mesh"));

        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.PropertyField(m_MeshScale, new GUIContent("Mesh Scale"));
        EditorGUILayout.PropertyField(m_RecalculateNormals, new GUIContent("Recalculate Normals"));

        GUI.enabled = true;

        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }

        GUILayout.Space(15);

        EditorGUILayout.PropertyField(m_PhysicsMode, new GUIContent("Use 2D Physics"));

        JellyMesh.PhysicsStyle selectedStyle = (JellyMesh.PhysicsStyle)m_PhysicsStyle.enumValueIndex;

        if (m_PhysicsStyle.intValue != (int)JellyMesh.PhysicsStyle.Free)
        {
            EditorGUILayout.PropertyField(m_AttachNeighbors, new GUIContent("Attach Neighbors"));
        }

        int initialStyle = m_PhysicsStyle.enumValueIndex;

        EditorGUILayout.PropertyField(m_PhysicsStyle, new GUIContent("Body Configuration"));

        if (m_PhysicsStyle.enumValueIndex != initialStyle && (JellyMesh.PhysicsStyle)m_PhysicsStyle.enumValueIndex == JellyMesh.PhysicsStyle.Free)
        {
            m_PhysicsStyle.enumValueIndex = initialStyle;
            Debug.LogError("Please use the 'Copy Configuration to Free Mode' button to switch the Jelly Mesh to Free Mode");
        }

        switch (selectedStyle)
        {
        case JellyMesh.PhysicsStyle.Circle:
            EditorGUILayout.IntSlider(m_CircleRadiusPoints, 8, 128, new GUIContent("Num Colliders"));
            break;

        case JellyMesh.PhysicsStyle.Sphere:
            EditorGUILayout.IntSlider(m_CircleRadiusPoints, 4, 128, new GUIContent("Collider Density"));
            break;

        case JellyMesh.PhysicsStyle.Rectangle:
            break;

        case JellyMesh.PhysicsStyle.Triangle:
            break;

        case JellyMesh.PhysicsStyle.Free:
            for (int i = 0; i < targetObject.m_FreeModeBodyPositions.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                Vector3 point     = targetObject.m_FreeModeBodyPositions[i];
                float   radius    = targetObject.m_FreeModeBodyRadii[i];
                bool    kinematic = targetObject.m_FreeModeBodyKinematic[i];

                Vector4 result = Vector4.zero;

                if (i == 0)
                {
                    result = EditorGUILayout.Vector3Field("Centre", new Vector3(point.x, point.y, point.z), GUILayout.MaxWidth(1500f));
                }
                else
                {
                    result = EditorGUILayout.Vector4Field("Body " + i.ToString(), new Vector4(point.x, point.y, point.z, radius), GUILayout.MaxWidth(1500f));
                }

                Vector3 positionResult  = new Vector3(result.x, result.y, result.z);
                bool    kinematicResult = false;

                if (point != positionResult)
                {
                    Undo.RecordObject(targetObject, "Adjusted Jelly Mesh Body Position");
                    targetObject.m_FreeModeBodyPositions[i] = positionResult;
                    SceneView.RepaintAll();
                }

                if (result.w != radius)
                {
                    Undo.RecordObject(targetObject, "Adjusted Jelly Mesh Body Radius");
                    targetObject.m_FreeModeBodyRadii[i] = result.w;
                    SceneView.RepaintAll();
                }

                using (new JellyMeshFixedWidthLabel("Kinematic"))
                {
                    kinematicResult = EditorGUILayout.Toggle(kinematic);
                }

                if (kinematicResult != kinematic)
                {
                    Undo.RecordObject(targetObject, "Adjusted Jelly Mesh Body Kinematic Flag");
                    targetObject.m_FreeModeBodyKinematic[i] = kinematicResult;
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button(new GUIContent("Delete", "delete this point"), EditorStyles.miniButtonRight, GUILayout.MaxWidth(100f)))
                {
                    if (i == 0)
                    {
                        Debug.LogWarning("Cannot remove central Jelly Mesh control point!");
                    }
                    else
                    {
                        Undo.RecordObject(targetObject, "Deleted Jelly Mesh Body");
                        targetObject.m_FreeModeBodyPositions.RemoveAt(i);
                        targetObject.m_FreeModeBodyRadii.RemoveAt(i);
                        SceneView.RepaintAll();
                        i--;
                    }
                }

                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(5);

            if (GUILayout.Button(new GUIContent("Add New Body", "Add new body"), EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(targetObject, "Added New Jelly Mesh Body");
                targetObject.m_FreeModeBodyPositions.Add(new Vector2(0.0f, -1.0f));
                targetObject.m_FreeModeBodyRadii.Add(1.0f);
                targetObject.m_FreeModeBodyKinematic.Add(false);
                SceneView.RepaintAll();
            }

            break;
        }

        if (selectedStyle != JellyMesh.PhysicsStyle.Free)
        {
            EditorGUILayout.Slider(m_ColliderRadius, 0.001f, 0.25f, new GUIContent("Collider Radius"));
            EditorGUILayout.PropertyField(m_SoftBodyScale, new GUIContent("Collider Scale"));
            EditorGUILayout.PropertyField(m_SoftBodyOffset, new GUIContent("Collider Offset"));
            EditorGUILayout.PropertyField(m_SoftBodyRotation, new GUIContent("Collider Rotation"));
            EditorGUILayout.PropertyField(m_SoftBodyPivotOffset, new GUIContent("Pivot Offset"));

            GUILayout.Space(5);

            if (GUILayout.Button(new GUIContent("Copy Configuration To Free Mode", "Copy this configuration to the free mode layout"), EditorStyles.miniButtonRight))
            {
                Undo.RecordObject(target, "Converted Jelly Mesh to Free Mode");
                targetObject.OnCopyToFreeModeSelected();
                SceneView.RepaintAll();
            }
        }

        GUI.enabled = true;

        EditorGUILayout.PropertyField(m_LockRotationX, new GUIContent("Freeze Rotation X"));
        EditorGUILayout.PropertyField(m_LockRotationY, new GUIContent("Freeze Rotation Y"));
        EditorGUILayout.PropertyField(m_LockRotationZ, new GUIContent("Freeze Rotation Z"));

        if (selectedStyle != JellyMesh.PhysicsStyle.Free)
        {
            EditorGUILayout.PropertyField(m_CentralBodyKinematic, new GUIContent("Kinematic Central Body"));
        }

        GUILayout.Space(15);

        if (m_PhysicsMode.boolValue)
        {
            EditorGUILayout.PropertyField(m_PhysicsMaterial2D, new GUIContent("Physics Material"));
            m_GravityScale.floatValue = EditorGUILayout.FloatField("Gravity Scale", m_GravityScale.floatValue);
        }
        else
        {
            EditorGUILayout.PropertyField(m_PhysicsMaterial, new GUIContent("Physics Material"));
        }

        EditorGUILayout.PropertyField(m_CollideConnected, new GUIContent("Collide Connected"));
        m_Drag.floatValue        = EditorGUILayout.FloatField("Drag", m_Drag.floatValue);
        m_AngularDrag.floatValue = EditorGUILayout.FloatField("Angular Drag", m_AngularDrag.floatValue);

        m_Stiffness.floatValue    = EditorGUILayout.FloatField("Spring Stiffness", m_Stiffness.floatValue);
        m_DampingRatio.floatValue = EditorGUILayout.FloatField("Spring Damping", m_DampingRatio.floatValue);
        EditorGUILayout.PropertyField(m_MassStyle, new GUIContent("Mass Type"));
        m_Mass.floatValue = EditorGUILayout.FloatField("Mass", m_Mass.floatValue);

        GUILayout.Space(15);

        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.Slider(m_DistanceExponent, 1.0f, 4.0f, new GUIContent("Ctrl Point Influence"));

        GUI.enabled = true;

        GUILayout.Space(15);

        m_NumAttachPoints.intValue = EditorGUILayout.IntField("Num Attach Points", m_NumAttachPoints.intValue);

        for (int loop = 0; loop < targetObject.m_AttachPoints.Length; loop++)
        {
            targetObject.m_AttachPoints[loop] = (Transform)EditorGUILayout.ObjectField("Attach Point", targetObject.m_AttachPoints[loop], typeof(Transform), true, null);
        }
    }
Exemplo n.º 11
0
    protected virtual void CheckForObjectChanges()
    {
        serializedObject.ApplyModifiedProperties();

        // Update the visible mesh if the mesh or vertex density was changed
        if (m_InitialMeshScale != m_MeshScale.vector3Value ||
            m_InitialMesh != m_SourceMesh.objectReferenceValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellyMesh targetObjectMesh = targetObject as JellyMesh;
                targetObjectMesh.RefreshMesh();
            }
        }

        // Update the springs if we altered any of their settings
        if (m_InitialStiffness != m_Stiffness.floatValue || m_InitialDamping != m_DampingRatio.floatValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellyMesh targetObjectMesh = targetObject as JellyMesh;
                targetObjectMesh.UpdateJoints();
                targetObjectMesh.WakeUp();
            }
        }

        // Recalculate weighting values if the exponent changes
        if (m_InitialDistanceExponent != m_DistanceExponent.floatValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellyMesh targetObjectMesh = targetObject as JellyMesh;
                targetObjectMesh.CalculateWeightingValues();
            }
        }

        // Update the mass of each body if the value changed
        if (m_InitialMassStyle != m_MassStyle.enumValueIndex ||
            m_InitialMass != m_Mass.floatValue ||
            m_InitialGravityScale != m_GravityScale.floatValue ||
            m_InitialAngularDrag != m_AngularDrag.floatValue ||
            m_InitialDrag != m_Drag.floatValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellyMesh targetObjectMesh = targetObject as JellyMesh;
                targetObjectMesh.InitMass();
                targetObjectMesh.WakeUp();
            }
        }

        if (m_InitialNumAttachPoints != m_NumAttachPoints.intValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellyMesh targetObjectMesh = targetObject as JellyMesh;
                targetObjectMesh.ResizeAttachPoints();
            }
        }

        if (m_InitialLockRotationX != m_LockRotationX.boolValue ||
            m_InitialLockRotationY != m_LockRotationY.boolValue ||
            m_InitialLockRotationZ != m_LockRotationZ.boolValue ||
            m_InitialCentralBodyKinematic != m_CentralBodyKinematic.boolValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellyMesh targetObjectMesh = targetObject as JellyMesh;
                targetObjectMesh.UpdateRotationLock();
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     posOri     = transform.position;
     player     = GameObject.Find("PlayerShell");
     playerMesh = player.GetComponent <JellyMesh>();
 }
Exemplo n.º 13
0
 //private int hueSwitch = 1;
 // Use this for initialization
 void Start()
 {
     m_JellyMesh = GetComponent<JellyMesh>();
     re = GetComponent<Renderer>();
     colNext = Color.grey;
     colPrev = Color.grey;
 }
Exemplo n.º 14
0
    /// <summary>
    /// Draws the GUI
    /// </summary>
    void OnGUI()
    {
        if (!m_DrawDebugText)
        {
            return;
        }

        GUI.Label(new Rect(20, 20, 900, 20), "Mouse: Look Around");
        GUI.Label(new Rect(20, 40, 900, 20), "W/A/S/D Keys: Move Camera");
        GUI.Label(new Rect(20, 60, 900, 20), "Left Mouse Button: Fire Physics Object");
        GUI.Label(new Rect(20, 80, 900, 20), "R Key: Toggle Physics Rendering");

        if (m_DrawPhysicsBodies)
        {
            if (m_KeyboardTogglePhysicsBodies)
            {
                m_DrawPhysicsBodies = !m_DrawPhysicsBodies;
                SetSpriteRenderersEnabled(false);
            }
        }
        else
        {
            if (m_KeyboardTogglePhysicsBodies)
            {
                m_DrawPhysicsBodies = !m_DrawPhysicsBodies;

                if (!m_DebugRenderersCreated)
                {
                    foreach (GameObject gameObject in m_BlobObjects)
                    {
                        JellyMesh jellyMesh = gameObject.GetComponent <JellyMesh>();

                        if (jellyMesh)
                        {
                            // Go through and create a simple circle mesh for each body
                            foreach (JellyMesh.ReferencePoint referencePoint in jellyMesh.ReferencePoints)
                            {
                                GameObject referencePointObject = new GameObject("Debug Renderer");
                                referencePointObject.transform.parent        = referencePoint.GameObject.transform;
                                referencePointObject.transform.localPosition = Vector3.zero;

                                if (referencePointObject)
                                {
                                    MeshRenderer meshRenderer = referencePointObject.AddComponent <MeshRenderer>();
                                    MeshFilter   meshFilter   = referencePointObject.AddComponent <MeshFilter>();
                                    meshFilter.sharedMesh       = m_DebugMesh;
                                    meshRenderer.sharedMaterial = m_DebugRenderMaterial;
                                    referencePointObject.transform.localScale = new Vector3(referencePoint.Radius, referencePoint.Radius, referencePoint.Radius);
                                }
                            }
                        }
                    }

                    m_DebugRenderersCreated = true;
                }

                SetSpriteRenderersEnabled(true);
            }
        }

        m_KeyboardTogglePhysicsBodies = false;
    }
Exemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        m_JellyMesh = GetComponent<JellyMesh>();
        re = GetComponent<Renderer>();

        hue = 0f;
        hueSpeed = 0f;
    }
Exemplo n.º 16
0
    [SerializeField] float _wanderChangeRate; // how fast the wander heading changes in the direction

    // Start is called before the first frame update
    void Start()
    {
        _jellyMesh = GetComponent <JellyMesh>();
        _stats     = GetComponent <PetStats>();
    }