コード例 #1
0
 void OnDisable()
 {
     if (Interop.isGlobalInit)
     {
         SM64Context.UnregisterSurfaceObject(this);
         Interop.SurfaceObjectDelete(_surfaceObjectId);
     }
 }
コード例 #2
0
 static void ensureInstanceExists()
 {
     if (s_instance == null)
     {
         var contextGo = new GameObject("SM64_CONTEXT");
         contextGo.hideFlags |= HideFlags.HideInHierarchy;
         s_instance           = contextGo.AddComponent <SM64Context>();
     }
 }
コード例 #3
0
ファイル: SM64Mario.cs プロジェクト: libsm64/libsm64-unity
        void OnDisable()
        {
            if (marioRendererObject != null)
            {
                Destroy(marioRendererObject);
                marioRendererObject = null;
            }

            if (Interop.isGlobalInit)
            {
                SM64Context.UnregisterMario(this);
                Interop.MarioDelete(marioId);
            }
        }
コード例 #4
0
        void OnEnable()
        {
            SM64Context.RegisterSurfaceObject(this);

            _position     = transform.position;
            _rotation     = transform.rotation;
            _lastPosition = _position;
            _lastRotation = _rotation;
            _nextPosition = _position;
            _nextRotation = _rotation;

            var mc       = GetComponent <MeshCollider>();
            var surfaces = Utils.GetSurfacesForMesh(transform.lossyScale, mc.sharedMesh, surfaceType, terrainType);

            _surfaceObjectId = Interop.SurfaceObjectCreate(_position, _rotation, surfaces.ToArray());
        }
コード例 #5
0
ファイル: SM64Mario.cs プロジェクト: libsm64/libsm64-unity
        void OnEnable()
        {
            SM64Context.RegisterMario(this);

            var initPos = transform.position;

            marioId = Interop.MarioCreate(new Vector3(-initPos.x, initPos.y, initPos.z) * Interop.SCALE_FACTOR);

            inputProvider = GetComponent <SM64InputProvider>();
            if (inputProvider == null)
            {
                throw new System.Exception("Need to add an input provider component to Mario");
            }

            marioRendererObject            = new GameObject("MARIO");
            marioRendererObject.hideFlags |= HideFlags.HideInHierarchy;

            var renderer   = marioRendererObject.AddComponent <MeshRenderer>();
            var meshFilter = marioRendererObject.AddComponent <MeshFilter>();

            states = new Interop.SM64MarioState[2] {
                new Interop.SM64MarioState(),
                new Interop.SM64MarioState()
            };

            renderer.material = material;
            renderer.sharedMaterial.SetTexture("_MainTex", Interop.marioTexture);

            marioRendererObject.transform.localScale    = new Vector3(-1, 1, 1) / Interop.SCALE_FACTOR;
            marioRendererObject.transform.localPosition = Vector3.zero;

            lerpPositionBuffer = new Vector3[3 * Interop.SM64_GEO_MAX_TRIANGLES];
            lerpNormalBuffer   = new Vector3[3 * Interop.SM64_GEO_MAX_TRIANGLES];
            positionBuffers    = new Vector3[][] { new Vector3[3 * Interop.SM64_GEO_MAX_TRIANGLES], new Vector3[3 * Interop.SM64_GEO_MAX_TRIANGLES] };
            normalBuffers      = new Vector3[][] { new Vector3[3 * Interop.SM64_GEO_MAX_TRIANGLES], new Vector3[3 * Interop.SM64_GEO_MAX_TRIANGLES] };
            colorBuffer        = new Vector3[3 * Interop.SM64_GEO_MAX_TRIANGLES];
            colorBufferColors  = new Color[3 * Interop.SM64_GEO_MAX_TRIANGLES];
            uvBuffer           = new Vector2[3 * Interop.SM64_GEO_MAX_TRIANGLES];

            marioMesh             = new Mesh();
            marioMesh.vertices    = lerpPositionBuffer;
            marioMesh.triangles   = Enumerable.Range(0, 3 * Interop.SM64_GEO_MAX_TRIANGLES).ToArray();
            meshFilter.sharedMesh = marioMesh;
        }
コード例 #6
0
 void OnApplicationQuit()
 {
     Interop.GlobalTerminate();
     s_instance = null;
 }