Ejemplo n.º 1
0
    override public void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.PropertyField(creature_asset);
        EditorGUILayout.PropertyField(local_time_scale);
        EditorGUILayout.PropertyField(region_offsets_z);
        EditorGUILayout.PropertyField(counter_clockwise);

        bool did_change = EditorGUI.EndChangeCheck();

        // new assignment
        if ((creature_asset.objectReferenceValue != null) && did_change)
        {
            UpdateData();
        }

        if (creature_asset.objectReferenceValue != null)
        {
            CreatureAsset cur_asset = (CreatureAsset)creature_asset.objectReferenceValue;
            // asset changed
            if (cur_asset.GetIsDirty())
            {
                UpdateData();
                cur_asset.SetIsDirty(false);
            }

            // animations
            if (cur_asset.creature_manager != null)
            {
                string[] animation_names = new string[cur_asset.creature_manager.animations.Keys.Count];
                int      i = 0;
                foreach (string cur_name in cur_asset.creature_manager.animations.Keys)
                {
                    animation_names[i] = cur_name;
                    i++;
                }

                animation_choice_index.intValue = EditorGUILayout.Popup("Animation:",
                                                                        animation_choice_index.intValue, animation_names);

                should_loop.boolValue = EditorGUILayout.Toggle("Loop", should_loop.boolValue);

                if (!Application.isPlaying)
                {
                    updateTargetAnimation();
                }

                serializedObject.ApplyModifiedProperties();
            }
        }
    }
Ejemplo n.º 2
0
    public virtual void LateUpdate()
    {
        if (creature_manager != null)
        {
            doSwapMesh();

            if (creature_asset.GetIsDirty() || vertices == null)
            {
                CreateRenderingData();
                creature_asset.SetIsDirty(false);
            }

            UpdateTime();
            UpdateRenderingData();

            meshFilter.sharedMesh = active_mesh;
        }
    }
    /*
     * public List<UIVertex> ConvertMesh()
     * {
     *  Vector3[] vertices = active_mesh.vertices;
     *  int[] triangles = active_mesh.triangles;
     *  Vector3[] normals = active_mesh.normals;
     *  Vector2[] uv = active_mesh.uv;
     *
     *  List<UIVertex> vertexList = new List<UIVertex>(triangles.Length);
     *
     *  UIVertex vertex;
     *  for (int i = 0; i < triangles.Length; i++)
     *  {
     *      vertex = new UIVertex();
     *      int triangle = triangles[i];
     *
     *      vertex.position = (vertices[triangle] - active_mesh.bounds.center);
     *      vertex.uv0 = uv[triangle];
     *      vertex.normal = normals[triangle];
     *
     *      vertexList.Add(vertex);
     *
     *      if (i % 3 == 0)
     *          vertexList.Add(vertex);
     *  }
     *
     *  return vertexList;
     * }
     */

    // Update is called once per frame
    void LateUpdate()
    {
        if (creature_manager != null)
        {
            doSwapMesh();

            if (creature_asset.GetIsDirty() || vertices == null)
            {
                CreateRenderingData();
                creature_asset.SetIsDirty(false);
            }

            UpdateTime();
            UpdateRenderingData();
        }

        var renderer = GetComponent <CanvasRenderer>();

        renderer.SetMesh(active_mesh);
        renderer.materialCount = 1;
        renderer.SetMaterial(material, 0);
    }
Ejemplo n.º 4
0
    public void RunLiveSync()
    {
        CreatureAsset creature_asset = (CreatureAsset)target;

        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            if (!LiveSync.creatureClient_isConnected())
            {
                var can_connect = LiveSync.creatureClient_startConnection();
                if (!can_connect)
                {
                    LiveSync.creatureClient_stopConnection();
                }
            }

            if (LiveSync.creatureClient_isConnected())
            {
                var sync_type = GetLiveSyncType();

                if (sync_type.Length > 0)
                {
                    System.IntPtr raw_ptr =
                        LiveSync.creatureClient_retrieveRequestExportFilename(sync_type);
                    string response_str = Marshal.PtrToStringAnsi(raw_ptr);
                    if (response_str.Length == 0)
                    {
                        UnityEditor.EditorUtility.DisplayDialog("Creature Live Sync Error", "Make sure Creature Pro is running in Animate Mode to Live Sync!", "Ok");
                    }
                    else
                    {
                        if (sync_type == "REQUEST_JSON")
                        {
                            string    file_contents = System.IO.File.ReadAllText(response_str);
                            TextAsset text_asset    = (TextAsset)creatureJSON.objectReferenceValue;
                            File.WriteAllText(AssetDatabase.GetAssetPath(text_asset), file_contents);
                            EditorUtility.SetDirty(text_asset);
                            creature_asset.creature_manager = null;
                            UpdateData();
                            creature_asset.SetIsDirty(true);
                        }
                        else if (sync_type == "REQUEST_BYTES")
                        {
                            byte[]    file_contents   = System.IO.File.ReadAllBytes(response_str);
                            TextAsset flat_text_asset = (TextAsset)flatCreatureData.objectReferenceValue;
                            File.WriteAllBytes(AssetDatabase.GetAssetPath(flat_text_asset), file_contents);
                            EditorUtility.SetDirty(flat_text_asset);
                            creature_asset.creature_manager = null;
                            UpdateData();
                            creature_asset.SetIsDirty(true);
                        }

                        AssetDatabase.Refresh();
                    }
                }
            }
            else
            {
                UnityEditor.EditorUtility.DisplayDialog("Creature Live Sync Error", "Make sure Creature Pro is running in Animate Mode to Live Sync!", "Ok");
            }
        }
    }